1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/skbuff.h>
3 #include <linux/slab.h>
4 #include <linux/netdevice.h>
5 #include <net/gro_cells.h>
8 struct sk_buff_head napi_skbs;
9 struct napi_struct napi;
12 int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
14 struct net_device *dev = skb->dev;
15 struct gro_cell *cell;
19 if (unlikely(!(dev->flags & IFF_UP)))
22 if (!gcells->cells || skb_cloned(skb) || netif_elide_gro(dev)) {
27 cell = this_cpu_ptr(gcells->cells);
29 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
31 atomic_long_inc(&dev->rx_dropped);
37 __skb_queue_tail(&cell->napi_skbs, skb);
38 if (skb_queue_len(&cell->napi_skbs) == 1)
39 napi_schedule(&cell->napi);
47 EXPORT_SYMBOL(gro_cells_receive);
49 /* called under BH context */
50 static int gro_cell_poll(struct napi_struct *napi, int budget)
52 struct gro_cell *cell = container_of(napi, struct gro_cell, napi);
56 while (work_done < budget) {
57 skb = __skb_dequeue(&cell->napi_skbs);
60 napi_gro_receive(napi, skb);
64 if (work_done < budget)
65 napi_complete_done(napi, work_done);
69 int gro_cells_init(struct gro_cells *gcells, struct net_device *dev)
73 gcells->cells = alloc_percpu(struct gro_cell);
77 for_each_possible_cpu(i) {
78 struct gro_cell *cell = per_cpu_ptr(gcells->cells, i);
80 __skb_queue_head_init(&cell->napi_skbs);
82 set_bit(NAPI_STATE_NO_BUSY_POLL, &cell->napi.state);
84 netif_napi_add(dev, &cell->napi, gro_cell_poll,
86 napi_enable(&cell->napi);
90 EXPORT_SYMBOL(gro_cells_init);
92 void gro_cells_destroy(struct gro_cells *gcells)
98 for_each_possible_cpu(i) {
99 struct gro_cell *cell = per_cpu_ptr(gcells->cells, i);
101 napi_disable(&cell->napi);
102 __netif_napi_del(&cell->napi);
103 __skb_queue_purge(&cell->napi_skbs);
105 /* This barrier is needed because netpoll could access dev->napi_list
106 * under rcu protection.
110 free_percpu(gcells->cells);
111 gcells->cells = NULL;
113 EXPORT_SYMBOL(gro_cells_destroy);