rt2x00ring.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. Copyright (C) 2004 - 2007 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 ring datastructures and routines
  20. */
  21. #ifndef RT2X00RING_H
  22. #define RT2X00RING_H
  23. /*
  24. * skb_desc
  25. * Descriptor information for the skb buffer
  26. */
  27. struct skb_desc {
  28. unsigned int frame_type;
  29. unsigned int desc_len;
  30. unsigned int data_len;
  31. void *desc;
  32. void *data;
  33. struct data_ring *ring;
  34. struct data_entry *entry;
  35. };
  36. static inline struct skb_desc* get_skb_desc(struct sk_buff *skb)
  37. {
  38. return (struct skb_desc*)&skb->cb[0];
  39. }
  40. /*
  41. * rxdata_entry_desc
  42. * Summary of information that has been read from the
  43. * RX frame descriptor.
  44. */
  45. struct rxdata_entry_desc {
  46. int signal;
  47. int rssi;
  48. int ofdm;
  49. int size;
  50. int flags;
  51. int my_bss;
  52. };
  53. /*
  54. * txdata_entry_desc
  55. * Summary of information that should be written into the
  56. * descriptor for sending a TX frame.
  57. */
  58. struct txdata_entry_desc {
  59. unsigned long flags;
  60. #define ENTRY_TXDONE 1
  61. #define ENTRY_TXD_RTS_FRAME 2
  62. #define ENTRY_TXD_OFDM_RATE 3
  63. #define ENTRY_TXD_MORE_FRAG 4
  64. #define ENTRY_TXD_REQ_TIMESTAMP 5
  65. #define ENTRY_TXD_BURST 6
  66. #define ENTRY_TXD_ACK 7
  67. /*
  68. * Queue ID. ID's 0-4 are data TX rings
  69. */
  70. int queue;
  71. #define QUEUE_MGMT 13
  72. #define QUEUE_RX 14
  73. #define QUEUE_OTHER 15
  74. /*
  75. * PLCP values.
  76. */
  77. u16 length_high;
  78. u16 length_low;
  79. u16 signal;
  80. u16 service;
  81. /*
  82. * Timing information
  83. */
  84. int aifs;
  85. int ifs;
  86. int cw_min;
  87. int cw_max;
  88. };
  89. /*
  90. * data_entry
  91. * The data ring is a list of data entries.
  92. * Each entry holds a reference to the descriptor
  93. * and the data buffer. For TX rings the reference to the
  94. * sk_buff of the packet being transmitted is also stored here.
  95. */
  96. struct data_entry {
  97. /*
  98. * Status flags
  99. */
  100. unsigned long flags;
  101. #define ENTRY_OWNER_NIC 1
  102. /*
  103. * Ring we belong to.
  104. */
  105. struct data_ring *ring;
  106. /*
  107. * sk_buff for the packet which is being transmitted
  108. * in this entry (Only used with TX related rings).
  109. */
  110. struct sk_buff *skb;
  111. /*
  112. * Store a ieee80211_tx_status structure in each
  113. * ring entry, this will optimize the txdone
  114. * handler.
  115. */
  116. struct ieee80211_tx_status tx_status;
  117. /*
  118. * private pointer specific to driver.
  119. */
  120. void *priv;
  121. /*
  122. * Data address for this entry.
  123. */
  124. void *data_addr;
  125. dma_addr_t data_dma;
  126. /*
  127. * Entry identification number (index).
  128. */
  129. unsigned int entry_idx;
  130. };
  131. /*
  132. * data_ring
  133. * Data rings are used by the device to send and receive packets.
  134. * The data_addr is the base address of the data memory.
  135. * To determine at which point in the ring we are,
  136. * have to use the rt2x00_ring_index_*() functions.
  137. */
  138. struct data_ring {
  139. /*
  140. * Pointer to main rt2x00dev structure where this
  141. * ring belongs to.
  142. */
  143. struct rt2x00_dev *rt2x00dev;
  144. /*
  145. * Base address for the device specific data entries.
  146. */
  147. struct data_entry *entry;
  148. /*
  149. * TX queue statistic info.
  150. */
  151. struct ieee80211_tx_queue_stats_data stats;
  152. /*
  153. * TX Queue parameters.
  154. */
  155. struct ieee80211_tx_queue_params tx_params;
  156. /*
  157. * Base address for data ring.
  158. */
  159. dma_addr_t data_dma;
  160. void *data_addr;
  161. /*
  162. * Queue identification number:
  163. * RX: 0
  164. * TX: IEEE80211_TX_*
  165. */
  166. unsigned int queue_idx;
  167. /*
  168. * Index variables.
  169. */
  170. u16 index;
  171. u16 index_done;
  172. /*
  173. * Size of packet and descriptor in bytes.
  174. */
  175. u16 data_size;
  176. u16 desc_size;
  177. };
  178. /*
  179. * Handlers to determine the address of the current device specific
  180. * data entry, where either index or index_done points to.
  181. */
  182. static inline struct data_entry *rt2x00_get_data_entry(struct data_ring *ring)
  183. {
  184. return &ring->entry[ring->index];
  185. }
  186. static inline struct data_entry *rt2x00_get_data_entry_done(struct data_ring
  187. *ring)
  188. {
  189. return &ring->entry[ring->index_done];
  190. }
  191. /*
  192. * Total ring memory
  193. */
  194. static inline int rt2x00_get_ring_size(struct data_ring *ring)
  195. {
  196. return ring->stats.limit * (ring->desc_size + ring->data_size);
  197. }
  198. /*
  199. * Ring index manipulation functions.
  200. */
  201. static inline void rt2x00_ring_index_inc(struct data_ring *ring)
  202. {
  203. ring->index++;
  204. if (ring->index >= ring->stats.limit)
  205. ring->index = 0;
  206. ring->stats.len++;
  207. }
  208. static inline void rt2x00_ring_index_done_inc(struct data_ring *ring)
  209. {
  210. ring->index_done++;
  211. if (ring->index_done >= ring->stats.limit)
  212. ring->index_done = 0;
  213. ring->stats.len--;
  214. ring->stats.count++;
  215. }
  216. static inline void rt2x00_ring_index_clear(struct data_ring *ring)
  217. {
  218. ring->index = 0;
  219. ring->index_done = 0;
  220. ring->stats.len = 0;
  221. ring->stats.count = 0;
  222. }
  223. static inline int rt2x00_ring_empty(struct data_ring *ring)
  224. {
  225. return ring->stats.len == 0;
  226. }
  227. static inline int rt2x00_ring_full(struct data_ring *ring)
  228. {
  229. return ring->stats.len == ring->stats.limit;
  230. }
  231. static inline int rt2x00_ring_free(struct data_ring *ring)
  232. {
  233. return ring->stats.limit - ring->stats.len;
  234. }
  235. /*
  236. * TX/RX Descriptor access functions.
  237. */
  238. static inline void rt2x00_desc_read(__le32 *desc,
  239. const u8 word, u32 *value)
  240. {
  241. *value = le32_to_cpu(desc[word]);
  242. }
  243. static inline void rt2x00_desc_write(__le32 *desc,
  244. const u8 word, const u32 value)
  245. {
  246. desc[word] = cpu_to_le32(value);
  247. }
  248. #endif /* RT2X00RING_H */