diff mbox series

[net-next,12/13] net: fec: fec_enet_rx_queue(): move_call to _vlan_hwaccel_put_tag()

Message ID 20241016-fec-cleanups-v1-12-de783bd15e6a@pengutronix.de (mailing list archive)
State New
Headers show
Series net: fec: cleanups, update quirk, update IRQ naming | expand

Commit Message

Marc Kleine-Budde Oct. 16, 2024, 9:52 p.m. UTC
To clean up the VLAN handling, move the call to
__vlan_hwaccel_put_tag() into the body of the if statement, which
checks for VLAN handling in the first place.

This allows to remove vlan_packet_rcvd and reduce the scope of
vlan_tag.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/ethernet/freescale/fec_main.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

Comments

Frank Li Oct. 17, 2024, 3:05 a.m. UTC | #1
On Wed, Oct 16, 2024 at 11:52:00PM +0200, Marc Kleine-Budde wrote:
> To clean up the VLAN handling, move the call to
> __vlan_hwaccel_put_tag() into the body of the if statement, which
> checks for VLAN handling in the first place.
>
> This allows to remove vlan_packet_rcvd and reduce the scope of
> vlan_tag.

Move __vlan_hwaccel_put_tag() into the if statement that sets
vlan_packet_rcvd=true. This change eliminates the unnecessary
vlan_packet_rcvd variable, simplifying the code and improving clarity.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/net/ethernet/freescale/fec_main.c | 16 ++++------------
>  1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
> index 640fbde10861005e7e2eb23358bfeaac49ec1792..d9415c7c16cea3fc3d91e198c21af9fe9e21747e 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -1688,8 +1688,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
>  	ushort	pkt_len;
>  	int	pkt_received = 0;
>  	struct	bufdesc_ex *ebdp = NULL;
> -	bool	vlan_packet_rcvd = false;
> -	u16	vlan_tag;
>  	int	index = 0;
>  	bool	need_swap = fep->quirks & FEC_QUIRK_SWAP_FRAME;
>  	struct bpf_prog *xdp_prog = READ_ONCE(fep->xdp_prog);
> @@ -1814,18 +1812,18 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
>  			ebdp = (struct bufdesc_ex *)bdp;
>
>  		/* If this is a VLAN packet remove the VLAN Tag */
> -		vlan_packet_rcvd = false;
>  		if ((ndev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
>  		    fep->bufdesc_ex &&
>  		    (ebdp->cbd_esc & cpu_to_fec32(BD_ENET_RX_VLAN))) {
>  			/* Push and remove the vlan tag */
>  			struct vlan_ethhdr *vlan_header = skb_vlan_eth_hdr(skb);
> -			vlan_tag = ntohs(vlan_header->h_vlan_TCI);
> -
> -			vlan_packet_rcvd = true;
> +			u16 vlan_tag = ntohs(vlan_header->h_vlan_TCI);
>
>  			memmove(skb->data + VLAN_HLEN, skb->data, ETH_ALEN * 2);
>  			skb_pull(skb, VLAN_HLEN);
> +			__vlan_hwaccel_put_tag(skb,
> +					       htons(ETH_P_8021Q),
> +					       vlan_tag);
>  		}
>
>  		skb->protocol = eth_type_trans(skb, ndev);
> @@ -1845,12 +1843,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
>  			}
>  		}
>
> -		/* Handle received VLAN packets */
> -		if (vlan_packet_rcvd)
> -			__vlan_hwaccel_put_tag(skb,
> -					       htons(ETH_P_8021Q),
> -					       vlan_tag);
> -
>  		skb_record_rx_queue(skb, queue_id);
>  		napi_gro_receive(&fep->napi, skb);
>
>
> --
> 2.45.2
>
>
Wei Fang Oct. 17, 2024, 3:29 a.m. UTC | #2
> -----Original Message-----
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> Sent: 2024年10月17日 5:52
> To: Wei Fang <wei.fang@nxp.com>; Shenwei Wang <shenwei.wang@nxp.com>;
> Clark Wang <xiaoning.wang@nxp.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Richard
> Cochran <richardcochran@gmail.com>
> Cc: imx@lists.linux.dev; netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
> kernel@pengutronix.de; Marc Kleine-Budde <mkl@pengutronix.de>
> Subject: [PATCH net-next 12/13] net: fec: fec_enet_rx_queue(): move_call to
> _vlan_hwaccel_put_tag()
> 
> To clean up the VLAN handling, move the call to
> __vlan_hwaccel_put_tag() into the body of the if statement, which
> checks for VLAN handling in the first place.
> 
> This allows to remove vlan_packet_rcvd and reduce the scope of
> vlan_tag.
> 
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/net/ethernet/freescale/fec_main.c | 16 ++++------------
>  1 file changed, 4 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index
> 640fbde10861005e7e2eb23358bfeaac49ec1792..d9415c7c16cea3fc3d91e19
> 8c21af9fe9e21747e 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -1688,8 +1688,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16
> queue_id, int budget)
>  	ushort	pkt_len;
>  	int	pkt_received = 0;
>  	struct	bufdesc_ex *ebdp = NULL;
> -	bool	vlan_packet_rcvd = false;
> -	u16	vlan_tag;
>  	int	index = 0;
>  	bool	need_swap = fep->quirks & FEC_QUIRK_SWAP_FRAME;
>  	struct bpf_prog *xdp_prog = READ_ONCE(fep->xdp_prog);
> @@ -1814,18 +1812,18 @@ fec_enet_rx_queue(struct net_device *ndev, u16
> queue_id, int budget)
>  			ebdp = (struct bufdesc_ex *)bdp;
> 
>  		/* If this is a VLAN packet remove the VLAN Tag */
> -		vlan_packet_rcvd = false;
>  		if ((ndev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
>  		    fep->bufdesc_ex &&
>  		    (ebdp->cbd_esc & cpu_to_fec32(BD_ENET_RX_VLAN))) {
>  			/* Push and remove the vlan tag */
>  			struct vlan_ethhdr *vlan_header = skb_vlan_eth_hdr(skb);
> -			vlan_tag = ntohs(vlan_header->h_vlan_TCI);
> -
> -			vlan_packet_rcvd = true;
> +			u16 vlan_tag = ntohs(vlan_header->h_vlan_TCI);
> 
>  			memmove(skb->data + VLAN_HLEN, skb->data, ETH_ALEN * 2);
>  			skb_pull(skb, VLAN_HLEN);
> +			__vlan_hwaccel_put_tag(skb,
> +					       htons(ETH_P_8021Q),
> +					       vlan_tag);
>  		}
> 
>  		skb->protocol = eth_type_trans(skb, ndev);
> @@ -1845,12 +1843,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16
> queue_id, int budget)
>  			}
>  		}
> 
> -		/* Handle received VLAN packets */
> -		if (vlan_packet_rcvd)
> -			__vlan_hwaccel_put_tag(skb,
> -					       htons(ETH_P_8021Q),
> -					       vlan_tag);
> -
>  		skb_record_rx_queue(skb, queue_id);
>  		napi_gro_receive(&fep->napi, skb);
> 
> 
> --
> 2.45.2
> 

