core.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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. #include "thermal.h"
  35. #include "wow.h"
  36. #include "swap.h"
  37. #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
  38. #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
  39. #define WO(_f) ((_f##_OFFSET) >> 2)
  40. #define ATH10K_SCAN_ID 0
  41. #define WMI_READY_TIMEOUT (5 * HZ)
  42. #define ATH10K_FLUSH_TIMEOUT_HZ (5 * HZ)
  43. #define ATH10K_CONNECTION_LOSS_HZ (3 * HZ)
  44. #define ATH10K_NUM_CHANS 39
  45. /* Antenna noise floor */
  46. #define ATH10K_DEFAULT_NOISE_FLOOR -95
  47. #define ATH10K_MAX_NUM_MGMT_PENDING 128
  48. /* number of failed packets (20 packets with 16 sw reties each) */
  49. #define ATH10K_KICKOUT_THRESHOLD (20 * 16)
  50. /*
  51. * Use insanely high numbers to make sure that the firmware implementation
  52. * won't start, we have the same functionality already in hostapd. Unit
  53. * is seconds.
  54. */
  55. #define ATH10K_KEEPALIVE_MIN_IDLE 3747
  56. #define ATH10K_KEEPALIVE_MAX_IDLE 3895
  57. #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
  58. struct ath10k;
  59. enum ath10k_bus {
  60. ATH10K_BUS_PCI,
  61. ATH10K_BUS_AHB,
  62. };
  63. static inline const char *ath10k_bus_str(enum ath10k_bus bus)
  64. {
  65. switch (bus) {
  66. case ATH10K_BUS_PCI:
  67. return "pci";
  68. case ATH10K_BUS_AHB:
  69. return "ahb";
  70. }
  71. return "unknown";
  72. }
  73. enum ath10k_skb_flags {
  74. ATH10K_SKB_F_NO_HWCRYPT = BIT(0),
  75. ATH10K_SKB_F_DTIM_ZERO = BIT(1),
  76. ATH10K_SKB_F_DELIVER_CAB = BIT(2),
  77. ATH10K_SKB_F_MGMT = BIT(3),
  78. ATH10K_SKB_F_QOS = BIT(4),
  79. };
  80. struct ath10k_skb_cb {
  81. dma_addr_t paddr;
  82. u8 flags;
  83. u8 eid;
  84. u16 msdu_id;
  85. struct ieee80211_vif *vif;
  86. struct ieee80211_txq *txq;
  87. } __packed;
  88. struct ath10k_skb_rxcb {
  89. dma_addr_t paddr;
  90. struct hlist_node hlist;
  91. };
  92. static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
  93. {
  94. BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
  95. IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
  96. return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
  97. }
  98. static inline struct ath10k_skb_rxcb *ATH10K_SKB_RXCB(struct sk_buff *skb)
  99. {
  100. BUILD_BUG_ON(sizeof(struct ath10k_skb_rxcb) > sizeof(skb->cb));
  101. return (struct ath10k_skb_rxcb *)skb->cb;
  102. }
  103. #define ATH10K_RXCB_SKB(rxcb) \
  104. container_of((void *)rxcb, struct sk_buff, cb)
  105. static inline u32 host_interest_item_address(u32 item_offset)
  106. {
  107. return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
  108. }
  109. struct ath10k_bmi {
  110. bool done_sent;
  111. };
  112. struct ath10k_mem_chunk {
  113. void *vaddr;
  114. dma_addr_t paddr;
  115. u32 len;
  116. u32 req_id;
  117. };
  118. struct ath10k_wmi {
  119. enum ath10k_htc_ep_id eid;
  120. struct completion service_ready;
  121. struct completion unified_ready;
  122. wait_queue_head_t tx_credits_wq;
  123. DECLARE_BITMAP(svc_map, WMI_SERVICE_MAX);
  124. struct wmi_cmd_map *cmd;
  125. struct wmi_vdev_param_map *vdev_param;
  126. struct wmi_pdev_param_map *pdev_param;
  127. const struct wmi_ops *ops;
  128. const struct wmi_peer_flags_map *peer_flags;
  129. u32 num_mem_chunks;
  130. u32 rx_decap_mode;
  131. struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
  132. };
  133. struct ath10k_fw_stats_peer {
  134. struct list_head list;
  135. u8 peer_macaddr[ETH_ALEN];
  136. u32 peer_rssi;
  137. u32 peer_tx_rate;
  138. u32 peer_rx_rate; /* 10x only */
  139. u32 rx_duration;
  140. };
  141. struct ath10k_fw_extd_stats_peer {
  142. struct list_head list;
  143. u8 peer_macaddr[ETH_ALEN];
  144. u32 rx_duration;
  145. };
  146. struct ath10k_fw_stats_vdev {
  147. struct list_head list;
  148. u32 vdev_id;
  149. u32 beacon_snr;
  150. u32 data_snr;
  151. u32 num_tx_frames[4];
  152. u32 num_rx_frames;
  153. u32 num_tx_frames_retries[4];
  154. u32 num_tx_frames_failures[4];
  155. u32 num_rts_fail;
  156. u32 num_rts_success;
  157. u32 num_rx_err;
  158. u32 num_rx_discard;
  159. u32 num_tx_not_acked;
  160. u32 tx_rate_history[10];
  161. u32 beacon_rssi_history[10];
  162. };
  163. struct ath10k_fw_stats_pdev {
  164. struct list_head list;
  165. /* PDEV stats */
  166. s32 ch_noise_floor;
  167. u32 tx_frame_count;
  168. u32 rx_frame_count;
  169. u32 rx_clear_count;
  170. u32 cycle_count;
  171. u32 phy_err_count;
  172. u32 chan_tx_power;
  173. u32 ack_rx_bad;
  174. u32 rts_bad;
  175. u32 rts_good;
  176. u32 fcs_bad;
  177. u32 no_beacons;
  178. u32 mib_int_count;
  179. /* PDEV TX stats */
  180. s32 comp_queued;
  181. s32 comp_delivered;
  182. s32 msdu_enqued;
  183. s32 mpdu_enqued;
  184. s32 wmm_drop;
  185. s32 local_enqued;
  186. s32 local_freed;
  187. s32 hw_queued;
  188. s32 hw_reaped;
  189. s32 underrun;
  190. u32 hw_paused;
  191. s32 tx_abort;
  192. s32 mpdus_requed;
  193. u32 tx_ko;
  194. u32 data_rc;
  195. u32 self_triggers;
  196. u32 sw_retry_failure;
  197. u32 illgl_rate_phy_err;
  198. u32 pdev_cont_xretry;
  199. u32 pdev_tx_timeout;
  200. u32 pdev_resets;
  201. u32 phy_underrun;
  202. u32 txop_ovf;
  203. u32 seq_posted;
  204. u32 seq_failed_queueing;
  205. u32 seq_completed;
  206. u32 seq_restarted;
  207. u32 mu_seq_posted;
  208. u32 mpdus_sw_flush;
  209. u32 mpdus_hw_filter;
  210. u32 mpdus_truncated;
  211. u32 mpdus_ack_failed;
  212. u32 mpdus_expired;
  213. /* PDEV RX stats */
  214. s32 mid_ppdu_route_change;
  215. s32 status_rcvd;
  216. s32 r0_frags;
  217. s32 r1_frags;
  218. s32 r2_frags;
  219. s32 r3_frags;
  220. s32 htt_msdus;
  221. s32 htt_mpdus;
  222. s32 loc_msdus;
  223. s32 loc_mpdus;
  224. s32 oversize_amsdu;
  225. s32 phy_errs;
  226. s32 phy_err_drop;
  227. s32 mpdu_errs;
  228. s32 rx_ovfl_errs;
  229. };
  230. struct ath10k_fw_stats {
  231. bool extended;
  232. struct list_head pdevs;
  233. struct list_head vdevs;
  234. struct list_head peers;
  235. struct list_head peers_extd;
  236. };
  237. #define ATH10K_TPC_TABLE_TYPE_FLAG 1
  238. #define ATH10K_TPC_PREAM_TABLE_END 0xFFFF
  239. struct ath10k_tpc_table {
  240. u32 pream_idx[WMI_TPC_RATE_MAX];
  241. u8 rate_code[WMI_TPC_RATE_MAX];
  242. char tpc_value[WMI_TPC_RATE_MAX][WMI_TPC_TX_N_CHAIN * WMI_TPC_BUF_SIZE];
  243. };
  244. struct ath10k_tpc_stats {
  245. u32 reg_domain;
  246. u32 chan_freq;
  247. u32 phy_mode;
  248. u32 twice_antenna_reduction;
  249. u32 twice_max_rd_power;
  250. s32 twice_antenna_gain;
  251. u32 power_limit;
  252. u32 num_tx_chain;
  253. u32 ctl;
  254. u32 rate_max;
  255. u8 flag[WMI_TPC_FLAG];
  256. struct ath10k_tpc_table tpc_table[WMI_TPC_FLAG];
  257. };
  258. struct ath10k_dfs_stats {
  259. u32 phy_errors;
  260. u32 pulses_total;
  261. u32 pulses_detected;
  262. u32 pulses_discarded;
  263. u32 radar_detected;
  264. };
  265. #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
  266. struct ath10k_peer {
  267. struct list_head list;
  268. struct ieee80211_vif *vif;
  269. struct ieee80211_sta *sta;
  270. int vdev_id;
  271. u8 addr[ETH_ALEN];
  272. DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
  273. /* protected by ar->data_lock */
  274. struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
  275. };
  276. struct ath10k_txq {
  277. struct list_head list;
  278. unsigned long num_fw_queued;
  279. unsigned long num_push_allowed;
  280. };
  281. struct ath10k_sta {
  282. struct ath10k_vif *arvif;
  283. /* the following are protected by ar->data_lock */
  284. u32 changed; /* IEEE80211_RC_* */
  285. u32 bw;
  286. u32 nss;
  287. u32 smps;
  288. u16 peer_id;
  289. struct work_struct update_wk;
  290. #ifdef CONFIG_MAC80211_DEBUGFS
  291. /* protected by conf_mutex */
  292. bool aggr_mode;
  293. u64 rx_duration;
  294. #endif
  295. };
  296. #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5 * HZ)
  297. enum ath10k_beacon_state {
  298. ATH10K_BEACON_SCHEDULED = 0,
  299. ATH10K_BEACON_SENDING,
  300. ATH10K_BEACON_SENT,
  301. };
  302. struct ath10k_vif {
  303. struct list_head list;
  304. u32 vdev_id;
  305. u16 peer_id;
  306. enum wmi_vdev_type vdev_type;
  307. enum wmi_vdev_subtype vdev_subtype;
  308. u32 beacon_interval;
  309. u32 dtim_period;
  310. struct sk_buff *beacon;
  311. /* protected by data_lock */
  312. enum ath10k_beacon_state beacon_state;
  313. void *beacon_buf;
  314. dma_addr_t beacon_paddr;
  315. unsigned long tx_paused; /* arbitrary values defined by target */
  316. struct ath10k *ar;
  317. struct ieee80211_vif *vif;
  318. bool is_started;
  319. bool is_up;
  320. bool spectral_enabled;
  321. bool ps;
  322. u32 aid;
  323. u8 bssid[ETH_ALEN];
  324. struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
  325. s8 def_wep_key_idx;
  326. u16 tx_seq_no;
  327. union {
  328. struct {
  329. u32 uapsd;
  330. } sta;
  331. struct {
  332. /* 512 stations */
  333. u8 tim_bitmap[64];
  334. u8 tim_len;
  335. u32 ssid_len;
  336. u8 ssid[IEEE80211_MAX_SSID_LEN];
  337. bool hidden_ssid;
  338. /* P2P_IE with NoA attribute for P2P_GO case */
  339. u32 noa_len;
  340. u8 *noa_data;
  341. } ap;
  342. } u;
  343. bool use_cts_prot;
  344. bool nohwcrypt;
  345. int num_legacy_stations;
  346. int txpower;
  347. struct wmi_wmm_params_all_arg wmm_params;
  348. struct work_struct ap_csa_work;
  349. struct delayed_work connection_loss_work;
  350. struct cfg80211_bitrate_mask bitrate_mask;
  351. };
  352. struct ath10k_vif_iter {
  353. u32 vdev_id;
  354. struct ath10k_vif *arvif;
  355. };
  356. /* used for crash-dump storage, protected by data-lock */
  357. struct ath10k_fw_crash_data {
  358. bool crashed_since_read;
  359. uuid_le uuid;
  360. struct timespec timestamp;
  361. __le32 registers[REG_DUMP_COUNT_QCA988X];
  362. };
  363. struct ath10k_debug {
  364. struct dentry *debugfs_phy;
  365. struct ath10k_fw_stats fw_stats;
  366. struct completion fw_stats_complete;
  367. bool fw_stats_done;
  368. unsigned long htt_stats_mask;
  369. struct delayed_work htt_stats_dwork;
  370. struct ath10k_dfs_stats dfs_stats;
  371. struct ath_dfs_pool_stats dfs_pool_stats;
  372. /* used for tpc-dump storage, protected by data-lock */
  373. struct ath10k_tpc_stats *tpc_stats;
  374. struct completion tpc_complete;
  375. /* protected by conf_mutex */
  376. u32 fw_dbglog_mask;
  377. u32 fw_dbglog_level;
  378. u32 pktlog_filter;
  379. u32 reg_addr;
  380. u32 nf_cal_period;
  381. struct ath10k_fw_crash_data *fw_crash_data;
  382. };
  383. enum ath10k_state {
  384. ATH10K_STATE_OFF = 0,
  385. ATH10K_STATE_ON,
  386. /* When doing firmware recovery the device is first powered down.
  387. * mac80211 is supposed to call in to start() hook later on. It is
  388. * however possible that driver unloading and firmware crash overlap.
  389. * mac80211 can wait on conf_mutex in stop() while the device is
  390. * stopped in ath10k_core_restart() work holding conf_mutex. The state
  391. * RESTARTED means that the device is up and mac80211 has started hw
  392. * reconfiguration. Once mac80211 is done with the reconfiguration we
  393. * set the state to STATE_ON in reconfig_complete(). */
  394. ATH10K_STATE_RESTARTING,
  395. ATH10K_STATE_RESTARTED,
  396. /* The device has crashed while restarting hw. This state is like ON
  397. * but commands are blocked in HTC and -ECOMM response is given. This
  398. * prevents completion timeouts and makes the driver more responsive to
  399. * userspace commands. This is also prevents recursive recovery. */
  400. ATH10K_STATE_WEDGED,
  401. /* factory tests */
  402. ATH10K_STATE_UTF,
  403. };
  404. enum ath10k_firmware_mode {
  405. /* the default mode, standard 802.11 functionality */
  406. ATH10K_FIRMWARE_MODE_NORMAL,
  407. /* factory tests etc */
  408. ATH10K_FIRMWARE_MODE_UTF,
  409. };
  410. enum ath10k_fw_features {
  411. /* wmi_mgmt_rx_hdr contains extra RSSI information */
  412. ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
  413. /* Firmware from 10X branch. Deprecated, don't use in new code. */
  414. ATH10K_FW_FEATURE_WMI_10X = 1,
  415. /* firmware support tx frame management over WMI, otherwise it's HTT */
  416. ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
  417. /* Firmware does not support P2P */
  418. ATH10K_FW_FEATURE_NO_P2P = 3,
  419. /* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature
  420. * bit is required to be set as well. Deprecated, don't use in new
  421. * code.
  422. */
  423. ATH10K_FW_FEATURE_WMI_10_2 = 4,
  424. /* Some firmware revisions lack proper multi-interface client powersave
  425. * implementation. Enabling PS could result in connection drops,
  426. * traffic stalls, etc.
  427. */
  428. ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT = 5,
  429. /* Some firmware revisions have an incomplete WoWLAN implementation
  430. * despite WMI service bit being advertised. This feature flag is used
  431. * to distinguish whether WoWLAN is really supported or not.
  432. */
  433. ATH10K_FW_FEATURE_WOWLAN_SUPPORT = 6,
  434. /* Don't trust error code from otp.bin */
  435. ATH10K_FW_FEATURE_IGNORE_OTP_RESULT = 7,
  436. /* Some firmware revisions pad 4th hw address to 4 byte boundary making
  437. * it 8 bytes long in Native Wifi Rx decap.
  438. */
  439. ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING = 8,
  440. /* Firmware supports bypassing PLL setting on init. */
  441. ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT = 9,
  442. /* Raw mode support. If supported, FW supports receiving and trasmitting
  443. * frames in raw mode.
  444. */
  445. ATH10K_FW_FEATURE_RAW_MODE_SUPPORT = 10,
  446. /* Firmware Supports Adaptive CCA*/
  447. ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA = 11,
  448. /* Firmware supports management frame protection */
  449. ATH10K_FW_FEATURE_MFP_SUPPORT = 12,
  450. /* Firmware supports pull-push model where host shares it's software
  451. * queue state with firmware and firmware generates fetch requests
  452. * telling host which queues to dequeue tx from.
  453. *
  454. * Primary function of this is improved MU-MIMO performance with
  455. * multiple clients.
  456. */
  457. ATH10K_FW_FEATURE_PEER_FLOW_CONTROL = 13,
  458. /* Firmware supports BT-Coex without reloading firmware via pdev param.
  459. * To support Bluetooth coexistence pdev param, WMI_COEX_GPIO_SUPPORT of
  460. * extended resource config should be enabled always. This firmware IE
  461. * is used to configure WMI_COEX_GPIO_SUPPORT.
  462. */
  463. ATH10K_FW_FEATURE_BTCOEX_PARAM = 14,
  464. /* keep last */
  465. ATH10K_FW_FEATURE_COUNT,
  466. };
  467. enum ath10k_dev_flags {
  468. /* Indicates that ath10k device is during CAC phase of DFS */
  469. ATH10K_CAC_RUNNING,
  470. ATH10K_FLAG_CORE_REGISTERED,
  471. /* Device has crashed and needs to restart. This indicates any pending
  472. * waiters should immediately cancel instead of waiting for a time out.
  473. */
  474. ATH10K_FLAG_CRASH_FLUSH,
  475. /* Use Raw mode instead of native WiFi Tx/Rx encap mode.
  476. * Raw mode supports both hardware and software crypto. Native WiFi only
  477. * supports hardware crypto.
  478. */
  479. ATH10K_FLAG_RAW_MODE,
  480. /* Disable HW crypto engine */
  481. ATH10K_FLAG_HW_CRYPTO_DISABLED,
  482. /* Bluetooth coexistance enabled */
  483. ATH10K_FLAG_BTCOEX,
  484. /* Per Station statistics service */
  485. ATH10K_FLAG_PEER_STATS,
  486. };
  487. enum ath10k_cal_mode {
  488. ATH10K_CAL_MODE_FILE,
  489. ATH10K_CAL_MODE_OTP,
  490. ATH10K_CAL_MODE_DT,
  491. ATH10K_PRE_CAL_MODE_FILE,
  492. ATH10K_PRE_CAL_MODE_DT,
  493. ATH10K_CAL_MODE_EEPROM,
  494. };
  495. enum ath10k_crypt_mode {
  496. /* Only use hardware crypto engine */
  497. ATH10K_CRYPT_MODE_HW,
  498. /* Only use software crypto engine */
  499. ATH10K_CRYPT_MODE_SW,
  500. };
  501. static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
  502. {
  503. switch (mode) {
  504. case ATH10K_CAL_MODE_FILE:
  505. return "file";
  506. case ATH10K_CAL_MODE_OTP:
  507. return "otp";
  508. case ATH10K_CAL_MODE_DT:
  509. return "dt";
  510. case ATH10K_PRE_CAL_MODE_FILE:
  511. return "pre-cal-file";
  512. case ATH10K_PRE_CAL_MODE_DT:
  513. return "pre-cal-dt";
  514. case ATH10K_CAL_MODE_EEPROM:
  515. return "eeprom";
  516. }
  517. return "unknown";
  518. }
  519. enum ath10k_scan_state {
  520. ATH10K_SCAN_IDLE,
  521. ATH10K_SCAN_STARTING,
  522. ATH10K_SCAN_RUNNING,
  523. ATH10K_SCAN_ABORTING,
  524. };
  525. static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
  526. {
  527. switch (state) {
  528. case ATH10K_SCAN_IDLE:
  529. return "idle";
  530. case ATH10K_SCAN_STARTING:
  531. return "starting";
  532. case ATH10K_SCAN_RUNNING:
  533. return "running";
  534. case ATH10K_SCAN_ABORTING:
  535. return "aborting";
  536. }
  537. return "unknown";
  538. }
  539. enum ath10k_tx_pause_reason {
  540. ATH10K_TX_PAUSE_Q_FULL,
  541. ATH10K_TX_PAUSE_MAX,
  542. };
  543. struct ath10k_fw_file {
  544. const struct firmware *firmware;
  545. char fw_version[ETHTOOL_FWVERS_LEN];
  546. DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
  547. enum ath10k_fw_wmi_op_version wmi_op_version;
  548. enum ath10k_fw_htt_op_version htt_op_version;
  549. const void *firmware_data;
  550. size_t firmware_len;
  551. const void *otp_data;
  552. size_t otp_len;
  553. const void *codeswap_data;
  554. size_t codeswap_len;
  555. };
  556. struct ath10k_fw_components {
  557. const struct firmware *board;
  558. const void *board_data;
  559. size_t board_len;
  560. struct ath10k_fw_file fw_file;
  561. };
  562. struct ath10k {
  563. struct ath_common ath_common;
  564. struct ieee80211_hw *hw;
  565. struct ieee80211_ops *ops;
  566. struct device *dev;
  567. u8 mac_addr[ETH_ALEN];
  568. enum ath10k_hw_rev hw_rev;
  569. u16 dev_id;
  570. u32 chip_id;
  571. u32 target_version;
  572. u8 fw_version_major;
  573. u32 fw_version_minor;
  574. u16 fw_version_release;
  575. u16 fw_version_build;
  576. u32 fw_stats_req_mask;
  577. u32 phy_capability;
  578. u32 hw_min_tx_power;
  579. u32 hw_max_tx_power;
  580. u32 ht_cap_info;
  581. u32 vht_cap_info;
  582. u32 num_rf_chains;
  583. u32 max_spatial_stream;
  584. /* protected by conf_mutex */
  585. bool ani_enabled;
  586. bool p2p;
  587. struct {
  588. enum ath10k_bus bus;
  589. const struct ath10k_hif_ops *ops;
  590. } hif;
  591. struct completion target_suspend;
  592. const struct ath10k_hw_regs *regs;
  593. const struct ath10k_hw_values *hw_values;
  594. struct ath10k_bmi bmi;
  595. struct ath10k_wmi wmi;
  596. struct ath10k_htc htc;
  597. struct ath10k_htt htt;
  598. struct ath10k_hw_params {
  599. u32 id;
  600. u16 dev_id;
  601. const char *name;
  602. u32 patch_load_addr;
  603. int uart_pin;
  604. u32 otp_exe_param;
  605. /* Type of hw cycle counter wraparound logic, for more info
  606. * refer enum ath10k_hw_cc_wraparound_type.
  607. */
  608. enum ath10k_hw_cc_wraparound_type cc_wraparound_type;
  609. /* Some of chip expects fragment descriptor to be continuous
  610. * memory for any TX operation. Set continuous_frag_desc flag
  611. * for the hardware which have such requirement.
  612. */
  613. bool continuous_frag_desc;
  614. /* CCK hardware rate table mapping for the newer chipsets
  615. * like QCA99X0, QCA4019 got revised. The CCK h/w rate values
  616. * are in a proper order with respect to the rate/preamble
  617. */
  618. bool cck_rate_map_rev2;
  619. u32 channel_counters_freq_hz;
  620. /* Mgmt tx descriptors threshold for limiting probe response
  621. * frames.
  622. */
  623. u32 max_probe_resp_desc_thres;
  624. /* The padding bytes's location is different on various chips */
  625. enum ath10k_hw_4addr_pad hw_4addr_pad;
  626. u32 tx_chain_mask;
  627. u32 rx_chain_mask;
  628. u32 max_spatial_stream;
  629. u32 cal_data_len;
  630. struct ath10k_hw_params_fw {
  631. const char *dir;
  632. const char *board;
  633. size_t board_size;
  634. size_t board_ext_size;
  635. } fw;
  636. } hw_params;
  637. /* contains the firmware images used with ATH10K_FIRMWARE_MODE_NORMAL */
  638. struct ath10k_fw_components normal_mode_fw;
  639. /* READ-ONLY images of the running firmware, which can be either
  640. * normal or UTF. Do not modify, release etc!
  641. */
  642. const struct ath10k_fw_components *running_fw;
  643. const struct firmware *pre_cal_file;
  644. const struct firmware *cal_file;
  645. struct {
  646. struct ath10k_swap_code_seg_info *firmware_swap_code_seg_info;
  647. } swap;
  648. struct {
  649. u32 vendor;
  650. u32 device;
  651. u32 subsystem_vendor;
  652. u32 subsystem_device;
  653. bool bmi_ids_valid;
  654. u8 bmi_board_id;
  655. u8 bmi_chip_id;
  656. } id;
  657. int fw_api;
  658. int bd_api;
  659. enum ath10k_cal_mode cal_mode;
  660. struct {
  661. struct completion started;
  662. struct completion completed;
  663. struct completion on_channel;
  664. struct delayed_work timeout;
  665. enum ath10k_scan_state state;
  666. bool is_roc;
  667. int vdev_id;
  668. int roc_freq;
  669. bool roc_notify;
  670. } scan;
  671. struct {
  672. struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
  673. } mac;
  674. /* should never be NULL; needed for regular htt rx */
  675. struct ieee80211_channel *rx_channel;
  676. /* valid during scan; needed for mgmt rx during scan */
  677. struct ieee80211_channel *scan_channel;
  678. /* current operating channel definition */
  679. struct cfg80211_chan_def chandef;
  680. /* currently configured operating channel in firmware */
  681. struct ieee80211_channel *tgt_oper_chan;
  682. unsigned long long free_vdev_map;
  683. struct ath10k_vif *monitor_arvif;
  684. bool monitor;
  685. int monitor_vdev_id;
  686. bool monitor_started;
  687. unsigned int filter_flags;
  688. unsigned long dev_flags;
  689. bool dfs_block_radar_events;
  690. /* protected by conf_mutex */
  691. bool radar_enabled;
  692. int num_started_vdevs;
  693. /* Protected by conf-mutex */
  694. u8 cfg_tx_chainmask;
  695. u8 cfg_rx_chainmask;
  696. struct completion install_key_done;
  697. struct completion vdev_setup_done;
  698. struct workqueue_struct *workqueue;
  699. /* Auxiliary workqueue */
  700. struct workqueue_struct *workqueue_aux;
  701. /* prevents concurrent FW reconfiguration */
  702. struct mutex conf_mutex;
  703. /* protects shared structure data */
  704. spinlock_t data_lock;
  705. /* protects: ar->txqs, artxq->list */
  706. spinlock_t txqs_lock;
  707. struct list_head txqs;
  708. struct list_head arvifs;
  709. struct list_head peers;
  710. struct ath10k_peer *peer_map[ATH10K_MAX_NUM_PEER_IDS];
  711. wait_queue_head_t peer_mapping_wq;
  712. /* protected by conf_mutex */
  713. int num_peers;
  714. int num_stations;
  715. int max_num_peers;
  716. int max_num_stations;
  717. int max_num_vdevs;
  718. int max_num_tdls_vdevs;
  719. int num_active_peers;
  720. int num_tids;
  721. struct work_struct svc_rdy_work;
  722. struct sk_buff *svc_rdy_skb;
  723. struct work_struct offchan_tx_work;
  724. struct sk_buff_head offchan_tx_queue;
  725. struct completion offchan_tx_completed;
  726. struct sk_buff *offchan_tx_skb;
  727. struct work_struct wmi_mgmt_tx_work;
  728. struct sk_buff_head wmi_mgmt_tx_queue;
  729. enum ath10k_state state;
  730. struct work_struct register_work;
  731. struct work_struct restart_work;
  732. /* cycle count is reported twice for each visited channel during scan.
  733. * access protected by data_lock */
  734. u32 survey_last_rx_clear_count;
  735. u32 survey_last_cycle_count;
  736. struct survey_info survey[ATH10K_NUM_CHANS];
  737. /* Channel info events are expected to come in pairs without and with
  738. * COMPLETE flag set respectively for each channel visit during scan.
  739. *
  740. * However there are deviations from this rule. This flag is used to
  741. * avoid reporting garbage data.
  742. */
  743. bool ch_info_can_report_survey;
  744. struct completion bss_survey_done;
  745. struct dfs_pattern_detector *dfs_detector;
  746. unsigned long tx_paused; /* see ATH10K_TX_PAUSE_ */
  747. #ifdef CONFIG_ATH10K_DEBUGFS
  748. struct ath10k_debug debug;
  749. struct {
  750. /* relay(fs) channel for spectral scan */
  751. struct rchan *rfs_chan_spec_scan;
  752. /* spectral_mode and spec_config are protected by conf_mutex */
  753. enum ath10k_spectral_mode mode;
  754. struct ath10k_spec_scan config;
  755. } spectral;
  756. #endif
  757. struct {
  758. /* protected by conf_mutex */
  759. struct ath10k_fw_components utf_mode_fw;
  760. /* protected by data_lock */
  761. bool utf_monitor;
  762. } testmode;
  763. struct {
  764. /* protected by data_lock */
  765. u32 fw_crash_counter;
  766. u32 fw_warm_reset_counter;
  767. u32 fw_cold_reset_counter;
  768. } stats;
  769. struct ath10k_thermal thermal;
  770. struct ath10k_wow wow;
  771. /* must be last */
  772. u8 drv_priv[0] __aligned(sizeof(void *));
  773. };
  774. static inline bool ath10k_peer_stats_enabled(struct ath10k *ar)
  775. {
  776. if (test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags) &&
  777. test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map))
  778. return true;
  779. return false;
  780. }
  781. struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
  782. enum ath10k_bus bus,
  783. enum ath10k_hw_rev hw_rev,
  784. const struct ath10k_hif_ops *hif_ops);
  785. void ath10k_core_destroy(struct ath10k *ar);
  786. void ath10k_core_get_fw_features_str(struct ath10k *ar,
  787. char *buf,
  788. size_t max_len);
  789. int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name,
  790. struct ath10k_fw_file *fw_file);
  791. int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode,
  792. const struct ath10k_fw_components *fw_components);
  793. int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
  794. void ath10k_core_stop(struct ath10k *ar);
  795. int ath10k_core_register(struct ath10k *ar, u32 chip_id);
  796. void ath10k_core_unregister(struct ath10k *ar);
  797. #endif /* _CORE_H_ */