diff mbox series

[2/2,net-next,v2] igb: refactor XDP registration

Message ID 20220114114354.1071776-3-vinschen@redhat.com
State Superseded
Headers show
Series igb/igc: fix XDP registration | expand

Commit Message

Corinna Vinschen Jan. 14, 2022, 11:43 a.m. UTC
On changing the RX ring parameters igb uses a hack to avoid a warning
when calling xdp_rxq_info_reg via igb_setup_rx_resources.  It just
clears the struct xdp_rxq_info content.

Change this to unregister if we're already registered instead.  ALign
code to the igc code.

Fixes: 9cbc948b5a20c ("igb: add XDP support")
Signed-off-by: Corinna Vinschen <vinschen@redhat.com>
---
 drivers/net/ethernet/intel/igb/igb_ethtool.c |  4 ----
 drivers/net/ethernet/intel/igb/igb_main.c    | 15 +++++++++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

Comments

Denis Kirjanov Jan. 14, 2022, 2:13 p.m. UTC | #1
1/14/22 14:43, Corinna Vinschen пишет:
> On changing the RX ring parameters igb uses a hack to avoid a warning
> when calling xdp_rxq_info_reg via igb_setup_rx_resources.  It just
> clears the struct xdp_rxq_info content.
> 
> Change this to unregister if we're already registered instead.  ALign
> code to the igc code.
> 
> Fixes: 9cbc948b5a20c ("igb: add XDP support")
> Signed-off-by: Corinna Vinschen <vinschen@redhat.com>
> ---
>   drivers/net/ethernet/intel/igb/igb_ethtool.c |  4 ----
>   drivers/net/ethernet/intel/igb/igb_main.c    | 15 +++++++++++----
>   2 files changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> index 51a2dcaf553d..2a5782063f4c 100644
> --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
> +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> @@ -965,10 +965,6 @@ static int igb_set_ringparam(struct net_device *netdev,
>   			memcpy(&temp_ring[i], adapter->rx_ring[i],
>   			       sizeof(struct igb_ring));
>   
> -			/* Clear copied XDP RX-queue info */
> -			memset(&temp_ring[i].xdp_rxq, 0,
> -			       sizeof(temp_ring[i].xdp_rxq));
> -
>   			temp_ring[i].count = new_rx_count;
>   			err = igb_setup_rx_resources(&temp_ring[i]);
>   			if (err) {
> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 38ba92022cd4..9638cb9c6014 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -4352,7 +4352,7 @@ int igb_setup_rx_resources(struct igb_ring *rx_ring)
>   {
>   	struct igb_adapter *adapter = netdev_priv(rx_ring->netdev);
>   	struct device *dev = rx_ring->dev;
> -	int size;
> +	int size, res;
>   
>   	size = sizeof(struct igb_rx_buffer) * rx_ring->count;
>   
> @@ -4376,9 +4376,16 @@ int igb_setup_rx_resources(struct igb_ring *rx_ring)
>   	rx_ring->xdp_prog = adapter->xdp_prog;
>   
>   	/* XDP RX-queue info */
> -	if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev,
> -			     rx_ring->queue_index, 0) < 0)
> -		goto err;
> +	if (xdp_rxq_info_is_reg(&rx_ring->xdp_rxq))
> +		xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
> +	res = xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev,
> +			       rx_ring->queue_index, 0);
> +	if (res < 0) {
> +		netdev_err(rx_ring->netdev,
> +			   "Failed to register xdp_rxq index %u\n",
> +			   rx_ring->queue_index);
nit: would be nice to have the same printing functions like dev_err()
in the error case

> +		return res;
> +	}
>   
>   	return 0;
>
Corinna Vinschen Jan. 14, 2022, 4:51 p.m. UTC | #2
On Jan 14 17:13, Denis Kirjanov wrote:
> 1/14/22 14:43, Corinna Vinschen пишет:
> > On changing the RX ring parameters igb uses a hack to avoid a warning
> > when calling xdp_rxq_info_reg via igb_setup_rx_resources.  It just
> > clears the struct xdp_rxq_info content.
> > 
> > Change this to unregister if we're already registered instead.  ALign
> > code to the igc code.
> > 
> > Fixes: 9cbc948b5a20c ("igb: add XDP support")
> > Signed-off-by: Corinna Vinschen <vinschen@redhat.com>
> > ---
> >   drivers/net/ethernet/intel/igb/igb_ethtool.c |  4 ----
> >   drivers/net/ethernet/intel/igb/igb_main.c    | 15 +++++++++++----
> >   2 files changed, 11 insertions(+), 8 deletions(-)
> > [...]
> > +	if (res < 0) {
> > +		netdev_err(rx_ring->netdev,
> > +			   "Failed to register xdp_rxq index %u\n",
> > +			   rx_ring->queue_index);
> nit: would be nice to have the same printing functions like dev_err()
> in the error case

Thanks, I pushed a v3.


Corinna
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index 51a2dcaf553d..2a5782063f4c 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -965,10 +965,6 @@  static int igb_set_ringparam(struct net_device *netdev,
 			memcpy(&temp_ring[i], adapter->rx_ring[i],
 			       sizeof(struct igb_ring));
 
-			/* Clear copied XDP RX-queue info */
-			memset(&temp_ring[i].xdp_rxq, 0,
-			       sizeof(temp_ring[i].xdp_rxq));
-
 			temp_ring[i].count = new_rx_count;
 			err = igb_setup_rx_resources(&temp_ring[i]);
 			if (err) {
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 38ba92022cd4..9638cb9c6014 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -4352,7 +4352,7 @@  int igb_setup_rx_resources(struct igb_ring *rx_ring)
 {
 	struct igb_adapter *adapter = netdev_priv(rx_ring->netdev);
 	struct device *dev = rx_ring->dev;
-	int size;
+	int size, res;
 
 	size = sizeof(struct igb_rx_buffer) * rx_ring->count;
 
@@ -4376,9 +4376,16 @@  int igb_setup_rx_resources(struct igb_ring *rx_ring)
 	rx_ring->xdp_prog = adapter->xdp_prog;
 
 	/* XDP RX-queue info */
-	if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev,
-			     rx_ring->queue_index, 0) < 0)
-		goto err;
+	if (xdp_rxq_info_is_reg(&rx_ring->xdp_rxq))
+		xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
+	res = xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev,
+			       rx_ring->queue_index, 0);
+	if (res < 0) {
+		netdev_err(rx_ring->netdev,
+			   "Failed to register xdp_rxq index %u\n",
+			   rx_ring->queue_index);
+		return res;
+	}
 
 	return 0;