txrx.h 20 KB

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