xmit.h 14 KB

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