rt2x00queue.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  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: Entrie 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. */
  32. #define DATA_FRAME_SIZE 2432
  33. #define MGMT_FRAME_SIZE 256
  34. /**
  35. * DOC: Number of entries per queue
  36. *
  37. * After research it was concluded that 12 entries in a RX and TX
  38. * queue would be sufficient. Although this is almost one third of
  39. * the amount the legacy driver allocated, the queues aren't getting
  40. * filled to the maximum even when working with the maximum rate.
  41. */
  42. #define RX_ENTRIES 12
  43. #define TX_ENTRIES 12
  44. #define BEACON_ENTRIES 1
  45. #define ATIM_ENTRIES 1
  46. /**
  47. * enum data_queue_qid: Queue identification
  48. *
  49. * @QID_AC_BE: AC BE queue
  50. * @QID_AC_BK: AC BK queue
  51. * @QID_AC_VI: AC VI queue
  52. * @QID_AC_VO: AC VO queue
  53. * @QID_HCCA: HCCA queue
  54. * @QID_MGMT: MGMT queue (prio queue)
  55. * @QID_RX: RX queue
  56. * @QID_OTHER: None of the above (don't use, only present for completeness)
  57. * @QID_BEACON: Beacon queue (value unspecified, don't send it to device)
  58. * @QID_ATIM: Atim queue (value unspeficied, don't send it to device)
  59. */
  60. enum data_queue_qid {
  61. QID_AC_BE = 0,
  62. QID_AC_BK = 1,
  63. QID_AC_VI = 2,
  64. QID_AC_VO = 3,
  65. QID_HCCA = 4,
  66. QID_MGMT = 13,
  67. QID_RX = 14,
  68. QID_OTHER = 15,
  69. QID_BEACON,
  70. QID_ATIM,
  71. };
  72. /**
  73. * mac80211_queue_to_qid - Convert mac80211 queue to rt2x00 qid
  74. * @queue: mac80211 queue.
  75. */
  76. static inline enum data_queue_qid mac80211_queue_to_qid(unsigned int queue)
  77. {
  78. /* Regular TX queues are mapped directly */
  79. if (queue < 4)
  80. return queue;
  81. WARN_ON(1);
  82. return QID_OTHER;
  83. }
  84. /**
  85. * enum skb_frame_desc_flags: Flags for &struct skb_frame_desc
  86. *
  87. * @FRAME_DESC_DRIVER_GENERATED: Frame was generated inside driver
  88. * and should not be reported back to mac80211 during txdone.
  89. */
  90. enum skb_frame_desc_flags {
  91. FRAME_DESC_DRIVER_GENERATED = 1 << 0,
  92. };
  93. /**
  94. * struct skb_frame_desc: Descriptor information for the skb buffer
  95. *
  96. * This structure is placed over the skb->cb array, this means that
  97. * this structure should not exceed the size of that array (48 bytes).
  98. *
  99. * @flags: Frame flags, see &enum skb_frame_desc_flags.
  100. * @data: Pointer to data part of frame (Start of ieee80211 header).
  101. * @desc: Pointer to descriptor part of the frame.
  102. * Note that this pointer could point to something outside
  103. * of the scope of the skb->data pointer.
  104. * @data_len: Length of the frame data.
  105. * @desc_len: Length of the frame descriptor.
  106. * @entry: The entry to which this sk buffer belongs.
  107. */
  108. struct skb_frame_desc {
  109. unsigned int flags;
  110. unsigned short data_len;
  111. unsigned short desc_len;
  112. void *data;
  113. void *desc;
  114. struct queue_entry *entry;
  115. };
  116. static inline struct skb_frame_desc* get_skb_frame_desc(struct sk_buff *skb)
  117. {
  118. BUILD_BUG_ON(sizeof(struct skb_frame_desc) > sizeof(skb->cb));
  119. return (struct skb_frame_desc *)&skb->cb[0];
  120. }
  121. /**
  122. * enum rxdone_entry_desc_flags: Flags for &struct rxdone_entry_desc
  123. *
  124. * @RXDONE_SIGNAL_PLCP: Does the signal field contain the plcp value,
  125. * or does it contain the bitrate itself.
  126. * @RXDONE_MY_BSS: Does this frame originate from device's BSS.
  127. */
  128. enum rxdone_entry_desc_flags {
  129. RXDONE_SIGNAL_PLCP = 1 << 0,
  130. RXDONE_MY_BSS = 1 << 1,
  131. };
  132. /**
  133. * struct rxdone_entry_desc: RX Entry descriptor
  134. *
  135. * Summary of information that has been read from the RX frame descriptor.
  136. *
  137. * @signal: Signal of the received frame.
  138. * @rssi: RSSI of the received frame.
  139. * @size: Data size of the received frame.
  140. * @flags: MAC80211 receive flags (See &enum mac80211_rx_flags).
  141. * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags).
  142. */
  143. struct rxdone_entry_desc {
  144. int signal;
  145. int rssi;
  146. int size;
  147. int flags;
  148. int dev_flags;
  149. };
  150. /**
  151. * struct txdone_entry_desc: TX done entry descriptor
  152. *
  153. * Summary of information that has been read from the TX frame descriptor
  154. * after the device is done with transmission.
  155. *
  156. * @control: Control structure which was used to transmit the frame.
  157. * @status: TX status (See &enum tx_status).
  158. * @retry: Retry count.
  159. */
  160. struct txdone_entry_desc {
  161. struct ieee80211_tx_control *control;
  162. int status;
  163. int retry;
  164. };
  165. /**
  166. * enum txentry_desc_flags: Status flags for TX entry descriptor
  167. *
  168. * @ENTRY_TXD_RTS_FRAME: This frame is a RTS frame.
  169. * @ENTRY_TXD_OFDM_RATE: This frame is send out with an OFDM rate.
  170. * @ENTRY_TXD_MORE_FRAG: This frame is followed by another fragment.
  171. * @ENTRY_TXD_REQ_TIMESTAMP: Require timestamp to be inserted.
  172. * @ENTRY_TXD_BURST: This frame belongs to the same burst event.
  173. * @ENTRY_TXD_ACK: An ACK is required for this frame.
  174. */
  175. enum txentry_desc_flags {
  176. ENTRY_TXD_RTS_FRAME,
  177. ENTRY_TXD_OFDM_RATE,
  178. ENTRY_TXD_MORE_FRAG,
  179. ENTRY_TXD_REQ_TIMESTAMP,
  180. ENTRY_TXD_BURST,
  181. ENTRY_TXD_ACK,
  182. };
  183. /**
  184. * struct txentry_desc: TX Entry descriptor
  185. *
  186. * Summary of information for the frame descriptor before sending a TX frame.
  187. *
  188. * @flags: Descriptor flags (See &enum queue_entry_flags).
  189. * @queue: Queue identification (See &enum data_queue_qid).
  190. * @length_high: PLCP length high word.
  191. * @length_low: PLCP length low word.
  192. * @signal: PLCP signal.
  193. * @service: PLCP service.
  194. * @aifs: AIFS value.
  195. * @ifs: IFS value.
  196. * @cw_min: cwmin value.
  197. * @cw_max: cwmax value.
  198. */
  199. struct txentry_desc {
  200. unsigned long flags;
  201. enum data_queue_qid queue;
  202. u16 length_high;
  203. u16 length_low;
  204. u16 signal;
  205. u16 service;
  206. int aifs;
  207. int ifs;
  208. int cw_min;
  209. int cw_max;
  210. };
  211. /**
  212. * enum queue_entry_flags: Status flags for queue entry
  213. *
  214. * @ENTRY_BCN_ASSIGNED: This entry has been assigned to an interface.
  215. * As long as this bit is set, this entry may only be touched
  216. * through the interface structure.
  217. * @ENTRY_OWNER_DEVICE_DATA: This entry is owned by the device for data
  218. * transfer (either TX or RX depending on the queue). The entry should
  219. * only be touched after the device has signaled it is done with it.
  220. * @ENTRY_OWNER_DEVICE_CRYPTO: This entry is owned by the device for data
  221. * encryption or decryption. The entry should only be touched after
  222. * the device has signaled it is done with it.
  223. */
  224. enum queue_entry_flags {
  225. ENTRY_BCN_ASSIGNED,
  226. ENTRY_OWNER_DEVICE_DATA,
  227. ENTRY_OWNER_DEVICE_CRYPTO,
  228. };
  229. /**
  230. * struct queue_entry: Entry inside the &struct data_queue
  231. *
  232. * @flags: Entry flags, see &enum queue_entry_flags.
  233. * @queue: The data queue (&struct data_queue) to which this entry belongs.
  234. * @skb: The buffer which is currently being transmitted (for TX queue),
  235. * or used to directly recieve data in (for RX queue).
  236. * @entry_idx: The entry index number.
  237. * @priv_data: Private data belonging to this queue entry. The pointer
  238. * points to data specific to a particular driver and queue type.
  239. */
  240. struct queue_entry {
  241. unsigned long flags;
  242. struct data_queue *queue;
  243. struct sk_buff *skb;
  244. unsigned int entry_idx;
  245. void *priv_data;
  246. };
  247. /**
  248. * enum queue_index: Queue index type
  249. *
  250. * @Q_INDEX: Index pointer to the current entry in the queue, if this entry is
  251. * owned by the hardware then the queue is considered to be full.
  252. * @Q_INDEX_DONE: Index pointer to the next entry which will be completed by
  253. * the hardware and for which we need to run the txdone handler. If this
  254. * entry is not owned by the hardware the queue is considered to be empty.
  255. * @Q_INDEX_CRYPTO: Index pointer to the next entry which encryption/decription
  256. * will be completed by the hardware next.
  257. * @Q_INDEX_MAX: Keep last, used in &struct data_queue to determine the size
  258. * of the index array.
  259. */
  260. enum queue_index {
  261. Q_INDEX,
  262. Q_INDEX_DONE,
  263. Q_INDEX_CRYPTO,
  264. Q_INDEX_MAX,
  265. };
  266. /**
  267. * struct data_queue: Data queue
  268. *
  269. * @rt2x00dev: Pointer to main &struct rt2x00dev where this queue belongs to.
  270. * @entries: Base address of the &struct queue_entry which are
  271. * part of this queue.
  272. * @qid: The queue identification, see &enum data_queue_qid.
  273. * @lock: Spinlock to protect index handling. Whenever @index, @index_done or
  274. * @index_crypt needs to be changed this lock should be grabbed to prevent
  275. * index corruption due to concurrency.
  276. * @count: Number of frames handled in the queue.
  277. * @limit: Maximum number of entries in the queue.
  278. * @length: Number of frames in queue.
  279. * @index: Index pointers to entry positions in the queue,
  280. * use &enum queue_index to get a specific index field.
  281. * @aifs: The aifs value for outgoing frames (field ignored in RX queue).
  282. * @cw_min: The cw min value for outgoing frames (field ignored in RX queue).
  283. * @cw_max: The cw max value for outgoing frames (field ignored in RX queue).
  284. * @data_size: Maximum data size for the frames in this queue.
  285. * @desc_size: Hardware descriptor size for the data in this queue.
  286. */
  287. struct data_queue {
  288. struct rt2x00_dev *rt2x00dev;
  289. struct queue_entry *entries;
  290. enum data_queue_qid qid;
  291. spinlock_t lock;
  292. unsigned int count;
  293. unsigned short limit;
  294. unsigned short length;
  295. unsigned short index[Q_INDEX_MAX];
  296. unsigned short aifs;
  297. unsigned short cw_min;
  298. unsigned short cw_max;
  299. unsigned short data_size;
  300. unsigned short desc_size;
  301. };
  302. /**
  303. * struct data_queue_desc: Data queue description
  304. *
  305. * The information in this structure is used by drivers
  306. * to inform rt2x00lib about the creation of the data queue.
  307. *
  308. * @entry_num: Maximum number of entries for a queue.
  309. * @data_size: Maximum data size for the frames in this queue.
  310. * @desc_size: Hardware descriptor size for the data in this queue.
  311. * @priv_size: Size of per-queue_entry private data.
  312. */
  313. struct data_queue_desc {
  314. unsigned short entry_num;
  315. unsigned short data_size;
  316. unsigned short desc_size;
  317. unsigned short priv_size;
  318. };
  319. /**
  320. * queue_end - Return pointer to the last queue (HELPER MACRO).
  321. * @__dev: Pointer to &struct rt2x00_dev
  322. *
  323. * Using the base rx pointer and the maximum number of available queues,
  324. * this macro will return the address of 1 position beyond the end of the
  325. * queues array.
  326. */
  327. #define queue_end(__dev) \
  328. &(__dev)->rx[(__dev)->data_queues]
  329. /**
  330. * tx_queue_end - Return pointer to the last TX queue (HELPER MACRO).
  331. * @__dev: Pointer to &struct rt2x00_dev
  332. *
  333. * Using the base tx pointer and the maximum number of available TX
  334. * queues, this macro will return the address of 1 position beyond
  335. * the end of the TX queue array.
  336. */
  337. #define tx_queue_end(__dev) \
  338. &(__dev)->tx[(__dev)->hw->queues]
  339. /**
  340. * queue_loop - Loop through the queues within a specific range (HELPER MACRO).
  341. * @__entry: Pointer where the current queue entry will be stored in.
  342. * @__start: Start queue pointer.
  343. * @__end: End queue pointer.
  344. *
  345. * This macro will loop through all queues between &__start and &__end.
  346. */
  347. #define queue_loop(__entry, __start, __end) \
  348. for ((__entry) = (__start); \
  349. prefetch(&(__entry)[1]), (__entry) != (__end); \
  350. (__entry) = &(__entry)[1])
  351. /**
  352. * queue_for_each - Loop through all queues
  353. * @__dev: Pointer to &struct rt2x00_dev
  354. * @__entry: Pointer where the current queue entry will be stored in.
  355. *
  356. * This macro will loop through all available queues.
  357. */
  358. #define queue_for_each(__dev, __entry) \
  359. queue_loop(__entry, (__dev)->rx, queue_end(__dev))
  360. /**
  361. * tx_queue_for_each - Loop through the TX queues
  362. * @__dev: Pointer to &struct rt2x00_dev
  363. * @__entry: Pointer where the current queue entry will be stored in.
  364. *
  365. * This macro will loop through all TX related queues excluding
  366. * the Beacon and Atim queues.
  367. */
  368. #define tx_queue_for_each(__dev, __entry) \
  369. queue_loop(__entry, (__dev)->tx, tx_queue_end(__dev))
  370. /**
  371. * txall_queue_for_each - Loop through all TX related queues
  372. * @__dev: Pointer to &struct rt2x00_dev
  373. * @__entry: Pointer where the current queue entry will be stored in.
  374. *
  375. * This macro will loop through all TX related queues including
  376. * the Beacon and Atim queues.
  377. */
  378. #define txall_queue_for_each(__dev, __entry) \
  379. queue_loop(__entry, (__dev)->tx, queue_end(__dev))
  380. /**
  381. * rt2x00queue_empty - Check if the queue is empty.
  382. * @queue: Queue to check if empty.
  383. */
  384. static inline int rt2x00queue_empty(struct data_queue *queue)
  385. {
  386. return queue->length == 0;
  387. }
  388. /**
  389. * rt2x00queue_full - Check if the queue is full.
  390. * @queue: Queue to check if full.
  391. */
  392. static inline int rt2x00queue_full(struct data_queue *queue)
  393. {
  394. return queue->length == queue->limit;
  395. }
  396. /**
  397. * rt2x00queue_free - Check the number of available entries in queue.
  398. * @queue: Queue to check.
  399. */
  400. static inline int rt2x00queue_available(struct data_queue *queue)
  401. {
  402. return queue->limit - queue->length;
  403. }
  404. /**
  405. * rt2x00_desc_read - Read a word from the hardware descriptor.
  406. * @desc: Base descriptor address
  407. * @word: Word index from where the descriptor should be read.
  408. * @value: Address where the descriptor value should be written into.
  409. */
  410. static inline void rt2x00_desc_read(__le32 *desc, const u8 word, u32 *value)
  411. {
  412. *value = le32_to_cpu(desc[word]);
  413. }
  414. /**
  415. * rt2x00_desc_write - wrote a word to the hardware descriptor.
  416. * @desc: Base descriptor address
  417. * @word: Word index from where the descriptor should be written.
  418. * @value: Value that should be written into the descriptor.
  419. */
  420. static inline void rt2x00_desc_write(__le32 *desc, const u8 word, u32 value)
  421. {
  422. desc[word] = cpu_to_le32(value);
  423. }
  424. #endif /* RT2X00QUEUE_H */