tx.h 5.3 KB

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