rsi_main.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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_MAIN_H__
  17. #define __RSI_MAIN_H__
  18. #include <linux/string.h>
  19. #include <linux/skbuff.h>
  20. #include <net/mac80211.h>
  21. #include <net/rsi_91x.h>
  22. struct rsi_sta {
  23. struct ieee80211_sta *sta;
  24. s16 sta_id;
  25. u16 seq_start[IEEE80211_NUM_TIDS];
  26. bool start_tx_aggr[IEEE80211_NUM_TIDS];
  27. };
  28. struct rsi_hw;
  29. #include "rsi_ps.h"
  30. #define ERR_ZONE BIT(0) /* For Error Msgs */
  31. #define INFO_ZONE BIT(1) /* For General Status Msgs */
  32. #define INIT_ZONE BIT(2) /* For Driver Init Seq Msgs */
  33. #define MGMT_TX_ZONE BIT(3) /* For TX Mgmt Path Msgs */
  34. #define MGMT_RX_ZONE BIT(4) /* For RX Mgmt Path Msgs */
  35. #define DATA_TX_ZONE BIT(5) /* For TX Data Path Msgs */
  36. #define DATA_RX_ZONE BIT(6) /* For RX Data Path Msgs */
  37. #define FSM_ZONE BIT(7) /* For State Machine Msgs */
  38. #define ISR_ZONE BIT(8) /* For Interrupt Msgs */
  39. enum RSI_FSM_STATES {
  40. FSM_FW_NOT_LOADED,
  41. FSM_CARD_NOT_READY,
  42. FSM_COMMON_DEV_PARAMS_SENT,
  43. FSM_BOOT_PARAMS_SENT,
  44. FSM_EEPROM_READ_MAC_ADDR,
  45. FSM_EEPROM_READ_RF_TYPE,
  46. FSM_RESET_MAC_SENT,
  47. FSM_RADIO_CAPS_SENT,
  48. FSM_BB_RF_PROG_SENT,
  49. FSM_MAC_INIT_DONE,
  50. NUM_FSM_STATES
  51. };
  52. extern u32 rsi_zone_enabled;
  53. extern __printf(2, 3) void rsi_dbg(u32 zone, const char *fmt, ...);
  54. #define RSI_MAX_BANDS 2
  55. #define RSI_MAX_VIFS 3
  56. #define NUM_EDCA_QUEUES 4
  57. #define IEEE80211_ADDR_LEN 6
  58. #define FRAME_DESC_SZ 16
  59. #define MIN_802_11_HDR_LEN 24
  60. #define RSI_DEF_KEEPALIVE 90
  61. #define RSI_WOW_KEEPALIVE 5
  62. #define RSI_BCN_MISS_THRESHOLD 24
  63. #define DATA_QUEUE_WATER_MARK 400
  64. #define MIN_DATA_QUEUE_WATER_MARK 300
  65. #define MULTICAST_WATER_MARK 200
  66. #define MAC_80211_HDR_FRAME_CONTROL 0
  67. #define WME_NUM_AC 4
  68. #define NUM_SOFT_QUEUES 6
  69. #define MAX_HW_QUEUES 12
  70. #define INVALID_QUEUE 0xff
  71. #define MAX_CONTINUOUS_VO_PKTS 8
  72. #define MAX_CONTINUOUS_VI_PKTS 4
  73. /* Hardware queue info */
  74. #define BROADCAST_HW_Q 9
  75. #define MGMT_HW_Q 10
  76. #define BEACON_HW_Q 11
  77. #define IEEE80211_MGMT_FRAME 0x00
  78. #define IEEE80211_CTL_FRAME 0x04
  79. #define RSI_MAX_ASSOC_STAS 32
  80. #define IEEE80211_QOS_TID 0x0f
  81. #define IEEE80211_NONQOS_TID 16
  82. #define MAX_DEBUGFS_ENTRIES 4
  83. #define TID_TO_WME_AC(_tid) ( \
  84. ((_tid) == 0 || (_tid) == 3) ? BE_Q : \
  85. ((_tid) < 3) ? BK_Q : \
  86. ((_tid) < 6) ? VI_Q : \
  87. VO_Q)
  88. #define WME_AC(_q) ( \
  89. ((_q) == BK_Q) ? IEEE80211_AC_BK : \
  90. ((_q) == BE_Q) ? IEEE80211_AC_BE : \
  91. ((_q) == VI_Q) ? IEEE80211_AC_VI : \
  92. IEEE80211_AC_VO)
  93. /* WoWLAN flags */
  94. #define RSI_WOW_ENABLED BIT(0)
  95. #define RSI_WOW_NO_CONNECTION BIT(1)
  96. #define RSI_MAX_RX_PKTS 64
  97. enum rsi_dev_model {
  98. RSI_DEV_9113 = 0,
  99. RSI_DEV_9116
  100. };
  101. struct version_info {
  102. u16 major;
  103. u16 minor;
  104. u8 release_num;
  105. u8 patch_num;
  106. union {
  107. struct {
  108. u8 fw_ver[8];
  109. } info;
  110. } ver;
  111. } __packed;
  112. struct skb_info {
  113. s8 rssi;
  114. u32 flags;
  115. u16 channel;
  116. s8 tid;
  117. s8 sta_id;
  118. u8 internal_hdr_size;
  119. struct ieee80211_vif *vif;
  120. u8 vap_id;
  121. bool have_key;
  122. };
  123. enum edca_queue {
  124. BK_Q,
  125. BE_Q,
  126. VI_Q,
  127. VO_Q,
  128. MGMT_SOFT_Q,
  129. MGMT_BEACON_Q
  130. };
  131. struct security_info {
  132. u32 ptk_cipher;
  133. u32 gtk_cipher;
  134. };
  135. struct wmm_qinfo {
  136. s32 weight;
  137. s32 wme_params;
  138. s32 pkt_contended;
  139. s32 txop;
  140. };
  141. struct transmit_q_stats {
  142. u32 total_tx_pkt_send[NUM_EDCA_QUEUES + 2];
  143. u32 total_tx_pkt_freed[NUM_EDCA_QUEUES + 2];
  144. };
  145. #define MAX_BGSCAN_CHANNELS_DUAL_BAND 38
  146. #define MAX_BGSCAN_PROBE_REQ_LEN 0x64
  147. #define RSI_DEF_BGSCAN_THRLD 0x0
  148. #define RSI_DEF_ROAM_THRLD 0xa
  149. #define RSI_BGSCAN_PERIODICITY 0x1e
  150. #define RSI_ACTIVE_SCAN_TIME 0x14
  151. #define RSI_PASSIVE_SCAN_TIME 0x46
  152. #define RSI_CHANNEL_SCAN_TIME 20
  153. struct rsi_bgscan_params {
  154. u16 bgscan_threshold;
  155. u16 roam_threshold;
  156. u16 bgscan_periodicity;
  157. u8 num_bgscan_channels;
  158. u8 two_probe;
  159. u16 active_scan_duration;
  160. u16 passive_scan_duration;
  161. };
  162. struct vif_priv {
  163. bool is_ht;
  164. bool sgi;
  165. u16 seq_start;
  166. int vap_id;
  167. };
  168. struct rsi_event {
  169. atomic_t event_condition;
  170. wait_queue_head_t event_queue;
  171. };
  172. struct rsi_thread {
  173. void (*thread_function)(void *);
  174. struct completion completion;
  175. struct task_struct *task;
  176. struct rsi_event event;
  177. atomic_t thread_done;
  178. };
  179. struct cqm_info {
  180. s8 last_cqm_event_rssi;
  181. int rssi_thold;
  182. u32 rssi_hyst;
  183. };
  184. enum rsi_dfs_regions {
  185. RSI_REGION_FCC = 0,
  186. RSI_REGION_ETSI,
  187. RSI_REGION_TELEC,
  188. RSI_REGION_WORLD
  189. };
  190. struct rsi_9116_features {
  191. u8 pll_mode;
  192. u8 rf_type;
  193. u8 wireless_mode;
  194. u8 afe_type;
  195. u8 enable_ppe;
  196. u8 dpd;
  197. u32 sifs_tx_enable;
  198. u32 ps_options;
  199. };
  200. struct rsi_rate_config {
  201. u32 configured_mask; /* configured by mac80211 bits 0-11=legacy 12+ mcs */
  202. u16 fixed_hw_rate;
  203. bool fixed_enabled;
  204. };
  205. struct rsi_common {
  206. struct rsi_hw *priv;
  207. struct vif_priv vif_info[RSI_MAX_VIFS];
  208. void *coex_cb;
  209. bool mgmt_q_block;
  210. struct version_info lmac_ver;
  211. struct rsi_thread tx_thread;
  212. struct sk_buff_head tx_queue[NUM_EDCA_QUEUES + 2];
  213. struct completion wlan_init_completion;
  214. /* Mutex declaration */
  215. struct mutex mutex;
  216. /* Mutex used for tx thread */
  217. struct mutex tx_lock;
  218. /* Mutex used for rx thread */
  219. struct mutex rx_lock;
  220. u8 endpoint;
  221. /* Channel/band related */
  222. u8 band;
  223. u8 num_supp_bands;
  224. u8 channel_width;
  225. u16 rts_threshold;
  226. u32 bitrate_mask[RSI_MAX_BANDS];
  227. struct rsi_rate_config rate_config[RSI_MAX_BANDS];
  228. u8 rf_reset;
  229. struct transmit_q_stats tx_stats;
  230. struct security_info secinfo;
  231. struct wmm_qinfo tx_qinfo[NUM_EDCA_QUEUES];
  232. struct ieee80211_tx_queue_params edca_params[NUM_EDCA_QUEUES];
  233. u8 mac_addr[IEEE80211_ADDR_LEN];
  234. /* state related */
  235. u32 fsm_state;
  236. bool init_done;
  237. u8 bb_rf_prog_count;
  238. bool iface_down;
  239. /* Generic */
  240. u8 channel;
  241. u8 *rx_data_pkt;
  242. u8 mac_id;
  243. u8 radio_id;
  244. u16 rate_pwr[20];
  245. /* WMM algo related */
  246. u8 selected_qnum;
  247. u32 pkt_cnt;
  248. u8 min_weight;
  249. /* bgscan related */
  250. struct cqm_info cqm_info;
  251. bool hw_data_qs_blocked;
  252. u8 driver_mode;
  253. u8 coex_mode;
  254. u16 oper_mode;
  255. u8 lp_ps_handshake_mode;
  256. u8 ulp_ps_handshake_mode;
  257. u8 uapsd_bitmap;
  258. u8 rf_power_val;
  259. u8 wlan_rf_power_mode;
  260. u8 obm_ant_sel_val;
  261. int tx_power;
  262. u8 ant_in_use;
  263. /* Mutex used for writing packet to bus */
  264. struct mutex tx_bus_mutex;
  265. bool hibernate_resume;
  266. bool reinit_hw;
  267. u8 wow_flags;
  268. u16 beacon_interval;
  269. u8 dtim_cnt;
  270. /* AP mode parameters */
  271. u8 beacon_enabled;
  272. u16 beacon_cnt;
  273. struct rsi_sta stations[RSI_MAX_ASSOC_STAS + 1];
  274. int num_stations;
  275. int max_stations;
  276. struct ieee80211_key_conf *key;
  277. /* Wi-Fi direct mode related */
  278. bool p2p_enabled;
  279. struct timer_list roc_timer;
  280. struct ieee80211_vif *roc_vif;
  281. bool eapol4_confirm;
  282. bool bt_defer_attach;
  283. void *bt_adapter;
  284. struct cfg80211_scan_request *hwscan;
  285. struct rsi_bgscan_params bgscan;
  286. struct rsi_9116_features w9116_features;
  287. u8 bgscan_en;
  288. u8 mac_ops_resumed;
  289. };
  290. struct eepromrw_info {
  291. u32 offset;
  292. u32 length;
  293. u8 write;
  294. u16 eeprom_erase;
  295. u8 data[480];
  296. };
  297. struct eeprom_read {
  298. u16 length;
  299. u16 off_set;
  300. };
  301. struct rsi_hw {
  302. struct rsi_common *priv;
  303. enum rsi_dev_model device_model;
  304. struct ieee80211_hw *hw;
  305. struct ieee80211_vif *vifs[RSI_MAX_VIFS];
  306. struct ieee80211_tx_queue_params edca_params[NUM_EDCA_QUEUES];
  307. struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
  308. struct device *device;
  309. u8 sc_nvifs;
  310. enum rsi_host_intf rsi_host_intf;
  311. u16 block_size;
  312. enum ps_state ps_state;
  313. struct rsi_ps_info ps_info;
  314. spinlock_t ps_lock; /*To protect power save config*/
  315. u32 usb_buffer_status_reg;
  316. #ifdef CONFIG_RSI_DEBUGFS
  317. struct rsi_debugfs *dfsentry;
  318. u8 num_debugfs_entries;
  319. #endif
  320. char *fw_file_name;
  321. struct timer_list bl_cmd_timer;
  322. bool blcmd_timer_expired;
  323. u32 flash_capacity;
  324. struct eepromrw_info eeprom;
  325. u32 interrupt_status;
  326. u8 dfs_region;
  327. char country[2];
  328. void *rsi_dev;
  329. struct rsi_host_intf_ops *host_intf_ops;
  330. int (*check_hw_queue_status)(struct rsi_hw *adapter, u8 q_num);
  331. int (*determine_event_timeout)(struct rsi_hw *adapter);
  332. };
  333. void rsi_print_version(struct rsi_common *common);
  334. struct rsi_host_intf_ops {
  335. int (*read_pkt)(struct rsi_hw *adapter, u8 *pkt, u32 len);
  336. int (*write_pkt)(struct rsi_hw *adapter, u8 *pkt, u32 len);
  337. int (*master_access_msword)(struct rsi_hw *adapter, u16 ms_word);
  338. int (*read_reg_multiple)(struct rsi_hw *adapter, u32 addr,
  339. u8 *data, u16 count);
  340. int (*write_reg_multiple)(struct rsi_hw *adapter, u32 addr,
  341. u8 *data, u16 count);
  342. int (*master_reg_read)(struct rsi_hw *adapter, u32 addr,
  343. u32 *read_buf, u16 size);
  344. int (*master_reg_write)(struct rsi_hw *adapter,
  345. unsigned long addr, unsigned long data,
  346. u16 size);
  347. int (*load_data_master_write)(struct rsi_hw *adapter, u32 addr,
  348. u32 instructions_size, u16 block_size,
  349. u8 *fw);
  350. int (*reinit_device)(struct rsi_hw *adapter);
  351. int (*ta_reset)(struct rsi_hw *adapter);
  352. };
  353. enum rsi_host_intf rsi_get_host_intf(void *priv);
  354. void rsi_set_bt_context(void *priv, void *bt_context);
  355. void rsi_attach_bt(struct rsi_common *common);
  356. #endif