From: Amritha Nambiar <amritha.nambiar@intel.com> mainline inclusion from mainline-v6.8-rc1 commit 2a502ff0c4e42a739b5aa550c901bf3852795532 category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/10109 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- Add the napi pointer in netdev queue for tracking the napi instance for each queue. This achieves the queue<->napi mapping. Signed-off-by: Amritha Nambiar <amritha.nambiar@intel.com> Reviewed-by: Sridhar Samudrala <sridhar.samudrala@intel.com> Link: https://lore.kernel.org/r/170147331483.5260.15723438819994285695.stgit@anamb... Signed-off-by: Jakub Kicinski <kuba@kernel.org> Conflicts: include/net/netdev_rx_queue.h include/linux/netdevice.h [Conflicts are caused because the upstream hunk inserts a new pointer right before the struct's closing brace, but that exact position is already occupied by the OLK KABI reserve slots, so the hunk is rejected and must be merged by hand into a KABI_USE slot. Independently, it will not compile as-is because the new code references an enum type that is only introduced by a separate netdev-genl spec patch not present in the OLK-6.6 base, so that enum must be added manually.] Signed-off-by: JiangJieHua <jiangjiehua1@huawei.com> Reviewed-by: Zhang Changzhong <zhangchangzhong@huaiwei.com> --- include/linux/netdevice.h | 13 ++++++++++++ include/net/netdev_rx_queue.h | 5 +++++ net/core/dev.c | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 47a4e2cb9477..43cb840f0f2b 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -348,6 +348,11 @@ struct gro_list { int count; }; +enum netdev_queue_type { + NETDEV_QUEUE_TYPE_RX, + NETDEV_QUEUE_TYPE_TX, +}; + /* * size of gro hash buckets, must less than bit number of * napi_struct::gro_bitmask @@ -656,6 +661,10 @@ struct netdev_queue { #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif + /* NAPI instance for the queue + * Readers and writers must hold RTNL + */ + struct napi_struct *napi; /* * write-mostly part */ @@ -2673,6 +2682,10 @@ static inline void *netdev_priv(const struct net_device *dev) */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) +void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index, + enum netdev_queue_type type, + struct napi_struct *napi); + /* Default NAPI poll() weight * Device drivers are strongly advised to not use bigger value */ diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index 3fb5d8eb18fc..444e6b4e4f3c 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -22,6 +22,11 @@ struct netdev_rx_queue { struct xsk_buff_pool *pool; #endif + /* NAPI instance for the queue + * Readers and writers must hold RTNL + */ + struct napi_struct *napi; + KABI_USE(1, void *__rcu oecls_ftb) KABI_RESERVE(2) KABI_RESERVE(3) diff --git a/net/core/dev.c b/net/core/dev.c index 6a03b2cb5f05..a8b10001905c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6691,6 +6691,43 @@ int dev_set_threaded(struct net_device *dev, bool threaded) } EXPORT_SYMBOL(dev_set_threaded); +/** + * netif_queue_set_napi - Associate queue with the napi + * @dev: device to which NAPI and queue belong + * @queue_index: Index of queue + * @type: queue type as RX or TX + * @napi: NAPI context, pass NULL to clear previously set NAPI + * + * Set queue with its corresponding napi context. This should be done after + * registering the NAPI handler for the queue-vector and the queues have been + * mapped to the corresponding interrupt vector. + */ +void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index, + enum netdev_queue_type type, struct napi_struct *napi) +{ + struct netdev_rx_queue *rxq; + struct netdev_queue *txq; + + if (WARN_ON_ONCE(napi && !napi->dev)) + return; + if (dev->reg_state >= NETREG_REGISTERED) + ASSERT_RTNL(); + + switch (type) { + case NETDEV_QUEUE_TYPE_RX: + rxq = __netif_get_rx_queue(dev, queue_index); + rxq->napi = napi; + return; + case NETDEV_QUEUE_TYPE_TX: + txq = netdev_get_tx_queue(dev, queue_index); + txq->napi = napi; + return; + default: + return; + } +} +EXPORT_SYMBOL(netif_queue_set_napi); + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight) { -- 2.18.0.huawei.25