diff mbox series

[net-next,v2,3/3] net: txgbe: add FDIR info to ethtool ops

Message ID 20240605020852.24144-4-jiawenwu@trustnetic.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series add flow director for txgbe | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 901 this patch: 901
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 905 this patch: 905
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 905 this patch: 905
netdev/checkpatch warning WARNING: line length of 88 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 22 this patch: 22
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-06-06--03-00 (tests: 1041)

Commit Message

Jiawen Wu June 5, 2024, 2:08 a.m. UTC
Add flow director filter match and miss statistics to ethtool -S.
And change the number of queues when using flow director for ehtool -l.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 .../net/ethernet/wangxun/libwx/wx_ethtool.c   | 39 +++++++++++++++++--
 drivers/net/ethernet/wangxun/libwx/wx_hw.c    |  5 +++
 drivers/net/ethernet/wangxun/libwx/wx_type.h  |  4 ++
 3 files changed, 45 insertions(+), 3 deletions(-)

Comments

Hariprasad Kelam June 5, 2024, 7:33 a.m. UTC | #1
> Add flow director filter match and miss statistics to ethtool -S.
> And change the number of queues when using flow director for ehtool -l.
> 
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> ---
>  .../net/ethernet/wangxun/libwx/wx_ethtool.c   | 39 +++++++++++++++++--
>  drivers/net/ethernet/wangxun/libwx/wx_hw.c    |  5 +++
>  drivers/net/ethernet/wangxun/libwx/wx_type.h  |  4 ++
>  3 files changed, 45 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
> b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
> index cc3bec42ed8e..a6241091e95c 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
> @@ -43,6 +43,11 @@ static const struct wx_stats wx_gstrings_stats[] = {
>  	WX_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),  };
> 
> +static const struct wx_stats wx_gstrings_fdir_stats[] = {
> +	WX_STAT("fdir_match", stats.fdirmatch),
> +	WX_STAT("fdir_miss", stats.fdirmiss),
> +};
> +
>  /* drivers allocates num_tx_queues and num_rx_queues symmetrically so
>   * we set the num_rx_queues to evaluate to num_tx_queues. This is
>   * used because we do not have a good way to get the max number of @@ -
> 55,12 +60,17 @@ static const struct wx_stats wx_gstrings_stats[] = {
>  		(WX_NUM_TX_QUEUES + WX_NUM_RX_QUEUES) * \
>  		(sizeof(struct wx_queue_stats) / sizeof(u64)))  #define
> WX_GLOBAL_STATS_LEN  ARRAY_SIZE(wx_gstrings_stats)
> +#define WX_FDIR_STATS_LEN  ARRAY_SIZE(wx_gstrings_fdir_stats)
>  #define WX_STATS_LEN (WX_GLOBAL_STATS_LEN + WX_QUEUE_STATS_LEN)
> 
>  int wx_get_sset_count(struct net_device *netdev, int sset)  {
> +	struct wx *wx = netdev_priv(netdev);
> +
>  	switch (sset) {
>  	case ETH_SS_STATS:
> +		if (wx->mac.type == wx_mac_sp)
> +			return WX_STATS_LEN + WX_FDIR_STATS_LEN;
>  		return WX_STATS_LEN;

             Better way is to use ternary operator.
                 Return (wx->mac.type == wx_mac_sp) ? WX_STATS_LEN + WX_FDIR_STATS_LEN : WX_STATS_LEN;
>  	default:
>  		return -EOPNOTSUPP;
> @@ -70,6 +80,7 @@ EXPORT_SYMBOL(wx_get_sset_count);
> 
>  void wx_get_strings(struct net_device *netdev, u32 stringset, u8 *data)  {
> +	struct wx *wx = netdev_priv(netdev);
>  	u8 *p = data;
>  	int i;
> 
> @@ -77,6 +88,10 @@ void wx_get_strings(struct net_device *netdev, u32
> stringset, u8 *data)
>  	case ETH_SS_STATS:
>  		for (i = 0; i < WX_GLOBAL_STATS_LEN; i++)
>  			ethtool_puts(&p, wx_gstrings_stats[i].stat_string);
> +		if (wx->mac.type == wx_mac_sp) {
> +			for (i = 0; i < WX_FDIR_STATS_LEN; i++)
> +				ethtool_puts(&p,
> wx_gstrings_fdir_stats[i].stat_string);
> +		}
>  		for (i = 0; i < netdev->num_tx_queues; i++) {
>  			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
>  			ethtool_sprintf(&p, "tx_queue_%u_bytes", i); @@ -
> 96,7 +111,7 @@ void wx_get_ethtool_stats(struct net_device *netdev,
>  	struct wx *wx = netdev_priv(netdev);
>  	struct wx_ring *ring;
>  	unsigned int start;
> -	int i, j;
> +	int i, j, k;
>  	char *p;
> 
>  	wx_update_stats(wx);
> @@ -107,6 +122,14 @@ void wx_get_ethtool_stats(struct net_device
> *netdev,
>  			   sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
>  	}
> 
> +	if (wx->mac.type == wx_mac_sp) {
> +		for (k = 0; k < WX_FDIR_STATS_LEN; k++) {
> +			p = (char *)wx + wx_gstrings_fdir_stats[k].stat_offset;
> +			data[i++] = (wx_gstrings_fdir_stats[k].sizeof_stat ==
> +				   sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
          Since fdir_match/fdir_len are u64, do we need to check the size here?                           
Thanks,
Hariprasad k

> +		}
> +	}
> +
>  	for (j = 0; j < netdev->num_tx_queues; j++) {
>  		ring = wx->tx_ring[j];
>  		if (!ring) {
> @@ -172,17 +195,21 @@ EXPORT_SYMBOL(wx_get_pause_stats);
> 
>  void wx_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
> {
> +	unsigned int stats_len = WX_STATS_LEN;
>  	struct wx *wx = netdev_priv(netdev);
> 
> +	if (wx->mac.type == wx_mac_sp)
> +		stats_len += WX_FDIR_STATS_LEN;
> +
>  	strscpy(info->driver, wx->driver_name, sizeof(info->driver));
>  	strscpy(info->fw_version, wx->eeprom_id, sizeof(info->fw_version));
>  	strscpy(info->bus_info, pci_name(wx->pdev), sizeof(info->bus_info));
>  	if (wx->num_tx_queues <= WX_NUM_TX_QUEUES) {
> -		info->n_stats = WX_STATS_LEN -
> +		info->n_stats = stats_len -
>  				   (WX_NUM_TX_QUEUES - wx-
> >num_tx_queues) *
>  				   (sizeof(struct wx_queue_stats) / sizeof(u64))
> * 2;
>  	} else {
> -		info->n_stats = WX_STATS_LEN;
> +		info->n_stats = stats_len;
>  	}
>  }
>  EXPORT_SYMBOL(wx_get_drvinfo);
> @@ -383,6 +410,9 @@ void wx_get_channels(struct net_device *dev,
> 
>  	/* record RSS queues */
>  	ch->combined_count = wx->ring_feature[RING_F_RSS].indices;
> +
> +	if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))
> +		ch->combined_count = wx-
> >ring_feature[RING_F_FDIR].indices;
>  }
>  EXPORT_SYMBOL(wx_get_channels);
> 
> @@ -400,6 +430,9 @@ int wx_set_channels(struct net_device *dev,
>  	if (count > wx_max_channels(wx))
>  		return -EINVAL;
> 
> +	if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))
> +		wx->ring_feature[RING_F_FDIR].limit = count;
> +
>  	wx->ring_feature[RING_F_RSS].limit = count;
> 
>  	return 0;
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> index 8fb38f83a615..44cd7a5866c1 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> @@ -2352,6 +2352,11 @@ void wx_update_stats(struct wx *wx)
>  	hwstats->b2ogprc += rd32(wx, WX_RDM_BMC2OS_CNT);
>  	hwstats->rdmdrop += rd32(wx, WX_RDM_DRP_PKT);
> 
> +	if (wx->mac.type == wx_mac_sp) {
> +		hwstats->fdirmatch += rd32(wx, WX_RDB_FDIR_MATCH);
> +		hwstats->fdirmiss += rd32(wx, WX_RDB_FDIR_MISS);
> +	}
> +
>  	for (i = 0; i < wx->mac.max_rx_queues; i++)
>  		hwstats->qmprc += rd32(wx, WX_PX_MPRC(i));  } diff --git
> a/drivers/net/ethernet/wangxun/libwx/wx_type.h
> b/drivers/net/ethernet/wangxun/libwx/wx_type.h
> index b1f9bab06e90..e0b7866f96ec 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_type.h
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h
> @@ -157,6 +157,8 @@
>  #define WX_RDB_RA_CTL_RSS_IPV6_TCP   BIT(21)
>  #define WX_RDB_RA_CTL_RSS_IPV4_UDP   BIT(22)
>  #define WX_RDB_RA_CTL_RSS_IPV6_UDP   BIT(23)
> +#define WX_RDB_FDIR_MATCH            0x19558
> +#define WX_RDB_FDIR_MISS             0x1955C
> 
>  /******************************* PSR Registers
> *******************************/
>  /* psr control */
> @@ -1018,6 +1020,8 @@ struct wx_hw_stats {
>  	u64 crcerrs;
>  	u64 rlec;
>  	u64 qmprc;
> +	u64 fdirmatch;
> +	u64 fdirmiss;
>  };
> 
>  enum wx_state {
> --
> 2.27.0
>
Jakub Kicinski June 6, 2024, 12:52 a.m. UTC | #2
On Wed, 5 Jun 2024 07:33:32 +0000 Hariprasad Kelam wrote:
> > +		if (wx->mac.type == wx_mac_sp)
> > +			return WX_STATS_LEN + WX_FDIR_STATS_LEN;
> >  		return WX_STATS_LEN;  
> 
>              Better way is to use ternary operator.
>                  Return (wx->mac.type == wx_mac_sp) ? WX_STATS_LEN + WX_FDIR_STATS_LEN : WX_STATS_LEN;

I'd leave it be. We prefer lines to be shorter than 80 chars.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
index cc3bec42ed8e..a6241091e95c 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
@@ -43,6 +43,11 @@  static const struct wx_stats wx_gstrings_stats[] = {
 	WX_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
 };
 
+static const struct wx_stats wx_gstrings_fdir_stats[] = {
+	WX_STAT("fdir_match", stats.fdirmatch),
+	WX_STAT("fdir_miss", stats.fdirmiss),
+};
+
 /* drivers allocates num_tx_queues and num_rx_queues symmetrically so
  * we set the num_rx_queues to evaluate to num_tx_queues. This is
  * used because we do not have a good way to get the max number of
@@ -55,12 +60,17 @@  static const struct wx_stats wx_gstrings_stats[] = {
 		(WX_NUM_TX_QUEUES + WX_NUM_RX_QUEUES) * \
 		(sizeof(struct wx_queue_stats) / sizeof(u64)))
 #define WX_GLOBAL_STATS_LEN  ARRAY_SIZE(wx_gstrings_stats)
+#define WX_FDIR_STATS_LEN  ARRAY_SIZE(wx_gstrings_fdir_stats)
 #define WX_STATS_LEN (WX_GLOBAL_STATS_LEN + WX_QUEUE_STATS_LEN)
 
 int wx_get_sset_count(struct net_device *netdev, int sset)
 {
+	struct wx *wx = netdev_priv(netdev);
+
 	switch (sset) {
 	case ETH_SS_STATS:
+		if (wx->mac.type == wx_mac_sp)
+			return WX_STATS_LEN + WX_FDIR_STATS_LEN;
 		return WX_STATS_LEN;
 	default:
 		return -EOPNOTSUPP;
@@ -70,6 +80,7 @@  EXPORT_SYMBOL(wx_get_sset_count);
 
 void wx_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 {
+	struct wx *wx = netdev_priv(netdev);
 	u8 *p = data;
 	int i;
 
@@ -77,6 +88,10 @@  void wx_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 	case ETH_SS_STATS:
 		for (i = 0; i < WX_GLOBAL_STATS_LEN; i++)
 			ethtool_puts(&p, wx_gstrings_stats[i].stat_string);
+		if (wx->mac.type == wx_mac_sp) {
+			for (i = 0; i < WX_FDIR_STATS_LEN; i++)
+				ethtool_puts(&p, wx_gstrings_fdir_stats[i].stat_string);
+		}
 		for (i = 0; i < netdev->num_tx_queues; i++) {
 			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
 			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
@@ -96,7 +111,7 @@  void wx_get_ethtool_stats(struct net_device *netdev,
 	struct wx *wx = netdev_priv(netdev);
 	struct wx_ring *ring;
 	unsigned int start;
-	int i, j;
+	int i, j, k;
 	char *p;
 
 	wx_update_stats(wx);
@@ -107,6 +122,14 @@  void wx_get_ethtool_stats(struct net_device *netdev,
 			   sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
 	}
 
+	if (wx->mac.type == wx_mac_sp) {
+		for (k = 0; k < WX_FDIR_STATS_LEN; k++) {
+			p = (char *)wx + wx_gstrings_fdir_stats[k].stat_offset;
+			data[i++] = (wx_gstrings_fdir_stats[k].sizeof_stat ==
+				   sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
+		}
+	}
+
 	for (j = 0; j < netdev->num_tx_queues; j++) {
 		ring = wx->tx_ring[j];
 		if (!ring) {
@@ -172,17 +195,21 @@  EXPORT_SYMBOL(wx_get_pause_stats);
 
 void wx_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
 {
+	unsigned int stats_len = WX_STATS_LEN;
 	struct wx *wx = netdev_priv(netdev);
 
+	if (wx->mac.type == wx_mac_sp)
+		stats_len += WX_FDIR_STATS_LEN;
+
 	strscpy(info->driver, wx->driver_name, sizeof(info->driver));
 	strscpy(info->fw_version, wx->eeprom_id, sizeof(info->fw_version));
 	strscpy(info->bus_info, pci_name(wx->pdev), sizeof(info->bus_info));
 	if (wx->num_tx_queues <= WX_NUM_TX_QUEUES) {
-		info->n_stats = WX_STATS_LEN -
+		info->n_stats = stats_len -
 				   (WX_NUM_TX_QUEUES - wx->num_tx_queues) *
 				   (sizeof(struct wx_queue_stats) / sizeof(u64)) * 2;
 	} else {
-		info->n_stats = WX_STATS_LEN;
+		info->n_stats = stats_len;
 	}
 }
 EXPORT_SYMBOL(wx_get_drvinfo);
@@ -383,6 +410,9 @@  void wx_get_channels(struct net_device *dev,
 
 	/* record RSS queues */
 	ch->combined_count = wx->ring_feature[RING_F_RSS].indices;
+
+	if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))
+		ch->combined_count = wx->ring_feature[RING_F_FDIR].indices;
 }
 EXPORT_SYMBOL(wx_get_channels);
 
