162306a36Sopenharmony_ci/* SPDX-License-Identifier: ISC */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2012-2016,2018-2019, The Linux Foundation. All rights reserved.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef WIL6210_TXRX_EDMA_H
762306a36Sopenharmony_ci#define WIL6210_TXRX_EDMA_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include "wil6210.h"
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/* limit status ring size in range [ring size..max ring size] */
1262306a36Sopenharmony_ci#define WIL_SRING_SIZE_ORDER_MIN	(WIL_RING_SIZE_ORDER_MIN)
1362306a36Sopenharmony_ci#define WIL_SRING_SIZE_ORDER_MAX	(WIL_RING_SIZE_ORDER_MAX)
1462306a36Sopenharmony_ci/* RX sring order should be bigger than RX ring order */
1562306a36Sopenharmony_ci#define WIL_RX_SRING_SIZE_ORDER_DEFAULT	(12)
1662306a36Sopenharmony_ci#define WIL_TX_SRING_SIZE_ORDER_DEFAULT	(14)
1762306a36Sopenharmony_ci#define WIL_RX_BUFF_ARR_SIZE_DEFAULT (2600)
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define WIL_DEFAULT_RX_STATUS_RING_ID 0
2062306a36Sopenharmony_ci#define WIL_RX_DESC_RING_ID 0
2162306a36Sopenharmony_ci#define WIL_RX_STATUS_IRQ_IDX 0
2262306a36Sopenharmony_ci#define WIL_TX_STATUS_IRQ_IDX 1
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define WIL_EDMA_AGG_WATERMARK (0xffff)
2562306a36Sopenharmony_ci#define WIL_EDMA_AGG_WATERMARK_POS (16)
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#define WIL_EDMA_IDLE_TIME_LIMIT_USEC (50)
2862306a36Sopenharmony_ci#define WIL_EDMA_TIME_UNIT_CLK_CYCLES (330) /* fits 1 usec */
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci/* Error field */
3162306a36Sopenharmony_ci#define WIL_RX_EDMA_ERROR_MIC	(1)
3262306a36Sopenharmony_ci#define WIL_RX_EDMA_ERROR_KEY	(2) /* Key missing */
3362306a36Sopenharmony_ci#define WIL_RX_EDMA_ERROR_REPLAY	(3)
3462306a36Sopenharmony_ci#define WIL_RX_EDMA_ERROR_AMSDU	(4)
3562306a36Sopenharmony_ci#define WIL_RX_EDMA_ERROR_FCS	(7)
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#define WIL_RX_EDMA_ERROR_L3_ERR	(BIT(0) | BIT(1))
3862306a36Sopenharmony_ci#define WIL_RX_EDMA_ERROR_L4_ERR	(BIT(0) | BIT(1))
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define WIL_RX_EDMA_DLPF_LU_MISS_BIT		BIT(11)
4162306a36Sopenharmony_ci#define WIL_RX_EDMA_DLPF_LU_MISS_CID_TID_MASK	0x7
4262306a36Sopenharmony_ci#define WIL_RX_EDMA_DLPF_LU_HIT_CID_TID_MASK	0xf
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#define WIL_RX_EDMA_DLPF_LU_MISS_CID_POS	2
4562306a36Sopenharmony_ci#define WIL_RX_EDMA_DLPF_LU_HIT_CID_POS		4
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define WIL_RX_EDMA_DLPF_LU_MISS_TID_POS	5
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define WIL_RX_EDMA_MID_VALID_BIT		BIT(20)
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_MAC_CFG_0_QID_POS 16
5262306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_MAC_CFG_0_QID_LEN 6
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_EOP_POS 0
5562306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_EOP_LEN 1
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_TSO_DESC_TYPE_POS 3
5862306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_TSO_DESC_TYPE_LEN 2
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_SEG_EN_POS 5
6162306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_SEG_EN_LEN 1
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_INSERT_IP_CHKSUM_POS 6
6462306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_INSERT_IP_CHKSUM_LEN 1
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_INSERT_TCP_CHKSUM_POS 7
6762306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_INSERT_TCP_CHKSUM_LEN 1
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_L4_TYPE_POS 15
7062306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_L4_TYPE_LEN 1
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_PSEUDO_HEADER_CALC_EN_POS 5
7362306a36Sopenharmony_ci#define WIL_EDMA_DESC_TX_CFG_PSEUDO_HEADER_CALC_EN_LEN 1
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci/* Enhanced Rx descriptor - MAC part
7662306a36Sopenharmony_ci * [dword 0] : Reserved
7762306a36Sopenharmony_ci * [dword 1] : Reserved
7862306a36Sopenharmony_ci * [dword 2] : Reserved
7962306a36Sopenharmony_ci * [dword 3]
8062306a36Sopenharmony_ci *	bit  0..15 : Buffer ID
8162306a36Sopenharmony_ci *	bit 16..31 : Reserved
8262306a36Sopenharmony_ci */
8362306a36Sopenharmony_cistruct wil_ring_rx_enhanced_mac {
8462306a36Sopenharmony_ci	u32 d[3];
8562306a36Sopenharmony_ci	__le16 buff_id;
8662306a36Sopenharmony_ci	u16 reserved;
8762306a36Sopenharmony_ci} __packed;
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci/* Enhanced Rx descriptor - DMA part
9062306a36Sopenharmony_ci * [dword 0] - Reserved
9162306a36Sopenharmony_ci * [dword 1]
9262306a36Sopenharmony_ci *	bit  0..31 : addr_low:32 The payload buffer address, bits 0-31
9362306a36Sopenharmony_ci * [dword 2]
9462306a36Sopenharmony_ci *	bit  0..15 : addr_high_low:16 The payload buffer address, bits 32-47
9562306a36Sopenharmony_ci *	bit 16..31 : Reserved
9662306a36Sopenharmony_ci * [dword 3]
9762306a36Sopenharmony_ci *	bit  0..15 : addr_high_high:16 The payload buffer address, bits 48-63
9862306a36Sopenharmony_ci *	bit 16..31 : length
9962306a36Sopenharmony_ci */
10062306a36Sopenharmony_cistruct wil_ring_rx_enhanced_dma {
10162306a36Sopenharmony_ci	u32 d0;
10262306a36Sopenharmony_ci	struct wil_ring_dma_addr addr;
10362306a36Sopenharmony_ci	u16 w5;
10462306a36Sopenharmony_ci	__le16 addr_high_high;
10562306a36Sopenharmony_ci	__le16 length;
10662306a36Sopenharmony_ci} __packed;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_cistruct wil_rx_enhanced_desc {
10962306a36Sopenharmony_ci	struct wil_ring_rx_enhanced_mac mac;
11062306a36Sopenharmony_ci	struct wil_ring_rx_enhanced_dma dma;
11162306a36Sopenharmony_ci} __packed;
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* Enhanced Tx descriptor - DMA part
11462306a36Sopenharmony_ci * [dword 0]
11562306a36Sopenharmony_ci *	Same as legacy
11662306a36Sopenharmony_ci * [dword 1]
11762306a36Sopenharmony_ci * bit  0..31 : addr_low:32 The payload buffer address, bits 0-31
11862306a36Sopenharmony_ci * [dword 2]
11962306a36Sopenharmony_ci * bit  0..15 : addr_high_low:16 The payload buffer address, bits 32-47
12062306a36Sopenharmony_ci * bit 16..23 : ip_length:8 The IP header length for the TX IP checksum
12162306a36Sopenharmony_ci *		offload feature
12262306a36Sopenharmony_ci * bit 24..30 : mac_length:7
12362306a36Sopenharmony_ci * bit     31 : ip_version:1 1 - IPv4, 0 - IPv6
12462306a36Sopenharmony_ci * [dword 3]
12562306a36Sopenharmony_ci * bit  0..15 : addr_high_high:16 The payload buffer address, bits 48-63
12662306a36Sopenharmony_ci * bit 16..31 : length
12762306a36Sopenharmony_ci */
12862306a36Sopenharmony_cistruct wil_ring_tx_enhanced_dma {
12962306a36Sopenharmony_ci	u8 l4_hdr_len;
13062306a36Sopenharmony_ci	u8 cmd;
13162306a36Sopenharmony_ci	u16 w1;
13262306a36Sopenharmony_ci	struct wil_ring_dma_addr addr;
13362306a36Sopenharmony_ci	u8  ip_length;
13462306a36Sopenharmony_ci	u8  b11;       /* 0..6: mac_length; 7:ip_version */
13562306a36Sopenharmony_ci	__le16 addr_high_high;
13662306a36Sopenharmony_ci	__le16 length;
13762306a36Sopenharmony_ci} __packed;
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/* Enhanced Tx descriptor - MAC part
14062306a36Sopenharmony_ci * [dword 0]
14162306a36Sopenharmony_ci * bit  0.. 9 : lifetime_expiry_value:10
14262306a36Sopenharmony_ci * bit     10 : interrupt_en:1
14362306a36Sopenharmony_ci * bit     11 : status_en:1
14462306a36Sopenharmony_ci * bit 12..13 : txss_override:2
14562306a36Sopenharmony_ci * bit     14 : timestamp_insertion:1
14662306a36Sopenharmony_ci * bit     15 : duration_preserve:1
14762306a36Sopenharmony_ci * bit 16..21 : reserved0:6
14862306a36Sopenharmony_ci * bit 22..26 : mcs_index:5
14962306a36Sopenharmony_ci * bit     27 : mcs_en:1
15062306a36Sopenharmony_ci * bit 28..30 : reserved1:3
15162306a36Sopenharmony_ci * bit     31 : sn_preserved:1
15262306a36Sopenharmony_ci * [dword 1]
15362306a36Sopenharmony_ci * bit  0.. 3 : pkt_mode:4
15462306a36Sopenharmony_ci * bit      4 : pkt_mode_en:1
15562306a36Sopenharmony_ci * bit  5..14 : reserved0:10
15662306a36Sopenharmony_ci * bit     15 : ack_policy_en:1
15762306a36Sopenharmony_ci * bit 16..19 : dst_index:4
15862306a36Sopenharmony_ci * bit     20 : dst_index_en:1
15962306a36Sopenharmony_ci * bit 21..22 : ack_policy:2
16062306a36Sopenharmony_ci * bit     23 : lifetime_en:1
16162306a36Sopenharmony_ci * bit 24..30 : max_retry:7
16262306a36Sopenharmony_ci * bit     31 : max_retry_en:1
16362306a36Sopenharmony_ci * [dword 2]
16462306a36Sopenharmony_ci * bit  0.. 7 : num_of_descriptors:8
16562306a36Sopenharmony_ci * bit  8..17 : reserved:10
16662306a36Sopenharmony_ci * bit 18..19 : l2_translation_type:2 00 - bypass, 01 - 802.3, 10 - 802.11
16762306a36Sopenharmony_ci * bit     20 : snap_hdr_insertion_en:1
16862306a36Sopenharmony_ci * bit     21 : vlan_removal_en:1
16962306a36Sopenharmony_ci * bit 22..23 : reserved0:2
17062306a36Sopenharmony_ci * bit	   24 : Dest ID extension:1
17162306a36Sopenharmony_ci * bit 25..31 : reserved0:7
17262306a36Sopenharmony_ci * [dword 3]
17362306a36Sopenharmony_ci * bit  0..15 : tso_mss:16
17462306a36Sopenharmony_ci * bit 16..31 : descriptor_scratchpad:16 - mailbox between driver and ucode
17562306a36Sopenharmony_ci */
17662306a36Sopenharmony_cistruct wil_ring_tx_enhanced_mac {
17762306a36Sopenharmony_ci	u32 d[3];
17862306a36Sopenharmony_ci	__le16 tso_mss;
17962306a36Sopenharmony_ci	u16 scratchpad;
18062306a36Sopenharmony_ci} __packed;
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_cistruct wil_tx_enhanced_desc {
18362306a36Sopenharmony_ci	struct wil_ring_tx_enhanced_mac mac;
18462306a36Sopenharmony_ci	struct wil_ring_tx_enhanced_dma dma;
18562306a36Sopenharmony_ci} __packed;
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci#define TX_STATUS_DESC_READY_POS 7
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci/* Enhanced TX status message
19062306a36Sopenharmony_ci * [dword 0]
19162306a36Sopenharmony_ci *	bit  0.. 7 : Number of Descriptor:8 - The number of descriptors that
19262306a36Sopenharmony_ci *		     are used to form the packets. It  is needed for WB when
19362306a36Sopenharmony_ci *		     releasing the packet
19462306a36Sopenharmony_ci *	bit  8..15 : tx_ring_id:8 The transmission ring ID that is related to
19562306a36Sopenharmony_ci *		     the message
19662306a36Sopenharmony_ci *	bit 16..23 : Status:8 - The TX status Code
19762306a36Sopenharmony_ci *		0x0 - A successful transmission
19862306a36Sopenharmony_ci *		0x1 - Retry expired
19962306a36Sopenharmony_ci *		0x2 - Lifetime Expired
20062306a36Sopenharmony_ci *		0x3 - Released
20162306a36Sopenharmony_ci *		0x4-0xFF - Reserved
20262306a36Sopenharmony_ci *	bit 24..30 : Reserved:7
20362306a36Sopenharmony_ci *	bit     31 : Descriptor Ready bit:1 - It is initiated to
20462306a36Sopenharmony_ci *		zero by the driver when the ring is created. It is set by the HW
20562306a36Sopenharmony_ci *		to one for each completed status message. Each wrap around,
20662306a36Sopenharmony_ci *		the DR bit value is flipped.
20762306a36Sopenharmony_ci * [dword 1]
20862306a36Sopenharmony_ci *	bit 0..31  : timestamp:32 - Set when MPDU is transmitted.
20962306a36Sopenharmony_ci * [dword 2]
21062306a36Sopenharmony_ci *	bit  0.. 4 : MCS:5 - The transmitted MCS value
21162306a36Sopenharmony_ci *	bit      5 : Reserved:1
21262306a36Sopenharmony_ci *	bit  6.. 7 : CB mode:2 - 0-DMG 1-EDMG 2-Wide
21362306a36Sopenharmony_ci *	bit  8..12 : QID:5 - The QID that was used for the transmission
21462306a36Sopenharmony_ci *	bit 13..15 : Reserved:3
21562306a36Sopenharmony_ci *	bit 16..20 : Num of MSDUs:5 - Number of MSDUs in the aggregation
21662306a36Sopenharmony_ci *	bit 21..22 : Reserved:2
21762306a36Sopenharmony_ci *	bit     23 : Retry:1 - An indication that the transmission was retried
21862306a36Sopenharmony_ci *	bit 24..31 : TX-Sector:8 - the antenna sector that was used for
21962306a36Sopenharmony_ci *		     transmission
22062306a36Sopenharmony_ci * [dword 3]
22162306a36Sopenharmony_ci *	bit  0..11 : Sequence number:12 - The Sequence Number that was used
22262306a36Sopenharmony_ci *		     for the MPDU transmission
22362306a36Sopenharmony_ci *	bit 12..31 : Reserved:20
22462306a36Sopenharmony_ci */
22562306a36Sopenharmony_cistruct wil_ring_tx_status {
22662306a36Sopenharmony_ci	u8 num_descriptors;
22762306a36Sopenharmony_ci	u8 ring_id;
22862306a36Sopenharmony_ci	u8 status;
22962306a36Sopenharmony_ci	u8 desc_ready; /* Only the last bit should be set */
23062306a36Sopenharmony_ci	u32 timestamp;
23162306a36Sopenharmony_ci	u32 d2;
23262306a36Sopenharmony_ci	u16 seq_number; /* Only the first 12 bits */
23362306a36Sopenharmony_ci	u16 w7;
23462306a36Sopenharmony_ci} __packed;
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci/* Enhanced Rx status message - compressed part
23762306a36Sopenharmony_ci * [dword 0]
23862306a36Sopenharmony_ci *	bit  0.. 2 : L2 Rx Status:3 - The L2 packet reception Status
23962306a36Sopenharmony_ci *		     0-Success, 1-MIC Error, 2-Key Error, 3-Replay Error,
24062306a36Sopenharmony_ci *		     4-A-MSDU Error, 5-Reserved, 6-Reserved, 7-FCS Error
24162306a36Sopenharmony_ci *	bit  3.. 4 : L3 Rx Status:2 - Bit0 - L3I - L3 identified and checksum
24262306a36Sopenharmony_ci *		     calculated, Bit1- L3Err - IPv4 Checksum Error
24362306a36Sopenharmony_ci *	bit  5.. 6 : L4 Rx Status:2 - Bit0 - L4I - L4 identified and checksum
24462306a36Sopenharmony_ci *		     calculated, Bit1- L4Err - TCP/UDP Checksum Error
24562306a36Sopenharmony_ci *	bit      7 : Reserved:1
24662306a36Sopenharmony_ci *	bit  8..19 : Flow ID:12 - MSDU flow ID
24762306a36Sopenharmony_ci *	bit     20 : MID_V:1 - The MAC ID field is valid
24862306a36Sopenharmony_ci *	bit 21..22 : MID:2 - The MAC ID
24962306a36Sopenharmony_ci *	bit     23 : L3T:1 - IP types: 0-IPv6, 1-IPv4
25062306a36Sopenharmony_ci *	bit     24 : L4T:1 - Layer 4 Type: 0-UDP, 1-TCP
25162306a36Sopenharmony_ci *	bit     25 : BC:1 - The received MPDU is broadcast
25262306a36Sopenharmony_ci *	bit     26 : MC:1 - The received MPDU is multicast
25362306a36Sopenharmony_ci *	bit     27 : Raw:1 - The MPDU received with no translation
25462306a36Sopenharmony_ci *	bit     28 : Sec:1 - The FC control (b14) - Frame Protected
25562306a36Sopenharmony_ci *	bit     29 : Error:1 - An error is set when (L2 status != 0) ||
25662306a36Sopenharmony_ci *		(L3 status == 3) || (L4 status == 3)
25762306a36Sopenharmony_ci *	bit     30 : EOP:1 - End of MSDU signaling. It is set to mark the end
25862306a36Sopenharmony_ci *		     of the transfer, otherwise the status indicates buffer
25962306a36Sopenharmony_ci *		     only completion.
26062306a36Sopenharmony_ci *	bit     31 : Descriptor Ready bit:1 - It is initiated to
26162306a36Sopenharmony_ci *		     zero by the driver when the ring is created. It is set
26262306a36Sopenharmony_ci *		     by the HW to one for each completed status message.
26362306a36Sopenharmony_ci *		     Each wrap around, the DR bit value is flipped.
26462306a36Sopenharmony_ci * [dword 1]
26562306a36Sopenharmony_ci *	bit  0.. 5 : MAC Len:6 - The number of bytes that are used for L2 header
26662306a36Sopenharmony_ci *	bit  6..11 : IPLEN:6 - The number of DW that are used for L3 header
26762306a36Sopenharmony_ci *	bit 12..15 : I4Len:4 - The number of DW that are used for L4 header
26862306a36Sopenharmony_ci *	bit 16..21 : MCS:6 - The received MCS field from the PLCP Header
26962306a36Sopenharmony_ci *	bit 22..23 : CB mode:2 - The CB Mode: 0-DMG, 1-EDMG, 2-Wide
27062306a36Sopenharmony_ci *	bit 24..27 : Data Offset:4 - The data offset, a code that describe the
27162306a36Sopenharmony_ci *		     payload shift from the beginning of the buffer:
27262306a36Sopenharmony_ci *		     0 - 0 Bytes, 3 - 2 Bytes
27362306a36Sopenharmony_ci *	bit     28 : A-MSDU Present:1 - The QoS (b7) A-MSDU present field
27462306a36Sopenharmony_ci *	bit     29 : A-MSDU Type:1 The QoS (b8) A-MSDU Type field
27562306a36Sopenharmony_ci *	bit     30 : A-MPDU:1 - Packet is part of aggregated MPDU
27662306a36Sopenharmony_ci *	bit     31 : Key ID:1 - The extracted Key ID from the encryption header
27762306a36Sopenharmony_ci * [dword 2]
27862306a36Sopenharmony_ci *	bit  0..15 : Buffer ID:16 - The Buffer Identifier
27962306a36Sopenharmony_ci *	bit 16..31 : Length:16 - It indicates the valid bytes that are stored
28062306a36Sopenharmony_ci *		     in the current descriptor buffer. For multiple buffer
28162306a36Sopenharmony_ci *		     descriptor, SW need to sum the total descriptor length
28262306a36Sopenharmony_ci *		     in all buffers to produce the packet length
28362306a36Sopenharmony_ci * [dword 3]
28462306a36Sopenharmony_ci *	bit  0..31  : timestamp:32 - The MPDU Timestamp.
28562306a36Sopenharmony_ci */
28662306a36Sopenharmony_cistruct wil_rx_status_compressed {
28762306a36Sopenharmony_ci	u32 d0;
28862306a36Sopenharmony_ci	u32 d1;
28962306a36Sopenharmony_ci	__le16 buff_id;
29062306a36Sopenharmony_ci	__le16 length;
29162306a36Sopenharmony_ci	u32 timestamp;
29262306a36Sopenharmony_ci} __packed;
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ci/* Enhanced Rx status message - extension part
29562306a36Sopenharmony_ci * [dword 0]
29662306a36Sopenharmony_ci *	bit  0.. 4 : QID:5 - The Queue Identifier that the packet is received
29762306a36Sopenharmony_ci *		     from
29862306a36Sopenharmony_ci *	bit  5.. 7 : Reserved:3
29962306a36Sopenharmony_ci *	bit  8..11 : TID:4 - The QoS (b3-0) TID Field
30062306a36Sopenharmony_ci *	bit 12..15   Source index:4 - The Source index that was found
30162306a36Sopenharmony_ci		     during Parsing the TA. This field is used to define the
30262306a36Sopenharmony_ci		     source of the packet
30362306a36Sopenharmony_ci *	bit 16..18 : Destination index:3 - The Destination index that
30462306a36Sopenharmony_ci		     was found during Parsing the RA.
30562306a36Sopenharmony_ci *	bit 19..20 : DS Type:2 - The FC Control (b9-8) - From / To DS
30662306a36Sopenharmony_ci *	bit 21..22 : MIC ICR:2 - this signal tells the DMA to assert an
30762306a36Sopenharmony_ci		     interrupt after it writes the packet
30862306a36Sopenharmony_ci *	bit     23 : ESOP:1 - The QoS (b4) ESOP field
30962306a36Sopenharmony_ci *	bit     24 : RDG:1
31062306a36Sopenharmony_ci *	bit 25..31 : Reserved:7
31162306a36Sopenharmony_ci * [dword 1]
31262306a36Sopenharmony_ci *	bit  0.. 1 : Frame Type:2 - The FC Control (b3-2) - MPDU Type
31362306a36Sopenharmony_ci		     (management, data, control and extension)
31462306a36Sopenharmony_ci *	bit  2.. 5 : Syb type:4 - The FC Control (b7-4) - Frame Subtype
31562306a36Sopenharmony_ci *	bit  6..11 : Ext sub type:6 - The FC Control (b11-8) - Frame Extended
31662306a36Sopenharmony_ci *                   Subtype
31762306a36Sopenharmony_ci *	bit 12..13 : ACK Policy:2 - The QoS (b6-5) ACK Policy fields
31862306a36Sopenharmony_ci *	bit 14     : DECRYPT_BYP:1 - The MPDU is bypass by the decryption unit
31962306a36Sopenharmony_ci *	bit 15..23 : Reserved:9
32062306a36Sopenharmony_ci *	bit 24..31 : RSSI/SNR:8 - The RSSI / SNR measurement for the received
32162306a36Sopenharmony_ci *                   MPDU
32262306a36Sopenharmony_ci * [dword 2]
32362306a36Sopenharmony_ci *	bit  0..11 : SN:12 - The received Sequence number field
32462306a36Sopenharmony_ci *	bit 12..15 : Reserved:4
32562306a36Sopenharmony_ci *	bit 16..31 : PN bits [15:0]:16
32662306a36Sopenharmony_ci * [dword 3]
32762306a36Sopenharmony_ci *	bit  0..31 : PN bits [47:16]:32
32862306a36Sopenharmony_ci */
32962306a36Sopenharmony_cistruct wil_rx_status_extension {
33062306a36Sopenharmony_ci	u32 d0;
33162306a36Sopenharmony_ci	u32 d1;
33262306a36Sopenharmony_ci	__le16 seq_num; /* only lower 12 bits */
33362306a36Sopenharmony_ci	struct_group_attr(pn, __packed,
33462306a36Sopenharmony_ci		u16 pn_15_0;
33562306a36Sopenharmony_ci		u32 pn_47_16;
33662306a36Sopenharmony_ci	);
33762306a36Sopenharmony_ci} __packed;
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_cistruct wil_rx_status_extended {
34062306a36Sopenharmony_ci	struct wil_rx_status_compressed comp;
34162306a36Sopenharmony_ci	struct wil_rx_status_extension ext;
34262306a36Sopenharmony_ci} __packed;
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_cistatic inline void *wil_skb_rxstatus(struct sk_buff *skb)
34562306a36Sopenharmony_ci{
34662306a36Sopenharmony_ci	return (void *)skb->cb;
34762306a36Sopenharmony_ci}
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_cistatic inline __le16 wil_rx_status_get_length(void *msg)
35062306a36Sopenharmony_ci{
35162306a36Sopenharmony_ci	return ((struct wil_rx_status_compressed *)msg)->length;
35262306a36Sopenharmony_ci}
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_cistatic inline u8 wil_rx_status_get_mcs(void *msg)
35562306a36Sopenharmony_ci{
35662306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d1,
35762306a36Sopenharmony_ci			    16, 21);
35862306a36Sopenharmony_ci}
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_cistatic inline u8 wil_rx_status_get_cb_mode(void *msg)
36162306a36Sopenharmony_ci{
36262306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d1,
36362306a36Sopenharmony_ci			    22, 23);
36462306a36Sopenharmony_ci}
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_cistatic inline u16 wil_rx_status_get_flow_id(void *msg)
36762306a36Sopenharmony_ci{
36862306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
36962306a36Sopenharmony_ci			    8, 19);
37062306a36Sopenharmony_ci}
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_cistatic inline u8 wil_rx_status_get_mcast(void *msg)
37362306a36Sopenharmony_ci{
37462306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
37562306a36Sopenharmony_ci			    26, 26);
37662306a36Sopenharmony_ci}
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_ci/**
37962306a36Sopenharmony_ci * In case of DLPF miss the parsing of flow Id should be as follows:
38062306a36Sopenharmony_ci * dest_id:2
38162306a36Sopenharmony_ci * src_id :3 - cid
38262306a36Sopenharmony_ci * tid:3
38362306a36Sopenharmony_ci * Otherwise:
38462306a36Sopenharmony_ci * tid:4
38562306a36Sopenharmony_ci * cid:4
38662306a36Sopenharmony_ci */
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_cistatic inline u8 wil_rx_status_get_cid(void *msg)
38962306a36Sopenharmony_ci{
39062306a36Sopenharmony_ci	u16 val = wil_rx_status_get_flow_id(msg);
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_ci	if (val & WIL_RX_EDMA_DLPF_LU_MISS_BIT)
39362306a36Sopenharmony_ci		/* CID is in bits 2..4 */
39462306a36Sopenharmony_ci		return (val >> WIL_RX_EDMA_DLPF_LU_MISS_CID_POS) &
39562306a36Sopenharmony_ci			WIL_RX_EDMA_DLPF_LU_MISS_CID_TID_MASK;
39662306a36Sopenharmony_ci	else
39762306a36Sopenharmony_ci		/* CID is in bits 4..7 */
39862306a36Sopenharmony_ci		return (val >> WIL_RX_EDMA_DLPF_LU_HIT_CID_POS) &
39962306a36Sopenharmony_ci			WIL_RX_EDMA_DLPF_LU_HIT_CID_TID_MASK;
40062306a36Sopenharmony_ci}
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_cistatic inline u8 wil_rx_status_get_tid(void *msg)
40362306a36Sopenharmony_ci{
40462306a36Sopenharmony_ci	u16 val = wil_rx_status_get_flow_id(msg);
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci	if (val & WIL_RX_EDMA_DLPF_LU_MISS_BIT)
40762306a36Sopenharmony_ci		/* TID is in bits 5..7 */
40862306a36Sopenharmony_ci		return (val >> WIL_RX_EDMA_DLPF_LU_MISS_TID_POS) &
40962306a36Sopenharmony_ci			WIL_RX_EDMA_DLPF_LU_MISS_CID_TID_MASK;
41062306a36Sopenharmony_ci	else
41162306a36Sopenharmony_ci		/* TID is in bits 0..3 */
41262306a36Sopenharmony_ci		return val & WIL_RX_EDMA_DLPF_LU_MISS_CID_TID_MASK;
41362306a36Sopenharmony_ci}
41462306a36Sopenharmony_ci
41562306a36Sopenharmony_cistatic inline int wil_rx_status_get_eop(void *msg) /* EoP = End of Packet */
41662306a36Sopenharmony_ci{
41762306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
41862306a36Sopenharmony_ci			    30, 30);
41962306a36Sopenharmony_ci}
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_cistatic inline void wil_rx_status_reset_buff_id(struct wil_status_ring *s)
42262306a36Sopenharmony_ci{
42362306a36Sopenharmony_ci	((struct wil_rx_status_compressed *)
42462306a36Sopenharmony_ci		(s->va + (s->elem_size * s->swhead)))->buff_id = 0;
42562306a36Sopenharmony_ci}
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_cistatic inline __le16 wil_rx_status_get_buff_id(void *msg)
42862306a36Sopenharmony_ci{
42962306a36Sopenharmony_ci	return ((struct wil_rx_status_compressed *)msg)->buff_id;
43062306a36Sopenharmony_ci}
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_cistatic inline u8 wil_rx_status_get_data_offset(void *msg)
43362306a36Sopenharmony_ci{
43462306a36Sopenharmony_ci	u8 val = WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d1,
43562306a36Sopenharmony_ci			      24, 27);
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_ci	switch (val) {
43862306a36Sopenharmony_ci	case 0: return 0;
43962306a36Sopenharmony_ci	case 3: return 2;
44062306a36Sopenharmony_ci	default: return 0xFF;
44162306a36Sopenharmony_ci	}
44262306a36Sopenharmony_ci}
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_cistatic inline int wil_rx_status_get_frame_type(struct wil6210_priv *wil,
44562306a36Sopenharmony_ci					       void *msg)
44662306a36Sopenharmony_ci{
44762306a36Sopenharmony_ci	if (wil->use_compressed_rx_status)
44862306a36Sopenharmony_ci		return IEEE80211_FTYPE_DATA;
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_extended *)msg)->ext.d1,
45162306a36Sopenharmony_ci			    0, 1) << 2;
45262306a36Sopenharmony_ci}
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_cistatic inline int wil_rx_status_get_fc1(struct wil6210_priv *wil, void *msg)
45562306a36Sopenharmony_ci{
45662306a36Sopenharmony_ci	if (wil->use_compressed_rx_status)
45762306a36Sopenharmony_ci		return 0;
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_extended *)msg)->ext.d1,
46062306a36Sopenharmony_ci			    0, 5) << 2;
46162306a36Sopenharmony_ci}
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_cistatic inline __le16 wil_rx_status_get_seq(struct wil6210_priv *wil, void *msg)
46462306a36Sopenharmony_ci{
46562306a36Sopenharmony_ci	if (wil->use_compressed_rx_status)
46662306a36Sopenharmony_ci		return 0;
46762306a36Sopenharmony_ci
46862306a36Sopenharmony_ci	return ((struct wil_rx_status_extended *)msg)->ext.seq_num;
46962306a36Sopenharmony_ci}
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_cistatic inline u8 wil_rx_status_get_retry(void *msg)
47262306a36Sopenharmony_ci{
47362306a36Sopenharmony_ci	/* retry bit is missing in EDMA HW. return 1 to be on the safe side */
47462306a36Sopenharmony_ci	return 1;
47562306a36Sopenharmony_ci}
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_cistatic inline int wil_rx_status_get_mid(void *msg)
47862306a36Sopenharmony_ci{
47962306a36Sopenharmony_ci	if (!(((struct wil_rx_status_compressed *)msg)->d0 &
48062306a36Sopenharmony_ci	    WIL_RX_EDMA_MID_VALID_BIT))
48162306a36Sopenharmony_ci		return 0; /* use the default MID */
48262306a36Sopenharmony_ci
48362306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
48462306a36Sopenharmony_ci			    21, 22);
48562306a36Sopenharmony_ci}
48662306a36Sopenharmony_ci
48762306a36Sopenharmony_cistatic inline int wil_rx_status_get_error(void *msg)
48862306a36Sopenharmony_ci{
48962306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
49062306a36Sopenharmony_ci			    29, 29);
49162306a36Sopenharmony_ci}
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_cistatic inline int wil_rx_status_get_l2_rx_status(void *msg)
49462306a36Sopenharmony_ci{
49562306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
49662306a36Sopenharmony_ci			    0, 2);
49762306a36Sopenharmony_ci}
49862306a36Sopenharmony_ci
49962306a36Sopenharmony_cistatic inline int wil_rx_status_get_l3_rx_status(void *msg)
50062306a36Sopenharmony_ci{
50162306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
50262306a36Sopenharmony_ci			    3, 4);
50362306a36Sopenharmony_ci}
50462306a36Sopenharmony_ci
50562306a36Sopenharmony_cistatic inline int wil_rx_status_get_l4_rx_status(void *msg)
50662306a36Sopenharmony_ci{
50762306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
50862306a36Sopenharmony_ci			    5, 6);
50962306a36Sopenharmony_ci}
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci/* L4	L3	Expected result
51262306a36Sopenharmony_ci * 0	0	Ok. No L3 and no L4 known protocols found.
51362306a36Sopenharmony_ci *		Treated as L2 packet. (no offloads on this packet)
51462306a36Sopenharmony_ci * 0	1	Ok. It means that L3 was found, and checksum check passed.
51562306a36Sopenharmony_ci *		No known L4 protocol was found.
51662306a36Sopenharmony_ci * 0	2	It means that L3 protocol was found, and checksum check failed.
51762306a36Sopenharmony_ci *		No L4 known protocol was found.
51862306a36Sopenharmony_ci * 1	any	Ok. It means that L4 was found, and checksum check passed.
51962306a36Sopenharmony_ci * 3	0	Not a possible scenario.
52062306a36Sopenharmony_ci * 3	1	Recalculate. It means that L3 protocol was found, and checksum
52162306a36Sopenharmony_ci *		passed. But L4 checksum failed. Need to see if really failed,
52262306a36Sopenharmony_ci *		or due to fragmentation.
52362306a36Sopenharmony_ci * 3	2	Both L3 and L4 checksum check failed.
52462306a36Sopenharmony_ci */
52562306a36Sopenharmony_cistatic inline int wil_rx_status_get_checksum(void *msg,
52662306a36Sopenharmony_ci					     struct wil_net_stats *stats)
52762306a36Sopenharmony_ci{
52862306a36Sopenharmony_ci	int l3_rx_status = wil_rx_status_get_l3_rx_status(msg);
52962306a36Sopenharmony_ci	int l4_rx_status = wil_rx_status_get_l4_rx_status(msg);
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci	if (l4_rx_status == 1)
53262306a36Sopenharmony_ci		return CHECKSUM_UNNECESSARY;
53362306a36Sopenharmony_ci
53462306a36Sopenharmony_ci	if (l4_rx_status == 0 && l3_rx_status == 1)
53562306a36Sopenharmony_ci		return CHECKSUM_UNNECESSARY;
53662306a36Sopenharmony_ci
53762306a36Sopenharmony_ci	if (l3_rx_status == 0 && l4_rx_status == 0)
53862306a36Sopenharmony_ci		/* L2 packet */
53962306a36Sopenharmony_ci		return CHECKSUM_NONE;
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci	/* If HW reports bad checksum, let IP stack re-check it
54262306a36Sopenharmony_ci	 * For example, HW doesn't understand Microsoft IP stack that
54362306a36Sopenharmony_ci	 * mis-calculates TCP checksum - if it should be 0x0,
54462306a36Sopenharmony_ci	 * it writes 0xffff in violation of RFC 1624
54562306a36Sopenharmony_ci	 */
54662306a36Sopenharmony_ci	stats->rx_csum_err++;
54762306a36Sopenharmony_ci	return CHECKSUM_NONE;
54862306a36Sopenharmony_ci}
54962306a36Sopenharmony_ci
55062306a36Sopenharmony_cistatic inline int wil_rx_status_get_security(void *msg)
55162306a36Sopenharmony_ci{
55262306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d0,
55362306a36Sopenharmony_ci			    28, 28);
55462306a36Sopenharmony_ci}
55562306a36Sopenharmony_ci
55662306a36Sopenharmony_cistatic inline u8 wil_rx_status_get_key_id(void *msg)
55762306a36Sopenharmony_ci{
55862306a36Sopenharmony_ci	return WIL_GET_BITS(((struct wil_rx_status_compressed *)msg)->d1,
55962306a36Sopenharmony_ci			    31, 31);
56062306a36Sopenharmony_ci}
56162306a36Sopenharmony_ci
56262306a36Sopenharmony_cistatic inline u8 wil_tx_status_get_mcs(struct wil_ring_tx_status *msg)
56362306a36Sopenharmony_ci{
56462306a36Sopenharmony_ci	return WIL_GET_BITS(msg->d2, 0, 4);
56562306a36Sopenharmony_ci}
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_cistatic inline u32 wil_ring_next_head(struct wil_ring *ring)
56862306a36Sopenharmony_ci{
56962306a36Sopenharmony_ci	return (ring->swhead + 1) % ring->size;
57062306a36Sopenharmony_ci}
57162306a36Sopenharmony_ci
57262306a36Sopenharmony_cistatic inline void wil_desc_set_addr_edma(struct wil_ring_dma_addr *addr,
57362306a36Sopenharmony_ci					  __le16 *addr_high_high,
57462306a36Sopenharmony_ci					  dma_addr_t pa)
57562306a36Sopenharmony_ci{
57662306a36Sopenharmony_ci	addr->addr_low = cpu_to_le32(lower_32_bits(pa));
57762306a36Sopenharmony_ci	addr->addr_high = cpu_to_le16((u16)upper_32_bits(pa));
57862306a36Sopenharmony_ci	*addr_high_high = cpu_to_le16((u16)(upper_32_bits(pa) >> 16));
57962306a36Sopenharmony_ci}
58062306a36Sopenharmony_ci
58162306a36Sopenharmony_cistatic inline
58262306a36Sopenharmony_cidma_addr_t wil_tx_desc_get_addr_edma(struct wil_ring_tx_enhanced_dma *dma)
58362306a36Sopenharmony_ci{
58462306a36Sopenharmony_ci	return le32_to_cpu(dma->addr.addr_low) |
58562306a36Sopenharmony_ci			   ((u64)le16_to_cpu(dma->addr.addr_high) << 32) |
58662306a36Sopenharmony_ci			   ((u64)le16_to_cpu(dma->addr_high_high) << 48);
58762306a36Sopenharmony_ci}
58862306a36Sopenharmony_ci
58962306a36Sopenharmony_cistatic inline
59062306a36Sopenharmony_cidma_addr_t wil_rx_desc_get_addr_edma(struct wil_ring_rx_enhanced_dma *dma)
59162306a36Sopenharmony_ci{
59262306a36Sopenharmony_ci	return le32_to_cpu(dma->addr.addr_low) |
59362306a36Sopenharmony_ci			   ((u64)le16_to_cpu(dma->addr.addr_high) << 32) |
59462306a36Sopenharmony_ci			   ((u64)le16_to_cpu(dma->addr_high_high) << 48);
59562306a36Sopenharmony_ci}
59662306a36Sopenharmony_ci
59762306a36Sopenharmony_civoid wil_configure_interrupt_moderation_edma(struct wil6210_priv *wil);
59862306a36Sopenharmony_ciint wil_tx_sring_handler(struct wil6210_priv *wil,
59962306a36Sopenharmony_ci			 struct wil_status_ring *sring);
60062306a36Sopenharmony_civoid wil_rx_handle_edma(struct wil6210_priv *wil, int *quota);
60162306a36Sopenharmony_civoid wil_init_txrx_ops_edma(struct wil6210_priv *wil);
60262306a36Sopenharmony_ci
60362306a36Sopenharmony_ci#endif /* WIL6210_TXRX_EDMA_H */
60462306a36Sopenharmony_ci
605