iwl-fh.h 30 KB

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