Thanks

Reviewed-by: Wei Fang <wei.fang@nxp.com>
Marc Kleine-Budde Oct. 17, 2024, 7:05 a.m. UTC | #3
On 16.10.2024 23:05:27, Frank Li wrote:
> On Wed, Oct 16, 2024 at 11:52:00PM +0200, Marc Kleine-Budde wrote:
> > To clean up the VLAN handling, move the call to
> > __vlan_hwaccel_put_tag() into the body of the if statement, which
> > checks for VLAN handling in the first place.
> >
> > This allows to remove vlan_packet_rcvd and reduce the scope of
> > vlan_tag.
> 
> Move __vlan_hwaccel_put_tag() into the if statement that sets
> vlan_packet_rcvd=true. This change eliminates the unnecessary
> vlan_packet_rcvd variable, simplifying the code and improving clarity.

Fixed,
Marc
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 640fbde10861005e7e2eb23358bfeaac49ec1792..d9415c7c16cea3fc3d91e198c21af9fe9e21747e 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1688,8 +1688,6 @@  fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
 	ushort	pkt_len;
 	int	pkt_received = 0;
 	struct	bufdesc_ex *ebdp = NULL;
-	bool	vlan_packet_rcvd = false;
-	u16	vlan_tag;
 	int	index = 0;
 	bool	need_swap = fep->quirks & FEC_QUIRK_SWAP_FRAME;
 	struct bpf_prog *xdp_prog = READ_ONCE(fep->xdp_prog);
@@ -1814,18 +1812,18 @@  fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
 			ebdp = (struct bufdesc_ex *)bdp;
 
 		/* If this is a VLAN packet remove the VLAN Tag */
-		vlan_packet_rcvd = false;
 		if ((ndev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
 		    fep->bufdesc_ex &&
 		    (ebdp->cbd_esc & cpu_to_fec32(BD_ENET_RX_VLAN))) {
 			/* Push and remove the vlan tag */
 			struct vlan_ethhdr *vlan_header = skb_vlan_eth_hdr(skb);
-			vlan_tag = ntohs(vlan_header->h_vlan_TCI);
-
-			vlan_packet_rcvd = true;
+			u16 vlan_tag = ntohs(vlan_header->h_vlan_TCI);
 
 			memmove(skb->data + VLAN_HLEN, skb->data, ETH_ALEN * 2);
 			skb_pull(skb, VLAN_HLEN);
+			__vlan_hwaccel_put_tag(skb,
+					       htons(ETH_P_8021Q),
+					       vlan_tag);
 		}
 
 		skb->protocol = eth_type_trans(skb, ndev);
@@ -1845,12 +1843,6 @@  fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
 			}
 		}
 
-		/* Handle received VLAN packets */
-		if (vlan_packet_rcvd)
-			__vlan_hwaccel_put_tag(skb,
-					       htons(ETH_P_8021Q),
-					       vlan_tag);
-
 		skb_record_rx_queue(skb, queue_id);
 		napi_gro_receive(&fep->napi, skb);