Commit | Line | Data |
---|---|---|
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 | ||
8 | struct gro_cell { | |
9 | struct sk_buff_head napi_skbs; | |
10 | struct napi_struct napi; | |
88340160 | 11 | }; |
c9e6bc64 ED |
12 | |
13 | struct gro_cells { | |
88340160 | 14 | struct gro_cell __percpu *cells; |
c9e6bc64 ED |
15 | }; |
16 | ||
5f652bb2 | 17 | static inline int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb) |
c9e6bc64 | 18 | { |
88340160 | 19 | struct gro_cell *cell; |
c9e6bc64 ED |
20 | struct net_device *dev = skb->dev; |
21 | ||
5f652bb2 PA |
22 | if (!gcells->cells || skb_cloned(skb) || !(dev->features & NETIF_F_GRO)) |
23 | return netif_rx(skb); | |
c9e6bc64 | 24 | |
88340160 | 25 | cell = this_cpu_ptr(gcells->cells); |
c9e6bc64 ED |
26 | |
27 | if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) { | |
28 | atomic_long_inc(&dev->rx_dropped); | |
29 | kfree_skb(skb); | |
5f652bb2 | 30 | return NET_RX_DROP; |
c9e6bc64 ED |
31 | } |
32 | ||
c9e6bc64 ED |
33 | __skb_queue_tail(&cell->napi_skbs, skb); |
34 | if (skb_queue_len(&cell->napi_skbs) == 1) | |
35 | napi_schedule(&cell->napi); | |
5f652bb2 | 36 | return NET_RX_SUCCESS; |
c9e6bc64 ED |
37 | } |
38 | ||
c42858ea | 39 | /* called under BH context */ |
c9e6bc64 ED |
40 | static inline int gro_cell_poll(struct napi_struct *napi, int budget) |
41 | { | |
42 | struct gro_cell *cell = container_of(napi, struct gro_cell, napi); | |
43 | struct sk_buff *skb; | |
44 | int work_done = 0; | |
45 | ||
46 | while (work_done < budget) { | |
f8e8f97c | 47 | skb = __skb_dequeue(&cell->napi_skbs); |
c9e6bc64 ED |
48 | if (!skb) |
49 | break; | |
c9e6bc64 ED |
50 | napi_gro_receive(napi, skb); |
51 | work_done++; | |
52 | } | |
53 | ||
54 | if (work_done < budget) | |
c42858ea | 55 | napi_complete_done(napi, work_done); |
c9e6bc64 ED |
56 | return work_done; |
57 | } | |
58 | ||
59 | static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *dev) | |
60 | { | |
61 | int i; | |
62 | ||
88340160 | 63 | gcells->cells = alloc_percpu(struct gro_cell); |
c9e6bc64 ED |
64 | if (!gcells->cells) |
65 | return -ENOMEM; | |
66 | ||
88340160 MKL |
67 | for_each_possible_cpu(i) { |
68 | struct gro_cell *cell = per_cpu_ptr(gcells->cells, i); | |
c9e6bc64 | 69 | |
c42858ea | 70 | __skb_queue_head_init(&cell->napi_skbs); |
c9e6bc64 ED |
71 | netif_napi_add(dev, &cell->napi, gro_cell_poll, 64); |
72 | napi_enable(&cell->napi); | |
73 | } | |
74 | return 0; | |
75 | } | |
76 | ||
77 | static inline void gro_cells_destroy(struct gro_cells *gcells) | |
78 | { | |
c9e6bc64 ED |
79 | int i; |
80 | ||
88340160 | 81 | if (!gcells->cells) |
c9e6bc64 | 82 | return; |
88340160 MKL |
83 | for_each_possible_cpu(i) { |
84 | struct gro_cell *cell = per_cpu_ptr(gcells->cells, i); | |
c42858ea | 85 | |
c9e6bc64 | 86 | netif_napi_del(&cell->napi); |
c42858ea | 87 | __skb_queue_purge(&cell->napi_skbs); |
c9e6bc64 | 88 | } |
88340160 | 89 | free_percpu(gcells->cells); |
c9e6bc64 ED |
90 | gcells->cells = NULL; |
91 | } | |
92 | ||
93 | #endif |