rsi_main.h 8.7 KB

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