Introduce napi_init_for_gro utility routine to initialize napi struct subfields not dependent by net_device pointer. This is a preliminary patch to enable GRO support to cpumap codebase without introducing net_device dependency in the cpumap_entry struct. Signed-off-by: Lorenzo Bianconi <lorenzo@xxxxxxxxxx> --- include/linux/netdevice.h | 2 ++ net/core/dev.c | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index ecc686409161ea8684926434a9dcb233e065dd6c..9f083314fc4bc97059b02c6ee6d919bedb4e046d 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2677,6 +2677,8 @@ static inline void netif_napi_set_irq(struct napi_struct *napi, int irq) */ #define NAPI_POLL_WEIGHT 64 +int napi_init_for_gro(struct net_device *dev, struct napi_struct *napi, + int (*poll)(struct napi_struct *, int), int weight); void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight); diff --git a/net/core/dev.c b/net/core/dev.c index 13d00fc10f55998077cb643a2f6e3c171974589d..20d531a54214e9ecf1128a668cf3763433e1989b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6723,13 +6723,14 @@ static void napi_save_config(struct napi_struct *n) napi_hash_del(n); } -void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, - int (*poll)(struct napi_struct *, int), int weight) +int napi_init_for_gro(struct net_device *dev, struct napi_struct *napi, + int (*poll)(struct napi_struct *, int), int weight) { if (WARN_ON(test_and_set_bit(NAPI_STATE_LISTED, &napi->state))) - return; + return -EBUSY; INIT_LIST_HEAD(&napi->poll_list); + INIT_LIST_HEAD(&napi->dev_list); INIT_HLIST_NODE(&napi->napi_hash_node); hrtimer_init(&napi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); napi->timer.function = napi_watchdog; @@ -6747,6 +6748,16 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, napi->poll_owner = -1; #endif napi->list_owner = -1; + + return 0; +} + +void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, + int (*poll)(struct napi_struct *, int), int weight) +{ + if (napi_init_for_gro(dev, napi, poll, weight)) + return; + set_bit(NAPI_STATE_SCHED, &napi->state); set_bit(NAPI_STATE_NPSVC, &napi->state); list_add_rcu(&napi->dev_list, &dev->napi_list); -- 2.47.0