xmit.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. #ifndef B43_XMIT_H_
  2. #define B43_XMIT_H_
  3. #include "main.h"
  4. #define _b43_declare_plcp_hdr(size) \
  5. struct b43_plcp_hdr##size { \
  6. union { \
  7. __le32 data; \
  8. __u8 raw[size]; \
  9. } __attribute__((__packed__)); \
  10. } __attribute__((__packed__))
  11. /* struct b43_plcp_hdr4 */
  12. _b43_declare_plcp_hdr(4);
  13. /* struct b43_plcp_hdr6 */
  14. _b43_declare_plcp_hdr(6);
  15. #undef _b43_declare_plcp_hdr
  16. /* TX header for v4 firmware */
  17. struct b43_txhdr {
  18. __le32 mac_ctl; /* MAC TX control */
  19. __le16 mac_frame_ctl; /* Copy of the FrameControl field */
  20. __le16 tx_fes_time_norm; /* TX FES Time Normal */
  21. __le16 phy_ctl; /* PHY TX control */
  22. __le16 phy_ctl1; /* PHY TX control word 1 */
  23. __le16 phy_ctl1_fb; /* PHY TX control word 1 for fallback rates */
  24. __le16 phy_ctl1_rts; /* PHY TX control word 1 RTS */
  25. __le16 phy_ctl1_rts_fb; /* PHY TX control word 1 RTS for fallback rates */
  26. __u8 phy_rate; /* PHY rate */
  27. __u8 phy_rate_rts; /* PHY rate for RTS/CTS */
  28. __u8 extra_ft; /* Extra Frame Types */
  29. __u8 chan_radio_code; /* Channel Radio Code */
  30. __u8 iv[16]; /* Encryption IV */
  31. __u8 tx_receiver[6]; /* TX Frame Receiver address */
  32. __le16 tx_fes_time_fb; /* TX FES Time Fallback */
  33. struct b43_plcp_hdr6 rts_plcp_fb; /* RTS fallback PLCP header */
  34. __le16 rts_dur_fb; /* RTS fallback duration */
  35. struct b43_plcp_hdr6 plcp_fb; /* Fallback PLCP header */
  36. __le16 dur_fb; /* Fallback duration */
  37. __le16 mimo_modelen; /* MIMO mode length */
  38. __le16 mimo_ratelen_fb; /* MIMO fallback rate length */
  39. __le32 timeout; /* Timeout */
  40. union {
  41. /* The new r410 format. */
  42. struct {
  43. __le16 mimo_antenna; /* MIMO antenna select */
  44. __le16 preload_size; /* Preload size */
  45. PAD_BYTES(2);
  46. __le16 cookie; /* TX frame cookie */
  47. __le16 tx_status; /* TX status */
  48. struct b43_plcp_hdr6 rts_plcp; /* RTS PLCP header */
  49. __u8 rts_frame[16]; /* The RTS frame (if used) */
  50. PAD_BYTES(2);
  51. struct b43_plcp_hdr6 plcp; /* Main PLCP header */
  52. } new_format __attribute__ ((__packed__));
  53. /* The old r351 format. */
  54. struct {
  55. PAD_BYTES(2);
  56. __le16 cookie; /* TX frame cookie */
  57. __le16 tx_status; /* TX status */
  58. struct b43_plcp_hdr6 rts_plcp; /* RTS PLCP header */
  59. __u8 rts_frame[16]; /* The RTS frame (if used) */
  60. PAD_BYTES(2);
  61. struct b43_plcp_hdr6 plcp; /* Main PLCP header */
  62. } old_format __attribute__ ((__packed__));
  63. } __attribute__ ((__packed__));
  64. } __attribute__ ((__packed__));
  65. /* MAC TX control */
  66. #define B43_TXH_MAC_USEFBR 0x10000000 /* Use fallback rate for this AMPDU */
  67. #define B43_TXH_MAC_KEYIDX 0x0FF00000 /* Security key index */
  68. #define B43_TXH_MAC_KEYIDX_SHIFT 20
  69. #define B43_TXH_MAC_KEYALG 0x00070000 /* Security key algorithm */
  70. #define B43_TXH_MAC_KEYALG_SHIFT 16
  71. #define B43_TXH_MAC_AMIC 0x00008000 /* AMIC */
  72. #define B43_TXH_MAC_RIFS 0x00004000 /* Use RIFS */
  73. #define B43_TXH_MAC_LIFETIME 0x00002000 /* Lifetime */
  74. #define B43_TXH_MAC_FRAMEBURST 0x00001000 /* Frameburst */
  75. #define B43_TXH_MAC_SENDCTS 0x00000800 /* Send CTS-to-self */
  76. #define B43_TXH_MAC_AMPDU 0x00000600 /* AMPDU status */
  77. #define B43_TXH_MAC_AMPDU_MPDU 0x00000000 /* Regular MPDU, not an AMPDU */
  78. #define B43_TXH_MAC_AMPDU_FIRST 0x00000200 /* First MPDU or AMPDU */
  79. #define B43_TXH_MAC_AMPDU_INTER 0x00000400 /* Intermediate MPDU or AMPDU */
  80. #define B43_TXH_MAC_AMPDU_LAST 0x00000600 /* Last (or only) MPDU of AMPDU */
  81. #define B43_TXH_MAC_40MHZ 0x00000100 /* Use 40 MHz bandwidth */
  82. #define B43_TXH_MAC_5GHZ 0x00000080 /* 5GHz band */
  83. #define B43_TXH_MAC_DFCS 0x00000040 /* DFCS */
  84. #define B43_TXH_MAC_IGNPMQ 0x00000020 /* Ignore PMQ */
  85. #define B43_TXH_MAC_HWSEQ 0x00000010 /* Use Hardware Sequence Number */
  86. #define B43_TXH_MAC_STMSDU 0x00000008 /* Start MSDU */
  87. #define B43_TXH_MAC_SENDRTS 0x00000004 /* Send RTS */
  88. #define B43_TXH_MAC_LONGFRAME 0x00000002 /* Long frame */
  89. #define B43_TXH_MAC_ACK 0x00000001 /* Immediate ACK */
  90. /* Extra Frame Types */
  91. #define B43_TXH_EFT_FB 0x03 /* Data frame fallback encoding */
  92. #define B43_TXH_EFT_FB_CCK 0x00 /* CCK */
  93. #define B43_TXH_EFT_FB_OFDM 0x01 /* OFDM */
  94. #define B43_TXH_EFT_FB_EWC 0x02 /* EWC */
  95. #define B43_TXH_EFT_FB_N 0x03 /* N */
  96. #define B43_TXH_EFT_RTS 0x0C /* RTS/CTS encoding */
  97. #define B43_TXH_EFT_RTS_CCK 0x00 /* CCK */
  98. #define B43_TXH_EFT_RTS_OFDM 0x04 /* OFDM */
  99. #define B43_TXH_EFT_RTS_EWC 0x08 /* EWC */
  100. #define B43_TXH_EFT_RTS_N 0x0C /* N */
  101. #define B43_TXH_EFT_RTSFB 0x30 /* RTS/CTS fallback encoding */
  102. #define B43_TXH_EFT_RTSFB_CCK 0x00 /* CCK */
  103. #define B43_TXH_EFT_RTSFB_OFDM 0x10 /* OFDM */
  104. #define B43_TXH_EFT_RTSFB_EWC 0x20 /* EWC */
  105. #define B43_TXH_EFT_RTSFB_N 0x30 /* N */
  106. /* PHY TX control word */
  107. #define B43_TXH_PHY_ENC 0x0003 /* Data frame encoding */
  108. #define B43_TXH_PHY_ENC_CCK 0x0000 /* CCK */
  109. #define B43_TXH_PHY_ENC_OFDM 0x0001 /* OFDM */
  110. #define B43_TXH_PHY_ENC_EWC 0x0002 /* EWC */
  111. #define B43_TXH_PHY_ENC_N 0x0003 /* N */
  112. #define B43_TXH_PHY_SHORTPRMBL 0x0010 /* Use short preamble */
  113. #define B43_TXH_PHY_ANT 0x03C0 /* Antenna selection */
  114. #define B43_TXH_PHY_ANT0 0x0000 /* Use antenna 0 */
  115. #define B43_TXH_PHY_ANT1 0x0040 /* Use antenna 1 */
  116. #define B43_TXH_PHY_ANT01AUTO 0x00C0 /* Use antenna 0/1 auto */
  117. #define B43_TXH_PHY_ANT2 0x0100 /* Use antenna 2 */
  118. #define B43_TXH_PHY_ANT3 0x0200 /* Use antenna 3 */
  119. #define B43_TXH_PHY_TXPWR 0xFC00 /* TX power */
  120. #define B43_TXH_PHY_TXPWR_SHIFT 10
  121. /* PHY TX control word 1 */
  122. #define B43_TXH_PHY1_BW 0x0007 /* Bandwidth */
  123. #define B43_TXH_PHY1_BW_10 0x0000 /* 10 MHz */
  124. #define B43_TXH_PHY1_BW_10U 0x0001 /* 10 MHz upper */
  125. #define B43_TXH_PHY1_BW_20 0x0002 /* 20 MHz */
  126. #define B43_TXH_PHY1_BW_20U 0x0003 /* 20 MHz upper */
  127. #define B43_TXH_PHY1_BW_40 0x0004 /* 40 MHz */
  128. #define B43_TXH_PHY1_BW_40DUP 0x0005 /* 50 MHz duplicate */
  129. #define B43_TXH_PHY1_MODE 0x0038 /* Mode */
  130. #define B43_TXH_PHY1_MODE_SISO 0x0000 /* SISO */
  131. #define B43_TXH_PHY1_MODE_CDD 0x0008 /* CDD */
  132. #define B43_TXH_PHY1_MODE_STBC 0x0010 /* STBC */
  133. #define B43_TXH_PHY1_MODE_SDM 0x0018 /* SDM */
  134. #define B43_TXH_PHY1_CRATE 0x0700 /* Coding rate */
  135. #define B43_TXH_PHY1_CRATE_1_2 0x0000 /* 1/2 */
  136. #define B43_TXH_PHY1_CRATE_2_3 0x0100 /* 2/3 */
  137. #define B43_TXH_PHY1_CRATE_3_4 0x0200 /* 3/4 */
  138. #define B43_TXH_PHY1_CRATE_4_5 0x0300 /* 4/5 */
  139. #define B43_TXH_PHY1_CRATE_5_6 0x0400 /* 5/6 */
  140. #define B43_TXH_PHY1_CRATE_7_8 0x0600 /* 7/8 */
  141. #define B43_TXH_PHY1_MODUL 0x3800 /* Modulation scheme */
  142. #define B43_TXH_PHY1_MODUL_BPSK 0x0000 /* BPSK */
  143. #define B43_TXH_PHY1_MODUL_QPSK 0x0800 /* QPSK */
  144. #define B43_TXH_PHY1_MODUL_QAM16 0x1000 /* QAM16 */
  145. #define B43_TXH_PHY1_MODUL_QAM64 0x1800 /* QAM64 */
  146. #define B43_TXH_PHY1_MODUL_QAM256 0x2000 /* QAM256 */
  147. /* r351 firmware compatibility stuff. */
  148. static inline
  149. bool b43_is_old_txhdr_format(struct b43_wldev *dev)
  150. {
  151. return (dev->fw.rev <= 351);
  152. }
  153. static inline
  154. size_t b43_txhdr_size(struct b43_wldev *dev)
  155. {
  156. if (b43_is_old_txhdr_format(dev))
  157. return 100 + sizeof(struct b43_plcp_hdr6);
  158. return 104 + sizeof(struct b43_plcp_hdr6);
  159. }
  160. int b43_generate_txhdr(struct b43_wldev *dev,
  161. u8 * txhdr,
  162. const unsigned char *fragment_data,
  163. unsigned int fragment_len,
  164. struct ieee80211_tx_info *txctl, u16 cookie);
  165. /* Transmit Status */
  166. struct b43_txstatus {
  167. u16 cookie; /* The cookie from the txhdr */
  168. u16 seq; /* Sequence number */
  169. u8 phy_stat; /* PHY TX status */
  170. u8 frame_count; /* Frame transmit count */
  171. u8 rts_count; /* RTS transmit count */
  172. u8 supp_reason; /* Suppression reason */
  173. /* flags */
  174. u8 pm_indicated; /* PM mode indicated to AP */
  175. u8 intermediate; /* Intermediate status notification (not final) */
  176. u8 for_ampdu; /* Status is for an AMPDU (afterburner) */
  177. u8 acked; /* Wireless ACK received */
  178. };
  179. /* txstatus supp_reason values */
  180. enum {
  181. B43_TXST_SUPP_NONE, /* Not suppressed */
  182. B43_TXST_SUPP_PMQ, /* Suppressed due to PMQ entry */
  183. B43_TXST_SUPP_FLUSH, /* Suppressed due to flush request */
  184. B43_TXST_SUPP_PREV, /* Previous fragment failed */
  185. B43_TXST_SUPP_CHAN, /* Channel mismatch */
  186. B43_TXST_SUPP_LIFE, /* Lifetime expired */
  187. B43_TXST_SUPP_UNDER, /* Buffer underflow */
  188. B43_TXST_SUPP_ABNACK, /* Afterburner NACK */
  189. };
  190. /* Receive header for v4 firmware. */
  191. struct b43_rxhdr_fw4 {
  192. __le16 frame_len; /* Frame length */
  193. PAD_BYTES(2);
  194. __le16 phy_status0; /* PHY RX Status 0 */
  195. union {
  196. /* RSSI for A/B/G-PHYs */
  197. struct {
  198. __u8 jssi; /* PHY RX Status 1: JSSI */
  199. __u8 sig_qual; /* PHY RX Status 1: Signal Quality */
  200. } __attribute__ ((__packed__));
  201. /* RSSI for N-PHYs */
  202. struct {
  203. __s8 power0; /* PHY RX Status 1: Power 0 */
  204. __s8 power1; /* PHY RX Status 1: Power 1 */
  205. } __attribute__ ((__packed__));
  206. } __attribute__ ((__packed__));
  207. __le16 phy_status2; /* PHY RX Status 2 */
  208. __le16 phy_status3; /* PHY RX Status 3 */
  209. __le32 mac_status; /* MAC RX status */
  210. __le16 mac_time;
  211. __le16 channel;
  212. } __attribute__ ((__packed__));
  213. /* PHY RX Status 0 */
  214. #define B43_RX_PHYST0_GAINCTL 0x4000 /* Gain Control */
  215. #define B43_RX_PHYST0_PLCPHCF 0x0200
  216. #define B43_RX_PHYST0_PLCPFV 0x0100
  217. #define B43_RX_PHYST0_SHORTPRMBL 0x0080 /* Received with Short Preamble */
  218. #define B43_RX_PHYST0_LCRS 0x0040
  219. #define B43_RX_PHYST0_ANT 0x0020 /* Antenna */
  220. #define B43_RX_PHYST0_UNSRATE 0x0010
  221. #define B43_RX_PHYST0_CLIP 0x000C
  222. #define B43_RX_PHYST0_CLIP_SHIFT 2
  223. #define B43_RX_PHYST0_FTYPE 0x0003 /* Frame type */
  224. #define B43_RX_PHYST0_CCK 0x0000 /* Frame type: CCK */
  225. #define B43_RX_PHYST0_OFDM 0x0001 /* Frame type: OFDM */
  226. #define B43_RX_PHYST0_PRE_N 0x0002 /* Pre-standard N-PHY frame */
  227. #define B43_RX_PHYST0_STD_N 0x0003 /* Standard N-PHY frame */
  228. /* PHY RX Status 2 */
  229. #define B43_RX_PHYST2_LNAG 0xC000 /* LNA Gain */
  230. #define B43_RX_PHYST2_LNAG_SHIFT 14
  231. #define B43_RX_PHYST2_PNAG 0x3C00 /* PNA Gain */
  232. #define B43_RX_PHYST2_PNAG_SHIFT 10
  233. #define B43_RX_PHYST2_FOFF 0x03FF /* F offset */
  234. /* PHY RX Status 3 */
  235. #define B43_RX_PHYST3_DIGG 0x1800 /* DIG Gain */
  236. #define B43_RX_PHYST3_DIGG_SHIFT 11
  237. #define B43_RX_PHYST3_TRSTATE 0x0400 /* TR state */
  238. /* MAC RX Status */
  239. #define B43_RX_MAC_RXST_VALID 0x01000000 /* PHY RXST valid */
  240. #define B43_RX_MAC_TKIP_MICERR 0x00100000 /* TKIP MIC error */
  241. #define B43_RX_MAC_TKIP_MICATT 0x00080000 /* TKIP MIC attempted */
  242. #define B43_RX_MAC_AGGTYPE 0x00060000 /* Aggregation type */
  243. #define B43_RX_MAC_AGGTYPE_SHIFT 17
  244. #define B43_RX_MAC_AMSDU 0x00010000 /* A-MSDU mask */
  245. #define B43_RX_MAC_BEACONSENT 0x00008000 /* Beacon sent flag */
  246. #define B43_RX_MAC_KEYIDX 0x000007E0 /* Key index */
  247. #define B43_RX_MAC_KEYIDX_SHIFT 5
  248. #define B43_RX_MAC_DECERR 0x00000010 /* Decrypt error */
  249. #define B43_RX_MAC_DEC 0x00000008 /* Decryption attempted */
  250. #define B43_RX_MAC_PADDING 0x00000004 /* Pad bytes present */
  251. #define B43_RX_MAC_RESP 0x00000002 /* Response frame transmitted */
  252. #define B43_RX_MAC_FCSERR 0x00000001 /* FCS error */
  253. /* RX channel */
  254. #define B43_RX_CHAN_40MHZ 0x1000 /* 40 Mhz channel width */
  255. #define B43_RX_CHAN_5GHZ 0x0800 /* 5 Ghz band */
  256. #define B43_RX_CHAN_ID 0x07F8 /* Channel ID */
  257. #define B43_RX_CHAN_ID_SHIFT 3
  258. #define B43_RX_CHAN_PHYTYPE 0x0007 /* PHY type */
  259. u8 b43_plcp_get_ratecode_cck(const u8 bitrate);
  260. u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate);
  261. void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
  262. const u16 octets, const u8 bitrate);
  263. void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr);
  264. void b43_handle_txstatus(struct b43_wldev *dev,
  265. const struct b43_txstatus *status);
  266. bool b43_fill_txstatus_report(struct b43_wldev *dev,
  267. struct ieee80211_tx_info *report,
  268. const struct b43_txstatus *status);
  269. void b43_tx_suspend(struct b43_wldev *dev);
  270. void b43_tx_resume(struct b43_wldev *dev);
  271. /* Helper functions for converting the key-table index from "firmware-format"
  272. * to "raw-format" and back. The firmware API changed for this at some revision.
  273. * We need to account for that here. */
  274. static inline int b43_new_kidx_api(struct b43_wldev *dev)
  275. {
  276. /* FIXME: Not sure the change was at rev 351 */
  277. return (dev->fw.rev >= 351);
  278. }
  279. static inline u8 b43_kidx_to_fw(struct b43_wldev *dev, u8 raw_kidx)
  280. {
  281. u8 firmware_kidx;
  282. if (b43_new_kidx_api(dev)) {
  283. firmware_kidx = raw_kidx;
  284. } else {
  285. if (raw_kidx >= 4) /* Is per STA key? */
  286. firmware_kidx = raw_kidx - 4;
  287. else
  288. firmware_kidx = raw_kidx; /* TX default key */
  289. }
  290. return firmware_kidx;
  291. }
  292. static inline u8 b43_kidx_to_raw(struct b43_wldev *dev, u8 firmware_kidx)
  293. {
  294. u8 raw_kidx;
  295. if (b43_new_kidx_api(dev))
  296. raw_kidx = firmware_kidx;
  297. else
  298. raw_kidx = firmware_kidx + 4; /* RX default keys or per STA keys */
  299. return raw_kidx;
  300. }
  301. #endif /* B43_XMIT_H_ */