rsi_main.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 1
  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 DATA_QUEUE_WATER_MARK 400
  60. #define MIN_DATA_QUEUE_WATER_MARK 300
  61. #define MULTICAST_WATER_MARK 200
  62. #define MAC_80211_HDR_FRAME_CONTROL 0
  63. #define WME_NUM_AC 4
  64. #define NUM_SOFT_QUEUES 6
  65. #define MAX_HW_QUEUES 12
  66. #define INVALID_QUEUE 0xff
  67. #define MAX_CONTINUOUS_VO_PKTS 8
  68. #define MAX_CONTINUOUS_VI_PKTS 4
  69. /* Hardware queue info */
  70. #define BROADCAST_HW_Q 9
  71. #define MGMT_HW_Q 10
  72. #define BEACON_HW_Q 11
  73. /* Queue information */
  74. #define RSI_COEX_Q 0x0
  75. #define RSI_WIFI_MGMT_Q 0x4
  76. #define RSI_WIFI_DATA_Q 0x5
  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. #define RSI_DEV_9113 1
  94. struct version_info {
  95. u16 major;
  96. u16 minor;
  97. u16 release_num;
  98. u16 patch_num;
  99. } __packed;
  100. struct skb_info {
  101. s8 rssi;
  102. u32 flags;
  103. u16 channel;
  104. s8 tid;
  105. s8 sta_id;
  106. u8 internal_hdr_size;
  107. };
  108. enum edca_queue {
  109. BK_Q,
  110. BE_Q,
  111. VI_Q,
  112. VO_Q,
  113. MGMT_SOFT_Q,
  114. MGMT_BEACON_Q
  115. };
  116. struct security_info {
  117. bool security_enable;
  118. u32 ptk_cipher;
  119. u32 gtk_cipher;
  120. };
  121. struct wmm_qinfo {
  122. s32 weight;
  123. s32 wme_params;
  124. s32 pkt_contended;
  125. s32 txop;
  126. };
  127. struct transmit_q_stats {
  128. u32 total_tx_pkt_send[NUM_EDCA_QUEUES + 2];
  129. u32 total_tx_pkt_freed[NUM_EDCA_QUEUES + 2];
  130. };
  131. struct vif_priv {
  132. bool is_ht;
  133. bool sgi;
  134. u16 seq_start;
  135. };
  136. struct rsi_event {
  137. atomic_t event_condition;
  138. wait_queue_head_t event_queue;
  139. };
  140. struct rsi_thread {
  141. void (*thread_function)(void *);
  142. struct completion completion;
  143. struct task_struct *task;
  144. struct rsi_event event;
  145. atomic_t thread_done;
  146. };
  147. struct cqm_info {
  148. s8 last_cqm_event_rssi;
  149. int rssi_thold;
  150. u32 rssi_hyst;
  151. };
  152. struct xtended_desc {
  153. u8 confirm_frame_type;
  154. u8 retry_cnt;
  155. u16 reserved;
  156. };
  157. enum rsi_dfs_regions {
  158. RSI_REGION_FCC = 0,
  159. RSI_REGION_ETSI,
  160. RSI_REGION_TELEC,
  161. RSI_REGION_WORLD
  162. };
  163. struct rsi_common {
  164. struct rsi_hw *priv;
  165. struct vif_priv vif_info[RSI_MAX_VIFS];
  166. bool mgmt_q_block;
  167. struct version_info driver_ver;
  168. struct version_info fw_ver;
  169. struct rsi_thread tx_thread;
  170. struct sk_buff_head tx_queue[NUM_EDCA_QUEUES + 2];
  171. /* Mutex declaration */
  172. struct mutex mutex;
  173. /* Mutex used for tx thread */
  174. struct mutex tx_lock;
  175. /* Mutex used for rx thread */
  176. struct mutex rx_lock;
  177. u8 endpoint;
  178. /* Channel/band related */
  179. u8 band;
  180. u8 num_supp_bands;
  181. u8 channel_width;
  182. u16 rts_threshold;
  183. u16 bitrate_mask[2];
  184. u32 fixedrate_mask[2];
  185. u8 rf_reset;
  186. struct transmit_q_stats tx_stats;
  187. struct security_info secinfo;
  188. struct wmm_qinfo tx_qinfo[NUM_EDCA_QUEUES];
  189. struct ieee80211_tx_queue_params edca_params[NUM_EDCA_QUEUES];
  190. u8 mac_addr[IEEE80211_ADDR_LEN];
  191. /* state related */
  192. u32 fsm_state;
  193. bool init_done;
  194. u8 bb_rf_prog_count;
  195. bool iface_down;
  196. /* Generic */
  197. u8 channel;
  198. u8 *rx_data_pkt;
  199. u8 mac_id;
  200. u8 radio_id;
  201. u16 rate_pwr[20];
  202. u16 min_rate;
  203. /* WMM algo related */
  204. u8 selected_qnum;
  205. u32 pkt_cnt;
  206. u8 min_weight;
  207. /* bgscan related */
  208. struct cqm_info cqm_info;
  209. bool hw_data_qs_blocked;
  210. u8 driver_mode;
  211. u8 coex_mode;
  212. u16 oper_mode;
  213. u8 lp_ps_handshake_mode;
  214. u8 ulp_ps_handshake_mode;
  215. u8 uapsd_bitmap;
  216. u8 rf_power_val;
  217. u8 wlan_rf_power_mode;
  218. u8 obm_ant_sel_val;
  219. int tx_power;
  220. u8 ant_in_use;
  221. u16 beacon_interval;
  222. u8 dtim_cnt;
  223. /* AP mode parameters */
  224. u8 beacon_enabled;
  225. u16 beacon_cnt;
  226. struct rsi_sta stations[RSI_MAX_ASSOC_STAS + 1];
  227. int num_stations;
  228. int max_stations;
  229. struct ieee80211_key_conf *key;
  230. };
  231. enum host_intf {
  232. RSI_HOST_INTF_SDIO = 0,
  233. RSI_HOST_INTF_USB
  234. };
  235. struct eepromrw_info {
  236. u32 offset;
  237. u32 length;
  238. u8 write;
  239. u16 eeprom_erase;
  240. u8 data[480];
  241. };
  242. struct eeprom_read {
  243. u16 length;
  244. u16 off_set;
  245. };
  246. struct rsi_hw {
  247. struct rsi_common *priv;
  248. u8 device_model;
  249. struct ieee80211_hw *hw;
  250. struct ieee80211_vif *vifs[RSI_MAX_VIFS];
  251. struct ieee80211_tx_queue_params edca_params[NUM_EDCA_QUEUES];
  252. struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
  253. struct device *device;
  254. u8 sc_nvifs;
  255. enum host_intf rsi_host_intf;
  256. u16 block_size;
  257. enum ps_state ps_state;
  258. struct rsi_ps_info ps_info;
  259. spinlock_t ps_lock; /*To protect power save config*/
  260. u32 usb_buffer_status_reg;
  261. #ifdef CONFIG_RSI_DEBUGFS
  262. struct rsi_debugfs *dfsentry;
  263. u8 num_debugfs_entries;
  264. #endif
  265. char *fw_file_name;
  266. struct timer_list bl_cmd_timer;
  267. bool blcmd_timer_expired;
  268. u32 flash_capacity;
  269. struct eepromrw_info eeprom;
  270. u32 interrupt_status;
  271. u8 dfs_region;
  272. char country[2];
  273. void *rsi_dev;
  274. struct rsi_host_intf_ops *host_intf_ops;
  275. int (*check_hw_queue_status)(struct rsi_hw *adapter, u8 q_num);
  276. int (*rx_urb_submit)(struct rsi_hw *adapter);
  277. int (*determine_event_timeout)(struct rsi_hw *adapter);
  278. };
  279. struct rsi_host_intf_ops {
  280. int (*read_pkt)(struct rsi_hw *adapter, u8 *pkt, u32 len);
  281. int (*write_pkt)(struct rsi_hw *adapter, u8 *pkt, u32 len);
  282. int (*master_access_msword)(struct rsi_hw *adapter, u16 ms_word);
  283. int (*read_reg_multiple)(struct rsi_hw *adapter, u32 addr,
  284. u8 *data, u16 count);
  285. int (*write_reg_multiple)(struct rsi_hw *adapter, u32 addr,
  286. u8 *data, u16 count);
  287. int (*master_reg_read)(struct rsi_hw *adapter, u32 addr,
  288. u32 *read_buf, u16 size);
  289. int (*master_reg_write)(struct rsi_hw *adapter,
  290. unsigned long addr, unsigned long data,
  291. u16 size);
  292. int (*load_data_master_write)(struct rsi_hw *adapter, u32 addr,
  293. u32 instructions_size, u16 block_size,
  294. u8 *fw);
  295. };
  296. #endif