core.h 24 KB

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