Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm...
[deliverable/linux.git] / include / net / gro_cells.h
CommitLineData
c9e6bc64
ED
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
8struct gro_cell {
9 struct sk_buff_head napi_skbs;
10 struct napi_struct napi;
88340160 11};
c9e6bc64
ED
12
13struct gro_cells {
88340160 14 struct gro_cell __percpu *cells;
c9e6bc64
ED
15};
16
17static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
18{
88340160 19 struct gro_cell *cell;
c9e6bc64
ED
20 struct net_device *dev = skb->dev;
21
88340160 22 if (!gcells->cells || skb_cloned(skb) || !(dev->features & NETIF_F_GRO)) {
c9e6bc64
ED
23 netif_rx(skb);
24 return;
25 }
26
88340160 27 cell = this_cpu_ptr(gcells->cells);
c9e6bc64
ED
28
29 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
30 atomic_long_inc(&dev->rx_dropped);
31 kfree_skb(skb);
32 return;
33 }
34
f8e8f97c
ED
35 /* We run in BH context */
36 spin_lock(&cell->napi_skbs.lock);
c9e6bc64
ED
37
38 __skb_queue_tail(&cell->napi_skbs, skb);
39 if (skb_queue_len(&cell->napi_skbs) == 1)
40 napi_schedule(&cell->napi);
41
f8e8f97c 42 spin_unlock(&cell->napi_skbs.lock);
c9e6bc64
ED
43}
44
f8e8f97c 45/* called unser BH context */
c9e6bc64
ED
46static inline int gro_cell_poll(struct napi_struct *napi, int budget)
47{
48 struct gro_cell *cell = container_of(napi, struct gro_cell, napi);
49 struct sk_buff *skb;
50 int work_done = 0;
51
f8e8f97c 52 spin_lock(&cell->napi_skbs.lock);
c9e6bc64 53 while (work_done < budget) {
f8e8f97c 54 skb = __skb_dequeue(&cell->napi_skbs);
c9e6bc64
ED
55 if (!skb)
56 break;
f8e8f97c 57 spin_unlock(&cell->napi_skbs.lock);
c9e6bc64
ED
58 napi_gro_receive(napi, skb);
59 work_done++;
f8e8f97c 60 spin_lock(&cell->napi_skbs.lock);
c9e6bc64
ED
61 }
62
63 if (work_done < budget)
64 napi_complete(napi);
f8e8f97c 65 spin_unlock(&cell->napi_skbs.lock);
c9e6bc64
ED
66 return work_done;
67}
68
69static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *dev)
70{
71 int i;
72
88340160 73 gcells->cells = alloc_percpu(struct gro_cell);
c9e6bc64
ED
74 if (!gcells->cells)
75 return -ENOMEM;
76
88340160
MKL
77 for_each_possible_cpu(i) {
78 struct gro_cell *cell = per_cpu_ptr(gcells->cells, i);
c9e6bc64
ED
79
80 skb_queue_head_init(&cell->napi_skbs);
81 netif_napi_add(dev, &cell->napi, gro_cell_poll, 64);
82 napi_enable(&cell->napi);
83 }
84 return 0;
85}
86
87static inline void gro_cells_destroy(struct gro_cells *gcells)
88{
c9e6bc64
ED
89 int i;
90
88340160 91 if (!gcells->cells)
c9e6bc64 92 return;
88340160
MKL
93 for_each_possible_cpu(i) {
94 struct gro_cell *cell = per_cpu_ptr(gcells->cells, i);
c9e6bc64
ED
95 netif_napi_del(&cell->napi);
96 skb_queue_purge(&cell->napi_skbs);
97 }
88340160 98 free_percpu(gcells->cells);
c9e6bc64
ED
99 gcells->cells = NULL;
100}
101
102#endif
This page took 0.162166 seconds and 5 git commands to generate.