Skip to content

Commit 1ddc028

Browse files
Huazhong Tandavem330
authored andcommitted
net: hns3: refactor out RX completion checksum
Only when RXD advanced layout is enabled, in some cases (e.g. ip fragments), the checksum of entire packet will be calculated and filled in the least significant 16 bits of the unused addr field. So refactor out the handling of RX completion checksum: adjust the location of the checksum in RX descriptor, and use ptype table to identify whether this kind of checksum is calculated. Signed-off-by: Huazhong Tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7966407 commit 1ddc028

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,6 @@ static int hns3_dbg_bd_info(struct hnae3_handle *h, const char *cmd_buf)
260260
dev_info(dev, "(RX)addr: %pad\n", &addr);
261261
dev_info(dev, "(RX)l234_info: %u\n", l234info);
262262

263-
if (l234info & BIT(HNS3_RXD_L2_CSUM_B)) {
264-
u32 lo, hi;
265-
266-
lo = hnae3_get_field(l234info, HNS3_RXD_L2_CSUM_L_M,
267-
HNS3_RXD_L2_CSUM_L_S);
268-
hi = hnae3_get_field(l234info, HNS3_RXD_L2_CSUM_H_M,
269-
HNS3_RXD_L2_CSUM_H_S);
270-
dev_info(dev, "(RX)csum: %u\n", lo | hi << 8);
271-
}
272-
273263
dev_info(dev, "(RX)pkt_len: %u\n", le16_to_cpu(rx_desc->rx.pkt_len));
274264
dev_info(dev, "(RX)size: %u\n", le16_to_cpu(rx_desc->rx.size));
275265
dev_info(dev, "(RX)rss_hash: %u\n", le32_to_cpu(rx_desc->rx.rss_hash));

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,20 +3252,20 @@ static int hns3_gro_complete(struct sk_buff *skb, u32 l234info)
32523252
return 0;
32533253
}
32543254

3255-
static void hns3_checksum_complete(struct hns3_enet_ring *ring,
3256-
struct sk_buff *skb, u32 l234info)
3255+
static bool hns3_checksum_complete(struct hns3_enet_ring *ring,
3256+
struct sk_buff *skb, u32 ptype, u16 csum)
32573257
{
3258-
u32 lo, hi;
3258+
if (ptype == HNS3_INVALID_PTYPE ||
3259+
hns3_rx_ptype_tbl[ptype].ip_summed != CHECKSUM_COMPLETE)
3260+
return false;
32593261

32603262
u64_stats_update_begin(&ring->syncp);
32613263
ring->stats.csum_complete++;
32623264
u64_stats_update_end(&ring->syncp);
32633265
skb->ip_summed = CHECKSUM_COMPLETE;
3264-
lo = hnae3_get_field(l234info, HNS3_RXD_L2_CSUM_L_M,
3265-
HNS3_RXD_L2_CSUM_L_S);
3266-
hi = hnae3_get_field(l234info, HNS3_RXD_L2_CSUM_H_M,
3267-
HNS3_RXD_L2_CSUM_H_S);
3268-
skb->csum = csum_unfold((__force __sum16)(lo | hi << 8));
3266+
skb->csum = csum_unfold((__force __sum16)csum);
3267+
3268+
return true;
32693269
}
32703270

