core.h 14 KB

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