Skip to content

Commit 910328d

Browse files
LorenzoBianconiKernel Patches Daemon
authored andcommitted
net: ice: Add xmo_rx_checksum callback
Implement xmo_rx_checksum callback in ice driver to report RX checksum result to the eBPF program bounded to the NIC. Introduce ice_get_rx_csum utility routine in order to rx cksum codebase available in ice_rx_csum(). Signed-off-by: Lorenzo Bianconi <[email protected]>
1 parent b756be9 commit 910328d

File tree

3 files changed

+83
-44
lines changed

3 files changed

+83
-44
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ static int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)
591591
}
592592
}
593593

594+
ring->pkt_ctx.rxq_flags = ring->flags;
594595
xdp_init_buff(&ring->xdp, ice_get_frame_sz(ring), &ring->xdp_rxq);
595596
ring->xdp.data = NULL;
596597
ring->xdp_ext.pkt_ctx = &ring->pkt_ctx;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ enum ice_rx_dtype {
260260
struct ice_pkt_ctx {
261261
u64 cached_phctime;
262262
__be16 vlan_proto;
263+
u8 rxq_flags;
263264
};
264265

265266
struct ice_xdp_buff {

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

Lines changed: 81 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -80,69 +80,46 @@ ice_rx_hash_to_skb(const struct ice_rx_ring *rx_ring,
8080
libeth_rx_pt_set_hash(skb, hash, decoded);
8181
}
8282

83-
/**
84-
* ice_rx_gcs - Set generic checksum in skb
85-
* @skb: skb currently being received and modified
86-
* @rx_desc: receive descriptor
87-
*/
88-
static void ice_rx_gcs(struct sk_buff *skb,
89-
const union ice_32b_rx_flex_desc *rx_desc)
90-
{
91-
const struct ice_32b_rx_flex_desc_nic *desc;
92-
u16 csum;
93-
94-
desc = (struct ice_32b_rx_flex_desc_nic *)rx_desc;
95-
skb->ip_summed = CHECKSUM_COMPLETE;
96-
csum = (__force u16)desc->raw_csum;
97-
skb->csum = csum_unfold((__force __sum16)swab16(csum));
98-
}
99-
100-
/**
101-
* ice_rx_csum - Indicate in skb if checksum is good
102-
* @ring: the ring we care about
103-
* @skb: skb currently being received and modified
104-
* @rx_desc: the receive descriptor
105-
* @ptype: the packet type decoded by hardware
106-
*
107-
* skb->protocol must be set before this function is called
108-
*/
10983
static void
110-
ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
111-
union ice_32b_rx_flex_desc *rx_desc, u16 ptype)
84+
ice_get_rx_csum(const union ice_32b_rx_flex_desc *rx_desc, u16 ptype,
85+
struct net_device *dev, struct ice_pf *pf, u8 rxq_flag,
86+
enum xdp_checksum *ip_summed, u32 *cksum_meta)
11287
{
113-
struct libeth_rx_pt decoded;
88+
struct libeth_rx_pt decoded = libie_rx_pt_parse(ptype);
11489
u16 rx_status0, rx_status1;
11590
bool ipv4, ipv6;
11691

117-
/* Start with CHECKSUM_NONE and by default csum_level = 0 */
118-
skb->ip_summed = CHECKSUM_NONE;
119-
120-
decoded = libie_rx_pt_parse(ptype);
121-
if (!libeth_rx_pt_has_checksum(ring->netdev, decoded))
122-
return;
92+
if (!libeth_rx_pt_has_checksum(dev, decoded))
93+
goto checksum_none;
12394

12495
rx_status0 = le16_to_cpu(rx_desc->wb.status_error0);
12596
rx_status1 = le16_to_cpu(rx_desc->wb.status_error1);
126-
127-
if ((ring->flags & ICE_RX_FLAGS_RING_GCS) &&
97+
if ((rxq_flag & ICE_RX_FLAGS_RING_GCS) &&
12898
rx_desc->wb.rxdid == ICE_RXDID_FLEX_NIC &&
12999
(decoded.inner_prot == LIBETH_RX_PT_INNER_TCP ||
130100
decoded.inner_prot == LIBETH_RX_PT_INNER_UDP ||
131101
decoded.inner_prot == LIBETH_RX_PT_INNER_ICMP)) {
132-
ice_rx_gcs(skb, rx_desc);
102+
const struct ice_32b_rx_flex_desc_nic *desc;
103+
u16 csum;
104+
105+
desc = (struct ice_32b_rx_flex_desc_nic *)rx_desc;
106+
*ip_summed = XDP_CHECKSUM_COMPLETE;
107+
csum = (__force u16)desc->raw_csum;
108+
*cksum_meta = csum_unfold((__force __sum16)swab16(csum));
133109
return;
134110
}
135111

136112
/* check if HW has decoded the packet and checksum */
137113
if (!(rx_status0 & BIT(ICE_RX_FLEX_DESC_STATUS0_L3L4P_S)))
138-
return;
114+
goto checksum_none;
139115

140116
ipv4 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV4;
141117
ipv6 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV6;
142118

143119
if (ipv4 && (rx_status0 & (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S)))) {
144-
ring->vsi->back->hw_rx_eipe_error++;
145-
return;
120+
if (pf)
121+
pf->hw_rx_eipe_error++;
122+
goto checksum_none;
146123
}
147124

148125
if (ipv4 && (rx_status0 & (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_IPE_S))))
@@ -167,13 +144,48 @@ ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
167144
* we are indicating we validated the inner checksum.
168145
*/
169146
if (decoded.tunnel_type >= LIBETH_RX_PT_TUNNEL_IP_GRENAT)
170-
skb->csum_level = 1;
147+
*cksum_meta = 1;
171148

172-
skb->ip_summed = CHECKSUM_UNNECESSARY;
149+
*ip_summed = XDP_CHECKSUM_UNNECESSARY;
173150
return;
174151

175152
checksum_fail:
176-
ring->vsi->back->hw_csum_rx_error++;
153+
if (pf)
154+
pf->hw_csum_rx_error++;
155+
checksum_none:
156+
*ip_summed = XDP_CHECKSUM_NONE;
157+
*cksum_meta = 0;
158+
}
159+
160+
/**
161+
* ice_rx_csum - Indicate in skb if checksum is good
162+
* @ring: the ring we care about
163+
* @skb: skb currently being received and modified
164+
* @rx_desc: the receive descriptor
165+
* @ptype: the packet type decoded by hardware
166+
*
167+
* skb->protocol must be set before this function is called
168+
*/
169+
static void
170+
ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
171+
union ice_32b_rx_flex_desc *rx_desc, u16 ptype)
172+
{
173+
enum xdp_checksum ip_summed;
174+
u32 cksum_meta;
175+
176+
ice_get_rx_csum(rx_desc, ptype, ring->netdev, ring->vsi->back,
177+
ring->flags, &ip_summed, &cksum_meta);
178+
switch (ip_summed) {
179+
case XDP_CHECKSUM_UNNECESSARY:
180+
skb->csum_level = cksum_meta;
181+
break;
182+
case XDP_CHECKSUM_COMPLETE:
183+
skb->csum = cksum_meta;
184+
break;
185+
default:
186+
break;
187+
}
188+
skb->ip_summed = ip_summed;
177189
}
178190

