netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 2/2] net: txgbe: Support the FDIR rules assigned to VFs
       [not found] <20250520063900.37370-1-jiawenwu@trustnetic.com>
@ 2025-05-20  6:39 ` Jiawen Wu
  2025-05-20 16:51   ` Simon Horman
  0 siblings, 1 reply; 3+ messages in thread
From: Jiawen Wu @ 2025-05-20  6:39 UTC (permalink / raw)
  To: netdev, pabeni, kuba, edumazet, davem, andrew+netdev, mengyuanlou
  Cc: Jiawen Wu

When SR-IOV is enabled, the FDIR rule is supported to filter packets to
VFs. The action queue id is calculated as an absolute id.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 .../ethernet/wangxun/txgbe/txgbe_ethtool.c    | 11 +++++++--
 .../net/ethernet/wangxun/txgbe/txgbe_fdir.c   | 23 +++++++++++--------
 .../net/ethernet/wangxun/txgbe/txgbe_type.h   |  2 +-
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c
index 78999d484f18..23af099e0a90 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c
@@ -342,12 +342,19 @@ static int txgbe_add_ethtool_fdir_entry(struct txgbe *txgbe,
 		queue = TXGBE_RDB_FDIR_DROP_QUEUE;
 	} else {
 		u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
+		u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
 
-		if (ring >= wx->num_rx_queues)
+		if (!vf && ring >= wx->num_rx_queues)
+			return -EINVAL;
+		else if (vf && (vf > wx->num_vfs ||
+				ring >= wx->num_rx_queues_per_pool))
 			return -EINVAL;
 
 		/* Map the ring onto the absolute queue index */
-		queue = wx->rx_ring[ring]->reg_idx;
+		if (!vf)
+			queue = wx->rx_ring[ring]->reg_idx;
+		else
+			queue = ((vf - 1) * wx->num_rx_queues_per_pool) + ring;
 	}
 
 	/* Don't allow indexes to exist outside of available space */
diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
index ef50efbaec0f..d542c8a5a689 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
@@ -307,6 +307,7 @@ void txgbe_atr(struct wx_ring *ring, struct wx_tx_buffer *first, u8 ptype)
 int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
 {
 	u32 fdirm = 0, fdirtcpm = 0, flex = 0;
+	int i, j;
 
 	/* Program the relevant mask registers. If src/dst_port or src/dst_addr
 	 * are zero, then assume a full mask for that field.  Also assume that
@@ -352,15 +353,17 @@ int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
 	/* Now mask VM pool and destination IPv6 - bits 5 and 2 */
 	wr32(wx, TXGBE_RDB_FDIR_OTHER_MSK, fdirm);
 
-	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0));
-	flex &= ~TXGBE_RDB_FDIR_FLEX_CFG_FIELD0;
+	i = VMDQ_P(0) / 4;
+	j = VMDQ_P(0) % 4;
+	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i));
+	flex &= ~(TXGBE_RDB_FDIR_FLEX_CFG_FIELD0 << (j * 8));
 	flex |= (TXGBE_RDB_FDIR_FLEX_CFG_BASE_MAC |
-		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6));
+		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6)) << (j * 8);
 
 	switch ((__force u16)input_mask->formatted.flex_bytes & 0xFFFF) {
 	case 0x0000:
 		/* Mask Flex Bytes */
-		flex |= TXGBE_RDB_FDIR_FLEX_CFG_MSK;
+		flex |= TXGBE_RDB_FDIR_FLEX_CFG_MSK << (j * 8);
 		break;
 	case 0xFFFF:
 		break;
@@ -368,7 +371,7 @@ int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
 		wx_err(wx, "Error on flexible byte mask\n");
 		return -EINVAL;
 	}
-	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0), flex);
+	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i), flex);
 
 	/* store the TCP/UDP port masks, bit reversed from port layout */
 	fdirtcpm = ntohs(input_mask->formatted.dst_port);
