rsi_mgmt.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /**
  2. * Copyright (c) 2014 Redpine Signals Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef __RSI_MGMT_H__
  17. #define __RSI_MGMT_H__
  18. #include <linux/sort.h>
  19. #include "rsi_boot_params.h"
  20. #include "rsi_main.h"
  21. #define MAX_MGMT_PKT_SIZE 512
  22. #define RSI_NEEDED_HEADROOM 80
  23. #define RSI_RCV_BUFFER_LEN 2000
  24. #define RSI_11B_MODE 0
  25. #define RSI_11G_MODE BIT(7)
  26. #define RETRY_COUNT 8
  27. #define RETRY_LONG 4
  28. #define RETRY_SHORT 7
  29. #define WMM_SHORT_SLOT_TIME 9
  30. #define SIFS_DURATION 16
  31. #define KEY_TYPE_CLEAR 0
  32. #define RSI_PAIRWISE_KEY 1
  33. #define RSI_GROUP_KEY 2
  34. /* EPPROM_READ_ADDRESS */
  35. #define WLAN_MAC_EEPROM_ADDR 40
  36. #define WLAN_MAC_MAGIC_WORD_LEN 0x01
  37. #define WLAN_HOST_MODE_LEN 0x04
  38. #define WLAN_FW_VERSION_LEN 0x08
  39. #define MAGIC_WORD 0x5A
  40. /* Receive Frame Types */
  41. #define TA_CONFIRM_TYPE 0x01
  42. #define RX_DOT11_MGMT 0x02
  43. #define TX_STATUS_IND 0x04
  44. #define PROBEREQ_CONFIRM 2
  45. #define CARD_READY_IND 0x00
  46. #define RSI_DELETE_PEER 0x0
  47. #define RSI_ADD_PEER 0x1
  48. #define START_AMPDU_AGGR 0x1
  49. #define STOP_AMPDU_AGGR 0x0
  50. #define INTERNAL_MGMT_PKT 0x99
  51. #define PUT_BBP_RESET 0
  52. #define BBP_REG_WRITE 0
  53. #define RF_RESET_ENABLE BIT(3)
  54. #define RATE_INFO_ENABLE BIT(0)
  55. #define RSI_BROADCAST_PKT BIT(9)
  56. #define UPPER_20_ENABLE (0x2 << 12)
  57. #define LOWER_20_ENABLE (0x4 << 12)
  58. #define FULL40M_ENABLE 0x6
  59. #define RSI_LMAC_CLOCK_80MHZ 0x1
  60. #define RSI_ENABLE_40MHZ (0x1 << 3)
  61. #define ENABLE_SHORTGI_RATE BIT(9)
  62. #define RX_BA_INDICATION 1
  63. #define RSI_TBL_SZ 40
  64. #define MAX_RETRIES 8
  65. #define RSI_IFTYPE_STATION 0
  66. #define STD_RATE_MCS7 0x07
  67. #define STD_RATE_MCS6 0x06
  68. #define STD_RATE_MCS5 0x05
  69. #define STD_RATE_MCS4 0x04
  70. #define STD_RATE_MCS3 0x03
  71. #define STD_RATE_MCS2 0x02
  72. #define STD_RATE_MCS1 0x01
  73. #define STD_RATE_MCS0 0x00
  74. #define STD_RATE_54 0x6c
  75. #define STD_RATE_48 0x60
  76. #define STD_RATE_36 0x48
  77. #define STD_RATE_24 0x30
  78. #define STD_RATE_18 0x24
  79. #define STD_RATE_12 0x18
  80. #define STD_RATE_11 0x16
  81. #define STD_RATE_09 0x12
  82. #define STD_RATE_06 0x0C
  83. #define STD_RATE_5_5 0x0B
  84. #define STD_RATE_02 0x04
  85. #define STD_RATE_01 0x02
  86. #define RSI_RF_TYPE 1
  87. #define RSI_RATE_00 0x00
  88. #define RSI_RATE_1 0x0
  89. #define RSI_RATE_2 0x2
  90. #define RSI_RATE_5_5 0x4
  91. #define RSI_RATE_11 0x6
  92. #define RSI_RATE_6 0x8b
  93. #define RSI_RATE_9 0x8f
  94. #define RSI_RATE_12 0x8a
  95. #define RSI_RATE_18 0x8e
  96. #define RSI_RATE_24 0x89
  97. #define RSI_RATE_36 0x8d
  98. #define RSI_RATE_48 0x88
  99. #define RSI_RATE_54 0x8c
  100. #define RSI_RATE_MCS0 0x100
  101. #define RSI_RATE_MCS1 0x101
  102. #define RSI_RATE_MCS2 0x102
  103. #define RSI_RATE_MCS3 0x103
  104. #define RSI_RATE_MCS4 0x104
  105. #define RSI_RATE_MCS5 0x105
  106. #define RSI_RATE_MCS6 0x106
  107. #define RSI_RATE_MCS7 0x107
  108. #define RSI_RATE_MCS7_SG 0x307
  109. #define BW_20MHZ 0
  110. #define BW_40MHZ 1
  111. #define EP_2GHZ_20MHZ 0
  112. #define EP_2GHZ_40MHZ 1
  113. #define EP_5GHZ_20MHZ 2
  114. #define EP_5GHZ_40MHZ 3
  115. #define SIFS_TX_11N_VALUE 580
  116. #define SIFS_TX_11B_VALUE 346
  117. #define SHORT_SLOT_VALUE 360
  118. #define LONG_SLOT_VALUE 640
  119. #define OFDM_ACK_TOUT_VALUE 2720
  120. #define CCK_ACK_TOUT_VALUE 9440
  121. #define LONG_PREAMBLE 0x0000
  122. #define SHORT_PREAMBLE 0x0001
  123. #define RSI_SUPP_FILTERS (FIF_ALLMULTI | FIF_PROBE_REQ |\
  124. FIF_BCN_PRBRESP_PROMISC)
  125. #define ANTENNA_SEL_INT 0x02 /* RF_OUT_2 / Integerated */
  126. #define ANTENNA_SEL_UFL 0x03 /* RF_OUT_1 / U.FL */
  127. /* Rx filter word definitions */
  128. #define PROMISCOUS_MODE BIT(0)
  129. #define ALLOW_DATA_ASSOC_PEER BIT(1)
  130. #define ALLOW_MGMT_ASSOC_PEER BIT(2)
  131. #define ALLOW_CTRL_ASSOC_PEER BIT(3)
  132. #define DISALLOW_BEACONS BIT(4)
  133. #define ALLOW_CONN_PEER_MGMT_WHILE_BUF_FULL BIT(5)
  134. #define DISALLOW_BROADCAST_DATA BIT(6)
  135. enum opmode {
  136. STA_OPMODE = 1,
  137. AP_OPMODE = 2
  138. };
  139. enum vap_status {
  140. VAP_ADD = 1,
  141. VAP_DELETE = 2,
  142. VAP_UPDATE = 3
  143. };
  144. extern struct ieee80211_rate rsi_rates[12];
  145. extern const u16 rsi_mcsrates[8];
  146. enum sta_notify_events {
  147. STA_CONNECTED = 0,
  148. STA_DISCONNECTED,
  149. STA_TX_ADDBA_DONE,
  150. STA_TX_DELBA,
  151. STA_RX_ADDBA_DONE,
  152. STA_RX_DELBA
  153. };
  154. /* Send Frames Types */
  155. enum cmd_frame_type {
  156. TX_DOT11_MGMT,
  157. RESET_MAC_REQ,
  158. RADIO_CAPABILITIES,
  159. BB_PROG_VALUES_REQUEST,
  160. RF_PROG_VALUES_REQUEST,
  161. WAKEUP_SLEEP_REQUEST,
  162. SCAN_REQUEST,
  163. TSF_UPDATE,
  164. PEER_NOTIFY,
  165. BLOCK_HW_QUEUE,
  166. SET_KEY_REQ,
  167. AUTO_RATE_IND,
  168. BOOTUP_PARAMS_REQUEST,
  169. VAP_CAPABILITIES,
  170. EEPROM_READ_TYPE ,
  171. EEPROM_WRITE,
  172. GPIO_PIN_CONFIG ,
  173. SET_RX_FILTER,
  174. AMPDU_IND,
  175. STATS_REQUEST_FRAME,
  176. BB_BUF_PROG_VALUES_REQ,
  177. BBP_PROG_IN_TA,
  178. BG_SCAN_PARAMS,
  179. BG_SCAN_PROBE_REQ,
  180. CW_MODE_REQ,
  181. PER_CMD_PKT,
  182. ANT_SEL_FRAME = 0x20,
  183. RADIO_PARAMS_UPDATE = 0x29
  184. };
  185. struct rsi_mac_frame {
  186. __le16 desc_word[8];
  187. } __packed;
  188. struct rsi_boot_params {
  189. __le16 desc_word[8];
  190. struct bootup_params bootup_params;
  191. } __packed;
  192. struct rsi_peer_notify {
  193. __le16 desc_word[8];
  194. u8 mac_addr[6];
  195. __le16 command;
  196. __le16 mpdu_density;
  197. __le16 reserved;
  198. __le32 sta_flags;
  199. } __packed;
  200. struct rsi_vap_caps {
  201. __le16 desc_word[8];
  202. u8 mac_addr[6];
  203. __le16 keep_alive_period;
  204. u8 bssid[6];
  205. __le16 reserved;
  206. __le32 flags;
  207. __le16 frag_threshold;
  208. __le16 rts_threshold;
  209. __le32 default_mgmt_rate;
  210. __le32 default_ctrl_rate;
  211. __le32 default_data_rate;
  212. __le16 beacon_interval;
  213. __le16 dtim_period;
  214. } __packed;
  215. struct rsi_set_key {
  216. __le16 desc_word[8];
  217. u8 key[4][32];
  218. u8 tx_mic_key[8];
  219. u8 rx_mic_key[8];
  220. } __packed;
  221. struct rsi_auto_rate {
  222. __le16 desc_word[8];
  223. __le16 failure_limit;
  224. __le16 initial_boundary;
  225. __le16 max_threshold_limt;
  226. __le16 num_supported_rates;
  227. __le16 aarf_rssi;
  228. __le16 moderate_rate_inx;
  229. __le16 collision_tolerance;
  230. __le16 supported_rates[40];
  231. } __packed;
  232. struct qos_params {
  233. __le16 cont_win_min_q;
  234. __le16 cont_win_max_q;
  235. __le16 aifsn_val_q;
  236. __le16 txop_q;
  237. } __packed;
  238. struct rsi_radio_caps {
  239. __le16 desc_word[8];
  240. struct qos_params qos_params[MAX_HW_QUEUES];
  241. u8 num_11n_rates;
  242. u8 num_11ac_rates;
  243. __le16 gcpd_per_rate[20];
  244. __le16 sifs_tx_11n;
  245. __le16 sifs_tx_11b;
  246. __le16 slot_rx_11n;
  247. __le16 ofdm_ack_tout;
  248. __le16 cck_ack_tout;
  249. __le16 preamble_type;
  250. } __packed;
  251. static inline u32 rsi_get_queueno(u8 *addr, u16 offset)
  252. {
  253. return (le16_to_cpu(*(__le16 *)&addr[offset]) & 0x7000) >> 12;
  254. }
  255. static inline u32 rsi_get_length(u8 *addr, u16 offset)
  256. {
  257. return (le16_to_cpu(*(__le16 *)&addr[offset])) & 0x0fff;
  258. }
  259. static inline u8 rsi_get_extended_desc(u8 *addr, u16 offset)
  260. {
  261. return le16_to_cpu(*((__le16 *)&addr[offset + 4])) & 0x00ff;
  262. }
  263. static inline u8 rsi_get_rssi(u8 *addr)
  264. {
  265. return *(u8 *)(addr + FRAME_DESC_SZ);
  266. }
  267. static inline u8 rsi_get_channel(u8 *addr)
  268. {
  269. return *(char *)(addr + 15);
  270. }
  271. int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg);
  272. int rsi_set_vap_capabilities(struct rsi_common *common, enum opmode mode,
  273. u8 vap_status);
  274. int rsi_send_aggregation_params_frame(struct rsi_common *common, u16 tid,
  275. u16 ssn, u8 buf_size, u8 event);
  276. int rsi_hal_load_key(struct rsi_common *common, u8 *data, u16 key_len,
  277. u8 key_type, u8 key_id, u32 cipher);
  278. int rsi_set_channel(struct rsi_common *common,
  279. struct ieee80211_channel *channel);
  280. int rsi_send_block_unblock_frame(struct rsi_common *common, bool event);
  281. void rsi_inform_bss_status(struct rsi_common *common, u8 status,
  282. const u8 *bssid, u8 qos_enable, u16 aid);
  283. void rsi_indicate_pkt_to_os(struct rsi_common *common, struct sk_buff *skb);
  284. int rsi_mac80211_attach(struct rsi_common *common);
  285. void rsi_indicate_tx_status(struct rsi_hw *common, struct sk_buff *skb,
  286. int status);
  287. bool rsi_is_cipher_wep(struct rsi_common *common);
  288. void rsi_core_qos_processor(struct rsi_common *common);
  289. void rsi_core_xmit(struct rsi_common *common, struct sk_buff *skb);
  290. int rsi_send_mgmt_pkt(struct rsi_common *common, struct sk_buff *skb);
  291. int rsi_send_data_pkt(struct rsi_common *common, struct sk_buff *skb);
  292. int rsi_band_check(struct rsi_common *common);
  293. int rsi_send_rx_filter_frame(struct rsi_common *common, u16 rx_filter_word);
  294. int rsi_send_radio_params_update(struct rsi_common *common);
  295. int rsi_set_antenna(struct rsi_common *common, u8 antenna);
  296. #endif