wme.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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 TC_80211_MAX_QUEUES 16
  20. const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
  21. struct ieee80211_sched_data
  22. {
  23. unsigned long qdisc_pool[BITS_TO_LONGS(TC_80211_MAX_QUEUES)];
  24. struct tcf_proto *filter_list;
  25. struct Qdisc *queues[TC_80211_MAX_QUEUES];
  26. struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
  27. };
  28. static const char llc_ip_hdr[8] = {0xAA, 0xAA, 0x3, 0, 0, 0, 0x08, 0};
  29. /* given a data frame determine the 802.1p/1d tag to use */
  30. static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
  31. {
  32. struct iphdr *ip;
  33. int dscp;
  34. int offset;
  35. struct ieee80211_sched_data *q = qdisc_priv(qd);
  36. struct tcf_result res = { -1, 0 };
  37. /* if there is a user set filter list, call out to that */
  38. if (q->filter_list) {
  39. tc_classify(skb, q->filter_list, &res);
  40. if (res.class != -1)
  41. return res.class;
  42. }
  43. /* skb->priority values from 256->263 are magic values to
  44. * directly indicate a specific 802.1d priority.
  45. * This is used to allow 802.1d priority to be passed directly in
  46. * from VLAN tags, etc. */
  47. if (skb->priority >= 256 && skb->priority <= 263)
  48. return skb->priority - 256;
  49. /* check there is a valid IP header present */
  50. offset = ieee80211_get_hdrlen_from_skb(skb);
  51. if (skb->len < offset + sizeof(llc_ip_hdr) + sizeof(*ip) ||
  52. memcmp(skb->data + offset, llc_ip_hdr, sizeof(llc_ip_hdr)))
  53. return 0;
  54. ip = (struct iphdr *) (skb->data + offset + sizeof(llc_ip_hdr));
  55. dscp = ip->tos & 0xfc;
  56. if (dscp & 0x1c)
  57. return 0;
  58. return dscp >> 5;
  59. }
  60. static inline int wme_downgrade_ac(struct sk_buff *skb)
  61. {
  62. switch (skb->priority) {
  63. case 6:
  64. case 7:
  65. skb->priority = 5; /* VO -> VI */
  66. return 0;
  67. case 4:
  68. case 5:
  69. skb->priority = 3; /* VI -> BE */
  70. return 0;
  71. case 0:
  72. case 3:
  73. skb->priority = 2; /* BE -> BK */
  74. return 0;
  75. default:
  76. return -1;
  77. }
  78. }
  79. /* positive return value indicates which queue to use
  80. * negative return value indicates to drop the frame */
  81. static inline int classify80211(struct sk_buff *skb, struct Qdisc *qd)
  82. {
  83. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  84. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  85. unsigned short fc = le16_to_cpu(hdr->frame_control);
  86. int qos;
  87. /* see if frame is data or non data frame */
  88. if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) {
  89. /* management frames go on AC_VO queue, but are sent
  90. * without QoS control fields */
  91. return IEEE80211_TX_QUEUE_DATA0;
  92. }
  93. if (0 /* injected */) {
  94. /* use AC from radiotap */
  95. }
  96. /* is this a QoS frame? */
  97. qos = fc & IEEE80211_STYPE_QOS_DATA;
  98. if (!qos) {
  99. skb->priority = 0; /* required for correct WPA/11i MIC */
  100. return ieee802_1d_to_ac[skb->priority];
  101. }
  102. /* use the data classifier to determine what 802.1d tag the
  103. * data frame has */
  104. skb->priority = classify_1d(skb, qd);
  105. /* in case we are a client verify acm is not set for this ac */
  106. while (unlikely(local->wmm_acm & BIT(skb->priority))) {
  107. if (wme_downgrade_ac(skb)) {
  108. /* No AC with lower priority has acm=0, drop packet. */
  109. return -1;
  110. }
  111. }
  112. /* look up which queue to use for frames with this 1d tag */
  113. return ieee802_1d_to_ac[skb->priority];
  114. }
  115. static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
  116. {
  117. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  118. struct ieee80211_sched_data *q = qdisc_priv(qd);
  119. struct ieee80211_tx_packet_data *pkt_data =
  120. (struct ieee80211_tx_packet_data *) skb->cb;
  121. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  122. unsigned short fc = le16_to_cpu(hdr->frame_control);
  123. struct Qdisc *qdisc;
  124. int err, queue;
  125. struct sta_info *sta;
  126. u8 tid;
  127. if (pkt_data->flags & IEEE80211_TXPD_REQUEUE) {
  128. queue = pkt_data->queue;
  129. rcu_read_lock();
  130. sta = sta_info_get(local, hdr->addr1);
  131. tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
  132. if (sta) {
  133. int ampdu_queue = sta->tid_to_tx_q[tid];
  134. if ((ampdu_queue < local->hw.queues) &&
  135. test_bit(ampdu_queue, q->qdisc_pool)) {
  136. queue = ampdu_queue;
  137. pkt_data->flags |= IEEE80211_TXPD_AMPDU;
  138. } else {
  139. pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
  140. }
  141. }
  142. rcu_read_unlock();
  143. skb_queue_tail(&q->requeued[queue], skb);
  144. qd->q.qlen++;
  145. return 0;
  146. }
  147. queue = classify80211(skb, qd);
  148. /* now we know the 1d priority, fill in the QoS header if there is one
  149. */
  150. if (WLAN_FC_IS_QOS_DATA(fc)) {
  151. u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2;
  152. u8 ack_policy = 0;
  153. tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
  154. if (local->wifi_wme_noack_test)
  155. ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
  156. QOS_CONTROL_ACK_POLICY_SHIFT;
  157. /* qos header is 2 bytes, second reserved */
  158. *p = ack_policy | tid;
  159. p++;
  160. *p = 0;
  161. rcu_read_lock();
  162. sta = sta_info_get(local, hdr->addr1);
  163. if (sta) {
  164. int ampdu_queue = sta->tid_to_tx_q[tid];
  165. if ((ampdu_queue < local->hw.queues) &&
  166. test_bit(ampdu_queue, q->qdisc_pool)) {
  167. queue = ampdu_queue;
  168. pkt_data->flags |= IEEE80211_TXPD_AMPDU;
  169. } else {
  170. pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
  171. }
  172. }
  173. rcu_read_unlock();
  174. }
  175. if (unlikely(queue >= local->hw.queues)) {
  176. #if 0
  177. if (net_ratelimit()) {
  178. printk(KERN_DEBUG "%s - queue=%d (hw does not "
  179. "support) -> %d\n",
  180. __func__, queue, local->hw.queues - 1);
  181. }
  182. #endif
  183. queue = local->hw.queues - 1;
  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 < hw->queues; 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 < hw->queues; 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 < hw->queues; 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. /* struct ieee80211_sched_data *q = qdisc_priv(qd);
  288. */
  289. /* check our options block is the right size */
  290. /* copy any options to our local structure */
  291. /* Ignore options block for now - always use static mapping
  292. struct tc_ieee80211_qopt *qopt = nla_data(opt);
  293. if (opt->nla_len < nla_attr_size(sizeof(*qopt)))
  294. return -EINVAL;
  295. memcpy(q->tag2queue, qopt->tag2queue, sizeof(qopt->tag2queue));
  296. */
  297. return 0;
  298. }
  299. /* called during initial creation of qdisc on device */
  300. static int wme_qdiscop_init(struct Qdisc *qd, struct nlattr *opt)
  301. {
  302. struct ieee80211_sched_data *q = qdisc_priv(qd);
  303. struct net_device *dev = qd->dev;
  304. struct ieee80211_local *local;
  305. int queues;
  306. int err = 0, i;
  307. /* check that device is a mac80211 device */
  308. if (!dev->ieee80211_ptr ||
  309. dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
  310. return -EINVAL;
  311. /* check this device is an ieee80211 master type device */
  312. if (dev->type != ARPHRD_IEEE80211)
  313. return -EINVAL;
  314. /* check that there is no qdisc currently attached to device
  315. * this ensures that we will be the root qdisc. (I can't find a better
  316. * way to test this explicitly) */
  317. if (dev->qdisc_sleeping != &noop_qdisc)
  318. return -EINVAL;
  319. if (qd->flags & TCQ_F_INGRESS)
  320. return -EINVAL;
  321. local = wdev_priv(dev->ieee80211_ptr);
  322. queues = local->hw.queues;
  323. /* if options were passed in, set them */
  324. if (opt) {
  325. err = wme_qdiscop_tune(qd, opt);
  326. }
  327. /* create child queues */
  328. for (i = 0; i < queues; i++) {
  329. skb_queue_head_init(&q->requeued[i]);
  330. q->queues[i] = qdisc_create_dflt(qd->dev, &pfifo_qdisc_ops,
  331. qd->handle);
  332. if (!q->queues[i]) {
  333. q->queues[i] = &noop_qdisc;
  334. printk(KERN_ERR "%s child qdisc %i creation failed\n",
  335. dev->name, i);
  336. }
  337. }
  338. /* reserve all legacy QoS queues */
  339. for (i = 0; i < min(IEEE80211_TX_QUEUE_DATA4, queues); i++)
  340. set_bit(i, q->qdisc_pool);
  341. return err;
  342. }
  343. static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
  344. {
  345. /* struct ieee80211_sched_data *q = qdisc_priv(qd);
  346. unsigned char *p = skb->tail;
  347. struct tc_ieee80211_qopt opt;
  348. memcpy(&opt.tag2queue, q->tag2queue, TC_80211_MAX_TAG + 1);
  349. NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
  350. */ return skb->len;
  351. /*
  352. nla_put_failure:
  353. skb_trim(skb, p - skb->data);*/
  354. return -1;
  355. }
  356. static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
  357. struct Qdisc *new, struct Qdisc **old)
  358. {
  359. struct ieee80211_sched_data *q = qdisc_priv(qd);
  360. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  361. struct ieee80211_hw *hw = &local->hw;
  362. unsigned long queue = arg - 1;
  363. if (queue >= hw->queues)
  364. return -EINVAL;
  365. if (!new)
  366. new = &noop_qdisc;
  367. sch_tree_lock(qd);
  368. *old = q->queues[queue];
  369. q->queues[queue] = new;
  370. qdisc_reset(*old);
  371. sch_tree_unlock(qd);
  372. return 0;
  373. }
  374. static struct Qdisc *
  375. wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
  376. {
  377. struct ieee80211_sched_data *q = qdisc_priv(qd);
  378. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  379. struct ieee80211_hw *hw = &local->hw;
  380. unsigned long queue = arg - 1;
  381. if (queue >= hw->queues)
  382. return NULL;
  383. return q->queues[queue];
  384. }
  385. static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
  386. {
  387. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  388. struct ieee80211_hw *hw = &local->hw;
  389. unsigned long queue = TC_H_MIN(classid);
  390. if (queue - 1 >= hw->queues)
  391. return 0;
  392. return queue;
  393. }
  394. static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
  395. u32 classid)
  396. {
  397. return wme_classop_get(qd, classid);
  398. }
  399. static void wme_classop_put(struct Qdisc *q, unsigned long cl)
  400. {
  401. }
  402. static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
  403. struct nlattr **tca, unsigned long *arg)
  404. {
  405. unsigned long cl = *arg;
  406. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  407. struct ieee80211_hw *hw = &local->hw;
  408. if (cl - 1 > hw->queues)
  409. return -ENOENT;
  410. /* TODO: put code to program hardware queue parameters here,
  411. * to allow programming from tc command line */
  412. return 0;
  413. }
  414. /* we don't support deleting hardware queues
  415. * when we add WMM-SA support - TSPECs may be deleted here */
  416. static int wme_classop_delete(struct Qdisc *qd, unsigned long cl)
  417. {
  418. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  419. struct ieee80211_hw *hw = &local->hw;
  420. if (cl - 1 > hw->queues)
  421. return -ENOENT;
  422. return 0;
  423. }
  424. static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
  425. struct sk_buff *skb, struct tcmsg *tcm)
  426. {
  427. struct ieee80211_sched_data *q = qdisc_priv(qd);
  428. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  429. struct ieee80211_hw *hw = &local->hw;
  430. if (cl - 1 > hw->queues)
  431. return -ENOENT;
  432. tcm->tcm_handle = TC_H_MIN(cl);
  433. tcm->tcm_parent = qd->handle;
  434. tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */
  435. return 0;
  436. }
  437. static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
  438. {
  439. struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
  440. struct ieee80211_hw *hw = &local->hw;
  441. int queue;
  442. if (arg->stop)
  443. return;
  444. for (queue = 0; queue < hw->queues; queue++) {
  445. if (arg->count < arg->skip) {
  446. arg->count++;
  447. continue;
  448. }
  449. /* we should return classids for our internal queues here
  450. * as well as the external ones */
  451. if (arg->fn(qd, queue+1, arg) < 0) {
  452. arg->stop = 1;
  453. break;
  454. }
  455. arg->count++;
  456. }
  457. }
  458. static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
  459. unsigned long cl)
  460. {
  461. struct ieee80211_sched_data *q = qdisc_priv(qd);
  462. if (cl)
  463. return NULL;
  464. return &q->filter_list;
  465. }
  466. /* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached)
  467. * - these are the operations on the classes */
  468. static const struct Qdisc_class_ops class_ops =
  469. {
  470. .graft = wme_classop_graft,
  471. .leaf = wme_classop_leaf,
  472. .get = wme_classop_get,
  473. .put = wme_classop_put,
  474. .change = wme_classop_change,
  475. .delete = wme_classop_delete,
  476. .walk = wme_classop_walk,
  477. .tcf_chain = wme_classop_find_tcf,
  478. .bind_tcf = wme_classop_bind,
  479. .unbind_tcf = wme_classop_put,
  480. .dump = wme_classop_dump_class,
  481. };
  482. /* queueing discipline operations */
  483. static struct Qdisc_ops wme_qdisc_ops __read_mostly =
  484. {
  485. .next = NULL,
  486. .cl_ops = &class_ops,
  487. .id = "ieee80211",
  488. .priv_size = sizeof(struct ieee80211_sched_data),
  489. .enqueue = wme_qdiscop_enqueue,
  490. .dequeue = wme_qdiscop_dequeue,
  491. .requeue = wme_qdiscop_requeue,
  492. .drop = NULL, /* drop not needed since we are always the root qdisc */
  493. .init = wme_qdiscop_init,
  494. .reset = wme_qdiscop_reset,
  495. .destroy = wme_qdiscop_destroy,
  496. .change = wme_qdiscop_tune,
  497. .dump = wme_qdiscop_dump,
  498. };
  499. void ieee80211_install_qdisc(struct net_device *dev)
  500. {
  501. struct Qdisc *qdisc;
  502. qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops, TC_H_ROOT);
  503. if (!qdisc) {
  504. printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
  505. return;
  506. }
  507. /* same handle as would be allocated by qdisc_alloc_handle() */
  508. qdisc->handle = 0x80010000;
  509. qdisc_lock_tree(dev);
  510. list_add_tail(&qdisc->list, &dev->qdisc_list);
  511. dev->qdisc_sleeping = qdisc;
  512. qdisc_unlock_tree(dev);
  513. }
  514. int ieee80211_qdisc_installed(struct net_device *dev)
  515. {
  516. return dev->qdisc_sleeping->ops == &wme_qdisc_ops;
  517. }
  518. int ieee80211_wme_register(void)
  519. {
  520. return register_qdisc(&wme_qdisc_ops);
  521. }
  522. void ieee80211_wme_unregister(void)
  523. {
  524. unregister_qdisc(&wme_qdisc_ops);
  525. }
  526. int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
  527. struct sta_info *sta, u16 tid)
  528. {
  529. int i;
  530. struct ieee80211_sched_data *q =
  531. qdisc_priv(local->mdev->qdisc_sleeping);
  532. DECLARE_MAC_BUF(mac);
  533. /* prepare the filter and save it for the SW queue
  534. * matching the recieved HW queue */
  535. /* try to get a Qdisc from the pool */
  536. for (i = IEEE80211_TX_QUEUE_BEACON; i < local->hw.queues; i++)
  537. if (!test_and_set_bit(i, q->qdisc_pool)) {
  538. ieee80211_stop_queue(local_to_hw(local), i);
  539. sta->tid_to_tx_q[tid] = i;
  540. /* IF there are already pending packets
  541. * on this tid first we need to drain them
  542. * on the previous queue
  543. * since HT is strict in order */
  544. #ifdef CONFIG_MAC80211_HT_DEBUG
  545. if (net_ratelimit())
  546. printk(KERN_DEBUG "allocated aggregation queue"
  547. " %d tid %d addr %s pool=0x%lX",
  548. i, tid, print_mac(mac, sta->addr),
  549. q->qdisc_pool[0]);
  550. #endif /* CONFIG_MAC80211_HT_DEBUG */
  551. return 0;
  552. }
  553. return -EAGAIN;
  554. }
  555. /**
  556. * the caller needs to hold local->mdev->queue_lock
  557. */
  558. void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
  559. struct sta_info *sta, u16 tid,
  560. u8 requeue)
  561. {
  562. struct ieee80211_sched_data *q =
  563. qdisc_priv(local->mdev->qdisc_sleeping);
  564. int agg_queue = sta->tid_to_tx_q[tid];
  565. /* return the qdisc to the pool */
  566. clear_bit(agg_queue, q->qdisc_pool);
  567. sta->tid_to_tx_q[tid] = local->hw.queues;
  568. if (requeue)
  569. ieee80211_requeue(local, agg_queue);
  570. else
  571. q->queues[agg_queue]->ops->reset(q->queues[agg_queue]);
  572. }
  573. void ieee80211_requeue(struct ieee80211_local *local, int queue)
  574. {
  575. struct Qdisc *root_qd = local->mdev->qdisc_sleeping;
  576. struct ieee80211_sched_data *q = qdisc_priv(root_qd);
  577. struct Qdisc *qdisc = q->queues[queue];
  578. struct sk_buff *skb = NULL;
  579. u32 len;
  580. if (!qdisc || !qdisc->dequeue)
  581. return;
  582. printk(KERN_DEBUG "requeue: qlen = %d\n", qdisc->q.qlen);
  583. for (len = qdisc->q.qlen; len > 0; len--) {
  584. skb = qdisc->dequeue(qdisc);
  585. root_qd->q.qlen--;
  586. /* packet will be classified again and */
  587. /* skb->packet_data->queue will be overridden if needed */
  588. if (skb)
  589. wme_qdiscop_enqueue(skb, root_qd);
  590. }
  591. }