Skip to content

Commit 0d54d8f

Browse files
bcreeley13anguy11
authored andcommitted
ice: Add hot path support for 802.1Q and 802.1ad VLAN offloads
Currently the driver only supports 802.1Q VLAN insertion and stripping. However, once Double VLAN Mode (DVM) is fully supported, then both 802.1Q and 802.1ad VLAN insertion and stripping will be supported. Unfortunately the VSI context parameters only allow for one VLAN ethertype at a time for VLAN offloads so only one or the other VLAN ethertype offload can be supported at once. To support this, multiple changes are needed. Rx path changes: [1] In DVM, the Rx queue context l2tagsel field needs to be cleared so the outermost tag shows up in the l2tag2_2nd field of the Rx flex descriptor. In Single VLAN Mode (SVM), the l2tagsel field should remain 1 to support SVM configurations. [2] Modify the ice_test_staterr() function to take a __le16 instead of the ice_32b_rx_flex_desc union pointer so this function can be used for both rx_desc->wb.status_error0 and rx_desc->wb.status_error1. [3] Add the new inline function ice_get_vlan_tag_from_rx_desc() that checks if there is a VLAN tag in l2tag1 or l2tag2_2nd. [4] In ice_receive_skb(), add a check to see if NETIF_F_HW_VLAN_STAG_RX is enabled in netdev->features. If it is, then this is the VLAN ethertype that needs to be added to the stripping VLAN tag. Since ice_fix_features() prevents CTAG_RX and STAG_RX from being enabled simultaneously, the VLAN ethertype will only ever be 802.1Q or 802.1ad. Tx path changes: [1] In DVM, the VLAN tag needs to be placed in the l2tag2 field of the Tx context descriptor. The new define ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN was added to the list of tx_flags to handle this case. [2] When the stack requests the VLAN tag to be offloaded on Tx, the driver needs to set either ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN or ICE_TX_FLAGS_HW_VLAN, so the tag is inserted in l2tag2 or l2tag1 respectively. To determine which location to use, set a bit in the Tx ring flags field during ring allocation that can be used to determine which field to use in the Tx descriptor. In DVM, always use l2tag2, and in SVM, always use l2tag1. Signed-off-by: Brett Creeley <[email protected]> Tested-by: Gurucharan G <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent c31af68 commit 0d54d8f

File tree

9 files changed

+87
-22
lines changed

9 files changed

+87
-22
lines changed

drivers/net/ethernet/intel/ice/ice_base.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,22 @@ static int ice_setup_rx_ctx(struct ice_rx_ring *ring)
418418
*/
419419
rlan_ctx.crcstrip = 1;
420420

421-
/* L2TSEL flag defines the reported L2 Tags in the receive descriptor */
422-
rlan_ctx.l2tsel = 1;
421+
/* L2TSEL flag defines the reported L2 Tags in the receive descriptor
422+
* and it needs to remain 1 for non-DVM capable configurations to not
423+
* break backward compatibility for VF drivers. Setting this field to 0
424+
* will cause the single/outer VLAN tag to be stripped to the L2TAG2_2ND
425+
* field in the Rx descriptor. Setting it to 1 allows the VLAN tag to
426+
* be stripped in L2TAG1 of the Rx descriptor, which is where VFs will
427+
* check for the tag
428+
*/
429+
if (ice_is_dvm_ena(hw))
430+
if (vsi->type == ICE_VSI_VF &&
431+
ice_vf_is_port_vlan_ena(&vsi->back->vf[vsi->vf_id]))
432+
rlan_ctx.l2tsel = 1;
433+
else
434+
rlan_ctx.l2tsel = 0;
435+
else
436+
rlan_ctx.l2tsel = 1;
423437

424438
rlan_ctx.dtype = ICE_RX_DTYPE_NO_SPLIT;
425439
rlan_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_NO_SPLIT;

drivers/net/ethernet/intel/ice/ice_dcb_lib.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,8 @@ ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring *tx_ring,
916916
return;
917917

