76869830ce2a3117be5c7bebb64a89487aa5ac8b
[openwrt/staging/jogo.git] /
1 From: Alexander Wetzel <alexander@wetzel-home.de>
2 Date: Sun, 9 Oct 2022 18:30:38 +0200
3 Subject: [PATCH] wifi: mac80211: add internal handler for wake_tx_queue
4
5 Start to align the TX handling to only use internal TX queues (iTXQs):
6
7 Provide a handler for drivers not having a custom wake_tx_queue
8 callback and update the documentation.
9
10 Signed-off-by: Alexander Wetzel <alexander@wetzel-home.de>
11 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
12 ---
13
14 --- a/include/net/mac80211.h
15 +++ b/include/net/mac80211.h
16 @@ -89,15 +89,13 @@
17 /**
18 * DOC: mac80211 software tx queueing
19 *
20 - * mac80211 provides an optional intermediate queueing implementation designed
21 - * to allow the driver to keep hardware queues short and provide some fairness
22 - * between different stations/interfaces.
23 - * In this model, the driver pulls data frames from the mac80211 queue instead
24 - * of letting mac80211 push them via drv_tx().
25 - * Other frames (e.g. control or management) are still pushed using drv_tx().
26 + * mac80211 uses an intermediate queueing implementation, designed to allow the
27 + * driver to keep hardware queues short and to provide some fairness between
28 + * different stations/interfaces.
29 *
30 - * Drivers indicate that they use this model by implementing the .wake_tx_queue
31 - * driver operation.
32 + * Drivers must provide the .wake_tx_queue driver operation by either
33 + * linking it to ieee80211_handle_wake_tx_queue() or implementing a custom
34 + * handler.
35 *
36 * Intermediate queues (struct ieee80211_txq) are kept per-sta per-tid, with
37 * another per-sta for non-data/non-mgmt and bufferable management frames, and
38 @@ -106,9 +104,12 @@
39 * The driver is expected to initialize its private per-queue data for stations
40 * and interfaces in the .add_interface and .sta_add ops.
41 *
42 - * The driver can't access the queue directly. To dequeue a frame from a
43 - * txq, it calls ieee80211_tx_dequeue(). Whenever mac80211 adds a new frame to a
44 - * queue, it calls the .wake_tx_queue driver op.
45 + * The driver can't access the internal TX queues (iTXQs) directly.
46 + * Whenever mac80211 adds a new frame to a queue, it calls the .wake_tx_queue
47 + * driver op.
48 + * Drivers implementing a custom .wake_tx_queue op can get them by calling
49 + * ieee80211_tx_dequeue(). Drivers using ieee80211_handle_wake_tx_queue() will
50 + * simply get the individual frames pushed via the .tx driver operation.
51 *
52 * Drivers can optionally delegate responsibility for scheduling queues to
53 * mac80211, to take advantage of airtime fairness accounting. In this case, to
54 @@ -1826,7 +1827,7 @@ struct ieee80211_vif_cfg {
55 * for this interface.
56 * @drv_priv: data area for driver use, will always be aligned to
57 * sizeof(void \*).
58 - * @txq: the multicast data TX queue (if driver uses the TXQ abstraction)
59 + * @txq: the multicast data TX queue
60 * @txqs_stopped: per AC flag to indicate that intermediate TXQs are stopped,
61 * protected by fq->lock.
62 * @offload_flags: 802.3 -> 802.11 enapsulation offload flags, see
63 @@ -2252,8 +2253,8 @@ struct ieee80211_link_sta {
64 * For non MLO STA it will point to the deflink data. For MLO STA
65 * ieee80211_sta_recalc_aggregates() must be called to update it.
66 * @support_p2p_ps: indicates whether the STA supports P2P PS mechanism or not.
67 - * @txq: per-TID data TX queues (if driver uses the TXQ abstraction); note that
68 - * the last entry (%IEEE80211_NUM_TIDS) is used for non-data frames
69 + * @txq: per-TID data TX queues; note that the last entry (%IEEE80211_NUM_TIDS)
70 + * is used for non-data frames
71 * @deflink: This holds the default link STA information, for non MLO STA all link
72 * specific STA information is accessed through @deflink or through
73 * link[0] which points to address of @deflink. For MLO Link STA
74 @@ -5691,7 +5692,7 @@ void ieee80211_key_replay(struct ieee802
75 * @hw: pointer as obtained from ieee80211_alloc_hw().
76 * @queue: queue number (counted from zero).
77 *
78 - * Drivers should use this function instead of netif_wake_queue.
79 + * Drivers must use this function instead of netif_wake_queue.
80 */
81 void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue);
82
83 @@ -5700,7 +5701,7 @@ void ieee80211_wake_queue(struct ieee802
84 * @hw: pointer as obtained from ieee80211_alloc_hw().
85 * @queue: queue number (counted from zero).
86 *
87 - * Drivers should use this function instead of netif_stop_queue.
88 + * Drivers must use this function instead of netif_stop_queue.
89 */
90 void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue);
91
92 @@ -5709,7 +5710,7 @@ void ieee80211_stop_queue(struct ieee802
93 * @hw: pointer as obtained from ieee80211_alloc_hw().
94 * @queue: queue number (counted from zero).
95 *
96 - * Drivers should use this function instead of netif_stop_queue.
97 + * Drivers must use this function instead of netif_queue_stopped.
98 *
99 * Return: %true if the queue is stopped. %false otherwise.
100 */
101 @@ -5720,7 +5721,7 @@ int ieee80211_queue_stopped(struct ieee8
102 * ieee80211_stop_queues - stop all queues
103 * @hw: pointer as obtained from ieee80211_alloc_hw().
104 *
105 - * Drivers should use this function instead of netif_stop_queue.
106 + * Drivers must use this function instead of netif_tx_stop_all_queues.
107 */
108 void ieee80211_stop_queues(struct ieee80211_hw *hw);
109
110 @@ -5728,7 +5729,7 @@ void ieee80211_stop_queues(struct ieee80
111 * ieee80211_wake_queues - wake all queues
112 * @hw: pointer as obtained from ieee80211_alloc_hw().
113 *
114 - * Drivers should use this function instead of netif_wake_queue.
115 + * Drivers must use this function instead of netif_tx_wake_all_queues.
116 */
117 void ieee80211_wake_queues(struct ieee80211_hw *hw);
118
119 @@ -6950,6 +6951,18 @@ static inline struct sk_buff *ieee80211_
120 }
121
122 /**
123 + * ieee80211_handle_wake_tx_queue - mac80211 handler for wake_tx_queue callback
124 + *
125 + * @hw: pointer as obtained from wake_tx_queue() callback().
126 + * @txq: pointer as obtained from wake_tx_queue() callback().
127 + *
128 + * Drivers can use this function for the mandatory mac80211 wake_tx_queue
129 + * callback in struct ieee80211_ops. They should not call this function.
130 + */
131 +void ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw,
132 + struct ieee80211_txq *txq);
133 +
134 +/**
135 * ieee80211_next_txq - get next tx queue to pull packets from
136 *
137 * @hw: pointer as obtained from ieee80211_alloc_hw()
138 --- a/net/mac80211/util.c
139 +++ b/net/mac80211/util.c
140 @@ -288,6 +288,52 @@ __le16 ieee80211_ctstoself_duration(stru
141 }
142 EXPORT_SYMBOL(ieee80211_ctstoself_duration);
143
144 +static void wake_tx_push_queue(struct ieee80211_local *local,
145 + struct ieee80211_sub_if_data *sdata,
146 + struct ieee80211_txq *queue)
147 +{
148 + int q = sdata->vif.hw_queue[queue->ac];
149 + struct ieee80211_tx_control control = {
150 + .sta = queue->sta,
151 + };
152 + struct sk_buff *skb;
153 + unsigned long flags;
154 + bool q_stopped;
155 +
156 + while (1) {
157 + spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
158 + q_stopped = local->queue_stop_reasons[q];
159 + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
160 +
161 + if (q_stopped)
162 + break;
163 +
164 + skb = ieee80211_tx_dequeue(&local->hw, queue);
165 + if (!skb)
166 + break;
167 +
168 + drv_tx(local, &control, skb);
169 + }
170 +}
171 +
172 +/* wake_tx_queue handler for driver not implementing a custom one*/
173 +void ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw,
174 + struct ieee80211_txq *txq)
175 +{
176 + struct ieee80211_local *local = hw_to_local(hw);
177 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->vif);
178 + struct ieee80211_txq *queue;
179 +
180 + /* Use ieee80211_next_txq() for airtime fairness accounting */
181 + ieee80211_txq_schedule_start(hw, txq->ac);
182 + while ((queue = ieee80211_next_txq(hw, txq->ac))) {
183 + wake_tx_push_queue(local, sdata, queue);
184 + ieee80211_return_txq(hw, queue, false);
185 + }
186 + ieee80211_txq_schedule_end(hw, txq->ac);
187 +}
188 +EXPORT_SYMBOL(ieee80211_handle_wake_tx_queue);
189 +
190 static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
191 {
192 struct ieee80211_local *local = sdata->local;