core.h 8.9 KB

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