Skip to content

Commit 84757d0

Browse files
liuyonglong86Paolo Abeni
authored andcommitted
net: hns: fix wrong head when modify the tx feature when sending packets
Upon changing the tx feature, the hns driver will modify the maybe_stop_tx() and fill_desc() functions, if the modify happens during packet sending, will cause the hardware and software pointers do not match, and the port can not work anymore. This patch deletes the maybe_stop_tx() and fill_desc() functions modification when setting tx feature, and use the skb_is_gro() to determine which functions to use in the tx path. Fixes: 38f616d ("net:hns: Add support of ethtool TSO set option for Hip06 in HNS") Signed-off-by: Yonglong Liu <liuyonglong@huawei.com> Signed-off-by: Jijie Shao <shaojijie@huawei.com> Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent cbe860b commit 84757d0

2 files changed

Lines changed: 33 additions & 23 deletions

File tree

drivers/net/ethernet/hisilicon/hns/hns_enet.c

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ MODULE_DEVICE_TABLE(acpi, hns_enet_acpi_match);
142142

143143
static void fill_desc(struct hnae_ring *ring, void *priv,
144144
int size, dma_addr_t dma, int frag_end,
145-
int buf_num, enum hns_desc_type type, int mtu)
145+
int buf_num, enum hns_desc_type type, int mtu,
146+
bool is_gso)
146147
{
147148
struct hnae_desc *desc = &ring->desc[ring->next_to_use];
148149
struct hnae_desc_cb *desc_cb = &ring->desc_cb[ring->next_to_use];
@@ -275,6 +276,15 @@ static int hns_nic_maybe_stop_tso(
275276
return 0;
276277
}
277278

279+
static int hns_nic_maybe_stop_tx_v2(struct sk_buff **out_skb, int *bnum,
280+
struct hnae_ring *ring)
281+
{
282+
if (skb_is_gso(*out_skb))
283+
return hns_nic_maybe_stop_tso(out_skb, bnum, ring);
284+
else
285+
return hns_nic_maybe_stop_tx(out_skb, bnum, ring);
286+
}
287+
278288
static void fill_tso_desc(struct hnae_ring *ring, void *priv,
279289
int size, dma_addr_t dma, int frag_end,
280290
int buf_num, enum hns_desc_type type, int mtu)
@@ -300,6 +310,19 @@ static void fill_tso_desc(struct hnae_ring *ring, void *priv,
300310
mtu);
301311
}
302312

313+
static void fill_desc_v2(struct hnae_ring *ring, void *priv,
314+
int size, dma_addr_t dma, int frag_end,
315+
int buf_num, enum hns_desc_type type, int mtu,
316+
bool is_gso)
317+
{
318+
if (is_gso)
319+
fill_tso_desc(ring, priv, size, dma, frag_end, buf_num, type,
320+
mtu);
321+
else
322+
fill_v2_desc(ring, priv, size, dma, frag_end, buf_num, type,
323+
mtu);
324+
}
325+
303326
netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev,
304327
struct sk_buff *skb,
305328
struct hns_nic_ring_data *ring_data)
@@ -313,6 +336,7 @@ netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev,
313336
int seg_num;
314337
dma_addr_t dma;
315338
int size, next_to_use;
339+
bool is_gso;
316340
int i;
317341

318342
switch (priv->ops.maybe_stop_tx(&skb, &buf_num, ring)) {
@@ -339,8 +363,9 @@ netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev,
339363
ring->stats.sw_err_cnt++;
340364
goto out_err_tx_ok;
341365
}
366+
is_gso = skb_is_gso(skb);
342367
priv->ops.fill_desc(ring, skb, size, dma, seg_num == 1 ? 1 : 0,
343-
buf_num, DESC_TYPE_SKB, ndev->mtu);
368+
buf_num, DESC_TYPE_SKB, ndev->mtu, is_gso);
344369

345370
/* fill the fragments */
346371
for (i = 1; i < seg_num; i++) {
@@ -354,7 +379,7 @@ netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev,
354379
}
355380
priv->ops.fill_desc(ring, skb_frag_page(frag), size, dma,
356381
seg_num - 1 == i ? 1 : 0, buf_num,
357-
DESC_TYPE_PAGE, ndev->mtu);
382+
DESC_TYPE_PAGE, ndev->mtu, is_gso);
358383
}
359384

360385
/*complete translate all packets*/
@@ -1776,15 +1801,6 @@ static int hns_nic_set_features(struct net_device *netdev,
17761801
netdev_info(netdev, "enet v1 do not support tso!\n");
17771802
break;
17781803
default:
1779-
if (features & (NETIF_F_TSO | NETIF_F_TSO6)) {
1780-
priv->ops.fill_desc = fill_tso_desc;
1781-
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tso;
1782-
/* The chip only support 7*4096 */
1783-
netif_set_tso_max_size(netdev, 7 * 4096);
1784-
} else {
1785-
priv->ops.fill_desc = fill_v2_desc;
1786-
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx;
1787-
}
17881804
break;
17891805
}
17901806
netdev->features = features;
@@ -2159,16 +2175,9 @@ static void hns_nic_set_priv_ops(struct net_device *netdev)
21592175
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx;
21602176
} else {
21612177
priv->ops.get_rxd_bnum = get_v2rx_desc_bnum;
2162-
if ((netdev->features & NETIF_F_TSO) ||
2163-
(netdev->features & NETIF_F_TSO6)) {
2164-
priv->ops.fill_desc = fill_tso_desc;
2165-
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tso;
2166-
/* This chip only support 7*4096 */
2167-
netif_set_tso_max_size(netdev, 7 * 4096);
2168-
} else {
2169-
priv->ops.fill_desc = fill_v2_desc;
2170-
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx;
2171-
}
2178+
priv->ops.fill_desc = fill_desc_v2;
2179+
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx_v2;
2180+
netif_set_tso_max_size(netdev, 7 * 4096);
21722181
/* enable tso when init
21732182
* control tso on/off through TSE bit in bd
21742183
*/

drivers/net/ethernet/hisilicon/hns/hns_enet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ struct hns_nic_ring_data {
4444
struct hns_nic_ops {
4545
void (*fill_desc)(struct hnae_ring *ring, void *priv,
4646
int size, dma_addr_t dma, int frag_end,
47-
int buf_num, enum hns_desc_type type, int mtu);
47+
int buf_num, enum hns_desc_type type, int mtu,
48+
bool is_gso);
4849
int (*maybe_stop_tx)(struct sk_buff **out_skb,
4950
int *bnum, struct hnae_ring *ring);
5051
void (*get_rxd_bnum)(u32 bnum_flag, int *out_bnum);

0 commit comments

Comments
 (0)