1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 25 Jul 2020 20:53:23 +0200
3 Subject: [PATCH] mac80211: add a function for running rx without passing skbs
6 This can be used to run mac80211 rx processing on a batch of frames in NAPI
7 poll before passing them to the network stack in a large batch.
8 This can improve icache footprint, or it can be used to pass frames via
9 netif_receive_skb_list.
11 Signed-off-by: Felix Fietkau <nbd@nbd.name>
14 --- a/include/net/mac80211.h
15 +++ b/include/net/mac80211.h
16 @@ -4358,6 +4358,31 @@ void ieee80211_free_hw(struct ieee80211_
17 void ieee80211_restart_hw(struct ieee80211_hw *hw);
20 + * ieee80211_rx_list - receive frame and store processed skbs in a list
22 + * Use this function to hand received frames to mac80211. The receive
23 + * buffer in @skb must start with an IEEE 802.11 header. In case of a
24 + * paged @skb is used, the driver is recommended to put the ieee80211
25 + * header of the frame on the linear part of the @skb to avoid memory
26 + * allocation and/or memcpy by the stack.
28 + * This function may not be called in IRQ context. Calls to this function
29 + * for a single hardware must be synchronized against each other. Calls to
30 + * this function, ieee80211_rx_ni() and ieee80211_rx_irqsafe() may not be
31 + * mixed for a single hardware. Must not run concurrently with
32 + * ieee80211_tx_status() or ieee80211_tx_status_ni().
34 + * This function must be called with BHs disabled and RCU read lock
36 + * @hw: the hardware this frame came in on
37 + * @sta: the station the frame was received from, or %NULL
38 + * @skb: the buffer to receive, owned by mac80211 after this call
39 + * @list: the destination list
41 +void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
42 + struct sk_buff *skb, struct list_head *list);
45 * ieee80211_rx_napi - receive frame from NAPI context
47 * Use this function to hand received frames to mac80211. The receive
48 --- a/net/mac80211/ieee80211_i.h
49 +++ b/net/mac80211/ieee80211_i.h
50 @@ -218,7 +218,7 @@ enum ieee80211_rx_flags {
53 struct ieee80211_rx_data {
54 - struct napi_struct *napi;
55 + struct list_head *list;
57 struct ieee80211_local *local;
58 struct ieee80211_sub_if_data *sdata;
59 --- a/net/mac80211/rx.c
60 +++ b/net/mac80211/rx.c
61 @@ -2552,8 +2552,8 @@ static void ieee80211_deliver_skb_to_loc
62 memset(skb->cb, 0, sizeof(skb->cb));
64 /* deliver to local stack */
66 - napi_gro_receive(rx->napi, skb);
68 + list_add_tail(&skb->list, rx->list);
70 netif_receive_skb(skb);
72 @@ -3843,7 +3843,6 @@ void ieee80211_release_reorder_timeout(s
73 /* This is OK -- must be QoS data frame */
76 - .napi = NULL, /* must be NULL to not have races */
78 struct tid_ampdu_rx *tid_agg_rx;
80 @@ -4453,8 +4452,8 @@ static bool ieee80211_invoke_fast_rx(str
81 /* deliver to local stack */
82 skb->protocol = eth_type_trans(skb, fast_rx->dev);
83 memset(skb->cb, 0, sizeof(skb->cb));
85 - napi_gro_receive(rx->napi, skb);
87 + list_add_tail(&skb->list, rx->list);
89 netif_receive_skb(skb);
91 @@ -4521,7 +4520,7 @@ static bool ieee80211_prepare_and_rx_han
92 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
93 struct ieee80211_sta *pubsta,
95 - struct napi_struct *napi)
96 + struct list_head *list)
98 struct ieee80211_local *local = hw_to_local(hw);
99 struct ieee80211_sub_if_data *sdata;
100 @@ -4536,7 +4535,7 @@ static void __ieee80211_rx_handle_packet
101 memset(&rx, 0, sizeof(rx));
107 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
108 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
109 @@ -4644,8 +4643,8 @@ static void __ieee80211_rx_handle_packet
110 * This is the receive path handler. It is called by a low level driver when an
111 * 802.11 MPDU is received from the hardware.
113 -void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
114 - struct sk_buff *skb, struct napi_struct *napi)
115 +void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
116 + struct sk_buff *skb, struct list_head *list)
118 struct ieee80211_local *local = hw_to_local(hw);
119 struct ieee80211_rate *rate = NULL;
120 @@ -4737,36 +4736,53 @@ void ieee80211_rx_napi(struct ieee80211_
121 status->rx_flags = 0;
124 - * key references and virtual interfaces are protected using RCU
125 - * and this requires that we are in a read-side RCU section during
126 - * receive processing
131 * Frames with failed FCS/PLCP checksum are not returned,
132 * all other frames are returned without radiotap header
133 * if it was previously present.
134 * Also, frames with less than 16 bytes are dropped.
136 skb = ieee80211_rx_monitor(local, skb, rate);
143 ieee80211_tpt_led_trig_rx(local,
144 ((struct ieee80211_hdr *)skb->data)->frame_control,
147 - __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
150 + __ieee80211_rx_handle_packet(hw, pubsta, skb, list);
156 +EXPORT_SYMBOL(ieee80211_rx_list);
158 +void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
159 + struct sk_buff *skb, struct napi_struct *napi)
161 + struct sk_buff *tmp;
166 + * key references and virtual interfaces are protected using RCU
167 + * and this requires that we are in a read-side RCU section during
168 + * receive processing
171 + ieee80211_rx_list(hw, pubsta, skb, &list);
175 + netif_receive_skb_list(&list);
179 + list_for_each_entry_safe(skb, tmp, &list, list) {
180 + skb_list_del_init(skb);
181 + napi_gro_receive(napi, skb);
184 EXPORT_SYMBOL(ieee80211_rx_napi);
186 /* This is a version of the rx handler that can be called from hard irq