iwl-fh.h 30 KB

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