rt2x00queue.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00
  19. Abstract: rt2x00 queue datastructures and routines
  20. */
  21. #ifndef RT2X00QUEUE_H
  22. #define RT2X00QUEUE_H
  23. #include <linux/prefetch.h>
  24. /**
  25. * DOC: Entry frame size
  26. *
  27. * Ralink PCI devices demand the Frame size to be a multiple of 128 bytes,
  28. * for USB devices this restriction does not apply, but the value of
  29. * 2432 makes sense since it is big enough to contain the maximum fragment
  30. * size according to the ieee802.11 specs.
  31. * The aggregation size depends on support from the driver, but should
  32. * be something around 3840 bytes.
  33. */
  34. #define DATA_FRAME_SIZE 2432
  35. #define MGMT_FRAME_SIZE 256
  36. #define AGGREGATION_SIZE 3840
  37. /**
  38. * DOC: Number of entries per queue
  39. *
  40. * Under normal load without fragmentation, 12 entries are sufficient
  41. * without the queue being filled up to the maximum. When using fragmentation
  42. * and the queue threshold code, we need to add some additional margins to
  43. * make sure the queue will never (or only under extreme load) fill up
  44. * completely.
  45. * Since we don't use preallocated DMA, having a large number of queue entries
  46. * will have minimal impact on the memory requirements for the queue.
  47. */
  48. #define RX_ENTRIES 24
  49. #define TX_ENTRIES 24
  50. #define BEACON_ENTRIES 1
  51. #define ATIM_ENTRIES 8
  52. /**
  53. * enum data_queue_qid: Queue identification
  54. *
  55. * @QID_AC_BE: AC BE queue
  56. * @QID_AC_BK: AC BK queue
  57. * @QID_AC_VI: AC VI queue
  58. * @QID_AC_VO: AC VO queue
  59. * @QID_HCCA: HCCA queue
  60. * @QID_MGMT: MGMT queue (prio queue)
  61. * @QID_RX: RX queue
  62. * @QID_OTHER: None of the above (don't use, only present for completeness)
  63. * @QID_BEACON: Beacon queue (value unspecified, don't send it to device)
  64. * @QID_ATIM: Atim queue (value unspeficied, don't send it to device)
  65. */
  66. enum data_queue_qid {
  67. QID_AC_BE = 0,
  68. QID_AC_BK = 1,
  69. QID_AC_VI = 2,
  70. QID_AC_VO = 3,
  71. QID_HCCA = 4,
  72. QID_MGMT = 13,
  73. QID_RX = 14,
  74. QID_OTHER = 15,
  75. QID_BEACON,
  76. QID_ATIM,
  77. };
  78. /**
  79. * enum skb_frame_desc_flags: Flags for &struct skb_frame_desc
  80. *
  81. * @SKBDESC_DMA_MAPPED_RX: &skb_dma field has been mapped for RX
  82. * @SKBDESC_DMA_MAPPED_TX: &skb_dma field has been mapped for TX
  83. * @SKBDESC_IV_STRIPPED: Frame contained a IV/EIV provided by
  84. * mac80211 but was stripped for processing by the driver.
  85. * @SKBDESC_NOT_MAC80211: Frame didn't originate from mac80211,
  86. * don't try to pass it back.
  87. * @SKBDESC_DESC_IN_SKB: The descriptor is at the start of the
  88. * skb, instead of in the desc field.
  89. */
  90. enum skb_frame_desc_flags {
  91. SKBDESC_DMA_MAPPED_RX = 1 << 0,
  92. SKBDESC_DMA_MAPPED_TX = 1 << 1,
  93. SKBDESC_IV_STRIPPED = 1 << 2,
  94. SKBDESC_NOT_MAC80211 = 1 << 3,
  95. SKBDESC_DESC_IN_SKB = 1 << 4,
  96. };
  97. /**
  98. * struct skb_frame_desc: Descriptor information for the skb buffer
  99. *
  100. * This structure is placed over the driver_data array, this means that
  101. * this structure should not exceed the size of that array (40 bytes).
  102. *
  103. * @flags: Frame flags, see &enum skb_frame_desc_flags.
  104. * @desc_len: Length of the frame descriptor.
  105. * @tx_rate_idx: the index of the TX rate, used for TX status reporting
  106. * @tx_rate_flags: the TX rate flags, used for TX status reporting
  107. * @desc: Pointer to descriptor part of the frame.
  108. * Note that this pointer could point to something outside
  109. * of the scope of the skb->data pointer.
  110. * @iv: IV/EIV data used during encryption/decryption.
  111. * @skb_dma: (PCI-only) the DMA address associated with the sk buffer.
  112. * @entry: The entry to which this sk buffer belongs.
  113. */
  114. struct skb_frame_desc {
  115. u8 flags;
  116. u8 desc_len;
  117. u8 tx_rate_idx;
  118. u8 tx_rate_flags;
  119. void *desc;
  120. __le32 iv[2];
  121. dma_addr_t skb_dma;
  122. struct queue_entry *entry;
  123. };
  124. /**
  125. * get_skb_frame_desc - Obtain the rt2x00 frame descriptor from a sk_buff.
  126. * @skb: &struct sk_buff from where we obtain the &struct skb_frame_desc
  127. */
  128. static inline struct skb_frame_desc* get_skb_frame_desc(struct sk_buff *skb)
  129. {
  130. BUILD_BUG_ON(sizeof(struct skb_frame_desc) >
  131. IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
  132. return (struct skb_frame_desc *)&IEEE80211_SKB_CB(skb)->driver_data;
  133. }
  134. /**
  135. * enum rxdone_entry_desc_flags: Flags for &struct rxdone_entry_desc
  136. *
  137. * @RXDONE_SIGNAL_PLCP: Signal field contains the plcp value.
  138. * @RXDONE_SIGNAL_BITRATE: Signal field contains the bitrate value.
  139. * @RXDONE_SIGNAL_MCS: Signal field contains the mcs value.
  140. * @RXDONE_MY_BSS: Does this frame originate from device's BSS.
  141. * @RXDONE_CRYPTO_IV: Driver provided IV/EIV data.
  142. * @RXDONE_CRYPTO_ICV: Driver provided ICV data.
  143. * @RXDONE_L2PAD: 802.11 payload has been padded to 4-byte boundary.
  144. */
  145. enum rxdone_entry_desc_flags {
  146. RXDONE_SIGNAL_PLCP = BIT(0),
  147. RXDONE_SIGNAL_BITRATE = BIT(1),
  148. RXDONE_SIGNAL_MCS = BIT(2),
  149. RXDONE_MY_BSS = BIT(3),
  150. RXDONE_CRYPTO_IV = BIT(4),
  151. RXDONE_CRYPTO_ICV = BIT(5),
  152. RXDONE_L2PAD = BIT(6),
  153. };
  154. /**
  155. * RXDONE_SIGNAL_MASK - Define to mask off all &rxdone_entry_desc_flags flags
  156. * except for the RXDONE_SIGNAL_* flags. This is useful to convert the dev_flags
  157. * from &rxdone_entry_desc to a signal value type.
  158. */
  159. #define RXDONE_SIGNAL_MASK \
  160. ( RXDONE_SIGNAL_PLCP | RXDONE_SIGNAL_BITRATE | RXDONE_SIGNAL_MCS )
  161. /**
  162. * struct rxdone_entry_desc: RX Entry descriptor
  163. *
  164. * Summary of information that has been read from the RX frame descriptor.
  165. *
  166. * @timestamp: RX Timestamp
  167. * @signal: Signal of the received frame.
  168. * @rssi: RSSI of the received frame.
  169. * @size: Data size of the received frame.
  170. * @flags: MAC80211 receive flags (See &enum mac80211_rx_flags).
  171. * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags).
  172. * @rate_mode: Rate mode (See @enum rate_modulation).
  173. * @cipher: Cipher type used during decryption.
  174. * @cipher_status: Decryption status.
  175. * @iv: IV/EIV data used during decryption.
  176. * @icv: ICV data used during decryption.
  177. */
  178. struct rxdone_entry_desc {
  179. u64 timestamp;
  180. int signal;
  181. int rssi;
  182. int size;
  183. int flags;
  184. int dev_flags;
  185. u16 rate_mode;
  186. u8 cipher;
  187. u8 cipher_status;
  188. __le32 iv[2];
  189. __le32 icv;
  190. };
  191. /**
  192. * enum txdone_entry_desc_flags: Flags for &struct txdone_entry_desc
  193. *
  194. * Every txdone report has to contain the basic result of the
  195. * transmission, either &TXDONE_UNKNOWN, &TXDONE_SUCCESS or
  196. * &TXDONE_FAILURE. The flag &TXDONE_FALLBACK can be used in
  197. * conjunction with all of these flags but should only be set
  198. * if retires > 0. The flag &TXDONE_EXCESSIVE_RETRY can only be used
  199. * in conjunction with &TXDONE_FAILURE.
  200. *
  201. * @TXDONE_UNKNOWN: Hardware could not determine success of transmission.
  202. * @TXDONE_SUCCESS: Frame was successfully send
  203. * @TXDONE_FALLBACK: Hardware used fallback rates for retries
  204. * @TXDONE_FAILURE: Frame was not successfully send
  205. * @TXDONE_EXCESSIVE_RETRY: In addition to &TXDONE_FAILURE, the
  206. * frame transmission failed due to excessive retries.
  207. */
  208. enum txdone_entry_desc_flags {
  209. TXDONE_UNKNOWN,
  210. TXDONE_SUCCESS,
  211. TXDONE_FALLBACK,
  212. TXDONE_FAILURE,
  213. TXDONE_EXCESSIVE_RETRY,
  214. };
  215. /**
  216. * struct txdone_entry_desc: TX done entry descriptor
  217. *
  218. * Summary of information that has been read from the TX frame descriptor
  219. * after the device is done with transmission.
  220. *
  221. * @flags: TX done flags (See &enum txdone_entry_desc_flags).
  222. * @retry: Retry count.
  223. */
  224. struct txdone_entry_desc {
  225. unsigned long flags;
  226. int retry;
  227. };
  228. /**
  229. * enum txentry_desc_flags: Status flags for TX entry descriptor
  230. *
  231. * @ENTRY_TXD_RTS_FRAME: This frame is a RTS frame.
  232. * @ENTRY_TXD_CTS_FRAME: This frame is a CTS-to-self frame.
  233. * @ENTRY_TXD_GENERATE_SEQ: This frame requires sequence counter.
  234. * @ENTRY_TXD_FIRST_FRAGMENT: This is the first frame.
  235. * @ENTRY_TXD_MORE_FRAG: This frame is followed by another fragment.
  236. * @ENTRY_TXD_REQ_TIMESTAMP: Require timestamp to be inserted.
  237. * @ENTRY_TXD_BURST: This frame belongs to the same burst event.
  238. * @ENTRY_TXD_ACK: An ACK is required for this frame.
  239. * @ENTRY_TXD_RETRY_MODE: When set, the long retry count is used.
  240. * @ENTRY_TXD_ENCRYPT: This frame should be encrypted.
  241. * @ENTRY_TXD_ENCRYPT_PAIRWISE: Use pairwise key table (instead of shared).
  242. * @ENTRY_TXD_ENCRYPT_IV: Generate IV/EIV in hardware.
  243. * @ENTRY_TXD_ENCRYPT_MMIC: Generate MIC in hardware.
  244. * @ENTRY_TXD_HT_AMPDU: This frame is part of an AMPDU.
  245. * @ENTRY_TXD_HT_BW_40: Use 40MHz Bandwidth.
  246. * @ENTRY_TXD_HT_SHORT_GI: Use short GI.
  247. * @ENTRY_TXD_HT_MIMO_PS: The receiving STA is in dynamic SM PS mode.
  248. */
  249. enum txentry_desc_flags {
  250. ENTRY_TXD_RTS_FRAME,
  251. ENTRY_TXD_CTS_FRAME,
  252. ENTRY_TXD_GENERATE_SEQ,
  253. ENTRY_TXD_FIRST_FRAGMENT,
  254. ENTRY_TXD_MORE_FRAG,
  255. ENTRY_TXD_REQ_TIMESTAMP,
  256. ENTRY_TXD_BURST,
  257. ENTRY_TXD_ACK,
  258. ENTRY_TXD_RETRY_MODE,
  259. ENTRY_TXD_ENCRYPT,
  260. ENTRY_TXD_ENCRYPT_PAIRWISE,
  261. ENTRY_TXD_ENCRYPT_IV,
  262. ENTRY_TXD_ENCRYPT_MMIC,
  263. ENTRY_TXD_HT_AMPDU,
  264. ENTRY_TXD_HT_BW_40,
  265. ENTRY_TXD_HT_SHORT_GI,
  266. ENTRY_TXD_HT_MIMO_PS,
  267. };
  268. /**
  269. * struct txentry_desc: TX Entry descriptor
  270. *
  271. * Summary of information for the frame descriptor before sending a TX frame.
  272. *
  273. * @flags: Descriptor flags (See &enum queue_entry_flags).
  274. * @qid: Queue identification (See &enum data_queue_qid).
  275. * @length: Length of the entire frame.
  276. * @header_length: Length of 802.11 header.
  277. * @length_high: PLCP length high word.
  278. * @length_low: PLCP length low word.
  279. * @signal: PLCP signal.
  280. * @service: PLCP service.
  281. * @msc: MCS.
  282. * @stbc: STBC.
  283. * @ba_size: BA size.
  284. * @rate_mode: Rate mode (See @enum rate_modulation).
  285. * @mpdu_density: MDPU density.
  286. * @retry_limit: Max number of retries.
  287. * @aifs: AIFS value.
  288. * @ifs: IFS value.
  289. * @txop: IFS value for 11n capable chips.
  290. * @cw_min: cwmin value.
  291. * @cw_max: cwmax value.
  292. * @cipher: Cipher type used for encryption.
  293. * @key_idx: Key index used for encryption.
  294. * @iv_offset: Position where IV should be inserted by hardware.
  295. * @iv_len: Length of IV data.
  296. */
  297. struct txentry_desc {
  298. unsigned long flags;
  299. enum data_queue_qid qid;
  300. u16 length;
  301. u16 header_length;
  302. u16 length_high;
  303. u16 length_low;
  304. u16 signal;
  305. u16 service;
  306. u16 mcs;
  307. u16 stbc;
  308. u16 ba_size;
  309. u16 rate_mode;
  310. u16 mpdu_density;
  311. short retry_limit;
  312. short aifs;
  313. short ifs;
  314. short txop;
  315. short cw_min;
  316. short cw_max;
  317. enum cipher cipher;
  318. u16 key_idx;
  319. u16 iv_offset;
  320. u16 iv_len;
  321. };
  322. /**
  323. * enum queue_entry_flags: Status flags for queue entry
  324. *
  325. * @ENTRY_BCN_ASSIGNED: This entry has been assigned to an interface.
  326. * As long as this bit is set, this entry may only be touched
  327. * through the interface structure.
  328. * @ENTRY_OWNER_DEVICE_DATA: This entry is owned by the device for data
  329. * transfer (either TX or RX depending on the queue). The entry should
  330. * only be touched after the device has signaled it is done with it.
  331. * @ENTRY_DATA_PENDING: This entry contains a valid frame and is waiting
  332. * for the signal to start sending.
  333. * @ENTRY_DATA_IO_FAILED: Hardware indicated that an IO error occured
  334. * while transfering the data to the hardware. No TX status report will
  335. * be expected from the hardware.
  336. */
  337. enum queue_entry_flags {
  338. ENTRY_BCN_ASSIGNED,
  339. ENTRY_OWNER_DEVICE_DATA,
  340. ENTRY_DATA_PENDING,
  341. ENTRY_DATA_IO_FAILED
  342. };
  343. /**
  344. * struct queue_entry: Entry inside the &struct data_queue
  345. *
  346. * @flags: Entry flags, see &enum queue_entry_flags.
  347. * @queue: The data queue (&struct data_queue) to which this entry belongs.
  348. * @skb: The buffer which is currently being transmitted (for TX queue),
  349. * or used to directly recieve data in (for RX queue).
  350. * @entry_idx: The entry index number.
  351. * @priv_data: Private data belonging to this queue entry. The pointer
  352. * points to data specific to a particular driver and queue type.
  353. */
  354. struct queue_entry {
  355. unsigned long flags;
  356. struct data_queue *queue;
  357. struct sk_buff *skb;
  358. unsigned int entry_idx;
  359. void *priv_data;
  360. };
  361. /**
  362. * enum queue_index: Queue index type
  363. *
  364. * @Q_INDEX: Index pointer to the current entry in the queue, if this entry is
  365. * owned by the hardware then the queue is considered to be full.
  366. * @Q_INDEX_DMA_DONE: Index pointer for the next entry which will have been
  367. * transfered to the hardware.
  368. * @Q_INDEX_DONE: Index pointer to the next entry which will be completed by
  369. * the hardware and for which we need to run the txdone handler. If this
  370. * entry is not owned by the hardware the queue is considered to be empty.
  371. * @Q_INDEX_MAX: Keep last, used in &struct data_queue to determine the size
  372. * of the index array.
  373. */
  374. enum queue_index {
  375. Q_INDEX,
  376. Q_INDEX_DMA_DONE,
  377. Q_INDEX_DONE,
  378. Q_INDEX_MAX,
  379. };
  380. /**
  381. * struct data_queue: Data queue
  382. *
  383. * @rt2x00dev: Pointer to main &struct rt2x00dev where this queue belongs to.
  384. * @entries: Base address of the &struct queue_entry which are
  385. * part of this queue.
  386. * @qid: The queue identification, see &enum data_queue_qid.
  387. * @lock: Spinlock to protect index handling. Whenever @index, @index_done or
  388. * @index_crypt needs to be changed this lock should be grabbed to prevent
  389. * index corruption due to concurrency.
  390. * @count: Number of frames handled in the queue.
  391. * @limit: Maximum number of entries in the queue.
  392. * @threshold: Minimum number of free entries before queue is kicked by force.
  393. * @length: Number of frames in queue.
  394. * @index: Index pointers to entry positions in the queue,
  395. * use &enum queue_index to get a specific index field.
  396. * @txop: maximum burst time.
  397. * @aifs: The aifs value for outgoing frames (field ignored in RX queue).
  398. * @cw_min: The cw min value for outgoing frames (field ignored in RX queue).
  399. * @cw_max: The cw max value for outgoing frames (field ignored in RX queue).
  400. * @data_size: Maximum data size for the frames in this queue.
  401. * @desc_size: Hardware descriptor size for the data in this queue.
  402. * @usb_endpoint: Device endpoint used for communication (USB only)
  403. * @usb_maxpacket: Max packet size for given endpoint (USB only)
  404. */
  405. struct data_queue {
  406. struct rt2x00_dev *rt2x00dev;
  407. struct queue_entry *entries;
  408. enum data_queue_qid qid;
  409. spinlock_t lock;
  410. unsigned int count;
  411. unsigned short limit;
  412. unsigned short threshold;
  413. unsigned short length;
  414. unsigned short index[Q_INDEX_MAX];
  415. unsigned long last_action[Q_INDEX_MAX];
  416. unsigned short txop;
  417. unsigned short aifs;
  418. unsigned short cw_min;
  419. unsigned short cw_max;
  420. unsigned short data_size;
  421. unsigned short desc_size;
  422. unsigned short usb_endpoint;
  423. unsigned short usb_maxpacket;
  424. };
  425. /**
  426. * struct data_queue_desc: Data queue description
  427. *
  428. * The information in this structure is used by drivers
  429. * to inform rt2x00lib about the creation of the data queue.
  430. *
  431. * @entry_num: Maximum number of entries for a queue.
  432. * @data_size: Maximum data size for the frames in this queue.
  433. * @desc_size: Hardware descriptor size for the data in this queue.
  434. * @priv_size: Size of per-queue_entry private data.
  435. */
  436. struct data_queue_desc {
  437. unsigned short entry_num;
  438. unsigned short data_size;
  439. unsigned short desc_size;
  440. unsigned short priv_size;
  441. };
  442. /**
  443. * queue_end - Return pointer to the last queue (HELPER MACRO).
  444. * @__dev: Pointer to &struct rt2x00_dev
  445. *
  446. * Using the base rx pointer and the maximum number of available queues,
  447. * this macro will return the address of 1 position beyond the end of the
  448. * queues array.
  449. */
  450. #define queue_end(__dev) \
  451. &(__dev)->rx[(__dev)->data_queues]
  452. /**
  453. * tx_queue_end - Return pointer to the last TX queue (HELPER MACRO).
  454. * @__dev: Pointer to &struct rt2x00_dev
  455. *
  456. * Using the base tx pointer and the maximum number of available TX
  457. * queues, this macro will return the address of 1 position beyond
  458. * the end of the TX queue array.
  459. */
  460. #define tx_queue_end(__dev) \
  461. &(__dev)->tx[(__dev)->ops->tx_queues]
  462. /**
  463. * queue_next - Return pointer to next queue in list (HELPER MACRO).
  464. * @__queue: Current queue for which we need the next queue
  465. *
  466. * Using the current queue address we take the address directly
  467. * after the queue to take the next queue. Note that this macro
  468. * should be used carefully since it does not protect against
  469. * moving past the end of the list. (See macros &queue_end and
  470. * &tx_queue_end for determining the end of the queue).
  471. */
  472. #define queue_next(__queue) \
  473. &(__queue)[1]
  474. /**
  475. * queue_loop - Loop through the queues within a specific range (HELPER MACRO).
  476. * @__entry: Pointer where the current queue entry will be stored in.
  477. * @__start: Start queue pointer.
  478. * @__end: End queue pointer.
  479. *
  480. * This macro will loop through all queues between &__start and &__end.
  481. */
  482. #define queue_loop(__entry, __start, __end) \
  483. for ((__entry) = (__start); \
  484. prefetch(queue_next(__entry)), (__entry) != (__end);\
  485. (__entry) = queue_next(__entry))
  486. /**
  487. * queue_for_each - Loop through all queues
  488. * @__dev: Pointer to &struct rt2x00_dev
  489. * @__entry: Pointer where the current queue entry will be stored in.
  490. *
  491. * This macro will loop through all available queues.
  492. */
  493. #define queue_for_each(__dev, __entry) \
  494. queue_loop(__entry, (__dev)->rx, queue_end(__dev))
  495. /**
  496. * tx_queue_for_each - Loop through the TX queues
  497. * @__dev: Pointer to &struct rt2x00_dev
  498. * @__entry: Pointer where the current queue entry will be stored in.
  499. *
  500. * This macro will loop through all TX related queues excluding
  501. * the Beacon and Atim queues.
  502. */
  503. #define tx_queue_for_each(__dev, __entry) \
  504. queue_loop(__entry, (__dev)->tx, tx_queue_end(__dev))
  505. /**
  506. * txall_queue_for_each - Loop through all TX related queues
  507. * @__dev: Pointer to &struct rt2x00_dev
  508. * @__entry: Pointer where the current queue entry will be stored in.
  509. *
  510. * This macro will loop through all TX related queues including
  511. * the Beacon and Atim queues.
  512. */
  513. #define txall_queue_for_each(__dev, __entry) \
  514. queue_loop(__entry, (__dev)->tx, queue_end(__dev))
  515. /**
  516. * rt2x00queue_for_each_entry - Loop through all entries in the queue
  517. * @queue: Pointer to @data_queue
  518. * @start: &enum queue_index Pointer to start index
  519. * @end: &enum queue_index Pointer to end index
  520. * @fn: The function to call for each &struct queue_entry
  521. *
  522. * This will walk through all entries in the queue, in chronological
  523. * order. This means it will start at the current @start pointer
  524. * and will walk through the queue until it reaches the @end pointer.
  525. */
  526. void rt2x00queue_for_each_entry(struct data_queue *queue,
  527. enum queue_index start,
  528. enum queue_index end,
  529. void (*fn)(struct queue_entry *entry));
  530. /**
  531. * rt2x00queue_empty - Check if the queue is empty.
  532. * @queue: Queue to check if empty.
  533. */
  534. static inline int rt2x00queue_empty(struct data_queue *queue)
  535. {
  536. return queue->length == 0;
  537. }
  538. /**
  539. * rt2x00queue_full - Check if the queue is full.
  540. * @queue: Queue to check if full.
  541. */
  542. static inline int rt2x00queue_full(struct data_queue *queue)
  543. {
  544. return queue->length == queue->limit;
  545. }
  546. /**
  547. * rt2x00queue_free - Check the number of available entries in queue.
  548. * @queue: Queue to check.
  549. */
  550. static inline int rt2x00queue_available(struct data_queue *queue)
  551. {
  552. return queue->limit - queue->length;
  553. }
  554. /**
  555. * rt2x00queue_threshold - Check if the queue is below threshold
  556. * @queue: Queue to check.
  557. */
  558. static inline int rt2x00queue_threshold(struct data_queue *queue)
  559. {
  560. return rt2x00queue_available(queue) < queue->threshold;
  561. }
  562. /**
  563. * rt2x00queue_timeout - Check if a timeout occured for STATUS reorts
  564. * @queue: Queue to check.
  565. */
  566. static inline int rt2x00queue_timeout(struct data_queue *queue)
  567. {
  568. return time_after(queue->last_action[Q_INDEX_DMA_DONE],
  569. queue->last_action[Q_INDEX_DONE] + (HZ / 10));
  570. }
  571. /**
  572. * rt2x00queue_timeout - Check if a timeout occured for DMA transfers
  573. * @queue: Queue to check.
  574. */
  575. static inline int rt2x00queue_dma_timeout(struct data_queue *queue)
  576. {
  577. return time_after(queue->last_action[Q_INDEX],
  578. queue->last_action[Q_INDEX_DMA_DONE] + (HZ / 10));
  579. }
  580. /**
  581. * _rt2x00_desc_read - Read a word from the hardware descriptor.
  582. * @desc: Base descriptor address
  583. * @word: Word index from where the descriptor should be read.
  584. * @value: Address where the descriptor value should be written into.
  585. */
  586. static inline void _rt2x00_desc_read(__le32 *desc, const u8 word, __le32 *value)
  587. {
  588. *value = desc[word];
  589. }
  590. /**
  591. * rt2x00_desc_read - Read a word from the hardware descriptor, this
  592. * function will take care of the byte ordering.
  593. * @desc: Base descriptor address
  594. * @word: Word index from where the descriptor should be read.
  595. * @value: Address where the descriptor value should be written into.
  596. */
  597. static inline void rt2x00_desc_read(__le32 *desc, const u8 word, u32 *value)
  598. {
  599. __le32 tmp;
  600. _rt2x00_desc_read(desc, word, &tmp);
  601. *value = le32_to_cpu(tmp);
  602. }
  603. /**
  604. * rt2x00_desc_write - write a word to the hardware descriptor, this
  605. * function will take care of the byte ordering.
  606. * @desc: Base descriptor address
  607. * @word: Word index from where the descriptor should be written.
  608. * @value: Value that should be written into the descriptor.
  609. */
  610. static inline void _rt2x00_desc_write(__le32 *desc, const u8 word, __le32 value)
  611. {
  612. desc[word] = value;
  613. }
  614. /**
  615. * rt2x00_desc_write - write a word to the hardware descriptor.
  616. * @desc: Base descriptor address
  617. * @word: Word index from where the descriptor should be written.
  618. * @value: Value that should be written into the descriptor.
  619. */
  620. static inline void rt2x00_desc_write(__le32 *desc, const u8 word, u32 value)
  621. {
  622. _rt2x00_desc_write(desc, word, cpu_to_le32(value));
  623. }
  624. #endif /* RT2X00QUEUE_H */