/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */1/*2* Copyright (C) 2005-2014, 2018-2021, 2023-2025 Intel Corporation3* Copyright (C) 2015-2017 Intel Deutschland GmbH4*/5#ifndef __iwl_fh_h__6#define __iwl_fh_h__78#include <linux/types.h>9#include <linux/bitfield.h>1011#include "iwl-trans.h"1213/****************************/14/* Flow Handler Definitions */15/****************************/1617/*18* This I/O area is directly read/writable by driver (e.g. Linux uses writel())19* Addresses are offsets from device's PCI hardware base address.20*/21#define FH_MEM_LOWER_BOUND (0x1000)22#define FH_MEM_UPPER_BOUND (0x2000)23#define FH_MEM_LOWER_BOUND_GEN2 (0xa06000)24#define FH_MEM_UPPER_BOUND_GEN2 (0xa08000)2526/*27* Keep-Warm (KW) buffer base address.28*29* Driver must allocate a 4KByte buffer that is for keeping the30* host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency31* DRAM access when doing Txing or Rxing. The dummy accesses prevent host32* from going into a power-savings mode that would cause higher DRAM latency,33* and possible data over/under-runs, before all Tx/Rx is complete.34*35* Driver loads FH_KW_MEM_ADDR_REG with the physical address (bits 35:4)36* of the buffer, which must be 4K aligned. Once this is set up, the device37* automatically invokes keep-warm accesses when normal accesses might not38* be sufficient to maintain fast DRAM response.39*40* Bit fields:41* 31-0: Keep-warm buffer physical base address [35:4], must be 4K aligned42*/43#define FH_KW_MEM_ADDR_REG (FH_MEM_LOWER_BOUND + 0x97C)444546/*47* TFD Circular Buffers Base (CBBC) addresses48*49* Device has 16 base pointer registers, one for each of 16 host-DRAM-resident50* circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)51* (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x0452* bytes from one another. Each TFD circular buffer in DRAM must be 256-byte53* aligned (address bits 0-7 must be 0).54* Later devices have 20 (5000 series) or 30 (higher) queues, but the registers55* for them are in different places.56*57* Bit fields in each pointer register:58* 27-0: TFD CB physical base address [35:8], must be 256-byte aligned59*/60#define FH_MEM_CBBC_0_15_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)61#define FH_MEM_CBBC_0_15_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10)62#define FH_MEM_CBBC_16_19_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBF0)63#define FH_MEM_CBBC_16_19_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)64#define FH_MEM_CBBC_20_31_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xB20)65#define FH_MEM_CBBC_20_31_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xB80)66/* 22000 TFD table address, 64 bit */67#define TFH_TFDQ_CBB_TABLE (0x1C00)6869/* Find TFD CB base pointer for given queue */70static inline unsigned int FH_MEM_CBBC_QUEUE(struct iwl_trans *trans,71unsigned int chnl)72{73if (trans->mac_cfg->gen2) {74WARN_ON_ONCE(chnl >= 64);75return TFH_TFDQ_CBB_TABLE + 8 * chnl;76}77if (chnl < 16)78return FH_MEM_CBBC_0_15_LOWER_BOUND + 4 * chnl;79if (chnl < 20)80return FH_MEM_CBBC_16_19_LOWER_BOUND + 4 * (chnl - 16);81WARN_ON_ONCE(chnl >= 32);82return FH_MEM_CBBC_20_31_LOWER_BOUND + 4 * (chnl - 20);83}8485/* 22000 configuration registers */8687/*88* TFH Configuration register.89*90* BIT fields:91*92* Bits 3:0:93* Define the maximum number of pending read requests.94* Maximum configuration value allowed is 0xC95* Bits 9:8:96* Define the maximum transfer size. (64 / 128 / 256)97* Bit 10:98* When bit is set and transfer size is set to 128B, the TFH will enable99* reading chunks of more than 64B only if the read address is aligned to 128B.100* In case of DRAM read address which is not aligned to 128B, the TFH will101* enable transfer size which doesn't cross 64B DRAM address boundary.102*/103#define TFH_TRANSFER_MODE (0x1F40)104#define TFH_TRANSFER_MAX_PENDING_REQ 0xc105#define TFH_CHUNK_SIZE_128 BIT(8)106#define TFH_CHUNK_SPLIT_MODE BIT(10)107/*108* Defines the offset address in dwords referring from the beginning of the109* Tx CMD which will be updated in DRAM.110* Note that the TFH offset address for Tx CMD update is always referring to111* the start of the TFD first TB.112* In case of a DRAM Tx CMD update the TFH will update PN and Key ID113*/114#define TFH_TXCMD_UPDATE_CFG (0x1F48)115/*116* Controls TX DMA operation117*118* BIT fields:119*120* Bits 31:30: Enable the SRAM DMA channel.121* Turning on bit 31 will kick the SRAM2DRAM DMA.122* Note that the sram2dram may be enabled only after configuring the DRAM and123* SRAM addresses registers and the byte count register.124* Bits 25:24: Defines the interrupt target upon dram2sram transfer done. When125* set to 1 - interrupt is sent to the driver126* Bit 0: Indicates the snoop configuration127*/128#define TFH_SRV_DMA_CHNL0_CTRL (0x1F60)129#define TFH_SRV_DMA_SNOOP BIT(0)130#define TFH_SRV_DMA_TO_DRIVER BIT(24)131#define TFH_SRV_DMA_START BIT(31)132133/* Defines the DMA SRAM write start address to transfer a data block */134#define TFH_SRV_DMA_CHNL0_SRAM_ADDR (0x1F64)135136/* Defines the 64bits DRAM start address to read the DMA data block from */137#define TFH_SRV_DMA_CHNL0_DRAM_ADDR (0x1F68)138139/*140* Defines the number of bytes to transfer from DRAM to SRAM.141* Note that this register may be configured with non-dword aligned size.142*/143#define TFH_SRV_DMA_CHNL0_BC (0x1F70)144145/*146* Rx SRAM Control and Status Registers (RSCSR)147*148* These registers provide handshake between driver and device for the Rx queue149* (this queue handles *all* command responses, notifications, Rx data, etc.150* sent from uCode to host driver). Unlike Tx, there is only one Rx151* queue, and only one Rx DMA/FIFO channel. Also unlike Tx, which can152* concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer153* Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1154* mapping between RBDs and RBs.155*156* Driver must allocate host DRAM memory for the following, and set the157* physical address of each into device registers:158*159* 1) Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256160* entries (although any power of 2, up to 4096, is selectable by driver).161* Each entry (1 dword) points to a receive buffer (RB) of consistent size162* (typically 4K, although 8K or 16K are also selectable by driver).163* Driver sets up RB size and number of RBDs in the CB via Rx config164* register FH_MEM_RCSR_CHNL0_CONFIG_REG.165*166* Bit fields within one RBD:167* 27-0: Receive Buffer physical address bits [35:8], 256-byte aligned168*169* Driver sets physical address [35:8] of base of RBD circular buffer170* into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].171*172* 2) Rx status buffer, 8 bytes, in which uCode indicates which Rx Buffers173* (RBs) have been filled, via a "write pointer", actually the index of174* the RB's corresponding RBD within the circular buffer. Driver sets175* physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0].176*177* Bit fields in lower dword of Rx status buffer (upper dword not used178* by driver:179* 31-12: Not used by driver180* 11- 0: Index of last filled Rx buffer descriptor181* (device writes, driver reads this value)182*183* As the driver prepares Receive Buffers (RBs) for device to fill, driver must184* enter pointers to these RBs into contiguous RBD circular buffer entries,185* and update the device's "write" index register,186* FH_RSCSR_CHNL0_RBDCB_WPTR_REG.187*188* This "write" index corresponds to the *next* RBD that the driver will make189* available, i.e. one RBD past the tail of the ready-to-fill RBDs within190* the circular buffer. This value should initially be 0 (before preparing any191* RBs), should be 8 after preparing the first 8 RBs (for example), and must192* wrap back to 0 at the end of the circular buffer (but don't wrap before193* "read" index has advanced past 1! See below).194* NOTE: DEVICE EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8.195*196* As the device fills RBs (referenced from contiguous RBDs within the circular197* buffer), it updates the Rx status buffer in host DRAM, 2) described above,198* to tell the driver the index of the latest filled RBD. The driver must199* read this "read" index from DRAM after receiving an Rx interrupt from device200*201* The driver must also internally keep track of a third index, which is the202* next RBD to process. When receiving an Rx interrupt, driver should process203* all filled but unprocessed RBs up to, but not including, the RB204* corresponding to the "read" index. For example, if "read" index becomes "1",205* driver may process the RB pointed to by RBD 0. Depending on volume of206* traffic, there may be many RBs to process.207*208* If read index == write index, device thinks there is no room to put new data.209* Due to this, the maximum number of filled RBs is 255, instead of 256. To210* be safe, make sure that there is a gap of at least 2 RBDs between "write"211* and "read" indexes; that is, make sure that there are no more than 254212* buffers waiting to be filled.213*/214#define FH_MEM_RSCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBC0)215#define FH_MEM_RSCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)216#define FH_MEM_RSCSR_CHNL0 (FH_MEM_RSCSR_LOWER_BOUND)217218/*219* Physical base address of 8-byte Rx Status buffer.220* Bit fields:221* 31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.222*/223#define FH_RSCSR_CHNL0_STTS_WPTR_REG (FH_MEM_RSCSR_CHNL0)224225/*226* Physical base address of Rx Buffer Descriptor Circular Buffer.227* Bit fields:228* 27-0: RBD CD physical base address [35:8], must be 256-byte aligned.229*/230#define FH_RSCSR_CHNL0_RBDCB_BASE_REG (FH_MEM_RSCSR_CHNL0 + 0x004)231232/*233* Rx write pointer (index, really!).234* Bit fields:235* 11-0: Index of driver's most recent prepared-to-be-filled RBD, + 1.236* NOTE: For 256-entry circular buffer, use only bits [7:0].237*/238#define FH_RSCSR_CHNL0_RBDCB_WPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x008)239#define FH_RSCSR_CHNL0_WPTR (FH_RSCSR_CHNL0_RBDCB_WPTR_REG)240241#define FW_RSCSR_CHNL0_RXDCB_RDPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x00c)242#define FH_RSCSR_CHNL0_RDPTR FW_RSCSR_CHNL0_RXDCB_RDPTR_REG243244/*245* Rx Config/Status Registers (RCSR)246* Rx Config Reg for channel 0 (only channel used)247*248* Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for249* normal operation (see bit fields).250*251* Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.252* Driver should poll FH_MEM_RSSR_RX_STATUS_REG for253* FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.254*255* Bit fields:256* 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,257* '10' operate normally258* 29-24: reserved259* 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),260* min "5" for 32 RBDs, max "12" for 4096 RBDs.261* 19-18: reserved262* 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,263* '10' 12K, '11' 16K.264* 15-14: reserved265* 13-12: IRQ destination; '00' none, '01' host driver (normal operation)266* 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)267* typical value 0x10 (about 1/2 msec)268* 3- 0: reserved269*/270#define FH_MEM_RCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)271#define FH_MEM_RCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xCC0)272#define FH_MEM_RCSR_CHNL0 (FH_MEM_RCSR_LOWER_BOUND)273274#define FH_MEM_RCSR_CHNL0_CONFIG_REG (FH_MEM_RCSR_CHNL0)275#define FH_MEM_RCSR_CHNL0_RBDCB_WPTR (FH_MEM_RCSR_CHNL0 + 0x8)276#define FH_MEM_RCSR_CHNL0_FLUSH_RB_REQ (FH_MEM_RCSR_CHNL0 + 0x10)277278#define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MSK (0x00000FF0) /* bits 4-11 */279#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MSK (0x00001000) /* bits 12 */280#define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK (0x00008000) /* bit 15 */281#define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MSK (0x00030000) /* bits 16-17 */282#define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MSK (0x00F00000) /* bits 20-23 */283#define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MSK (0xC0000000) /* bits 30-31*/284285#define FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS (20)286#define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS (4)287#define RX_RB_TIMEOUT (0x11)288289#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000)290#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000)291#define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000)292293#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000)294#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K (0x00010000)295#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K (0x00020000)296#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K (0x00030000)297298#define FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY (0x00000004)299#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000)300#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000)301302/*303* Rx Shared Status Registers (RSSR)304*305* After stopping Rx DMA channel (writing 0 to306* FH_MEM_RCSR_CHNL0_CONFIG_REG), driver must poll307* FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.308*309* Bit fields:310* 24: 1 = Channel 0 is idle311*312* FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV313* contain default values that should not be altered by the driver.314*/315#define FH_MEM_RSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC40)316#define FH_MEM_RSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)317318#define FH_MEM_RSSR_SHARED_CTRL_REG (FH_MEM_RSSR_LOWER_BOUND)319#define FH_MEM_RSSR_RX_STATUS_REG (FH_MEM_RSSR_LOWER_BOUND + 0x004)320#define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV\321(FH_MEM_RSSR_LOWER_BOUND + 0x008)322323#define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (0x01000000)324325#define FH_MEM_TFDIB_REG1_ADDR_BITSHIFT 28326#define FH_MEM_TB_MAX_LENGTH (0x00020000)327328/* 9000 rx series registers */329330#define RFH_Q0_FRBDCB_BA_LSB 0xA08000 /* 64 bit address */331#define RFH_Q_FRBDCB_BA_LSB(q) (RFH_Q0_FRBDCB_BA_LSB + (q) * 8)332/* Write index table */333#define RFH_Q0_FRBDCB_WIDX 0xA08080334#define RFH_Q_FRBDCB_WIDX(q) (RFH_Q0_FRBDCB_WIDX + (q) * 4)335/* Write index table - shadow registers */336#define RFH_Q0_FRBDCB_WIDX_TRG 0x1C80337#define RFH_Q_FRBDCB_WIDX_TRG(q) (RFH_Q0_FRBDCB_WIDX_TRG + (q) * 4)338/* Read index table */339#define RFH_Q0_FRBDCB_RIDX 0xA080C0340#define RFH_Q_FRBDCB_RIDX(q) (RFH_Q0_FRBDCB_RIDX + (q) * 4)341/* Used list table */342#define RFH_Q0_URBDCB_BA_LSB 0xA08100 /* 64 bit address */343#define RFH_Q_URBDCB_BA_LSB(q) (RFH_Q0_URBDCB_BA_LSB + (q) * 8)344/* Write index table */345#define RFH_Q0_URBDCB_WIDX 0xA08180346#define RFH_Q_URBDCB_WIDX(q) (RFH_Q0_URBDCB_WIDX + (q) * 4)347#define RFH_Q0_URBDCB_VAID 0xA081C0348#define RFH_Q_URBDCB_VAID(q) (RFH_Q0_URBDCB_VAID + (q) * 4)349/* stts */350#define RFH_Q0_URBD_STTS_WPTR_LSB 0xA08200 /*64 bits address */351#define RFH_Q_URBD_STTS_WPTR_LSB(q) (RFH_Q0_URBD_STTS_WPTR_LSB + (q) * 8)352353#define RFH_Q0_ORB_WPTR_LSB 0xA08280354#define RFH_Q_ORB_WPTR_LSB(q) (RFH_Q0_ORB_WPTR_LSB + (q) * 8)355#define RFH_RBDBUF_RBD0_LSB 0xA08300356#define RFH_RBDBUF_RBD_LSB(q) (RFH_RBDBUF_RBD0_LSB + (q) * 8)357358/*359* RFH Status Register360*361* Bit fields:362*363* Bit 29: RBD_FETCH_IDLE364* This status flag is set by the RFH when there is no active RBD fetch from365* DRAM.366* Once the RFH RBD controller starts fetching (or when there is a pending367* RBD read response from DRAM), this flag is immediately turned off.368*369* Bit 30: SRAM_DMA_IDLE370* This status flag is set by the RFH when there is no active transaction from371* SRAM to DRAM.372* Once the SRAM to DRAM DMA is active, this flag is immediately turned off.373*374* Bit 31: RXF_DMA_IDLE375* This status flag is set by the RFH when there is no active transaction from376* RXF to DRAM.377* Once the RXF-to-DRAM DMA is active, this flag is immediately turned off.378*/379#define RFH_GEN_STATUS 0xA09808380#define RFH_GEN_STATUS_AX210 0xA07824381#define RBD_FETCH_IDLE BIT(29)382#define SRAM_DMA_IDLE BIT(30)383#define RXF_DMA_IDLE BIT(31)384385/* DMA configuration */386#define RFH_RXF_DMA_CFG 0xA09820387#define RFH_RXF_DMA_CFG_AX210 0xA07880388/* RB size */389#define RFH_RXF_DMA_RB_SIZE_MASK (0x000F0000) /* bits 16-19 */390#define RFH_RXF_DMA_RB_SIZE_POS 16391#define RFH_RXF_DMA_RB_SIZE_1K (0x1 << RFH_RXF_DMA_RB_SIZE_POS)392#define RFH_RXF_DMA_RB_SIZE_2K (0x2 << RFH_RXF_DMA_RB_SIZE_POS)393#define RFH_RXF_DMA_RB_SIZE_4K (0x4 << RFH_RXF_DMA_RB_SIZE_POS)394#define RFH_RXF_DMA_RB_SIZE_8K (0x8 << RFH_RXF_DMA_RB_SIZE_POS)395#define RFH_RXF_DMA_RB_SIZE_12K (0x9 << RFH_RXF_DMA_RB_SIZE_POS)396#define RFH_RXF_DMA_RB_SIZE_16K (0xA << RFH_RXF_DMA_RB_SIZE_POS)397#define RFH_RXF_DMA_RB_SIZE_20K (0xB << RFH_RXF_DMA_RB_SIZE_POS)398#define RFH_RXF_DMA_RB_SIZE_24K (0xC << RFH_RXF_DMA_RB_SIZE_POS)399#define RFH_RXF_DMA_RB_SIZE_28K (0xD << RFH_RXF_DMA_RB_SIZE_POS)400#define RFH_RXF_DMA_RB_SIZE_32K (0xE << RFH_RXF_DMA_RB_SIZE_POS)401/* RB Circular Buffer size:defines the table sizes in RBD units */402#define RFH_RXF_DMA_RBDCB_SIZE_MASK (0x00F00000) /* bits 20-23 */403#define RFH_RXF_DMA_RBDCB_SIZE_POS 20404#define RFH_RXF_DMA_RBDCB_SIZE_8 (0x3 << RFH_RXF_DMA_RBDCB_SIZE_POS)405#define RFH_RXF_DMA_RBDCB_SIZE_16 (0x4 << RFH_RXF_DMA_RBDCB_SIZE_POS)406#define RFH_RXF_DMA_RBDCB_SIZE_32 (0x5 << RFH_RXF_DMA_RBDCB_SIZE_POS)407#define RFH_RXF_DMA_RBDCB_SIZE_64 (0x7 << RFH_RXF_DMA_RBDCB_SIZE_POS)408#define RFH_RXF_DMA_RBDCB_SIZE_128 (0x7 << RFH_RXF_DMA_RBDCB_SIZE_POS)409#define RFH_RXF_DMA_RBDCB_SIZE_256 (0x8 << RFH_RXF_DMA_RBDCB_SIZE_POS)410#define RFH_RXF_DMA_RBDCB_SIZE_512 (0x9 << RFH_RXF_DMA_RBDCB_SIZE_POS)411#define RFH_RXF_DMA_RBDCB_SIZE_1024 (0xA << RFH_RXF_DMA_RBDCB_SIZE_POS)412#define RFH_RXF_DMA_RBDCB_SIZE_2048 (0xB << RFH_RXF_DMA_RBDCB_SIZE_POS)413#define RFH_RXF_DMA_MIN_RB_SIZE_MASK (0x03000000) /* bit 24-25 */414#define RFH_RXF_DMA_MIN_RB_SIZE_POS 24415#define RFH_RXF_DMA_MIN_RB_4_8 (3 << RFH_RXF_DMA_MIN_RB_SIZE_POS)416#define RFH_RXF_DMA_DROP_TOO_LARGE_MASK (0x04000000) /* bit 26 */417#define RFH_RXF_DMA_SINGLE_FRAME_MASK (0x20000000) /* bit 29 */418#define RFH_DMA_EN_MASK (0xC0000000) /* bits 30-31*/419#define RFH_DMA_EN_ENABLE_VAL BIT(31)420421#define RFH_RXF_RXQ_ACTIVE 0xA0980C422423#define RFH_GEN_CFG 0xA09800424#define RFH_GEN_CFG_SERVICE_DMA_SNOOP BIT(0)425#define RFH_GEN_CFG_RFH_DMA_SNOOP BIT(1)426#define RFH_GEN_CFG_RB_CHUNK_SIZE BIT(4)427#define RFH_GEN_CFG_RB_CHUNK_SIZE_128 1428#define RFH_GEN_CFG_RB_CHUNK_SIZE_64 0429/* the driver assumes everywhere that the default RXQ is 0 */430#define RFH_GEN_CFG_DEFAULT_RXQ_NUM 0xF00431#define RFH_GEN_CFG_VAL(_n, _v) FIELD_PREP(RFH_GEN_CFG_ ## _n, _v)432433/* end of 9000 rx series registers */434435/* TFDB Area - TFDs buffer table */436#define FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK (0xFFFFFFFF)437#define FH_TFDIB_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x900)438#define FH_TFDIB_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0x958)439#define FH_TFDIB_CTRL0_REG(_chnl) (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl))440#define FH_TFDIB_CTRL1_REG(_chnl) (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl) + 0x4)441442/*443* Transmit DMA Channel Control/Status Registers (TCSR)444*445* Device has one configuration register for each of 8 Tx DMA/FIFO channels446* supported in hardware (don't confuse these with the 16 Tx queues in DRAM,447* which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.448*449* To use a Tx DMA channel, driver must initialize its450* FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with:451*452* FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |453* FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL454*455* All other bits should be 0.456*457* Bit fields:458* 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,459* '10' operate normally460* 29- 4: Reserved, set to "0"461* 3: Enable internal DMA requests (1, normal operation), disable (0)462* 2- 0: Reserved, set to "0"463*/464#define FH_TCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)465#define FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60)466467/* Find Control/Status reg for given Tx DMA/FIFO channel */468#define FH_TCSR_CHNL_NUM (8)469470/* TCSR: tx_config register values */471#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \472(FH_TCSR_LOWER_BOUND + 0x20 * (_chnl))473#define FH_TCSR_CHNL_TX_CREDIT_REG(_chnl) \474(FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x4)475#define FH_TCSR_CHNL_TX_BUF_STS_REG(_chnl) \476(FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x8)477478#define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF (0x00000000)479#define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRV (0x00000001)480481#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE (0x00000000)482#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE (0x00000008)483484#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT (0x00000000)485#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD (0x00100000)486#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000)487488#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT (0x00000000)489#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_ENDTFD (0x00400000)490#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_IFTFD (0x00800000)491492#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000)493#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000)494#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)495496#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY (0x00000000)497#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT (0x00002000)498#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00000003)499500#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM (20)501#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX (12)502503/*504* Tx Shared Status Registers (TSSR)505*506* After stopping Tx DMA channel (writing 0 to507* FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll508* FH_TSSR_TX_STATUS_REG until selected Tx channel is idle509* (channel's buffers empty | no pending requests).510*511* Bit fields:512* 31-24: 1 = Channel buffers empty (channel 7:0)513* 23-16: 1 = No pending requests (channel 7:0)514*/515#define FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0)516#define FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0)517518#define FH_TSSR_TX_STATUS_REG (FH_TSSR_LOWER_BOUND + 0x010)519520/*521* Bit fields for TSSR(Tx Shared Status & Control) error status register:522* 31: Indicates an address error when accessed to internal memory523* uCode/driver must write "1" in order to clear this flag524* 30: Indicates that Host did not send the expected number of dwords to FH525* uCode/driver must write "1" in order to clear this flag526* 16-9:Each status bit is for one channel. Indicates that an (Error) ActDMA527* command was received from the scheduler while the TRB was already full528* with previous command529* uCode/driver must write "1" in order to clear this flag530* 7-0: Each status bit indicates a channel's TxCredit error. When an error531* bit is set, it indicates that the FH has received a full indication532* from the RTC TxFIFO and the current value of the TxCredit counter was533* not equal to zero. This mean that the credit mechanism was not534* synchronized to the TxFIFO status535* uCode/driver must write "1" in order to clear this flag536*/537#define FH_TSSR_TX_ERROR_REG (FH_TSSR_LOWER_BOUND + 0x018)538#define FH_TSSR_TX_MSG_CONFIG_REG (FH_TSSR_LOWER_BOUND + 0x008)539540#define FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) ((1 << (_chnl)) << 16)541542/* Tx service channels */543#define FH_SRVC_CHNL (9)544#define FH_SRVC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9C8)545#define FH_SRVC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)546#define FH_SRVC_CHNL_SRAM_ADDR_REG(_chnl) \547(FH_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4)548549#define FH_TX_CHICKEN_BITS_REG (FH_MEM_LOWER_BOUND + 0xE98)550#define FH_TX_TRB_REG(_chan) (FH_MEM_LOWER_BOUND + 0x958 + (_chan) * 4)551552/* Instruct FH to increment the retry count of a packet when553* it is brought from the memory to TX-FIFO554*/555#define FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN (0x00000002)556557#define RX_POOL_SIZE(rbds) ((rbds) - 1 + \558IWL_MAX_RX_HW_QUEUES * \559(RX_CLAIM_REQ_ALLOC - RX_POST_REQ_ALLOC))560/* cb size is the exponent */561#define RX_QUEUE_CB_SIZE(x) ilog2(x)562563#define RX_QUEUE_SIZE 256564#define RX_QUEUE_MASK 255565#define RX_QUEUE_SIZE_LOG 8566567#define IWL_DEFAULT_RX_QUEUE 0568569/**570* struct iwl_rb_status - reserve buffer status571* host memory mapped FH registers572* @closed_rb_num: [0:11] Indicates the index of the RB which was closed573* @closed_fr_num: [0:11] Indicates the index of the RX Frame which was closed574* @finished_rb_num: [0:11] Indicates the index of the current RB575* in which the last frame was written to576* @finished_fr_num: [0:11] Indicates the index of the RX Frame577* which was transferred578* @__spare: reserved579*/580struct iwl_rb_status {581__le16 closed_rb_num;582__le16 closed_fr_num;583__le16 finished_rb_num;584__le16 finished_fr_num;585__le32 __spare;586} __packed;587588589#define TFD_QUEUE_SIZE_MAX (256)590/* cb size is the exponent - 3 */591#define TFD_QUEUE_CB_SIZE(x) (ilog2(x) - 3)592#define TFD_QUEUE_SIZE_BC_DUP (64)593#define TFD_QUEUE_BC_SIZE (TFD_QUEUE_SIZE_MAX + TFD_QUEUE_SIZE_BC_DUP)594#define TFD_QUEUE_BC_SIZE_AX210 1024595#define TFD_QUEUE_BC_SIZE_BZ (1024 * 4)596#define IWL_TX_DMA_MASK DMA_BIT_MASK(36)597#define IWL_NUM_OF_TBS 20598#define IWL_TFH_NUM_TBS 25599600/* IMR DMA registers */601#define IMR_TFH_SRV_DMA_CHNL0_CTRL 0x00a0a51c602#define IMR_TFH_SRV_DMA_CHNL0_SRAM_ADDR 0x00a0a520603#define IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_LSB 0x00a0a524604#define IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_MSB 0x00a0a528605#define IMR_TFH_SRV_DMA_CHNL0_BC 0x00a0a52c606#define TFH_SRV_DMA_CHNL0_LEFT_BC 0x00a0a530607608/* RFH S2D DMA registers */609#define IMR_RFH_GEN_CFG_SERVICE_DMA_RS_MSK 0x0000000c610#define IMR_RFH_GEN_CFG_SERVICE_DMA_SNOOP_MSK 0x00000002611612/* TFH D2S DMA registers */613#define IMR_UREG_CHICK_HALT_UMAC_PERMANENTLY_MSK 0x80000000614#define IMR_UREG_CHICK 0x00d05c00615#define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_IRQ_TARGET_POS 0x00800000616#define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_RS_MSK 0x00000030617#define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_DMA_EN_POS 0x80000000618619static inline u8 iwl_get_dma_hi_addr(dma_addr_t addr)620{621return (sizeof(addr) > sizeof(u32) ? upper_32_bits(addr) : 0) & 0xF;622}623624/**625* enum iwl_tfd_tb_hi_n_len - TB hi_n_len bits626* @TB_HI_N_LEN_ADDR_HI_MSK: high 4 bits (to make it 36) of DMA address627* @TB_HI_N_LEN_LEN_MSK: length of the TB628*/629enum iwl_tfd_tb_hi_n_len {630TB_HI_N_LEN_ADDR_HI_MSK = 0xf,631TB_HI_N_LEN_LEN_MSK = 0xfff0,632};633634/**635* struct iwl_tfd_tb - transmit buffer descriptor within transmit frame descriptor636*637* This structure contains dma address and length of transmission address638*639* @lo: low [31:0] portion of the dma address of TX buffer640* every even is unaligned on 16 bit boundary641* @hi_n_len: &enum iwl_tfd_tb_hi_n_len642*/643struct iwl_tfd_tb {644__le32 lo;645__le16 hi_n_len;646} __packed;647648/**649* struct iwl_tfh_tb - transmit buffer descriptor within transmit frame descriptor650*651* This structure contains dma address and length of transmission address652*653* @tb_len: length of the tx buffer654* @addr: 64 bits dma address655*/656struct iwl_tfh_tb {657__le16 tb_len;658__le64 addr;659} __packed;660661/*662* Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM.663* Both driver and device share these circular buffers, each of which must be664* contiguous 256 TFDs.665* For pre 22000 HW it is 256 x 128 bytes-per-TFD = 32 KBytes666* For 22000 HW and on it is 256 x 256 bytes-per-TFD = 65 KBytes667*668* Driver must indicate the physical address of the base of each669* circular buffer via the FH_MEM_CBBC_QUEUE registers.670*671* Each TFD contains pointer/size information for up to 20 / 25 data buffers672* in host DRAM. These buffers collectively contain the (one) frame described673* by the TFD. Each buffer must be a single contiguous block of memory within674* itself, but buffers may be scattered in host DRAM. Each buffer has max size675* of (4K - 4). The concatenates all of a TFD's buffers into a single676* Tx frame, up to 8 KBytes in size.677*678* A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.679*/680681/**682* struct iwl_tfd - Transmit Frame Descriptor (TFD)683* @__reserved1: reserved684* @num_tbs:685* 0-4 number of active tbs686* 5 reserved687* 6-7 padding (not used)688* @tbs: transmit frame buffer descriptors689* @__pad: padding690*/691struct iwl_tfd {692u8 __reserved1[3];693u8 num_tbs;694struct iwl_tfd_tb tbs[IWL_NUM_OF_TBS];695__le32 __pad;696} __packed;697698/**699* struct iwl_tfh_tfd - Transmit Frame Descriptor (TFD)700* @num_tbs:701* 0-4 number of active tbs702* 5-15 reserved703* @tbs: transmit frame buffer descriptors704* @__pad: padding705*/706struct iwl_tfh_tfd {707__le16 num_tbs;708struct iwl_tfh_tb tbs[IWL_TFH_NUM_TBS];709__le32 __pad;710} __packed;711712/* Keep Warm Size */713#define IWL_KW_SIZE 0x1000 /* 4k */714715/* Fixed (non-configurable) rx data from phy */716717/**718* struct iwl_bc_tbl_entry - scheduler byte count table entry719* base physical address provided by SCD_DRAM_BASE_ADDR720* For devices up to 22000:721* @tfd_offset:722* For devices up to 22000:723* 0-12 - tx command byte count724* 12-16 - station index725* For 22000 and on:726* 0-12 - tx command byte count727* 12-13 - number of 64 byte chunks728* 14-16 - reserved729*/730struct iwl_bc_tbl_entry {731__le16 tfd_offset;732} __packed;733734#endif /* !__iwl_fh_h__ */735736737