wme.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /*
  2. * Copyright 2004, Instant802 Networks, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/netdevice.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/module.h>
  11. #include <linux/if_arp.h>
  12. #include <linux/types.h>
  13. #include <net/ip.h>
  14. #include <net/pkt_sched.h>
  15. #include <net/mac80211.h>
  16. #include "ieee80211_i.h"
  17. #include "wme.h"
  18. /* maximum number of hardware queues we support. */
  19. #define QD_MAX_QUEUES (IEEE80211_MAX_AMPDU_QUEUES + IEEE80211_MAX_QUEUES)
  20. /* current number of hardware queues we support. */
  21. #define QD_NUM(hw) ((hw)->queues + (hw)->ampdu_queues)
  22. /*
  23. * Default mapping in classifier to work with default
  24. * queue setup.
  25. */
  26. const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
  27. struct ieee80211_sched_data
  28. {
  29. unsigned long qdisc_pool[BITS_TO_LONGS(QD_MAX_QUEUES)];
  30. struct tcf_proto *filter_list;
  31. struct Qdisc *queues[QD_MAX_QUEUES];
  32. struct sk_buff_head requeued[QD_MAX_QUEUES];
  33. };
  34. static const char llc_ip_hdr[8] = {0xAA, 0xAA, 0x3, 0, 0, 0, 0x08, 0};
  35. /* given a data frame determine the 802.1p/1d tag to use */
  36. static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
  37. {
  38. struct iphdr *ip;
  39. int dscp;
  40. int offset;
  41. struct ieee80211_sched_data *q = qdisc_priv(qd);
  42. struct tcf_result res = { -1, 0 };
  43. /* if there is a user set filter list, call out to that */
  44. if (q->filter_list) {
  45. tc_classify(skb, q->filter_list, &res);
  46. if (res.class != -1)
  47. return res.class;
  48. }
  49. /* skb->priority values from 256->263 are magic values to
  50. * directly indicate a specific 802.1d priority.
  51. * This is used to allow 802.1d priority to be passed directly in
  52. * from VLAN tags, etc. */
  53. if (skb->priority >= 256 && skb->priority <= 263)
  54. return skb->priority - 256;
  55. /* check there is a valid IP header present */
  56. offset = ieee80211_get_hdrlen_from_skb(skb);
  57. if (skb->len < offset + sizeof(llc_ip_hdr) + sizeof(*ip) ||
  58. memcmp(skb->data + offset, llc_ip_hdr, sizeof(llc_ip_hdr)))
  59. return 0;
  60. ip = (struct iphdr *) (skb->data + offset + sizeof(llc_ip_hdr));
  61. dscp = ip->tos & 0xfc;
  62. if (dscp & 0x1c)
  63. return 0;
  64. return dscp >> 5;
  65. }
  66. static inline int wme_downgrade_ac(struct sk_buff *skb)
  67. {
  68. switch (skb->priority) {
  69. case 6:
  70. case 7:
  71. skb->priority = 5; /* VO -> VI */
  72. return 0;
  73. case 4:
  74. case 5:
  75. skb->priority = 3; /* VI -> BE */
  76. return 0;
  77. case 0:
  78. case 3:
  79. skb->priority = 2; /* BE -> BK */
  80. return 0;
  81. default:
  82. return -1;
  83. }
  84. }
  85. /* positive return value indicates which queue to use
  86. * negative return value indicates to drop the frame */
  87. static int classify80211(struct sk_buff *skb, struct Qdisc *qd)
  88. {
  89. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  90. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  91. unsigned short fc = le16_to_cpu(hdr->frame_control);
  92. int qos;
  93. /* see if frame is data or non data frame */
  94. if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) {
  95. /* management frames go on AC_VO queue, but are sent
  96. * without QoS control fields */
  97. return 0;
  98. }
  99. if (0 /* injected */) {
  100. /* use AC from radiotap */
  101. }
  102. /* is this a QoS frame? */
  103. qos = fc & IEEE80211_STYPE_QOS_DATA;
  104. if (!qos) {
  105. skb->priority = 0; /* required for correct WPA/11i MIC */
  106. return ieee802_1d_to_ac[skb->priority];
  107. }
  108. /* use the data classifier to determine what 802.1d tag the
  109. * data frame has */
  110. skb->priority = classify_1d(skb, qd);
  111. /* in case we are a client verify acm is not set for this ac */
  112. while (unlikely(local->wmm_acm & BIT(skb->priority))) {
  113. if (wme_downgrade_ac(skb)) {
  114. /* No AC with lower priority has acm=0, drop packet. */
  115. return -1;
  116. }
  117. }
  118. /* look up which queue to use for frames with this 1d tag */
  119. return ieee802_1d_to_ac[skb->priority];
  120. }
  121. static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
  122. {
  123. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  124. struct ieee80211_hw *hw = &local->hw;
  125. struct ieee80211_sched_data *q = qdisc_priv(qd);
  126. struct ieee80211_tx_packet_data *pkt_data =
  127. (struct ieee80211_tx_packet_data *) skb->cb;
  128. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  129. unsigned short fc = le16_to_cpu(hdr->frame_control);
  130. struct Qdisc *qdisc;
  131. struct sta_info *sta;
  132. int err;
  133. u16 queue;
  134. u8 tid;
  135. if (pkt_data->flags & IEEE80211_TXPD_REQUEUE) {
  136. queue = pkt_data->queue;
  137. rcu_read_lock();
  138. sta = sta_info_get(local, hdr->addr1);
  139. tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
  140. if (sta) {
  141. int ampdu_queue = sta->tid_to_tx_q[tid];
  142. if ((ampdu_queue < QD_NUM(hw)) &&
  143. test_bit(ampdu_queue, q->qdisc_pool)) {
  144. queue = ampdu_queue;
  145. pkt_data->flags |= IEEE80211_TXPD_AMPDU;
  146. } else {
  147. pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
  148. }
  149. }
  150. rcu_read_unlock();
  151. skb_queue_tail(&q->requeued[queue], skb);
  152. qd->q.qlen++;
  153. return 0;
  154. }
  155. queue = classify80211(skb, qd);
  156. if (unlikely(queue >= local->hw.queues))
  157. queue = local->hw.queues - 1;
  158. /* now we know the 1d priority, fill in the QoS header if there is one
  159. */
  160. if (WLAN_FC_IS_QOS_DATA(fc)) {
  161. u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2;
  162. u8 ack_policy = 0;
  163. tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
  164. if (local->wifi_wme_noack_test)
  165. ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
  166. QOS_CONTROL_ACK_POLICY_SHIFT;
  167. /* qos header is 2 bytes, second reserved */
  168. *p = ack_policy | tid;
  169. p++;
  170. *p = 0;
  171. rcu_read_lock();
  172. sta = sta_info_get(local, hdr->addr1);
  173. if (sta) {
  174. int ampdu_queue = sta->tid_to_tx_q[tid];
  175. if ((ampdu_queue < QD_NUM(hw)) &&
  176. test_bit(ampdu_queue, q->qdisc_pool)) {
  177. queue = ampdu_queue;
  178. pkt_data->flags |= IEEE80211_TXPD_AMPDU;
  179. } else {
  180. pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
  181. }
  182. }
  183. rcu_read_unlock();
  184. }
  185. if (unlikely(queue < 0)) {
  186. kfree_skb(skb);
  187. err = NET_XMIT_DROP;
  188. } else {
  189. tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
  190. pkt_data->queue = (unsigned int) queue;
  191. qdisc = q->queues[queue];
  192. err = qdisc->enqueue(skb, qdisc);
  193. if (err == NET_XMIT_SUCCESS) {
  194. qd->q.qlen++;
  195. qd->bstats.bytes += skb->len;
  196. qd->bstats.packets++;
  197. return NET_XMIT_SUCCESS;
  198. }
  199. }
  200. qd->qstats.drops++;
  201. return err;
  202. }
  203. /* TODO: clean up the cases where master_hard_start_xmit
  204. * returns non 0 - it shouldn't ever do that. Once done we
  205. * can remove this function */
  206. static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
  207. {
  208. struct ieee80211_sched_data *q = qdisc_priv(qd);
  209. struct ieee80211_tx_packet_data *pkt_data =
  210. (struct ieee80211_tx_packet_data *) skb->cb;
  211. struct Qdisc *qdisc;
  212. int err;
  213. /* we recorded which queue to use earlier! */
  214. qdisc = q->queues[pkt_data->queue];
  215. if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
  216. qd->q.qlen++;
  217. return 0;
  218. }
  219. qd->qstats.drops++;
  220. return err;
  221. }
  222. static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
  223. {
  224. struct ieee80211_sched_data *q = qdisc_priv(qd);
  225. struct net_device *dev = qd->dev;
  226. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  227. struct ieee80211_hw *hw = &local->hw;
  228. struct sk_buff *skb;
  229. struct Qdisc *qdisc;
  230. int queue;
  231. /* check all the h/w queues in numeric/priority order */
  232. for (queue = 0; queue < QD_NUM(hw); queue++) {
  233. /* see if there is room in this hardware queue */
  234. if ((test_bit(IEEE80211_LINK_STATE_XOFF,
  235. &local->state[queue])) ||
  236. (test_bit(IEEE80211_LINK_STATE_PENDING,
  237. &local->state[queue])) ||
  238. (!test_bit(queue, q->qdisc_pool)))
  239. continue;
  240. /* there is space - try and get a frame */
  241. skb = skb_dequeue(&q->requeued[queue]);
  242. if (skb) {
  243. qd->q.qlen--;
  244. return skb;
  245. }
  246. qdisc = q->queues[queue];
  247. skb = qdisc->dequeue(qdisc);
  248. if (skb) {
  249. qd->q.qlen--;
  250. return skb;
  251. }
  252. }
  253. /* returning a NULL here when all the h/w queues are full means we
  254. * never need to call netif_stop_queue in the driver */
  255. return NULL;
  256. }
  257. static void wme_qdiscop_reset(struct Qdisc* qd)
  258. {
  259. struct ieee80211_sched_data *q = qdisc_priv(qd);
  260. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  261. struct ieee80211_hw *hw = &local->hw;
  262. int queue;
  263. /* QUESTION: should we have some hardware flush functionality here? */
  264. for (queue = 0; queue < QD_NUM(hw); queue++) {
  265. skb_queue_purge(&q->requeued[queue]);
  266. qdisc_reset(q->queues[queue]);
  267. }
  268. qd->q.qlen = 0;
  269. }
  270. static void wme_qdiscop_destroy(struct Qdisc* qd)
  271. {
  272. struct ieee80211_sched_data *q = qdisc_priv(qd);
  273. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  274. struct ieee80211_hw *hw = &local->hw;
  275. int queue;
  276. tcf_destroy_chain(q->filter_list);
  277. q->filter_list = NULL;
  278. for (queue = 0; queue < QD_NUM(hw); queue++) {
  279. skb_queue_purge(&q->requeued[queue]);
  280. qdisc_destroy(q->queues[queue]);
  281. q->queues[queue] = &noop_qdisc;
  282. }
  283. }
  284. /* called whenever parameters are updated on existing qdisc */
  285. static int wme_qdiscop_tune(struct Qdisc *qd, struct nlattr *opt)
  286. {
  287. return 0;
  288. }
  289. /* called during initial creation of qdisc on device */
  290. static int wme_qdiscop_init(struct Qdisc *qd, struct nlattr *opt)
  291. {
  292. struct ieee80211_sched_data *q = qdisc_priv(qd);
  293. struct net_device *dev = qd->dev;
  294. struct ieee80211_local *local;
  295. struct ieee80211_hw *hw;
  296. int err = 0, i;
  297. /* check that device is a mac80211 device */
  298. if (!dev->ieee80211_ptr ||
  299. dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
  300. return -EINVAL;
  301. local = wdev_priv(dev->ieee80211_ptr);
  302. hw = &local->hw;
  303. /* only allow on master dev */
  304. if (dev != local->mdev)
  305. return -EINVAL;
  306. /* ensure that we are root qdisc */
  307. if (qd->parent != TC_H_ROOT)
  308. return -EINVAL;
  309. if (qd->flags & TCQ_F_INGRESS)
  310. return -EINVAL;
  311. /* if options were passed in, set them */
  312. if (opt)
  313. err = wme_qdiscop_tune(qd, opt);
  314. /* create child queues */
  315. for (i = 0; i < QD_NUM(hw); i++) {
  316. skb_queue_head_init(&q->requeued[i]);
  317. q->queues[i] = qdisc_create_dflt(qd->dev, &pfifo_qdisc_ops,
  318. qd->handle);
  319. if (!q->queues[i]) {
  320. q->queues[i] = &noop_qdisc;
  321. printk(KERN_ERR "%s child qdisc %i creation failed", dev->name, i);
  322. }
  323. }
  324. /* non-aggregation queues: reserve/mark as used */
  325. for (i = 0; i < local->hw.queues; i++)
  326. set_bit(i, q->qdisc_pool);
  327. return err;
  328. }
  329. static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
  330. {
  331. return -1;
  332. }
  333. static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
  334. struct Qdisc *new, struct Qdisc **old)
  335. {
  336. struct ieee80211_sched_data *q = qdisc_priv(qd);
  337. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  338. struct ieee80211_hw *hw = &local->hw;
  339. unsigned long queue = arg - 1;
  340. if (queue >= QD_NUM(hw))
  341. return -EINVAL;
  342. if (!new)
  343. new = &noop_qdisc;
  344. sch_tree_lock(qd);
  345. *old = q->queues[queue];
  346. q->queues[queue] = new;
  347. qdisc_reset(*old);
  348. sch_tree_unlock(qd);
  349. return 0;
  350. }
  351. static struct Qdisc *
  352. wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
  353. {
  354. struct ieee80211_sched_data *q = qdisc_priv(qd);
  355. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  356. struct ieee80211_hw *hw = &local->hw;
  357. unsigned long queue = arg - 1;
  358. if (queue >= QD_NUM(hw))
  359. return NULL;
  360. return q->queues[queue];
  361. }
  362. static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
  363. {
  364. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  365. struct ieee80211_hw *hw = &local->hw;
  366. unsigned long queue = TC_H_MIN(classid);
  367. if (queue - 1 >= QD_NUM(hw))
  368. return 0;
  369. return queue;
  370. }
  371. static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
  372. u32 classid)
  373. {
  374. return wme_classop_get(qd, classid);
  375. }
  376. static void wme_classop_put(struct Qdisc *q, unsigned long cl)
  377. {
  378. }
  379. static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
  380. struct nlattr **tca, unsigned long *arg)
  381. {
  382. unsigned long cl = *arg;
  383. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  384. struct ieee80211_hw *hw = &local->hw;
  385. if (cl - 1 > QD_NUM(hw))
  386. return -ENOENT;
  387. /* TODO: put code to program hardware queue parameters here,
  388. * to allow programming from tc command line */
  389. return 0;
  390. }
  391. /* we don't support deleting hardware queues
  392. * when we add WMM-SA support - TSPECs may be deleted here */
  393. static int wme_classop_delete(struct Qdisc *qd, unsigned long cl)
  394. {
  395. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  396. struct ieee80211_hw *hw = &local->hw;
  397. if (cl - 1 > QD_NUM(hw))
  398. return -ENOENT;
  399. return 0;
  400. }
  401. static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
  402. struct sk_buff *skb, struct tcmsg *tcm)
  403. {
  404. struct ieee80211_sched_data *q = qdisc_priv(qd);
  405. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  406. struct ieee80211_hw *hw = &local->hw;
  407. if (cl - 1 > QD_NUM(hw))
  408. return -ENOENT;
  409. tcm->tcm_handle = TC_H_MIN(cl);
  410. tcm->tcm_parent = qd->handle;
  411. tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */
  412. return 0;
  413. }
  414. static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
  415. {
  416. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  417. struct ieee80211_hw *hw = &local->hw;
  418. int queue;
  419. if (arg->stop)
  420. return;
  421. for (queue = 0; queue < QD_NUM(hw); queue++) {
  422. if (arg->count < arg->skip) {
  423. arg->count++;
  424. continue;
  425. }
  426. /* we should return classids for our internal queues here
  427. * as well as the external ones */
  428. if (arg->fn(qd, queue+1, arg) < 0) {
  429. arg->stop = 1;
  430. break;
  431. }
  432. arg->count++;
  433. }
  434. }
  435. static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
  436. unsigned long cl)
  437. {
  438. struct ieee80211_sched_data *q = qdisc_priv(qd);
  439. if (cl)
  440. return NULL;
  441. return &q->filter_list;
  442. }
  443. /* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached)
  444. * - these are the operations on the classes */
  445. static const struct Qdisc_class_ops class_ops =
  446. {
  447. .graft = wme_classop_graft,
  448. .leaf = wme_classop_leaf,
  449. .get = wme_classop_get,
  450. .put = wme_classop_put,
  451. .change = wme_classop_change,
  452. .delete = wme_classop_delete,
  453. .walk = wme_classop_walk,
  454. .tcf_chain = wme_classop_find_tcf,
  455. .bind_tcf = wme_classop_bind,
  456. .unbind_tcf = wme_classop_put,
  457. .dump = wme_classop_dump_class,
  458. };
  459. /* queueing discipline operations */
  460. static struct Qdisc_ops wme_qdisc_ops __read_mostly =
  461. {
  462. .next = NULL,
  463. .cl_ops = &class_ops,
  464. .id = "ieee80211",
  465. .priv_size = sizeof(struct ieee80211_sched_data),
  466. .enqueue = wme_qdiscop_enqueue,
  467. .dequeue = wme_qdiscop_dequeue,
  468. .requeue = wme_qdiscop_requeue,
  469. .drop = NULL, /* drop not needed since we are always the root qdisc */
  470. .init = wme_qdiscop_init,
  471. .reset = wme_qdiscop_reset,
  472. .destroy = wme_qdiscop_destroy,
  473. .change = wme_qdiscop_tune,
  474. .dump = wme_qdiscop_dump,
  475. };
  476. void ieee80211_install_qdisc(struct net_device *dev)
  477. {
  478. struct Qdisc *qdisc;
  479. qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops, TC_H_ROOT);
  480. if (!qdisc) {
  481. printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
  482. return;
  483. }
  484. /* same handle as would be allocated by qdisc_alloc_handle() */
  485. qdisc->handle = 0x80010000;
  486. qdisc_lock_tree(dev);
  487. list_add_tail(&qdisc->list, &dev->qdisc_list);
  488. dev->qdisc_sleeping = qdisc;
  489. qdisc_unlock_tree(dev);
  490. }
  491. int ieee80211_qdisc_installed(struct net_device *dev)
  492. {
  493. return dev->qdisc_sleeping->ops == &wme_qdisc_ops;
  494. }
  495. int ieee80211_wme_register(void)
  496. {
  497. return register_qdisc(&wme_qdisc_ops);
  498. }
  499. void ieee80211_wme_unregister(void)
  500. {
  501. unregister_qdisc(&wme_qdisc_ops);
  502. }
  503. int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
  504. struct sta_info *sta, u16 tid)
  505. {
  506. int i;
  507. struct ieee80211_sched_data *q =
  508. qdisc_priv(local->mdev->qdisc_sleeping);
  509. DECLARE_MAC_BUF(mac);
  510. /* prepare the filter and save it for the SW queue
  511. * matching the received HW queue */
  512. if (!local->hw.ampdu_queues)
  513. return -EPERM;
  514. /* try to get a Qdisc from the pool */
  515. for (i = local->hw.queues; i < QD_NUM(&local->hw); i++)
  516. if (!test_and_set_bit(i, q->qdisc_pool)) {
  517. ieee80211_stop_queue(local_to_hw(local), i);
  518. sta->tid_to_tx_q[tid] = i;
  519. /* IF there are already pending packets
  520. * on this tid first we need to drain them
  521. * on the previous queue
  522. * since HT is strict in order */
  523. #ifdef CONFIG_MAC80211_HT_DEBUG
  524. if (net_ratelimit())
  525. printk(KERN_DEBUG "allocated aggregation queue"
  526. " %d tid %d addr %s pool=0x%lX",
  527. i, tid, print_mac(mac, sta->addr),
  528. q->qdisc_pool[0]);
  529. #endif /* CONFIG_MAC80211_HT_DEBUG */
  530. return 0;
  531. }
  532. return -EAGAIN;
  533. }
  534. /**
  535. * the caller needs to hold local->mdev->queue_lock
  536. */
  537. void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
  538. struct sta_info *sta, u16 tid,
  539. u8 requeue)
  540. {
  541. struct ieee80211_hw *hw = &local->hw;
  542. struct ieee80211_sched_data *q =
  543. qdisc_priv(local->mdev->qdisc_sleeping);
  544. int agg_queue = sta->tid_to_tx_q[tid];
  545. /* return the qdisc to the pool */
  546. clear_bit(agg_queue, q->qdisc_pool);
  547. sta->tid_to_tx_q[tid] = QD_NUM(hw);
  548. if (requeue)
  549. ieee80211_requeue(local, agg_queue);
  550. else
  551. q->queues[agg_queue]->ops->reset(q->queues[agg_queue]);
  552. }
  553. void ieee80211_requeue(struct ieee80211_local *local, int queue)
  554. {
  555. struct Qdisc *root_qd = local->mdev->qdisc_sleeping;
  556. struct ieee80211_sched_data *q = qdisc_priv(root_qd);
  557. struct Qdisc *qdisc = q->queues[queue];
  558. struct sk_buff *skb = NULL;
  559. u32 len;
  560. if (!qdisc || !qdisc->dequeue)
  561. return;
  562. printk(KERN_DEBUG "requeue: qlen = %d\n", qdisc->q.qlen);
  563. for (len = qdisc->q.qlen; len > 0; len--) {
  564. skb = qdisc->dequeue(qdisc);
  565. root_qd->q.qlen--;
  566. /* packet will be classified again and */
  567. /* skb->packet_data->queue will be overridden if needed */
  568. if (skb)
  569. wme_qdiscop_enqueue(skb, root_qd);
  570. }
  571. }