tx.h 5.9 KB

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