diff mbox series

[net-next,v2,4/9] net: Move kernel helpers for queue index outside sysfs

Message ID 169266033119.10199.3382453499474113876.stgit@anambiarhost.jf.intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Introduce NAPI queues support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
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: 5466 this patch: 5466
netdev/cc_maintainers warning 4 maintainers not CCed: pabeni@redhat.com gregkh@linuxfoundation.org wangyufen@huawei.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 2249 this patch: 2249
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: 5706 this patch: 5706
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 50 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Nambiar, Amritha Aug. 21, 2023, 11:25 p.m. UTC
The kernel helpers for retrieving tx/rx queue index
(get_netdev_queue_index and get_netdev_rx_queue_index)
are restricted to sysfs, move this out for more usability.
Also, replace BUG_ON with DEBUG_NET_WARN_ON_ONCE.

Signed-off-by: Amritha Nambiar <amritha.nambiar@intel.com>
---
 include/linux/netdevice.h     |   12 ++++++++++++
 include/net/netdev_rx_queue.h |    4 +---
 net/core/net-sysfs.c          |   11 -----------
 3 files changed, 13 insertions(+), 14 deletions(-)

Comments

Jakub Kicinski Aug. 23, 2023, 12:40 a.m. UTC | #1
On Mon, 21 Aug 2023 16:25:31 -0700 Amritha Nambiar wrote:
> +static inline
> +unsigned int get_netdev_queue_index(struct netdev_queue *queue)
> +{
> +	struct net_device *dev = queue->dev;
> +	unsigned int i;
> +
> +	i = queue - dev->_tx;
> +	DEBUG_NET_WARN_ON_ONCE(i >= dev->num_tx_queues);
> +
> +	return i;
> +}

If this is needed let's move it to a new header -
include/net/netdev_tx_queue.h ?

>  static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
>  						    const struct sk_buff *skb)
>  {
> diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h
> index 66bda0dfe71c..ac58fa7c2532 100644
> --- a/include/net/netdev_rx_queue.h
> +++ b/include/net/netdev_rx_queue.h
Nambiar, Amritha Aug. 23, 2023, 11:57 p.m. UTC | #2
On 8/22/2023 5:40 PM, Jakub Kicinski wrote:
> On Mon, 21 Aug 2023 16:25:31 -0700 Amritha Nambiar wrote:
>> +static inline
>> +unsigned int get_netdev_queue_index(struct netdev_queue *queue)
>> +{
>> +	struct net_device *dev = queue->dev;
>> +	unsigned int i;
>> +
>> +	i = queue - dev->_tx;
>> +	DEBUG_NET_WARN_ON_ONCE(i >= dev->num_tx_queues);
>> +
>> +	return i;
>> +}
> 
> If this is needed let's move it to a new header -
> include/net/netdev_tx_queue.h ?
> 

Okay, I'll submit a separate patch to move struct netdev_queue out of 
netdevice.h to a new header before this.

>>   static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
>>   						    const struct sk_buff *skb)
>>   {
>> diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h
>> index 66bda0dfe71c..ac58fa7c2532 100644
>> --- a/include/net/netdev_rx_queue.h
>> +++ b/include/net/netdev_rx_queue.h
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 7645c0ba0995..4ec86d9aceb2 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2503,6 +2503,18 @@  struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
 	return &dev->_tx[index];
 }
 
+static inline
+unsigned int get_netdev_queue_index(struct netdev_queue *queue)
+{
+	struct net_device *dev = queue->dev;
+	unsigned int i;
+
+	i = queue - dev->_tx;
+	DEBUG_NET_WARN_ON_ONCE(i >= dev->num_tx_queues);
+
+	return i;
+}
+
 static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
 						    const struct sk_buff *skb)
 {
diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h
index 66bda0dfe71c..ac58fa7c2532 100644
--- a/include/net/netdev_rx_queue.h
+++ b/include/net/netdev_rx_queue.h
@@ -42,15 +42,13 @@  __netif_get_rx_queue(struct net_device *dev, unsigned int rxq)
 	return dev->_rx + rxq;
 }
 
-#ifdef CONFIG_SYSFS
 static inline unsigned int
 get_netdev_rx_queue_index(struct netdev_rx_queue *queue)
 {
 	struct net_device *dev = queue->dev;
 	int index = queue - dev->_rx;
 
-	BUG_ON(index >= dev->num_rx_queues);
+	DEBUG_NET_WARN_ON_ONCE(index >= dev->num_rx_queues);
 	return index;
 }
 #endif
-#endif
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index fccaa5bac0ed..858d50503e4f 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1240,17 +1240,6 @@  static ssize_t tx_timeout_show(struct netdev_queue *queue, char *buf)
 	return sysfs_emit(buf, fmt_ulong, trans_timeout);
 }
 
-static unsigned int get_netdev_queue_index(struct netdev_queue *queue)
-{
-	struct net_device *dev = queue->dev;
-	unsigned int i;
-
-	i = queue - dev->_tx;
-	BUG_ON(i >= dev->num_tx_queues);
-
-	return i;
-}
-
 static ssize_t traffic_class_show(struct netdev_queue *queue,
 				  char *buf)
 {