core.h 23 KB

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