918918
/* Insert 802.1p priority into VLAN header */
919-
if ((first->tx_flags & ICE_TX_FLAGS_HW_VLAN) ||
919+
if ((first->tx_flags & ICE_TX_FLAGS_HW_VLAN ||
920+
first->tx_flags & ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN) ||
920921
skb->priority != TC_PRIO_CONTROL) {
921922
first->tx_flags &= ~ICE_TX_FLAGS_VLAN_PR_M;
922923
/* Mask the lower 3 bits to set the 802.1p priority */
@@ -925,7 +926,10 @@ ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring *tx_ring,
925926
/* if this is not already set it means a VLAN 0 + priority needs
926927
* to be offloaded
927928
*/
928-
first->tx_flags |= ICE_TX_FLAGS_HW_VLAN;
929+
if (tx_ring->flags & ICE_TX_FLAGS_RING_VLAN_L2TAG2)
930+
first->tx_flags |= ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN;
931+
else
932+
first->tx_flags |= ICE_TX_FLAGS_HW_VLAN;
929933
}
930934
}
931935

drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ enum ice_rx_flex_desc_status_error_0_bits {
424424
enum ice_rx_flex_desc_status_error_1_bits {
425425
/* Note: These are predefined bit offsets */
426426
ICE_RX_FLEX_DESC_STATUS1_NAT_S = 4,
427+
/* [10:5] reserved */
428+
ICE_RX_FLEX_DESC_STATUS1_L2TAG2P_S = 11,
427429
ICE_RX_FLEX_DESC_STATUS1_LAST /* this entry must be last!!! */
428430
};
429431

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,7 @@ static void ice_vsi_clear_rings(struct ice_vsi *vsi)
14131413
*/
14141414
static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
14151415
{
1416+
bool dvm_ena = ice_is_dvm_ena(&vsi->back->hw);
14161417
struct ice_pf *pf = vsi->back;
14171418
struct device *dev;
14181419
u16 i;
@@ -1434,6 +1435,10 @@ static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
14341435
ring->tx_tstamps = &pf->ptp.port.tx;
14351436
ring->dev = dev;
14361437
ring->count = vsi->num_tx_desc;
1438+
if (dvm_ena)
1439+
ring->flags |= ICE_TX_FLAGS_RING_VLAN_L2TAG2;
1440+
else
1441+
ring->flags |= ICE_TX_FLAGS_RING_VLAN_L2TAG1;
14371442
WRITE_ONCE(vsi->tx_rings[i], ring);
14381443
}
14391444

drivers/net/ethernet/intel/ice/ice_txrx.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ ice_is_non_eop(struct ice_rx_ring *rx_ring, union ice_32b_rx_flex_desc *rx_desc)
10871087
{
10881088
/* if we are the last buffer then there is nothing else to do */
10891089
#define ICE_RXD_EOF BIT(ICE_RX_FLEX_DESC_STATUS0_EOF_S)
1090-
if (likely(ice_test_staterr(rx_desc, ICE_RXD_EOF)))
1090+
if (likely(ice_test_staterr(rx_desc->wb.status_error0, ICE_RXD_EOF)))
10911091
return false;
10921092

10931093
rx_ring->rx_stats.non_eop_descs++;
@@ -1149,7 +1149,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
11491149
* hardware wrote DD then it will be non-zero
11501150
*/
11511151
stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_DD_S);
1152-
if (!ice_test_staterr(rx_desc, stat_err_bits))
1152+
if (!ice_test_staterr(rx_desc->wb.status_error0, stat_err_bits))
11531153
break;
11541154

11551155
/* This memory barrier is needed to keep us from reading
@@ -1235,14 +1235,13 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
12351235
continue;
12361236

12371237
stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_RXE_S);
1238-
if (unlikely(ice_test_staterr(rx_desc, stat_err_bits))) {
1238+
if (unlikely(ice_test_staterr(rx_desc->wb.status_error0,
1239+
stat_err_bits))) {
12391240
dev_kfree_skb_any(skb);
12401241
continue;
12411242
}
12421243

1243-
stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S);
1244-
if (ice_test_staterr(rx_desc, stat_err_bits))
1245-
vlan_tag = le16_to_cpu(rx_desc->wb.l2tag1);
1244+
vlan_tag = ice_get_vlan_tag_from_rx_desc(rx_desc);
12461245

12471246
/* pad the skb if needed, to make a valid ethernet frame */
12481247
if (eth_skb_pad(skb)) {
@@ -1924,12 +1923,16 @@ ice_tx_prepare_vlan_flags(struct ice_tx_ring *tx_ring, struct ice_tx_buf *first)
19241923
if (!skb_vlan_tag_present(skb) && eth_type_vlan(skb->protocol))
19251924
return;
19261925

1927-
/* currently, we always assume 802.1Q for VLAN insertion as VLAN
1928-
* insertion for 802.1AD is not supported
1926+
/* the VLAN ethertype/tpid is determined by VSI configuration and netdev
1927+
* feature flags, which the driver only allows either 802.1Q or 802.1ad
1928+
* VLAN offloads exclusively so we only care about the VLAN ID here
19291929
*/
19301930
if (skb_vlan_tag_present(skb)) {
19311931
first->tx_flags |= skb_vlan_tag_get(skb) << ICE_TX_FLAGS_VLAN_S;
1932-
first->tx_flags |= ICE_TX_FLAGS_HW_VLAN;
1932+
if (tx_ring->flags & ICE_TX_FLAGS_RING_VLAN_L2TAG2)
1933+
first->tx_flags |= ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN;
1934+
else
1935+
first->tx_flags |= ICE_TX_FLAGS_HW_VLAN;
19331936
}
19341937

19351938
ice_tx_prepare_vlan_flags_dcb(tx_ring, first);
@@ -2302,6 +2305,13 @@ ice_xmit_frame_ring(struct sk_buff *skb, struct ice_tx_ring *tx_ring)
23022305

23032306
/* prepare the VLAN tagging flags for Tx */
23042307
ice_tx_prepare_vlan_flags(tx_ring, first);
2308+
if (first->tx_flags & ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN) {
2309+
offload.cd_qw1 |= (u64)(ICE_TX_DESC_DTYPE_CTX |
2310+
(ICE_TX_CTX_DESC_IL2TAG2 <<
2311+
ICE_TXD_CTX_QW1_CMD_S));
2312+
offload.cd_l2tag2 = (first->tx_flags & ICE_TX_FLAGS_VLAN_M) >>
2313+
ICE_TX_FLAGS_VLAN_S;
2314+
}
23052315

23062316
/* set up TSO offload */
23072317
tso = ice_tso(first, &offload);

drivers/net/ethernet/intel/ice/ice_txrx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static inline int ice_skb_pad(void)
122122
#define ICE_TX_FLAGS_IPV4 BIT(5)
123123
#define ICE_TX_FLAGS_IPV6 BIT(6)
124124
#define ICE_TX_FLAGS_TUNNEL BIT(7)
125+
#define ICE_TX_FLAGS_HW_OUTER_SINGLE_VLAN BIT(8)
125126
#define ICE_TX_FLAGS_VLAN_M 0xffff0000
126127
#define ICE_TX_FLAGS_VLAN_PR_M 0xe0000000
127128
#define ICE_TX_FLAGS_VLAN_PR_S 29
@@ -333,6 +334,8 @@ struct ice_tx_ring {
333334
spinlock_t tx_lock;
334335
u32 txq_teid; /* Added Tx queue TEID */
335336
#define ICE_TX_FLAGS_RING_XDP BIT(0)
337+
#define ICE_TX_FLAGS_RING_VLAN_L2TAG1 BIT(1)
338+
#define ICE_TX_FLAGS_RING_VLAN_L2TAG2 BIT(2)
336339
u8 flags;
337340
u8 dcb_tc; /* Traffic class of ring */
338341
u8 ptp_tx;

drivers/net/ethernet/intel/ice/ice_txrx_lib.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,14 @@ ice_process_skb_fields(struct ice_rx_ring *rx_ring,
209209
void
210210
ice_receive_skb(struct ice_rx_ring *rx_ring, struct sk_buff *skb, u16 vlan_tag)
211211
{
212-
if ((rx_ring->netdev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
213-
(vlan_tag & VLAN_VID_MASK))
212+
netdev_features_t features = rx_ring->netdev->features;
213+
bool non_zero_vlan = !!(vlan_tag & VLAN_VID_MASK);
214+
215+
if ((features & NETIF_F_HW_VLAN_CTAG_RX) && non_zero_vlan)
214216
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
217+
else if ((features & NETIF_F_HW_VLAN_STAG_RX) && non_zero_vlan)
218+
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021AD), vlan_tag);
219+
215220
napi_gro_receive(&rx_ring->q_vector->napi, skb);
216221
}
217222

drivers/net/ethernet/intel/ice/ice_txrx_lib.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* ice_test_staterr - tests bits in Rx descriptor status and error fields
10-
* @rx_desc: pointer to receive descriptor (in le64 format)
10+
* @status_err_n: Rx descriptor status_error0 or status_error1 bits
1111
* @stat_err_bits: value to mask
1212
*
1313
* This function does some fast chicanery in order to return the
@@ -16,9 +16,9 @@
1616
* at offset zero.
1717
*/
1818
static inline bool
19-
ice_test_staterr(union ice_32b_rx_flex_desc *rx_desc, const u16 stat_err_bits)
19+
ice_test_staterr(__le16 status_err_n, const u16 stat_err_bits)
2020
{
21-
return !!(rx_desc->wb.status_error0 & cpu_to_le16(stat_err_bits));
21+
return !!(status_err_n & cpu_to_le16(stat_err_bits));
2222
}
2323

2424
static inline __le64
@@ -31,6 +31,30 @@ ice_build_ctob(u64 td_cmd, u64 td_offset, unsigned int size, u64 td_tag)
3131
(td_tag << ICE_TXD_QW1_L2TAG1_S));
3232
}
3333

34+
/**
35+
* ice_get_vlan_tag_from_rx_desc - get VLAN from Rx flex descriptor
36+
* @rx_desc: Rx 32b flex descriptor with RXDID=2
37+
*
38+
* The OS and current PF implementation only support stripping a single VLAN tag
39+
* at a time, so there should only ever be 0 or 1 tags in the l2tag* fields. If
40+
* one is found return the tag, else return 0 to mean no VLAN tag was found.
41+
*/
42+
static inline u16
43+
ice_get_vlan_tag_from_rx_desc(union ice_32b_rx_flex_desc *rx_desc)
44+
{
45+
u16 stat_err_bits;
46+
47+
stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S);
48+
if (ice_test_staterr(rx_desc->wb.status_error0, stat_err_bits))
49+
return le16_to_cpu(rx_desc->wb.l2tag1);
50+
51+
stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS1_L2TAG2P_S);
52+
if (ice_test_staterr(rx_desc->wb.status_error1, stat_err_bits))
53+
return le16_to_cpu(rx_desc->wb.l2tag2_2nd);
54+
55+
return 0;
56+
}
57+
3458
/**
3559
* ice_xdp_ring_update_tail - Updates the XDP Tx ring tail register
3660
* @xdp_ring: XDP Tx ring

drivers/net/ethernet/intel/ice/ice_xsk.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, int budget)
532532
rx_desc = ICE_RX_DESC(rx_ring, rx_ring->next_to_clean);
533533

534534
stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_DD_S);
535-
if (!ice_test_staterr(rx_desc, stat_err_bits))
535+
if (!ice_test_staterr(rx_desc->wb.status_error0, stat_err_bits))
536536
break;
537537

538538
/* This memory barrier is needed to keep us from reading
@@ -587,9 +587,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, int budget)
587587
total_rx_bytes += skb->len;
588588
total_rx_packets++;
589589

590-
stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S);
591-
if (ice_test_staterr(rx_desc, stat_err_bits))
592-
vlan_tag = le16_to_cpu(rx_desc->wb.l2tag1);
590+
vlan_tag = ice_get_vlan_tag_from_rx_desc(rx_desc);
593591

594592
rx_ptype = le16_to_cpu(rx_desc->wb.ptype_flex_flags0) &
595593
ICE_RX_FLEX_DESC_PTYPE_M;

0 commit comments

Comments
 (0)