300-mac80211-add-stop-start-logic-for-software-TXQs.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. From: Manikanta Pubbisetty <mpubbise@codeaurora.org>
  2. Date: Wed, 11 Jul 2018 00:12:53 +0530
  3. Subject: [PATCH] mac80211: add stop/start logic for software TXQs
  4. Sometimes, it is required to stop the transmissions momentarily and
  5. resume it later; stopping the txqs becomes very critical in scenarios where
  6. the packet transmission has to be ceased completely. For example, during
  7. the hardware restart, during off channel operations,
  8. when initiating CSA(upon detecting a radar on the DFS channel), etc.
  9. The TX queue stop/start logic in mac80211 works well in stopping the TX
  10. when drivers make use of netdev queues, i.e, when Qdiscs in network layer
  11. take care of traffic scheduling. Since the devices implementing
  12. wake_tx_queue can run without Qdiscs, packets will be handed to mac80211
  13. directly without queueing them in the netdev queues.
  14. Also, mac80211 does not invoke any of the
  15. netif_stop_*/netif_wake_* APIs if wake_tx_queue is implemented.
  16. Since the queues are not stopped in this case, transmissions can continue
  17. and this will impact negatively on the operation of the wireless device.
  18. For example,
  19. During hardware restart, we stop the netdev queues so that packets are
  20. not sent to the driver. Since ath10k implements wake_tx_queue,
  21. TX queues will not be stopped and packets might reach the hardware while
  22. it is restarting; this can make hardware unresponsive and the only
  23. possible option for recovery is to reboot the entire system.
  24. There is another problem to this, it is observed that the packets
  25. were sent on the DFS channel for a prolonged duration after radar
  26. detection impacting the channel closing time.
  27. We can still invoke netif stop/wake APIs when wake_tx_queue is implemented
  28. but this could lead to packet drops in network layer; adding stop/start
  29. logic for software TXQs in mac80211 instead makes more sense; the change
  30. proposed adds the same in mac80211.
  31. Signed-off-by: Manikanta Pubbisetty <mpubbise@codeaurora.org>
  32. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  33. ---
  34. --- a/include/net/mac80211.h
  35. +++ b/include/net/mac80211.h
  36. @@ -1504,6 +1504,8 @@ enum ieee80211_vif_flags {
  37. * @drv_priv: data area for driver use, will always be aligned to
  38. * sizeof(void \*).
  39. * @txq: the multicast data TX queue (if driver uses the TXQ abstraction)
  40. + * @txqs_stopped: per AC flag to indicate that intermediate TXQs are stopped,
  41. + * protected by fq->lock.
  42. */
  43. struct ieee80211_vif {
  44. enum nl80211_iftype type;
  45. @@ -1528,6 +1530,8 @@ struct ieee80211_vif {
  46. unsigned int probe_req_reg;
  47. + bool txqs_stopped[IEEE80211_NUM_ACS];
  48. +
  49. /* must be last */
  50. u8 drv_priv[0] __aligned(sizeof(void *));
  51. };
  52. --- a/net/mac80211/ieee80211_i.h
  53. +++ b/net/mac80211/ieee80211_i.h
  54. @@ -818,6 +818,7 @@ enum txq_info_flags {
  55. IEEE80211_TXQ_STOP,
  56. IEEE80211_TXQ_AMPDU,
  57. IEEE80211_TXQ_NO_AMSDU,
  58. + IEEE80211_TXQ_STOP_NETIF_TX,
  59. };
  60. /**
  61. @@ -1226,6 +1227,7 @@ struct ieee80211_local {
  62. struct sk_buff_head pending[IEEE80211_MAX_QUEUES];
  63. struct tasklet_struct tx_pending_tasklet;
  64. + struct tasklet_struct wake_txqs_tasklet;
  65. atomic_t agg_queue_stop[IEEE80211_MAX_QUEUES];
  66. @@ -2047,6 +2049,7 @@ void ieee80211_txq_remove_vlan(struct ie
  67. struct ieee80211_sub_if_data *sdata);
  68. void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
  69. struct txq_info *txqi);
  70. +void ieee80211_wake_txqs(unsigned long data);
  71. void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  72. u16 transaction, u16 auth_alg, u16 status,
  73. const u8 *extra, size_t extra_len, const u8 *bssid,
  74. --- a/net/mac80211/main.c
  75. +++ b/net/mac80211/main.c
  76. @@ -686,6 +686,10 @@ struct ieee80211_hw *ieee80211_alloc_hw_
  77. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  78. (unsigned long)local);
  79. + if (ops->wake_tx_queue)
  80. + tasklet_init(&local->wake_txqs_tasklet, ieee80211_wake_txqs,
  81. + (unsigned long)local);
  82. +
  83. tasklet_init(&local->tasklet,
  84. ieee80211_tasklet_handler,
  85. (unsigned long) local);
  86. --- a/net/mac80211/tx.c
  87. +++ b/net/mac80211/tx.c
  88. @@ -3487,13 +3487,19 @@ struct sk_buff *ieee80211_tx_dequeue(str
  89. struct ieee80211_tx_info *info;
  90. struct ieee80211_tx_data tx;
  91. ieee80211_tx_result r;
  92. - struct ieee80211_vif *vif;
  93. + struct ieee80211_vif *vif = txq->vif;
  94. spin_lock_bh(&fq->lock);
  95. - if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags))
  96. + if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags) ||
  97. + test_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags))
  98. goto out;
  99. + if (vif->txqs_stopped[ieee80211_ac_from_tid(txq->tid)]) {
  100. + set_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags);
  101. + goto out;
  102. + }
  103. +
  104. /* Make sure fragments stay together. */
  105. skb = __skb_dequeue(&txqi->frags);
  106. if (skb)
  107. @@ -3606,6 +3612,7 @@ begin:
  108. }
  109. IEEE80211_SKB_CB(skb)->control.vif = vif;
  110. +
  111. out:
  112. spin_unlock_bh(&fq->lock);
  113. --- a/net/mac80211/util.c
  114. +++ b/net/mac80211/util.c
  115. @@ -240,6 +240,99 @@ __le16 ieee80211_ctstoself_duration(stru
  116. }
  117. EXPORT_SYMBOL(ieee80211_ctstoself_duration);
  118. +static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
  119. +{
  120. + struct ieee80211_local *local = sdata->local;
  121. + struct ieee80211_vif *vif = &sdata->vif;
  122. + struct fq *fq = &local->fq;
  123. + struct ps_data *ps = NULL;
  124. + struct txq_info *txqi;
  125. + struct sta_info *sta;
  126. + int i;
  127. +
  128. + spin_lock_bh(&fq->lock);
  129. +
  130. + if (sdata->vif.type == NL80211_IFTYPE_AP)
  131. + ps = &sdata->bss->ps;
  132. +
  133. + sdata->vif.txqs_stopped[ac] = false;
  134. +
  135. + list_for_each_entry_rcu(sta, &local->sta_list, list) {
  136. + if (sdata != sta->sdata)
  137. + continue;
  138. +
  139. + for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
  140. + struct ieee80211_txq *txq = sta->sta.txq[i];
  141. +
  142. + txqi = to_txq_info(txq);
  143. +
  144. + if (ac != txq->ac)
  145. + continue;
  146. +
  147. + if (!test_and_clear_bit(IEEE80211_TXQ_STOP_NETIF_TX,
  148. + &txqi->flags))
  149. + continue;
  150. +
  151. + spin_unlock_bh(&fq->lock);
  152. + drv_wake_tx_queue(local, txqi);
  153. + spin_lock_bh(&fq->lock);
  154. + }
  155. + }
  156. +
  157. + if (!vif->txq)
  158. + goto out;
  159. +
  160. + txqi = to_txq_info(vif->txq);
  161. +
  162. + if (!test_and_clear_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags) ||
  163. + (ps && atomic_read(&ps->num_sta_ps)) || ac != vif->txq->ac)
  164. + goto out;
  165. +
  166. + spin_unlock_bh(&fq->lock);
  167. +
  168. + drv_wake_tx_queue(local, txqi);
  169. + return;
  170. +out:
  171. + spin_unlock_bh(&fq->lock);
  172. +}
  173. +
  174. +void ieee80211_wake_txqs(unsigned long data)
  175. +{
  176. + struct ieee80211_local *local = (struct ieee80211_local *)data;
  177. + struct ieee80211_sub_if_data *sdata;
  178. + int n_acs = IEEE80211_NUM_ACS;
  179. + unsigned long flags;
  180. + int i;
  181. +
  182. + rcu_read_lock();
  183. + spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  184. +
  185. + if (local->hw.queues < IEEE80211_NUM_ACS)
  186. + n_acs = 1;
  187. +
  188. + for (i = 0; i < local->hw.queues; i++) {
  189. + if (local->queue_stop_reasons[i])
  190. + continue;
  191. +
  192. + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  193. + list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  194. + int ac;
  195. +
  196. + for (ac = 0; ac < n_acs; ac++) {
  197. + int ac_queue = sdata->vif.hw_queue[ac];
  198. +
  199. + if (ac_queue == i ||
  200. + sdata->vif.cab_queue == i)
  201. + __ieee80211_wake_txqs(sdata, ac);
  202. + }
  203. + }
  204. + spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  205. + }
  206. +
  207. + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  208. + rcu_read_unlock();
  209. +}
  210. +
  211. void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue)
  212. {
  213. struct ieee80211_sub_if_data *sdata;
  214. @@ -308,6 +401,9 @@ static void __ieee80211_wake_queue(struc
  215. rcu_read_unlock();
  216. } else
  217. tasklet_schedule(&local->tx_pending_tasklet);
  218. +
  219. + if (local->ops->wake_tx_queue)
  220. + tasklet_schedule(&local->wake_txqs_tasklet);
  221. }
  222. void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
  223. @@ -351,9 +447,6 @@ static void __ieee80211_stop_queue(struc
  224. if (__test_and_set_bit(reason, &local->queue_stop_reasons[queue]))
  225. return;
  226. - if (local->ops->wake_tx_queue)
  227. - return;
  228. -
  229. if (local->hw.queues < IEEE80211_NUM_ACS)
  230. n_acs = 1;
  231. @@ -366,8 +459,15 @@ static void __ieee80211_stop_queue(struc
  232. for (ac = 0; ac < n_acs; ac++) {
  233. if (sdata->vif.hw_queue[ac] == queue ||
  234. - sdata->vif.cab_queue == queue)
  235. - netif_stop_subqueue(sdata->dev, ac);
  236. + sdata->vif.cab_queue == queue) {
  237. + if (!local->ops->wake_tx_queue) {
  238. + netif_stop_subqueue(sdata->dev, ac);
  239. + continue;
  240. + }
  241. + spin_lock(&local->fq.lock);
  242. + sdata->vif.txqs_stopped[ac] = true;
  243. + spin_unlock(&local->fq.lock);
  244. + }
  245. }
  246. }
  247. rcu_read_unlock();