net: enetc: fix some known issues
Subsystems (5)
Wei Fang
maintainerv3 cover net: enetc: fix some known issues
There are some issues with the enetc driver, some of which are specific to the LS1028A platform, and some of which were introduced recently when i.MX95 ENETC support was added, so this patch set aims to clean up those issues.
---
v1 link: https://lore.kernel.org/imx/[email protected]/
v2 changes:
1. Remove the unneeded semicolon from patch 1
2. Modify the commit message of patch 1
3. Add new patch 9 to fix another off-by-one issue
v2 link: https://lore.kernel.org/imx/[email protected]/
v3 changes:
1. remove the patch "net: enetc: correct the EMDIO base offset for ENETC v4"
2. Add a helper function enetc_unwind_tx_frame()
3. Change the subject of patch 2, and refactor the implementation.
4. Use enetc_unwind_tx_frame() in patch 8, and roll back 'i' when enetc_map_tx_tso_data() returns an error
5. Collect Reviewed-by and Tested-by tags
---
Wei Fang (8):
net: enetc: fix the off-by-one issue in enetc_map_tx_buffs()
net: enetc: keep track of correct Tx BD count in
enetc_map_tx_tso_buffs()
net: enetc: correct the xdp_tx statistics
net: enetc: VFs do not support HWTSTAMP_TX_ONESTEP_SYNC
net: enetc: update UDP checksum when updating originTimestamp field
net: enetc: add missing enetc4_link_deinit()
net: enetc: remove the mm_lock from the ENETC v4 driver
net: enetc: fix the off-by-one issue in enetc_map_tx_tso_buffs()
drivers/net/ethernet/freescale/enetc/enetc.c | 103 +++++++++++++----- .../net/ethernet/freescale/enetc/enetc4_pf.c | 2 +- .../ethernet/freescale/enetc/enetc_ethtool.c | 7 +- 3 files changed, 80 insertions(+), 32 deletions(-)
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v3 1/8 net: enetc: fix the off-by-one issue in enetc_map_tx_buffs()
When a DMA mapping error occurs while processing skb frags, it will free one more tx_swbd than expected, so fix this off-by-one issue.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 26 ++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +19 -7
@@ -167,6 +167,24 @@ static bool enetc_skb_is_tcp(struct sk_buff *skb)return skb->csum_offset == offsetof(struct tcphdr , check); } +/** +* enetc_unwind_tx_frame() - Unwind the DMA mappings of a multi-buffer Tx frame +* @tx_ring: Pointer to the Tx ring on which the buffer descriptors are located +* @count: Number of Tx buffer descriptors which need to be unmapped +* @i: Index of the last successfully mapped Tx buffer descriptor +*/ +static void enetc_unwind_tx_frame (struct enetc_bdr *tx_ring,int count,int i) +{ +while (count--) { +struct enetc_tx_swbd *tx_swbd = &tx_ring->tx_swbd[i]; + +enetc_free_tx_frame (tx_ring, tx_swbd); +if (i ==0 ) + i = tx_ring->bd_count; + i--; + } +} +static int enetc_map_tx_buffs (struct enetc_bdr *tx_ring,struct sk_buff *skb) {bool do_vlan, do_onestep_tstamp = false, do_twostep_tstamp = false;
@@ -372,13 +390,7 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb) dma_err:dev_err (tx_ring->dev,"DMA map error" ); -do { - tx_swbd = &tx_ring->tx_swbd[i]; -enetc_free_tx_frame (tx_ring, tx_swbd); -if (i ==0 ) - i = tx_ring->bd_count; - i--; - }while (count--); +enetc_unwind_tx_frame (tx_ring, count, i);return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH v3 net 1/8] net: enetc: fix the off-by-one issue in enetc_map_tx_buffs()
Quoted 9 lines · Wei Fang
When a DMA mapping error occurs while processing skb frags, it will free one more
tx_swbdthan expected, so fix this off-by-one issue.Fixes d4fd0404c1c9 ("enetc: Introduce basic PF and VF ENETC ethernet drivers")Suggested-by Vladimir Oltean <[email protected]>Suggested-by Michal Swiatkowski <[email protected]>Signed-off-by Wei Fang <[email protected]>---
RE: [PATCH v3 net 1/8] net: enetc: fix the off-by-one issue in enetc_map_tx_buffs()
In reply to Wei FangQuoted 3 lines
-----Original Message-----
From: Wei Fang <[email protected]>
Sent: Monday, February 24, 2025 1:13 PM
[...]
Quoted 6 lines
Subject: [PATCH v3 net 1/8] net: enetc: fix the off-by-one issue in
enetc_map_tx_buffs()When a DMA mapping error occurs while processing skb frags, it will free one more
tx_swbdthan expected, so fix this off-by-one issue.
Quoted 7 lines
Fixes d4fd0404c1c9 ("enetc: Introduce basic PF and VF ENETC ethernetdrivers")
Suggested-by Vladimir Oltean <[email protected]>Suggested-by Michal Swiatkowski <[email protected]>Signed-off-by Wei Fang <[email protected]>---
Wei Fang
maintainerPATCH v3 2/8 net: enetc: keep track of correct Tx BD count in enetc_map_tx_tso_buffs()
In reply to Wei FangWhen creating a TSO header, if the skb is VLAN tagged, the extended BD will be used and the 'count' should be increased by 2 instead of 1. Otherwise, when an error occurs, less tx_swbd will be freed than the actual number.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +10 -6
@@ -395,14 +395,15 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)return 0 ; } -static void enetc_map_tx_tso_hdr (struct enetc_bdr *tx_ring,struct sk_buff *skb, -struct enetc_tx_swbd *tx_swbd, -union enetc_tx_bd *txbd,int *i,int hdr_len, -int data_len) +static int enetc_map_tx_tso_hdr (struct enetc_bdr *tx_ring,struct sk_buff *skb, +struct enetc_tx_swbd *tx_swbd, +union enetc_tx_bd *txbd,int *i,int hdr_len, +int data_len) {union enetc_tx_bd txbd_tmp;u8 flags =0 , e_flags =0 ;dma_addr_t addr; +int count =1 ;enetc_clear_tx_bd (&txbd_tmp); addr = tx_ring->tso_headers_dma + *i *TSO_HEADER_SIZE ;
@@ -445,7 +446,10 @@ static void enetc_map_tx_tso_hdr(struct enetc_bdr *tx_ring, struct sk_buff *skb,/* Write the BD */ txbd_tmp.ext.e_flags = e_flags; *txbd = txbd_tmp; + count++; } + +return count; } static int enetc_map_tx_tso_data(struct enetc_bdr *tx_ring, struct sk_buff *skb,
@@ -802,9 +806,9 @@ static int enetc_map_tx_tso_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb/* compute the csum over the L4 header */ csum =enetc_tso_hdr_csum (&tso, skb, hdr, hdr_len, &pos); -enetc_map_tx_tso_hdr (tx_ring, skb, tx_swbd, txbd, &i, hdr_len, data_len); + count +=enetc_map_tx_tso_hdr (tx_ring, skb, tx_swbd, txbd, + &i, hdr_len, data_len); bd_data_num =0 ; - count++;while (data_len >0 ) {int size;
Signature · 1 line
2.34.1
Re: [PATCH v3 net 2/8] net: enetc: keep track of correct Tx BD count in enetc_map_tx_tso_buffs()
Quoted 10 lines · Wei Fang
When creating a TSO header, if the skb is VLAN tagged, the extended BD will be used and the 'count' should be increased by 2 instead of 1. Otherwise, when an error occurs, less
tx_swbdwill be freed than the actual number.Fixes fb8629e2cbfc ("net: enetc: add support for software TSO")Suggested-by Vladimir Oltean <[email protected]>Signed-off-by Wei Fang <[email protected]>---
RE: [PATCH v3 net 2/8] net: enetc: keep track of correct Tx BD count in enetc_map_tx_tso_buffs()
In reply to Wei FangQuoted 3 lines
-----Original Message-----
From: Wei Fang <[email protected]>
Sent: Monday, February 24, 2025 1:13 PM
[...]
Quoted 8 lines
Subject: [PATCH v3 net 2/8] net: enetc: keep track of correct Tx BD count in
enetc_map_tx_tso_buffs()When creating a TSO header, if the skb is VLAN tagged, the extended BD will be used and the 'count' should be increased by 2 instead of 1. Otherwise, when an error occurs, less
tx_swbdwill be freed than the actual number.
Quoted 5 lines
Fixes fb8629e2cbfc ("net: enetc: add support for software TSO")Suggested-by Vladimir Oltean <[email protected]>Signed-off-by Wei Fang <[email protected]>---
Wei Fang
maintainerPATCH v3 3/8 net: enetc: correct the xdp_tx statistics
In reply to Wei FangThe 'xdp_tx' is used to count the number of XDP_TX frames sent, not the number of Tx BDs.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/freescale/enetc/enetc.c +1 -1
@@ -1917,7 +1917,7 @@ static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring,enetc_xdp_drop (rx_ring, orig_i, i); tx_ring->stats.xdp_tx_drops++; }else { - tx_ring->stats.xdp_tx += xdp_tx_bd_cnt; + tx_ring->stats.xdp_tx++; rx_ring->xdp.xdp_tx_in_flight += xdp_tx_bd_cnt; xdp_tx_frm_cnt++;/* The XDP_TX enqueue was successful, so we
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v3 4/8 net: enetc: VFs do not support HWTSTAMP_TX_ONESTEP_SYNC
In reply to Wei FangActually ENETC VFs do not support HWTSTAMP_TX_ONESTEP_SYNC because only ENETC PF can access PMa_SINGLE_STEP registers. And there will be a crash if VFs are used to test one-step timestamp, the crash log as follows.
[ 129.110909] Unable to handle kernel paging request at virtual address 00000000000080c0 [ 129.287769] Call trace: [ 129.290219] enetc_port_mac_wr+0x30/0xec (P) [ 129.294504] enetc_start_xmit+0xda4/0xe74 [ 129.298525] enetc_xmit+0x70/0xec [ 129.301848] dev_hard_start_xmit+0x98/0x118
--- drivers/net/ethernet/freescale/enetc/enetc.c | 3 +++ drivers/net/ethernet/freescale/enetc/enetc_ethtool.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +3 -0
@@ -3244,6 +3244,9 @@ static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr) new_offloads |=ENETC_F_TX_TSTAMP ;break ;case HWTSTAMP_TX_ONESTEP_SYNC : +if (!enetc_si_is_pf (priv->si)) +return -EOPNOTSUPP ; + new_offloads &= ~ENETC_F_TX_TSTAMP_MASK ; new_offloads |=ENETC_F_TX_ONESTEP_SYNC_TSTAMP ;break ;
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +5 -2
@@ -832,6 +832,7 @@ static int enetc_set_coalesce(struct net_device *ndev,static int enetc_get_ts_info (struct net_device *ndev,struct kernel_ethtool_ts_info *info) { +struct enetc_ndev_priv *priv =netdev_priv (ndev);int *phc_idx; phc_idx =symbol_get (enetc_phc_index);
@@ -852,8 +853,10 @@ static int enetc_get_ts_info(struct net_device *ndev,SOF_TIMESTAMPING_TX_SOFTWARE ; info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | - (1 <<HWTSTAMP_TX_ON ) | - (1 <<HWTSTAMP_TX_ONESTEP_SYNC ); + (1 <<HWTSTAMP_TX_ON ); + +if (enetc_si_is_pf (priv->si)) + info->tx_types |= (1 <<HWTSTAMP_TX_ONESTEP_SYNC ); info->rx_filters = (1 <<HWTSTAMP_FILTER_NONE ) | (1 <<HWTSTAMP_FILTER_ALL );
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v3 5/8 net: enetc: update UDP checksum when updating originTimestamp field
In reply to Wei FangThere is an issue with one-step timestamp based on UDP/IP. The peer will discard the sync packet because of the wrong UDP checksum. For ENETC v1, the software needs to update the UDP checksum when updating the originTimestamp field, so that the hardware can correctly update the UDP checksum when updating the correction field. Otherwise, the UDP checksum in the sync packet will be wrong.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 41 ++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +34 -7
@@ -297,9 +297,11 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb) }if (do_onestep_tstamp) { -u32 lo, hi, val; -u64 sec, nsec; +__be32 new_sec_l, new_nsec; +u32 lo, hi, nsec, val; +__be16 new_sec_h;u8 *data; +u64 sec; lo =enetc_rd_hot (hw,ENETC_SICTR0 ); hi =enetc_rd_hot (hw,ENETC_SICTR1 );
@@ -313,13 +315,38 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)/* Update originTimestamp field of Sync packet * - 48 bits seconds field * - 32 bits nanseconds field +* +* In addition, the UDP checksum needs to be updated +* by software after updating originTimestamp field, +* otherwise the hardware will calculate the wrong +* checksum when updating the correction field and +* update it to the packet. */ data =skb_mac_header (skb); - *(__be16 *)(data + offset2) = -htons ((sec >>32 ) &0xffff ); - *(__be32 *)(data + offset2 +2 ) = -htonl (sec &0xffffffff ); - *(__be32 *)(data + offset2 +6 ) =htonl (nsec); + new_sec_h =htons ((sec >>32 ) &0xffff ); + new_sec_l =htonl (sec &0xffffffff ); + new_nsec =htonl (nsec); +if (udp) { +struct udphdr *uh =udp_hdr (skb); +__be32 old_sec_l, old_nsec; +__be16 old_sec_h; + + old_sec_h = *(__be16 *)(data + offset2); +inet_proto_csum_replace2 (&uh->check, skb, old_sec_h, + new_sec_h, false); + + old_sec_l = *(__be32 *)(data + offset2 +2 ); +inet_proto_csum_replace4 (&uh->check, skb, old_sec_l, + new_sec_l, false); + + old_nsec = *(__be32 *)(data + offset2 +6 ); +inet_proto_csum_replace4 (&uh->check, skb, old_nsec, + new_nsec, false); + } + + *(__be16 *)(data + offset2) = new_sec_h; + *(__be32 *)(data + offset2 +2 ) = new_sec_l; + *(__be32 *)(data + offset2 +6 ) = new_nsec;/* Configure single-step register */ val =ENETC_PM0_SINGLE_STEP_EN ;
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v3 6/8 net: enetc: add missing enetc4_link_deinit()
In reply to Wei FangThe enetc4_link_init() is called when the PF driver probes to create phylink and MDIO bus, but we forgot to call enetc4_link_deinit() to free the phylink and MDIO bus when the driver was unbound. so add missing enetc4_link_deinit() to enetc4_pf_netdev_destroy().
--- drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +1 -0
@@ -684,6 +684,7 @@ static void enetc4_pf_netdev_destroy(struct enetc_si *si)struct net_device *ndev = si->ndev;unregister_netdev (ndev); +enetc4_link_deinit (priv);enetc_free_msix (priv);free_netdev (ndev); }
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v3 7/8 net: enetc: remove the mm_lock from the ENETC v4 driver
In reply to Wei FangCurrently, the ENETC v4 driver has not added the MAC merge layer support in the upstream, so the mm_lock is not initialized and used, so remove the mm_lock from the driver.
--- drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +0 -1
@@ -672,7 +672,6 @@ static int enetc4_pf_netdev_create(struct enetc_si *si) err_alloc_msix: err_config_si: err_clk_get: -mutex_destroy (&priv->mm_lock);free_netdev (ndev);return err;
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v3 8/8 net: enetc: fix the off-by-one issue in enetc_map_tx_tso_buffs()
In reply to Wei FangThere is an off-by-one issue for the err_chained_bd path, it will free one more tx_swbd than expected. But there is no such issue for the err_map_data path. To fix this off-by-one issue and make the two error handling consistent, the increment of 'i' and 'count' remain in sync and enetc_unwind_tx_frame() is called for error handling.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +7 -8
@@ -859,8 +859,13 @@ static int enetc_map_tx_tso_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb err =enetc_map_tx_tso_data (tx_ring, skb, tx_swbd, txbd, tso.data, size, size == data_len); -if (err) +if (err) { +if (i ==0 ) + i = tx_ring->bd_count; + i--; + goto err_map_data; + } data_len -= size; count++;
@@ -889,13 +894,7 @@ static int enetc_map_tx_tso_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skbdev_err (tx_ring->dev,"DMA map error" ); err_chained_bd: -do { - tx_swbd = &tx_ring->tx_swbd[i]; -enetc_free_tx_frame (tx_ring, tx_swbd); -if (i ==0 ) - i = tx_ring->bd_count; - i--; - }while (count--); +enetc_unwind_tx_frame (tx_ring, count, i);return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH v3 net 8/8] net: enetc: fix the off-by-one issue in enetc_map_tx_tso_buffs()
Quoted 11 lines · Wei Fang
There is an off-by-one issue for the
err_chained_bdpath, it will free one moretx_swbdthan expected. But there is no such issue for theerr_map_datapath. To fix this off-by-one issue and make the two error handling consistent, the increment of 'i' and 'count' remain in sync andenetc_unwind_tx_frame()is called for error handling.Fixes fb8629e2cbfc ("net: enetc: add support for software TSO")Suggested-by Vladimir Oltean <[email protected]>Signed-off-by Wei Fang <[email protected]>---
RE: [PATCH v3 net 8/8] net: enetc: fix the off-by-one issue in enetc_map_tx_tso_buffs()
In reply to Wei FangQuoted 3 lines
-----Original Message-----
From: Wei Fang <[email protected]>
Sent: Monday, February 24, 2025 1:13 PM
[...]
Quoted 9 lines
Subject: [PATCH v3 net 8/8] net: enetc: fix the off-by-one issue in
enetc_map_tx_tso_buffs()There is an off-by-one issue for the
err_chained_bdpath, it will free one moretx_swbdthan expected. But there is no such issue for theerr_map_datapath. To fix this off-by-one issue and make the two error handling consistent, the increment of 'i' and 'count' remain in sync andenetc_unwind_tx_frame()is called for error handling.
Quoted 5 lines
Fixes fb8629e2cbfc ("net: enetc: add support for software TSO")Suggested-by Vladimir Oltean <[email protected]>Signed-off-by Wei Fang <[email protected]>---
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Mon, 24 Feb 2025 19:12:43 +0800 you wrote:
There are some issues with the enetc driver, some of which are specific to the LS1028A platform, and some of which were introduced recently when i.MX95 ENETC support was added, so this patch set aims to clean up those issues.
Quoted 8 lines
---
v1 link: https://lore.kernel.org/imx/[email protected]/
v2 changes:
1. Remove the unneeded semicolon from patch 1
2. Modify the commit message of patch 1
3. Add new patch 9 to fix another off-by-one issue[...]
Here is the summary with links:
- [v3,net,1/8] net: enetc: fix the off-by-one issue in enetc_map_tx_buffs()
https://git.kernel.org/netdev/net/c/39ab773e4c12 - [v3,net,2/8] net: enetc: keep track of correct Tx BD count in enetc_map_tx_tso_buffs() https://git.kernel.org/netdev/net/c/da291996b16e - [v3,net,3/8] net: enetc: correct the xdp_tx statistics https://git.kernel.org/netdev/net/c/432a2cb3ee97 - [v3,net,4/8] net: enetc: VFs do not support HWTSTAMP_TX_ONESTEP_SYNC https://git.kernel.org/netdev/net/c/a562d0c4a893 - [v3,net,5/8] net: enetc: update UDP checksum when updating originTimestamp field https://git.kernel.org/netdev/net/c/bbcbc906ab7b - [v3,net,6/8] net: enetc: add missing enetc4_link_deinit() https://git.kernel.org/netdev/net/c/8e43decdfbb4 - [v3,net,7/8] net: enetc: remove the mm_lock from the ENETC v4 driver https://git.kernel.org/netdev/net/c/119049b66b88 - [v3,net,8/8] net: enetc: fix the off-by-one issue in enetc_map_tx_tso_buffs() https://git.kernel.org/netdev/net/c/249df695c3ff
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html