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
;
11 } ____cacheline_aligned_in_smp
;
14 unsigned int gro_cells_mask
;
15 struct gro_cell
*cells
;
18 static inline void gro_cells_receive(struct gro_cells
*gcells
, struct sk_buff
*skb
)
20 struct gro_cell
*cell
= gcells
->cells
;
21 struct net_device
*dev
= skb
->dev
;
23 if (!cell
|| skb_cloned(skb
) || !(dev
->features
& NETIF_F_GRO
)) {
28 if (skb_rx_queue_recorded(skb
))
29 cell
+= skb_get_rx_queue(skb
) & gcells
->gro_cells_mask
;
31 if (skb_queue_len(&cell
->napi_skbs
) > netdev_max_backlog
) {
32 atomic_long_inc(&dev
->rx_dropped
);
37 /* We run in BH context */
38 spin_lock(&cell
->napi_skbs
.lock
);
40 __skb_queue_tail(&cell
->napi_skbs
, skb
);
41 if (skb_queue_len(&cell
->napi_skbs
) == 1)
42 napi_schedule(&cell
->napi
);
44 spin_unlock(&cell
->napi_skbs
.lock
);
47 /* called unser BH context */
48 static inline int gro_cell_poll(struct napi_struct
*napi
, int budget
)
50 struct gro_cell
*cell
= container_of(napi
, struct gro_cell
, napi
);
54 spin_lock(&cell
->napi_skbs
.lock
);
55 while (work_done
< budget
) {
56 skb
= __skb_dequeue(&cell
->napi_skbs
);
59 spin_unlock(&cell
->napi_skbs
.lock
);
60 napi_gro_receive(napi
, skb
);
62 spin_lock(&cell
->napi_skbs
.lock
);
65 if (work_done
< budget
)
67 spin_unlock(&cell
->napi_skbs
.lock
);
71 static inline int gro_cells_init(struct gro_cells
*gcells
, struct net_device
*dev
)
75 gcells
->gro_cells_mask
= roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
76 gcells
->cells
= kcalloc(gcells
->gro_cells_mask
+ 1,
77 sizeof(struct gro_cell
),
82 for (i
= 0; i
<= gcells
->gro_cells_mask
; i
++) {
83 struct gro_cell
*cell
= gcells
->cells
+ i
;
85 skb_queue_head_init(&cell
->napi_skbs
);
86 netif_napi_add(dev
, &cell
->napi
, gro_cell_poll
, 64);
87 napi_enable(&cell
->napi
);
92 static inline void gro_cells_destroy(struct gro_cells
*gcells
)
94 struct gro_cell
*cell
= gcells
->cells
;
99 for (i
= 0; i
<= gcells
->gro_cells_mask
; i
++,cell
++) {
100 netif_napi_del(&cell
->napi
);
101 skb_queue_purge(&cell
->napi_skbs
);
103 kfree(gcells
->cells
);
104 gcells
->cells
= NULL
;