core.h 8.7 KB

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