rt2x00queue.h 13 KB

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