rt2x00ring.h 5.5 KB

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