txrx.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * Copyright (c) 2012-2016 Qualcomm Atheros, Inc.
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef WIL6210_TXRX_H
  18. #define WIL6210_TXRX_H
  19. #include "wil6210.h"
  20. #include "txrx_edma.h"
  21. #define BUF_SW_OWNED (1)
  22. #define BUF_HW_OWNED (0)
  23. /* default size of MAC Tx/Rx buffers */
  24. #define TXRX_BUF_LEN_DEFAULT (2048)
  25. /* how many bytes to reserve for rtap header? */
  26. #define WIL6210_RTAP_SIZE (128)
  27. /* Tx/Rx path */
  28. static inline dma_addr_t wil_desc_addr(struct wil_ring_dma_addr *addr)
  29. {
  30. return le32_to_cpu(addr->addr_low) |
  31. ((u64)le16_to_cpu(addr->addr_high) << 32);
  32. }
  33. static inline void wil_desc_addr_set(struct wil_ring_dma_addr *addr,
  34. dma_addr_t pa)
  35. {
  36. addr->addr_low = cpu_to_le32(lower_32_bits(pa));
  37. addr->addr_high = cpu_to_le16((u16)upper_32_bits(pa));
  38. }
  39. /* Tx descriptor - MAC part
  40. * [dword 0]
  41. * bit 0.. 9 : lifetime_expiry_value:10
  42. * bit 10 : interrupt_en:1
  43. * bit 11 : status_en:1
  44. * bit 12..13 : txss_override:2
  45. * bit 14 : timestamp_insertion:1
  46. * bit 15 : duration_preserve:1
  47. * bit 16..21 : reserved0:6
  48. * bit 22..26 : mcs_index:5
  49. * bit 27 : mcs_en:1
  50. * bit 28..30 : reserved1:3
  51. * bit 31 : sn_preserved:1
  52. * [dword 1]
  53. * bit 0.. 3 : pkt_mode:4
  54. * bit 4 : pkt_mode_en:1
  55. * bit 5 : mac_id_en:1
  56. * bit 6..7 : mac_id:2
  57. * bit 8..14 : reserved0:7
  58. * bit 15 : ack_policy_en:1
  59. * bit 16..19 : dst_index:4
  60. * bit 20 : dst_index_en:1
  61. * bit 21..22 : ack_policy:2
  62. * bit 23 : lifetime_en:1
  63. * bit 24..30 : max_retry:7
  64. * bit 31 : max_retry_en:1
  65. * [dword 2]
  66. * bit 0.. 7 : num_of_descriptors:8
  67. * bit 8..17 : reserved:10
  68. * bit 18..19 : l2_translation_type:2 00 - bypass, 01 - 802.3, 10 - 802.11
  69. * bit 20 : snap_hdr_insertion_en:1
  70. * bit 21 : vlan_removal_en:1
  71. * bit 22..31 : reserved0:10
  72. * [dword 3]
  73. * bit 0.. 31: ucode_cmd:32
  74. */
  75. struct vring_tx_mac {
  76. u32 d[3];
  77. u32 ucode_cmd;
  78. } __packed;
  79. /* TX MAC Dword 0 */
  80. #define MAC_CFG_DESC_TX_0_LIFETIME_EXPIRY_VALUE_POS 0
  81. #define MAC_CFG_DESC_TX_0_LIFETIME_EXPIRY_VALUE_LEN 10
  82. #define MAC_CFG_DESC_TX_0_LIFETIME_EXPIRY_VALUE_MSK 0x3FF
  83. #define MAC_CFG_DESC_TX_0_INTERRUP_EN_POS 10
  84. #define MAC_CFG_DESC_TX_0_INTERRUP_EN_LEN 1
  85. #define MAC_CFG_DESC_TX_0_INTERRUP_EN_MSK 0x400
  86. #define MAC_CFG_DESC_TX_0_STATUS_EN_POS 11
  87. #define MAC_CFG_DESC_TX_0_STATUS_EN_LEN 1
  88. #define MAC_CFG_DESC_TX_0_STATUS_EN_MSK 0x800
  89. #define MAC_CFG_DESC_TX_0_TXSS_OVERRIDE_POS 12
  90. #define MAC_CFG_DESC_TX_0_TXSS_OVERRIDE_LEN 2
  91. #define MAC_CFG_DESC_TX_0_TXSS_OVERRIDE_MSK 0x3000
  92. #define MAC_CFG_DESC_TX_0_TIMESTAMP_INSERTION_POS 14
  93. #define MAC_CFG_DESC_TX_0_TIMESTAMP_INSERTION_LEN 1
  94. #define MAC_CFG_DESC_TX_0_TIMESTAMP_INSERTION_MSK 0x4000
  95. #define MAC_CFG_DESC_TX_0_DURATION_PRESERVE_POS 15
  96. #define MAC_CFG_DESC_TX_0_DURATION_PRESERVE_LEN 1
  97. #define MAC_CFG_DESC_TX_0_DURATION_PRESERVE_MSK 0x8000
  98. #define MAC_CFG_DESC_TX_0_MCS_INDEX_POS 22
  99. #define MAC_CFG_DESC_TX_0_MCS_INDEX_LEN 5
  100. #define MAC_CFG_DESC_TX_0_MCS_INDEX_MSK 0x7C00000
  101. #define MAC_CFG_DESC_TX_0_MCS_EN_POS 27
  102. #define MAC_CFG_DESC_TX_0_MCS_EN_LEN 1
  103. #define MAC_CFG_DESC_TX_0_MCS_EN_MSK 0x8000000
  104. #define MAC_CFG_DESC_TX_0_SN_PRESERVED_POS 31
  105. #define MAC_CFG_DESC_TX_0_SN_PRESERVED_LEN 1
  106. #define MAC_CFG_DESC_TX_0_SN_PRESERVED_MSK 0x80000000
  107. /* TX MAC Dword 1 */
  108. #define MAC_CFG_DESC_TX_1_PKT_MODE_POS 0
  109. #define MAC_CFG_DESC_TX_1_PKT_MODE_LEN 4
  110. #define MAC_CFG_DESC_TX_1_PKT_MODE_MSK 0xF
  111. #define MAC_CFG_DESC_TX_1_PKT_MODE_EN_POS 4
  112. #define MAC_CFG_DESC_TX_1_PKT_MODE_EN_LEN 1
  113. #define MAC_CFG_DESC_TX_1_PKT_MODE_EN_MSK 0x10
  114. #define MAC_CFG_DESC_TX_1_MAC_ID_EN_POS 5
  115. #define MAC_CFG_DESC_TX_1_MAC_ID_EN_LEN 1
  116. #define MAC_CFG_DESC_TX_1_MAC_ID_EN_MSK 0x20
  117. #define MAC_CFG_DESC_TX_1_MAC_ID_POS 6
  118. #define MAC_CFG_DESC_TX_1_MAC_ID_LEN 2
  119. #define MAC_CFG_DESC_TX_1_MAC_ID_MSK 0xc0
  120. #define MAC_CFG_DESC_TX_1_ACK_POLICY_EN_POS 15
  121. #define MAC_CFG_DESC_TX_1_ACK_POLICY_EN_LEN 1
  122. #define MAC_CFG_DESC_TX_1_ACK_POLICY_EN_MSK 0x8000
  123. #define MAC_CFG_DESC_TX_1_DST_INDEX_POS 16
  124. #define MAC_CFG_DESC_TX_1_DST_INDEX_LEN 4
  125. #define MAC_CFG_DESC_TX_1_DST_INDEX_MSK 0xF0000
  126. #define MAC_CFG_DESC_TX_1_DST_INDEX_EN_POS 20
  127. #define MAC_CFG_DESC_TX_1_DST_INDEX_EN_LEN 1
  128. #define MAC_CFG_DESC_TX_1_DST_INDEX_EN_MSK 0x100000
  129. #define MAC_CFG_DESC_TX_1_ACK_POLICY_POS 21
  130. #define MAC_CFG_DESC_TX_1_ACK_POLICY_LEN 2
  131. #define MAC_CFG_DESC_TX_1_ACK_POLICY_MSK 0x600000
  132. #define MAC_CFG_DESC_TX_1_LIFETIME_EN_POS 23
  133. #define MAC_CFG_DESC_TX_1_LIFETIME_EN_LEN 1
  134. #define MAC_CFG_DESC_TX_1_LIFETIME_EN_MSK 0x800000
  135. #define MAC_CFG_DESC_TX_1_MAX_RETRY_POS 24
  136. #define MAC_CFG_DESC_TX_1_MAX_RETRY_LEN 7
  137. #define MAC_CFG_DESC_TX_1_MAX_RETRY_MSK 0x7F000000
  138. #define MAC_CFG_DESC_TX_1_MAX_RETRY_EN_POS 31
  139. #define MAC_CFG_DESC_TX_1_MAX_RETRY_EN_LEN 1
  140. #define MAC_CFG_DESC_TX_1_MAX_RETRY_EN_MSK 0x80000000
  141. /* TX MAC Dword 2 */
  142. #define MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS 0
  143. #define MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_LEN 8
  144. #define MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_MSK 0xFF
  145. #define MAC_CFG_DESC_TX_2_RESERVED_POS 8
  146. #define MAC_CFG_DESC_TX_2_RESERVED_LEN 10
  147. #define MAC_CFG_DESC_TX_2_RESERVED_MSK 0x3FF00
  148. #define MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_POS 18
  149. #define MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_LEN 2
  150. #define MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_MSK 0xC0000
  151. #define MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_POS 20
  152. #define MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_LEN 1
  153. #define MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_MSK 0x100000
  154. #define MAC_CFG_DESC_TX_2_VLAN_REMOVAL_EN_POS 21
  155. #define MAC_CFG_DESC_TX_2_VLAN_REMOVAL_EN_LEN 1
  156. #define MAC_CFG_DESC_TX_2_VLAN_REMOVAL_EN_MSK 0x200000
  157. /* TX MAC Dword 3 */
  158. #define MAC_CFG_DESC_TX_3_UCODE_CMD_POS 0
  159. #define MAC_CFG_DESC_TX_3_UCODE_CMD_LEN 32
  160. #define MAC_CFG_DESC_TX_3_UCODE_CMD_MSK 0xFFFFFFFF
  161. /* TX DMA Dword 0 */
  162. #define DMA_CFG_DESC_TX_0_L4_LENGTH_POS 0
  163. #define DMA_CFG_DESC_TX_0_L4_LENGTH_LEN 8
  164. #define DMA_CFG_DESC_TX_0_L4_LENGTH_MSK 0xFF
  165. #define DMA_CFG_DESC_TX_0_CMD_EOP_POS 8
  166. #define DMA_CFG_DESC_TX_0_CMD_EOP_LEN 1
  167. #define DMA_CFG_DESC_TX_0_CMD_EOP_MSK 0x100
  168. #define DMA_CFG_DESC_TX_0_CMD_MARK_WB_POS 9
  169. #define DMA_CFG_DESC_TX_0_CMD_MARK_WB_LEN 1
  170. #define DMA_CFG_DESC_TX_0_CMD_MARK_WB_MSK 0x200
  171. #define DMA_CFG_DESC_TX_0_CMD_DMA_IT_POS 10
  172. #define DMA_CFG_DESC_TX_0_CMD_DMA_IT_LEN 1
  173. #define DMA_CFG_DESC_TX_0_CMD_DMA_IT_MSK 0x400
  174. #define DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_POS 11
  175. #define DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_LEN 2
  176. #define DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_MSK 0x1800
  177. #define DMA_CFG_DESC_TX_0_TCP_SEG_EN_POS 13
  178. #define DMA_CFG_DESC_TX_0_TCP_SEG_EN_LEN 1
  179. #define DMA_CFG_DESC_TX_0_TCP_SEG_EN_MSK 0x2000
  180. #define DMA_CFG_DESC_TX_0_IPV4_CHECKSUM_EN_POS 14
  181. #define DMA_CFG_DESC_TX_0_IPV4_CHECKSUM_EN_LEN 1
  182. #define DMA_CFG_DESC_TX_0_IPV4_CHECKSUM_EN_MSK 0x4000
  183. #define DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS 15
  184. #define DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_LEN 1
  185. #define DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_MSK 0x8000
  186. #define DMA_CFG_DESC_TX_0_QID_POS 16
  187. #define DMA_CFG_DESC_TX_0_QID_LEN 5
  188. #define DMA_CFG_DESC_TX_0_QID_MSK 0x1F0000
  189. #define DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS 21
  190. #define DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_LEN 1
  191. #define DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_MSK 0x200000
  192. #define DMA_CFG_DESC_TX_0_L4_TYPE_POS 30
  193. #define DMA_CFG_DESC_TX_0_L4_TYPE_LEN 2
  194. #define DMA_CFG_DESC_TX_0_L4_TYPE_MSK 0xC0000000 /* L4 type: 0-UDP, 2-TCP */
  195. #define DMA_CFG_DESC_TX_OFFLOAD_CFG_MAC_LEN_POS 0
  196. #define DMA_CFG_DESC_TX_OFFLOAD_CFG_MAC_LEN_LEN 7
  197. #define DMA_CFG_DESC_TX_OFFLOAD_CFG_MAC_LEN_MSK 0x7F /* MAC hdr len */
  198. #define DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_POS 7
  199. #define DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_LEN 1
  200. #define DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_MSK 0x80 /* 1-IPv4, 0-IPv6 */
  201. #define TX_DMA_STATUS_DU BIT(0)
  202. /* Tx descriptor - DMA part
  203. * [dword 0]
  204. * bit 0.. 7 : l4_length:8 layer 4 length
  205. * bit 8 : cmd_eop:1 This descriptor is the last one in the packet
  206. * bit 9 : reserved
  207. * bit 10 : cmd_dma_it:1 immediate interrupt
  208. * bit 11..12 : SBD - Segment Buffer Details
  209. * 00 - Header Segment
  210. * 01 - First Data Segment
  211. * 10 - Medium Data Segment
  212. * 11 - Last Data Segment
  213. * bit 13 : TSE - TCP Segmentation Enable
  214. * bit 14 : IIC - Directs the HW to Insert IPv4 Checksum
  215. * bit 15 : ITC - Directs the HW to Insert TCP/UDP Checksum
  216. * bit 16..20 : QID - The target QID that the packet should be stored
  217. * in the MAC.
  218. * bit 21 : PO - Pseudo header Offload:
  219. * 0 - Use the pseudo header value from the TCP checksum field
  220. * 1- Calculate Pseudo header Checksum
  221. * bit 22 : NC - No UDP Checksum
  222. * bit 23..29 : reserved
  223. * bit 30..31 : L4T - Layer 4 Type: 00 - UDP , 10 - TCP , 10, 11 - Reserved
  224. * If L4Len equal 0, no L4 at all
  225. * [dword 1]
  226. * bit 0..31 : addr_low:32 The payload buffer low address
  227. * [dword 2]
  228. * bit 0..15 : addr_high:16 The payload buffer high address
  229. * bit 16..23 : ip_length:8 The IP header length for the TX IP checksum
  230. * offload feature
  231. * bit 24..30 : mac_length:7
  232. * bit 31 : ip_version:1 1 - IPv4, 0 - IPv6
  233. * [dword 3]
  234. * [byte 12] error
  235. * bit 0 2 : mac_status:3
  236. * bit 3 7 : reserved:5
  237. * [byte 13] status
  238. * bit 0 : DU:1 Descriptor Used
  239. * bit 1 7 : reserved:7
  240. * [word 7] length
  241. */
  242. struct vring_tx_dma {
  243. u32 d0;
  244. struct wil_ring_dma_addr addr;
  245. u8 ip_length;
  246. u8 b11; /* 0..6: mac_length; 7:ip_version */
  247. u8 error; /* 0..2: err; 3..7: reserved; */
  248. u8 status; /* 0: used; 1..7; reserved */
  249. __le16 length;
  250. } __packed;
  251. /* TSO type used in dma descriptor d0 bits 11-12 */
  252. enum {
  253. wil_tso_type_hdr = 0,
  254. wil_tso_type_first = 1,
  255. wil_tso_type_mid = 2,
  256. wil_tso_type_lst = 3,
  257. };
  258. /* Rx descriptor - MAC part
  259. * [dword 0]
  260. * bit 0.. 3 : tid:4 The QoS (b3-0) TID Field
  261. * bit 4.. 6 : cid:3 The Source index that was found during parsing the TA.
  262. * This field is used to define the source of the packet
  263. * bit 7 : MAC_id_valid:1, 1 if MAC virtual number is valid.
  264. * bit 8.. 9 : mid:2 The MAC virtual number
  265. * bit 10..11 : frame_type:2 : The FC (b3-2) - MPDU Type
  266. * (management, data, control and extension)
  267. * bit 12..15 : frame_subtype:4 : The FC (b7-4) - Frame Subtype
  268. * bit 16..27 : seq_number:12 The received Sequence number field
  269. * bit 28..31 : extended:4 extended subtype
  270. * [dword 1]
  271. * bit 0.. 3 : reserved
  272. * bit 4.. 5 : key_id:2
  273. * bit 6 : decrypt_bypass:1
  274. * bit 7 : security:1 FC (b14)
  275. * bit 8.. 9 : ds_bits:2 FC (b9-8)
  276. * bit 10 : a_msdu_present:1 QoS (b7)
  277. * bit 11 : a_msdu_type:1 QoS (b8)
  278. * bit 12 : a_mpdu:1 part of AMPDU aggregation
  279. * bit 13 : broadcast:1
  280. * bit 14 : mutlicast:1
  281. * bit 15 : reserved:1
  282. * bit 16..20 : rx_mac_qid:5 The Queue Identifier that the packet
  283. * is received from
  284. * bit 21..24 : mcs:4
  285. * bit 25..28 : mic_icr:4 this signal tells the DMA to assert an interrupt
  286. * after it writes the packet
  287. * bit 29..31 : reserved:3
  288. * [dword 2]
  289. * bit 0.. 2 : time_slot:3 The timeslot that the MPDU is received
  290. * bit 3.. 4 : fc_protocol_ver:1 The FC (b1-0) - Protocol Version
  291. * bit 5 : fc_order:1 The FC Control (b15) -Order
  292. * bit 6.. 7 : qos_ack_policy:2 The QoS (b6-5) ack policy Field
  293. * bit 8 : esop:1 The QoS (b4) ESOP field
  294. * bit 9 : qos_rdg_more_ppdu:1 The QoS (b9) RDG field
  295. * bit 10..14 : qos_reserved:5 The QoS (b14-10) Reserved field
  296. * bit 15 : qos_ac_constraint:1 QoS (b15)
  297. * bit 16..31 : pn_15_0:16 low 2 bytes of PN
  298. * [dword 3]
  299. * bit 0..31 : pn_47_16:32 high 4 bytes of PN
  300. */
  301. struct vring_rx_mac {
  302. u32 d0;
  303. u32 d1;
  304. u16 w4;
  305. u16 pn_15_0;
  306. u32 pn_47_16;
  307. } __packed;
  308. /* Rx descriptor - DMA part
  309. * [dword 0]
  310. * bit 0.. 7 : l4_length:8 layer 4 length. The field is only valid if
  311. * L4I bit is set
  312. * bit 8 : cmd_eop:1 set to 1
  313. * bit 9 : cmd_rt:1 set to 1
  314. * bit 10 : cmd_dma_it:1 immediate interrupt
  315. * bit 11..15 : reserved:5
  316. * bit 16..29 : phy_info_length:14 It is valid when the PII is set.
  317. * When the FFM bit is set bits 29-27 are used for for
  318. * Flex Filter Match. Matching Index to one of the L2
  319. * EtherType Flex Filter
  320. * bit 30..31 : l4_type:2 valid if the L4I bit is set in the status field
  321. * 00 - UDP, 01 - TCP, 10, 11 - reserved
  322. * [dword 1]
  323. * bit 0..31 : addr_low:32 The payload buffer low address
  324. * [dword 2]
  325. * bit 0..15 : addr_high:16 The payload buffer high address
  326. * bit 16..23 : ip_length:8 The filed is valid only if the L3I bit is set
  327. * bit 24..30 : mac_length:7
  328. * bit 31 : ip_version:1 1 - IPv4, 0 - IPv6
  329. * [dword 3]
  330. * [byte 12] error
  331. * bit 0 : FCS:1
  332. * bit 1 : MIC:1
  333. * bit 2 : Key miss:1
  334. * bit 3 : Replay:1
  335. * bit 4 : L3:1 IPv4 checksum
  336. * bit 5 : L4:1 TCP/UDP checksum
  337. * bit 6 7 : reserved:2
  338. * [byte 13] status
  339. * bit 0 : DU:1 Descriptor Used
  340. * bit 1 : EOP:1 The descriptor indicates the End of Packet
  341. * bit 2 : error:1
  342. * bit 3 : MI:1 MAC Interrupt is asserted (according to parser decision)
  343. * bit 4 : L3I:1 L3 identified and checksum calculated
  344. * bit 5 : L4I:1 L4 identified and checksum calculated
  345. * bit 6 : PII:1 PHY Info Included in the packet
  346. * bit 7 : FFM:1 EtherType Flex Filter Match
  347. * [word 7] length
  348. */
  349. #define RX_DMA_D0_CMD_DMA_EOP BIT(8)
  350. #define RX_DMA_D0_CMD_DMA_RT BIT(9) /* always 1 */
  351. #define RX_DMA_D0_CMD_DMA_IT BIT(10) /* interrupt */
  352. #define RX_MAC_D0_MAC_ID_VALID BIT(7)
  353. /* Error field */
  354. #define RX_DMA_ERROR_FCS BIT(0)
  355. #define RX_DMA_ERROR_MIC BIT(1)
  356. #define RX_DMA_ERROR_KEY BIT(2) /* Key missing */
  357. #define RX_DMA_ERROR_REPLAY BIT(3)
  358. #define RX_DMA_ERROR_L3_ERR BIT(4)
  359. #define RX_DMA_ERROR_L4_ERR BIT(5)
  360. /* Status field */
  361. #define RX_DMA_STATUS_DU BIT(0)
  362. #define RX_DMA_STATUS_EOP BIT(1)
  363. #define RX_DMA_STATUS_ERROR BIT(2)
  364. #define RX_DMA_STATUS_MI BIT(3) /* MAC Interrupt is asserted */
  365. #define RX_DMA_STATUS_L3I BIT(4)
  366. #define RX_DMA_STATUS_L4I BIT(5)
  367. #define RX_DMA_STATUS_PHY_INFO BIT(6)
  368. #define RX_DMA_STATUS_FFM BIT(7) /* EtherType Flex Filter Match */
  369. struct vring_rx_dma {
  370. u32 d0;
  371. struct wil_ring_dma_addr addr;
  372. u8 ip_length;
  373. u8 b11;
  374. u8 error;
  375. u8 status;
  376. __le16 length;
  377. } __packed;
  378. struct vring_tx_desc {
  379. struct vring_tx_mac mac;
  380. struct vring_tx_dma dma;
  381. } __packed;
  382. union wil_tx_desc {
  383. struct vring_tx_desc legacy;
  384. struct wil_tx_enhanced_desc enhanced;
  385. } __packed;
  386. struct vring_rx_desc {
  387. struct vring_rx_mac mac;
  388. struct vring_rx_dma dma;
  389. } __packed;
  390. union wil_rx_desc {
  391. struct vring_rx_desc legacy;
  392. struct wil_rx_enhanced_desc enhanced;
  393. } __packed;
  394. union wil_ring_desc {
  395. union wil_tx_desc tx;
  396. union wil_rx_desc rx;
  397. } __packed;
  398. static inline int wil_rxdesc_tid(struct vring_rx_desc *d)
  399. {
  400. return WIL_GET_BITS(d->mac.d0, 0, 3);
  401. }
  402. static inline int wil_rxdesc_cid(struct vring_rx_desc *d)
  403. {
  404. return WIL_GET_BITS(d->mac.d0, 4, 6);
  405. }
  406. static inline int wil_rxdesc_mid(struct vring_rx_desc *d)
  407. {
  408. return (d->mac.d0 & RX_MAC_D0_MAC_ID_VALID) ?
  409. WIL_GET_BITS(d->mac.d0, 8, 9) : 0;
  410. }
  411. static inline int wil_rxdesc_ftype(struct vring_rx_desc *d)
  412. {
  413. return WIL_GET_BITS(d->mac.d0, 10, 11);
  414. }
  415. static inline int wil_rxdesc_subtype(struct vring_rx_desc *d)
  416. {
  417. return WIL_GET_BITS(d->mac.d0, 12, 15);
  418. }
  419. /* 1-st byte (with frame type/subtype) of FC field */
  420. static inline u8 wil_rxdesc_fc1(struct vring_rx_desc *d)
  421. {
  422. return (u8)(WIL_GET_BITS(d->mac.d0, 10, 15) << 2);
  423. }
  424. static inline int wil_rxdesc_seq(struct vring_rx_desc *d)
  425. {
  426. return WIL_GET_BITS(d->mac.d0, 16, 27);
  427. }
  428. static inline int wil_rxdesc_ext_subtype(struct vring_rx_desc *d)
  429. {
  430. return WIL_GET_BITS(d->mac.d0, 28, 31);
  431. }
  432. static inline int wil_rxdesc_retry(struct vring_rx_desc *d)
  433. {
  434. return WIL_GET_BITS(d->mac.d0, 31, 31);
  435. }
  436. static inline int wil_rxdesc_key_id(struct vring_rx_desc *d)
  437. {
  438. return WIL_GET_BITS(d->mac.d1, 4, 5);
  439. }
  440. static inline int wil_rxdesc_security(struct vring_rx_desc *d)
  441. {
  442. return WIL_GET_BITS(d->mac.d1, 7, 7);
  443. }
  444. static inline int wil_rxdesc_ds_bits(struct vring_rx_desc *d)
  445. {
  446. return WIL_GET_BITS(d->mac.d1, 8, 9);
  447. }
  448. static inline int wil_rxdesc_mcs(struct vring_rx_desc *d)
  449. {
  450. return WIL_GET_BITS(d->mac.d1, 21, 24);
  451. }
  452. static inline int wil_rxdesc_mcast(struct vring_rx_desc *d)
  453. {
  454. return WIL_GET_BITS(d->mac.d1, 13, 14);
  455. }
  456. static inline int wil_rxdesc_phy_length(struct vring_rx_desc *d)
  457. {
  458. return WIL_GET_BITS(d->dma.d0, 16, 29);
  459. }
  460. static inline struct vring_rx_desc *wil_skb_rxdesc(struct sk_buff *skb)
  461. {
  462. return (void *)skb->cb;
  463. }
  464. static inline int wil_ring_is_empty(struct wil_ring *ring)
  465. {
  466. return ring->swhead == ring->swtail;
  467. }
  468. static inline u32 wil_ring_next_tail(struct wil_ring *ring)
  469. {
  470. return (ring->swtail + 1) % ring->size;
  471. }
  472. static inline void wil_ring_advance_head(struct wil_ring *ring, int n)
  473. {
  474. ring->swhead = (ring->swhead + n) % ring->size;
  475. }
  476. static inline int wil_ring_is_full(struct wil_ring *ring)
  477. {
  478. return wil_ring_next_tail(ring) == ring->swhead;
  479. }
  480. static inline bool wil_need_txstat(struct sk_buff *skb)
  481. {
  482. struct ethhdr *eth = (void *)skb->data;
  483. return is_unicast_ether_addr(eth->h_dest) && skb->sk &&
  484. (skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS);
  485. }
  486. static inline void wil_consume_skb(struct sk_buff *skb, bool acked)
  487. {
  488. if (unlikely(wil_need_txstat(skb)))
  489. skb_complete_wifi_ack(skb, acked);
  490. else
  491. acked ? dev_consume_skb_any(skb) : dev_kfree_skb_any(skb);
  492. }
  493. /* Used space in Tx ring */
  494. static inline int wil_ring_used_tx(struct wil_ring *ring)
  495. {
  496. u32 swhead = ring->swhead;
  497. u32 swtail = ring->swtail;
  498. return (ring->size + swhead - swtail) % ring->size;
  499. }
  500. /* Available space in Tx ring */
  501. static inline int wil_ring_avail_tx(struct wil_ring *ring)
  502. {
  503. return ring->size - wil_ring_used_tx(ring) - 1;
  504. }
  505. static inline int wil_get_min_tx_ring_id(struct wil6210_priv *wil)
  506. {
  507. /* In Enhanced DMA ring 0 is reserved for RX */
  508. return wil->use_enhanced_dma_hw ? 1 : 0;
  509. }
  510. /* similar to ieee80211_ version, but FC contain only 1-st byte */
  511. static inline int wil_is_back_req(u8 fc)
  512. {
  513. return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  514. (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ);
  515. }
  516. /* wil_val_in_range - check if value in [min,max) */
  517. static inline bool wil_val_in_range(int val, int min, int max)
  518. {
  519. return val >= min && val < max;
  520. }
  521. void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev);
  522. void wil_rx_reorder(struct wil6210_priv *wil, struct sk_buff *skb);
  523. void wil_rx_bar(struct wil6210_priv *wil, struct wil6210_vif *vif,
  524. u8 cid, u8 tid, u16 seq);
  525. struct wil_tid_ampdu_rx *wil_tid_ampdu_rx_alloc(struct wil6210_priv *wil,
  526. int size, u16 ssn);
  527. void wil_tid_ampdu_rx_free(struct wil6210_priv *wil,
  528. struct wil_tid_ampdu_rx *r);
  529. void wil_tx_data_init(struct wil_ring_tx_data *txdata);
  530. void wil_init_txrx_ops_legacy_dma(struct wil6210_priv *wil);
  531. void wil_tx_latency_calc(struct wil6210_priv *wil, struct sk_buff *skb,
  532. struct wil_sta_info *sta);
  533. #endif /* WIL6210_TXRX_H */