@@ -400,6 +430,9 @@  int wx_set_channels(struct net_device *dev,
 	if (count > wx_max_channels(wx))
 		return -EINVAL;
 
+	if (test_bit(WX_FLAG_FDIR_CAPABLE, wx->flags))
+		wx->ring_feature[RING_F_FDIR].limit = count;
+
 	wx->ring_feature[RING_F_RSS].limit = count;
 
 	return 0;
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
index 8fb38f83a615..44cd7a5866c1 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
@@ -2352,6 +2352,11 @@  void wx_update_stats(struct wx *wx)
 	hwstats->b2ogprc += rd32(wx, WX_RDM_BMC2OS_CNT);
 	hwstats->rdmdrop += rd32(wx, WX_RDM_DRP_PKT);
 
+	if (wx->mac.type == wx_mac_sp) {
+		hwstats->fdirmatch += rd32(wx, WX_RDB_FDIR_MATCH);
+		hwstats->fdirmiss += rd32(wx, WX_RDB_FDIR_MISS);
+	}
+
 	for (i = 0; i < wx->mac.max_rx_queues; i++)
 		hwstats->qmprc += rd32(wx, WX_PX_MPRC(i));
 }
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h
index b1f9bab06e90..e0b7866f96ec 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_type.h
+++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h
@@ -157,6 +157,8 @@ 
 #define WX_RDB_RA_CTL_RSS_IPV6_TCP   BIT(21)
 #define WX_RDB_RA_CTL_RSS_IPV4_UDP   BIT(22)
 #define WX_RDB_RA_CTL_RSS_IPV6_UDP   BIT(23)
+#define WX_RDB_FDIR_MATCH            0x19558
+#define WX_RDB_FDIR_MISS             0x1955C
 
 /******************************* PSR Registers *******************************/
 /* psr control */
@@ -1018,6 +1020,8 @@  struct wx_hw_stats {
 	u64 crcerrs;
 	u64 rlec;
 	u64 qmprc;
+	u64 fdirmatch;
+	u64 fdirmiss;
 };
 
 enum wx_state {