rt2x00queue.h 21 KB

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