32713271
static void hns3_rx_handle_csum(struct sk_buff *skb, u32 l234info,
@@ -3307,7 +3307,8 @@ static void hns3_rx_handle_csum(struct sk_buff *skb, u32 l234info,
33073307
}
33083308

33093309
static void hns3_rx_checksum(struct hns3_enet_ring *ring, struct sk_buff *skb,
3310-
u32 l234info, u32 bd_base_info, u32 ol_info)
3310+
u32 l234info, u32 bd_base_info, u32 ol_info,
3311+
u16 csum)
33113312
{
33123313
struct net_device *netdev = ring_to_netdev(ring);
33133314
struct hns3_nic_priv *priv = netdev_priv(netdev);
@@ -3324,10 +3325,8 @@ static void hns3_rx_checksum(struct hns3_enet_ring *ring, struct sk_buff *skb,
33243325
ptype = hnae3_get_field(ol_info, HNS3_RXD_PTYPE_M,
33253326
HNS3_RXD_PTYPE_S);
33263327

3327-
if (l234info & BIT(HNS3_RXD_L2_CSUM_B)) {
3328-
hns3_checksum_complete(ring, skb, l234info);
3328+
if (hns3_checksum_complete(ring, skb, ptype, csum))
33293329
return;
3330-
}
33313330

33323331
/* check if hardware has done checksum */
33333332
if (!(bd_base_info & BIT(HNS3_RXD_L3L4P_B)))
@@ -3527,7 +3526,7 @@ static int hns3_add_frag(struct hns3_enet_ring *ring)
35273526

35283527
static int hns3_set_gro_and_checksum(struct hns3_enet_ring *ring,
35293528
struct sk_buff *skb, u32 l234info,
3530-
u32 bd_base_info, u32 ol_info)
3529+
u32 bd_base_info, u32 ol_info, u16 csum)
35313530
{
35323531
struct net_device *netdev = ring_to_netdev(ring);
35333532
struct hns3_nic_priv *priv = netdev_priv(netdev);
@@ -3538,7 +3537,8 @@ static int hns3_set_gro_and_checksum(struct hns3_enet_ring *ring,
35383537
HNS3_RXD_GRO_SIZE_S);
35393538
/* if there is no HW GRO, do not set gro params */
35403539
if (!skb_shinfo(skb)->gso_size) {
3541-
hns3_rx_checksum(ring, skb, l234info, bd_base_info, ol_info);
3540+
hns3_rx_checksum(ring, skb, l234info, bd_base_info, ol_info,
3541+
csum);
35423542
return 0;
35433543
}
35443544

@@ -3588,6 +3588,7 @@ static int hns3_handle_bdinfo(struct hns3_enet_ring *ring, struct sk_buff *skb)
35883588
struct hns3_desc *desc;
35893589
unsigned int len;
35903590
int pre_ntc, ret;
3591+
u16 csum;
35913592

35923593
/* bdinfo handled below is only valid on the last BD of the
35933594
* current packet, and ring->next_to_clean indicates the first
@@ -3599,6 +3600,7 @@ static int hns3_handle_bdinfo(struct hns3_enet_ring *ring, struct sk_buff *skb)
35993600
bd_base_info = le32_to_cpu(desc->rx.bd_base_info);
36003601
l234info = le32_to_cpu(desc->rx.l234_info);
36013602
ol_info = le32_to_cpu(desc->rx.ol_info);
3603+
csum = le16_to_cpu(desc->csum);
36023604

36033605
/* Based on hw strategy, the tag offloaded will be stored at
36043606
* ot_vlan_tag in two layer tag case, and stored at vlan_tag
@@ -3631,7 +3633,7 @@ static int hns3_handle_bdinfo(struct hns3_enet_ring *ring, struct sk_buff *skb)
36313633

36323634
/* This is needed in order to enable forwarding support */
36333635
ret = hns3_set_gro_and_checksum(ring, skb, l234info,
3634-
bd_base_info, ol_info);
3636+
bd_base_info, ol_info, csum);
36353637
if (unlikely(ret)) {
36363638
u64_stats_update_begin(&ring->syncp);
36373639
ring->stats.rx_err_cnt++;

drivers/net/ethernet/hisilicon/hns3/hns3_enet.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ enum hns3_nic_state {
8383
#define HNS3_RXD_STRP_TAGP_S 13
8484
#define HNS3_RXD_STRP_TAGP_M (0x3 << HNS3_RXD_STRP_TAGP_S)
8585

86-
#define HNS3_RXD_L2_CSUM_B 15
87-
#define HNS3_RXD_L2_CSUM_L_S 4
88-
#define HNS3_RXD_L2_CSUM_L_M (0xff << HNS3_RXD_L2_CSUM_L_S)
89-
#define HNS3_RXD_L2_CSUM_H_S 24
90-
#define HNS3_RXD_L2_CSUM_H_M (0xff << HNS3_RXD_L2_CSUM_H_S)
91-
9286
#define HNS3_RXD_L2E_B 16
9387
#define HNS3_RXD_L3E_B 17
9488
#define HNS3_RXD_L4E_B 18
@@ -242,7 +236,10 @@ enum hns3_pkt_tun_type {
242236

243237
/* hardware spec ring buffer format */
244238
struct __packed hns3_desc {
245-
__le64 addr;
239+
union {
240+
__le64 addr;
241+
__le16 csum;
242+
};
246243
union {
247244
struct {
248245
__le16 vlan_tag;
@@ -409,6 +406,7 @@ struct ring_stats {
409406
u64 rx_multicast;
410407
u64 non_reuse_pg;
411408
};
409+
__le16 csum;
412410
};
413411
};
414412

0 commit comments

Comments
 (0)