179191
/**
@@ -555,6 +567,30 @@ static int ice_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
555567
return 0;
556568
}
557569

570+
/**
571+
* ice_xdp_rx_checksum - RX checksum XDP hint handler
572+
* @ctx: XDP buff pointer
573+
* @ip_summed: RX checksum result destination address
574+
* @cksum_meta: XDP RX checksum metadata destination address
575+
*
576+
* Copy RX checksum result (if available) and its metadata to the
577+
* destination address.
578+
*/
579+
static int ice_xdp_rx_checksum(const struct xdp_md *ctx,
580+
enum xdp_checksum *ip_summed,
581+
u32 *cksum_meta)
582+
{
583+
const struct ice_xdp_buff *xdp_ext = (void *)ctx;
584+
const union ice_32b_rx_flex_desc *rx_desc = xdp_ext->eop_desc;
585+
586+
ice_get_rx_csum(rx_desc, ice_get_ptype(rx_desc),
587+
xdp_ext->xdp_buff.rxq->dev, NULL,
588+
xdp_ext->pkt_ctx->rxq_flags,
589+
ip_summed, cksum_meta);
590+
591+
return 0;
592+
}
593+
558594
/**
559595
* ice_xdp_rx_vlan_tag - VLAN tag XDP hint handler
560596
* @ctx: XDP buff pointer
@@ -584,4 +620,5 @@ const struct xdp_metadata_ops ice_xdp_md_ops = {
584620
.xmo_rx_timestamp = ice_xdp_rx_hw_ts,
585621
.xmo_rx_hash = ice_xdp_rx_hash,
586622
.xmo_rx_vlan_tag = ice_xdp_rx_vlan_tag,
623+
.xmo_rx_checksum = ice_xdp_rx_checksum,
587624
};

0 commit comments

Comments
 (0)