iwl-fh.h 29 KB

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