iwl-fh.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2005-2014, 2018-2021 Intel Corporation
  4. * Copyright (C) 2015-2017 Intel Deutschland GmbH
  5. */
  6. #ifndef __iwl_fh_h__
  7. #define __iwl_fh_h__
  8. #include <linux/types.h>
  9. #include <linux/bitfield.h>
  10. #include "iwl-trans.h"
  11. /****************************/
  12. /* Flow Handler Definitions */
  13. /****************************/
  14. /**
  15. * This I/O area is directly read/writable by driver (e.g. Linux uses writel())
  16. * Addresses are offsets from device's PCI hardware base address.
  17. */
  18. #define FH_MEM_LOWER_BOUND (0x1000)
  19. #define FH_MEM_UPPER_BOUND (0x2000)
  20. #define FH_MEM_LOWER_BOUND_GEN2 (0xa06000)
  21. #define FH_MEM_UPPER_BOUND_GEN2 (0xa08000)
  22. /**
  23. * Keep-Warm (KW) buffer base address.
  24. *
  25. * Driver must allocate a 4KByte buffer that is for keeping the
  26. * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency
  27. * DRAM access when doing Txing or Rxing. The dummy accesses prevent host
  28. * from going into a power-savings mode that would cause higher DRAM latency,
  29. * and possible data over/under-runs, before all Tx/Rx is complete.
  30. *
  31. * Driver loads FH_KW_MEM_ADDR_REG with the physical address (bits 35:4)
  32. * of the buffer, which must be 4K aligned. Once this is set up, the device
  33. * automatically invokes keep-warm accesses when normal accesses might not
  34. * be sufficient to maintain fast DRAM response.
  35. *
  36. * Bit fields:
  37. * 31-0: Keep-warm buffer physical base address [35:4], must be 4K aligned
  38. */
  39. #define FH_KW_MEM_ADDR_REG (FH_MEM_LOWER_BOUND + 0x97C)
  40. /**
  41. * TFD Circular Buffers Base (CBBC) addresses
  42. *
  43. * Device has 16 base pointer registers, one for each of 16 host-DRAM-resident
  44. * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)
  45. * (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x04
  46. * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte
  47. * aligned (address bits 0-7 must be 0).
  48. * Later devices have 20 (5000 series) or 30 (higher) queues, but the registers
  49. * for them are in different places.
  50. *
  51. * Bit fields in each pointer register:
  52. * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned
  53. */
  54. #define FH_MEM_CBBC_0_15_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)
  55. #define FH_MEM_CBBC_0_15_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10)
  56. #define FH_MEM_CBBC_16_19_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBF0)
  57. #define FH_MEM_CBBC_16_19_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
  58. #define FH_MEM_CBBC_20_31_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xB20)
  59. #define FH_MEM_CBBC_20_31_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xB80)
  60. /* 22000 TFD table address, 64 bit */
  61. #define TFH_TFDQ_CBB_TABLE (0x1C00)
  62. /* Find TFD CB base pointer for given queue */
  63. static inline unsigned int FH_MEM_CBBC_QUEUE(struct iwl_trans *trans,
  64. unsigned int chnl)
  65. {
  66. if (trans->trans_cfg->use_tfh) {
  67. WARN_ON_ONCE(chnl >= 64);
  68. return TFH_TFDQ_CBB_TABLE + 8 * chnl;
  69. }
  70. if (chnl < 16)
  71. return FH_MEM_CBBC_0_15_LOWER_BOUND + 4 * chnl;
  72. if (chnl < 20)
  73. return FH_MEM_CBBC_16_19_LOWER_BOUND + 4 * (chnl - 16);
  74. WARN_ON_ONCE(chnl >= 32);
  75. return FH_MEM_CBBC_20_31_LOWER_BOUND + 4 * (chnl - 20);
  76. }
  77. /* 22000 configuration registers */
  78. /*
  79. * TFH Configuration register.
  80. *
  81. * BIT fields:
  82. *
  83. * Bits 3:0:
  84. * Define the maximum number of pending read requests.
  85. * Maximum configuration value allowed is 0xC
  86. * Bits 9:8:
  87. * Define the maximum transfer size. (64 / 128 / 256)
  88. * Bit 10:
  89. * When bit is set and transfer size is set to 128B, the TFH will enable
  90. * reading chunks of more than 64B only if the read address is aligned to 128B.
  91. * In case of DRAM read address which is not aligned to 128B, the TFH will
  92. * enable transfer size which doesn't cross 64B DRAM address boundary.
  93. */
  94. #define TFH_TRANSFER_MODE (0x1F40)
  95. #define TFH_TRANSFER_MAX_PENDING_REQ 0xc
  96. #define TFH_CHUNK_SIZE_128 BIT(8)
  97. #define TFH_CHUNK_SPLIT_MODE BIT(10)
  98. /*
  99. * Defines the offset address in dwords referring from the beginning of the
  100. * Tx CMD which will be updated in DRAM.
  101. * Note that the TFH offset address for Tx CMD update is always referring to
  102. * the start of the TFD first TB.
  103. * In case of a DRAM Tx CMD update the TFH will update PN and Key ID
  104. */
  105. #define TFH_TXCMD_UPDATE_CFG (0x1F48)
  106. /*
  107. * Controls TX DMA operation
  108. *
  109. * BIT fields:
  110. *
  111. * Bits 31:30: Enable the SRAM DMA channel.
  112. * Turning on bit 31 will kick the SRAM2DRAM DMA.
  113. * Note that the sram2dram may be enabled only after configuring the DRAM and
  114. * SRAM addresses registers and the byte count register.
  115. * Bits 25:24: Defines the interrupt target upon dram2sram transfer done. When
  116. * set to 1 - interrupt is sent to the driver
  117. * Bit 0: Indicates the snoop configuration
  118. */
  119. #define TFH_SRV_DMA_CHNL0_CTRL (0x1F60)
  120. #define TFH_SRV_DMA_SNOOP BIT(0)
  121. #define TFH_SRV_DMA_TO_DRIVER BIT(24)
  122. #define TFH_SRV_DMA_START BIT(31)
  123. /* Defines the DMA SRAM write start address to transfer a data block */
  124. #define TFH_SRV_DMA_CHNL0_SRAM_ADDR (0x1F64)
  125. /* Defines the 64bits DRAM start address to read the DMA data block from */
  126. #define TFH_SRV_DMA_CHNL0_DRAM_ADDR (0x1F68)
  127. /*
  128. * Defines the number of bytes to transfer from DRAM to SRAM.
  129. * Note that this register may be configured with non-dword aligned size.
  130. */
  131. #define TFH_SRV_DMA_CHNL0_BC (0x1F70)
  132. /**
  133. * Rx SRAM Control and Status Registers (RSCSR)
  134. *
  135. * These registers provide handshake between driver and device for the Rx queue
  136. * (this queue handles *all* command responses, notifications, Rx data, etc.
  137. * sent from uCode to host driver). Unlike Tx, there is only one Rx
  138. * queue, and only one Rx DMA/FIFO channel. Also unlike Tx, which can
  139. * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer
  140. * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1
  141. * mapping between RBDs and RBs.
  142. *
  143. * Driver must allocate host DRAM memory for the following, and set the
  144. * physical address of each into device registers:
  145. *
  146. * 1) Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256
  147. * entries (although any power of 2, up to 4096, is selectable by driver).
  148. * Each entry (1 dword) points to a receive buffer (RB) of consistent size
  149. * (typically 4K, although 8K or 16K are also selectable by driver).
  150. * Driver sets up RB size and number of RBDs in the CB via Rx config
  151. * register FH_MEM_RCSR_CHNL0_CONFIG_REG.
  152. *
  153. * Bit fields within one RBD:
  154. * 27-0: Receive Buffer physical address bits [35:8], 256-byte aligned
  155. *
  156. * Driver sets physical address [35:8] of base of RBD circular buffer
  157. * into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].
  158. *
  159. * 2) Rx status buffer, 8 bytes, in which uCode indicates which Rx Buffers
  160. * (RBs) have been filled, via a "write pointer", actually the index of
  161. * the RB's corresponding RBD within the circular buffer. Driver sets
  162. * physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0].
  163. *
  164. * Bit fields in lower dword of Rx status buffer (upper dword not used
  165. * by driver:
  166. * 31-12: Not used by driver
  167. * 11- 0: Index of last filled Rx buffer descriptor
  168. * (device writes, driver reads this value)
  169. *
  170. * As the driver prepares Receive Buffers (RBs) for device to fill, driver must
  171. * enter pointers to these RBs into contiguous RBD circular buffer entries,
  172. * and update the device's "write" index register,
  173. * FH_RSCSR_CHNL0_RBDCB_WPTR_REG.
  174. *
  175. * This "write" index corresponds to the *next* RBD that the driver will make
  176. * available, i.e. one RBD past the tail of the ready-to-fill RBDs within
  177. * the circular buffer. This value should initially be 0 (before preparing any
  178. * RBs), should be 8 after preparing the first 8 RBs (for example), and must
  179. * wrap back to 0 at the end of the circular buffer (but don't wrap before
  180. * "read" index has advanced past 1! See below).
  181. * NOTE: DEVICE EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8.
  182. *
  183. * As the device fills RBs (referenced from contiguous RBDs within the circular
  184. * buffer), it updates the Rx status buffer in host DRAM, 2) described above,
  185. * to tell the driver the index of the latest filled RBD. The driver must
  186. * read this "read" index from DRAM after receiving an Rx interrupt from device
  187. *
  188. * The driver must also internally keep track of a third index, which is the
  189. * next RBD to process. When receiving an Rx interrupt, driver should process
  190. * all filled but unprocessed RBs up to, but not including, the RB
  191. * corresponding to the "read" index. For example, if "read" index becomes "1",
  192. * driver may process the RB pointed to by RBD 0. Depending on volume of
  193. * traffic, there may be many RBs to process.
  194. *
  195. * If read index == write index, device thinks there is no room to put new data.
  196. * Due to this, the maximum number of filled RBs is 255, instead of 256. To
  197. * be safe, make sure that there is a gap of at least 2 RBDs between "write"
  198. * and "read" indexes; that is, make sure that there are no more than 254
  199. * buffers waiting to be filled.
  200. */
  201. #define FH_MEM_RSCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBC0)
  202. #define FH_MEM_RSCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
  203. #define FH_MEM_RSCSR_CHNL0 (FH_MEM_RSCSR_LOWER_BOUND)
  204. /**
  205. * Physical base address of 8-byte Rx Status buffer.
  206. * Bit fields:
  207. * 31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.
  208. */
  209. #define FH_RSCSR_CHNL0_STTS_WPTR_REG (FH_MEM_RSCSR_CHNL0)
  210. /**
  211. * Physical base address of Rx Buffer Descriptor Circular Buffer.
  212. * Bit fields:
  213. * 27-0: RBD CD physical base address [35:8], must be 256-byte aligned.
  214. */
  215. #define FH_RSCSR_CHNL0_RBDCB_BASE_REG (FH_MEM_RSCSR_CHNL0 + 0x004)
  216. /**
  217. * Rx write pointer (index, really!).
  218. * Bit fields:
  219. * 11-0: Index of driver's most recent prepared-to-be-filled RBD, + 1.
  220. * NOTE: For 256-entry circular buffer, use only bits [7:0].
  221. */
  222. #define FH_RSCSR_CHNL0_RBDCB_WPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x008)
  223. #define FH_RSCSR_CHNL0_WPTR (FH_RSCSR_CHNL0_RBDCB_WPTR_REG)
  224. #define FW_RSCSR_CHNL0_RXDCB_RDPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x00c)
  225. #define FH_RSCSR_CHNL0_RDPTR FW_RSCSR_CHNL0_RXDCB_RDPTR_REG
  226. /**
  227. * Rx Config/Status Registers (RCSR)
  228. * Rx Config Reg for channel 0 (only channel used)
  229. *
  230. * Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for
  231. * normal operation (see bit fields).
  232. *
  233. * Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.
  234. * Driver should poll FH_MEM_RSSR_RX_STATUS_REG for
  235. * FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.
  236. *
  237. * Bit fields:
  238. * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,
  239. * '10' operate normally
  240. * 29-24: reserved
  241. * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),
  242. * min "5" for 32 RBDs, max "12" for 4096 RBDs.
  243. * 19-18: reserved
  244. * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,
  245. * '10' 12K, '11' 16K.
  246. * 15-14: reserved
  247. * 13-12: IRQ destination; '00' none, '01' host driver (normal operation)
  248. * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)
  249. * typical value 0x10 (about 1/2 msec)
  250. * 3- 0: reserved
  251. */
  252. #define FH_MEM_RCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
  253. #define FH_MEM_RCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xCC0)
  254. #define FH_MEM_RCSR_CHNL0 (FH_MEM_RCSR_LOWER_BOUND)
  255. #define FH_MEM_RCSR_CHNL0_CONFIG_REG (FH_MEM_RCSR_CHNL0)
  256. #define FH_MEM_RCSR_CHNL0_RBDCB_WPTR (FH_MEM_RCSR_CHNL0 + 0x8)
  257. #define FH_MEM_RCSR_CHNL0_FLUSH_RB_REQ (FH_MEM_RCSR_CHNL0 + 0x10)
  258. #define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MSK (0x00000FF0) /* bits 4-11 */
  259. #define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MSK (0x00001000) /* bits 12 */
  260. #define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK (0x00008000) /* bit 15 */
  261. #define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MSK (0x00030000) /* bits 16-17 */
  262. #define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MSK (0x00F00000) /* bits 20-23 */
  263. #define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MSK (0xC0000000) /* bits 30-31*/
  264. #define FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS (20)
  265. #define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS (4)
  266. #define RX_RB_TIMEOUT (0x11)
  267. #define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000)
  268. #define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000)
  269. #define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000)
  270. #define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000)
  271. #define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K (0x00010000)
  272. #define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K (0x00020000)
  273. #define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K (0x00030000)
  274. #define FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY (0x00000004)
  275. #define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000)
  276. #define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000)
  277. /**
  278. * Rx Shared Status Registers (RSSR)
  279. *
  280. * After stopping Rx DMA channel (writing 0 to
  281. * FH_MEM_RCSR_CHNL0_CONFIG_REG), driver must poll
  282. * FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.
  283. *
  284. * Bit fields:
  285. * 24: 1 = Channel 0 is idle
  286. *
  287. * FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV
  288. * contain default values that should not be altered by the driver.
  289. */
  290. #define FH_MEM_RSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC40)
  291. #define FH_MEM_RSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
  292. #define FH_MEM_RSSR_SHARED_CTRL_REG (FH_MEM_RSSR_LOWER_BOUND)
  293. #define FH_MEM_RSSR_RX_STATUS_REG (FH_MEM_RSSR_LOWER_BOUND + 0x004)
  294. #define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV\
  295. (FH_MEM_RSSR_LOWER_BOUND + 0x008)
  296. #define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (0x01000000)
  297. #define FH_MEM_TFDIB_REG1_ADDR_BITSHIFT 28
  298. #define FH_MEM_TB_MAX_LENGTH (0x00020000)
  299. /* 9000 rx series registers */
  300. #define RFH_Q0_FRBDCB_BA_LSB 0xA08000 /* 64 bit address */
  301. #define RFH_Q_FRBDCB_BA_LSB(q) (RFH_Q0_FRBDCB_BA_LSB + (q) * 8)
  302. /* Write index table */
  303. #define RFH_Q0_FRBDCB_WIDX 0xA08080
  304. #define RFH_Q_FRBDCB_WIDX(q) (RFH_Q0_FRBDCB_WIDX + (q) * 4)
  305. /* Write index table - shadow registers */
  306. #define RFH_Q0_FRBDCB_WIDX_TRG 0x1C80
  307. #define RFH_Q_FRBDCB_WIDX_TRG(q) (RFH_Q0_FRBDCB_WIDX_TRG + (q) * 4)
  308. /* Read index table */
  309. #define RFH_Q0_FRBDCB_RIDX 0xA080C0
  310. #define RFH_Q_FRBDCB_RIDX(q) (RFH_Q0_FRBDCB_RIDX + (q) * 4)
  311. /* Used list table */
  312. #define RFH_Q0_URBDCB_BA_LSB 0xA08100 /* 64 bit address */
  313. #define RFH_Q_URBDCB_BA_LSB(q) (RFH_Q0_URBDCB_BA_LSB + (q) * 8)
  314. /* Write index table */
  315. #define RFH_Q0_URBDCB_WIDX 0xA08180
  316. #define RFH_Q_URBDCB_WIDX(q) (RFH_Q0_URBDCB_WIDX + (q) * 4)
  317. #define RFH_Q0_URBDCB_VAID 0xA081C0
  318. #define RFH_Q_URBDCB_VAID(q) (RFH_Q0_URBDCB_VAID + (q) * 4)
  319. /* stts */
  320. #define RFH_Q0_URBD_STTS_WPTR_LSB 0xA08200 /*64 bits address */
  321. #define RFH_Q_URBD_STTS_WPTR_LSB(q) (RFH_Q0_URBD_STTS_WPTR_LSB + (q) * 8)
  322. #define RFH_Q0_ORB_WPTR_LSB 0xA08280
  323. #define RFH_Q_ORB_WPTR_LSB(q) (RFH_Q0_ORB_WPTR_LSB + (q) * 8)
  324. #define RFH_RBDBUF_RBD0_LSB 0xA08300
  325. #define RFH_RBDBUF_RBD_LSB(q) (RFH_RBDBUF_RBD0_LSB + (q) * 8)
  326. /**
  327. * RFH Status Register
  328. *
  329. * Bit fields:
  330. *
  331. * Bit 29: RBD_FETCH_IDLE
  332. * This status flag is set by the RFH when there is no active RBD fetch from
  333. * DRAM.
  334. * Once the RFH RBD controller starts fetching (or when there is a pending
  335. * RBD read response from DRAM), this flag is immediately turned off.
  336. *
  337. * Bit 30: SRAM_DMA_IDLE
  338. * This status flag is set by the RFH when there is no active transaction from
  339. * SRAM to DRAM.
  340. * Once the SRAM to DRAM DMA is active, this flag is immediately turned off.
  341. *
  342. * Bit 31: RXF_DMA_IDLE
  343. * This status flag is set by the RFH when there is no active transaction from
  344. * RXF to DRAM.
  345. * Once the RXF-to-DRAM DMA is active, this flag is immediately turned off.
  346. */
  347. #define RFH_GEN_STATUS 0xA09808
  348. #define RFH_GEN_STATUS_GEN3 0xA07824
  349. #define RBD_FETCH_IDLE BIT(29)
  350. #define SRAM_DMA_IDLE BIT(30)
  351. #define RXF_DMA_IDLE BIT(31)
  352. /* DMA configuration */
  353. #define RFH_RXF_DMA_CFG 0xA09820
  354. #define RFH_RXF_DMA_CFG_GEN3 0xA07880
  355. /* RB size */
  356. #define RFH_RXF_DMA_RB_SIZE_MASK (0x000F0000) /* bits 16-19 */
  357. #define RFH_RXF_DMA_RB_SIZE_POS 16
  358. #define RFH_RXF_DMA_RB_SIZE_1K (0x1 << RFH_RXF_DMA_RB_SIZE_POS)
  359. #define RFH_RXF_DMA_RB_SIZE_2K (0x2 << RFH_RXF_DMA_RB_SIZE_POS)
  360. #define RFH_RXF_DMA_RB_SIZE_4K (0x4 << RFH_RXF_DMA_RB_SIZE_POS)
  361. #define RFH_RXF_DMA_RB_SIZE_8K (0x8 << RFH_RXF_DMA_RB_SIZE_POS)
  362. #define RFH_RXF_DMA_RB_SIZE_12K (0x9 << RFH_RXF_DMA_RB_SIZE_POS)
  363. #define RFH_RXF_DMA_RB_SIZE_16K (0xA << RFH_RXF_DMA_RB_SIZE_POS)
  364. #define RFH_RXF_DMA_RB_SIZE_20K (0xB << RFH_RXF_DMA_RB_SIZE_POS)
  365. #define RFH_RXF_DMA_RB_SIZE_24K (0xC << RFH_RXF_DMA_RB_SIZE_POS)
  366. #define RFH_RXF_DMA_RB_SIZE_28K (0xD << RFH_RXF_DMA_RB_SIZE_POS)
  367. #define RFH_RXF_DMA_RB_SIZE_32K (0xE << RFH_RXF_DMA_RB_SIZE_POS)
  368. /* RB Circular Buffer size:defines the table sizes in RBD units */
  369. #define RFH_RXF_DMA_RBDCB_SIZE_MASK (0x00F00000) /* bits 20-23 */
  370. #define RFH_RXF_DMA_RBDCB_SIZE_POS 20
  371. #define RFH_RXF_DMA_RBDCB_SIZE_8 (0x3 << RFH_RXF_DMA_RBDCB_SIZE_POS)
  372. #define RFH_RXF_DMA_RBDCB_SIZE_16 (0x4 << RFH_RXF_DMA_RBDCB_SIZE_POS)
  373. #define RFH_RXF_DMA_RBDCB_SIZE_32 (0x5 << RFH_RXF_DMA_RBDCB_SIZE_POS)
  374. #define RFH_RXF_DMA_RBDCB_SIZE_64 (0x7 << RFH_RXF_DMA_RBDCB_SIZE_POS)
  375. #define RFH_RXF_DMA_RBDCB_SIZE_128 (0x7 << RFH_RXF_DMA_RBDCB_SIZE_POS)
  376. #define RFH_RXF_DMA_RBDCB_SIZE_256 (0x8 << RFH_RXF_DMA_RBDCB_SIZE_POS)
  377. #define RFH_RXF_DMA_RBDCB_SIZE_512 (0x9 << RFH_RXF_DMA_RBDCB_SIZE_POS)
  378. #define RFH_RXF_DMA_RBDCB_SIZE_1024 (0xA << RFH_RXF_DMA_RBDCB_SIZE_POS)
  379. #define RFH_RXF_DMA_RBDCB_SIZE_2048 (0xB << RFH_RXF_DMA_RBDCB_SIZE_POS)
  380. #define RFH_RXF_DMA_MIN_RB_SIZE_MASK (0x03000000) /* bit 24-25 */
  381. #define RFH_RXF_DMA_MIN_RB_SIZE_POS 24
  382. #define RFH_RXF_DMA_MIN_RB_4_8 (3 << RFH_RXF_DMA_MIN_RB_SIZE_POS)
  383. #define RFH_RXF_DMA_DROP_TOO_LARGE_MASK (0x04000000) /* bit 26 */
  384. #define RFH_RXF_DMA_SINGLE_FRAME_MASK (0x20000000) /* bit 29 */
  385. #define RFH_DMA_EN_MASK (0xC0000000) /* bits 30-31*/
  386. #define RFH_DMA_EN_ENABLE_VAL BIT(31)
  387. #define RFH_RXF_RXQ_ACTIVE 0xA0980C
  388. #define RFH_GEN_CFG 0xA09800
  389. #define RFH_GEN_CFG_SERVICE_DMA_SNOOP BIT(0)
  390. #define RFH_GEN_CFG_RFH_DMA_SNOOP BIT(1)
  391. #define RFH_GEN_CFG_RB_CHUNK_SIZE BIT(4)
  392. #define RFH_GEN_CFG_RB_CHUNK_SIZE_128 1
  393. #define RFH_GEN_CFG_RB_CHUNK_SIZE_64 0
  394. /* the driver assumes everywhere that the default RXQ is 0 */
  395. #define RFH_GEN_CFG_DEFAULT_RXQ_NUM 0xF00
  396. #define RFH_GEN_CFG_VAL(_n, _v) FIELD_PREP(RFH_GEN_CFG_ ## _n, _v)
  397. /* end of 9000 rx series registers */
  398. /* TFDB Area - TFDs buffer table */
  399. #define FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK (0xFFFFFFFF)
  400. #define FH_TFDIB_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x900)
  401. #define FH_TFDIB_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0x958)
  402. #define FH_TFDIB_CTRL0_REG(_chnl) (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl))
  403. #define FH_TFDIB_CTRL1_REG(_chnl) (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl) + 0x4)
  404. /**
  405. * Transmit DMA Channel Control/Status Registers (TCSR)
  406. *
  407. * Device has one configuration register for each of 8 Tx DMA/FIFO channels
  408. * supported in hardware (don't confuse these with the 16 Tx queues in DRAM,
  409. * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.
  410. *
  411. * To use a Tx DMA channel, driver must initialize its
  412. * FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with:
  413. *
  414. * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  415. * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL
  416. *
  417. * All other bits should be 0.
  418. *
  419. * Bit fields:
  420. * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,
  421. * '10' operate normally
  422. * 29- 4: Reserved, set to "0"
  423. * 3: Enable internal DMA requests (1, normal operation), disable (0)
  424. * 2- 0: Reserved, set to "0"
  425. */
  426. #define FH_TCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
  427. #define FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60)
  428. /* Find Control/Status reg for given Tx DMA/FIFO channel */
  429. #define FH_TCSR_CHNL_NUM (8)
  430. /* TCSR: tx_config register values */
  431. #define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
  432. (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl))
  433. #define FH_TCSR_CHNL_TX_CREDIT_REG(_chnl) \
  434. (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x4)
  435. #define FH_TCSR_CHNL_TX_BUF_STS_REG(_chnl) \
  436. (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x8)
  437. #define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF (0x00000000)
  438. #define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRV (0x00000001)
  439. #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE (0x00000000)
  440. #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE (0x00000008)
  441. #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT (0x00000000)
  442. #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD (0x00100000)
  443. #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000)
  444. #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT (0x00000000)
  445. #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_ENDTFD (0x00400000)
  446. #define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_IFTFD (0x00800000)
  447. #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000)
  448. #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000)
  449. #define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)
  450. #define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY (0x00000000)
  451. #define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT (0x00002000)
  452. #define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00000003)
  453. #define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM (20)
  454. #define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX (12)
  455. /**
  456. * Tx Shared Status Registers (TSSR)
  457. *
  458. * After stopping Tx DMA channel (writing 0 to
  459. * FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll
  460. * FH_TSSR_TX_STATUS_REG until selected Tx channel is idle
  461. * (channel's buffers empty | no pending requests).
  462. *
  463. * Bit fields:
  464. * 31-24: 1 = Channel buffers empty (channel 7:0)
  465. * 23-16: 1 = No pending requests (channel 7:0)
  466. */
  467. #define FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0)
  468. #define FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0)
  469. #define FH_TSSR_TX_STATUS_REG (FH_TSSR_LOWER_BOUND + 0x010)
  470. /**
  471. * Bit fields for TSSR(Tx Shared Status & Control) error status register:
  472. * 31: Indicates an address error when accessed to internal memory
  473. * uCode/driver must write "1" in order to clear this flag
  474. * 30: Indicates that Host did not send the expected number of dwords to FH
  475. * uCode/driver must write "1" in order to clear this flag
  476. * 16-9:Each status bit is for one channel. Indicates that an (Error) ActDMA
  477. * command was received from the scheduler while the TRB was already full
  478. * with previous command
  479. * uCode/driver must write "1" in order to clear this flag
  480. * 7-0: Each status bit indicates a channel's TxCredit error. When an error
  481. * bit is set, it indicates that the FH has received a full indication
  482. * from the RTC TxFIFO and the current value of the TxCredit counter was
  483. * not equal to zero. This mean that the credit mechanism was not
  484. * synchronized to the TxFIFO status
  485. * uCode/driver must write "1" in order to clear this flag
  486. */
  487. #define FH_TSSR_TX_ERROR_REG (FH_TSSR_LOWER_BOUND + 0x018)
  488. #define FH_TSSR_TX_MSG_CONFIG_REG (FH_TSSR_LOWER_BOUND + 0x008)
  489. #define FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) ((1 << (_chnl)) << 16)
  490. /* Tx service channels */
  491. #define FH_SRVC_CHNL (9)
  492. #define FH_SRVC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9C8)
  493. #define FH_SRVC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)
  494. #define FH_SRVC_CHNL_SRAM_ADDR_REG(_chnl) \
  495. (FH_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4)
  496. #define FH_TX_CHICKEN_BITS_REG (FH_MEM_LOWER_BOUND + 0xE98)
  497. #define FH_TX_TRB_REG(_chan) (FH_MEM_LOWER_BOUND + 0x958 + (_chan) * 4)
  498. /* Instruct FH to increment the retry count of a packet when
  499. * it is brought from the memory to TX-FIFO
  500. */
  501. #define FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN (0x00000002)
  502. #define RX_POOL_SIZE(rbds) ((rbds) - 1 + \
  503. IWL_MAX_RX_HW_QUEUES * \
  504. (RX_CLAIM_REQ_ALLOC - RX_POST_REQ_ALLOC))
  505. /* cb size is the exponent */
  506. #define RX_QUEUE_CB_SIZE(x) ilog2(x)
  507. #define RX_QUEUE_SIZE 256
  508. #define RX_QUEUE_MASK 255
  509. #define RX_QUEUE_SIZE_LOG 8
  510. /**
  511. * struct iwl_rb_status - reserve buffer status
  512. * host memory mapped FH registers
  513. * @closed_rb_num [0:11] - Indicates the index of the RB which was closed
  514. * @closed_fr_num [0:11] - Indicates the index of the RX Frame which was closed
  515. * @finished_rb_num [0:11] - Indicates the index of the current RB
  516. * in which the last frame was written to
  517. * @finished_fr_num [0:11] - Indicates the index of the RX Frame
  518. * which was transferred
  519. */
  520. struct iwl_rb_status {
  521. __le16 closed_rb_num;
  522. __le16 closed_fr_num;
  523. __le16 finished_rb_num;
  524. __le16 finished_fr_nam;
  525. __le32 __spare;
  526. } __packed;
  527. #define TFD_QUEUE_SIZE_MAX (256)
  528. #define TFD_QUEUE_SIZE_MAX_GEN3 (65536)
  529. /* cb size is the exponent - 3 */
  530. #define TFD_QUEUE_CB_SIZE(x) (ilog2(x) - 3)
  531. #define TFD_QUEUE_SIZE_BC_DUP (64)
  532. #define TFD_QUEUE_BC_SIZE (TFD_QUEUE_SIZE_MAX + TFD_QUEUE_SIZE_BC_DUP)
  533. #define TFD_QUEUE_BC_SIZE_GEN3_AX210 1024
  534. #define TFD_QUEUE_BC_SIZE_GEN3_BZ (1024 * 4)
  535. #define IWL_TX_DMA_MASK DMA_BIT_MASK(36)
  536. #define IWL_NUM_OF_TBS 20
  537. #define IWL_TFH_NUM_TBS 25
  538. /* IMR DMA registers */
  539. #define IMR_TFH_SRV_DMA_CHNL0_CTRL 0x00a0a51c
  540. #define IMR_TFH_SRV_DMA_CHNL0_SRAM_ADDR 0x00a0a520
  541. #define IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_LSB 0x00a0a524
  542. #define IMR_TFH_SRV_DMA_CHNL0_DRAM_ADDR_MSB 0x00a0a528
  543. #define IMR_TFH_SRV_DMA_CHNL0_BC 0x00a0a52c
  544. #define TFH_SRV_DMA_CHNL0_LEFT_BC 0x00a0a530
  545. /* RFH S2D DMA registers */
  546. #define IMR_RFH_GEN_CFG_SERVICE_DMA_RS_MSK 0x0000000c
  547. #define IMR_RFH_GEN_CFG_SERVICE_DMA_SNOOP_MSK 0x00000002
  548. /* TFH D2S DMA registers */
  549. #define IMR_UREG_CHICK_HALT_UMAC_PERMANENTLY_MSK 0x80000000
  550. #define IMR_UREG_CHICK 0x00d05c00
  551. #define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_IRQ_TARGET_POS 0x00800000
  552. #define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_RS_MSK 0x00000030
  553. #define IMR_TFH_SRV_DMA_CHNL0_CTRL_D2S_DMA_EN_POS 0x80000000
  554. static inline u8 iwl_get_dma_hi_addr(dma_addr_t addr)
  555. {
  556. return (sizeof(addr) > sizeof(u32) ? upper_32_bits(addr) : 0) & 0xF;
  557. }
  558. /**
  559. * enum iwl_tfd_tb_hi_n_len - TB hi_n_len bits
  560. * @TB_HI_N_LEN_ADDR_HI_MSK: high 4 bits (to make it 36) of DMA address
  561. * @TB_HI_N_LEN_LEN_MSK: length of the TB
  562. */
  563. enum iwl_tfd_tb_hi_n_len {
  564. TB_HI_N_LEN_ADDR_HI_MSK = 0xf,
  565. TB_HI_N_LEN_LEN_MSK = 0xfff0,
  566. };
  567. /**
  568. * struct iwl_tfd_tb transmit buffer descriptor within transmit frame descriptor
  569. *
  570. * This structure contains dma address and length of transmission address
  571. *
  572. * @lo: low [31:0] portion of the dma address of TX buffer
  573. * every even is unaligned on 16 bit boundary
  574. * @hi_n_len: &enum iwl_tfd_tb_hi_n_len
  575. */
  576. struct iwl_tfd_tb {
  577. __le32 lo;
  578. __le16 hi_n_len;
  579. } __packed;
  580. /**
  581. * struct iwl_tfh_tb transmit buffer descriptor within transmit frame descriptor
  582. *
  583. * This structure contains dma address and length of transmission address
  584. *
  585. * @tb_len length of the tx buffer
  586. * @addr 64 bits dma address
  587. */
  588. struct iwl_tfh_tb {
  589. __le16 tb_len;
  590. __le64 addr;
  591. } __packed;
  592. /**
  593. * Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM.
  594. * Both driver and device share these circular buffers, each of which must be
  595. * contiguous 256 TFDs.
  596. * For pre 22000 HW it is 256 x 128 bytes-per-TFD = 32 KBytes
  597. * For 22000 HW and on it is 256 x 256 bytes-per-TFD = 65 KBytes
  598. *
  599. * Driver must indicate the physical address of the base of each
  600. * circular buffer via the FH_MEM_CBBC_QUEUE registers.
  601. *
  602. * Each TFD contains pointer/size information for up to 20 / 25 data buffers
  603. * in host DRAM. These buffers collectively contain the (one) frame described
  604. * by the TFD. Each buffer must be a single contiguous block of memory within
  605. * itself, but buffers may be scattered in host DRAM. Each buffer has max size
  606. * of (4K - 4). The concatenates all of a TFD's buffers into a single
  607. * Tx frame, up to 8 KBytes in size.
  608. *
  609. * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.
  610. */
  611. /**
  612. * struct iwl_tfd - Transmit Frame Descriptor (TFD)
  613. * @ __reserved1[3] reserved
  614. * @ num_tbs 0-4 number of active tbs
  615. * 5 reserved
  616. * 6-7 padding (not used)
  617. * @ tbs[20] transmit frame buffer descriptors
  618. * @ __pad padding
  619. */
  620. struct iwl_tfd {
  621. u8 __reserved1[3];
  622. u8 num_tbs;
  623. struct iwl_tfd_tb tbs[IWL_NUM_OF_TBS];
  624. __le32 __pad;
  625. } __packed;
  626. /**
  627. * struct iwl_tfh_tfd - Transmit Frame Descriptor (TFD)
  628. * @ num_tbs 0-4 number of active tbs
  629. * 5 -15 reserved
  630. * @ tbs[25] transmit frame buffer descriptors
  631. * @ __pad padding
  632. */
  633. struct iwl_tfh_tfd {
  634. __le16 num_tbs;
  635. struct iwl_tfh_tb tbs[IWL_TFH_NUM_TBS];
  636. __le32 __pad;
  637. } __packed;
  638. /* Keep Warm Size */
  639. #define IWL_KW_SIZE 0x1000 /* 4k */
  640. /* Fixed (non-configurable) rx data from phy */
  641. /**
  642. * struct iwlagn_schedq_bc_tbl scheduler byte count table
  643. * base physical address provided by SCD_DRAM_BASE_ADDR
  644. * For devices up to 22000:
  645. * @tfd_offset 0-12 - tx command byte count
  646. * 12-16 - station index
  647. * For 22000:
  648. * @tfd_offset 0-12 - tx command byte count
  649. * 12-13 - number of 64 byte chunks
  650. * 14-16 - reserved
  651. */
  652. struct iwlagn_scd_bc_tbl {
  653. __le16 tfd_offset[TFD_QUEUE_BC_SIZE];
  654. } __packed;
  655. /**
  656. * struct iwl_gen3_bc_tbl_entry scheduler byte count table entry gen3
  657. * For AX210 and on:
  658. * @tfd_offset: 0-12 - tx command byte count
  659. * 12-13 - number of 64 byte chunks
  660. * 14-16 - reserved
  661. */
  662. struct iwl_gen3_bc_tbl_entry {
  663. __le16 tfd_offset;
  664. } __packed;
  665. #endif /* !__iwl_fh_h__ */