Blame view

include/net/gro_cells.h 2.02 KB
c9e6bc644   Eric Dumazet   net: add gro_cell...
1
2
3
4
5
6
7
8
9
10
  #ifndef _NET_GRO_CELLS_H
  #define _NET_GRO_CELLS_H
  
  #include <linux/skbuff.h>
  #include <linux/slab.h>
  #include <linux/netdevice.h>
  
  struct gro_cell {
  	struct sk_buff_head	napi_skbs;
  	struct napi_struct	napi;
88340160f   Martin KaFai Lau   ip_tunnel: Create...
11
  };
c9e6bc644   Eric Dumazet   net: add gro_cell...
12
13
  
  struct gro_cells {
88340160f   Martin KaFai Lau   ip_tunnel: Create...
14
  	struct gro_cell __percpu	*cells;
c9e6bc644   Eric Dumazet   net: add gro_cell...
15
  };
5f652bb2e   Paolo Abeni   gro_cells: gro_ce...
16
  static inline int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
c9e6bc644   Eric Dumazet   net: add gro_cell...
17
  {
88340160f   Martin KaFai Lau   ip_tunnel: Create...
18
  	struct gro_cell *cell;
c9e6bc644   Eric Dumazet   net: add gro_cell...
19
  	struct net_device *dev = skb->dev;
5f652bb2e   Paolo Abeni   gro_cells: gro_ce...
20
21
  	if (!gcells->cells || skb_cloned(skb) || !(dev->features & NETIF_F_GRO))
  		return netif_rx(skb);
c9e6bc644   Eric Dumazet   net: add gro_cell...
22

88340160f   Martin KaFai Lau   ip_tunnel: Create...
23
  	cell = this_cpu_ptr(gcells->cells);
c9e6bc644   Eric Dumazet   net: add gro_cell...
24
25
26
27
  
  	if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
  		atomic_long_inc(&dev->rx_dropped);
  		kfree_skb(skb);
5f652bb2e   Paolo Abeni   gro_cells: gro_ce...
28
  		return NET_RX_DROP;
c9e6bc644   Eric Dumazet   net: add gro_cell...
29
  	}
c9e6bc644   Eric Dumazet   net: add gro_cell...
30
31
32
  	__skb_queue_tail(&cell->napi_skbs, skb);
  	if (skb_queue_len(&cell->napi_skbs) == 1)
  		napi_schedule(&cell->napi);
5f652bb2e   Paolo Abeni   gro_cells: gro_ce...
33
  	return NET_RX_SUCCESS;
c9e6bc644   Eric Dumazet   net: add gro_cell...
34
  }
c42858eaf   Eric Dumazet   gro_cells: remove...
35
  /* called under BH context */
c9e6bc644   Eric Dumazet   net: add gro_cell...
36
37
38
39
40
41
42
  static inline int gro_cell_poll(struct napi_struct *napi, int budget)
  {
  	struct gro_cell *cell = container_of(napi, struct gro_cell, napi);
  	struct sk_buff *skb;
  	int work_done = 0;
  
  	while (work_done < budget) {
f8e8f97c1   Eric Dumazet   net: fix a race i...
43
  		skb = __skb_dequeue(&cell->napi_skbs);
c9e6bc644   Eric Dumazet   net: add gro_cell...
44
45
  		if (!skb)
  			break;
c9e6bc644   Eric Dumazet   net: add gro_cell...
46
47
48
49
50
  		napi_gro_receive(napi, skb);
  		work_done++;
  	}
  
  	if (work_done < budget)
c42858eaf   Eric Dumazet   gro_cells: remove...
51
  		napi_complete_done(napi, work_done);
c9e6bc644   Eric Dumazet   net: add gro_cell...
52
53
54
55
56
57
  	return work_done;
  }
  
  static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *dev)
  {
  	int i;
88340160f   Martin KaFai Lau   ip_tunnel: Create...
58
  	gcells->cells = alloc_percpu(struct gro_cell);
c9e6bc644   Eric Dumazet   net: add gro_cell...
59
60
  	if (!gcells->cells)
  		return -ENOMEM;
88340160f   Martin KaFai Lau   ip_tunnel: Create...
61
62
  	for_each_possible_cpu(i) {
  		struct gro_cell *cell = per_cpu_ptr(gcells->cells, i);
c9e6bc644   Eric Dumazet   net: add gro_cell...
63

c42858eaf   Eric Dumazet   gro_cells: remove...
64
  		__skb_queue_head_init(&cell->napi_skbs);
e88a27661   Eric Dumazet   gro_cells: mark n...
65
66
  
  		set_bit(NAPI_STATE_NO_BUSY_POLL, &cell->napi.state);
c9e6bc644   Eric Dumazet   net: add gro_cell...
67
68
69
70
71
72
73
74
  		netif_napi_add(dev, &cell->napi, gro_cell_poll, 64);
  		napi_enable(&cell->napi);
  	}
  	return 0;
  }
  
  static inline void gro_cells_destroy(struct gro_cells *gcells)
  {
c9e6bc644   Eric Dumazet   net: add gro_cell...
75
  	int i;
88340160f   Martin KaFai Lau   ip_tunnel: Create...
76
  	if (!gcells->cells)
c9e6bc644   Eric Dumazet   net: add gro_cell...
77
  		return;
88340160f   Martin KaFai Lau   ip_tunnel: Create...
78
79
  	for_each_possible_cpu(i) {
  		struct gro_cell *cell = per_cpu_ptr(gcells->cells, i);
c42858eaf   Eric Dumazet   gro_cells: remove...
80

c9e6bc644   Eric Dumazet   net: add gro_cell...
81
  		netif_napi_del(&cell->napi);
c42858eaf   Eric Dumazet   gro_cells: remove...
82
  		__skb_queue_purge(&cell->napi_skbs);
c9e6bc644   Eric Dumazet   net: add gro_cell...
83
  	}
88340160f   Martin KaFai Lau   ip_tunnel: Create...
84
  	free_percpu(gcells->cells);
c9e6bc644   Eric Dumazet   net: add gro_cell...
85
86
87
88
  	gcells->cells = NULL;
  }
  
  #endif