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
5 Start to align the TX handling to only use internal TX queues (iTXQs):
7 Provide a handler for drivers not having a custom wake_tx_queue
8 callback and update the documentation.
10 Signed-off-by: Alexander Wetzel <alexander@wetzel-home.de>
11 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
14 --- a/include/net/mac80211.h
15 +++ b/include/net/mac80211.h
18 * DOC: mac80211 software tx queueing
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.
30 - * Drivers indicate that they use this model by implementing the .wake_tx_queue
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
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
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.
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
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.
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 {
56 * @drv_priv: data area for driver use, will always be aligned to
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).
78 - * Drivers should use this function instead of netif_wake_queue.
79 + * Drivers must use this function instead of netif_wake_queue.
81 void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue);
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).
87 - * Drivers should use this function instead of netif_stop_queue.
88 + * Drivers must use this function instead of netif_stop_queue.
90 void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue);
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).
96 - * Drivers should use this function instead of netif_stop_queue.
97 + * Drivers must use this function instead of netif_queue_stopped.
99 * Return: %true if the queue is stopped. %false otherwise.
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().
105 - * Drivers should use this function instead of netif_stop_queue.
106 + * Drivers must use this function instead of netif_tx_stop_all_queues.
108 void ieee80211_stop_queues(struct ieee80211_hw *hw);
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().
114 - * Drivers should use this function instead of netif_wake_queue.
115 + * Drivers must use this function instead of netif_tx_wake_all_queues.
117 void ieee80211_wake_queues(struct ieee80211_hw *hw);
119 @@ -6950,6 +6951,18 @@ static inline struct sk_buff *ieee80211_
123 + * ieee80211_handle_wake_tx_queue - mac80211 handler for wake_tx_queue callback
125 + * @hw: pointer as obtained from wake_tx_queue() callback().
126 + * @txq: pointer as obtained from wake_tx_queue() callback().
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.
131 +void ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw,
132 + struct ieee80211_txq *txq);
135 * ieee80211_next_txq - get next tx queue to pull packets from
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
142 EXPORT_SYMBOL(ieee80211_ctstoself_duration);
144 +static void wake_tx_push_queue(struct ieee80211_local *local,
145 + struct ieee80211_sub_if_data *sdata,
146 + struct ieee80211_txq *queue)
148 + int q = sdata->vif.hw_queue[queue->ac];
149 + struct ieee80211_tx_control control = {
152 + struct sk_buff *skb;
153 + unsigned long flags;
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);
164 + skb = ieee80211_tx_dequeue(&local->hw, queue);
168 + drv_tx(local, &control, skb);
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)
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;
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);
186 + ieee80211_txq_schedule_end(hw, txq->ac);
188 +EXPORT_SYMBOL(ieee80211_handle_wake_tx_queue);
190 static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
192 struct ieee80211_local *local = sdata->local;