* [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver
@ 2023-12-04 14:32 Jijie Shao
2023-12-04 14:32 ` [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets Jijie Shao
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Jijie Shao @ 2023-12-04 14:32 UTC (permalink / raw)
To: yisen.zhuang, salil.mehta, davem, edumazet, kuba, pabeni,
wojciech.drewek
Cc: shenjian15, wangjie125, liuyonglong, shaojijie, netdev,
linux-kernel
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/20231204011051.4055031-1-shaojijie@huawei.com/
v1 -> v2:
- Fixed the internal function is not decorated with static issue, suggested by Jakub
v1: https://lore.kernel.org/all/20231201102703.4134592-1-shaojijie@huawei.com/
---
Yonglong Liu (2):
net: hns: fix wrong head when modify the tx feature when sending
packets
net: hns: fix fake link up on xge port
.../net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 29 ++++++++++
drivers/net/ethernet/hisilicon/hns/hns_enet.c | 53 +++++++++++--------
drivers/net/ethernet/hisilicon/hns/hns_enet.h | 3 +-
3 files changed, 62 insertions(+), 23 deletions(-)
--
2.30.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets 2023-12-04 14:32 [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver Jijie Shao @ 2023-12-04 14:32 ` Jijie Shao 2023-12-06 11:18 ` Paolo Abeni 2023-12-04 14:32 ` [PATCH V3 net 2/2] net: hns: fix fake link up on xge port Jijie Shao 2023-12-06 11:30 ` [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver patchwork-bot+netdevbpf 2 siblings, 1 reply; 8+ messages in thread From: Jijie Shao @ 2023-12-04 14:32 UTC (permalink / raw) To: yisen.zhuang, salil.mehta, davem, edumazet, kuba, pabeni, wojciech.drewek Cc: shenjian15, wangjie125, liuyonglong, shaojijie, netdev, linux-kernel From: Yonglong Liu <liuyonglong@huawei.com> 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: 38f616da1c28 ("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> --- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 53 +++++++++++-------- drivers/net/ethernet/hisilicon/hns/hns_enet.h | 3 +- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c index 0900abf5c508..8a713eed4465 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c @@ -142,7 +142,8 @@ MODULE_DEVICE_TABLE(acpi, hns_enet_acpi_match); static void fill_desc(struct hnae_ring *ring, void *priv, int size, dma_addr_t dma, int frag_end, - int buf_num, enum hns_desc_type type, int mtu) + int buf_num, enum hns_desc_type type, int mtu, + bool is_gso) { struct hnae_desc *desc = &ring->desc[ring->next_to_use]; struct hnae_desc_cb *desc_cb = &ring->desc_cb[ring->next_to_use]; @@ -275,6 +276,15 @@ static int hns_nic_maybe_stop_tso( return 0; } +static int hns_nic_maybe_stop_tx_v2(struct sk_buff **out_skb, int *bnum, + struct hnae_ring *ring) +{ + if (skb_is_gso(*out_skb)) + return hns_nic_maybe_stop_tso(out_skb, bnum, ring); + else + return hns_nic_maybe_stop_tx(out_skb, bnum, ring); +} + static void fill_tso_desc(struct hnae_ring *ring, void *priv, int size, dma_addr_t dma, int frag_end, 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, mtu); } +static void fill_desc_v2(struct hnae_ring *ring, void *priv, + int size, dma_addr_t dma, int frag_end, + int buf_num, enum hns_desc_type type, int mtu, + bool is_gso) +{ + if (is_gso) + fill_tso_desc(ring, priv, size, dma, frag_end, buf_num, type, + mtu); + else + fill_v2_desc(ring, priv, size, dma, frag_end, buf_num, type, + mtu); +} + netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev, struct sk_buff *skb, struct hns_nic_ring_data *ring_data) @@ -313,6 +336,7 @@ netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev, int seg_num; dma_addr_t dma; int size, next_to_use; + bool is_gso; int i; 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, ring->stats.sw_err_cnt++; goto out_err_tx_ok; } + is_gso = skb_is_gso(skb); priv->ops.fill_desc(ring, skb, size, dma, seg_num == 1 ? 1 : 0, - buf_num, DESC_TYPE_SKB, ndev->mtu); + buf_num, DESC_TYPE_SKB, ndev->mtu, is_gso); /* fill the fragments */ for (i = 1; i < seg_num; i++) { @@ -354,7 +379,7 @@ netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev, } priv->ops.fill_desc(ring, skb_frag_page(frag), size, dma, seg_num - 1 == i ? 1 : 0, buf_num, - DESC_TYPE_PAGE, ndev->mtu); + DESC_TYPE_PAGE, ndev->mtu, is_gso); } /*complete translate all packets*/ @@ -1776,15 +1801,6 @@ static int hns_nic_set_features(struct net_device *netdev, netdev_info(netdev, "enet v1 do not support tso!\n"); break; default: - if (features & (NETIF_F_TSO | NETIF_F_TSO6)) { - priv->ops.fill_desc = fill_tso_desc; - priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tso; - /* The chip only support 7*4096 */ - netif_set_tso_max_size(netdev, 7 * 4096); - } else { - priv->ops.fill_desc = fill_v2_desc; - priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx; - } break; } netdev->features = features; @@ -2159,16 +2175,9 @@ static void hns_nic_set_priv_ops(struct net_device *netdev) priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx; } else { priv->ops.get_rxd_bnum = get_v2rx_desc_bnum; - if ((netdev->features & NETIF_F_TSO) || - (netdev->features & NETIF_F_TSO6)) { - priv->ops.fill_desc = fill_tso_desc; - priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tso; - /* This chip only support 7*4096 */ - netif_set_tso_max_size(netdev, 7 * 4096); - } else { - priv->ops.fill_desc = fill_v2_desc; - priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx; - } + priv->ops.fill_desc = fill_desc_v2; + priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx_v2; + netif_set_tso_max_size(netdev, 7 * 4096); /* enable tso when init * control tso on/off through TSE bit in bd */ diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.h b/drivers/net/ethernet/hisilicon/hns/hns_enet.h index ffa9d6573f54..3f3ee032f631 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.h +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.h @@ -44,7 +44,8 @@ struct hns_nic_ring_data { struct hns_nic_ops { void (*fill_desc)(struct hnae_ring *ring, void *priv, int size, dma_addr_t dma, int frag_end, - int buf_num, enum hns_desc_type type, int mtu); + int buf_num, enum hns_desc_type type, int mtu, + bool is_gso); int (*maybe_stop_tx)(struct sk_buff **out_skb, int *bnum, struct hnae_ring *ring); void (*get_rxd_bnum)(u32 bnum_flag, int *out_bnum); -- 2.30.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets 2023-12-04 14:32 ` [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets Jijie Shao @ 2023-12-06 11:18 ` Paolo Abeni 2023-12-06 12:31 ` Jijie Shao 0 siblings, 1 reply; 8+ messages in thread From: Paolo Abeni @ 2023-12-06 11:18 UTC (permalink / raw) To: Jijie Shao, yisen.zhuang, salil.mehta, davem, edumazet, kuba, wojciech.drewek Cc: shenjian15, wangjie125, liuyonglong, netdev, linux-kernel On Mon, 2023-12-04 at 22:32 +0800, Jijie Shao wrote: > @@ -2159,16 +2175,9 @@ static void hns_nic_set_priv_ops(struct net_device *netdev) > priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx; > } else { > priv->ops.get_rxd_bnum = get_v2rx_desc_bnum; > - if ((netdev->features & NETIF_F_TSO) || > - (netdev->features & NETIF_F_TSO6)) { > - priv->ops.fill_desc = fill_tso_desc; > - priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tso; > - /* This chip only support 7*4096 */ > - netif_set_tso_max_size(netdev, 7 * 4096); > - } else { > - priv->ops.fill_desc = fill_v2_desc; > - priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx; > - } > + priv->ops.fill_desc = fill_desc_v2; > + priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx_v2; > + netif_set_tso_max_size(netdev, 7 * 4096); > /* enable tso when init > * control tso on/off through TSE bit in bd > */ Side note: since both 'fill_desc' and 'maybe_stop_tx' have constant values, for net-next you should really consider replacing the function pointers with direct-calls. You currently have at least 2 indirect calls per wire packet, which hurt performances a lot in case security issues mitigations are in place. Cheers, Paolo ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets 2023-12-06 11:18 ` Paolo Abeni @ 2023-12-06 12:31 ` Jijie Shao 2023-12-06 14:27 ` Paolo Abeni 0 siblings, 1 reply; 8+ messages in thread From: Jijie Shao @ 2023-12-06 12:31 UTC (permalink / raw) To: Paolo Abeni, yisen.zhuang, salil.mehta, davem, edumazet, kuba, wojciech.drewek Cc: shaojijie, shenjian15, wangjie125, liuyonglong, netdev, linux-kernel on 2023/12/6 19:18, Paolo Abeni wrote: > + priv->ops.fill_desc = fill_desc_v2; > + priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx_v2; > Side note: since both 'fill_desc' and 'maybe_stop_tx' have constant > values, for net-next you should really consider replacing the function > pointers with direct-calls. > > You currently have at least 2 indirect calls per wire packet, which > hurt performances a lot in case security issues mitigations are in > place. > > Cheers, > > Paolo Thank you for your advice. Currently, because the hardware behavior is different, the two versions of ops are retained to unify the subsequent process. We will try to unify the two version ops, and if that does not work, we will consider maintaining the status quo. Thanks again! Jijie ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets 2023-12-06 12:31 ` Jijie Shao @ 2023-12-06 14:27 ` Paolo Abeni 0 siblings, 0 replies; 8+ messages in thread From: Paolo Abeni @ 2023-12-06 14:27 UTC (permalink / raw) To: Jijie Shao, yisen.zhuang, salil.mehta, davem, edumazet, kuba, wojciech.drewek Cc: shenjian15, wangjie125, liuyonglong, netdev, linux-kernel On Wed, 2023-12-06 at 20:31 +0800, Jijie Shao wrote: > on 2023/12/6 19:18, Paolo Abeni wrote: > > + priv->ops.fill_desc = fill_desc_v2; > > + priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx_v2; > > Side note: since both 'fill_desc' and 'maybe_stop_tx' have constant > > values, for net-next you should really consider replacing the function > > pointers with direct-calls. > > > > You currently have at least 2 indirect calls per wire packet, which > > hurt performances a lot in case security issues mitigations are in > > place. > > > > Cheers, > > > > Paolo > > Thank you for your advice. Currently, because the hardware behavior is > different, the two versions of ops are retained to unify the subsequent > process. We will try to unify the two version ops, and if that does not > work, we will consider maintaining the status quo. Thanks again! Jijie Note that even if you will have to resort to call different functions for different H/W revisions, from performance PoV you will be far better off doing a test at runtime to call the corresponding helper. Or you can use the indirect call wrappers - have a look into: include/linux/indirect_call_wrapper.h Cheers, Paolo ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH V3 net 2/2] net: hns: fix fake link up on xge port 2023-12-04 14:32 [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver Jijie Shao 2023-12-04 14:32 ` [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets Jijie Shao @ 2023-12-04 14:32 ` Jijie Shao 2023-12-05 11:44 ` Wojciech Drewek 2023-12-06 11:30 ` [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver patchwork-bot+netdevbpf 2 siblings, 1 reply; 8+ messages in thread From: Jijie Shao @ 2023-12-04 14:32 UTC (permalink / raw) To: yisen.zhuang, salil.mehta, davem, edumazet, kuba, pabeni, wojciech.drewek Cc: shenjian15, wangjie125, liuyonglong, shaojijie, netdev, linux-kernel From: Yonglong Liu <liuyonglong@huawei.com> If a xge port just connect with an optical module and no fiber, it may have a fake link up because there may be interference on the hardware. This patch adds an anti-shake to avoid the problem. And the time of anti-shake is base on tests. Fixes: b917078c1c10 ("net: hns: Add ACPI support to check SFP present") Signed-off-by: Yonglong Liu <liuyonglong@huawei.com> Signed-off-by: Jijie Shao <shaojijie@huawei.com> --- .../net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c index 928d934cb21a..f75668c47935 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c @@ -66,6 +66,27 @@ static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb) } } +static u32 hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv) +{ +#define HNS_MAC_LINK_WAIT_TIME 5 +#define HNS_MAC_LINK_WAIT_CNT 40 + + u32 link_status = 0; + int i; + + if (!mac_ctrl_drv->get_link_status) + return link_status; + + for (i = 0; i < HNS_MAC_LINK_WAIT_CNT; i++) { + msleep(HNS_MAC_LINK_WAIT_TIME); + mac_ctrl_drv->get_link_status(mac_ctrl_drv, &link_status); + if (!link_status) + break; + } + + return link_status; +} + void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status) { 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) &sfp_prsnt); if (!ret) *link_status = *link_status && sfp_prsnt; + + /* for FIBER port, it may have a fake link up. + * when the link status changes from down to up, we need to do + * anti-shake. the anti-shake time is base on tests. + * only FIBER port need to do this. + */ + if (*link_status && !mac_cb->link) + *link_status = hns_mac_link_anti_shake(mac_ctrl_drv); } mac_cb->link = *link_status; -- 2.30.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH V3 net 2/2] net: hns: fix fake link up on xge port 2023-12-04 14:32 ` [PATCH V3 net 2/2] net: hns: fix fake link up on xge port Jijie Shao @ 2023-12-05 11:44 ` Wojciech Drewek 0 siblings, 0 replies; 8+ messages in thread From: Wojciech Drewek @ 2023-12-05 11:44 UTC (permalink / raw) To: Jijie Shao, yisen.zhuang, salil.mehta, davem, edumazet, kuba, pabeni Cc: shenjian15, wangjie125, liuyonglong, netdev, linux-kernel On 04.12.2023 15:32, Jijie Shao wrote: > From: Yonglong Liu <liuyonglong@huawei.com> > > If a xge port just connect with an optical module and no fiber, > it may have a fake link up because there may be interference on > the hardware. This patch adds an anti-shake to avoid the problem. > And the time of anti-shake is base on tests. > > Fixes: b917078c1c10 ("net: hns: Add ACPI support to check SFP present") > Signed-off-by: Yonglong Liu <liuyonglong@huawei.com> > Signed-off-by: Jijie Shao <shaojijie@huawei.com> > --- Thanks! Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com> > .../net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 29 +++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c > index 928d934cb21a..f75668c47935 100644 > --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c > +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c > @@ -66,6 +66,27 @@ static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb) > } > } > > +static u32 hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv) > +{ > +#define HNS_MAC_LINK_WAIT_TIME 5 > +#define HNS_MAC_LINK_WAIT_CNT 40 > + > + u32 link_status = 0; > + int i; > + > + if (!mac_ctrl_drv->get_link_status) > + return link_status; > + > + for (i = 0; i < HNS_MAC_LINK_WAIT_CNT; i++) { > + msleep(HNS_MAC_LINK_WAIT_TIME); > + mac_ctrl_drv->get_link_status(mac_ctrl_drv, &link_status); > + if (!link_status) > + break; > + } > + > + return link_status; > +} > + > void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status) > { > 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) > &sfp_prsnt); > if (!ret) > *link_status = *link_status && sfp_prsnt; > + > + /* for FIBER port, it may have a fake link up. > + * when the link status changes from down to up, we need to do > + * anti-shake. the anti-shake time is base on tests. > + * only FIBER port need to do this. > + */ > + if (*link_status && !mac_cb->link) > + *link_status = hns_mac_link_anti_shake(mac_ctrl_drv); > } > > mac_cb->link = *link_status; ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver 2023-12-04 14:32 [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver Jijie Shao 2023-12-04 14:32 ` [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets Jijie Shao 2023-12-04 14:32 ` [PATCH V3 net 2/2] net: hns: fix fake link up on xge port Jijie Shao @ 2023-12-06 11:30 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 8+ messages in thread From: patchwork-bot+netdevbpf @ 2023-12-06 11:30 UTC (permalink / raw) To: Jijie Shao Cc: yisen.zhuang, salil.mehta, davem, edumazet, kuba, pabeni, wojciech.drewek, shenjian15, wangjie125, liuyonglong, netdev, linux-kernel Hello: This series was applied to netdev/net.git (main) by Paolo Abeni <pabeni@redhat.com>: On Mon, 4 Dec 2023 22:32:30 +0800 you wrote: > 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/20231204011051.4055031-1-shaojijie@huawei.com/ > v1 -> v2: > - Fixed the internal function is not decorated with static issue, suggested by Jakub > v1: https://lore.kernel.org/all/20231201102703.4134592-1-shaojijie@huawei.com/ > > [...] Here is the summary with links: - [V3,net,1/2] net: hns: fix wrong head when modify the tx feature when sending packets https://git.kernel.org/netdev/net/c/84757d083945 - [V3,net,2/2] net: hns: fix fake link up on xge port https://git.kernel.org/netdev/net/c/f708aba40f9c You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-12-06 14:28 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-12-04 14:32 [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver Jijie Shao 2023-12-04 14:32 ` [PATCH V3 net 1/2] net: hns: fix wrong head when modify the tx feature when sending packets Jijie Shao 2023-12-06 11:18 ` Paolo Abeni 2023-12-06 12:31 ` Jijie Shao 2023-12-06 14:27 ` Paolo Abeni 2023-12-04 14:32 ` [PATCH V3 net 2/2] net: hns: fix fake link up on xge port Jijie Shao 2023-12-05 11:44 ` Wojciech Drewek 2023-12-06 11:30 ` [PATCH V3 net 0/2] There are some bugfix for the HNS ethernet driver patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox