core.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 "htt.h"
  24. #include "htc.h"
  25. #include "hw.h"
  26. #include "targaddrs.h"
  27. #include "wmi.h"
  28. #include "../ath.h"
  29. #include "../regd.h"
  30. #include "../dfs_pattern_detector.h"
  31. #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
  32. #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
  33. #define WO(_f) ((_f##_OFFSET) >> 2)
  34. #define ATH10K_SCAN_ID 0
  35. #define WMI_READY_TIMEOUT (5 * HZ)
  36. #define ATH10K_FLUSH_TIMEOUT_HZ (5*HZ)
  37. #define ATH10K_NUM_CHANS 38
  38. /* Antenna noise floor */
  39. #define ATH10K_DEFAULT_NOISE_FLOOR -95
  40. #define ATH10K_MAX_NUM_MGMT_PENDING 128
  41. struct ath10k;
  42. struct ath10k_skb_cb {
  43. dma_addr_t paddr;
  44. bool is_mapped;
  45. bool is_aborted;
  46. u8 vdev_id;
  47. struct {
  48. u8 tid;
  49. bool is_offchan;
  50. u8 frag_len;
  51. u8 pad_len;
  52. } __packed htt;
  53. } __packed;
  54. static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
  55. {
  56. BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
  57. IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
  58. return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
  59. }
  60. static inline int ath10k_skb_map(struct device *dev, struct sk_buff *skb)
  61. {
  62. if (ATH10K_SKB_CB(skb)->is_mapped)
  63. return -EINVAL;
  64. ATH10K_SKB_CB(skb)->paddr = dma_map_single(dev, skb->data, skb->len,
  65. DMA_TO_DEVICE);
  66. if (unlikely(dma_mapping_error(dev, ATH10K_SKB_CB(skb)->paddr)))
  67. return -EIO;
  68. ATH10K_SKB_CB(skb)->is_mapped = true;
  69. return 0;
  70. }
  71. static inline int ath10k_skb_unmap(struct device *dev, struct sk_buff *skb)
  72. {
  73. if (!ATH10K_SKB_CB(skb)->is_mapped)
  74. return -EINVAL;
  75. dma_unmap_single(dev, ATH10K_SKB_CB(skb)->paddr, skb->len,
  76. DMA_TO_DEVICE);
  77. ATH10K_SKB_CB(skb)->is_mapped = false;
  78. return 0;
  79. }
  80. static inline u32 host_interest_item_address(u32 item_offset)
  81. {
  82. return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
  83. }
  84. struct ath10k_bmi {
  85. bool done_sent;
  86. };
  87. #define ATH10K_MAX_MEM_REQS 16
  88. struct ath10k_mem_chunk {
  89. void *vaddr;
  90. dma_addr_t paddr;
  91. u32 len;
  92. u32 req_id;
  93. };
  94. struct ath10k_wmi {
  95. enum ath10k_htc_ep_id eid;
  96. struct completion service_ready;
  97. struct completion unified_ready;
  98. wait_queue_head_t tx_credits_wq;
  99. struct wmi_cmd_map *cmd;
  100. struct wmi_vdev_param_map *vdev_param;
  101. struct wmi_pdev_param_map *pdev_param;
  102. u32 num_mem_chunks;
  103. struct ath10k_mem_chunk mem_chunks[ATH10K_MAX_MEM_REQS];
  104. };
  105. struct ath10k_peer_stat {
  106. u8 peer_macaddr[ETH_ALEN];
  107. u32 peer_rssi;
  108. u32 peer_tx_rate;
  109. };
  110. struct ath10k_target_stats {
  111. /* PDEV stats */
  112. s32 ch_noise_floor;
  113. u32 tx_frame_count;
  114. u32 rx_frame_count;
  115. u32 rx_clear_count;
  116. u32 cycle_count;
  117. u32 phy_err_count;
  118. u32 chan_tx_power;
  119. /* PDEV TX stats */
  120. s32 comp_queued;
  121. s32 comp_delivered;
  122. s32 msdu_enqued;
  123. s32 mpdu_enqued;
  124. s32 wmm_drop;
  125. s32 local_enqued;
  126. s32 local_freed;
  127. s32 hw_queued;
  128. s32 hw_reaped;
  129. s32 underrun;
  130. s32 tx_abort;
  131. s32 mpdus_requed;
  132. u32 tx_ko;
  133. u32 data_rc;
  134. u32 self_triggers;
  135. u32 sw_retry_failure;
  136. u32 illgl_rate_phy_err;
  137. u32 pdev_cont_xretry;
  138. u32 pdev_tx_timeout;
  139. u32 pdev_resets;
  140. u32 phy_underrun;
  141. u32 txop_ovf;
  142. /* PDEV RX stats */
  143. s32 mid_ppdu_route_change;
  144. s32 status_rcvd;
  145. s32 r0_frags;
  146. s32 r1_frags;
  147. s32 r2_frags;
  148. s32 r3_frags;
  149. s32 htt_msdus;
  150. s32 htt_mpdus;
  151. s32 loc_msdus;
  152. s32 loc_mpdus;
  153. s32 oversize_amsdu;
  154. s32 phy_errs;
  155. s32 phy_err_drop;
  156. s32 mpdu_errs;
  157. /* VDEV STATS */
  158. /* PEER STATS */
  159. u8 peers;
  160. struct ath10k_peer_stat peer_stat[TARGET_NUM_PEERS];
  161. /* TODO: Beacon filter stats */
  162. };
  163. struct ath10k_dfs_stats {
  164. u32 phy_errors;
  165. u32 pulses_total;
  166. u32 pulses_detected;
  167. u32 pulses_discarded;
  168. u32 radar_detected;
  169. };
  170. #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
  171. struct ath10k_peer {
  172. struct list_head list;
  173. int vdev_id;
  174. u8 addr[ETH_ALEN];
  175. DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
  176. struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
  177. };
  178. #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5*HZ)
  179. struct ath10k_vif {
  180. struct list_head list;
  181. u32 vdev_id;
  182. enum wmi_vdev_type vdev_type;
  183. enum wmi_vdev_subtype vdev_subtype;
  184. u32 beacon_interval;
  185. u32 dtim_period;
  186. struct sk_buff *beacon;
  187. struct ath10k *ar;
  188. struct ieee80211_vif *vif;
  189. struct work_struct wep_key_work;
  190. struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
  191. u8 def_wep_key_idx;
  192. u8 def_wep_key_newidx;
  193. u16 tx_seq_no;
  194. union {
  195. struct {
  196. u8 bssid[ETH_ALEN];
  197. u32 uapsd;
  198. } sta;
  199. struct {
  200. /* 127 stations; wmi limit */
  201. u8 tim_bitmap[16];
  202. u8 tim_len;
  203. u32 ssid_len;
  204. u8 ssid[IEEE80211_MAX_SSID_LEN];
  205. bool hidden_ssid;
  206. /* P2P_IE with NoA attribute for P2P_GO case */
  207. u32 noa_len;
  208. u8 *noa_data;
  209. } ap;
  210. struct {
  211. u8 bssid[ETH_ALEN];
  212. } ibss;
  213. } u;
  214. };
  215. struct ath10k_vif_iter {
  216. u32 vdev_id;
  217. struct ath10k_vif *arvif;
  218. };
  219. struct ath10k_debug {
  220. struct dentry *debugfs_phy;
  221. struct ath10k_target_stats target_stats;
  222. u32 wmi_service_bitmap[WMI_SERVICE_BM_SIZE];
  223. struct completion event_stats_compl;
  224. unsigned long htt_stats_mask;
  225. struct delayed_work htt_stats_dwork;
  226. struct ath10k_dfs_stats dfs_stats;
  227. struct ath_dfs_pool_stats dfs_pool_stats;
  228. };
  229. enum ath10k_state {
  230. ATH10K_STATE_OFF = 0,
  231. ATH10K_STATE_ON,
  232. /* When doing firmware recovery the device is first powered down.
  233. * mac80211 is supposed to call in to start() hook later on. It is
  234. * however possible that driver unloading and firmware crash overlap.
  235. * mac80211 can wait on conf_mutex in stop() while the device is
  236. * stopped in ath10k_core_restart() work holding conf_mutex. The state
  237. * RESTARTED means that the device is up and mac80211 has started hw
  238. * reconfiguration. Once mac80211 is done with the reconfiguration we
  239. * set the state to STATE_ON in restart_complete(). */
  240. ATH10K_STATE_RESTARTING,
  241. ATH10K_STATE_RESTARTED,
  242. /* The device has crashed while restarting hw. This state is like ON
  243. * but commands are blocked in HTC and -ECOMM response is given. This
  244. * prevents completion timeouts and makes the driver more responsive to
  245. * userspace commands. This is also prevents recursive recovery. */
  246. ATH10K_STATE_WEDGED,
  247. };
  248. enum ath10k_fw_features {
  249. /* wmi_mgmt_rx_hdr contains extra RSSI information */
  250. ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
  251. /* firmware from 10X branch */
  252. ATH10K_FW_FEATURE_WMI_10X = 1,
  253. /* firmware support tx frame management over WMI, otherwise it's HTT */
  254. ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
  255. /* keep last */
  256. ATH10K_FW_FEATURE_COUNT,
  257. };
  258. enum ath10k_dev_flags {
  259. /* Indicates that ath10k device is during CAC phase of DFS */
  260. ATH10K_CAC_RUNNING,
  261. ATH10K_FLAG_FIRST_BOOT_DONE,
  262. };
  263. struct ath10k {
  264. struct ath_common ath_common;
  265. struct ieee80211_hw *hw;
  266. struct device *dev;
  267. u8 mac_addr[ETH_ALEN];
  268. u32 chip_id;
  269. u32 target_version;
  270. u8 fw_version_major;
  271. u32 fw_version_minor;
  272. u16 fw_version_release;
  273. u16 fw_version_build;
  274. u32 phy_capability;
  275. u32 hw_min_tx_power;
  276. u32 hw_max_tx_power;
  277. u32 ht_cap_info;
  278. u32 vht_cap_info;
  279. u32 num_rf_chains;
  280. DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
  281. struct targetdef *targetdef;
  282. struct hostdef *hostdef;
  283. bool p2p;
  284. struct {
  285. void *priv;
  286. const struct ath10k_hif_ops *ops;
  287. } hif;
  288. wait_queue_head_t event_queue;
  289. bool is_target_paused;
  290. struct ath10k_bmi bmi;
  291. struct ath10k_wmi wmi;
  292. struct ath10k_htc htc;
  293. struct ath10k_htt htt;
  294. struct ath10k_hw_params {
  295. u32 id;
  296. const char *name;
  297. u32 patch_load_addr;
  298. struct ath10k_hw_params_fw {
  299. const char *dir;
  300. const char *fw;
  301. const char *otp;
  302. const char *board;
  303. } fw;
  304. } hw_params;
  305. const struct firmware *board;
  306. const void *board_data;
  307. size_t board_len;
  308. const struct firmware *otp;
  309. const void *otp_data;
  310. size_t otp_len;
  311. const struct firmware *firmware;
  312. const void *firmware_data;
  313. size_t firmware_len;
  314. int fw_api;
  315. struct {
  316. struct completion started;
  317. struct completion completed;
  318. struct completion on_channel;
  319. struct timer_list timeout;
  320. bool is_roc;
  321. bool in_progress;
  322. bool aborting;
  323. int vdev_id;
  324. int roc_freq;
  325. } scan;
  326. struct {
  327. struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
  328. } mac;
  329. /* should never be NULL; needed for regular htt rx */
  330. struct ieee80211_channel *rx_channel;
  331. /* valid during scan; needed for mgmt rx during scan */
  332. struct ieee80211_channel *scan_channel;
  333. int free_vdev_map;
  334. int monitor_vdev_id;
  335. bool monitor_enabled;
  336. bool monitor_present;
  337. unsigned int filter_flags;
  338. unsigned long dev_flags;
  339. u32 dfs_block_radar_events;
  340. struct wmi_pdev_set_wmm_params_arg wmm_params;
  341. struct completion install_key_done;
  342. struct completion vdev_setup_done;
  343. struct workqueue_struct *workqueue;
  344. /* prevents concurrent FW reconfiguration */
  345. struct mutex conf_mutex;
  346. /* protects shared structure data */
  347. spinlock_t data_lock;
  348. struct list_head arvifs;
  349. struct list_head peers;
  350. wait_queue_head_t peer_mapping_wq;
  351. struct work_struct offchan_tx_work;
  352. struct sk_buff_head offchan_tx_queue;
  353. struct completion offchan_tx_completed;
  354. struct sk_buff *offchan_tx_skb;
  355. struct work_struct wmi_mgmt_tx_work;
  356. struct sk_buff_head wmi_mgmt_tx_queue;
  357. enum ath10k_state state;
  358. struct work_struct restart_work;
  359. /* cycle count is reported twice for each visited channel during scan.
  360. * access protected by data_lock */
  361. u32 survey_last_rx_clear_count;
  362. u32 survey_last_cycle_count;
  363. struct survey_info survey[ATH10K_NUM_CHANS];
  364. struct dfs_pattern_detector *dfs_detector;
  365. #ifdef CONFIG_ATH10K_DEBUGFS
  366. struct ath10k_debug debug;
  367. #endif
  368. };
  369. struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
  370. const struct ath10k_hif_ops *hif_ops);
  371. void ath10k_core_destroy(struct ath10k *ar);
  372. int ath10k_core_start(struct ath10k *ar);
  373. void ath10k_core_stop(struct ath10k *ar);
  374. int ath10k_core_register(struct ath10k *ar, u32 chip_id);
  375. void ath10k_core_unregister(struct ath10k *ar);
  376. #endif /* _CORE_H_ */