@@ -516,14 +519,16 @@ static void txgbe_fdir_enable(struct wx *wx, u32 fdirctrl)
 static void txgbe_init_fdir_signature(struct wx *wx)
 {
 	u32 fdirctrl = TXGBE_FDIR_PBALLOC_64K;
+	int i = VMDQ_P(0) / 4;
+	int j = VMDQ_P(0) % 4;
 	u32 flex = 0;
 
-	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0));
-	flex &= ~TXGBE_RDB_FDIR_FLEX_CFG_FIELD0;
+	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i));
+	flex &= ~(TXGBE_RDB_FDIR_FLEX_CFG_FIELD0 << (j * 8));
 
 	flex |= (TXGBE_RDB_FDIR_FLEX_CFG_BASE_MAC |
-		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6));
-	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0), flex);
+		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6)) << (j * 8);
+	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i), flex);
 
 	/* Continue setup of fdirctrl register bits:
 	 *  Move the flexible bytes to use the ethertype - shift 6 words
diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
index 261a83308568..094d55cdb86c 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
@@ -272,7 +272,7 @@ struct txgbe_fdir_filter {
 	struct hlist_node fdir_node;
 	union txgbe_atr_input filter;
 	u16 sw_idx;
-	u16 action;
+	u64 action;
 };
 
 /* TX/RX descriptor defines */
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next 2/2] net: txgbe: Support the FDIR rules assigned to VFs
  2025-05-20  6:39 ` [PATCH net-next 2/2] net: txgbe: Support the FDIR rules assigned to VFs Jiawen Wu
@ 2025-05-20 16:51   ` Simon Horman
  2025-05-22  9:37     ` Jiawen Wu
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2025-05-20 16:51 UTC (permalink / raw)
  To: Jiawen Wu
  Cc: netdev, pabeni, kuba, edumazet, davem, andrew+netdev, mengyuanlou

On Tue, May 20, 2025 at 02:39:00PM +0800, Jiawen Wu wrote:
> When SR-IOV is enabled, the FDIR rule is supported to filter packets to
> VFs. The action queue id is calculated as an absolute id.
> 
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> ---
>  .../ethernet/wangxun/txgbe/txgbe_ethtool.c    | 11 +++++++--
>  .../net/ethernet/wangxun/txgbe/txgbe_fdir.c   | 23 +++++++++++--------
>  .../net/ethernet/wangxun/txgbe/txgbe_type.h   |  2 +-
>  3 files changed, 24 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c
> index 78999d484f18..23af099e0a90 100644
> --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c
> +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c
> @@ -342,12 +342,19 @@ static int txgbe_add_ethtool_fdir_entry(struct txgbe *txgbe,
>  		queue = TXGBE_RDB_FDIR_DROP_QUEUE;
>  	} else {
>  		u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
> +		u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
>  
> -		if (ring >= wx->num_rx_queues)
> +		if (!vf && ring >= wx->num_rx_queues)
> +			return -EINVAL;
> +		else if (vf && (vf > wx->num_vfs ||
> +				ring >= wx->num_rx_queues_per_pool))
>  			return -EINVAL;
>  
>  		/* Map the ring onto the absolute queue index */
> -		queue = wx->rx_ring[ring]->reg_idx;
> +		if (!vf)
> +			queue = wx->rx_ring[ring]->reg_idx;
> +		else
> +			queue = ((vf - 1) * wx->num_rx_queues_per_pool) + ring;
>  	}
>  
>  	/* Don't allow indexes to exist outside of available space */
> diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
> index ef50efbaec0f..d542c8a5a689 100644
> --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
> +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
> @@ -307,6 +307,7 @@ void txgbe_atr(struct wx_ring *ring, struct wx_tx_buffer *first, u8 ptype)
>  int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
>  {
>  	u32 fdirm = 0, fdirtcpm = 0, flex = 0;
> +	int i, j;

It would be nice to have more intuitive variable names than i and j,
which seem more appropriate as names for iterators.

>  
>  	/* Program the relevant mask registers. If src/dst_port or src/dst_addr
>  	 * are zero, then assume a full mask for that field.  Also assume that
> @@ -352,15 +353,17 @@ int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
>  	/* Now mask VM pool and destination IPv6 - bits 5 and 2 */
>  	wr32(wx, TXGBE_RDB_FDIR_OTHER_MSK, fdirm);
>  
> -	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0));
> -	flex &= ~TXGBE_RDB_FDIR_FLEX_CFG_FIELD0;
> +	i = VMDQ_P(0) / 4;
> +	j = VMDQ_P(0) % 4;
> +	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i));
> +	flex &= ~(TXGBE_RDB_FDIR_FLEX_CFG_FIELD0 << (j * 8));
>  	flex |= (TXGBE_RDB_FDIR_FLEX_CFG_BASE_MAC |
> -		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6));
> +		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6)) << (j * 8);
>  
>  	switch ((__force u16)input_mask->formatted.flex_bytes & 0xFFFF) {
>  	case 0x0000:
>  		/* Mask Flex Bytes */
> -		flex |= TXGBE_RDB_FDIR_FLEX_CFG_MSK;
> +		flex |= TXGBE_RDB_FDIR_FLEX_CFG_MSK << (j * 8);
>  		break;
>  	case 0xFFFF:
>  		break;
> @@ -368,7 +371,7 @@ int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
>  		wx_err(wx, "Error on flexible byte mask\n");
>  		return -EINVAL;
>  	}
> -	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0), flex);
> +	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i), flex);
>  
>  	/* store the TCP/UDP port masks, bit reversed from port layout */
>  	fdirtcpm = ntohs(input_mask->formatted.dst_port);
> @@ -516,14 +519,16 @@ static void txgbe_fdir_enable(struct wx *wx, u32 fdirctrl)
>  static void txgbe_init_fdir_signature(struct wx *wx)
>  {
>  	u32 fdirctrl = TXGBE_FDIR_PBALLOC_64K;
> +	int i = VMDQ_P(0) / 4;
> +	int j = VMDQ_P(0) % 4;

Ditto.

>  	u32 flex = 0;
>  
> -	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0));
> -	flex &= ~TXGBE_RDB_FDIR_FLEX_CFG_FIELD0;
> +	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i));
> +	flex &= ~(TXGBE_RDB_FDIR_FLEX_CFG_FIELD0 << (j * 8));
>  
>  	flex |= (TXGBE_RDB_FDIR_FLEX_CFG_BASE_MAC |
> -		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6));
> -	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0), flex);
> +		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6)) << (j * 8);
> +	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i), flex);
>  
>  	/* Continue setup of fdirctrl register bits:
>  	 *  Move the flexible bytes to use the ethertype - shift 6 words
> diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
> index 261a83308568..094d55cdb86c 100644
> --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
> +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
> @@ -272,7 +272,7 @@ struct txgbe_fdir_filter {
>  	struct hlist_node fdir_node;
>  	union txgbe_atr_input filter;
>  	u16 sw_idx;
> -	u16 action;
> +	u64 action;
>  };
>  
>  /* TX/RX descriptor defines */
> -- 
> 2.48.1
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH net-next 2/2] net: txgbe: Support the FDIR rules assigned to VFs
  2025-05-20 16:51   ` Simon Horman
