core.h 14 KB

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