Skip to content

Commit 6b07b52

Browse files
author
Paolo Abeni
committed
Merge branch 'there-are-some-bugfix-for-the-hns-ethernet-driver'
Jijie Shao says: ==================== There are some bugfix for the HNS ethernet driver There are some bugfix for the HNS ethernet driver --- changeLog: v2 -> v3: - Refine the commit msg as Wojciech suggestions - Reconstruct the "hns_mac_link_anti_shake" function suggested by Wojciech v2: https://lore.kernel.org/all/[email protected]/ v1 -> v2: - Fixed the internal function is not decorated with static issue, suggested by Jakub v1: https://lore.kernel.org/all/[email protected]/ --- ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents cbe860b + f708aba commit 6b07b52

File tree

3 files changed

+62
-23
lines changed

3 files changed

+62
-23
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb)
6666
}
6767
}
6868

69+
static u32 hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv)
70+
{
71+
#define HNS_MAC_LINK_WAIT_TIME 5
72+
#define HNS_MAC_LINK_WAIT_CNT 40
73+
74+
u32 link_status = 0;
75+
int i;
76+
77+
if (!mac_ctrl_drv->get_link_status)
78+
return link_status;
79+
80+
for (i = 0; i < HNS_MAC_LINK_WAIT_CNT; i++) {
81+
msleep(HNS_MAC_LINK_WAIT_TIME);
82+
mac_ctrl_drv->get_link_status(mac_ctrl_drv, &link_status);
83+
if (!link_status)
84+
break;
85+
}
86+
87+
return link_status;
88+
}
89+
6990
void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status)
7091
{
7192
struct mac_driver *mac_ctrl_drv;
@@ -83,6 +104,14 @@ void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status)
83104
&sfp_prsnt);
84105
if (!ret)
85106
*link_status = *link_status && sfp_prsnt;
107+
108+
/* for FIBER port, it may have a fake link up.
109+
* when the link status changes from down to up, we need to do
110+
* anti-shake. the anti-shake time is base on tests.
111+
* only FIBER port need to do this.
112+
*/
113+
if (*link_status && !mac_cb->link)
114+
*link_status = hns_mac_link_anti_shake(mac_ctrl_drv);
86115
}
87116

88117
mac_cb->link = *link_status;

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)