]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/wireless/ath/ath10k/core.h
Merge tag 'mac80211-next-for-john-2014-11-04' of git://git.kernel.org/pub/scm/linux...
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / ath / ath10k / core.h
1 /*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #ifndef _CORE_H_
19 #define _CORE_H_
20
21 #include <linux/completion.h>
22 #include <linux/if_ether.h>
23 #include <linux/types.h>
24 #include <linux/pci.h>
25 #include <linux/uuid.h>
26 #include <linux/time.h>
27
28 #include "htt.h"
29 #include "htc.h"
30 #include "hw.h"
31 #include "targaddrs.h"
32 #include "wmi.h"
33 #include "../ath.h"
34 #include "../regd.h"
35 #include "../dfs_pattern_detector.h"
36 #include "spectral.h"
37
38 #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
39 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
40 #define WO(_f) ((_f##_OFFSET) >> 2)
41
42 #define ATH10K_SCAN_ID 0
43 #define WMI_READY_TIMEOUT (5 * HZ)
44 #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
45 #define ATH10K_NUM_CHANS 38
46
47 /* Antenna noise floor */
48 #define ATH10K_DEFAULT_NOISE_FLOOR -95
49
50 #define ATH10K_MAX_NUM_MGMT_PENDING 128
51
52 /* number of failed packets */
53 #define ATH10K_KICKOUT_THRESHOLD 50
54
55 /*
56 * Use insanely high numbers to make sure that the firmware implementation
57 * won't start, we have the same functionality already in hostapd. Unit
58 * is seconds.
59 */
60 #define ATH10K_KEEPALIVE_MIN_IDLE 3747
61 #define ATH10K_KEEPALIVE_MAX_IDLE 3895
62 #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
63
64 struct ath10k;
65
66 enum ath10k_bus {
67 ATH10K_BUS_PCI,
68 };
69
70 static inline const char *ath10k_bus_str(enum ath10k_bus bus)
71 {
72 switch (bus) {
73 case ATH10K_BUS_PCI:
74 return "pci";
75 }
76
77 return "unknown";
78 }
79
80 struct ath10k_skb_cb {
81 dma_addr_t paddr;
82 u8 vdev_id;
83
84 struct {
85 u8 tid;
86 bool is_offchan;
87 struct ath10k_htt_txbuf *txbuf;
88 u32 txbuf_paddr;
89 } __packed htt;
90
91 struct {
92 bool dtim_zero;
93 bool deliver_cab;
94 } bcn;
95 } __packed;
96
97 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
98 {
99 BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
100 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
101 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
102 }
103
104 static inline u32 host_interest_item_address(u32 item_offset)
105 {
106 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
107 }
108
109 struct ath10k_bmi {
110 bool done_sent;
111 };
112
113 struct ath10k_mem_chunk {
114 void *vaddr;
115 dma_addr_t paddr;
116 u32 len;
117 u32 req_id;
118 };
119
120 struct ath10k_wmi {
121 enum ath10k_htc_ep_id eid;
122 struct completion service_ready;
123 struct completion unified_ready;
124 wait_queue_head_t tx_credits_wq;
125 struct wmi_cmd_map *cmd;
126 struct wmi_vdev_param_map *vdev_param;
127 struct wmi_pdev_param_map *pdev_param;
128
129 u32 num_mem_chunks;
130 struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
131 };
132
133 struct ath10k_fw_stats_peer {
134 struct list_head list;
135
136 u8 peer_macaddr[ETH_ALEN];
137 u32 peer_rssi;
138 u32 peer_tx_rate;
139 u32 peer_rx_rate; /* 10x only */
140 };
141
142 struct ath10k_fw_stats_pdev {
143 struct list_head list;
144
145 /* PDEV stats */
146 s32 ch_noise_floor;
147 u32 tx_frame_count;
148 u32 rx_frame_count;
149 u32 rx_clear_count;
150 u32 cycle_count;
151 u32 phy_err_count;
152 u32 chan_tx_power;
153 u32 ack_rx_bad;
154 u32 rts_bad;
155 u32 rts_good;
156 u32 fcs_bad;
157 u32 no_beacons;
158 u32 mib_int_count;
159
160 /* PDEV TX stats */
161 s32 comp_queued;
162 s32 comp_delivered;
163 s32 msdu_enqued;
164 s32 mpdu_enqued;
165 s32 wmm_drop;
166 s32 local_enqued;
167 s32 local_freed;
168 s32 hw_queued;
169 s32 hw_reaped;
170 s32 underrun;
171 s32 tx_abort;
172 s32 mpdus_requed;
173 u32 tx_ko;
174 u32 data_rc;
175 u32 self_triggers;
176 u32 sw_retry_failure;
177 u32 illgl_rate_phy_err;
178 u32 pdev_cont_xretry;
179 u32 pdev_tx_timeout;
180 u32 pdev_resets;
181 u32 phy_underrun;
182 u32 txop_ovf;
183
184 /* PDEV RX stats */
185 s32 mid_ppdu_route_change;
186 s32 status_rcvd;
187 s32 r0_frags;
188 s32 r1_frags;
189 s32 r2_frags;
190 s32 r3_frags;
191 s32 htt_msdus;
192 s32 htt_mpdus;
193 s32 loc_msdus;
194 s32 loc_mpdus;
195 s32 oversize_amsdu;
196 s32 phy_errs;
197 s32 phy_err_drop;
198 s32 mpdu_errs;
199 };
200
201 struct ath10k_fw_stats {
202 struct list_head pdevs;
203 struct list_head peers;
204 };
205
206 struct ath10k_dfs_stats {
207 u32 phy_errors;
208 u32 pulses_total;
209 u32 pulses_detected;
210 u32 pulses_discarded;
211 u32 radar_detected;
212 };
213
214 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
215
216 struct ath10k_peer {
217 struct list_head list;
218 int vdev_id;
219 u8 addr[ETH_ALEN];
220 DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
221 struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
222 };
223
224 struct ath10k_sta {
225 struct ath10k_vif *arvif;
226
227 /* the following are protected by ar->data_lock */
228 u32 changed; /* IEEE80211_RC_* */
229 u32 bw;
230 u32 nss;
231 u32 smps;
232
233 struct work_struct update_wk;
234 };
235
236 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
237
238 struct ath10k_vif {
239 struct list_head list;
240
241 u32 vdev_id;
242 enum wmi_vdev_type vdev_type;
243 enum wmi_vdev_subtype vdev_subtype;
244 u32 beacon_interval;
245 u32 dtim_period;
246 struct sk_buff *beacon;
247 /* protected by data_lock */
248 bool beacon_sent;
249 void *beacon_buf;
250 dma_addr_t beacon_paddr;
251
252 struct ath10k *ar;
253 struct ieee80211_vif *vif;
254
255 bool is_started;
256 bool is_up;
257 bool spectral_enabled;
258 u32 aid;
259 u8 bssid[ETH_ALEN];
260
261 struct work_struct wep_key_work;
262 struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
263 u8 def_wep_key_idx;
264 u8 def_wep_key_newidx;
265
266 u16 tx_seq_no;
267
268 union {
269 struct {
270 u32 uapsd;
271 } sta;
272 struct {
273 /* 127 stations; wmi limit */
274 u8 tim_bitmap[16];
275 u8 tim_len;
276 u32 ssid_len;
277 u8 ssid[IEEE80211_MAX_SSID_LEN];
278 bool hidden_ssid;
279 /* P2P_IE with NoA attribute for P2P_GO case */
280 u32 noa_len;
281 u8 *noa_data;
282 } ap;
283 } u;
284
285 u8 fixed_rate;
286 u8 fixed_nss;
287 u8 force_sgi;
288 bool use_cts_prot;
289 int num_legacy_stations;
290 int txpower;
291 };
292
293 struct ath10k_vif_iter {
294 u32 vdev_id;
295 struct ath10k_vif *arvif;
296 };
297
298 /* used for crash-dump storage, protected by data-lock */
299 struct ath10k_fw_crash_data {
300 bool crashed_since_read;
301
302 uuid_le uuid;
303 struct timespec timestamp;
304 __le32 registers[REG_DUMP_COUNT_QCA988X];
305 };
306
307 struct ath10k_debug {
308 struct dentry *debugfs_phy;
309
310 struct ath10k_fw_stats fw_stats;
311 struct completion fw_stats_complete;
312 bool fw_stats_done;
313 DECLARE_BITMAP(wmi_service_bitmap, WMI_SERVICE_MAX);
314
315 unsigned long htt_stats_mask;
316 struct delayed_work htt_stats_dwork;
317 struct ath10k_dfs_stats dfs_stats;
318 struct ath_dfs_pool_stats dfs_pool_stats;
319
320 /* protected by conf_mutex */
321 u32 fw_dbglog_mask;
322 u32 pktlog_filter;
323
324 u8 htt_max_amsdu;
325 u8 htt_max_ampdu;
326
327 struct ath10k_fw_crash_data *fw_crash_data;
328 };
329
330 enum ath10k_state {
331 ATH10K_STATE_OFF = 0,
332 ATH10K_STATE_ON,
333
334 /* When doing firmware recovery the device is first powered down.
335 * mac80211 is supposed to call in to start() hook later on. It is
336 * however possible that driver unloading and firmware crash overlap.
337 * mac80211 can wait on conf_mutex in stop() while the device is
338 * stopped in ath10k_core_restart() work holding conf_mutex. The state
339 * RESTARTED means that the device is up and mac80211 has started hw
340 * reconfiguration. Once mac80211 is done with the reconfiguration we
341 * set the state to STATE_ON in reconfig_complete(). */
342 ATH10K_STATE_RESTARTING,
343 ATH10K_STATE_RESTARTED,
344
345 /* The device has crashed while restarting hw. This state is like ON
346 * but commands are blocked in HTC and -ECOMM response is given. This
347 * prevents completion timeouts and makes the driver more responsive to
348 * userspace commands. This is also prevents recursive recovery. */
349 ATH10K_STATE_WEDGED,
350
351 /* factory tests */
352 ATH10K_STATE_UTF,
353 };
354
355 enum ath10k_firmware_mode {
356 /* the default mode, standard 802.11 functionality */
357 ATH10K_FIRMWARE_MODE_NORMAL,
358
359 /* factory tests etc */
360 ATH10K_FIRMWARE_MODE_UTF,
361 };
362
363 enum ath10k_fw_features {
364 /* wmi_mgmt_rx_hdr contains extra RSSI information */
365 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
366
367 /* firmware from 10X branch */
368 ATH10K_FW_FEATURE_WMI_10X = 1,
369
370 /* firmware support tx frame management over WMI, otherwise it's HTT */
371 ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
372
373 /* Firmware does not support P2P */
374 ATH10K_FW_FEATURE_NO_P2P = 3,
375
376 /* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature bit
377 * is required to be set as well.
378 */
379 ATH10K_FW_FEATURE_WMI_10_2 = 4,
380
381 /* keep last */
382 ATH10K_FW_FEATURE_COUNT,
383 };
384
385 enum ath10k_dev_flags {
386 /* Indicates that ath10k device is during CAC phase of DFS */
387 ATH10K_CAC_RUNNING,
388 ATH10K_FLAG_CORE_REGISTERED,
389 };
390
391 enum ath10k_cal_mode {
392 ATH10K_CAL_MODE_FILE,
393 ATH10K_CAL_MODE_OTP,
394 };
395
396 static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
397 {
398 switch (mode) {
399 case ATH10K_CAL_MODE_FILE:
400 return "file";
401 case ATH10K_CAL_MODE_OTP:
402 return "otp";
403 }
404
405 return "unknown";
406 }
407
408 enum ath10k_scan_state {
409 ATH10K_SCAN_IDLE,
410 ATH10K_SCAN_STARTING,
411 ATH10K_SCAN_RUNNING,
412 ATH10K_SCAN_ABORTING,
413 };
414
415 static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
416 {
417 switch (state) {
418 case ATH10K_SCAN_IDLE:
419 return "idle";
420 case ATH10K_SCAN_STARTING:
421 return "starting";
422 case ATH10K_SCAN_RUNNING:
423 return "running";
424 case ATH10K_SCAN_ABORTING:
425 return "aborting";
426 }
427
428 return "unknown";
429 }
430
431 struct ath10k {
432 struct ath_common ath_common;
433 struct ieee80211_hw *hw;
434 struct device *dev;
435 u8 mac_addr[ETH_ALEN];
436
437 u32 chip_id;
438 u32 target_version;
439 u8 fw_version_major;
440 u32 fw_version_minor;
441 u16 fw_version_release;
442 u16 fw_version_build;
443 u32 phy_capability;
444 u32 hw_min_tx_power;
445 u32 hw_max_tx_power;
446 u32 ht_cap_info;
447 u32 vht_cap_info;
448 u32 num_rf_chains;
449
450 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
451
452 struct targetdef *targetdef;
453 struct hostdef *hostdef;
454
455 bool p2p;
456
457 struct {
458 enum ath10k_bus bus;
459 const struct ath10k_hif_ops *ops;
460 } hif;
461
462 struct completion target_suspend;
463
464 struct ath10k_bmi bmi;
465 struct ath10k_wmi wmi;
466 struct ath10k_htc htc;
467 struct ath10k_htt htt;
468
469 struct ath10k_hw_params {
470 u32 id;
471 const char *name;
472 u32 patch_load_addr;
473
474 struct ath10k_hw_params_fw {
475 const char *dir;
476 const char *fw;
477 const char *otp;
478 const char *board;
479 } fw;
480 } hw_params;
481
482 const struct firmware *board;
483 const void *board_data;
484 size_t board_len;
485
486 const struct firmware *otp;
487 const void *otp_data;
488 size_t otp_len;
489
490 const struct firmware *firmware;
491 const void *firmware_data;
492 size_t firmware_len;
493
494 const struct firmware *cal_file;
495
496 int fw_api;
497 enum ath10k_cal_mode cal_mode;
498
499 struct {
500 struct completion started;
501 struct completion completed;
502 struct completion on_channel;
503 struct delayed_work timeout;
504 enum ath10k_scan_state state;
505 bool is_roc;
506 int vdev_id;
507 int roc_freq;
508 } scan;
509
510 struct {
511 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
512 } mac;
513
514 /* should never be NULL; needed for regular htt rx */
515 struct ieee80211_channel *rx_channel;
516
517 /* valid during scan; needed for mgmt rx during scan */
518 struct ieee80211_channel *scan_channel;
519
520 /* current operating channel definition */
521 struct cfg80211_chan_def chandef;
522
523 unsigned long long free_vdev_map;
524 bool monitor;
525 int monitor_vdev_id;
526 bool monitor_started;
527 unsigned int filter_flags;
528 unsigned long dev_flags;
529 u32 dfs_block_radar_events;
530
531 /* protected by conf_mutex */
532 bool radar_enabled;
533 int num_started_vdevs;
534
535 /* Protected by conf-mutex */
536 u8 supp_tx_chainmask;
537 u8 supp_rx_chainmask;
538 u8 cfg_tx_chainmask;
539 u8 cfg_rx_chainmask;
540
541 struct wmi_pdev_set_wmm_params_arg wmm_params;
542 struct completion install_key_done;
543
544 struct completion vdev_setup_done;
545
546 struct workqueue_struct *workqueue;
547
548 /* prevents concurrent FW reconfiguration */
549 struct mutex conf_mutex;
550
551 /* protects shared structure data */
552 spinlock_t data_lock;
553
554 struct list_head arvifs;
555 struct list_head peers;
556 wait_queue_head_t peer_mapping_wq;
557
558 /* number of created peers; protected by data_lock */
559 int num_peers;
560
561 struct work_struct offchan_tx_work;
562 struct sk_buff_head offchan_tx_queue;
563 struct completion offchan_tx_completed;
564 struct sk_buff *offchan_tx_skb;
565
566 struct work_struct wmi_mgmt_tx_work;
567 struct sk_buff_head wmi_mgmt_tx_queue;
568
569 enum ath10k_state state;
570
571 struct work_struct register_work;
572 struct work_struct restart_work;
573
574 /* cycle count is reported twice for each visited channel during scan.
575 * access protected by data_lock */
576 u32 survey_last_rx_clear_count;
577 u32 survey_last_cycle_count;
578 struct survey_info survey[ATH10K_NUM_CHANS];
579
580 struct dfs_pattern_detector *dfs_detector;
581
582 #ifdef CONFIG_ATH10K_DEBUGFS
583 struct ath10k_debug debug;
584 #endif
585
586 struct {
587 /* relay(fs) channel for spectral scan */
588 struct rchan *rfs_chan_spec_scan;
589
590 /* spectral_mode and spec_config are protected by conf_mutex */
591 enum ath10k_spectral_mode mode;
592 struct ath10k_spec_scan config;
593 } spectral;
594
595 struct {
596 /* protected by conf_mutex */
597 const struct firmware *utf;
598 DECLARE_BITMAP(orig_fw_features, ATH10K_FW_FEATURE_COUNT);
599
600 /* protected by data_lock */
601 bool utf_monitor;
602 } testmode;
603
604 struct {
605 /* protected by data_lock */
606 u32 fw_crash_counter;
607 u32 fw_warm_reset_counter;
608 u32 fw_cold_reset_counter;
609 } stats;
610
611 /* must be last */
612 u8 drv_priv[0] __aligned(sizeof(void *));
613 };
614
615 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
616 enum ath10k_bus bus,
617 const struct ath10k_hif_ops *hif_ops);
618 void ath10k_core_destroy(struct ath10k *ar);
619
620 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode);
621 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
622 void ath10k_core_stop(struct ath10k *ar);
623 int ath10k_core_register(struct ath10k *ar, u32 chip_id);
624 void ath10k_core_unregister(struct ath10k *ar);
625
626 #endif /* _CORE_H_ */