Skip to content

Commit 833b65a

Browse files
Jijie ShaoPaolo Abeni
authored andcommitted
net: hibmcge: Add support for checksum offload
This patch implements the rx checksum offload feature. The tx checksum offload processing in .ndo_start_xmit() has been accepted. This patch also adds the tx checksum feature, including NETIF_F_IP_CSUM and NETIF_F_IPV6_CSUM Signed-off-by: Jijie Shao <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent c0bf9bf commit 833b65a

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include "hbg_txrx.h"
1515
#include "hbg_debugfs.h"
1616

17+
#define HBG_SUPPORT_FEATURES (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | \
18+
NETIF_F_RXCSUM)
19+
1720
static void hbg_all_irq_enable(struct hbg_priv *priv, bool enabled)
1821
{
1922
struct hbg_irq_info *info;
@@ -419,6 +422,9 @@ static int hbg_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
419422
if (ret)
420423
return ret;
421424

425+
/* set default features */
426+
netdev->features |= HBG_SUPPORT_FEATURES;
427+
netdev->hw_features |= HBG_SUPPORT_FEATURES;
422428
netdev->priv_flags |= IFF_UNICAST_FLT;
423429

424430
netdev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;

drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,14 @@ static int hbg_napi_tx_recycle(struct napi_struct *napi, int budget)
202202
}
203203

204204
static bool hbg_rx_check_l3l4_error(struct hbg_priv *priv,
205-
struct hbg_rx_desc *desc)
205+
struct hbg_rx_desc *desc,
206+
struct sk_buff *skb)
206207
{
208+
bool rx_checksum_offload = !!(priv->netdev->features & NETIF_F_RXCSUM);
209+
210+
skb->ip_summed = rx_checksum_offload ?
211+
CHECKSUM_UNNECESSARY : CHECKSUM_NONE;
212+
207213
if (likely(!FIELD_GET(HBG_RX_DESC_W4_L3_ERR_CODE_M, desc->word4) &&
208214
!FIELD_GET(HBG_RX_DESC_W4_L4_ERR_CODE_M, desc->word4)))
209215
return true;
@@ -215,8 +221,13 @@ static bool hbg_rx_check_l3l4_error(struct hbg_priv *priv,
215221
priv->stats.rx_desc_l3_wrong_head_cnt++;
216222
return false;
217223
case HBG_L3_CSUM_ERR:
224+
skb->ip_summed = CHECKSUM_NONE;
218225
priv->stats.rx_desc_l3_csum_err_cnt++;
219-
return false;
226+
227+
/* Don't drop packets on csum validation failure,
228+
* suggest by Jakub
229+
*/
230+
break;
220231
case HBG_L3_LEN_ERR:
221232
priv->stats.rx_desc_l3_len_err_cnt++;
222233
return false;
@@ -238,8 +249,13 @@ static bool hbg_rx_check_l3l4_error(struct hbg_priv *priv,
238249
priv->stats.rx_desc_l4_len_err_cnt++;
239250
return false;
240251
case HBG_L4_CSUM_ERR:
252+
skb->ip_summed = CHECKSUM_NONE;
241253
priv->stats.rx_desc_l4_csum_err_cnt++;
242-
return false;
254+
255+
/* Don't drop packets on csum validation failure,
256+
* suggest by Jakub
257+
*/
258+
break;
243259
case HBG_L4_ZERO_PORT_NUM:
244260
priv->stats.rx_desc_l4_zero_port_num_cnt++;
245261
return false;
@@ -322,7 +338,8 @@ static void hbg_update_rx_protocol_stats(struct hbg_priv *priv,
322338
hbg_update_rx_ip_protocol_stats(priv, desc);
323339
}
324340

325-
static bool hbg_rx_pkt_check(struct hbg_priv *priv, struct hbg_rx_desc *desc)
341+
static bool hbg_rx_pkt_check(struct hbg_priv *priv, struct hbg_rx_desc *desc,
342+
struct sk_buff *skb)
326343
{
327344
if (unlikely(FIELD_GET(HBG_RX_DESC_W2_PKT_LEN_M, desc->word2) >
328345
priv->dev_specs.max_frame_len)) {
@@ -342,7 +359,7 @@ static bool hbg_rx_pkt_check(struct hbg_priv *priv, struct hbg_rx_desc *desc)
342359
return false;
343360
}
344361

345-
if (unlikely(!hbg_rx_check_l3l4_error(priv, desc))) {
362+
if (unlikely(!hbg_rx_check_l3l4_error(priv, desc, skb))) {
346363
priv->stats.rx_desc_l3l4_err_cnt++;
347364
return false;
348365
}
@@ -413,7 +430,7 @@ static int hbg_napi_rx_poll(struct napi_struct *napi, int budget)
413430
rx_desc = (struct hbg_rx_desc *)buffer->skb->data;
414431
pkt_len = FIELD_GET(HBG_RX_DESC_W2_PKT_LEN_M, rx_desc->word2);
415432

416-
if (unlikely(!hbg_rx_pkt_check(priv, rx_desc))) {
433+
if (unlikely(!hbg_rx_pkt_check(priv, rx_desc, buffer->skb))) {
417434
hbg_buffer_free(buffer);
418435
goto next_buffer;
419436
}

0 commit comments

Comments
 (0)