Skip to content

Commit e9f476d

Browse files
halfboy93anguy11
authored andcommitted
iavf: define Rx descriptors as qwords
The union iavf_32byte_rx_desc consists of two unnamed structs defined inside. One of them represents legacy 32 byte descriptor and second the 16 byte descriptor (extended to 32 byte). Each of them consists of bunch of unions, structs and __le fields that represent specific fields in descriptor. This commit changes the representation of iavf_32byte_rx_desc union to store four __le64 fields (qw0, qw1, qw2, qw3) that represent quad-words. Those quad-words will be then accessed by calling leXY_get_bits macros in upcoming commits. Suggested-by: Alexander Lobakin <aleksander.lobakin@intel.com> Tested-by: Rafal Romanowski <rafal.romanowski@intel.com> Signed-off-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent ce5cf4a commit e9f476d

File tree

5 files changed

+77
-111
lines changed

5 files changed

+77
-111
lines changed

drivers/net/ethernet/intel/iavf/iavf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct iavf_vsi {
8383

8484
#define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
8585

86-
#define IAVF_RX_DESC(R, i) (&(((union iavf_32byte_rx_desc *)((R)->desc))[i]))
86+
#define IAVF_RX_DESC(R, i) (&(((struct iavf_rx_desc *)((R)->desc))[i]))
8787
#define IAVF_TX_DESC(R, i) (&(((struct iavf_tx_desc *)((R)->desc))[i]))
8888
#define IAVF_TX_CTXTDESC(R, i) \
8989
(&(((struct iavf_tx_context_desc *)((R)->desc))[i]))

drivers/net/ethernet/intel/iavf/iavf_trace.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ DECLARE_EVENT_CLASS(
112112
iavf_rx_template,
113113

114114
TP_PROTO(struct iavf_ring *ring,
115-
union iavf_32byte_rx_desc *desc,
115+
struct iavf_rx_desc *desc,
116116
struct sk_buff *skb),
117117

118118
TP_ARGS(ring, desc, skb),
@@ -140,15 +140,15 @@ DECLARE_EVENT_CLASS(
140140
DEFINE_EVENT(
141141
iavf_rx_template, iavf_clean_rx_irq,
142142
TP_PROTO(struct iavf_ring *ring,
143-
union iavf_32byte_rx_desc *desc,
143+
struct iavf_rx_desc *desc,
144144
struct sk_buff *skb),
145145

146146
TP_ARGS(ring, desc, skb));
147147

148148
DEFINE_EVENT(
149149
iavf_rx_template, iavf_clean_rx_irq_rx,
150150
TP_PROTO(struct iavf_ring *ring,
151-
union iavf_32byte_rx_desc *desc,
151+
struct iavf_rx_desc *desc,
152152
struct sk_buff *skb),
153153

154154
TP_ARGS(ring, desc, skb));

drivers/net/ethernet/intel/iavf/iavf_txrx.c

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ int iavf_setup_rx_descriptors(struct iavf_ring *rx_ring)
766766
u64_stats_init(&rx_ring->syncp);
767767

768768
/* Round up to nearest 4K */
769-
rx_ring->size = rx_ring->count * sizeof(union iavf_32byte_rx_desc);
769+
rx_ring->size = rx_ring->count * sizeof(struct iavf_rx_desc);
770770
rx_ring->size = ALIGN(rx_ring->size, 4096);
771771
rx_ring->desc = dma_alloc_coherent(fq.pp->p.dev, rx_ring->size,
772772
&rx_ring->dma, GFP_KERNEL);
@@ -845,7 +845,7 @@ bool iavf_alloc_rx_buffers(struct iavf_ring *rx_ring, u16 cleaned_count)
845845
.count = rx_ring->count,
846846
};
847847
u16 ntu = rx_ring->next_to_use;
848-
union iavf_rx_desc *rx_desc;
848+
struct iavf_rx_desc *rx_desc;
849849

850850
/* do nothing if no valid netdev defined */
851851
if (!rx_ring->netdev || !cleaned_count)
@@ -863,7 +863,7 @@ bool iavf_alloc_rx_buffers(struct iavf_ring *rx_ring, u16 cleaned_count)
863863
/* Refresh the desc even if buffer_addrs didn't change
864864
* because each write-back erases this info.
865865
*/
866-
rx_desc->read.pkt_addr = cpu_to_le64(addr);
866+
rx_desc->qw0 = cpu_to_le64(addr);
867867

868868
rx_desc++;
869869
ntu++;
@@ -873,7 +873,7 @@ bool iavf_alloc_rx_buffers(struct iavf_ring *rx_ring, u16 cleaned_count)
873873
}
874874

875875
/* clear the status bits for the next_to_use descriptor */
876-
rx_desc->wb.qword1.status_error_len = 0;
876+
rx_desc->qw1 = 0;
877877

878878
cleaned_count--;
879879
} while (cleaned_count);
@@ -901,19 +901,18 @@ bool iavf_alloc_rx_buffers(struct iavf_ring *rx_ring, u16 cleaned_count)
901901
* @skb: skb currently being received and modified
902902
* @rx_desc: the receive descriptor
903903
**/
904-
static void iavf_rx_checksum(struct iavf_vsi *vsi,
905-
struct sk_buff *skb,
906-
union iavf_rx_desc *rx_desc)
904+
static void iavf_rx_checksum(struct iavf_vsi *vsi, struct sk_buff *skb,
905+
struct iavf_rx_desc *rx_desc)
907906
{
908907
struct libeth_rx_pt decoded;
909908
u32 rx_error, rx_status;
910909
bool ipv4, ipv6;
911-
u8 ptype;
912910
u64 qword;
911+
u32 ptype;
913912

914913
skb->ip_summed = CHECKSUM_NONE;
915914

916-
qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
915+
qword = le64_to_cpu(rx_desc->qw1);
917916
ptype = FIELD_GET(IAVF_RXD_QW1_PTYPE_MASK, qword);
918917

919918
decoded = libie_rx_pt_parse(ptype);
@@ -967,7 +966,7 @@ static void iavf_rx_checksum(struct iavf_vsi *vsi,
967966
* @rx_ptype: Rx packet type
968967
**/
969968
static void iavf_rx_hash(struct iavf_ring *ring,
970-
union iavf_rx_desc *rx_desc,
969+
struct iavf_rx_desc *rx_desc,
971970
struct sk_buff *skb,
972971
u8 rx_ptype)
973972
{
@@ -981,8 +980,8 @@ static void iavf_rx_hash(struct iavf_ring *ring,
981980
if (!libeth_rx_pt_has_hash(ring->netdev, decoded))
982981
return;
983982

984-
if ((rx_desc->wb.qword1.status_error_len & rss_mask) == rss_mask) {
985-
hash = le32_to_cpu(rx_desc->wb.qword0.hi_dword.rss);
983+
if ((rx_desc->qw1 & rss_mask) == rss_mask) {
984+
hash = le64_get_bits(rx_desc->qw0, IAVF_RXD_LEGACY_RSS_M);
986985
libeth_rx_pt_set_hash(skb, hash, decoded);
987986
}
988987
}
@@ -1000,7 +999,7 @@ static void iavf_rx_hash(struct iavf_ring *ring,
1000999
**/
10011000
static void
10021001
iavf_process_skb_fields(struct iavf_ring *rx_ring,
1003-
union iavf_rx_desc *rx_desc, struct sk_buff *skb,
1002+
struct iavf_rx_desc *rx_desc, struct sk_buff *skb,
10041003
u8 rx_ptype)
10051004
{
10061005
iavf_rx_hash(rx_ring, rx_desc, skb, rx_ptype);
@@ -1101,7 +1100,7 @@ static struct sk_buff *iavf_build_skb(const struct libeth_fqe *rx_buffer,
11011100
* that this is in fact a non-EOP buffer.
11021101
**/
11031102
static bool iavf_is_non_eop(struct iavf_ring *rx_ring,
1104-
union iavf_rx_desc *rx_desc,
1103+
struct iavf_rx_desc *rx_desc,
11051104
struct sk_buff *skb)
11061105
{
11071106
u32 ntc = rx_ring->next_to_clean + 1;
@@ -1143,11 +1142,12 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)
11431142

11441143
while (likely(total_rx_packets < (unsigned int)budget)) {
11451144
struct libeth_fqe *rx_buffer;
1146-
union iavf_rx_desc *rx_desc;
1145+
struct iavf_rx_desc *rx_desc;
1146+
u16 ext_status = 0;
11471147
unsigned int size;
11481148
u16 vlan_tag = 0;
11491149
u8 rx_ptype;
1150-
u64 qword;
1150+
u64 qw1;
11511151

11521152
/* return some buffers to hardware, one at a time is too slow */
11531153
if (cleaned_count >= IAVF_RX_BUFFER_WRITE) {
@@ -1163,7 +1163,7 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)
11631163
* which is always zero because packet split isn't used, if the
11641164
* hardware wrote DD then the length will be non-zero
11651165
*/
1166-
qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
1166+
qw1 = le64_to_cpu(rx_desc->qw1);
11671167

11681168
/* This memory barrier is needed to keep us from reading
11691169
* any other fields out of the rx_desc until we have
@@ -1174,7 +1174,7 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)
11741174
if (!iavf_test_staterr(rx_desc, IAVF_RXD_DD))
11751175
break;
11761176

1177-
size = FIELD_GET(IAVF_RXD_QW1_LENGTH_PBUF_MASK, qword);
1177+
size = FIELD_GET(IAVF_RXD_QW1_LENGTH_PBUF_MASK, qw1);
11781178

11791179
iavf_trace(clean_rx_irq, rx_ring, rx_desc, skb);
11801180

@@ -1219,19 +1219,23 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)
12191219
/* probably a little skewed due to removing CRC */
12201220
total_rx_bytes += skb->len;
12211221

1222-
qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
1223-
rx_ptype = FIELD_GET(IAVF_RXD_QW1_PTYPE_MASK, qword);
1222+
rx_ptype = FIELD_GET(IAVF_RXD_QW1_PTYPE_MASK, qw1);
12241223

12251224
/* populate checksum, VLAN, and protocol */
12261225
iavf_process_skb_fields(rx_ring, rx_desc, skb, rx_ptype);
12271226

1228-
if (qword & BIT(IAVF_RX_DESC_STATUS_L2TAG1P_SHIFT) &&
1227+
if (qw1 & BIT(IAVF_RX_DESC_STATUS_L2TAG1P_SHIFT) &&
12291228
rx_ring->flags & IAVF_TXRX_FLAGS_VLAN_TAG_LOC_L2TAG1)
1230-
vlan_tag = le16_to_cpu(rx_desc->wb.qword0.lo_dword.l2tag1);
1231-
if (rx_desc->wb.qword2.ext_status &
1232-
cpu_to_le16(BIT(IAVF_RX_DESC_EXT_STATUS_L2TAG2P_SHIFT)) &&
1233-
rx_ring->flags & IAVF_RXR_FLAGS_VLAN_TAG_LOC_L2TAG2_2)
1234-
vlan_tag = le16_to_cpu(rx_desc->wb.qword2.l2tag2_2);
1229+
vlan_tag = le64_get_bits(rx_desc->qw0,
1230+
IAVF_RXD_LEGACY_L2TAG1_M);
1231+
1232+
ext_status = le64_get_bits(rx_desc->qw2,
1233+
IAVF_RXD_LEGACY_EXT_STATUS_M);
1234+
1235+
if ((ext_status & IAVF_RX_DESC_EXT_STATUS_L2TAG2P_M) &&
1236+
(rx_ring->flags & IAVF_RXR_FLAGS_VLAN_TAG_LOC_L2TAG2_2))
1237+
vlan_tag = le64_get_bits(rx_desc->qw2,
1238+
IAVF_RXD_LEGACY_L2TAG2_2_M);
12351239

12361240
iavf_trace(clean_rx_irq_rx, rx_ring, rx_desc, skb);
12371241
iavf_receive_skb(rx_ring, skb, vlan_tag);

drivers/net/ethernet/intel/iavf/iavf_txrx.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ enum iavf_dyn_idx_t {
8080
BIT_ULL(IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | \
8181
BIT_ULL(IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP))
8282

83-
#define iavf_rx_desc iavf_32byte_rx_desc
84-
8583
/**
8684
* iavf_test_staterr - tests bits in Rx descriptor status and error fields
8785
* @rx_desc: pointer to receive descriptor (in le64 format)
@@ -92,11 +90,10 @@ enum iavf_dyn_idx_t {
9290
* The status_error_len doesn't need to be shifted because it begins
9391
* at offset zero.
9492
*/
95-
static inline bool iavf_test_staterr(union iavf_rx_desc *rx_desc,
93+
static inline bool iavf_test_staterr(struct iavf_rx_desc *rx_desc,
9694
const u64 stat_err_bits)
9795
{
98-
return !!(rx_desc->wb.qword1.status_error_len &
99-
cpu_to_le64(stat_err_bits));
96+
return !!(rx_desc->qw1 & cpu_to_le64(stat_err_bits));
10097
}
10198

10299
/* How many Rx Buffers do we bundle into one write to the hardware ? */

drivers/net/ethernet/intel/iavf/iavf_type.h

Lines changed: 41 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -178,82 +178,45 @@ struct iavf_hw {
178178
char err_str[16];
179179
};
180180

181-
/* RX Descriptors */
182-
union iavf_16byte_rx_desc {
183-
struct {
184-
__le64 pkt_addr; /* Packet buffer address */
185-
__le64 hdr_addr; /* Header buffer address */
186-
} read;
187-
struct {
188-
struct {
189-
struct {
190-
union {
191-
__le16 mirroring_status;
192-
__le16 fcoe_ctx_id;
193-
} mirr_fcoe;
194-
__le16 l2tag1;
195-
} lo_dword;
196-
union {
197-
__le32 rss; /* RSS Hash */
198-
__le32 fd_id; /* Flow director filter id */
199-
__le32 fcoe_param; /* FCoE DDP Context id */
200-
} hi_dword;
201-
} qword0;
202-
struct {
203-
/* ext status/error/pktype/length */
204-
__le64 status_error_len;
205-
} qword1;
206-
} wb; /* writeback */
207-
};
208-
209-
union iavf_32byte_rx_desc {
210-
struct {
211-
__le64 pkt_addr; /* Packet buffer address */
212-
__le64 hdr_addr; /* Header buffer address */
213-
/* bit 0 of hdr_buffer_addr is DD bit */
214-
__le64 rsvd1;
215-
__le64 rsvd2;
216-
} read;
217-
struct {
218-
struct {
219-
struct {
220-
union {
221-
__le16 mirroring_status;
222-
__le16 fcoe_ctx_id;
223-
} mirr_fcoe;
224-
__le16 l2tag1;
225-
} lo_dword;
226-
union {
227-
__le32 rss; /* RSS Hash */
228-
__le32 fcoe_param; /* FCoE DDP Context id */
229-
/* Flow director filter id in case of
230-
* Programming status desc WB
231-
*/
232-
__le32 fd_id;
233-
} hi_dword;
234-
} qword0;
235-
struct {
236-
/* status/error/pktype/length */
237-
__le64 status_error_len;
238-
} qword1;
239-
struct {
240-
__le16 ext_status; /* extended status */
241-
__le16 rsvd;
242-
__le16 l2tag2_1;
243-
__le16 l2tag2_2;
244-
} qword2;
245-
struct {
246-
union {
247-
__le32 flex_bytes_lo;
248-
__le32 pe_status;
249-
} lo_dword;
250-
union {
251-
__le32 flex_bytes_hi;
252-
__le32 fd_id;
253-
} hi_dword;
254-
} qword3;
255-
} wb; /* writeback */
256-
};
181+
/**
182+
* struct iavf_rx_desc - Receive descriptor (both legacy and flexible)
183+
* @qw0: quad word 0 fields:
184+
* Legacy: Descriptor Type; Mirror ID; L2TAG1P (S-TAG); Filter Status
185+
* Flex: Descriptor Type; Mirror ID; UMBCAST; Packet Type; Flexible Flags
186+
* Section 0; Packet Length; Header Length; Split Header Flag;
187+
* Flexible Flags section 1 / Extended Status
188+
* @qw1: quad word 1 fields:
189+
* Legacy: Status Field; Error Field; Packet Type; Packet Length (packet,
190+
* header, Split Header Flag)
191+
* Flex: Status / Error 0 Field; L2TAG1P (S-TAG); Flexible Metadata
192+
* Container #0; Flexible Metadata Container #1
193+
* @qw2: quad word 2 fields:
194+
* Legacy: Extended Status; 1st L2TAG2P (C-TAG); 2nd L2TAG2P (C-TAG)
195+
* Flex: Status / Error 1 Field; Flexible Flags section 2; Timestamp Low;
196+
* 1st L2TAG2 (C-TAG); 2nd L2TAG2 (C-TAG)
197+
* @qw3: quad word 3 fields:
198+
* Legacy: FD Filter ID / Flexible Bytes
199+
* Flex: Flexible Metadata Container #2; Flexible Metadata Container #3;
200+
* Flexible Metadata Container #4 / Timestamp High 0; Flexible
201+
* Metadata Container #5 / Timestamp High 1;
202+
*/
203+
struct iavf_rx_desc {
204+
aligned_le64 qw0;
205+
/* The hash signature (RSS) */
206+
#define IAVF_RXD_LEGACY_RSS_M GENMASK_ULL(63, 32)
207+
/* Stripped C-TAG VLAN from the receive packet */
208+
#define IAVF_RXD_LEGACY_L2TAG1_M GENMASK_ULL(33, 16)
209+
210+
aligned_le64 qw1;
211+
aligned_le64 qw2;
212+
/* Stripped S-TAG VLAN from the receive packet */
213+
#define IAVF_RXD_LEGACY_L2TAG2_2_M GENMASK_ULL(63, 48)
214+
/* Extended status bits */
215+
#define IAVF_RXD_LEGACY_EXT_STATUS_M GENMASK_ULL(11, 0)
216+
217+
aligned_le64 qw3;
218+
} __aligned(4 * sizeof(__le64));
219+
static_assert(sizeof(struct iavf_rx_desc) == 32);
257220

258221
enum iavf_rx_desc_status_bits {
259222
/* Note: These are predefined bit offsets */
@@ -347,6 +310,8 @@ enum iavf_rx_desc_ext_status_bits {
347310
IAVF_RX_DESC_EXT_STATUS_PELONGB_SHIFT = 11,
348311
};
349312

313+
#define IAVF_RX_DESC_EXT_STATUS_L2TAG2P_M BIT(IAVF_RX_DESC_EXT_STATUS_L2TAG2P_SHIFT)
314+
350315
enum iavf_rx_desc_pe_status_bits {
351316
/* Note: These are predefined bit offsets */
352317
IAVF_RX_DESC_PE_STATUS_QPID_SHIFT = 0, /* 18 BITS */

0 commit comments

Comments
 (0)