rt2x00queue.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. /*
  2. Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
  3. Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
  4. Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
  5. <http://rt2x00.serialmonkey.com>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the
  16. Free Software Foundation, Inc.,
  17. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. Module: rt2x00lib
  21. Abstract: rt2x00 queue specific routines.
  22. */
  23. #include <linux/slab.h>
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/dma-mapping.h>
  27. #include "rt2x00.h"
  28. #include "rt2x00lib.h"
  29. struct sk_buff *rt2x00queue_alloc_rxskb(struct queue_entry *entry)
  30. {
  31. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  32. struct sk_buff *skb;
  33. struct skb_frame_desc *skbdesc;
  34. unsigned int frame_size;
  35. unsigned int head_size = 0;
  36. unsigned int tail_size = 0;
  37. /*
  38. * The frame size includes descriptor size, because the
  39. * hardware directly receive the frame into the skbuffer.
  40. */
  41. frame_size = entry->queue->data_size + entry->queue->desc_size;
  42. /*
  43. * The payload should be aligned to a 4-byte boundary,
  44. * this means we need at least 3 bytes for moving the frame
  45. * into the correct offset.
  46. */
  47. head_size = 4;
  48. /*
  49. * For IV/EIV/ICV assembly we must make sure there is
  50. * at least 8 bytes bytes available in headroom for IV/EIV
  51. * and 8 bytes for ICV data as tailroon.
  52. */
  53. if (test_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags)) {
  54. head_size += 8;
  55. tail_size += 8;
  56. }
  57. /*
  58. * Allocate skbuffer.
  59. */
  60. skb = dev_alloc_skb(frame_size + head_size + tail_size);
  61. if (!skb)
  62. return NULL;
  63. /*
  64. * Make sure we not have a frame with the requested bytes
  65. * available in the head and tail.
  66. */
  67. skb_reserve(skb, head_size);
  68. skb_put(skb, frame_size);
  69. /*
  70. * Populate skbdesc.
  71. */
  72. skbdesc = get_skb_frame_desc(skb);
  73. memset(skbdesc, 0, sizeof(*skbdesc));
  74. skbdesc->entry = entry;
  75. if (test_bit(REQUIRE_DMA, &rt2x00dev->cap_flags)) {
  76. skbdesc->skb_dma = dma_map_single(rt2x00dev->dev,
  77. skb->data,
  78. skb->len,
  79. DMA_FROM_DEVICE);
  80. skbdesc->flags |= SKBDESC_DMA_MAPPED_RX;
  81. }
  82. return skb;
  83. }
  84. void rt2x00queue_map_txskb(struct queue_entry *entry)
  85. {
  86. struct device *dev = entry->queue->rt2x00dev->dev;
  87. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  88. skbdesc->skb_dma =
  89. dma_map_single(dev, entry->skb->data, entry->skb->len, DMA_TO_DEVICE);
  90. skbdesc->flags |= SKBDESC_DMA_MAPPED_TX;
  91. }
  92. EXPORT_SYMBOL_GPL(rt2x00queue_map_txskb);
  93. void rt2x00queue_unmap_skb(struct queue_entry *entry)
  94. {
  95. struct device *dev = entry->queue->rt2x00dev->dev;
  96. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  97. if (skbdesc->flags & SKBDESC_DMA_MAPPED_RX) {
  98. dma_unmap_single(dev, skbdesc->skb_dma, entry->skb->len,
  99. DMA_FROM_DEVICE);
  100. skbdesc->flags &= ~SKBDESC_DMA_MAPPED_RX;
  101. } else if (skbdesc->flags & SKBDESC_DMA_MAPPED_TX) {
  102. dma_unmap_single(dev, skbdesc->skb_dma, entry->skb->len,
  103. DMA_TO_DEVICE);
  104. skbdesc->flags &= ~SKBDESC_DMA_MAPPED_TX;
  105. }
  106. }
  107. EXPORT_SYMBOL_GPL(rt2x00queue_unmap_skb);
  108. void rt2x00queue_free_skb(struct queue_entry *entry)
  109. {
  110. if (!entry->skb)
  111. return;
  112. rt2x00queue_unmap_skb(entry);
  113. dev_kfree_skb_any(entry->skb);
  114. entry->skb = NULL;
  115. }
  116. void rt2x00queue_align_frame(struct sk_buff *skb)
  117. {
  118. unsigned int frame_length = skb->len;
  119. unsigned int align = ALIGN_SIZE(skb, 0);
  120. if (!align)
  121. return;
  122. skb_push(skb, align);
  123. memmove(skb->data, skb->data + align, frame_length);
  124. skb_trim(skb, frame_length);
  125. }
  126. void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length)
  127. {
  128. unsigned int payload_length = skb->len - header_length;
  129. unsigned int header_align = ALIGN_SIZE(skb, 0);
  130. unsigned int payload_align = ALIGN_SIZE(skb, header_length);
  131. unsigned int l2pad = payload_length ? L2PAD_SIZE(header_length) : 0;
  132. /*
  133. * Adjust the header alignment if the payload needs to be moved more
  134. * than the header.
  135. */
  136. if (payload_align > header_align)
  137. header_align += 4;
  138. /* There is nothing to do if no alignment is needed */
  139. if (!header_align)
  140. return;
  141. /* Reserve the amount of space needed in front of the frame */
  142. skb_push(skb, header_align);
  143. /*
  144. * Move the header.
  145. */
  146. memmove(skb->data, skb->data + header_align, header_length);
  147. /* Move the payload, if present and if required */
  148. if (payload_length && payload_align)
  149. memmove(skb->data + header_length + l2pad,
  150. skb->data + header_length + l2pad + payload_align,
  151. payload_length);
  152. /* Trim the skb to the correct size */
  153. skb_trim(skb, header_length + l2pad + payload_length);
  154. }
  155. void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int header_length)
  156. {
  157. /*
  158. * L2 padding is only present if the skb contains more than just the
  159. * IEEE 802.11 header.
  160. */
  161. unsigned int l2pad = (skb->len > header_length) ?
  162. L2PAD_SIZE(header_length) : 0;
  163. if (!l2pad)
  164. return;
  165. memmove(skb->data + l2pad, skb->data, header_length);
  166. skb_pull(skb, l2pad);
  167. }
  168. static void rt2x00queue_create_tx_descriptor_seq(struct queue_entry *entry,
  169. struct txentry_desc *txdesc)
  170. {
  171. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
  172. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)entry->skb->data;
  173. struct rt2x00_intf *intf = vif_to_intf(tx_info->control.vif);
  174. if (!(tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ))
  175. return;
  176. __set_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags);
  177. if (!test_bit(REQUIRE_SW_SEQNO, &entry->queue->rt2x00dev->cap_flags))
  178. return;
  179. /*
  180. * The hardware is not able to insert a sequence number. Assign a
  181. * software generated one here.
  182. *
  183. * This is wrong because beacons are not getting sequence
  184. * numbers assigned properly.
  185. *
  186. * A secondary problem exists for drivers that cannot toggle
  187. * sequence counting per-frame, since those will override the
  188. * sequence counter given by mac80211.
  189. */
  190. spin_lock(&intf->seqlock);
  191. if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
  192. intf->seqno += 0x10;
  193. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  194. hdr->seq_ctrl |= cpu_to_le16(intf->seqno);
  195. spin_unlock(&intf->seqlock);
  196. }
  197. static void rt2x00queue_create_tx_descriptor_plcp(struct queue_entry *entry,
  198. struct txentry_desc *txdesc,
  199. const struct rt2x00_rate *hwrate)
  200. {
  201. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  202. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
  203. struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
  204. unsigned int data_length;
  205. unsigned int duration;
  206. unsigned int residual;
  207. /*
  208. * Determine with what IFS priority this frame should be send.
  209. * Set ifs to IFS_SIFS when the this is not the first fragment,
  210. * or this fragment came after RTS/CTS.
  211. */
  212. if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
  213. txdesc->u.plcp.ifs = IFS_BACKOFF;
  214. else
  215. txdesc->u.plcp.ifs = IFS_SIFS;
  216. /* Data length + CRC + Crypto overhead (IV/EIV/ICV/MIC) */
  217. data_length = entry->skb->len + 4;
  218. data_length += rt2x00crypto_tx_overhead(rt2x00dev, entry->skb);
  219. /*
  220. * PLCP setup
  221. * Length calculation depends on OFDM/CCK rate.
  222. */
  223. txdesc->u.plcp.signal = hwrate->plcp;
  224. txdesc->u.plcp.service = 0x04;
  225. if (hwrate->flags & DEV_RATE_OFDM) {
  226. txdesc->u.plcp.length_high = (data_length >> 6) & 0x3f;
  227. txdesc->u.plcp.length_low = data_length & 0x3f;
  228. } else {
  229. /*
  230. * Convert length to microseconds.
  231. */
  232. residual = GET_DURATION_RES(data_length, hwrate->bitrate);
  233. duration = GET_DURATION(data_length, hwrate->bitrate);
  234. if (residual != 0) {
  235. duration++;
  236. /*
  237. * Check if we need to set the Length Extension
  238. */
  239. if (hwrate->bitrate == 110 && residual <= 30)
  240. txdesc->u.plcp.service |= 0x80;
  241. }
  242. txdesc->u.plcp.length_high = (duration >> 8) & 0xff;
  243. txdesc->u.plcp.length_low = duration & 0xff;
  244. /*
  245. * When preamble is enabled we should set the
  246. * preamble bit for the signal.
  247. */
  248. if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  249. txdesc->u.plcp.signal |= 0x08;
  250. }
  251. }
  252. static void rt2x00queue_create_tx_descriptor_ht(struct queue_entry *entry,
  253. struct txentry_desc *txdesc,
  254. const struct rt2x00_rate *hwrate)
  255. {
  256. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
  257. struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
  258. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)entry->skb->data;
  259. if (tx_info->control.sta)
  260. txdesc->u.ht.mpdu_density =
  261. tx_info->control.sta->ht_cap.ampdu_density;
  262. txdesc->u.ht.ba_size = 7; /* FIXME: What value is needed? */
  263. /*
  264. * Only one STBC stream is supported for now.
  265. */
  266. if (tx_info->flags & IEEE80211_TX_CTL_STBC)
  267. txdesc->u.ht.stbc = 1;
  268. /*
  269. * If IEEE80211_TX_RC_MCS is set txrate->idx just contains the
  270. * mcs rate to be used
  271. */
  272. if (txrate->flags & IEEE80211_TX_RC_MCS) {
  273. txdesc->u.ht.mcs = txrate->idx;
  274. /*
  275. * MIMO PS should be set to 1 for STA's using dynamic SM PS
  276. * when using more then one tx stream (>MCS7).
  277. */
  278. if (tx_info->control.sta && txdesc->u.ht.mcs > 7 &&
  279. ((tx_info->control.sta->ht_cap.cap &
  280. IEEE80211_HT_CAP_SM_PS) >>
  281. IEEE80211_HT_CAP_SM_PS_SHIFT) ==
  282. WLAN_HT_CAP_SM_PS_DYNAMIC)
  283. __set_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags);
  284. } else {
  285. txdesc->u.ht.mcs = rt2x00_get_rate_mcs(hwrate->mcs);
  286. if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  287. txdesc->u.ht.mcs |= 0x08;
  288. }
  289. /*
  290. * This frame is eligible for an AMPDU, however, don't aggregate
  291. * frames that are intended to probe a specific tx rate.
  292. */
  293. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU &&
  294. !(tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE))
  295. __set_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags);
  296. /*
  297. * Set 40Mhz mode if necessary (for legacy rates this will
  298. * duplicate the frame to both channels).
  299. */
  300. if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH ||
  301. txrate->flags & IEEE80211_TX_RC_DUP_DATA)
  302. __set_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags);
  303. if (txrate->flags & IEEE80211_TX_RC_SHORT_GI)
  304. __set_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags);
  305. /*
  306. * Determine IFS values
  307. * - Use TXOP_BACKOFF for management frames except beacons
  308. * - Use TXOP_SIFS for fragment bursts
  309. * - Use TXOP_HTTXOP for everything else
  310. *
  311. * Note: rt2800 devices won't use CTS protection (if used)
  312. * for frames not transmitted with TXOP_HTTXOP
  313. */
  314. if (ieee80211_is_mgmt(hdr->frame_control) &&
  315. !ieee80211_is_beacon(hdr->frame_control))
  316. txdesc->u.ht.txop = TXOP_BACKOFF;
  317. else if (!(tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT))
  318. txdesc->u.ht.txop = TXOP_SIFS;
  319. else
  320. txdesc->u.ht.txop = TXOP_HTTXOP;
  321. }
  322. static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
  323. struct txentry_desc *txdesc)
  324. {
  325. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  326. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
  327. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)entry->skb->data;
  328. struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
  329. struct ieee80211_rate *rate;
  330. const struct rt2x00_rate *hwrate = NULL;
  331. memset(txdesc, 0, sizeof(*txdesc));
  332. /*
  333. * Header and frame information.
  334. */
  335. txdesc->length = entry->skb->len;
  336. txdesc->header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
  337. /*
  338. * Check whether this frame is to be acked.
  339. */
  340. if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK))
  341. __set_bit(ENTRY_TXD_ACK, &txdesc->flags);
  342. /*
  343. * Check if this is a RTS/CTS frame
  344. */
  345. if (ieee80211_is_rts(hdr->frame_control) ||
  346. ieee80211_is_cts(hdr->frame_control)) {
  347. __set_bit(ENTRY_TXD_BURST, &txdesc->flags);
  348. if (ieee80211_is_rts(hdr->frame_control))
  349. __set_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags);
  350. else
  351. __set_bit(ENTRY_TXD_CTS_FRAME, &txdesc->flags);
  352. if (tx_info->control.rts_cts_rate_idx >= 0)
  353. rate =
  354. ieee80211_get_rts_cts_rate(rt2x00dev->hw, tx_info);
  355. }
  356. /*
  357. * Determine retry information.
  358. */
  359. txdesc->retry_limit = tx_info->control.rates[0].count - 1;
  360. if (txdesc->retry_limit >= rt2x00dev->long_retry)
  361. __set_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags);
  362. /*
  363. * Check if more fragments are pending
  364. */
  365. if (ieee80211_has_morefrags(hdr->frame_control)) {
  366. __set_bit(ENTRY_TXD_BURST, &txdesc->flags);
  367. __set_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags);
  368. }
  369. /*
  370. * Check if more frames (!= fragments) are pending
  371. */
  372. if (tx_info->flags & IEEE80211_TX_CTL_MORE_FRAMES)
  373. __set_bit(ENTRY_TXD_BURST, &txdesc->flags);
  374. /*
  375. * Beacons and probe responses require the tsf timestamp
  376. * to be inserted into the frame.
  377. */
  378. if (ieee80211_is_beacon(hdr->frame_control) ||
  379. ieee80211_is_probe_resp(hdr->frame_control))
  380. __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags);
  381. if ((tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) &&
  382. !test_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags))
  383. __set_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags);
  384. /*
  385. * Determine rate modulation.
  386. */
  387. if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD)
  388. txdesc->rate_mode = RATE_MODE_HT_GREENFIELD;
  389. else if (txrate->flags & IEEE80211_TX_RC_MCS)
  390. txdesc->rate_mode = RATE_MODE_HT_MIX;
  391. else {
  392. rate = ieee80211_get_tx_rate(rt2x00dev->hw, tx_info);
  393. hwrate = rt2x00_get_rate(rate->hw_value);
  394. if (hwrate->flags & DEV_RATE_OFDM)
  395. txdesc->rate_mode = RATE_MODE_OFDM;
  396. else
  397. txdesc->rate_mode = RATE_MODE_CCK;
  398. }
  399. /*
  400. * Apply TX descriptor handling by components
  401. */
  402. rt2x00crypto_create_tx_descriptor(entry, txdesc);
  403. rt2x00queue_create_tx_descriptor_seq(entry, txdesc);
  404. if (test_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags))
  405. rt2x00queue_create_tx_descriptor_ht(entry, txdesc, hwrate);
  406. else
  407. rt2x00queue_create_tx_descriptor_plcp(entry, txdesc, hwrate);
  408. }
  409. static int rt2x00queue_write_tx_data(struct queue_entry *entry,
  410. struct txentry_desc *txdesc)
  411. {
  412. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  413. /*
  414. * This should not happen, we already checked the entry
  415. * was ours. When the hardware disagrees there has been
  416. * a queue corruption!
  417. */
  418. if (unlikely(rt2x00dev->ops->lib->get_entry_state &&
  419. rt2x00dev->ops->lib->get_entry_state(entry))) {
  420. ERROR(rt2x00dev,
  421. "Corrupt queue %d, accessing entry which is not ours.\n"
  422. "Please file bug report to %s.\n",
  423. entry->queue->qid, DRV_PROJECT);
  424. return -EINVAL;
  425. }
  426. /*
  427. * Add the requested extra tx headroom in front of the skb.
  428. */
  429. skb_push(entry->skb, rt2x00dev->ops->extra_tx_headroom);
  430. memset(entry->skb->data, 0, rt2x00dev->ops->extra_tx_headroom);
  431. /*
  432. * Call the driver's write_tx_data function, if it exists.
  433. */
  434. if (rt2x00dev->ops->lib->write_tx_data)
  435. rt2x00dev->ops->lib->write_tx_data(entry, txdesc);
  436. /*
  437. * Map the skb to DMA.
  438. */
  439. if (test_bit(REQUIRE_DMA, &rt2x00dev->cap_flags))
  440. rt2x00queue_map_txskb(entry);
  441. return 0;
  442. }
  443. static void rt2x00queue_write_tx_descriptor(struct queue_entry *entry,
  444. struct txentry_desc *txdesc)
  445. {
  446. struct data_queue *queue = entry->queue;
  447. queue->rt2x00dev->ops->lib->write_tx_desc(entry, txdesc);
  448. /*
  449. * All processing on the frame has been completed, this means
  450. * it is now ready to be dumped to userspace through debugfs.
  451. */
  452. rt2x00debug_dump_frame(queue->rt2x00dev, DUMP_FRAME_TX, entry->skb);
  453. }
  454. static void rt2x00queue_kick_tx_queue(struct data_queue *queue,
  455. struct txentry_desc *txdesc)
  456. {
  457. /*
  458. * Check if we need to kick the queue, there are however a few rules
  459. * 1) Don't kick unless this is the last in frame in a burst.
  460. * When the burst flag is set, this frame is always followed
  461. * by another frame which in some way are related to eachother.
  462. * This is true for fragments, RTS or CTS-to-self frames.
  463. * 2) Rule 1 can be broken when the available entries
  464. * in the queue are less then a certain threshold.
  465. */
  466. if (rt2x00queue_threshold(queue) ||
  467. !test_bit(ENTRY_TXD_BURST, &txdesc->flags))
  468. queue->rt2x00dev->ops->lib->kick_queue(queue);
  469. }
  470. int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
  471. bool local)
  472. {
  473. struct ieee80211_tx_info *tx_info;
  474. struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
  475. struct txentry_desc txdesc;
  476. struct skb_frame_desc *skbdesc;
  477. u8 rate_idx, rate_flags;
  478. if (unlikely(rt2x00queue_full(queue))) {
  479. ERROR(queue->rt2x00dev,
  480. "Dropping frame due to full tx queue %d.\n", queue->qid);
  481. return -ENOBUFS;
  482. }
  483. if (unlikely(test_and_set_bit(ENTRY_OWNER_DEVICE_DATA,
  484. &entry->flags))) {
  485. ERROR(queue->rt2x00dev,
  486. "Arrived at non-free entry in the non-full queue %d.\n"
  487. "Please file bug report to %s.\n",
  488. queue->qid, DRV_PROJECT);
  489. return -EINVAL;
  490. }
  491. /*
  492. * Copy all TX descriptor information into txdesc,
  493. * after that we are free to use the skb->cb array
  494. * for our information.
  495. */
  496. entry->skb = skb;
  497. rt2x00queue_create_tx_descriptor(entry, &txdesc);
  498. /*
  499. * All information is retrieved from the skb->cb array,
  500. * now we should claim ownership of the driver part of that
  501. * array, preserving the bitrate index and flags.
  502. */
  503. tx_info = IEEE80211_SKB_CB(skb);
  504. rate_idx = tx_info->control.rates[0].idx;
  505. rate_flags = tx_info->control.rates[0].flags;
  506. skbdesc = get_skb_frame_desc(skb);
  507. memset(skbdesc, 0, sizeof(*skbdesc));
  508. skbdesc->entry = entry;
  509. skbdesc->tx_rate_idx = rate_idx;
  510. skbdesc->tx_rate_flags = rate_flags;
  511. if (local)
  512. skbdesc->flags |= SKBDESC_NOT_MAC80211;
  513. /*
  514. * When hardware encryption is supported, and this frame
  515. * is to be encrypted, we should strip the IV/EIV data from
  516. * the frame so we can provide it to the driver separately.
  517. */
  518. if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) &&
  519. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags)) {
  520. if (test_bit(REQUIRE_COPY_IV, &queue->rt2x00dev->cap_flags))
  521. rt2x00crypto_tx_copy_iv(skb, &txdesc);
  522. else
  523. rt2x00crypto_tx_remove_iv(skb, &txdesc);
  524. }
  525. /*
  526. * When DMA allocation is required we should guarantee to the
  527. * driver that the DMA is aligned to a 4-byte boundary.
  528. * However some drivers require L2 padding to pad the payload
  529. * rather then the header. This could be a requirement for
  530. * PCI and USB devices, while header alignment only is valid
  531. * for PCI devices.
  532. */
  533. if (test_bit(REQUIRE_L2PAD, &queue->rt2x00dev->cap_flags))
  534. rt2x00queue_insert_l2pad(entry->skb, txdesc.header_length);
  535. else if (test_bit(REQUIRE_DMA, &queue->rt2x00dev->cap_flags))
  536. rt2x00queue_align_frame(entry->skb);
  537. /*
  538. * It could be possible that the queue was corrupted and this
  539. * call failed. Since we always return NETDEV_TX_OK to mac80211,
  540. * this frame will simply be dropped.
  541. */
  542. if (unlikely(rt2x00queue_write_tx_data(entry, &txdesc))) {
  543. clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
  544. entry->skb = NULL;
  545. return -EIO;
  546. }
  547. set_bit(ENTRY_DATA_PENDING, &entry->flags);
  548. rt2x00queue_index_inc(entry, Q_INDEX);
  549. rt2x00queue_write_tx_descriptor(entry, &txdesc);
  550. rt2x00queue_kick_tx_queue(queue, &txdesc);
  551. return 0;
  552. }
  553. int rt2x00queue_clear_beacon(struct rt2x00_dev *rt2x00dev,
  554. struct ieee80211_vif *vif)
  555. {
  556. struct rt2x00_intf *intf = vif_to_intf(vif);
  557. if (unlikely(!intf->beacon))
  558. return -ENOBUFS;
  559. mutex_lock(&intf->beacon_skb_mutex);
  560. /*
  561. * Clean up the beacon skb.
  562. */
  563. rt2x00queue_free_skb(intf->beacon);
  564. /*
  565. * Clear beacon (single bssid devices don't need to clear the beacon
  566. * since the beacon queue will get stopped anyway).
  567. */
  568. if (rt2x00dev->ops->lib->clear_beacon)
  569. rt2x00dev->ops->lib->clear_beacon(intf->beacon);
  570. mutex_unlock(&intf->beacon_skb_mutex);
  571. return 0;
  572. }
  573. int rt2x00queue_update_beacon_locked(struct rt2x00_dev *rt2x00dev,
  574. struct ieee80211_vif *vif)
  575. {
  576. struct rt2x00_intf *intf = vif_to_intf(vif);
  577. struct skb_frame_desc *skbdesc;
  578. struct txentry_desc txdesc;
  579. if (unlikely(!intf->beacon))
  580. return -ENOBUFS;
  581. /*
  582. * Clean up the beacon skb.
  583. */
  584. rt2x00queue_free_skb(intf->beacon);
  585. intf->beacon->skb = ieee80211_beacon_get(rt2x00dev->hw, vif);
  586. if (!intf->beacon->skb)
  587. return -ENOMEM;
  588. /*
  589. * Copy all TX descriptor information into txdesc,
  590. * after that we are free to use the skb->cb array
  591. * for our information.
  592. */
  593. rt2x00queue_create_tx_descriptor(intf->beacon, &txdesc);
  594. /*
  595. * Fill in skb descriptor
  596. */
  597. skbdesc = get_skb_frame_desc(intf->beacon->skb);
  598. memset(skbdesc, 0, sizeof(*skbdesc));
  599. skbdesc->entry = intf->beacon;
  600. /*
  601. * Send beacon to hardware.
  602. */
  603. rt2x00dev->ops->lib->write_beacon(intf->beacon, &txdesc);
  604. return 0;
  605. }
  606. int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
  607. struct ieee80211_vif *vif)
  608. {
  609. struct rt2x00_intf *intf = vif_to_intf(vif);
  610. int ret;
  611. mutex_lock(&intf->beacon_skb_mutex);
  612. ret = rt2x00queue_update_beacon_locked(rt2x00dev, vif);
  613. mutex_unlock(&intf->beacon_skb_mutex);
  614. return ret;
  615. }
  616. bool rt2x00queue_for_each_entry(struct data_queue *queue,
  617. enum queue_index start,
  618. enum queue_index end,
  619. void *data,
  620. bool (*fn)(struct queue_entry *entry,
  621. void *data))
  622. {
  623. unsigned long irqflags;
  624. unsigned int index_start;
  625. unsigned int index_end;
  626. unsigned int i;
  627. if (unlikely(start >= Q_INDEX_MAX || end >= Q_INDEX_MAX)) {
  628. ERROR(queue->rt2x00dev,
  629. "Entry requested from invalid index range (%d - %d)\n",
  630. start, end);
  631. return true;
  632. }
  633. /*
  634. * Only protect the range we are going to loop over,
  635. * if during our loop a extra entry is set to pending
  636. * it should not be kicked during this run, since it
  637. * is part of another TX operation.
  638. */
  639. spin_lock_irqsave(&queue->index_lock, irqflags);
  640. index_start = queue->index[start];
  641. index_end = queue->index[end];
  642. spin_unlock_irqrestore(&queue->index_lock, irqflags);
  643. /*
  644. * Start from the TX done pointer, this guarantees that we will
  645. * send out all frames in the correct order.
  646. */
  647. if (index_start < index_end) {
  648. for (i = index_start; i < index_end; i++) {
  649. if (fn(&queue->entries[i], data))
  650. return true;
  651. }
  652. } else {
  653. for (i = index_start; i < queue->limit; i++) {
  654. if (fn(&queue->entries[i], data))
  655. return true;
  656. }
  657. for (i = 0; i < index_end; i++) {
  658. if (fn(&queue->entries[i], data))
  659. return true;
  660. }
  661. }
  662. return false;
  663. }
  664. EXPORT_SYMBOL_GPL(rt2x00queue_for_each_entry);
  665. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  666. enum queue_index index)
  667. {
  668. struct queue_entry *entry;
  669. unsigned long irqflags;
  670. if (unlikely(index >= Q_INDEX_MAX)) {
  671. ERROR(queue->rt2x00dev,
  672. "Entry requested from invalid index type (%d)\n", index);
  673. return NULL;
  674. }
  675. spin_lock_irqsave(&queue->index_lock, irqflags);
  676. entry = &queue->entries[queue->index[index]];
  677. spin_unlock_irqrestore(&queue->index_lock, irqflags);
  678. return entry;
  679. }
  680. EXPORT_SYMBOL_GPL(rt2x00queue_get_entry);
  681. void rt2x00queue_index_inc(struct queue_entry *entry, enum queue_index index)
  682. {
  683. struct data_queue *queue = entry->queue;
  684. unsigned long irqflags;
  685. if (unlikely(index >= Q_INDEX_MAX)) {
  686. ERROR(queue->rt2x00dev,
  687. "Index change on invalid index type (%d)\n", index);
  688. return;
  689. }
  690. spin_lock_irqsave(&queue->index_lock, irqflags);
  691. queue->index[index]++;
  692. if (queue->index[index] >= queue->limit)
  693. queue->index[index] = 0;
  694. entry->last_action = jiffies;
  695. if (index == Q_INDEX) {
  696. queue->length++;
  697. } else if (index == Q_INDEX_DONE) {
  698. queue->length--;
  699. queue->count++;
  700. }
  701. spin_unlock_irqrestore(&queue->index_lock, irqflags);
  702. }
  703. void rt2x00queue_pause_queue(struct data_queue *queue)
  704. {
  705. if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
  706. !test_bit(QUEUE_STARTED, &queue->flags) ||
  707. test_and_set_bit(QUEUE_PAUSED, &queue->flags))
  708. return;
  709. switch (queue->qid) {
  710. case QID_AC_VO:
  711. case QID_AC_VI:
  712. case QID_AC_BE:
  713. case QID_AC_BK:
  714. /*
  715. * For TX queues, we have to disable the queue
  716. * inside mac80211.
  717. */
  718. ieee80211_stop_queue(queue->rt2x00dev->hw, queue->qid);
  719. break;
  720. default:
  721. break;
  722. }
  723. }
  724. EXPORT_SYMBOL_GPL(rt2x00queue_pause_queue);
  725. void rt2x00queue_unpause_queue(struct data_queue *queue)
  726. {
  727. if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
  728. !test_bit(QUEUE_STARTED, &queue->flags) ||
  729. !test_and_clear_bit(QUEUE_PAUSED, &queue->flags))
  730. return;
  731. switch (queue->qid) {
  732. case QID_AC_VO:
  733. case QID_AC_VI:
  734. case QID_AC_BE:
  735. case QID_AC_BK:
  736. /*
  737. * For TX queues, we have to enable the queue
  738. * inside mac80211.
  739. */
  740. ieee80211_wake_queue(queue->rt2x00dev->hw, queue->qid);
  741. break;
  742. case QID_RX:
  743. /*
  744. * For RX we need to kick the queue now in order to
  745. * receive frames.
  746. */
  747. queue->rt2x00dev->ops->lib->kick_queue(queue);
  748. default:
  749. break;
  750. }
  751. }
  752. EXPORT_SYMBOL_GPL(rt2x00queue_unpause_queue);
  753. void rt2x00queue_start_queue(struct data_queue *queue)
  754. {
  755. mutex_lock(&queue->status_lock);
  756. if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
  757. test_and_set_bit(QUEUE_STARTED, &queue->flags)) {
  758. mutex_unlock(&queue->status_lock);
  759. return;
  760. }
  761. set_bit(QUEUE_PAUSED, &queue->flags);
  762. queue->rt2x00dev->ops->lib->start_queue(queue);
  763. rt2x00queue_unpause_queue(queue);
  764. mutex_unlock(&queue->status_lock);
  765. }
  766. EXPORT_SYMBOL_GPL(rt2x00queue_start_queue);
  767. void rt2x00queue_stop_queue(struct data_queue *queue)
  768. {
  769. mutex_lock(&queue->status_lock);
  770. if (!test_and_clear_bit(QUEUE_STARTED, &queue->flags)) {
  771. mutex_unlock(&queue->status_lock);
  772. return;
  773. }
  774. rt2x00queue_pause_queue(queue);
  775. queue->rt2x00dev->ops->lib->stop_queue(queue);
  776. mutex_unlock(&queue->status_lock);
  777. }
  778. EXPORT_SYMBOL_GPL(rt2x00queue_stop_queue);
  779. void rt2x00queue_flush_queue(struct data_queue *queue, bool drop)
  780. {
  781. bool started;
  782. bool tx_queue =
  783. (queue->qid == QID_AC_VO) ||
  784. (queue->qid == QID_AC_VI) ||
  785. (queue->qid == QID_AC_BE) ||
  786. (queue->qid == QID_AC_BK);
  787. mutex_lock(&queue->status_lock);
  788. /*
  789. * If the queue has been started, we must stop it temporarily
  790. * to prevent any new frames to be queued on the device. If
  791. * we are not dropping the pending frames, the queue must
  792. * only be stopped in the software and not the hardware,
  793. * otherwise the queue will never become empty on its own.
  794. */
  795. started = test_bit(QUEUE_STARTED, &queue->flags);
  796. if (started) {
  797. /*
  798. * Pause the queue
  799. */
  800. rt2x00queue_pause_queue(queue);
  801. /*
  802. * If we are not supposed to drop any pending
  803. * frames, this means we must force a start (=kick)
  804. * to the queue to make sure the hardware will
  805. * start transmitting.
  806. */
  807. if (!drop && tx_queue)
  808. queue->rt2x00dev->ops->lib->kick_queue(queue);
  809. }
  810. /*
  811. * Check if driver supports flushing, if that is the case we can
  812. * defer the flushing to the driver. Otherwise we must use the
  813. * alternative which just waits for the queue to become empty.
  814. */
  815. if (likely(queue->rt2x00dev->ops->lib->flush_queue))
  816. queue->rt2x00dev->ops->lib->flush_queue(queue, drop);
  817. /*
  818. * The queue flush has failed...
  819. */
  820. if (unlikely(!rt2x00queue_empty(queue)))
  821. WARNING(queue->rt2x00dev, "Queue %d failed to flush\n", queue->qid);
  822. /*
  823. * Restore the queue to the previous status
  824. */
  825. if (started)
  826. rt2x00queue_unpause_queue(queue);
  827. mutex_unlock(&queue->status_lock);
  828. }
  829. EXPORT_SYMBOL_GPL(rt2x00queue_flush_queue);
  830. void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev)
  831. {
  832. struct data_queue *queue;
  833. /*
  834. * rt2x00queue_start_queue will call ieee80211_wake_queue
  835. * for each queue after is has been properly initialized.
  836. */
  837. tx_queue_for_each(rt2x00dev, queue)
  838. rt2x00queue_start_queue(queue);
  839. rt2x00queue_start_queue(rt2x00dev->rx);
  840. }
  841. EXPORT_SYMBOL_GPL(rt2x00queue_start_queues);
  842. void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev)
  843. {
  844. struct data_queue *queue;
  845. /*
  846. * rt2x00queue_stop_queue will call ieee80211_stop_queue
  847. * as well, but we are completely shutting doing everything
  848. * now, so it is much safer to stop all TX queues at once,
  849. * and use rt2x00queue_stop_queue for cleaning up.
  850. */
  851. ieee80211_stop_queues(rt2x00dev->hw);
  852. tx_queue_for_each(rt2x00dev, queue)
  853. rt2x00queue_stop_queue(queue);
  854. rt2x00queue_stop_queue(rt2x00dev->rx);
  855. }
  856. EXPORT_SYMBOL_GPL(rt2x00queue_stop_queues);
  857. void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop)
  858. {
  859. struct data_queue *queue;
  860. tx_queue_for_each(rt2x00dev, queue)
  861. rt2x00queue_flush_queue(queue, drop);
  862. rt2x00queue_flush_queue(rt2x00dev->rx, drop);
  863. }
  864. EXPORT_SYMBOL_GPL(rt2x00queue_flush_queues);
  865. static void rt2x00queue_reset(struct data_queue *queue)
  866. {
  867. unsigned long irqflags;
  868. unsigned int i;
  869. spin_lock_irqsave(&queue->index_lock, irqflags);
  870. queue->count = 0;
  871. queue->length = 0;
  872. for (i = 0; i < Q_INDEX_MAX; i++)
  873. queue->index[i] = 0;
  874. spin_unlock_irqrestore(&queue->index_lock, irqflags);
  875. }
  876. void rt2x00queue_init_queues(struct rt2x00_dev *rt2x00dev)
  877. {
  878. struct data_queue *queue;
  879. unsigned int i;
  880. queue_for_each(rt2x00dev, queue) {
  881. rt2x00queue_reset(queue);
  882. for (i = 0; i < queue->limit; i++)
  883. rt2x00dev->ops->lib->clear_entry(&queue->entries[i]);
  884. }
  885. }
  886. static int rt2x00queue_alloc_entries(struct data_queue *queue,
  887. const struct data_queue_desc *qdesc)
  888. {
  889. struct queue_entry *entries;
  890. unsigned int entry_size;
  891. unsigned int i;
  892. rt2x00queue_reset(queue);
  893. queue->limit = qdesc->entry_num;
  894. queue->threshold = DIV_ROUND_UP(qdesc->entry_num, 10);
  895. queue->data_size = qdesc->data_size;
  896. queue->desc_size = qdesc->desc_size;
  897. /*
  898. * Allocate all queue entries.
  899. */
  900. entry_size = sizeof(*entries) + qdesc->priv_size;
  901. entries = kcalloc(queue->limit, entry_size, GFP_KERNEL);
  902. if (!entries)
  903. return -ENOMEM;
  904. #define QUEUE_ENTRY_PRIV_OFFSET(__base, __index, __limit, __esize, __psize) \
  905. (((char *)(__base)) + ((__limit) * (__esize)) + \
  906. ((__index) * (__psize)))
  907. for (i = 0; i < queue->limit; i++) {
  908. entries[i].flags = 0;
  909. entries[i].queue = queue;
  910. entries[i].skb = NULL;
  911. entries[i].entry_idx = i;
  912. entries[i].priv_data =
  913. QUEUE_ENTRY_PRIV_OFFSET(entries, i, queue->limit,
  914. sizeof(*entries), qdesc->priv_size);
  915. }
  916. #undef QUEUE_ENTRY_PRIV_OFFSET
  917. queue->entries = entries;
  918. return 0;
  919. }
  920. static void rt2x00queue_free_skbs(struct data_queue *queue)
  921. {
  922. unsigned int i;
  923. if (!queue->entries)
  924. return;
  925. for (i = 0; i < queue->limit; i++) {
  926. rt2x00queue_free_skb(&queue->entries[i]);
  927. }
  928. }
  929. static int rt2x00queue_alloc_rxskbs(struct data_queue *queue)
  930. {
  931. unsigned int i;
  932. struct sk_buff *skb;
  933. for (i = 0; i < queue->limit; i++) {
  934. skb = rt2x00queue_alloc_rxskb(&queue->entries[i]);
  935. if (!skb)
  936. return -ENOMEM;
  937. queue->entries[i].skb = skb;
  938. }
  939. return 0;
  940. }
  941. int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev)
  942. {
  943. struct data_queue *queue;
  944. int status;
  945. status = rt2x00queue_alloc_entries(rt2x00dev->rx, rt2x00dev->ops->rx);
  946. if (status)
  947. goto exit;
  948. tx_queue_for_each(rt2x00dev, queue) {
  949. status = rt2x00queue_alloc_entries(queue, rt2x00dev->ops->tx);
  950. if (status)
  951. goto exit;
  952. }
  953. status = rt2x00queue_alloc_entries(rt2x00dev->bcn, rt2x00dev->ops->bcn);
  954. if (status)
  955. goto exit;
  956. if (test_bit(REQUIRE_ATIM_QUEUE, &rt2x00dev->cap_flags)) {
  957. status = rt2x00queue_alloc_entries(rt2x00dev->atim,
  958. rt2x00dev->ops->atim);
  959. if (status)
  960. goto exit;
  961. }
  962. status = rt2x00queue_alloc_rxskbs(rt2x00dev->rx);
  963. if (status)
  964. goto exit;
  965. return 0;
  966. exit:
  967. ERROR(rt2x00dev, "Queue entries allocation failed.\n");
  968. rt2x00queue_uninitialize(rt2x00dev);
  969. return status;
  970. }
  971. void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev)
  972. {
  973. struct data_queue *queue;
  974. rt2x00queue_free_skbs(rt2x00dev->rx);
  975. queue_for_each(rt2x00dev, queue) {
  976. kfree(queue->entries);
  977. queue->entries = NULL;
  978. }
  979. }
  980. static void rt2x00queue_init(struct rt2x00_dev *rt2x00dev,
  981. struct data_queue *queue, enum data_queue_qid qid)
  982. {
  983. mutex_init(&queue->status_lock);
  984. spin_lock_init(&queue->index_lock);
  985. queue->rt2x00dev = rt2x00dev;
  986. queue->qid = qid;
  987. queue->txop = 0;
  988. queue->aifs = 2;
  989. queue->cw_min = 5;
  990. queue->cw_max = 10;
  991. }
  992. int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev)
  993. {
  994. struct data_queue *queue;
  995. enum data_queue_qid qid;
  996. unsigned int req_atim =
  997. !!test_bit(REQUIRE_ATIM_QUEUE, &rt2x00dev->cap_flags);
  998. /*
  999. * We need the following queues:
  1000. * RX: 1
  1001. * TX: ops->tx_queues
  1002. * Beacon: 1
  1003. * Atim: 1 (if required)
  1004. */
  1005. rt2x00dev->data_queues = 2 + rt2x00dev->ops->tx_queues + req_atim;
  1006. queue = kcalloc(rt2x00dev->data_queues, sizeof(*queue), GFP_KERNEL);
  1007. if (!queue) {
  1008. ERROR(rt2x00dev, "Queue allocation failed.\n");
  1009. return -ENOMEM;
  1010. }
  1011. /*
  1012. * Initialize pointers
  1013. */
  1014. rt2x00dev->rx = queue;
  1015. rt2x00dev->tx = &queue[1];
  1016. rt2x00dev->bcn = &queue[1 + rt2x00dev->ops->tx_queues];
  1017. rt2x00dev->atim = req_atim ? &queue[2 + rt2x00dev->ops->tx_queues] : NULL;
  1018. /*
  1019. * Initialize queue parameters.
  1020. * RX: qid = QID_RX
  1021. * TX: qid = QID_AC_VO + index
  1022. * TX: cw_min: 2^5 = 32.
  1023. * TX: cw_max: 2^10 = 1024.
  1024. * BCN: qid = QID_BEACON
  1025. * ATIM: qid = QID_ATIM
  1026. */
  1027. rt2x00queue_init(rt2x00dev, rt2x00dev->rx, QID_RX);
  1028. qid = QID_AC_VO;
  1029. tx_queue_for_each(rt2x00dev, queue)
  1030. rt2x00queue_init(rt2x00dev, queue, qid++);
  1031. rt2x00queue_init(rt2x00dev, rt2x00dev->bcn, QID_BEACON);
  1032. if (req_atim)
  1033. rt2x00queue_init(rt2x00dev, rt2x00dev->atim, QID_ATIM);
  1034. return 0;
  1035. }
  1036. void rt2x00queue_free(struct rt2x00_dev *rt2x00dev)
  1037. {
  1038. kfree(rt2x00dev->rx);
  1039. rt2x00dev->rx = NULL;
  1040. rt2x00dev->tx = NULL;
  1041. rt2x00dev->bcn = NULL;
  1042. }