1 #ifndef _NET_GRO_CELLS_H
2 #define _NET_GRO_CELLS_H
4 #include <linux/skbuff.h>
5 #include <linux/slab.h>
6 #include <linux/netdevice.h>
9 struct sk_buff_head napi_skbs
;
10 struct napi_struct napi
;
14 struct gro_cell __percpu
*cells
;
17 static inline int gro_cells_receive(struct gro_cells
*gcells
, struct sk_buff
*skb
)
19 struct gro_cell
*cell
;
20 struct net_device
*dev
= skb
->dev
;
22 if (!gcells
->cells
|| skb_cloned(skb
) || !(dev
->features
& NETIF_F_GRO
))
25 cell
= this_cpu_ptr(gcells
->cells
);
27 if (skb_queue_len(&cell
->napi_skbs
) > netdev_max_backlog
) {
28 atomic_long_inc(&dev
->rx_dropped
);
33 __skb_queue_tail(&cell
->napi_skbs
, skb
);
34 if (skb_queue_len(&cell
->napi_skbs
) == 1)
35 napi_schedule(&cell
->napi
);
36 return NET_RX_SUCCESS
;
39 /* called under BH context */
40 static inline int gro_cell_poll(struct napi_struct
*napi
, int budget
)
42 struct gro_cell
*cell
= container_of(napi
, struct gro_cell
, napi
);
46 while (work_done
< budget
) {
47 skb
= __skb_dequeue(&cell
->napi_skbs
);
50 napi_gro_receive(napi
, skb
);
54 if (work_done
< budget
)
55 napi_complete_done(napi
, work_done
);
59 static inline int gro_cells_init(struct gro_cells
*gcells
, struct net_device
*dev
)
63 gcells
->cells
= alloc_percpu(struct gro_cell
);
67 for_each_possible_cpu(i
) {
68 struct gro_cell
*cell
= per_cpu_ptr(gcells
->cells
, i
);
70 __skb_queue_head_init(&cell
->napi_skbs
);
71 netif_napi_add(dev
, &cell
->napi
, gro_cell_poll
, 64);
72 napi_enable(&cell
->napi
);
77 static inline void gro_cells_destroy(struct gro_cells
*gcells
)
83 for_each_possible_cpu(i
) {
84 struct gro_cell
*cell
= per_cpu_ptr(gcells
->cells
, i
);
86 netif_napi_del(&cell
->napi
);
87 __skb_queue_purge(&cell
->napi_skbs
);
89 free_percpu(gcells
->cells
);