rt2x00ring.h 5.5 KB

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