xref: /openbmc/linux/drivers/net/wireless/ath/wil6210/txrx.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
185630469SLior David /* SPDX-License-Identifier: ISC */
22be7d22fSVladimir Kondratiev /*
358527421SVladimir Kondratiev  * Copyright (c) 2012-2016 Qualcomm Atheros, Inc.
4387f3794SMaya Erez  * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
52be7d22fSVladimir Kondratiev  */
62be7d22fSVladimir Kondratiev 
72be7d22fSVladimir Kondratiev #ifndef WIL6210_TXRX_H
82be7d22fSVladimir Kondratiev #define WIL6210_TXRX_H
92be7d22fSVladimir Kondratiev 
1010590c6aSGidon Studinski #include "wil6210.h"
1110590c6aSGidon Studinski #include "txrx_edma.h"
1210590c6aSGidon Studinski 
132be7d22fSVladimir Kondratiev #define BUF_SW_OWNED    (1)
142be7d22fSVladimir Kondratiev #define BUF_HW_OWNED    (0)
152be7d22fSVladimir Kondratiev 
16c44690a1SVladimir Kondratiev /* default size of MAC Tx/Rx buffers */
17c44690a1SVladimir Kondratiev #define TXRX_BUF_LEN_DEFAULT (2048)
189a06bec9SVladimir Kondratiev 
192be7d22fSVladimir Kondratiev /* how many bytes to reserve for rtap header? */
202be7d22fSVladimir Kondratiev #define WIL6210_RTAP_SIZE (128)
212be7d22fSVladimir Kondratiev 
222be7d22fSVladimir Kondratiev /* Tx/Rx path */
2368ada71eSVladimir Kondratiev 
wil_desc_addr(struct wil_ring_dma_addr * addr)2410590c6aSGidon Studinski static inline dma_addr_t wil_desc_addr(struct wil_ring_dma_addr *addr)
2568ada71eSVladimir Kondratiev {
2668ada71eSVladimir Kondratiev 	return le32_to_cpu(addr->addr_low) |
2768ada71eSVladimir Kondratiev 			   ((u64)le16_to_cpu(addr->addr_high) << 32);
2868ada71eSVladimir Kondratiev }
2968ada71eSVladimir Kondratiev 
wil_desc_addr_set(struct wil_ring_dma_addr * addr,dma_addr_t pa)3010590c6aSGidon Studinski static inline void wil_desc_addr_set(struct wil_ring_dma_addr *addr,
3168ada71eSVladimir Kondratiev 				     dma_addr_t pa)
3268ada71eSVladimir Kondratiev {
3368ada71eSVladimir Kondratiev 	addr->addr_low = cpu_to_le32(lower_32_bits(pa));
3468ada71eSVladimir Kondratiev 	addr->addr_high = cpu_to_le16((u16)upper_32_bits(pa));
3568ada71eSVladimir Kondratiev }
3668ada71eSVladimir Kondratiev 
378d3b2f03SVladimir Kondratiev /* Tx descriptor - MAC part
382be7d22fSVladimir Kondratiev  * [dword 0]
392be7d22fSVladimir Kondratiev  * bit  0.. 9 : lifetime_expiry_value:10
408d3b2f03SVladimir Kondratiev  * bit     10 : interrupt_en:1
412be7d22fSVladimir Kondratiev  * bit     11 : status_en:1
422be7d22fSVladimir Kondratiev  * bit 12..13 : txss_override:2
432be7d22fSVladimir Kondratiev  * bit     14 : timestamp_insertion:1
442be7d22fSVladimir Kondratiev  * bit     15 : duration_preserve:1
452be7d22fSVladimir Kondratiev  * bit 16..21 : reserved0:6
462be7d22fSVladimir Kondratiev  * bit 22..26 : mcs_index:5
472be7d22fSVladimir Kondratiev  * bit     27 : mcs_en:1
488d3b2f03SVladimir Kondratiev  * bit 28..30 : reserved1:3
492be7d22fSVladimir Kondratiev  * bit     31 : sn_preserved:1
502be7d22fSVladimir Kondratiev  * [dword 1]
512be7d22fSVladimir Kondratiev  * bit  0.. 3 : pkt_mode:4
522be7d22fSVladimir Kondratiev  * bit      4 : pkt_mode_en:1
535bd60982SLior David  * bit      5 : mac_id_en:1
545bd60982SLior David  * bit   6..7 : mac_id:2
555bd60982SLior David  * bit  8..14 : reserved0:7
562be7d22fSVladimir Kondratiev  * bit     15 : ack_policy_en:1
572be7d22fSVladimir Kondratiev  * bit 16..19 : dst_index:4
582be7d22fSVladimir Kondratiev  * bit     20 : dst_index_en:1
592be7d22fSVladimir Kondratiev  * bit 21..22 : ack_policy:2
602be7d22fSVladimir Kondratiev  * bit     23 : lifetime_en:1
612be7d22fSVladimir Kondratiev  * bit 24..30 : max_retry:7
622be7d22fSVladimir Kondratiev  * bit     31 : max_retry_en:1
632be7d22fSVladimir Kondratiev  * [dword 2]
642be7d22fSVladimir Kondratiev  * bit  0.. 7 : num_of_descriptors:8
652be7d22fSVladimir Kondratiev  * bit  8..17 : reserved:10
668d3b2f03SVladimir Kondratiev  * bit 18..19 : l2_translation_type:2 00 - bypass, 01 - 802.3, 10 - 802.11
672be7d22fSVladimir Kondratiev  * bit     20 : snap_hdr_insertion_en:1
682be7d22fSVladimir Kondratiev  * bit     21 : vlan_removal_en:1
692be7d22fSVladimir Kondratiev  * bit 22..31 : reserved0:10
702be7d22fSVladimir Kondratiev  * [dword 3]
712be7d22fSVladimir Kondratiev  * bit  0.. 31: ucode_cmd:32
722be7d22fSVladimir Kondratiev  */
732be7d22fSVladimir Kondratiev struct vring_tx_mac {
742be7d22fSVladimir Kondratiev 	u32 d[3];
752be7d22fSVladimir Kondratiev 	u32 ucode_cmd;
762be7d22fSVladimir Kondratiev } __packed;
772be7d22fSVladimir Kondratiev 
782be7d22fSVladimir Kondratiev /* TX MAC Dword 0 */
792be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_LIFETIME_EXPIRY_VALUE_POS 0
802be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_LIFETIME_EXPIRY_VALUE_LEN 10
812be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_LIFETIME_EXPIRY_VALUE_MSK 0x3FF
822be7d22fSVladimir Kondratiev 
832be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_INTERRUP_EN_POS 10
842be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_INTERRUP_EN_LEN 1
852be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_INTERRUP_EN_MSK 0x400
862be7d22fSVladimir Kondratiev 
872be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_STATUS_EN_POS 11
882be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_STATUS_EN_LEN 1
892be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_STATUS_EN_MSK 0x800
902be7d22fSVladimir Kondratiev 
912be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_TXSS_OVERRIDE_POS 12
922be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_TXSS_OVERRIDE_LEN 2
932be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_TXSS_OVERRIDE_MSK 0x3000
942be7d22fSVladimir Kondratiev 
952be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_TIMESTAMP_INSERTION_POS 14
962be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_TIMESTAMP_INSERTION_LEN 1
972be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_TIMESTAMP_INSERTION_MSK 0x4000
982be7d22fSVladimir Kondratiev 
992be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_DURATION_PRESERVE_POS 15
1002be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_DURATION_PRESERVE_LEN 1
1012be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_DURATION_PRESERVE_MSK 0x8000
1022be7d22fSVladimir Kondratiev 
1032be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_MCS_INDEX_POS 22
1042be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_MCS_INDEX_LEN 5
1052be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_MCS_INDEX_MSK 0x7C00000
1062be7d22fSVladimir Kondratiev 
1072be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_MCS_EN_POS 27
1082be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_MCS_EN_LEN 1
1092be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_MCS_EN_MSK 0x8000000
1102be7d22fSVladimir Kondratiev 
1112be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_SN_PRESERVED_POS 31
1122be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_SN_PRESERVED_LEN 1
1132be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_0_SN_PRESERVED_MSK 0x80000000
1142be7d22fSVladimir Kondratiev 
1152be7d22fSVladimir Kondratiev /* TX MAC Dword 1 */
1162be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_PKT_MODE_POS 0
1172be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_PKT_MODE_LEN 4
1182be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_PKT_MODE_MSK 0xF
1192be7d22fSVladimir Kondratiev 
1202be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_PKT_MODE_EN_POS 4
1212be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_PKT_MODE_EN_LEN 1
1222be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_PKT_MODE_EN_MSK 0x10
1232be7d22fSVladimir Kondratiev 
1245bd60982SLior David #define MAC_CFG_DESC_TX_1_MAC_ID_EN_POS 5
1255bd60982SLior David #define MAC_CFG_DESC_TX_1_MAC_ID_EN_LEN 1
1265bd60982SLior David #define MAC_CFG_DESC_TX_1_MAC_ID_EN_MSK 0x20
1275bd60982SLior David 
1285bd60982SLior David #define MAC_CFG_DESC_TX_1_MAC_ID_POS 6
1295bd60982SLior David #define MAC_CFG_DESC_TX_1_MAC_ID_LEN 2
1305bd60982SLior David #define MAC_CFG_DESC_TX_1_MAC_ID_MSK 0xc0
1315bd60982SLior David 
1322be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_ACK_POLICY_EN_POS 15
1332be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_ACK_POLICY_EN_LEN 1
1342be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_ACK_POLICY_EN_MSK 0x8000
1352be7d22fSVladimir Kondratiev 
1362be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_DST_INDEX_POS 16
1372be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_DST_INDEX_LEN 4
1382be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_DST_INDEX_MSK 0xF0000
1392be7d22fSVladimir Kondratiev 
1402be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_DST_INDEX_EN_POS 20
1412be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_DST_INDEX_EN_LEN 1
1422be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_DST_INDEX_EN_MSK 0x100000
1432be7d22fSVladimir Kondratiev 
1442be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_ACK_POLICY_POS 21
1452be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_ACK_POLICY_LEN 2
1462be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_ACK_POLICY_MSK 0x600000
1472be7d22fSVladimir Kondratiev 
1482be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_LIFETIME_EN_POS 23
1492be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_LIFETIME_EN_LEN 1
1502be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_LIFETIME_EN_MSK 0x800000
1512be7d22fSVladimir Kondratiev 
1522be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_MAX_RETRY_POS 24
1532be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_MAX_RETRY_LEN 7
1542be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_MAX_RETRY_MSK 0x7F000000
1552be7d22fSVladimir Kondratiev 
1562be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_MAX_RETRY_EN_POS 31
1572be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_MAX_RETRY_EN_LEN 1
1582be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_1_MAX_RETRY_EN_MSK 0x80000000
1592be7d22fSVladimir Kondratiev 
1602be7d22fSVladimir Kondratiev /* TX MAC Dword 2 */
1612be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS 0
1622be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_LEN 8
1632be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_MSK 0xFF
1642be7d22fSVladimir Kondratiev 
1652be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_RESERVED_POS 8
1662be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_RESERVED_LEN 10
1672be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_RESERVED_MSK 0x3FF00
1682be7d22fSVladimir Kondratiev 
1692be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_POS 18
1702be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_LEN 2
1712be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_MSK 0xC0000
1722be7d22fSVladimir Kondratiev 
1732be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_POS 20
1742be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_LEN 1
1752be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_MSK 0x100000
1762be7d22fSVladimir Kondratiev 
1772be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_VLAN_REMOVAL_EN_POS 21
1782be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_VLAN_REMOVAL_EN_LEN 1
1792be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_2_VLAN_REMOVAL_EN_MSK 0x200000
1802be7d22fSVladimir Kondratiev 
1812be7d22fSVladimir Kondratiev /* TX MAC Dword 3 */
1822be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_3_UCODE_CMD_POS 0
1832be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_3_UCODE_CMD_LEN 32
1842be7d22fSVladimir Kondratiev #define MAC_CFG_DESC_TX_3_UCODE_CMD_MSK 0xFFFFFFFF
1852be7d22fSVladimir Kondratiev 
1862be7d22fSVladimir Kondratiev /* TX DMA Dword 0 */
1872be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_L4_LENGTH_POS 0
1882be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_L4_LENGTH_LEN 8
1892be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_L4_LENGTH_MSK 0xFF
1902be7d22fSVladimir Kondratiev 
1912be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_CMD_EOP_POS 8
1922be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_CMD_EOP_LEN 1
1932be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_CMD_EOP_MSK 0x100
1942be7d22fSVladimir Kondratiev 
195668b2bbdSKirshenbaum Erez #define DMA_CFG_DESC_TX_0_CMD_MARK_WB_POS 9
196668b2bbdSKirshenbaum Erez #define DMA_CFG_DESC_TX_0_CMD_MARK_WB_LEN 1
197668b2bbdSKirshenbaum Erez #define DMA_CFG_DESC_TX_0_CMD_MARK_WB_MSK 0x200
198668b2bbdSKirshenbaum Erez 
1992be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_CMD_DMA_IT_POS 10
2002be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_CMD_DMA_IT_LEN 1
2012be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_CMD_DMA_IT_MSK 0x400
2022be7d22fSVladimir Kondratiev 
2032be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_POS 11
2042be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_LEN 2
2052be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_MSK 0x1800
2062be7d22fSVladimir Kondratiev 
2072be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_TCP_SEG_EN_POS 13
2082be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_TCP_SEG_EN_LEN 1
2092be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_TCP_SEG_EN_MSK 0x2000
2102be7d22fSVladimir Kondratiev 
2112be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_IPV4_CHECKSUM_EN_POS 14
2122be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_IPV4_CHECKSUM_EN_LEN 1
2132be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_IPV4_CHECKSUM_EN_MSK 0x4000
2142be7d22fSVladimir Kondratiev 
2152be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS 15
2162be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_LEN 1
2172be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_MSK 0x8000
2182be7d22fSVladimir Kondratiev 
2192be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_QID_POS 16
2202be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_QID_LEN 5
2212be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_QID_MSK 0x1F0000
2222be7d22fSVladimir Kondratiev 
2232be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS 21
2242be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_LEN 1
2252be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_MSK 0x200000
2262be7d22fSVladimir Kondratiev 
2272be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_L4_TYPE_POS 30
2282be7d22fSVladimir Kondratiev #define DMA_CFG_DESC_TX_0_L4_TYPE_LEN 2
229504937d4SKirshenbaum Erez #define DMA_CFG_DESC_TX_0_L4_TYPE_MSK 0xC0000000 /* L4 type: 0-UDP, 2-TCP */
230504937d4SKirshenbaum Erez 
231504937d4SKirshenbaum Erez #define DMA_CFG_DESC_TX_OFFLOAD_CFG_MAC_LEN_POS 0
232504937d4SKirshenbaum Erez #define DMA_CFG_DESC_TX_OFFLOAD_CFG_MAC_LEN_LEN 7
233504937d4SKirshenbaum Erez #define DMA_CFG_DESC_TX_OFFLOAD_CFG_MAC_LEN_MSK 0x7F /* MAC hdr len */
234504937d4SKirshenbaum Erez 
235504937d4SKirshenbaum Erez #define DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_POS 7
236504937d4SKirshenbaum Erez #define DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_LEN 1
237504937d4SKirshenbaum Erez #define DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_MSK 0x80 /* 1-IPv4, 0-IPv6 */
2382be7d22fSVladimir Kondratiev 
2392be7d22fSVladimir Kondratiev #define TX_DMA_STATUS_DU         BIT(0)
2402be7d22fSVladimir Kondratiev 
2418d3b2f03SVladimir Kondratiev /* Tx descriptor - DMA part
2428d3b2f03SVladimir Kondratiev  * [dword 0]
2438d3b2f03SVladimir Kondratiev  * bit  0.. 7 : l4_length:8 layer 4 length
2448d3b2f03SVladimir Kondratiev  * bit      8 : cmd_eop:1 This descriptor is the last one in the packet
2458d3b2f03SVladimir Kondratiev  * bit      9 : reserved
2468d3b2f03SVladimir Kondratiev  * bit     10 : cmd_dma_it:1 immediate interrupt
2478d3b2f03SVladimir Kondratiev  * bit 11..12 : SBD - Segment Buffer Details
2488d3b2f03SVladimir Kondratiev  *		00 - Header Segment
2498d3b2f03SVladimir Kondratiev  *		01 - First Data Segment
2508d3b2f03SVladimir Kondratiev  *		10 - Medium Data Segment
2518d3b2f03SVladimir Kondratiev  *		11 - Last Data Segment
2528d3b2f03SVladimir Kondratiev  * bit     13 : TSE - TCP Segmentation Enable
2538d3b2f03SVladimir Kondratiev  * bit     14 : IIC - Directs the HW to Insert IPv4 Checksum
2548d3b2f03SVladimir Kondratiev  * bit     15 : ITC - Directs the HW to Insert TCP/UDP Checksum
2558d3b2f03SVladimir Kondratiev  * bit 16..20 : QID - The target QID that the packet should be stored
2568d3b2f03SVladimir Kondratiev  *		in the MAC.
2578d3b2f03SVladimir Kondratiev  * bit     21 : PO - Pseudo header Offload:
2588d3b2f03SVladimir Kondratiev  *		0 - Use the pseudo header value from the TCP checksum field
2598d3b2f03SVladimir Kondratiev  *		1- Calculate Pseudo header Checksum
2608d3b2f03SVladimir Kondratiev  * bit     22 : NC - No UDP Checksum
2618d3b2f03SVladimir Kondratiev  * bit 23..29 : reserved
2628d3b2f03SVladimir Kondratiev  * bit 30..31 : L4T - Layer 4 Type: 00 - UDP , 10 - TCP , 10, 11 - Reserved
2638d3b2f03SVladimir Kondratiev  *		If L4Len equal 0, no L4 at all
2648d3b2f03SVladimir Kondratiev  * [dword 1]
2658d3b2f03SVladimir Kondratiev  * bit  0..31 : addr_low:32 The payload buffer low address
2668d3b2f03SVladimir Kondratiev  * [dword 2]
2678d3b2f03SVladimir Kondratiev  * bit  0..15 : addr_high:16 The payload buffer high address
2688d3b2f03SVladimir Kondratiev  * bit 16..23 : ip_length:8 The IP header length for the TX IP checksum
2698d3b2f03SVladimir Kondratiev  *		offload feature
2708d3b2f03SVladimir Kondratiev  * bit 24..30 : mac_length:7
2718d3b2f03SVladimir Kondratiev  * bit     31 : ip_version:1 1 - IPv4, 0 - IPv6
2728d3b2f03SVladimir Kondratiev  * [dword 3]
2738d3b2f03SVladimir Kondratiev  *  [byte 12] error
2748d3b2f03SVladimir Kondratiev  * bit  0   2 : mac_status:3
2758d3b2f03SVladimir Kondratiev  * bit  3   7 : reserved:5
2768d3b2f03SVladimir Kondratiev  *  [byte 13] status
2778d3b2f03SVladimir Kondratiev  * bit      0 : DU:1 Descriptor Used
2788d3b2f03SVladimir Kondratiev  * bit  1   7 : reserved:7
2798d3b2f03SVladimir Kondratiev  *  [word 7] length
2808d3b2f03SVladimir Kondratiev  */
2812be7d22fSVladimir Kondratiev struct vring_tx_dma {
2822be7d22fSVladimir Kondratiev 	u32 d0;
28310590c6aSGidon Studinski 	struct wil_ring_dma_addr addr;
2842be7d22fSVladimir Kondratiev 	u8  ip_length;
2852be7d22fSVladimir Kondratiev 	u8  b11;       /* 0..6: mac_length; 7:ip_version */
2862be7d22fSVladimir Kondratiev 	u8  error;     /* 0..2: err; 3..7: reserved; */
2872be7d22fSVladimir Kondratiev 	u8  status;    /* 0: used; 1..7; reserved */
2887e594444SVladimir Kondratiev 	__le16 length;
2892be7d22fSVladimir Kondratiev } __packed;
2902be7d22fSVladimir Kondratiev 
2913d4bde15SVladimir Kondratiev /* TSO type used in dma descriptor d0 bits 11-12 */
2923d4bde15SVladimir Kondratiev enum {
2933d4bde15SVladimir Kondratiev 	wil_tso_type_hdr = 0,
2943d4bde15SVladimir Kondratiev 	wil_tso_type_first = 1,
2953d4bde15SVladimir Kondratiev 	wil_tso_type_mid  = 2,
2963d4bde15SVladimir Kondratiev 	wil_tso_type_lst  = 3,
2973d4bde15SVladimir Kondratiev };
2983d4bde15SVladimir Kondratiev 
2998d3b2f03SVladimir Kondratiev /* Rx descriptor - MAC part
3002be7d22fSVladimir Kondratiev  * [dword 0]
3012be7d22fSVladimir Kondratiev  * bit  0.. 3 : tid:4 The QoS (b3-0) TID Field
3028d3b2f03SVladimir Kondratiev  * bit  4.. 6 : cid:3 The Source index that  was found during parsing the TA.
3038d3b2f03SVladimir Kondratiev  *		This field is used to define the source of the packet
3045bd60982SLior David  * bit      7 : MAC_id_valid:1, 1 if MAC virtual number is valid.
3058d3b2f03SVladimir Kondratiev  * bit  8.. 9 : mid:2 The MAC virtual number
3068d3b2f03SVladimir Kondratiev  * bit 10..11 : frame_type:2 : The FC (b3-2) - MPDU Type
3072be7d22fSVladimir Kondratiev  *		(management, data, control and extension)
3088d3b2f03SVladimir Kondratiev  * bit 12..15 : frame_subtype:4 : The FC (b7-4) - Frame Subtype
3092be7d22fSVladimir Kondratiev  * bit 16..27 : seq_number:12 The received Sequence number field
3102be7d22fSVladimir Kondratiev  * bit 28..31 : extended:4 extended subtype
3112be7d22fSVladimir Kondratiev  * [dword 1]
3122be7d22fSVladimir Kondratiev  * bit  0.. 3 : reserved
3132be7d22fSVladimir Kondratiev  * bit  4.. 5 : key_id:2
3142be7d22fSVladimir Kondratiev  * bit      6 : decrypt_bypass:1
3158d3b2f03SVladimir Kondratiev  * bit      7 : security:1 FC (b14)
3168d3b2f03SVladimir Kondratiev  * bit  8.. 9 : ds_bits:2 FC (b9-8)
3178d3b2f03SVladimir Kondratiev  * bit     10 : a_msdu_present:1  QoS (b7)
3188d3b2f03SVladimir Kondratiev  * bit     11 : a_msdu_type:1  QoS (b8)
3192be7d22fSVladimir Kondratiev  * bit     12 : a_mpdu:1  part of AMPDU aggregation
3202be7d22fSVladimir Kondratiev  * bit     13 : broadcast:1
3212be7d22fSVladimir Kondratiev  * bit     14 : mutlicast:1
3222be7d22fSVladimir Kondratiev  * bit     15 : reserved:1
3232be7d22fSVladimir Kondratiev  * bit 16..20 : rx_mac_qid:5 The Queue Identifier that the packet
3242be7d22fSVladimir Kondratiev  *		is received from
3252be7d22fSVladimir Kondratiev  * bit 21..24 : mcs:4
3268d3b2f03SVladimir Kondratiev  * bit 25..28 : mic_icr:4 this signal tells the DMA to assert an interrupt
3278d3b2f03SVladimir Kondratiev  *		after it writes the packet
3282be7d22fSVladimir Kondratiev  * bit 29..31 : reserved:3
3292be7d22fSVladimir Kondratiev  * [dword 2]
3302be7d22fSVladimir Kondratiev  * bit  0.. 2 : time_slot:3 The timeslot that the MPDU is received
3318d3b2f03SVladimir Kondratiev  * bit  3.. 4 : fc_protocol_ver:1 The FC (b1-0) - Protocol Version
3328d3b2f03SVladimir Kondratiev  * bit      5 : fc_order:1 The FC Control (b15) -Order
3338d3b2f03SVladimir Kondratiev  * bit  6.. 7 : qos_ack_policy:2 The QoS (b6-5) ack policy Field
3342be7d22fSVladimir Kondratiev  * bit      8 : esop:1 The QoS (b4) ESOP field
3352be7d22fSVladimir Kondratiev  * bit      9 : qos_rdg_more_ppdu:1 The QoS (b9) RDG field
3362be7d22fSVladimir Kondratiev  * bit 10..14 : qos_reserved:5 The QoS (b14-10) Reserved field
3378d3b2f03SVladimir Kondratiev  * bit     15 : qos_ac_constraint:1 QoS (b15)
3382be7d22fSVladimir Kondratiev  * bit 16..31 : pn_15_0:16 low 2 bytes of PN
3392be7d22fSVladimir Kondratiev  * [dword 3]
3402be7d22fSVladimir Kondratiev  * bit  0..31 : pn_47_16:32 high 4 bytes of PN
3412be7d22fSVladimir Kondratiev  */
3422be7d22fSVladimir Kondratiev struct vring_rx_mac {
3432be7d22fSVladimir Kondratiev 	u32 d0;
3442be7d22fSVladimir Kondratiev 	u32 d1;
3452be7d22fSVladimir Kondratiev 	u16 w4;
346*1ad8237eSDmitry Antipov 	struct_group_attr(pn, __packed,
3472be7d22fSVladimir Kondratiev 		u16 pn_15_0;
3482be7d22fSVladimir Kondratiev 		u32 pn_47_16;
349*1ad8237eSDmitry Antipov 	);
3502be7d22fSVladimir Kondratiev } __packed;
3512be7d22fSVladimir Kondratiev 
3528d3b2f03SVladimir Kondratiev /* Rx descriptor - DMA part
3532be7d22fSVladimir Kondratiev  * [dword 0]
3548d3b2f03SVladimir Kondratiev  * bit  0.. 7 : l4_length:8 layer 4 length. The field is only valid if
3558d3b2f03SVladimir Kondratiev  *		L4I bit is set
3568d3b2f03SVladimir Kondratiev  * bit      8 : cmd_eop:1 set to 1
3578d3b2f03SVladimir Kondratiev  * bit      9 : cmd_rt:1 set to 1
3588d3b2f03SVladimir Kondratiev  * bit     10 : cmd_dma_it:1 immediate interrupt
3592be7d22fSVladimir Kondratiev  * bit 11..15 : reserved:5
3608d3b2f03SVladimir Kondratiev  * bit 16..29 : phy_info_length:14 It is valid when the PII is set.
361aa6f2be4SJilin Yuan  *		When the FFM bit is set bits 29-27 are used for
3628d3b2f03SVladimir Kondratiev  *		Flex Filter Match. Matching Index to one of the L2
3638d3b2f03SVladimir Kondratiev  *		EtherType Flex Filter
3642be7d22fSVladimir Kondratiev  * bit 30..31 : l4_type:2 valid if the L4I bit is set in the status field
3658d3b2f03SVladimir Kondratiev  *		00 - UDP, 01 - TCP, 10, 11 - reserved
3662be7d22fSVladimir Kondratiev  * [dword 1]
3672be7d22fSVladimir Kondratiev  * bit  0..31 : addr_low:32 The payload buffer low address
3682be7d22fSVladimir Kondratiev  * [dword 2]
3692be7d22fSVladimir Kondratiev  * bit  0..15 : addr_high:16 The payload buffer high address
3708d3b2f03SVladimir Kondratiev  * bit 16..23 : ip_length:8 The filed is valid only if the L3I bit is set
3712be7d22fSVladimir Kondratiev  * bit 24..30 : mac_length:7
3728d3b2f03SVladimir Kondratiev  * bit     31 : ip_version:1 1 - IPv4, 0 - IPv6
3732be7d22fSVladimir Kondratiev  * [dword 3]
3742be7d22fSVladimir Kondratiev  *  [byte 12] error
3758d3b2f03SVladimir Kondratiev  * bit      0 : FCS:1
3768d3b2f03SVladimir Kondratiev  * bit      1 : MIC:1
3778d3b2f03SVladimir Kondratiev  * bit      2 : Key miss:1
3788d3b2f03SVladimir Kondratiev  * bit      3 : Replay:1
3798d3b2f03SVladimir Kondratiev  * bit      4 : L3:1 IPv4 checksum
3808d3b2f03SVladimir Kondratiev  * bit      5 : L4:1 TCP/UDP checksum
3818d3b2f03SVladimir Kondratiev  * bit  6   7 : reserved:2
3822be7d22fSVladimir Kondratiev  *  [byte 13] status
3838d3b2f03SVladimir Kondratiev  * bit      0 : DU:1 Descriptor Used
3848d3b2f03SVladimir Kondratiev  * bit      1 : EOP:1 The descriptor indicates the End of Packet
3852be7d22fSVladimir Kondratiev  * bit      2 : error:1
3868d3b2f03SVladimir Kondratiev  * bit      3 : MI:1 MAC Interrupt is asserted (according to parser decision)
3878d3b2f03SVladimir Kondratiev  * bit      4 : L3I:1 L3 identified and checksum calculated
3888d3b2f03SVladimir Kondratiev  * bit      5 : L4I:1 L4 identified and checksum calculated
3898d3b2f03SVladimir Kondratiev  * bit      6 : PII:1 PHY Info Included in the packet
3908d3b2f03SVladimir Kondratiev  * bit      7 : FFM:1 EtherType Flex Filter Match
3912be7d22fSVladimir Kondratiev  *  [word 7] length
3922be7d22fSVladimir Kondratiev  */
3932be7d22fSVladimir Kondratiev 
39448c963afSVladimir Kondratiev #define RX_DMA_D0_CMD_DMA_EOP	BIT(8)
39548c963afSVladimir Kondratiev #define RX_DMA_D0_CMD_DMA_RT	BIT(9)  /* always 1 */
39648c963afSVladimir Kondratiev #define RX_DMA_D0_CMD_DMA_IT	BIT(10) /* interrupt */
3975bd60982SLior David #define RX_MAC_D0_MAC_ID_VALID	BIT(7)
3982be7d22fSVladimir Kondratiev 
39948c963afSVladimir Kondratiev /* Error field */
40048c963afSVladimir Kondratiev #define RX_DMA_ERROR_FCS	BIT(0)
40148c963afSVladimir Kondratiev #define RX_DMA_ERROR_MIC	BIT(1)
40248c963afSVladimir Kondratiev #define RX_DMA_ERROR_KEY	BIT(2) /* Key missing */
40348c963afSVladimir Kondratiev #define RX_DMA_ERROR_REPLAY	BIT(3)
404504937d4SKirshenbaum Erez #define RX_DMA_ERROR_L3_ERR	BIT(4)
405504937d4SKirshenbaum Erez #define RX_DMA_ERROR_L4_ERR	BIT(5)
406504937d4SKirshenbaum Erez 
407504937d4SKirshenbaum Erez /* Status field */
4082be7d22fSVladimir Kondratiev #define RX_DMA_STATUS_DU	BIT(0)
40948c963afSVladimir Kondratiev #define RX_DMA_STATUS_EOP	BIT(1)
4102be7d22fSVladimir Kondratiev #define RX_DMA_STATUS_ERROR	BIT(2)
41148c963afSVladimir Kondratiev #define RX_DMA_STATUS_MI	BIT(3) /* MAC Interrupt is asserted */
4128d3b2f03SVladimir Kondratiev #define RX_DMA_STATUS_L3I	BIT(4)
4138d3b2f03SVladimir Kondratiev #define RX_DMA_STATUS_L4I	BIT(5)
4142be7d22fSVladimir Kondratiev #define RX_DMA_STATUS_PHY_INFO	BIT(6)
41548c963afSVladimir Kondratiev #define RX_DMA_STATUS_FFM	BIT(7) /* EtherType Flex Filter Match */
4162be7d22fSVladimir Kondratiev 
41742fe1e51SAhmad Masri /* IEEE 802.11, 8.5.2 EAPOL-Key frames */
41842fe1e51SAhmad Masri #define WIL_KEY_INFO_KEY_TYPE BIT(3) /* val of 1 = Pairwise, 0 = Group key */
41942fe1e51SAhmad Masri 
42042fe1e51SAhmad Masri #define WIL_KEY_INFO_MIC BIT(8)
42142fe1e51SAhmad Masri #define WIL_KEY_INFO_ENCR_KEY_DATA BIT(12) /* for rsn only */
42242fe1e51SAhmad Masri 
42342fe1e51SAhmad Masri #define WIL_EAP_NONCE_LEN 32
42442fe1e51SAhmad Masri #define WIL_EAP_KEY_RSC_LEN 8
42542fe1e51SAhmad Masri #define WIL_EAP_REPLAY_COUNTER_LEN 8
42642fe1e51SAhmad Masri #define WIL_EAP_KEY_IV_LEN 16
42742fe1e51SAhmad Masri #define WIL_EAP_KEY_ID_LEN 8
42842fe1e51SAhmad Masri 
42942fe1e51SAhmad Masri enum {
43042fe1e51SAhmad Masri 	WIL_1X_TYPE_EAP_PACKET = 0,
43142fe1e51SAhmad Masri 	WIL_1X_TYPE_EAPOL_START = 1,
43242fe1e51SAhmad Masri 	WIL_1X_TYPE_EAPOL_LOGOFF = 2,
43342fe1e51SAhmad Masri 	WIL_1X_TYPE_EAPOL_KEY = 3,
43442fe1e51SAhmad Masri };
43542fe1e51SAhmad Masri 
43642fe1e51SAhmad Masri #define WIL_EAPOL_KEY_TYPE_RSN 2
43742fe1e51SAhmad Masri #define WIL_EAPOL_KEY_TYPE_WPA 254
43842fe1e51SAhmad Masri 
43942fe1e51SAhmad Masri struct wil_1x_hdr {
44042fe1e51SAhmad Masri 	u8 version;
44142fe1e51SAhmad Masri 	u8 type;
44242fe1e51SAhmad Masri 	__be16 length;
44342fe1e51SAhmad Masri 	/* followed by data */
44442fe1e51SAhmad Masri } __packed;
44542fe1e51SAhmad Masri 
44642fe1e51SAhmad Masri struct wil_eapol_key {
44742fe1e51SAhmad Masri 	u8 type;
44842fe1e51SAhmad Masri 	__be16 key_info;
44942fe1e51SAhmad Masri 	__be16 key_length;
45042fe1e51SAhmad Masri 	u8 replay_counter[WIL_EAP_REPLAY_COUNTER_LEN];
45142fe1e51SAhmad Masri 	u8 key_nonce[WIL_EAP_NONCE_LEN];
45242fe1e51SAhmad Masri 	u8 key_iv[WIL_EAP_KEY_IV_LEN];
45342fe1e51SAhmad Masri 	u8 key_rsc[WIL_EAP_KEY_RSC_LEN];
45442fe1e51SAhmad Masri 	u8 key_id[WIL_EAP_KEY_ID_LEN];
45542fe1e51SAhmad Masri } __packed;
45642fe1e51SAhmad Masri 
4572be7d22fSVladimir Kondratiev struct vring_rx_dma {
4582be7d22fSVladimir Kondratiev 	u32 d0;
45910590c6aSGidon Studinski 	struct wil_ring_dma_addr addr;
4602be7d22fSVladimir Kondratiev 	u8  ip_length;
4612be7d22fSVladimir Kondratiev 	u8  b11;
4622be7d22fSVladimir Kondratiev 	u8  error;
4632be7d22fSVladimir Kondratiev 	u8  status;
4647e594444SVladimir Kondratiev 	__le16 length;
4652be7d22fSVladimir Kondratiev } __packed;
4662be7d22fSVladimir Kondratiev 
4672be7d22fSVladimir Kondratiev struct vring_tx_desc {
4682be7d22fSVladimir Kondratiev 	struct vring_tx_mac mac;
4692be7d22fSVladimir Kondratiev 	struct vring_tx_dma dma;
4702be7d22fSVladimir Kondratiev } __packed;
4712be7d22fSVladimir Kondratiev 
47210590c6aSGidon Studinski union wil_tx_desc {
47310590c6aSGidon Studinski 	struct vring_tx_desc legacy;
47410590c6aSGidon Studinski 	struct wil_tx_enhanced_desc enhanced;
47510590c6aSGidon Studinski } __packed;
47610590c6aSGidon Studinski 
4772be7d22fSVladimir Kondratiev struct vring_rx_desc {
4782be7d22fSVladimir Kondratiev 	struct vring_rx_mac mac;
4792be7d22fSVladimir Kondratiev 	struct vring_rx_dma dma;
4802be7d22fSVladimir Kondratiev } __packed;
4812be7d22fSVladimir Kondratiev 
48210590c6aSGidon Studinski union wil_rx_desc {
48310590c6aSGidon Studinski 	struct vring_rx_desc legacy;
48410590c6aSGidon Studinski 	struct wil_rx_enhanced_desc enhanced;
48510590c6aSGidon Studinski } __packed;
48610590c6aSGidon Studinski 
48710590c6aSGidon Studinski union wil_ring_desc {
48810590c6aSGidon Studinski 	union wil_tx_desc tx;
48910590c6aSGidon Studinski 	union wil_rx_desc rx;
4902be7d22fSVladimir Kondratiev } __packed;
4912be7d22fSVladimir Kondratiev 
492bf0353a6SAhmad Masri struct packet_rx_info {
493bf0353a6SAhmad Masri 	u8 cid;
494bf0353a6SAhmad Masri };
495bf0353a6SAhmad Masri 
496bf0353a6SAhmad Masri /* this struct will be stored in the skb cb buffer
497bf0353a6SAhmad Masri  * max length of the struct is limited to 48 bytes
498bf0353a6SAhmad Masri  */
499bf0353a6SAhmad Masri struct skb_rx_info {
500bf0353a6SAhmad Masri 	struct vring_rx_desc rx_desc;
501bf0353a6SAhmad Masri 	struct packet_rx_info rx_info;
502bf0353a6SAhmad Masri };
503bf0353a6SAhmad Masri 
wil_rxdesc_tid(struct vring_rx_desc * d)5044fc4118cSVladimir Kondratiev static inline int wil_rxdesc_tid(struct vring_rx_desc *d)
5052be7d22fSVladimir Kondratiev {
5064fc4118cSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d0, 0, 3);
5072be7d22fSVladimir Kondratiev }
5082be7d22fSVladimir Kondratiev 
wil_rxdesc_cid(struct vring_rx_desc * d)5094fc4118cSVladimir Kondratiev static inline int wil_rxdesc_cid(struct vring_rx_desc *d)
5102be7d22fSVladimir Kondratiev {
5114fc4118cSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d0, 4, 6);
5124fc4118cSVladimir Kondratiev }
5134fc4118cSVladimir Kondratiev 
wil_rxdesc_mid(struct vring_rx_desc * d)5144fc4118cSVladimir Kondratiev static inline int wil_rxdesc_mid(struct vring_rx_desc *d)
5154fc4118cSVladimir Kondratiev {
5165bd60982SLior David 	return (d->mac.d0 & RX_MAC_D0_MAC_ID_VALID) ?
5175bd60982SLior David 		WIL_GET_BITS(d->mac.d0, 8, 9) : 0;
5184fc4118cSVladimir Kondratiev }
5194fc4118cSVladimir Kondratiev 
wil_rxdesc_ftype(struct vring_rx_desc * d)5204fc4118cSVladimir Kondratiev static inline int wil_rxdesc_ftype(struct vring_rx_desc *d)
5214fc4118cSVladimir Kondratiev {
5224fc4118cSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d0, 10, 11);
5234fc4118cSVladimir Kondratiev }
5244fc4118cSVladimir Kondratiev 
wil_rxdesc_subtype(struct vring_rx_desc * d)5254fc4118cSVladimir Kondratiev static inline int wil_rxdesc_subtype(struct vring_rx_desc *d)
5264fc4118cSVladimir Kondratiev {
5274fc4118cSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d0, 12, 15);
5284fc4118cSVladimir Kondratiev }
5294fc4118cSVladimir Kondratiev 
530a8313341SVladimir Kondratiev /* 1-st byte (with frame type/subtype) of FC field */
wil_rxdesc_fc1(struct vring_rx_desc * d)531a8313341SVladimir Kondratiev static inline u8 wil_rxdesc_fc1(struct vring_rx_desc *d)
532a8313341SVladimir Kondratiev {
533a8313341SVladimir Kondratiev 	return (u8)(WIL_GET_BITS(d->mac.d0, 10, 15) << 2);
534a8313341SVladimir Kondratiev }
535a8313341SVladimir Kondratiev 
wil_rxdesc_seq(struct vring_rx_desc * d)5364fc4118cSVladimir Kondratiev static inline int wil_rxdesc_seq(struct vring_rx_desc *d)
5374fc4118cSVladimir Kondratiev {
5384fc4118cSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d0, 16, 27);
5394fc4118cSVladimir Kondratiev }
5404fc4118cSVladimir Kondratiev 
wil_rxdesc_ext_subtype(struct vring_rx_desc * d)5414fc4118cSVladimir Kondratiev static inline int wil_rxdesc_ext_subtype(struct vring_rx_desc *d)
5424fc4118cSVladimir Kondratiev {
5434fc4118cSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d0, 28, 31);
5442be7d22fSVladimir Kondratiev }
5452be7d22fSVladimir Kondratiev 
wil_rxdesc_retry(struct vring_rx_desc * d)5461bd82ee0SDedy Lansky static inline int wil_rxdesc_retry(struct vring_rx_desc *d)
5471bd82ee0SDedy Lansky {
5481bd82ee0SDedy Lansky 	return WIL_GET_BITS(d->mac.d0, 31, 31);
5491bd82ee0SDedy Lansky }
5501bd82ee0SDedy Lansky 
wil_rxdesc_key_id(struct vring_rx_desc * d)55158527421SVladimir Kondratiev static inline int wil_rxdesc_key_id(struct vring_rx_desc *d)
55258527421SVladimir Kondratiev {
55358527421SVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d1, 4, 5);
55458527421SVladimir Kondratiev }
55558527421SVladimir Kondratiev 
wil_rxdesc_security(struct vring_rx_desc * d)55658527421SVladimir Kondratiev static inline int wil_rxdesc_security(struct vring_rx_desc *d)
55758527421SVladimir Kondratiev {
55858527421SVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d1, 7, 7);
55958527421SVladimir Kondratiev }
56058527421SVladimir Kondratiev 
wil_rxdesc_ds_bits(struct vring_rx_desc * d)56133e61169SVladimir Kondratiev static inline int wil_rxdesc_ds_bits(struct vring_rx_desc *d)
5622be7d22fSVladimir Kondratiev {
5632be7d22fSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d1, 8, 9);
5642be7d22fSVladimir Kondratiev }
5652be7d22fSVladimir Kondratiev 
wil_rxdesc_mcs(struct vring_rx_desc * d)5664fc4118cSVladimir Kondratiev static inline int wil_rxdesc_mcs(struct vring_rx_desc *d)
5672be7d22fSVladimir Kondratiev {
5684fc4118cSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d1, 21, 24);
5694fc4118cSVladimir Kondratiev }
5704fc4118cSVladimir Kondratiev 
wil_rxdesc_mcast(struct vring_rx_desc * d)571e4373d8eSVladimir Kondratiev static inline int wil_rxdesc_mcast(struct vring_rx_desc *d)
572e4373d8eSVladimir Kondratiev {
573e4373d8eSVladimir Kondratiev 	return WIL_GET_BITS(d->mac.d1, 13, 14);
574e4373d8eSVladimir Kondratiev }
575e4373d8eSVladimir Kondratiev 
wil_skb_rxdesc(struct sk_buff * skb)57633e61169SVladimir Kondratiev static inline struct vring_rx_desc *wil_skb_rxdesc(struct sk_buff *skb)
57733e61169SVladimir Kondratiev {
57833e61169SVladimir Kondratiev 	return (void *)skb->cb;
57933e61169SVladimir Kondratiev }
58033e61169SVladimir Kondratiev 
wil_ring_is_empty(struct wil_ring * ring)58110590c6aSGidon Studinski static inline int wil_ring_is_empty(struct wil_ring *ring)
58210590c6aSGidon Studinski {
58310590c6aSGidon Studinski 	return ring->swhead == ring->swtail;
58410590c6aSGidon Studinski }
58510590c6aSGidon Studinski 
wil_ring_next_tail(struct wil_ring * ring)58610590c6aSGidon Studinski static inline u32 wil_ring_next_tail(struct wil_ring *ring)
58710590c6aSGidon Studinski {
58810590c6aSGidon Studinski 	return (ring->swtail + 1) % ring->size;
58910590c6aSGidon Studinski }
59010590c6aSGidon Studinski 
wil_ring_advance_head(struct wil_ring * ring,int n)59110590c6aSGidon Studinski static inline void wil_ring_advance_head(struct wil_ring *ring, int n)
59210590c6aSGidon Studinski {
59310590c6aSGidon Studinski 	ring->swhead = (ring->swhead + n) % ring->size;
59410590c6aSGidon Studinski }
59510590c6aSGidon Studinski 
wil_ring_is_full(struct wil_ring * ring)59610590c6aSGidon Studinski static inline int wil_ring_is_full(struct wil_ring *ring)
59710590c6aSGidon Studinski {
59810590c6aSGidon Studinski 	return wil_ring_next_tail(ring) == ring->swhead;
59910590c6aSGidon Studinski }
60010590c6aSGidon Studinski 
wil_skb_get_da(struct sk_buff * skb)6016d1ba32cSAhmad Masri static inline u8 *wil_skb_get_da(struct sk_buff *skb)
6029202d7b6SMaya Erez {
6039202d7b6SMaya Erez 	struct ethhdr *eth = (void *)skb->data;
6049202d7b6SMaya Erez 
6056d1ba32cSAhmad Masri 	return eth->h_dest;
6066d1ba32cSAhmad Masri }
6076d1ba32cSAhmad Masri 
wil_skb_get_sa(struct sk_buff * skb)6086d1ba32cSAhmad Masri static inline u8 *wil_skb_get_sa(struct sk_buff *skb)
6096d1ba32cSAhmad Masri {
6106d1ba32cSAhmad Masri 	struct ethhdr *eth = (void *)skb->data;
6116d1ba32cSAhmad Masri 
6126d1ba32cSAhmad Masri 	return eth->h_source;
6136d1ba32cSAhmad Masri }
6146d1ba32cSAhmad Masri 
wil_need_txstat(struct sk_buff * skb)6156d1ba32cSAhmad Masri static inline bool wil_need_txstat(struct sk_buff *skb)
6166d1ba32cSAhmad Masri {
6176d1ba32cSAhmad Masri 	const u8 *da = wil_skb_get_da(skb);
6186d1ba32cSAhmad Masri 
6196d1ba32cSAhmad Masri 	return is_unicast_ether_addr(da) && skb->sk &&
6209202d7b6SMaya Erez 	       (skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS);
6219202d7b6SMaya Erez }
6229202d7b6SMaya Erez 
wil_consume_skb(struct sk_buff * skb,bool acked)6239202d7b6SMaya Erez static inline void wil_consume_skb(struct sk_buff *skb, bool acked)
6249202d7b6SMaya Erez {
6259202d7b6SMaya Erez 	if (unlikely(wil_need_txstat(skb)))
6269202d7b6SMaya Erez 		skb_complete_wifi_ack(skb, acked);
6279202d7b6SMaya Erez 	else
6289202d7b6SMaya Erez 		acked ? dev_consume_skb_any(skb) : dev_kfree_skb_any(skb);
6299202d7b6SMaya Erez }
6309202d7b6SMaya Erez 
63110590c6aSGidon Studinski /* Used space in Tx ring */
wil_ring_used_tx(struct wil_ring * ring)63210590c6aSGidon Studinski static inline int wil_ring_used_tx(struct wil_ring *ring)
63310590c6aSGidon Studinski {
63410590c6aSGidon Studinski 	u32 swhead = ring->swhead;
63510590c6aSGidon Studinski 	u32 swtail = ring->swtail;
63610590c6aSGidon Studinski 
63710590c6aSGidon Studinski 	return (ring->size + swhead - swtail) % ring->size;
63810590c6aSGidon Studinski }
63910590c6aSGidon Studinski 
64010590c6aSGidon Studinski /* Available space in Tx ring */
wil_ring_avail_tx(struct wil_ring * ring)64110590c6aSGidon Studinski static inline int wil_ring_avail_tx(struct wil_ring *ring)
64210590c6aSGidon Studinski {
64310590c6aSGidon Studinski 	return ring->size - wil_ring_used_tx(ring) - 1;
64410590c6aSGidon Studinski }
64510590c6aSGidon Studinski 
wil_get_min_tx_ring_id(struct wil6210_priv * wil)64696c93589SGidon Studinski static inline int wil_get_min_tx_ring_id(struct wil6210_priv *wil)
64796c93589SGidon Studinski {
64896c93589SGidon Studinski 	/* In Enhanced DMA ring 0 is reserved for RX */
64996c93589SGidon Studinski 	return wil->use_enhanced_dma_hw ? 1 : 0;
65096c93589SGidon Studinski }
65196c93589SGidon Studinski 
6527be13fc3SGidon Studinski /* similar to ieee80211_ version, but FC contain only 1-st byte */
wil_is_back_req(u8 fc)6537be13fc3SGidon Studinski static inline int wil_is_back_req(u8 fc)
6547be13fc3SGidon Studinski {
6557be13fc3SGidon Studinski 	return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
6567be13fc3SGidon Studinski 	       (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ);
6577be13fc3SGidon Studinski }
6587be13fc3SGidon Studinski 
6599202d7b6SMaya Erez /* wil_val_in_range - check if value in [min,max) */
wil_val_in_range(int val,int min,int max)6609202d7b6SMaya Erez static inline bool wil_val_in_range(int val, int min, int max)
6619202d7b6SMaya Erez {
6629202d7b6SMaya Erez 	return val >= min && val < max;
6639202d7b6SMaya Erez }
6649202d7b6SMaya Erez 
wil_skb_get_cid(struct sk_buff * skb)665bf0353a6SAhmad Masri static inline u8 wil_skb_get_cid(struct sk_buff *skb)
666bf0353a6SAhmad Masri {
667bf0353a6SAhmad Masri 	struct skb_rx_info *skb_rx_info = (void *)skb->cb;
668bf0353a6SAhmad Masri 
669bf0353a6SAhmad Masri 	return skb_rx_info->rx_info.cid;
670bf0353a6SAhmad Masri }
671bf0353a6SAhmad Masri 
wil_skb_set_cid(struct sk_buff * skb,u8 cid)672bf0353a6SAhmad Masri static inline void wil_skb_set_cid(struct sk_buff *skb, u8 cid)
673bf0353a6SAhmad Masri {
674bf0353a6SAhmad Masri 	struct skb_rx_info *skb_rx_info = (void *)skb->cb;
675bf0353a6SAhmad Masri 
676bf0353a6SAhmad Masri 	skb_rx_info->rx_info.cid = cid;
677bf0353a6SAhmad Masri }
678bf0353a6SAhmad Masri 
679b4490f42SVladimir Kondratiev void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev);
680f99fe49fSDedy Lansky void wil_netif_rx(struct sk_buff *skb, struct net_device *ndev, int cid,
681f99fe49fSDedy Lansky 		  struct wil_net_stats *stats, bool gro);
682b4490f42SVladimir Kondratiev void wil_rx_reorder(struct wil6210_priv *wil, struct sk_buff *skb);
6835bd60982SLior David void wil_rx_bar(struct wil6210_priv *wil, struct wil6210_vif *vif,
6845bd60982SLior David 		u8 cid, u8 tid, u16 seq);
685b4490f42SVladimir Kondratiev struct wil_tid_ampdu_rx *wil_tid_ampdu_rx_alloc(struct wil6210_priv *wil,
686b4490f42SVladimir Kondratiev 						int size, u16 ssn);
687b4490f42SVladimir Kondratiev void wil_tid_ampdu_rx_free(struct wil6210_priv *wil,
688b4490f42SVladimir Kondratiev 			   struct wil_tid_ampdu_rx *r);
68996c93589SGidon Studinski void wil_tx_data_init(struct wil_ring_tx_data *txdata);
69096c93589SGidon Studinski void wil_init_txrx_ops_legacy_dma(struct wil6210_priv *wil);
691a24a3d6aSDedy Lansky void wil_tx_latency_calc(struct wil6210_priv *wil, struct sk_buff *skb,
692a24a3d6aSDedy Lansky 			 struct wil_sta_info *sta);
693b4490f42SVladimir Kondratiev 
6942be7d22fSVladimir Kondratiev #endif /* WIL6210_TXRX_H */
695