162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2005-2014, 2018-2021, 2023 Intel Corporation
462306a36Sopenharmony_ci * Copyright (C) 2015-2017 Intel Deutschland GmbH
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef __iwl_fh_h__
762306a36Sopenharmony_ci#define __iwl_fh_h__
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/types.h>
1062306a36Sopenharmony_ci#include <linux/bitfield.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include "iwl-trans.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/****************************/
1562306a36Sopenharmony_ci/* Flow Handler Definitions */
1662306a36Sopenharmony_ci/****************************/
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/**
1962306a36Sopenharmony_ci * This I/O area is directly read/writable by driver (e.g. Linux uses writel())
2062306a36Sopenharmony_ci * Addresses are offsets from device's PCI hardware base address.
2162306a36Sopenharmony_ci */
2262306a36Sopenharmony_ci#define FH_MEM_LOWER_BOUND                   (0x1000)
2362306a36Sopenharmony_ci#define FH_MEM_UPPER_BOUND                   (0x2000)
2462306a36Sopenharmony_ci#define FH_MEM_LOWER_BOUND_GEN2              (0xa06000)
2562306a36Sopenharmony_ci#define FH_MEM_UPPER_BOUND_GEN2              (0xa08000)
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/**
2862306a36Sopenharmony_ci * Keep-Warm (KW) buffer base address.
2962306a36Sopenharmony_ci *
3062306a36Sopenharmony_ci * Driver must allocate a 4KByte buffer that is for keeping the
3162306a36Sopenharmony_ci * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency
3262306a36Sopenharmony_ci * DRAM access when doing Txing or Rxing.  The dummy accesses prevent host
3362306a36Sopenharmony_ci * from going into a power-savings mode that would cause higher DRAM latency,
3462306a36Sopenharmony_ci * and possible data over/under-runs, before all Tx/Rx is complete.
3562306a36Sopenharmony_ci *
3662306a36Sopenharmony_ci * Driver loads FH_KW_MEM_ADDR_REG with the physical address (bits 35:4)
3762306a36Sopenharmony_ci * of the buffer, which must be 4K aligned.  Once this is set up, the device
3862306a36Sopenharmony_ci * automatically invokes keep-warm accesses when normal accesses might not
3962306a36Sopenharmony_ci * be sufficient to maintain fast DRAM response.
4062306a36Sopenharmony_ci *
4162306a36Sopenharmony_ci * Bit fields:
4262306a36Sopenharmony_ci *  31-0:  Keep-warm buffer physical base address [35:4], must be 4K aligned
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_ci#define FH_KW_MEM_ADDR_REG		     (FH_MEM_LOWER_BOUND + 0x97C)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci/**
4862306a36Sopenharmony_ci * TFD Circular Buffers Base (CBBC) addresses
4962306a36Sopenharmony_ci *
5062306a36Sopenharmony_ci * Device has 16 base pointer registers, one for each of 16 host-DRAM-resident
5162306a36Sopenharmony_ci * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)
5262306a36Sopenharmony_ci * (see struct iwl_tfd_frame).  These 16 pointer registers are offset by 0x04
5362306a36Sopenharmony_ci * bytes from one another.  Each TFD circular buffer in DRAM must be 256-byte
5462306a36Sopenharmony_ci * aligned (address bits 0-7 must be 0).
5562306a36Sopenharmony_ci * Later devices have 20 (5000 series) or 30 (higher) queues, but the registers
5662306a36Sopenharmony_ci * for them are in different places.
5762306a36Sopenharmony_ci *
5862306a36Sopenharmony_ci * Bit fields in each pointer register:
5962306a36Sopenharmony_ci *  27-0: TFD CB physical base address [35:8], must be 256-byte aligned
6062306a36Sopenharmony_ci */
6162306a36Sopenharmony_ci#define FH_MEM_CBBC_0_15_LOWER_BOUND		(FH_MEM_LOWER_BOUND + 0x9D0)
6262306a36Sopenharmony_ci#define FH_MEM_CBBC_0_15_UPPER_BOUND		(FH_MEM_LOWER_BOUND + 0xA10)
6362306a36Sopenharmony_ci#define FH_MEM_CBBC_16_19_LOWER_BOUND		(FH_MEM_LOWER_BOUND + 0xBF0)
6462306a36Sopenharmony_ci#define FH_MEM_CBBC_16_19_UPPER_BOUND		(FH_MEM_LOWER_BOUND + 0xC00)
6562306a36Sopenharmony_ci#define FH_MEM_CBBC_20_31_LOWER_BOUND		(FH_MEM_LOWER_BOUND + 0xB20)
6662306a36Sopenharmony_ci#define FH_MEM_CBBC_20_31_UPPER_BOUND		(FH_MEM_LOWER_BOUND + 0xB80)
6762306a36Sopenharmony_ci/* 22000 TFD table address, 64 bit */
6862306a36Sopenharmony_ci#define TFH_TFDQ_CBB_TABLE			(0x1C00)
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* Find TFD CB base pointer for given queue */
7162306a36Sopenharmony_cistatic inline unsigned int FH_MEM_CBBC_QUEUE(struct iwl_trans *trans,
7262306a36Sopenharmony_ci					     unsigned int chnl)
7362306a36Sopenharmony_ci{
7462306a36Sopenharmony_ci	if (trans->trans_cfg->gen2) {
7562306a36Sopenharmony_ci		WARN_ON_ONCE(chnl >= 64);
7662306a36Sopenharmony_ci		return TFH_TFDQ_CBB_TABLE + 8 * chnl;
7762306a36Sopenharmony_ci	}
7862306a36Sopenharmony_ci	if (chnl < 16)
7962306a36Sopenharmony_ci		return FH_MEM_CBBC_0_15_LOWER_BOUND + 4 * chnl;
8062306a36Sopenharmony_ci	if (chnl < 20)
8162306a36Sopenharmony_ci		return FH_MEM_CBBC_16_19_LOWER_BOUND + 4 * (chnl - 16);
8262306a36Sopenharmony_ci	WARN_ON_ONCE(chnl >= 32);
8362306a36Sopenharmony_ci	return FH_MEM_CBBC_20_31_LOWER_BOUND + 4 * (chnl - 20);
8462306a36Sopenharmony_ci}
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* 22000 configuration registers */
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/*
8962306a36Sopenharmony_ci * TFH Configuration register.
9062306a36Sopenharmony_ci *
9162306a36Sopenharmony_ci * BIT fields:
9262306a36Sopenharmony_ci *
9362306a36Sopenharmony_ci * Bits 3:0:
9462306a36Sopenharmony_ci * Define the maximum number of pending read requests.
9562306a36Sopenharmony_ci * Maximum configuration value allowed is 0xC
9662306a36Sopenharmony_ci * Bits 9:8:
9762306a36Sopenharmony_ci * Define the maximum transfer size. (64 / 128 / 256)
9862306a36Sopenharmony_ci * Bit 10:
9962306a36Sopenharmony_ci * When bit is set and transfer size is set to 128B, the TFH will enable
10062306a36Sopenharmony_ci * reading chunks of more than 64B only if the read address is aligned to 128B.
10162306a36Sopenharmony_ci * In case of DRAM read address which is not aligned to 128B, the TFH will
10262306a36Sopenharmony_ci * enable transfer size which doesn't cross 64B DRAM address boundary.
10362306a36Sopenharmony_ci*/
10462306a36Sopenharmony_ci#define TFH_TRANSFER_MODE		(0x1F40)
10562306a36Sopenharmony_ci#define TFH_TRANSFER_MAX_PENDING_REQ	0xc
10662306a36Sopenharmony_ci#define TFH_CHUNK_SIZE_128			BIT(8)
10762306a36Sopenharmony_ci#define TFH_CHUNK_SPLIT_MODE		BIT(10)
10862306a36Sopenharmony_ci/*
10962306a36Sopenharmony_ci * Defines the offset address in dwords referring from the beginning of the
11062306a36Sopenharmony_ci * Tx CMD which will be updated in DRAM.
11162306a36Sopenharmony_ci * Note that the TFH offset address for Tx CMD update is always referring to
11262306a36Sopenharmony_ci * the start of the TFD first TB.
11362306a36Sopenharmony_ci * In case of a DRAM Tx CMD update the TFH will update PN and Key ID
11462306a36Sopenharmony_ci */
11562306a36Sopenharmony_ci#define TFH_TXCMD_UPDATE_CFG		(0x1F48)
11662306a36Sopenharmony_ci/*
11762306a36Sopenharmony_ci * Controls TX DMA operation
11862306a36Sopenharmony_ci *
11962306a36Sopenharmony_ci * BIT fields:
12062306a36Sopenharmony_ci *
12162306a36Sopenharmony_ci * Bits 31:30: Enable the SRAM DMA channel.
12262306a36Sopenharmony_ci * Turning on bit 31 will kick the SRAM2DRAM DMA.
12362306a36Sopenharmony_ci * Note that the sram2dram may be enabled only after configuring the DRAM and
12462306a36Sopenharmony_ci * SRAM addresses registers and the byte count register.
12562306a36Sopenharmony_ci * Bits 25:24: Defines the interrupt target upon dram2sram transfer done. When
12662306a36Sopenharmony_ci * set to 1 - interrupt is sent to the driver
12762306a36Sopenharmony_ci * Bit 0: Indicates the snoop configuration
12862306a36Sopenharmony_ci*/
12962306a36Sopenharmony_ci#define TFH_SRV_DMA_CHNL0_CTRL	(0x1F60)
13062306a36Sopenharmony_ci#define TFH_SRV_DMA_SNOOP	BIT(0)
13162306a36Sopenharmony_ci#define TFH_SRV_DMA_TO_DRIVER	BIT(24)
13262306a36Sopenharmony_ci#define TFH_SRV_DMA_START	BIT(31)
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci/* Defines the DMA SRAM write start address to transfer a data block */
13562306a36Sopenharmony_ci#define TFH_SRV_DMA_CHNL0_SRAM_ADDR	(0x1F64)
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci/* Defines the 64bits DRAM start address to read the DMA data block from */
13862306a36Sopenharmony_ci#define TFH_SRV_DMA_CHNL0_DRAM_ADDR	(0x1F68)
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci/*
14162306a36Sopenharmony_ci * Defines the number of bytes to transfer from DRAM to SRAM.
14262306a36Sopenharmony_ci * Note that this register may be configured with non-dword aligned size.
14362306a36Sopenharmony_ci */
14462306a36Sopenharmony_ci#define TFH_SRV_DMA_CHNL0_BC	(0x1F70)
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci/**
14762306a36Sopenharmony_ci * Rx SRAM Control and Status Registers (RSCSR)
14862306a36Sopenharmony_ci *
14962306a36Sopenharmony_ci * These registers provide handshake between driver and device for the Rx queue
15062306a36Sopenharmony_ci * (this queue handles *all* command responses, notifications, Rx data, etc.
15162306a36Sopenharmony_ci * sent from uCode to host driver).  Unlike Tx, there is only one Rx
15262306a36Sopenharmony_ci * queue, and only one Rx DMA/FIFO channel.  Also unlike Tx, which can
15362306a36Sopenharmony_ci * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer
15462306a36Sopenharmony_ci * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1
15562306a36Sopenharmony_ci * mapping between RBDs and RBs.
15662306a36Sopenharmony_ci *
15762306a36Sopenharmony_ci * Driver must allocate host DRAM memory for the following, and set the
15862306a36Sopenharmony_ci * physical address of each into device registers:
15962306a36Sopenharmony_ci *
16062306a36Sopenharmony_ci * 1)  Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256
16162306a36Sopenharmony_ci *     entries (although any power of 2, up to 4096, is selectable by driver).
16262306a36Sopenharmony_ci *     Each entry (1 dword) points to a receive buffer (RB) of consistent size
16362306a36Sopenharmony_ci *     (typically 4K, although 8K or 16K are also selectable by driver).
16462306a36Sopenharmony_ci *     Driver sets up RB size and number of RBDs in the CB via Rx config
16562306a36Sopenharmony_ci *     register FH_MEM_RCSR_CHNL0_CONFIG_REG.
16662306a36Sopenharmony_ci *
16762306a36Sopenharmony_ci *     Bit fields within one RBD:
16862306a36Sopenharmony_ci *     27-0:  Receive Buffer physical address bits [35:8], 256-byte aligned
16962306a36Sopenharmony_ci *
17062306a36Sopenharmony_ci *     Driver sets physical address [35:8] of base of RBD circular buffer
17162306a36Sopenharmony_ci *     into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].
17262306a36Sopenharmony_ci *
17362306a36Sopenharmony_ci * 2)  Rx status buffer, 8 bytes, in which uCode indicates which Rx Buffers
17462306a36Sopenharmony_ci *     (RBs) have been filled, via a "write pointer", actually the index of
17562306a36Sopenharmony_ci *     the RB's corresponding RBD within the circular buffer.  Driver sets
17662306a36Sopenharmony_ci *     physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0].
17762306a36Sopenharmony_ci *
17862306a36Sopenharmony_ci *     Bit fields in lower dword of Rx status buffer (upper dword not used
17962306a36Sopenharmony_ci *     by driver:
18062306a36Sopenharmony_ci *     31-12:  Not used by driver
18162306a36Sopenharmony_ci *     11- 0:  Index of last filled Rx buffer descriptor
18262306a36Sopenharmony_ci *             (device writes, driver reads this value)
18362306a36Sopenharmony_ci *
18462306a36Sopenharmony_ci * As the driver prepares Receive Buffers (RBs) for device to fill, driver must
18562306a36Sopenharmony_ci * enter pointers to these RBs into contiguous RBD circular buffer entries,
18662306a36Sopenharmony_ci * and update the device's "write" index register,
18762306a36Sopenharmony_ci * FH_RSCSR_CHNL0_RBDCB_WPTR_REG.
18862306a36Sopenharmony_ci *
18962306a36Sopenharmony_ci * This "write" index corresponds to the *next* RBD that the driver will make
19062306a36Sopenharmony_ci * available, i.e. one RBD past the tail of the ready-to-fill RBDs within
19162306a36Sopenharmony_ci * the circular buffer.  This value should initially be 0 (before preparing any
19262306a36Sopenharmony_ci * RBs), should be 8 after preparing the first 8 RBs (for example), and must
19362306a36Sopenharmony_ci * wrap back to 0 at the end of the circular buffer (but don't wrap before
19462306a36Sopenharmony_ci * "read" index has advanced past 1!  See below).
19562306a36Sopenharmony_ci * NOTE:  DEVICE EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8.
19662306a36Sopenharmony_ci *
19762306a36Sopenharmony_ci * As the device fills RBs (referenced from contiguous RBDs within the circular
19862306a36Sopenharmony_ci * buffer), it updates the Rx status buffer in host DRAM, 2) described above,
19962306a36Sopenharmony_ci * to tell the driver the index of the latest filled RBD.  The driver must
20062306a36Sopenharmony_ci * read this "read" index from DRAM after receiving an Rx interrupt from device
20162306a36Sopenharmony_ci *
20262306a36Sopenharmony_ci * The driver must also internally keep track of a third index, which is the
20362306a36Sopenharmony_ci * next RBD to process.  When receiving an Rx interrupt, driver should process
20462306a36Sopenharmony_ci * all filled but unprocessed RBs up to, but not including, the RB
20562306a36Sopenharmony_ci * corresponding to the "read" index.  For example, if "read" index becomes "1",
20662306a36Sopenharmony_ci * driver may process the RB pointed to by RBD 0.  Depending on volume of
20762306a36Sopenharmony_ci * traffic, there may be many RBs to process.
20862306a36Sopenharmony_ci *
20962306a36Sopenharmony_ci * If read index == write index, device thinks there is no room to put new data.
21062306a36Sopenharmony_ci * Due to this, the maximum number of filled RBs is 255, instead of 256.  To
21162306a36Sopenharmony_ci * be safe, make sure that there is a gap of at least 2 RBDs between "write"
21262306a36Sopenharmony_ci * and "read" indexes; that is, make sure that there are no more than 254
21362306a36Sopenharmony_ci * buffers waiting to be filled.
21462306a36Sopenharmony_ci */
21562306a36Sopenharmony_ci#define FH_MEM_RSCSR_LOWER_BOUND	(FH_MEM_LOWER_BOUND + 0xBC0)
21662306a36Sopenharmony_ci#define FH_MEM_RSCSR_UPPER_BOUND	(FH_MEM_LOWER_BOUND + 0xC00)
21762306a36Sopenharmony_ci#define FH_MEM_RSCSR_CHNL0		(FH_MEM_RSCSR_LOWER_BOUND)
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci/**
22062306a36Sopenharmony_ci * Physical base address of 8-byte Rx Status buffer.
22162306a36Sopenharmony_ci * Bit fields:
22262306a36Sopenharmony_ci *  31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.
22362306a36Sopenharmony_ci */
22462306a36Sopenharmony_ci#define FH_RSCSR_CHNL0_STTS_WPTR_REG	(FH_MEM_RSCSR_CHNL0)
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci/**
22762306a36Sopenharmony_ci * Physical base address of Rx Buffer Descriptor Circular Buffer.
22862306a36Sopenharmony_ci * Bit fields:
22962306a36Sopenharmony_ci *  27-0:  RBD CD physical base address [35:8], must be 256-byte aligned.
23062306a36Sopenharmony_ci */
23162306a36Sopenharmony_ci#define FH_RSCSR_CHNL0_RBDCB_BASE_REG	(FH_MEM_RSCSR_CHNL0 + 0x004)
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ci/**
23462306a36Sopenharmony_ci * Rx write pointer (index, really!).
23562306a36Sopenharmony_ci * Bit fields:
23662306a36Sopenharmony_ci *  11-0:  Index of driver's most recent prepared-to-be-filled RBD, + 1.
23762306a36Sopenharmony_ci *         NOTE:  For 256-entry circular buffer, use only bits [7:0].
23862306a36Sopenharmony_ci */
23962306a36Sopenharmony_ci#define FH_RSCSR_CHNL0_RBDCB_WPTR_REG	(FH_MEM_RSCSR_CHNL0 + 0x008)
24062306a36Sopenharmony_ci#define FH_RSCSR_CHNL0_WPTR        (FH_RSCSR_CHNL0_RBDCB_WPTR_REG)
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci#define FW_RSCSR_CHNL0_RXDCB_RDPTR_REG	(FH_MEM_RSCSR_CHNL0 + 0x00c)
24362306a36Sopenharmony_ci#define FH_RSCSR_CHNL0_RDPTR		FW_RSCSR_CHNL0_RXDCB_RDPTR_REG
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci/**
24662306a36Sopenharmony_ci * Rx Config/Status Registers (RCSR)
24762306a36Sopenharmony_ci * Rx Config Reg for channel 0 (only channel used)
24862306a36Sopenharmony_ci *
24962306a36Sopenharmony_ci * Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for
25062306a36Sopenharmony_ci * normal operation (see bit fields).
25162306a36Sopenharmony_ci *
25262306a36Sopenharmony_ci * Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.
25362306a36Sopenharmony_ci * Driver should poll FH_MEM_RSSR_RX_STATUS_REG	for
25462306a36Sopenharmony_ci * FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.
25562306a36Sopenharmony_ci *
25662306a36Sopenharmony_ci * Bit fields:
25762306a36Sopenharmony_ci * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,
25862306a36Sopenharmony_ci *        '10' operate normally
25962306a36Sopenharmony_ci * 29-24: reserved
26062306a36Sopenharmony_ci * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),
26162306a36Sopenharmony_ci *        min "5" for 32 RBDs, max "12" for 4096 RBDs.
26262306a36Sopenharmony_ci * 19-18: reserved
26362306a36Sopenharmony_ci * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,
26462306a36Sopenharmony_ci *        '10' 12K, '11' 16K.
26562306a36Sopenharmony_ci * 15-14: reserved
26662306a36Sopenharmony_ci * 13-12: IRQ destination; '00' none, '01' host driver (normal operation)
26762306a36Sopenharmony_ci * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)
26862306a36Sopenharmony_ci *        typical value 0x10 (about 1/2 msec)
26962306a36Sopenharmony_ci *  3- 0: reserved
27062306a36Sopenharmony_ci */
27162306a36Sopenharmony_ci#define FH_MEM_RCSR_LOWER_BOUND      (FH_MEM_LOWER_BOUND + 0xC00)
27262306a36Sopenharmony_ci#define FH_MEM_RCSR_UPPER_BOUND      (FH_MEM_LOWER_BOUND + 0xCC0)
27362306a36Sopenharmony_ci#define FH_MEM_RCSR_CHNL0            (FH_MEM_RCSR_LOWER_BOUND)
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci#define FH_MEM_RCSR_CHNL0_CONFIG_REG	(FH_MEM_RCSR_CHNL0)
27662306a36Sopenharmony_ci#define FH_MEM_RCSR_CHNL0_RBDCB_WPTR	(FH_MEM_RCSR_CHNL0 + 0x8)
27762306a36Sopenharmony_ci#define FH_MEM_RCSR_CHNL0_FLUSH_RB_REQ	(FH_MEM_RCSR_CHNL0 + 0x10)
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MSK (0x00000FF0) /* bits 4-11 */
28062306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MSK   (0x00001000) /* bits 12 */
28162306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK (0x00008000) /* bit 15 */
28262306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MSK   (0x00030000) /* bits 16-17 */
28362306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MSK (0x00F00000) /* bits 20-23 */
28462306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MSK (0xC0000000) /* bits 30-31*/
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS	(20)
28762306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS	(4)
28862306a36Sopenharmony_ci#define RX_RB_TIMEOUT	(0x11)
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL         (0x00000000)
29162306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL     (0x40000000)
29262306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL        (0x80000000)
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K    (0x00000000)
29562306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K    (0x00010000)
29662306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K   (0x00020000)
29762306a36Sopenharmony_ci#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K   (0x00030000)
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY              (0x00000004)
30062306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL    (0x00000000)
30162306a36Sopenharmony_ci#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL  (0x00001000)
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci/**
30462306a36Sopenharmony_ci * Rx Shared Status Registers (RSSR)
30562306a36Sopenharmony_ci *
30662306a36Sopenharmony_ci * After stopping Rx DMA channel (writing 0 to
30762306a36Sopenharmony_ci * FH_MEM_RCSR_CHNL0_CONFIG_REG), driver must poll
30862306a36Sopenharmony_ci * FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.
30962306a36Sopenharmony_ci *
31062306a36Sopenharmony_ci * Bit fields:
31162306a36Sopenharmony_ci *  24:  1 = Channel 0 is idle
31262306a36Sopenharmony_ci *
31362306a36Sopenharmony_ci * FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV
31462306a36Sopenharmony_ci * contain default values that should not be altered by the driver.
31562306a36Sopenharmony_ci */
31662306a36Sopenharmony_ci#define FH_MEM_RSSR_LOWER_BOUND           (FH_MEM_LOWER_BOUND + 0xC40)
31762306a36Sopenharmony_ci#define FH_MEM_RSSR_UPPER_BOUND           (FH_MEM_LOWER_BOUND + 0xD00)
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci#define FH_MEM_RSSR_SHARED_CTRL_REG       (FH_MEM_RSSR_LOWER_BOUND)
32062306a36Sopenharmony_ci#define FH_MEM_RSSR_RX_STATUS_REG	(FH_MEM_RSSR_LOWER_BOUND + 0x004)
32162306a36Sopenharmony_ci#define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV\
32262306a36Sopenharmony_ci					(FH_MEM_RSSR_LOWER_BOUND + 0x008)
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci#define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE	(0x01000000)
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_ci#define FH_MEM_TFDIB_REG1_ADDR_BITSHIFT	28
32762306a36Sopenharmony_ci#define FH_MEM_TB_MAX_LENGTH			(0x00020000)
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_ci/* 9000 rx series registers */
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_ci#define RFH_Q0_FRBDCB_BA_LSB 0xA08000 /* 64 bit address */
33262306a36Sopenharmony_ci#define RFH_Q_FRBDCB_BA_LSB(q) (RFH_Q0_FRBDCB_BA_LSB + (q) * 8)
33362306a36Sopenharmony_ci/* Write index table */
33462306a36Sopenharmony_ci#define RFH_Q0_FRBDCB_WIDX 0xA08080
33562306a36Sopenharmony_ci#define RFH_Q_FRBDCB_WIDX(q) (RFH_Q0_FRBDCB_WIDX + (q) * 4)
33662306a36Sopenharmony_ci/* Write index table - shadow registers */
33762306a36Sopenharmony_ci#define RFH_Q0_FRBDCB_WIDX_TRG 0x1C80
33862306a36Sopenharmony_ci#define RFH_Q_FRBDCB_WIDX_TRG(q) (RFH_Q0_FRBDCB_WIDX_TRG + (q) * 4)
33962306a36Sopenharmony_ci/* Read index table */
34062306a36Sopenharmony_ci#define RFH_Q0_FRBDCB_RIDX 0xA080C0
34162306a36Sopenharmony_ci#define RFH_Q_FRBDCB_RIDX(q) (RFH_Q0_FRBDCB_RIDX + (q) * 4)
34262306a36Sopenharmony_ci/* Used list table */
34362306a36Sopenharmony_ci#define RFH_Q0_URBDCB_BA_LSB 0xA08100 /* 64 bit address */
34462306a36Sopenharmony_ci#define RFH_Q_URBDCB_BA_LSB(q) (RFH_Q0_URBDCB_BA_LSB + (q) * 8)
34562306a36Sopenharmony_ci/* Write index table */
34662306a36Sopenharmony_ci#define RFH_Q0_URBDCB_WIDX 0xA08180
34762306a36Sopenharmony_ci#define RFH_Q_URBDCB_WIDX(q) (RFH_Q0_URBDCB_WIDX + (q) * 4)
34862306a36Sopenharmony_ci#define RFH_Q0_URBDCB_VAID 0xA081C0
34962306a36Sopenharmony_ci#define RFH_Q_URBDCB_VAID(q) (RFH_Q0_URBDCB_VAID + (q) * 4)
35062306a36Sopenharmony_ci/* stts */
35162306a36Sopenharmony_ci#define RFH_Q0_URBD_STTS_WPTR_LSB 0xA08200 /*64 bits address */
35262306a36Sopenharmony_ci#define RFH_Q_URBD_STTS_WPTR_LSB(q) (RFH_Q0_URBD_STTS_WPTR_LSB + (q) * 8)
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci#define RFH_Q0_ORB_WPTR_LSB 0xA08280
35562306a36Sopenharmony_ci#define RFH_Q_ORB_WPTR_LSB(q) (RFH_Q0_ORB_WPTR_LSB + (q) * 8)
35662306a36Sopenharmony_ci#define RFH_RBDBUF_RBD0_LSB 0xA08300
35762306a36Sopenharmony_ci#define RFH_RBDBUF_RBD_LSB(q) (RFH_RBDBUF_RBD0_LSB + (q) * 8)
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci/**
36062306a36Sopenharmony_ci * RFH Status Register
36162306a36Sopenharmony_ci *
36262306a36Sopenharmony_ci * Bit fields:
36362306a36Sopenharmony_ci *
36462306a36Sopenharmony_ci * Bit 29: RBD_FETCH_IDLE
36562306a36Sopenharmony_ci * This status flag is set by the RFH when there is no active RBD fetch from
36662306a36Sopenharmony_ci * DRAM.
36762306a36Sopenharmony_ci * Once the RFH RBD controller starts fetching (or when there is a pending
36862306a36Sopenharmony_ci * RBD read response from DRAM), this flag is immediately turned off.
36962306a36Sopenharmony_ci *
37062306a36Sopenharmony_ci * Bit 30: SRAM_DMA_IDLE
37162306a36Sopenharmony_ci * This status flag is set by the RFH when there is no active transaction from
37262306a36Sopenharmony_ci * SRAM to DRAM.
37362306a36Sopenharmony_ci * Once the SRAM to DRAM DMA is active, this flag is immediately turned off.
37462306a36Sopenharmony_ci *
37562306a36Sopenharmony_ci * Bit 31: RXF_DMA_IDLE
37662306a36Sopenharmony_ci * This status flag is set by the RFH when there is no active transaction from
37762306a36Sopenharmony_ci * RXF to DRAM.
37862306a36Sopenharmony_ci * Once the RXF-to-DRAM DMA is active, this flag is immediately turned off.
37962306a36Sopenharmony_ci */
38062306a36Sopenharmony_ci#define RFH_GEN_STATUS		0xA09808
38162306a36Sopenharmony_ci#define RFH_GEN_STATUS_GEN3	0xA07824
38262306a36Sopenharmony_ci#define RBD_FETCH_IDLE	BIT(29)
38362306a36Sopenharmony_ci#define SRAM_DMA_IDLE	BIT(30)
38462306a36Sopenharmony_ci#define RXF_DMA_IDLE	BIT(31)
38562306a36Sopenharmony_ci
38662306a36Sopenharmony_ci/* DMA configuration */
38762306a36Sopenharmony_ci#define RFH_RXF_DMA_CFG		0xA09820
38862306a36Sopenharmony_ci#define RFH_RXF_DMA_CFG_GEN3	0xA07880
38962306a36Sopenharmony_ci/* RB size */
39062306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_MASK (0x000F0000) /* bits 16-19 */
39162306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_POS 16
39262306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_1K	(0x1 << RFH_RXF_DMA_RB_SIZE_POS)
39362306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_2K	(0x2 << RFH_RXF_DMA_RB_SIZE_POS)
39462306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_4K	(0x4 << RFH_RXF_DMA_RB_SIZE_POS)
39562306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_8K	(0x8 << RFH_RXF_DMA_RB_SIZE_POS)
39662306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_12K	(0x9 << RFH_RXF_DMA_RB_SIZE_POS)
39762306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_16K	(0xA << RFH_RXF_DMA_RB_SIZE_POS)
39862306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_20K	(0xB << RFH_RXF_DMA_RB_SIZE_POS)
39962306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_24K	(0xC << RFH_RXF_DMA_RB_SIZE_POS)
40062306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_28K	(0xD << RFH_RXF_DMA_RB_SIZE_POS)
40162306a36Sopenharmony_ci#define RFH_RXF_DMA_RB_SIZE_32K	(0xE << RFH_RXF_DMA_RB_SIZE_POS)
40262306a36Sopenharmony_ci/* RB Circular Buffer size:defines the table sizes in RBD units */
40362306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_MASK (0x00F00000) /* bits 20-23 */
40462306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_POS 20
40562306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_8	(0x3 << RFH_RXF_DMA_RBDCB_SIZE_POS)
40662306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_16	(0x4 << RFH_RXF_DMA_RBDCB_SIZE_POS)
40762306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_32	(0x5 << RFH_RXF_DMA_RBDCB_SIZE_POS)
40862306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_64	(0x7 << RFH_RXF_DMA_RBDCB_SIZE_POS)
40962306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_128	(0x7 << RFH_RXF_DMA_RBDCB_SIZE_POS)
41062306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_256	(0x8 << RFH_RXF_DMA_RBDCB_SIZE_POS)
41162306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_512	(0x9 << RFH_RXF_DMA_RBDCB_SIZE_POS)
41262306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_1024	(0xA << RFH_RXF_DMA_RBDCB_SIZE_POS)
41362306a36Sopenharmony_ci#define RFH_RXF_DMA_RBDCB_SIZE_2048	(0xB << RFH_RXF_DMA_RBDCB_SIZE_POS)
41462306a36Sopenharmony_ci#define RFH_RXF_DMA_MIN_RB_SIZE_MASK	(0x03000000) /* bit 24-25 */
41562306a36Sopenharmony_ci#define RFH_RXF_DMA_MIN_RB_SIZE_POS	24
41662306a36Sopenharmony_ci#define RFH_RXF_DMA_MIN_RB_4_8		(3 << RFH_RXF_DMA_MIN_RB_SIZE_POS)
41762306a36Sopenharmony_ci#define RFH_RXF_DMA_DROP_TOO_LARGE_MASK	(0x04000000) /* bit 26 */
41862306a36Sopenharmony_ci#define RFH_RXF_DMA_SINGLE_FRAME_MASK	(0x20000000) /* bit 29 */
41962306a36Sopenharmony_ci#define RFH_DMA_EN_MASK			(0xC0000000) /* bits 30-31*/
42062306a36Sopenharmony_ci#define RFH_DMA_EN_ENABLE_VAL		BIT(31)
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci#define RFH_RXF_RXQ_ACTIVE 0xA0980C
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_ci#define RFH_GEN_CFG	0xA09800
42562306a36Sopenharmony_ci#define RFH_GEN_CFG_SERVICE_DMA_SNOOP	BIT(0)
42662306a36Sopenharmony_ci#define RFH_GEN_CFG_RFH_DMA_SNOOP	BIT(1)
42762306a36Sopenharmony_ci#define RFH_GEN_CFG_RB_CHUNK_SIZE	BIT(4)
42862306a36Sopenharmony_ci#define RFH_GEN_CFG_RB_CHUNK_SIZE_128	1
42962306a36Sopenharmony_ci#define RFH_GEN_CFG_RB_CHUNK_SIZE_64	0
43062306a36Sopenharmony_ci/* the driver assumes everywhere that the default RXQ is 0 */
43162306a36Sopenharmony_ci#define RFH_GEN_CFG_DEFAULT_RXQ_NUM	0xF00
43262306a36Sopenharmony_ci#define RFH_GEN_CFG_VAL(_n, _v)		FIELD_PREP(RFH_GEN_CFG_ ## _n, _v)
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci/* end of 9000 rx series registers */
43562306a36Sopenharmony_ci
43662306a36Sopenharmony_ci/* TFDB  Area - TFDs buffer table */
43762306a36Sopenharmony_ci#define FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK      (0xFFFFFFFF)
43862306a36Sopenharmony_ci#define FH_TFDIB_LOWER_BOUND       (FH_MEM_LOWER_BOUND + 0x900)
43962306a36Sopenharmony_ci#define FH_TFDIB_UPPER_BOUND       (FH_MEM_LOWER_BOUND + 0x958)
44062306a36Sopenharmony_ci#define FH_TFDIB_CTRL0_REG(_chnl)  (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl))
44162306a36Sopenharmony_ci#define FH_TFDIB_CTRL1_REG(_chnl)  (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl) + 0x4)
44262306a36Sopenharmony_ci
44362306a36Sopenharmony_ci/**
44462306a36Sopenharmony_ci * Transmit DMA Channel Control/Status Registers (TCSR)
44562306a36Sopenharmony_ci *
44662306a36Sopenharmony_ci * Device has one configuration register for each of 8 Tx DMA/FIFO channels
44762306a36Sopenharmony_ci * supported in hardware (don't confuse these with the 16 Tx queues in DRAM,
44862306a36Sopenharmony_ci * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.
44962306a36Sopenharmony_ci *
45062306a36Sopenharmony_ci * To use a Tx DMA channel, driver must initialize its
45162306a36Sopenharmony_ci * FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with:
45262306a36Sopenharmony_ci *
45362306a36Sopenharmony_ci * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
45462306a36Sopenharmony_ci * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL
45562306a36Sopenharmony_ci *
45662306a36Sopenharmony_ci * All other bits should be 0.
45762306a36Sopenharmony_ci *
45862306a36Sopenharmony_ci * Bit fields:
45962306a36Sopenharmony_ci * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,
46062306a36Sopenharmony_ci *        '10' operate normally
46162306a36Sopenharmony_ci * 29- 4: Reserved, set to "0"
46262306a36Sopenharmony_ci *     3: Enable internal DMA requests (1, normal operation), disable (0)
46362306a36Sopenharmony_ci *  2- 0: Reserved, set to "0"
46462306a36Sopenharmony_ci */
46562306a36Sopenharmony_ci#define FH_TCSR_LOWER_BOUND  (FH_MEM_LOWER_BOUND + 0xD00)
46662306a36Sopenharmony_ci#define FH_TCSR_UPPER_BOUND  (FH_MEM_LOWER_BOUND + 0xE60)
46762306a36Sopenharmony_ci
46862306a36Sopenharmony_ci/* Find Control/Status reg for given Tx DMA/FIFO channel */
46962306a36Sopenharmony_ci#define FH_TCSR_CHNL_NUM                            (8)
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci/* TCSR: tx_config register values */
47262306a36Sopenharmony_ci#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl)	\
47362306a36Sopenharmony_ci		(FH_TCSR_LOWER_BOUND + 0x20 * (_chnl))
47462306a36Sopenharmony_ci#define FH_TCSR_CHNL_TX_CREDIT_REG(_chnl)	\
47562306a36Sopenharmony_ci		(FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x4)
47662306a36Sopenharmony_ci#define FH_TCSR_CHNL_TX_BUF_STS_REG(_chnl)	\
47762306a36Sopenharmony_ci		(FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x8)
47862306a36Sopenharmony_ci
47962306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF		(0x00000000)
48062306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRV		(0x00000001)
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE	(0x00000000)
48362306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE	(0x00000008)
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT	(0x00000000)
48662306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD	(0x00100000)
48762306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD	(0x00200000)
48862306a36Sopenharmony_ci
48962306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT	(0x00000000)
49062306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_ENDTFD	(0x00400000)
49162306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_IFTFD	(0x00800000)
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE	(0x00000000)
49462306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF	(0x40000000)
49562306a36Sopenharmony_ci#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE	(0x80000000)
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_ci#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY	(0x00000000)
49862306a36Sopenharmony_ci#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT	(0x00002000)
49962306a36Sopenharmony_ci#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID	(0x00000003)
50062306a36Sopenharmony_ci
50162306a36Sopenharmony_ci#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM		(20)
50262306a36Sopenharmony_ci#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX		(12)
50362306a36Sopenharmony_ci
50462306a36Sopenharmony_ci/**
50562306a36Sopenharmony_ci * Tx Shared Status Registers (TSSR)
50662306a36Sopenharmony_ci *
50762306a36Sopenharmony_ci * After stopping Tx DMA channel (writing 0 to
50862306a36Sopenharmony_ci * FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll
50962306a36Sopenharmony_ci * FH_TSSR_TX_STATUS_REG until selected Tx channel is idle
51062306a36Sopenharmony_ci * (channel's buffers empty | no pending requests).
51162306a36Sopenharmony_ci *
51262306a36Sopenharmony_ci * Bit fields:
51362306a36Sopenharmony_ci * 31-24:  1 = Channel buffers empty (channel 7:0)
51462306a36Sopenharmony_ci * 23-16:  1 = No pending requests (channel 7:0)
51562306a36Sopenharmony_ci */
51662306a36Sopenharmony_ci#define FH_TSSR_LOWER_BOUND		(FH_MEM_LOWER_BOUND + 0xEA0)
51762306a36Sopenharmony_ci#define FH_TSSR_UPPER_BOUND		(FH_MEM_LOWER_BOUND + 0xEC0)
51862306a36Sopenharmony_ci
51962306a36Sopenharmony_ci#define FH_TSSR_TX_STATUS_REG		(FH_TSSR_LOWER_BOUND + 0x010)
52062306a36Sopenharmony_ci
52162306a36Sopenharmony_ci/**
52262306a36Sopenharmony_ci * Bit fields for TSSR(Tx Shared Status & Control) error status register:
52362306a36Sopenharmony_ci * 31:  Indicates an address error when accessed to internal memory
52462306a36Sopenharmony_ci *	uCode/driver must write "1" in order to clear this flag
52562306a36Sopenharmony_ci * 30:  Indicates that Host did not send the expected number of dwords to FH
52662306a36Sopenharmony_ci *	uCode/driver must write "1" in order to clear this flag
52762306a36Sopenharmony_ci * 16-9:Each status bit is for one channel. Indicates that an (Error) ActDMA
52862306a36Sopenharmony_ci *	command was received from the scheduler while the TRB was already full
52962306a36Sopenharmony_ci *	with previous command
53062306a36Sopenharmony_ci *	uCode/driver must write "1" in order to clear this flag
53162306a36Sopenharmony_ci * 7-0: Each status bit indicates a channel's TxCredit error. When an error
53262306a36Sopenharmony_ci *	bit is set, it indicates that the FH has received a full indication
53362306a36Sopenharmony_ci *	from the RTC TxFIFO and the current value of the TxCredit counter was
53462306a36Sopenharmony_ci *	not equal to zero. This mean that the credit mechanism was not
53562306a36Sopenharmony_ci *	synchronized to the TxFIFO status
53662306a36Sopenharmony_ci *	uCode/driver must write "1" in order to clear this flag
53762306a36Sopenharmony_ci */
53862306a36Sopenharmony_ci#define FH_TSSR_TX_ERROR_REG		(FH_TSSR_LOWER_BOUND + 0x018)
53962306a36Sopenharmony_ci#define FH_TSSR_TX_MSG_CONFIG_REG	(FH_TSSR_LOWER_BOUND + 0x008)
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci#define FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) ((1 << (_chnl)) << 16)
54262306a36Sopenharmony_ci
54362306a36Sopenharmony_ci/* Tx service channels */
54462306a36Sopenharmony_ci#define FH_SRVC_CHNL		(9)
54562306a36Sopenharmony_ci#define FH_SRVC_LOWER_BOUND	(FH_MEM_LOWER_BOUND + 0x9C8)
54662306a36Sopenharmony_ci#define FH_SRVC_UPPER_BOUND	(FH_MEM_LOWER_BOUND + 0x9D0)
54762306a36Sopenharmony_ci#define FH_SRVC_CHNL_SRAM_ADDR_REG(_chnl) \
54862306a36Sopenharmony_ci		(FH_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4)
54962306a36Sopenharmony_ci
55062306a36Sopenharmony_ci#define FH_TX_CHICKEN_BITS_REG	(FH_MEM_LOWER_BOUND + 0xE98)
55162306a36Sopenharmony_ci#define FH_TX_TRB_REG(_chan)	(FH_MEM_LOWER_BOUND + 0x958 + (_chan) * 4)
55262306a36Sopenharmony_ci
55362306a36Sopenharmony_ci/* Instruct FH to increment the retry count of a packet when
55462306a36Sopenharmony_ci * it is brought from the memory to TX-FIFO
55562306a36Sopenharmony_ci */
55662306a36Sopenharmony_ci#define FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN	(0x00000002)
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci#define RX_POOL_SIZE(rbds)	((rbds) - 1 +	\
55962306a36Sopenharmony_ci				 IWL_MAX_RX_HW_QUEUES *	\
56062306a36Sopenharmony_ci				 (RX_CLAIM_REQ_ALLOC - RX_POST_REQ_ALLOC))
56162306a36Sopenharmony_ci/* cb size is the exponent */
56262306a36Sopenharmony_ci#define RX_QUEUE_CB_SIZE(x)	ilog2(x)
56362306a36Sopenharmony_ci
56462306a36Sopenharmony_ci#define RX_QUEUE_SIZE                         256
56562306a36Sopenharmony_ci#define RX_QUEUE_MASK                         255
56662306a36Sopenharmony_ci#define RX_QUEUE_SIZE_LOG                     8
56762306a36Sopenharmony_ci
56862306a36Sopenharmony_ci#define IWL_DEFAULT_RX_QUEUE			0
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_ci/**
57162306a36Sopenharmony_ci * struct iwl_rb_status - reserve buffer status
57262306a36Sopenharmony_ci * 	host memory mapped FH registers
57362306a36Sopenharmony_ci * @closed_rb_num [0:11] - Indicates the index of the RB which was closed
57462306a36Sopenharmony_ci * @closed_fr_num [0:11] - Indicates the index of the RX Frame which was closed
57562306a36Sopenharmony_ci * @finished_rb_num [0:11] - Indicates the index of the current RB
57662306a36Sopenharmony_ci * 	in which the last frame was written to
57762306a36Sopenharmony_ci * @finished_fr_num [0:11] - Indicates the index of the RX Frame
57862306a36Sopenharmony_ci * 	which was transferred
57962306a36Sopenharmony_ci */
58062306a36Sopenharmony_cistruct iwl_rb_status {
58162306a36Sopenharmony_ci	__le16 closed_rb_num;
58262306a36Sopenharmony_ci	__le16 closed_fr_num;
58362306a36Sopenharmony_ci	__le16 finished_rb_num;
58462306a36Sopenharmony_ci	__le16 finished_fr_nam;
58562306a36Sopenharmony_ci	__le32 __spare;
58662306a36Sopenharmony_ci} __packed;
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_ci
58962306a36Sopenharmony_ci#define TFD_QUEUE_SIZE_MAX      (256)
59062306a36Sopenharmony_ci#define TFD_QUEUE_SIZE_MAX_GEN3 (65536)
59162306a36Sopenharmony_ci/* cb size is the exponent - 3 */
59262306a36Sopenharmony_ci#define TFD_QUEUE_CB_SIZE(x)	(ilog2(x) - 3)
59362306a36Sopenharmony_ci#define TFD_QUEUE_SIZE_BC_DUP	(64)
59462306a36Sopenharmony_ci#define TFD_QUEUE_BC_SIZE	(TFD_QUEUE_SIZE_MAX + TFD_QUEUE_SIZE_BC_DUP)
59562306a36Sopenharmony_ci#define TFD_QUEUE_BC_SIZE_GEN3_AX210	1024
59662306a36Sopenharmony_ci#define TFD_QUEUE_BC_SIZE_GEN3_BZ	(1024 * 4)
59762306a36Sopenharmony_ci#define IWL_TX_DMA_MASK        DMA_BIT_MASK(36)
59862306a36Sopenharmony_ci#define IWL_NUM_OF_TBS		20
59962306a36Sopenharmony_ci#define IWL_TFH_NUM_TBS		25
60062306a36Sopenharmony_ci
60162306a36Sopenharmony_ci/* IMR DMA registers */
60262306a36Sopenharmony_ci#define IMR_TFH_SRV_DMA_CHNL0_CTRL           0x00a0a51c
60362306a36Sopenharmony_ci#define IMR_TFH_SRV_DMA_CHNL0_SRAM_ADDR      0x00a0a520
60462306a36Sopenharmony_ci#define IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_LSB  0x00a0a524
60562306a36Sopenharmony_ci#define IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_MSB  0x00a0a528
60662306a36Sopenharmony_ci#define IMR_TFH_SRV_DMA_CHNL0_BC             0x00a0a52c
60762306a36Sopenharmony_ci#define TFH_SRV_DMA_CHNL0_LEFT_BC	     0x00a0a530
60862306a36Sopenharmony_ci
60962306a36Sopenharmony_ci/* RFH S2D DMA registers */
61062306a36Sopenharmony_ci#define IMR_RFH_GEN_CFG_SERVICE_DMA_RS_MSK	0x0000000c
61162306a36Sopenharmony_ci#define IMR_RFH_GEN_CFG_SERVICE_DMA_SNOOP_MSK	0x00000002
61262306a36Sopenharmony_ci
61362306a36Sopenharmony_ci/* TFH D2S DMA registers */
61462306a36Sopenharmony_ci#define IMR_UREG_CHICK_HALT_UMAC_PERMANENTLY_MSK	0x80000000
61562306a36Sopenharmony_ci#define IMR_UREG_CHICK					0x00d05c00
61662306a36Sopenharmony_ci#define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_IRQ_TARGET_POS	0x00800000
61762306a36Sopenharmony_ci#define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_RS_MSK		0x00000030
61862306a36Sopenharmony_ci#define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_DMA_EN_POS	0x80000000
61962306a36Sopenharmony_ci
62062306a36Sopenharmony_cistatic inline u8 iwl_get_dma_hi_addr(dma_addr_t addr)
62162306a36Sopenharmony_ci{
62262306a36Sopenharmony_ci	return (sizeof(addr) > sizeof(u32) ? upper_32_bits(addr) : 0) & 0xF;
62362306a36Sopenharmony_ci}
62462306a36Sopenharmony_ci
62562306a36Sopenharmony_ci/**
62662306a36Sopenharmony_ci * enum iwl_tfd_tb_hi_n_len - TB hi_n_len bits
62762306a36Sopenharmony_ci * @TB_HI_N_LEN_ADDR_HI_MSK: high 4 bits (to make it 36) of DMA address
62862306a36Sopenharmony_ci * @TB_HI_N_LEN_LEN_MSK: length of the TB
62962306a36Sopenharmony_ci */
63062306a36Sopenharmony_cienum iwl_tfd_tb_hi_n_len {
63162306a36Sopenharmony_ci	TB_HI_N_LEN_ADDR_HI_MSK	= 0xf,
63262306a36Sopenharmony_ci	TB_HI_N_LEN_LEN_MSK	= 0xfff0,
63362306a36Sopenharmony_ci};
63462306a36Sopenharmony_ci
63562306a36Sopenharmony_ci/**
63662306a36Sopenharmony_ci * struct iwl_tfd_tb transmit buffer descriptor within transmit frame descriptor
63762306a36Sopenharmony_ci *
63862306a36Sopenharmony_ci * This structure contains dma address and length of transmission address
63962306a36Sopenharmony_ci *
64062306a36Sopenharmony_ci * @lo: low [31:0] portion of the dma address of TX buffer
64162306a36Sopenharmony_ci * 	every even is unaligned on 16 bit boundary
64262306a36Sopenharmony_ci * @hi_n_len: &enum iwl_tfd_tb_hi_n_len
64362306a36Sopenharmony_ci */
64462306a36Sopenharmony_cistruct iwl_tfd_tb {
64562306a36Sopenharmony_ci	__le32 lo;
64662306a36Sopenharmony_ci	__le16 hi_n_len;
64762306a36Sopenharmony_ci} __packed;
64862306a36Sopenharmony_ci
64962306a36Sopenharmony_ci/**
65062306a36Sopenharmony_ci * struct iwl_tfh_tb transmit buffer descriptor within transmit frame descriptor
65162306a36Sopenharmony_ci *
65262306a36Sopenharmony_ci * This structure contains dma address and length of transmission address
65362306a36Sopenharmony_ci *
65462306a36Sopenharmony_ci * @tb_len length of the tx buffer
65562306a36Sopenharmony_ci * @addr 64 bits dma address
65662306a36Sopenharmony_ci */
65762306a36Sopenharmony_cistruct iwl_tfh_tb {
65862306a36Sopenharmony_ci	__le16 tb_len;
65962306a36Sopenharmony_ci	__le64 addr;
66062306a36Sopenharmony_ci} __packed;
66162306a36Sopenharmony_ci
66262306a36Sopenharmony_ci/**
66362306a36Sopenharmony_ci * Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM.
66462306a36Sopenharmony_ci * Both driver and device share these circular buffers, each of which must be
66562306a36Sopenharmony_ci * contiguous 256 TFDs.
66662306a36Sopenharmony_ci * For pre 22000 HW it is 256 x 128 bytes-per-TFD = 32 KBytes
66762306a36Sopenharmony_ci * For 22000 HW and on it is 256 x 256 bytes-per-TFD = 65 KBytes
66862306a36Sopenharmony_ci *
66962306a36Sopenharmony_ci * Driver must indicate the physical address of the base of each
67062306a36Sopenharmony_ci * circular buffer via the FH_MEM_CBBC_QUEUE registers.
67162306a36Sopenharmony_ci *
67262306a36Sopenharmony_ci * Each TFD contains pointer/size information for up to 20 / 25 data buffers
67362306a36Sopenharmony_ci * in host DRAM.  These buffers collectively contain the (one) frame described
67462306a36Sopenharmony_ci * by the TFD.  Each buffer must be a single contiguous block of memory within
67562306a36Sopenharmony_ci * itself, but buffers may be scattered in host DRAM.  Each buffer has max size
67662306a36Sopenharmony_ci * of (4K - 4).  The concatenates all of a TFD's buffers into a single
67762306a36Sopenharmony_ci * Tx frame, up to 8 KBytes in size.
67862306a36Sopenharmony_ci *
67962306a36Sopenharmony_ci * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.
68062306a36Sopenharmony_ci */
68162306a36Sopenharmony_ci
68262306a36Sopenharmony_ci/**
68362306a36Sopenharmony_ci * struct iwl_tfd - Transmit Frame Descriptor (TFD)
68462306a36Sopenharmony_ci * @ __reserved1[3] reserved
68562306a36Sopenharmony_ci * @ num_tbs 0-4 number of active tbs
68662306a36Sopenharmony_ci *	     5   reserved
68762306a36Sopenharmony_ci *	     6-7 padding (not used)
68862306a36Sopenharmony_ci * @ tbs[20]	transmit frame buffer descriptors
68962306a36Sopenharmony_ci * @ __pad	padding
69062306a36Sopenharmony_ci */
69162306a36Sopenharmony_cistruct iwl_tfd {
69262306a36Sopenharmony_ci	u8 __reserved1[3];
69362306a36Sopenharmony_ci	u8 num_tbs;
69462306a36Sopenharmony_ci	struct iwl_tfd_tb tbs[IWL_NUM_OF_TBS];
69562306a36Sopenharmony_ci	__le32 __pad;
69662306a36Sopenharmony_ci} __packed;
69762306a36Sopenharmony_ci
69862306a36Sopenharmony_ci/**
69962306a36Sopenharmony_ci * struct iwl_tfh_tfd - Transmit Frame Descriptor (TFD)
70062306a36Sopenharmony_ci * @ num_tbs 0-4 number of active tbs
70162306a36Sopenharmony_ci *	     5 -15   reserved
70262306a36Sopenharmony_ci * @ tbs[25]	transmit frame buffer descriptors
70362306a36Sopenharmony_ci * @ __pad	padding
70462306a36Sopenharmony_ci */
70562306a36Sopenharmony_cistruct iwl_tfh_tfd {
70662306a36Sopenharmony_ci	__le16 num_tbs;
70762306a36Sopenharmony_ci	struct iwl_tfh_tb tbs[IWL_TFH_NUM_TBS];
70862306a36Sopenharmony_ci	__le32 __pad;
70962306a36Sopenharmony_ci} __packed;
71062306a36Sopenharmony_ci
71162306a36Sopenharmony_ci/* Keep Warm Size */
71262306a36Sopenharmony_ci#define IWL_KW_SIZE 0x1000	/* 4k */
71362306a36Sopenharmony_ci
71462306a36Sopenharmony_ci/* Fixed (non-configurable) rx data from phy */
71562306a36Sopenharmony_ci
71662306a36Sopenharmony_ci/**
71762306a36Sopenharmony_ci * struct iwlagn_schedq_bc_tbl scheduler byte count table
71862306a36Sopenharmony_ci *	base physical address provided by SCD_DRAM_BASE_ADDR
71962306a36Sopenharmony_ci * For devices up to 22000:
72062306a36Sopenharmony_ci * @tfd_offset  0-12 - tx command byte count
72162306a36Sopenharmony_ci *		12-16 - station index
72262306a36Sopenharmony_ci * For 22000:
72362306a36Sopenharmony_ci * @tfd_offset  0-12 - tx command byte count
72462306a36Sopenharmony_ci *		12-13 - number of 64 byte chunks
72562306a36Sopenharmony_ci *		14-16 - reserved
72662306a36Sopenharmony_ci */
72762306a36Sopenharmony_cistruct iwlagn_scd_bc_tbl {
72862306a36Sopenharmony_ci	__le16 tfd_offset[TFD_QUEUE_BC_SIZE];
72962306a36Sopenharmony_ci} __packed;
73062306a36Sopenharmony_ci
73162306a36Sopenharmony_ci/**
73262306a36Sopenharmony_ci * struct iwl_gen3_bc_tbl_entry scheduler byte count table entry gen3
73362306a36Sopenharmony_ci * For AX210 and on:
73462306a36Sopenharmony_ci * @tfd_offset: 0-12 - tx command byte count
73562306a36Sopenharmony_ci *		12-13 - number of 64 byte chunks
73662306a36Sopenharmony_ci *		14-16 - reserved
73762306a36Sopenharmony_ci */
73862306a36Sopenharmony_cistruct iwl_gen3_bc_tbl_entry {
73962306a36Sopenharmony_ci	__le16 tfd_offset;
74062306a36Sopenharmony_ci} __packed;
74162306a36Sopenharmony_ci
74262306a36Sopenharmony_ci#endif /* !__iwl_fh_h__ */
743