@ 2025-05-22  9:37     ` Jiawen Wu
  0 siblings, 0 replies; 3+ messages in thread
From: Jiawen Wu @ 2025-05-22  9:37 UTC (permalink / raw)
  To: 'Simon Horman'
  Cc: netdev, pabeni, kuba, edumazet, davem, andrew+netdev, mengyuanlou

> > diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
> > index ef50efbaec0f..d542c8a5a689 100644
> > --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
> > +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_fdir.c
> > @@ -307,6 +307,7 @@ void txgbe_atr(struct wx_ring *ring, struct wx_tx_buffer *first, u8 ptype)
> >  int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
> >  {
> >  	u32 fdirm = 0, fdirtcpm = 0, flex = 0;
> > +	int i, j;
> 
> It would be nice to have more intuitive variable names than i and j,
> which seem more appropriate as names for iterators.

May not be a very intuitive variable name. It just defines the index and offset.
This code piece says, there are 16 registers to store flex information of 64 VMs.
And each register has 32 bits for 4 VMs. I can change to name it "index" and
"offset" if necessary. :)

> 
> >
> >  	/* Program the relevant mask registers. If src/dst_port or src/dst_addr
> >  	 * are zero, then assume a full mask for that field.  Also assume that
> > @@ -352,15 +353,17 @@ int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
> >  	/* Now mask VM pool and destination IPv6 - bits 5 and 2 */
> >  	wr32(wx, TXGBE_RDB_FDIR_OTHER_MSK, fdirm);
> >
> > -	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0));
> > -	flex &= ~TXGBE_RDB_FDIR_FLEX_CFG_FIELD0;
> > +	i = VMDQ_P(0) / 4;
> > +	j = VMDQ_P(0) % 4;
> > +	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i));
> > +	flex &= ~(TXGBE_RDB_FDIR_FLEX_CFG_FIELD0 << (j * 8));
> >  	flex |= (TXGBE_RDB_FDIR_FLEX_CFG_BASE_MAC |
> > -		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6));
> > +		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6)) << (j * 8);
> >
> >  	switch ((__force u16)input_mask->formatted.flex_bytes & 0xFFFF) {
> >  	case 0x0000:
> >  		/* Mask Flex Bytes */
> > -		flex |= TXGBE_RDB_FDIR_FLEX_CFG_MSK;
> > +		flex |= TXGBE_RDB_FDIR_FLEX_CFG_MSK << (j * 8);
> >  		break;
> >  	case 0xFFFF:
> >  		break;
> > @@ -368,7 +371,7 @@ int txgbe_fdir_set_input_mask(struct wx *wx, union txgbe_atr_input *input_mask)
> >  		wx_err(wx, "Error on flexible byte mask\n");
> >  		return -EINVAL;
> >  	}
> > -	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0), flex);
> > +	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i), flex);
> >
> >  	/* store the TCP/UDP port masks, bit reversed from port layout */
> >  	fdirtcpm = ntohs(input_mask->formatted.dst_port);
> > @@ -516,14 +519,16 @@ static void txgbe_fdir_enable(struct wx *wx, u32 fdirctrl)
> >  static void txgbe_init_fdir_signature(struct wx *wx)
> >  {
> >  	u32 fdirctrl = TXGBE_FDIR_PBALLOC_64K;
> > +	int i = VMDQ_P(0) / 4;
> > +	int j = VMDQ_P(0) % 4;
> 
> Ditto.
> 
> >  	u32 flex = 0;
> >
> > -	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0));
> > -	flex &= ~TXGBE_RDB_FDIR_FLEX_CFG_FIELD0;
> > +	flex = rd32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i));
> > +	flex &= ~(TXGBE_RDB_FDIR_FLEX_CFG_FIELD0 << (j * 8));
> >
> >  	flex |= (TXGBE_RDB_FDIR_FLEX_CFG_BASE_MAC |
> > -		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6));
> > -	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(0), flex);
> > +		 TXGBE_RDB_FDIR_FLEX_CFG_OFST(0x6)) << (j * 8);
> > +	wr32(wx, TXGBE_RDB_FDIR_FLEX_CFG(i), flex);
> >
> >  	/* Continue setup of fdirctrl register bits:
> >  	 *  Move the flexible bytes to use the ethertype - shift 6 words
> > diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
> > index 261a83308568..094d55cdb86c 100644
> > --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
> > +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
> > @@ -272,7 +272,7 @@ struct txgbe_fdir_filter {
> >  	struct hlist_node fdir_node;
> >  	union txgbe_atr_input filter;
> >  	u16 sw_idx;
> > -	u16 action;
> > +	u64 action;
> >  };
> >
> >  /* TX/RX descriptor defines */
> > --
> > 2.48.1
> >
> >
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-22  9:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250520063900.37370-1-jiawenwu@trustnetic.com>
2025-05-20  6:39 ` [PATCH net-next 2/2] net: txgbe: Support the FDIR rules assigned to VFs Jiawen Wu
2025-05-20 16:51   ` Simon Horman
2025-05-22  9:37     ` Jiawen Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).