Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
0002 /*
0003  * Copyright (C) 2005-2014, 2018-2021 Intel Corporation
0004  * Copyright (C) 2015-2017 Intel Deutschland GmbH
0005  */
0006 #ifndef __iwl_fh_h__
0007 #define __iwl_fh_h__
0008 
0009 #include <linux/types.h>
0010 #include <linux/bitfield.h>
0011 
0012 #include "iwl-trans.h"
0013 
0014 /****************************/
0015 /* Flow Handler Definitions */
0016 /****************************/
0017 
0018 /**
0019  * This I/O area is directly read/writable by driver (e.g. Linux uses writel())
0020  * Addresses are offsets from device's PCI hardware base address.
0021  */
0022 #define FH_MEM_LOWER_BOUND                   (0x1000)
0023 #define FH_MEM_UPPER_BOUND                   (0x2000)
0024 #define FH_MEM_LOWER_BOUND_GEN2              (0xa06000)
0025 #define FH_MEM_UPPER_BOUND_GEN2              (0xa08000)
0026 
0027 /**
0028  * Keep-Warm (KW) buffer base address.
0029  *
0030  * Driver must allocate a 4KByte buffer that is for keeping the
0031  * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency
0032  * DRAM access when doing Txing or Rxing.  The dummy accesses prevent host
0033  * from going into a power-savings mode that would cause higher DRAM latency,
0034  * and possible data over/under-runs, before all Tx/Rx is complete.
0035  *
0036  * Driver loads FH_KW_MEM_ADDR_REG with the physical address (bits 35:4)
0037  * of the buffer, which must be 4K aligned.  Once this is set up, the device
0038  * automatically invokes keep-warm accesses when normal accesses might not
0039  * be sufficient to maintain fast DRAM response.
0040  *
0041  * Bit fields:
0042  *  31-0:  Keep-warm buffer physical base address [35:4], must be 4K aligned
0043  */
0044 #define FH_KW_MEM_ADDR_REG           (FH_MEM_LOWER_BOUND + 0x97C)
0045 
0046 
0047 /**
0048  * TFD Circular Buffers Base (CBBC) addresses
0049  *
0050  * Device has 16 base pointer registers, one for each of 16 host-DRAM-resident
0051  * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)
0052  * (see struct iwl_tfd_frame).  These 16 pointer registers are offset by 0x04
0053  * bytes from one another.  Each TFD circular buffer in DRAM must be 256-byte
0054  * aligned (address bits 0-7 must be 0).
0055  * Later devices have 20 (5000 series) or 30 (higher) queues, but the registers
0056  * for them are in different places.
0057  *
0058  * Bit fields in each pointer register:
0059  *  27-0: TFD CB physical base address [35:8], must be 256-byte aligned
0060  */
0061 #define FH_MEM_CBBC_0_15_LOWER_BOUND        (FH_MEM_LOWER_BOUND + 0x9D0)
0062 #define FH_MEM_CBBC_0_15_UPPER_BOUND        (FH_MEM_LOWER_BOUND + 0xA10)
0063 #define FH_MEM_CBBC_16_19_LOWER_BOUND       (FH_MEM_LOWER_BOUND + 0xBF0)
0064 #define FH_MEM_CBBC_16_19_UPPER_BOUND       (FH_MEM_LOWER_BOUND + 0xC00)
0065 #define FH_MEM_CBBC_20_31_LOWER_BOUND       (FH_MEM_LOWER_BOUND + 0xB20)
0066 #define FH_MEM_CBBC_20_31_UPPER_BOUND       (FH_MEM_LOWER_BOUND + 0xB80)
0067 /* 22000 TFD table address, 64 bit */
0068 #define TFH_TFDQ_CBB_TABLE          (0x1C00)
0069 
0070 /* Find TFD CB base pointer for given queue */
0071 static inline unsigned int FH_MEM_CBBC_QUEUE(struct iwl_trans *trans,
0072                          unsigned int chnl)
0073 {
0074     if (trans->trans_cfg->use_tfh) {
0075         WARN_ON_ONCE(chnl >= 64);
0076         return TFH_TFDQ_CBB_TABLE + 8 * chnl;
0077     }
0078     if (chnl < 16)
0079         return FH_MEM_CBBC_0_15_LOWER_BOUND + 4 * chnl;
0080     if (chnl < 20)
0081         return FH_MEM_CBBC_16_19_LOWER_BOUND + 4 * (chnl - 16);
0082     WARN_ON_ONCE(chnl >= 32);
0083     return FH_MEM_CBBC_20_31_LOWER_BOUND + 4 * (chnl - 20);
0084 }
0085 
0086 /* 22000 configuration registers */
0087 
0088 /*
0089  * TFH Configuration register.
0090  *
0091  * BIT fields:
0092  *
0093  * Bits 3:0:
0094  * Define the maximum number of pending read requests.
0095  * Maximum configuration value allowed is 0xC
0096  * Bits 9:8:
0097  * Define the maximum transfer size. (64 / 128 / 256)
0098  * Bit 10:
0099  * When bit is set and transfer size is set to 128B, the TFH will enable
0100  * reading chunks of more than 64B only if the read address is aligned to 128B.
0101  * In case of DRAM read address which is not aligned to 128B, the TFH will
0102  * enable transfer size which doesn't cross 64B DRAM address boundary.
0103 */
0104 #define TFH_TRANSFER_MODE       (0x1F40)
0105 #define TFH_TRANSFER_MAX_PENDING_REQ    0xc
0106 #define TFH_CHUNK_SIZE_128          BIT(8)
0107 #define TFH_CHUNK_SPLIT_MODE        BIT(10)
0108 /*
0109  * Defines the offset address in dwords referring from the beginning of the
0110  * Tx CMD which will be updated in DRAM.
0111  * Note that the TFH offset address for Tx CMD update is always referring to
0112  * the start of the TFD first TB.
0113  * In case of a DRAM Tx CMD update the TFH will update PN and Key ID
0114  */
0115 #define TFH_TXCMD_UPDATE_CFG        (0x1F48)
0116 /*
0117  * Controls TX DMA operation
0118  *
0119  * BIT fields:
0120  *
0121  * Bits 31:30: Enable the SRAM DMA channel.
0122  * Turning on bit 31 will kick the SRAM2DRAM DMA.
0123  * Note that the sram2dram may be enabled only after configuring the DRAM and
0124  * SRAM addresses registers and the byte count register.
0125  * Bits 25:24: Defines the interrupt target upon dram2sram transfer done. When
0126  * set to 1 - interrupt is sent to the driver
0127  * Bit 0: Indicates the snoop configuration
0128 */
0129 #define TFH_SRV_DMA_CHNL0_CTRL  (0x1F60)
0130 #define TFH_SRV_DMA_SNOOP   BIT(0)
0131 #define TFH_SRV_DMA_TO_DRIVER   BIT(24)
0132 #define TFH_SRV_DMA_START   BIT(31)
0133 
0134 /* Defines the DMA SRAM write start address to transfer a data block */
0135 #define TFH_SRV_DMA_CHNL0_SRAM_ADDR (0x1F64)
0136 
0137 /* Defines the 64bits DRAM start address to read the DMA data block from */
0138 #define TFH_SRV_DMA_CHNL0_DRAM_ADDR (0x1F68)
0139 
0140 /*
0141  * Defines the number of bytes to transfer from DRAM to SRAM.
0142  * Note that this register may be configured with non-dword aligned size.
0143  */
0144 #define TFH_SRV_DMA_CHNL0_BC    (0x1F70)
0145 
0146 /**
0147  * Rx SRAM Control and Status Registers (RSCSR)
0148  *
0149  * These registers provide handshake between driver and device for the Rx queue
0150  * (this queue handles *all* command responses, notifications, Rx data, etc.
0151  * sent from uCode to host driver).  Unlike Tx, there is only one Rx
0152  * queue, and only one Rx DMA/FIFO channel.  Also unlike Tx, which can
0153  * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer
0154  * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1
0155  * mapping between RBDs and RBs.
0156  *
0157  * Driver must allocate host DRAM memory for the following, and set the
0158  * physical address of each into device registers:
0159  *
0160  * 1)  Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256
0161  *     entries (although any power of 2, up to 4096, is selectable by driver).
0162  *     Each entry (1 dword) points to a receive buffer (RB) of consistent size
0163  *     (typically 4K, although 8K or 16K are also selectable by driver).
0164  *     Driver sets up RB size and number of RBDs in the CB via Rx config
0165  *     register FH_MEM_RCSR_CHNL0_CONFIG_REG.
0166  *
0167  *     Bit fields within one RBD:
0168  *     27-0:  Receive Buffer physical address bits [35:8], 256-byte aligned
0169  *
0170  *     Driver sets physical address [35:8] of base of RBD circular buffer
0171  *     into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].
0172  *
0173  * 2)  Rx status buffer, 8 bytes, in which uCode indicates which Rx Buffers
0174  *     (RBs) have been filled, via a "write pointer", actually the index of
0175  *     the RB's corresponding RBD within the circular buffer.  Driver sets
0176  *     physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0].
0177  *
0178  *     Bit fields in lower dword of Rx status buffer (upper dword not used
0179  *     by driver:
0180  *     31-12:  Not used by driver
0181  *     11- 0:  Index of last filled Rx buffer descriptor
0182  *             (device writes, driver reads this value)
0183  *
0184  * As the driver prepares Receive Buffers (RBs) for device to fill, driver must
0185  * enter pointers to these RBs into contiguous RBD circular buffer entries,
0186  * and update the device's "write" index register,
0187  * FH_RSCSR_CHNL0_RBDCB_WPTR_REG.
0188  *
0189  * This "write" index corresponds to the *next* RBD that the driver will make
0190  * available, i.e. one RBD past the tail of the ready-to-fill RBDs within
0191  * the circular buffer.  This value should initially be 0 (before preparing any
0192  * RBs), should be 8 after preparing the first 8 RBs (for example), and must
0193  * wrap back to 0 at the end of the circular buffer (but don't wrap before
0194  * "read" index has advanced past 1!  See below).
0195  * NOTE:  DEVICE EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8.
0196  *
0197  * As the device fills RBs (referenced from contiguous RBDs within the circular
0198  * buffer), it updates the Rx status buffer in host DRAM, 2) described above,
0199  * to tell the driver the index of the latest filled RBD.  The driver must
0200  * read this "read" index from DRAM after receiving an Rx interrupt from device
0201  *
0202  * The driver must also internally keep track of a third index, which is the
0203  * next RBD to process.  When receiving an Rx interrupt, driver should process
0204  * all filled but unprocessed RBs up to, but not including, the RB
0205  * corresponding to the "read" index.  For example, if "read" index becomes "1",
0206  * driver may process the RB pointed to by RBD 0.  Depending on volume of
0207  * traffic, there may be many RBs to process.
0208  *
0209  * If read index == write index, device thinks there is no room to put new data.
0210  * Due to this, the maximum number of filled RBs is 255, instead of 256.  To
0211  * be safe, make sure that there is a gap of at least 2 RBDs between "write"
0212  * and "read" indexes; that is, make sure that there are no more than 254
0213  * buffers waiting to be filled.
0214  */
0215 #define FH_MEM_RSCSR_LOWER_BOUND    (FH_MEM_LOWER_BOUND + 0xBC0)
0216 #define FH_MEM_RSCSR_UPPER_BOUND    (FH_MEM_LOWER_BOUND + 0xC00)
0217 #define FH_MEM_RSCSR_CHNL0      (FH_MEM_RSCSR_LOWER_BOUND)
0218 
0219 /**
0220  * Physical base address of 8-byte Rx Status buffer.
0221  * Bit fields:
0222  *  31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.
0223  */
0224 #define FH_RSCSR_CHNL0_STTS_WPTR_REG    (FH_MEM_RSCSR_CHNL0)
0225 
0226 /**
0227  * Physical base address of Rx Buffer Descriptor Circular Buffer.
0228  * Bit fields:
0229  *  27-0:  RBD CD physical base address [35:8], must be 256-byte aligned.
0230  */
0231 #define FH_RSCSR_CHNL0_RBDCB_BASE_REG   (FH_MEM_RSCSR_CHNL0 + 0x004)
0232 
0233 /**
0234  * Rx write pointer (index, really!).
0235  * Bit fields:
0236  *  11-0:  Index of driver's most recent prepared-to-be-filled RBD, + 1.
0237  *         NOTE:  For 256-entry circular buffer, use only bits [7:0].
0238  */
0239 #define FH_RSCSR_CHNL0_RBDCB_WPTR_REG   (FH_MEM_RSCSR_CHNL0 + 0x008)
0240 #define FH_RSCSR_CHNL0_WPTR        (FH_RSCSR_CHNL0_RBDCB_WPTR_REG)
0241 
0242 #define FW_RSCSR_CHNL0_RXDCB_RDPTR_REG  (FH_MEM_RSCSR_CHNL0 + 0x00c)
0243 #define FH_RSCSR_CHNL0_RDPTR        FW_RSCSR_CHNL0_RXDCB_RDPTR_REG
0244 
0245 /**
0246  * Rx Config/Status Registers (RCSR)
0247  * Rx Config Reg for channel 0 (only channel used)
0248  *
0249  * Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for
0250  * normal operation (see bit fields).
0251  *
0252  * Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.
0253  * Driver should poll FH_MEM_RSSR_RX_STATUS_REG for
0254  * FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.
0255  *
0256  * Bit fields:
0257  * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,
0258  *        '10' operate normally
0259  * 29-24: reserved
0260  * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),
0261  *        min "5" for 32 RBDs, max "12" for 4096 RBDs.
0262  * 19-18: reserved
0263  * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,
0264  *        '10' 12K, '11' 16K.
0265  * 15-14: reserved
0266  * 13-12: IRQ destination; '00' none, '01' host driver (normal operation)
0267  * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)
0268  *        typical value 0x10 (about 1/2 msec)
0269  *  3- 0: reserved
0270  */
0271 #define FH_MEM_RCSR_LOWER_BOUND      (FH_MEM_LOWER_BOUND + 0xC00)
0272 #define FH_MEM_RCSR_UPPER_BOUND      (FH_MEM_LOWER_BOUND + 0xCC0)
0273 #define FH_MEM_RCSR_CHNL0            (FH_MEM_RCSR_LOWER_BOUND)
0274 
0275 #define FH_MEM_RCSR_CHNL0_CONFIG_REG    (FH_MEM_RCSR_CHNL0)
0276 #define FH_MEM_RCSR_CHNL0_RBDCB_WPTR    (FH_MEM_RCSR_CHNL0 + 0x8)
0277 #define FH_MEM_RCSR_CHNL0_FLUSH_RB_REQ  (FH_MEM_RCSR_CHNL0 + 0x10)
0278 
0279 #define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MSK (0x00000FF0) /* bits 4-11 */
0280 #define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MSK   (0x00001000) /* bits 12 */
0281 #define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK (0x00008000) /* bit 15 */
0282 #define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MSK   (0x00030000) /* bits 16-17 */
0283 #define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MSK (0x00F00000) /* bits 20-23 */
0284 #define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MSK (0xC0000000) /* bits 30-31*/
0285 
0286 #define FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS    (20)
0287 #define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS  (4)
0288 #define RX_RB_TIMEOUT   (0x11)
0289 
0290 #define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL         (0x00000000)
0291 #define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL     (0x40000000)
0292 #define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL        (0x80000000)
0293 
0294 #define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K    (0x00000000)
0295 #define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K    (0x00010000)
0296 #define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K   (0x00020000)
0297 #define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K   (0x00030000)
0298 
0299 #define FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY              (0x00000004)
0300 #define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL    (0x00000000)
0301 #define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL  (0x00001000)
0302 
0303 /**
0304  * Rx Shared Status Registers (RSSR)
0305  *
0306  * After stopping Rx DMA channel (writing 0 to
0307  * FH_MEM_RCSR_CHNL0_CONFIG_REG), driver must poll
0308  * FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.
0309  *
0310  * Bit fields:
0311  *  24:  1 = Channel 0 is idle
0312  *
0313  * FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV
0314  * contain default values that should not be altered by the driver.
0315  */
0316 #define FH_MEM_RSSR_LOWER_BOUND           (FH_MEM_LOWER_BOUND + 0xC40)
0317 #define FH_MEM_RSSR_UPPER_BOUND           (FH_MEM_LOWER_BOUND + 0xD00)
0318 
0319 #define FH_MEM_RSSR_SHARED_CTRL_REG       (FH_MEM_RSSR_LOWER_BOUND)
0320 #define FH_MEM_RSSR_RX_STATUS_REG   (FH_MEM_RSSR_LOWER_BOUND + 0x004)
0321 #define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV\
0322                     (FH_MEM_RSSR_LOWER_BOUND + 0x008)
0323 
0324 #define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE   (0x01000000)
0325 
0326 #define FH_MEM_TFDIB_REG1_ADDR_BITSHIFT 28
0327 #define FH_MEM_TB_MAX_LENGTH            (0x00020000)
0328 
0329 /* 9000 rx series registers */
0330 
0331 #define RFH_Q0_FRBDCB_BA_LSB 0xA08000 /* 64 bit address */
0332 #define RFH_Q_FRBDCB_BA_LSB(q) (RFH_Q0_FRBDCB_BA_LSB + (q) * 8)
0333 /* Write index table */
0334 #define RFH_Q0_FRBDCB_WIDX 0xA08080
0335 #define RFH_Q_FRBDCB_WIDX(q) (RFH_Q0_FRBDCB_WIDX + (q) * 4)
0336 /* Write index table - shadow registers */
0337 #define RFH_Q0_FRBDCB_WIDX_TRG 0x1C80
0338 #define RFH_Q_FRBDCB_WIDX_TRG(q) (RFH_Q0_FRBDCB_WIDX_TRG + (q) * 4)
0339 /* Read index table */
0340 #define RFH_Q0_FRBDCB_RIDX 0xA080C0
0341 #define RFH_Q_FRBDCB_RIDX(q) (RFH_Q0_FRBDCB_RIDX + (q) * 4)
0342 /* Used list table */
0343 #define RFH_Q0_URBDCB_BA_LSB 0xA08100 /* 64 bit address */
0344 #define RFH_Q_URBDCB_BA_LSB(q) (RFH_Q0_URBDCB_BA_LSB + (q) * 8)
0345 /* Write index table */
0346 #define RFH_Q0_URBDCB_WIDX 0xA08180
0347 #define RFH_Q_URBDCB_WIDX(q) (RFH_Q0_URBDCB_WIDX + (q) * 4)
0348 #define RFH_Q0_URBDCB_VAID 0xA081C0
0349 #define RFH_Q_URBDCB_VAID(q) (RFH_Q0_URBDCB_VAID + (q) * 4)
0350 /* stts */
0351 #define RFH_Q0_URBD_STTS_WPTR_LSB 0xA08200 /*64 bits address */
0352 #define RFH_Q_URBD_STTS_WPTR_LSB(q) (RFH_Q0_URBD_STTS_WPTR_LSB + (q) * 8)
0353 
0354 #define RFH_Q0_ORB_WPTR_LSB 0xA08280
0355 #define RFH_Q_ORB_WPTR_LSB(q) (RFH_Q0_ORB_WPTR_LSB + (q) * 8)
0356 #define RFH_RBDBUF_RBD0_LSB 0xA08300
0357 #define RFH_RBDBUF_RBD_LSB(q) (RFH_RBDBUF_RBD0_LSB + (q) * 8)
0358 
0359 /**
0360  * RFH Status Register
0361  *
0362  * Bit fields:
0363  *
0364  * Bit 29: RBD_FETCH_IDLE
0365  * This status flag is set by the RFH when there is no active RBD fetch from
0366  * DRAM.
0367  * Once the RFH RBD controller starts fetching (or when there is a pending
0368  * RBD read response from DRAM), this flag is immediately turned off.
0369  *
0370  * Bit 30: SRAM_DMA_IDLE
0371  * This status flag is set by the RFH when there is no active transaction from
0372  * SRAM to DRAM.
0373  * Once the SRAM to DRAM DMA is active, this flag is immediately turned off.
0374  *
0375  * Bit 31: RXF_DMA_IDLE
0376  * This status flag is set by the RFH when there is no active transaction from
0377  * RXF to DRAM.
0378  * Once the RXF-to-DRAM DMA is active, this flag is immediately turned off.
0379  */
0380 #define RFH_GEN_STATUS      0xA09808
0381 #define RFH_GEN_STATUS_GEN3 0xA07824
0382 #define RBD_FETCH_IDLE  BIT(29)
0383 #define SRAM_DMA_IDLE   BIT(30)
0384 #define RXF_DMA_IDLE    BIT(31)
0385 
0386 /* DMA configuration */
0387 #define RFH_RXF_DMA_CFG     0xA09820
0388 #define RFH_RXF_DMA_CFG_GEN3    0xA07880
0389 /* RB size */
0390 #define RFH_RXF_DMA_RB_SIZE_MASK (0x000F0000) /* bits 16-19 */
0391 #define RFH_RXF_DMA_RB_SIZE_POS 16
0392 #define RFH_RXF_DMA_RB_SIZE_1K  (0x1 << RFH_RXF_DMA_RB_SIZE_POS)
0393 #define RFH_RXF_DMA_RB_SIZE_2K  (0x2 << RFH_RXF_DMA_RB_SIZE_POS)
0394 #define RFH_RXF_DMA_RB_SIZE_4K  (0x4 << RFH_RXF_DMA_RB_SIZE_POS)
0395 #define RFH_RXF_DMA_RB_SIZE_8K  (0x8 << RFH_RXF_DMA_RB_SIZE_POS)
0396 #define RFH_RXF_DMA_RB_SIZE_12K (0x9 << RFH_RXF_DMA_RB_SIZE_POS)
0397 #define RFH_RXF_DMA_RB_SIZE_16K (0xA << RFH_RXF_DMA_RB_SIZE_POS)
0398 #define RFH_RXF_DMA_RB_SIZE_20K (0xB << RFH_RXF_DMA_RB_SIZE_POS)
0399 #define RFH_RXF_DMA_RB_SIZE_24K (0xC << RFH_RXF_DMA_RB_SIZE_POS)
0400 #define RFH_RXF_DMA_RB_SIZE_28K (0xD << RFH_RXF_DMA_RB_SIZE_POS)
0401 #define RFH_RXF_DMA_RB_SIZE_32K (0xE << RFH_RXF_DMA_RB_SIZE_POS)
0402 /* RB Circular Buffer size:defines the table sizes in RBD units */
0403 #define RFH_RXF_DMA_RBDCB_SIZE_MASK (0x00F00000) /* bits 20-23 */
0404 #define RFH_RXF_DMA_RBDCB_SIZE_POS 20
0405 #define RFH_RXF_DMA_RBDCB_SIZE_8    (0x3 << RFH_RXF_DMA_RBDCB_SIZE_POS)
0406 #define RFH_RXF_DMA_RBDCB_SIZE_16   (0x4 << RFH_RXF_DMA_RBDCB_SIZE_POS)
0407 #define RFH_RXF_DMA_RBDCB_SIZE_32   (0x5 << RFH_RXF_DMA_RBDCB_SIZE_POS)
0408 #define RFH_RXF_DMA_RBDCB_SIZE_64   (0x7 << RFH_RXF_DMA_RBDCB_SIZE_POS)
0409 #define RFH_RXF_DMA_RBDCB_SIZE_128  (0x7 << RFH_RXF_DMA_RBDCB_SIZE_POS)
0410 #define RFH_RXF_DMA_RBDCB_SIZE_256  (0x8 << RFH_RXF_DMA_RBDCB_SIZE_POS)
0411 #define RFH_RXF_DMA_RBDCB_SIZE_512  (0x9 << RFH_RXF_DMA_RBDCB_SIZE_POS)
0412 #define RFH_RXF_DMA_RBDCB_SIZE_1024 (0xA << RFH_RXF_DMA_RBDCB_SIZE_POS)
0413 #define RFH_RXF_DMA_RBDCB_SIZE_2048 (0xB << RFH_RXF_DMA_RBDCB_SIZE_POS)
0414 #define RFH_RXF_DMA_MIN_RB_SIZE_MASK    (0x03000000) /* bit 24-25 */
0415 #define RFH_RXF_DMA_MIN_RB_SIZE_POS 24
0416 #define RFH_RXF_DMA_MIN_RB_4_8      (3 << RFH_RXF_DMA_MIN_RB_SIZE_POS)
0417 #define RFH_RXF_DMA_DROP_TOO_LARGE_MASK (0x04000000) /* bit 26 */
0418 #define RFH_RXF_DMA_SINGLE_FRAME_MASK   (0x20000000) /* bit 29 */
0419 #define RFH_DMA_EN_MASK         (0xC0000000) /* bits 30-31*/
0420 #define RFH_DMA_EN_ENABLE_VAL       BIT(31)
0421 
0422 #define RFH_RXF_RXQ_ACTIVE 0xA0980C
0423 
0424 #define RFH_GEN_CFG 0xA09800
0425 #define RFH_GEN_CFG_SERVICE_DMA_SNOOP   BIT(0)
0426 #define RFH_GEN_CFG_RFH_DMA_SNOOP   BIT(1)
0427 #define RFH_GEN_CFG_RB_CHUNK_SIZE   BIT(4)
0428 #define RFH_GEN_CFG_RB_CHUNK_SIZE_128   1
0429 #define RFH_GEN_CFG_RB_CHUNK_SIZE_64    0
0430 /* the driver assumes everywhere that the default RXQ is 0 */
0431 #define RFH_GEN_CFG_DEFAULT_RXQ_NUM 0xF00
0432 #define RFH_GEN_CFG_VAL(_n, _v)     FIELD_PREP(RFH_GEN_CFG_ ## _n, _v)
0433 
0434 /* end of 9000 rx series registers */
0435 
0436 /* TFDB  Area - TFDs buffer table */
0437 #define FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK      (0xFFFFFFFF)
0438 #define FH_TFDIB_LOWER_BOUND       (FH_MEM_LOWER_BOUND + 0x900)
0439 #define FH_TFDIB_UPPER_BOUND       (FH_MEM_LOWER_BOUND + 0x958)
0440 #define FH_TFDIB_CTRL0_REG(_chnl)  (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl))
0441 #define FH_TFDIB_CTRL1_REG(_chnl)  (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl) + 0x4)
0442 
0443 /**
0444  * Transmit DMA Channel Control/Status Registers (TCSR)
0445  *
0446  * Device has one configuration register for each of 8 Tx DMA/FIFO channels
0447  * supported in hardware (don't confuse these with the 16 Tx queues in DRAM,
0448  * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.
0449  *
0450  * To use a Tx DMA channel, driver must initialize its
0451  * FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with:
0452  *
0453  * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
0454  * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL
0455  *
0456  * All other bits should be 0.
0457  *
0458  * Bit fields:
0459  * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,
0460  *        '10' operate normally
0461  * 29- 4: Reserved, set to "0"
0462  *     3: Enable internal DMA requests (1, normal operation), disable (0)
0463  *  2- 0: Reserved, set to "0"
0464  */
0465 #define FH_TCSR_LOWER_BOUND  (FH_MEM_LOWER_BOUND + 0xD00)
0466 #define FH_TCSR_UPPER_BOUND  (FH_MEM_LOWER_BOUND + 0xE60)
0467 
0468 /* Find Control/Status reg for given Tx DMA/FIFO channel */
0469 #define FH_TCSR_CHNL_NUM                            (8)
0470 
0471 /* TCSR: tx_config register values */
0472 #define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl)   \
0473         (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl))
0474 #define FH_TCSR_CHNL_TX_CREDIT_REG(_chnl)   \
0475         (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x4)
0476 #define FH_TCSR_CHNL_TX_BUF_STS_REG(_chnl)  \
0477         (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x8)
0478 
0479 #define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF      (0x00000000)
0480 #define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRV      (0x00000001)
0481 
0482 #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE    (0x00000000)
0483 #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE (0x00000008)
0484 
0485 #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT   (0x00000000)
0486 #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD  (0x00100000)
0487 #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD   (0x00200000)
0488 
0489 #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT    (0x00000000)
0490 #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_ENDTFD   (0x00400000)
0491 #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_IFTFD    (0x00800000)
0492 
0493 #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE    (0x00000000)
0494 #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF    (0x40000000)
0495 #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE   (0x80000000)
0496 
0497 #define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY  (0x00000000)
0498 #define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT   (0x00002000)
0499 #define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID  (0x00000003)
0500 
0501 #define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM      (20)
0502 #define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX      (12)
0503 
0504 /**
0505  * Tx Shared Status Registers (TSSR)
0506  *
0507  * After stopping Tx DMA channel (writing 0 to
0508  * FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll
0509  * FH_TSSR_TX_STATUS_REG until selected Tx channel is idle
0510  * (channel's buffers empty | no pending requests).
0511  *
0512  * Bit fields:
0513  * 31-24:  1 = Channel buffers empty (channel 7:0)
0514  * 23-16:  1 = No pending requests (channel 7:0)
0515  */
0516 #define FH_TSSR_LOWER_BOUND     (FH_MEM_LOWER_BOUND + 0xEA0)
0517 #define FH_TSSR_UPPER_BOUND     (FH_MEM_LOWER_BOUND + 0xEC0)
0518 
0519 #define FH_TSSR_TX_STATUS_REG       (FH_TSSR_LOWER_BOUND + 0x010)
0520 
0521 /**
0522  * Bit fields for TSSR(Tx Shared Status & Control) error status register:
0523  * 31:  Indicates an address error when accessed to internal memory
0524  *  uCode/driver must write "1" in order to clear this flag
0525  * 30:  Indicates that Host did not send the expected number of dwords to FH
0526  *  uCode/driver must write "1" in order to clear this flag
0527  * 16-9:Each status bit is for one channel. Indicates that an (Error) ActDMA
0528  *  command was received from the scheduler while the TRB was already full
0529  *  with previous command
0530  *  uCode/driver must write "1" in order to clear this flag
0531  * 7-0: Each status bit indicates a channel's TxCredit error. When an error
0532  *  bit is set, it indicates that the FH has received a full indication
0533  *  from the RTC TxFIFO and the current value of the TxCredit counter was
0534  *  not equal to zero. This mean that the credit mechanism was not
0535  *  synchronized to the TxFIFO status
0536  *  uCode/driver must write "1" in order to clear this flag
0537  */
0538 #define FH_TSSR_TX_ERROR_REG        (FH_TSSR_LOWER_BOUND + 0x018)
0539 #define FH_TSSR_TX_MSG_CONFIG_REG   (FH_TSSR_LOWER_BOUND + 0x008)
0540 
0541 #define FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) ((1 << (_chnl)) << 16)
0542 
0543 /* Tx service channels */
0544 #define FH_SRVC_CHNL        (9)
0545 #define FH_SRVC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9C8)
0546 #define FH_SRVC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)
0547 #define FH_SRVC_CHNL_SRAM_ADDR_REG(_chnl) \
0548         (FH_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4)
0549 
0550 #define FH_TX_CHICKEN_BITS_REG  (FH_MEM_LOWER_BOUND + 0xE98)
0551 #define FH_TX_TRB_REG(_chan)    (FH_MEM_LOWER_BOUND + 0x958 + (_chan) * 4)
0552 
0553 /* Instruct FH to increment the retry count of a packet when
0554  * it is brought from the memory to TX-FIFO
0555  */
0556 #define FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN    (0x00000002)
0557 
0558 #define RX_POOL_SIZE(rbds)  ((rbds) - 1 +   \
0559                  IWL_MAX_RX_HW_QUEUES * \
0560                  (RX_CLAIM_REQ_ALLOC - RX_POST_REQ_ALLOC))
0561 /* cb size is the exponent */
0562 #define RX_QUEUE_CB_SIZE(x) ilog2(x)
0563 
0564 #define RX_QUEUE_SIZE                         256
0565 #define RX_QUEUE_MASK                         255
0566 #define RX_QUEUE_SIZE_LOG                     8
0567 
0568 /**
0569  * struct iwl_rb_status - reserve buffer status
0570  *  host memory mapped FH registers
0571  * @closed_rb_num [0:11] - Indicates the index of the RB which was closed
0572  * @closed_fr_num [0:11] - Indicates the index of the RX Frame which was closed
0573  * @finished_rb_num [0:11] - Indicates the index of the current RB
0574  *  in which the last frame was written to
0575  * @finished_fr_num [0:11] - Indicates the index of the RX Frame
0576  *  which was transferred
0577  */
0578 struct iwl_rb_status {
0579     __le16 closed_rb_num;
0580     __le16 closed_fr_num;
0581     __le16 finished_rb_num;
0582     __le16 finished_fr_nam;
0583     __le32 __spare;
0584 } __packed;
0585 
0586 
0587 #define TFD_QUEUE_SIZE_MAX      (256)
0588 #define TFD_QUEUE_SIZE_MAX_GEN3 (65536)
0589 /* cb size is the exponent - 3 */
0590 #define TFD_QUEUE_CB_SIZE(x)    (ilog2(x) - 3)
0591 #define TFD_QUEUE_SIZE_BC_DUP   (64)
0592 #define TFD_QUEUE_BC_SIZE   (TFD_QUEUE_SIZE_MAX + TFD_QUEUE_SIZE_BC_DUP)
0593 #define TFD_QUEUE_BC_SIZE_GEN3_AX210    1024
0594 #define TFD_QUEUE_BC_SIZE_GEN3_BZ   (1024 * 4)
0595 #define IWL_TX_DMA_MASK        DMA_BIT_MASK(36)
0596 #define IWL_NUM_OF_TBS      20
0597 #define IWL_TFH_NUM_TBS     25
0598 
0599 /* IMR DMA registers */
0600 #define IMR_TFH_SRV_DMA_CHNL0_CTRL           0x00a0a51c
0601 #define IMR_TFH_SRV_DMA_CHNL0_SRAM_ADDR      0x00a0a520
0602 #define IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_LSB  0x00a0a524
0603 #define IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_MSB  0x00a0a528
0604 #define IMR_TFH_SRV_DMA_CHNL0_BC             0x00a0a52c
0605 #define TFH_SRV_DMA_CHNL0_LEFT_BC        0x00a0a530
0606 
0607 /* RFH S2D DMA registers */
0608 #define IMR_RFH_GEN_CFG_SERVICE_DMA_RS_MSK  0x0000000c
0609 #define IMR_RFH_GEN_CFG_SERVICE_DMA_SNOOP_MSK   0x00000002
0610 
0611 /* TFH D2S DMA registers */
0612 #define IMR_UREG_CHICK_HALT_UMAC_PERMANENTLY_MSK    0x80000000
0613 #define IMR_UREG_CHICK                  0x00d05c00
0614 #define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_IRQ_TARGET_POS   0x00800000
0615 #define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_RS_MSK       0x00000030
0616 #define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_DMA_EN_POS   0x80000000
0617 
0618 static inline u8 iwl_get_dma_hi_addr(dma_addr_t addr)
0619 {
0620     return (sizeof(addr) > sizeof(u32) ? upper_32_bits(addr) : 0) & 0xF;
0621 }
0622 
0623 /**
0624  * enum iwl_tfd_tb_hi_n_len - TB hi_n_len bits
0625  * @TB_HI_N_LEN_ADDR_HI_MSK: high 4 bits (to make it 36) of DMA address
0626  * @TB_HI_N_LEN_LEN_MSK: length of the TB
0627  */
0628 enum iwl_tfd_tb_hi_n_len {
0629     TB_HI_N_LEN_ADDR_HI_MSK = 0xf,
0630     TB_HI_N_LEN_LEN_MSK = 0xfff0,
0631 };
0632 
0633 /**
0634  * struct iwl_tfd_tb transmit buffer descriptor within transmit frame descriptor
0635  *
0636  * This structure contains dma address and length of transmission address
0637  *
0638  * @lo: low [31:0] portion of the dma address of TX buffer
0639  *  every even is unaligned on 16 bit boundary
0640  * @hi_n_len: &enum iwl_tfd_tb_hi_n_len
0641  */
0642 struct iwl_tfd_tb {
0643     __le32 lo;
0644     __le16 hi_n_len;
0645 } __packed;
0646 
0647 /**
0648  * struct iwl_tfh_tb transmit buffer descriptor within transmit frame descriptor
0649  *
0650  * This structure contains dma address and length of transmission address
0651  *
0652  * @tb_len length of the tx buffer
0653  * @addr 64 bits dma address
0654  */
0655 struct iwl_tfh_tb {
0656     __le16 tb_len;
0657     __le64 addr;
0658 } __packed;
0659 
0660 /**
0661  * Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM.
0662  * Both driver and device share these circular buffers, each of which must be
0663  * contiguous 256 TFDs.
0664  * For pre 22000 HW it is 256 x 128 bytes-per-TFD = 32 KBytes
0665  * For 22000 HW and on it is 256 x 256 bytes-per-TFD = 65 KBytes
0666  *
0667  * Driver must indicate the physical address of the base of each
0668  * circular buffer via the FH_MEM_CBBC_QUEUE registers.
0669  *
0670  * Each TFD contains pointer/size information for up to 20 / 25 data buffers
0671  * in host DRAM.  These buffers collectively contain the (one) frame described
0672  * by the TFD.  Each buffer must be a single contiguous block of memory within
0673  * itself, but buffers may be scattered in host DRAM.  Each buffer has max size
0674  * of (4K - 4).  The concatenates all of a TFD's buffers into a single
0675  * Tx frame, up to 8 KBytes in size.
0676  *
0677  * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.
0678  */
0679 
0680 /**
0681  * struct iwl_tfd - Transmit Frame Descriptor (TFD)
0682  * @ __reserved1[3] reserved
0683  * @ num_tbs 0-4 number of active tbs
0684  *       5   reserved
0685  *       6-7 padding (not used)
0686  * @ tbs[20]    transmit frame buffer descriptors
0687  * @ __pad  padding
0688  */
0689 struct iwl_tfd {
0690     u8 __reserved1[3];
0691     u8 num_tbs;
0692     struct iwl_tfd_tb tbs[IWL_NUM_OF_TBS];
0693     __le32 __pad;
0694 } __packed;
0695 
0696 /**
0697  * struct iwl_tfh_tfd - Transmit Frame Descriptor (TFD)
0698  * @ num_tbs 0-4 number of active tbs
0699  *       5 -15   reserved
0700  * @ tbs[25]    transmit frame buffer descriptors
0701  * @ __pad  padding
0702  */
0703 struct iwl_tfh_tfd {
0704     __le16 num_tbs;
0705     struct iwl_tfh_tb tbs[IWL_TFH_NUM_TBS];
0706     __le32 __pad;
0707 } __packed;
0708 
0709 /* Keep Warm Size */
0710 #define IWL_KW_SIZE 0x1000  /* 4k */
0711 
0712 /* Fixed (non-configurable) rx data from phy */
0713 
0714 /**
0715  * struct iwlagn_schedq_bc_tbl scheduler byte count table
0716  *  base physical address provided by SCD_DRAM_BASE_ADDR
0717  * For devices up to 22000:
0718  * @tfd_offset  0-12 - tx command byte count
0719  *      12-16 - station index
0720  * For 22000:
0721  * @tfd_offset  0-12 - tx command byte count
0722  *      12-13 - number of 64 byte chunks
0723  *      14-16 - reserved
0724  */
0725 struct iwlagn_scd_bc_tbl {
0726     __le16 tfd_offset[TFD_QUEUE_BC_SIZE];
0727 } __packed;
0728 
0729 /**
0730  * struct iwl_gen3_bc_tbl_entry scheduler byte count table entry gen3
0731  * For AX210 and on:
0732  * @tfd_offset: 0-12 - tx command byte count
0733  *      12-13 - number of 64 byte chunks
0734  *      14-16 - reserved
0735  */
0736 struct iwl_gen3_bc_tbl_entry {
0737     __le16 tfd_offset;
0738 } __packed;
0739 
0740 #endif /* !__iwl_fh_h__ */