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