OSDN Git Service

cfg80211: Support backport of removing ieee80211
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / net / gro_cells.h
1 #ifndef _NET_GRO_CELLS_H
2 #define _NET_GRO_CELLS_H
3
4 #include <linux/skbuff.h>
5 #include <linux/slab.h>
6 #include <linux/netdevice.h>
7
8 struct gro_cell {
9         struct sk_buff_head     napi_skbs;
10         struct napi_struct      napi;
11 };
12
13 struct gro_cells {
14         struct gro_cell __percpu        *cells;
15 };
16
17 static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
18 {
19         struct gro_cell *cell;
20         struct net_device *dev = skb->dev;
21
22         rcu_read_lock();
23         if (unlikely(!(dev->flags & IFF_UP)))
24                 goto drop;
25
26         if (!gcells->cells || skb_cloned(skb) || !(dev->features & NETIF_F_GRO)) {
27                 netif_rx(skb);
28                 goto unlock;
29         }
30
31         cell = this_cpu_ptr(gcells->cells);
32
33         if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
34 drop:
35                 atomic_long_inc(&dev->rx_dropped);
36                 kfree_skb(skb);
37                 goto unlock;
38         }
39
40         __skb_queue_tail(&cell->napi_skbs, skb);
41         if (skb_queue_len(&cell->napi_skbs) == 1)
42                 napi_schedule(&cell->napi);
43
44 unlock:
45         rcu_read_unlock();
46 }
47
48 /* called under BH context */
49 static inline int gro_cell_poll(struct napi_struct *napi, int budget)
50 {
51         struct gro_cell *cell = container_of(napi, struct gro_cell, napi);
52         struct sk_buff *skb;
53         int work_done = 0;
54
55         while (work_done < budget) {
56                 skb = __skb_dequeue(&cell->napi_skbs);
57                 if (!skb)
58                         break;
59                 napi_gro_receive(napi, skb);
60                 work_done++;
61         }
62
63         if (work_done < budget)
64                 napi_complete_done(napi, work_done);
65         return work_done;
66 }
67
68 static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *dev)
69 {
70         int i;
71
72         gcells->cells = alloc_percpu(struct gro_cell);
73         if (!gcells->cells)
74                 return -ENOMEM;
75
76         for_each_possible_cpu(i) {
77                 struct gro_cell *cell = per_cpu_ptr(gcells->cells, i);
78
79                 __skb_queue_head_init(&cell->napi_skbs);
80                 netif_napi_add(dev, &cell->napi, gro_cell_poll, 64);
81                 napi_enable(&cell->napi);
82         }
83         return 0;
84 }
85
86 static inline void gro_cells_destroy(struct gro_cells *gcells)
87 {
88         int i;
89
90         if (!gcells->cells)
91                 return;
92         for_each_possible_cpu(i) {
93                 struct gro_cell *cell = per_cpu_ptr(gcells->cells, i);
94
95                 napi_disable(&cell->napi);
96                 netif_napi_del(&cell->napi);
97                 __skb_queue_purge(&cell->napi_skbs);
98         }
99         free_percpu(gcells->cells);
100         gcells->cells = NULL;
101 }
102
103 #endif