wl1251_tx.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * This file is part of wl1251
  3. *
  4. * Copyright (c) 1998-2007 Texas Instruments Incorporated
  5. * Copyright (C) 2008 Nokia Corporation
  6. *
  7. * Contact: Kalle Valo <kalle.valo@nokia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #ifndef __WL1251_TX_H__
  25. #define __WL1251_TX_H__
  26. #include <linux/bitops.h>
  27. #include "wl1251_acx.h"
  28. /*
  29. *
  30. * TX PATH
  31. *
  32. * The Tx path uses a double buffer and a tx_control structure, each located
  33. * at a fixed address in the device's memory. On startup, the host retrieves
  34. * the pointers to these addresses. A double buffer allows for continuous data
  35. * flow towards the device. The host keeps track of which buffer is available
  36. * and alternates between these two buffers on a per packet basis.
  37. *
  38. * The size of each of the two buffers is large enough to hold the longest
  39. * 802.3 packet - maximum size Ethernet packet + header + descriptor.
  40. * TX complete indication will be received a-synchronously in a TX done cyclic
  41. * buffer which is composed of 16 tx_result descriptors structures and is used
  42. * in a cyclic manner.
  43. *
  44. * The TX (HOST) procedure is as follows:
  45. * 1. Read the Tx path status, that will give the data_out_count.
  46. * 2. goto 1, if not possible.
  47. * i.e. if data_in_count - data_out_count >= HwBuffer size (2 for double
  48. * buffer).
  49. * 3. Copy the packet (preceded by double_buffer_desc), if possible.
  50. * i.e. if data_in_count - data_out_count < HwBuffer size (2 for double
  51. * buffer).
  52. * 4. increment data_in_count.
  53. * 5. Inform the firmware by generating a firmware internal interrupt.
  54. * 6. FW will increment data_out_count after it reads the buffer.
  55. *
  56. * The TX Complete procedure:
  57. * 1. To get a TX complete indication the host enables the tx_complete flag in
  58. * the TX descriptor Structure.
  59. * 2. For each packet with a Tx Complete field set, the firmware adds the
  60. * transmit results to the cyclic buffer (txDoneRing) and sets both done_1
  61. * and done_2 to 1 to indicate driver ownership.
  62. * 3. The firmware sends a Tx Complete interrupt to the host to trigger the
  63. * host to process the new data. Note: interrupt will be send per packet if
  64. * TX complete indication was requested in tx_control or per crossing
  65. * aggregation threshold.
  66. * 4. After receiving the Tx Complete interrupt, the host reads the
  67. * TxDescriptorDone information in a cyclic manner and clears both done_1
  68. * and done_2 fields.
  69. *
  70. */
  71. #define TX_COMPLETE_REQUIRED_BIT 0x80
  72. #define TX_STATUS_DATA_OUT_COUNT_MASK 0xf
  73. #define WL1251_TX_ALIGN_TO 4
  74. #define WL1251_TX_ALIGN(len) (((len) + WL1251_TX_ALIGN_TO - 1) & \
  75. ~(WL1251_TX_ALIGN_TO - 1))
  76. #define WL1251_TKIP_IV_SPACE 4
  77. struct tx_control {
  78. /* Rate Policy (class) index */
  79. unsigned rate_policy:3;
  80. /* When set, no ack policy is expected */
  81. unsigned ack_policy:1;
  82. /*
  83. * Packet type:
  84. * 0 -> 802.11
  85. * 1 -> 802.3
  86. * 2 -> IP
  87. * 3 -> raw codec
  88. */
  89. unsigned packet_type:2;
  90. /* If set, this is a QoS-Null or QoS-Data frame */
  91. unsigned qos:1;
  92. /*
  93. * If set, the target triggers the tx complete INT
  94. * upon frame sending completion.
  95. */
  96. unsigned tx_complete:1;
  97. /* 2 bytes padding before packet header */
  98. unsigned xfer_pad:1;
  99. unsigned reserved:7;
  100. } __attribute__ ((packed));
  101. struct tx_double_buffer_desc {
  102. /* Length of payload, including headers. */
  103. u16 length;
  104. /*
  105. * A bit mask that specifies the initial rate to be used
  106. * Possible values are:
  107. * 0x0001 - 1Mbits
  108. * 0x0002 - 2Mbits
  109. * 0x0004 - 5.5Mbits
  110. * 0x0008 - 6Mbits
  111. * 0x0010 - 9Mbits
  112. * 0x0020 - 11Mbits
  113. * 0x0040 - 12Mbits
  114. * 0x0080 - 18Mbits
  115. * 0x0100 - 22Mbits
  116. * 0x0200 - 24Mbits
  117. * 0x0400 - 36Mbits
  118. * 0x0800 - 48Mbits
  119. * 0x1000 - 54Mbits
  120. */
  121. u16 rate;
  122. /* Time in us that a packet can spend in the target */
  123. u32 expiry_time;
  124. /* index of the TX queue used for this packet */
  125. u8 xmit_queue;
  126. /* Used to identify a packet */
  127. u8 id;
  128. struct tx_control control;
  129. /*
  130. * The FW should cut the packet into fragments
  131. * of this size.
  132. */
  133. u16 frag_threshold;
  134. /* Numbers of HW queue blocks to be allocated */
  135. u8 num_mem_blocks;
  136. u8 reserved;
  137. } __attribute__ ((packed));
  138. enum {
  139. TX_SUCCESS = 0,
  140. TX_DMA_ERROR = BIT(7),
  141. TX_DISABLED = BIT(6),
  142. TX_RETRY_EXCEEDED = BIT(5),
  143. TX_TIMEOUT = BIT(4),
  144. TX_KEY_NOT_FOUND = BIT(3),
  145. TX_ENCRYPT_FAIL = BIT(2),
  146. TX_UNAVAILABLE_PRIORITY = BIT(1),
  147. };
  148. struct tx_result {
  149. /*
  150. * Ownership synchronization between the host and
  151. * the firmware. If done_1 and done_2 are cleared,
  152. * owned by the FW (no info ready).
  153. */
  154. u8 done_1;
  155. /* same as double_buffer_desc->id */
  156. u8 id;
  157. /*
  158. * Total air access duration consumed by this
  159. * packet, including all retries and overheads.
  160. */
  161. u16 medium_usage;
  162. /* Total media delay (from 1st EDCA AIFS counter until TX Complete). */
  163. u32 medium_delay;
  164. /* Time between host xfer and tx complete */
  165. u32 fw_hnadling_time;
  166. /* The LS-byte of the last TKIP sequence number. */
  167. u8 lsb_seq_num;
  168. /* Retry count */
  169. u8 ack_failures;
  170. /* At which rate we got a ACK */
  171. u16 rate;
  172. u16 reserved;
  173. /* TX_* */
  174. u8 status;
  175. /* See done_1 */
  176. u8 done_2;
  177. } __attribute__ ((packed));
  178. static inline int wl1251_tx_get_queue(int queue)
  179. {
  180. switch (queue) {
  181. case 0:
  182. return QOS_AC_VO;
  183. case 1:
  184. return QOS_AC_VI;
  185. case 2:
  186. return QOS_AC_BE;
  187. case 3:
  188. return QOS_AC_BK;
  189. default:
  190. return QOS_AC_BE;
  191. }
  192. }
  193. void wl1251_tx_work(struct work_struct *work);
  194. void wl1251_tx_complete(struct wl1251 *wl);
  195. void wl1251_tx_flush(struct wl1251 *wl);
  196. #endif