core.h 24 KB

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