htc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. * Copyright (c) 2010 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef HTC_H
  17. #define HTC_H
  18. #include <linux/module.h>
  19. #include <linux/usb.h>
  20. #include <linux/firmware.h>
  21. #include <linux/skbuff.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/leds.h>
  24. #include <net/mac80211.h>
  25. #include "common.h"
  26. #include "htc_hst.h"
  27. #include "hif_usb.h"
  28. #include "wmi.h"
  29. #define ATH_STA_SHORT_CALINTERVAL 1000 /* 1 second */
  30. #define ATH_ANI_POLLINTERVAL 100 /* 100 ms */
  31. #define ATH_LONG_CALINTERVAL 30000 /* 30 seconds */
  32. #define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes */
  33. #define ATH_DEFAULT_BMISS_LIMIT 10
  34. #define IEEE80211_MS_TO_TU(x) (((x) * 1000) / 1024)
  35. #define TSF_TO_TU(_h, _l) \
  36. ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
  37. extern struct ieee80211_ops ath9k_htc_ops;
  38. extern int htc_modparam_nohwcrypt;
  39. enum htc_phymode {
  40. HTC_MODE_AUTO = 0,
  41. HTC_MODE_11A = 1,
  42. HTC_MODE_11B = 2,
  43. HTC_MODE_11G = 3,
  44. HTC_MODE_FH = 4,
  45. HTC_MODE_TURBO_A = 5,
  46. HTC_MODE_TURBO_G = 6,
  47. HTC_MODE_11NA = 7,
  48. HTC_MODE_11NG = 8
  49. };
  50. enum htc_opmode {
  51. HTC_M_STA = 1,
  52. HTC_M_IBSS = 0,
  53. HTC_M_AHDEMO = 3,
  54. HTC_M_HOSTAP = 6,
  55. HTC_M_MONITOR = 8,
  56. HTC_M_WDS = 2
  57. };
  58. #define ATH9K_HTC_HDRSPACE sizeof(struct htc_frame_hdr)
  59. #define ATH9K_HTC_AMPDU 1
  60. #define ATH9K_HTC_NORMAL 2
  61. #define ATH9K_HTC_TX_CTSONLY 0x1
  62. #define ATH9K_HTC_TX_RTSCTS 0x2
  63. #define ATH9K_HTC_TX_USE_MIN_RATE 0x100
  64. struct tx_frame_hdr {
  65. u8 data_type;
  66. u8 node_idx;
  67. u8 vif_idx;
  68. u8 tidno;
  69. u32 flags; /* ATH9K_HTC_TX_* */
  70. u8 key_type;
  71. u8 keyix;
  72. u8 reserved[26];
  73. } __packed;
  74. struct tx_mgmt_hdr {
  75. u8 node_idx;
  76. u8 vif_idx;
  77. u8 tidno;
  78. u8 flags;
  79. u8 key_type;
  80. u8 keyix;
  81. u16 reserved;
  82. } __packed;
  83. struct tx_beacon_header {
  84. u8 len_changed;
  85. u8 vif_index;
  86. u16 rev;
  87. } __packed;
  88. struct ath9k_htc_target_hw {
  89. u32 flags;
  90. u32 flags_ext;
  91. u32 ampdu_limit;
  92. u8 ampdu_subframes;
  93. u8 tx_chainmask;
  94. u8 tx_chainmask_legacy;
  95. u8 rtscts_ratecode;
  96. u8 protmode;
  97. } __packed;
  98. struct ath9k_htc_cap_target {
  99. u32 flags;
  100. u32 flags_ext;
  101. u32 ampdu_limit;
  102. u8 ampdu_subframes;
  103. u8 tx_chainmask;
  104. u8 tx_chainmask_legacy;
  105. u8 rtscts_ratecode;
  106. u8 protmode;
  107. } __packed;
  108. struct ath9k_htc_target_vif {
  109. u8 index;
  110. u8 des_bssid[ETH_ALEN];
  111. __be32 opmode;
  112. u8 myaddr[ETH_ALEN];
  113. u8 bssid[ETH_ALEN];
  114. u32 flags;
  115. u32 flags_ext;
  116. u16 ps_sta;
  117. __be16 rtsthreshold;
  118. u8 ath_cap;
  119. u8 node;
  120. s8 mcast_rate;
  121. } __packed;
  122. #define ATH_HTC_STA_AUTH 0x0001
  123. #define ATH_HTC_STA_QOS 0x0002
  124. #define ATH_HTC_STA_ERP 0x0004
  125. #define ATH_HTC_STA_HT 0x0008
  126. /* FIXME: UAPSD variables */
  127. struct ath9k_htc_target_sta {
  128. u16 associd;
  129. u16 txpower;
  130. u32 ucastkey;
  131. u8 macaddr[ETH_ALEN];
  132. u8 bssid[ETH_ALEN];
  133. u8 sta_index;
  134. u8 vif_index;
  135. u8 vif_sta;
  136. __be16 flags; /* ATH_HTC_STA_* */
  137. u16 htcap;
  138. u8 valid;
  139. u16 capinfo;
  140. struct ath9k_htc_target_hw *hw;
  141. struct ath9k_htc_target_vif *vif;
  142. u16 txseqmgmt;
  143. u8 is_vif_sta;
  144. u16 maxampdu;
  145. u16 iv16;
  146. u32 iv32;
  147. } __packed;
  148. struct ath9k_htc_target_aggr {
  149. u8 sta_index;
  150. u8 tidno;
  151. u8 aggr_enable;
  152. u8 padding;
  153. } __packed;
  154. #define ATH_HTC_RATE_MAX 30
  155. #define WLAN_RC_DS_FLAG 0x01
  156. #define WLAN_RC_40_FLAG 0x02
  157. #define WLAN_RC_SGI_FLAG 0x04
  158. #define WLAN_RC_HT_FLAG 0x08
  159. struct ath9k_htc_rateset {
  160. u8 rs_nrates;
  161. u8 rs_rates[ATH_HTC_RATE_MAX];
  162. };
  163. struct ath9k_htc_rate {
  164. struct ath9k_htc_rateset legacy_rates;
  165. struct ath9k_htc_rateset ht_rates;
  166. } __packed;
  167. struct ath9k_htc_target_rate {
  168. u8 sta_index;
  169. u8 isnew;
  170. __be32 capflags;
  171. struct ath9k_htc_rate rates;
  172. };
  173. struct ath9k_htc_target_stats {
  174. __be32 tx_shortretry;
  175. __be32 tx_longretry;
  176. __be32 tx_xretries;
  177. __be32 ht_txunaggr_xretry;
  178. __be32 ht_tx_xretries;
  179. } __packed;
  180. struct ath9k_htc_vif {
  181. u8 index;
  182. };
  183. #define ATH9K_HTC_MAX_STA 8
  184. #define ATH9K_HTC_MAX_TID 8
  185. enum tid_aggr_state {
  186. AGGR_STOP = 0,
  187. AGGR_PROGRESS,
  188. AGGR_START,
  189. AGGR_OPERATIONAL
  190. };
  191. struct ath9k_htc_sta {
  192. u8 index;
  193. enum tid_aggr_state tid_state[ATH9K_HTC_MAX_TID];
  194. };
  195. struct ath9k_htc_aggr_work {
  196. u16 tid;
  197. u8 sta_addr[ETH_ALEN];
  198. struct ieee80211_hw *hw;
  199. struct ieee80211_vif *vif;
  200. enum ieee80211_ampdu_mlme_action action;
  201. struct mutex mutex;
  202. };
  203. #define ATH9K_HTC_RXBUF 256
  204. #define HTC_RX_FRAME_HEADER_SIZE 40
  205. struct ath9k_htc_rxbuf {
  206. bool in_process;
  207. struct sk_buff *skb;
  208. struct ath_htc_rx_status rxstatus;
  209. struct list_head list;
  210. };
  211. struct ath9k_htc_rx {
  212. int last_rssi; /* FIXME: per-STA */
  213. struct list_head rxbuf;
  214. spinlock_t rxbuflock;
  215. };
  216. struct ath9k_htc_tx_ctl {
  217. u8 type; /* ATH9K_HTC_* */
  218. };
  219. #ifdef CONFIG_ATH9K_HTC_DEBUGFS
  220. #define TX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.tx_stats.c++)
  221. #define RX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.rx_stats.c++)
  222. struct ath_tx_stats {
  223. u32 buf_queued;
  224. u32 buf_completed;
  225. u32 skb_queued;
  226. u32 skb_completed;
  227. u32 skb_dropped;
  228. };
  229. struct ath_rx_stats {
  230. u32 skb_allocated;
  231. u32 skb_completed;
  232. u32 skb_dropped;
  233. };
  234. struct ath9k_debug {
  235. struct dentry *debugfs_phy;
  236. struct dentry *debugfs_tgt_stats;
  237. struct dentry *debugfs_xmit;
  238. struct dentry *debugfs_recv;
  239. struct ath_tx_stats tx_stats;
  240. struct ath_rx_stats rx_stats;
  241. u32 txrate;
  242. };
  243. #else
  244. #define TX_STAT_INC(c) do { } while (0)
  245. #define RX_STAT_INC(c) do { } while (0)
  246. #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
  247. #define ATH_LED_PIN_DEF 1
  248. #define ATH_LED_PIN_9287 8
  249. #define ATH_LED_PIN_9271 15
  250. #define ATH_LED_ON_DURATION_IDLE 350 /* in msecs */
  251. #define ATH_LED_OFF_DURATION_IDLE 250 /* in msecs */
  252. enum ath_led_type {
  253. ATH_LED_RADIO,
  254. ATH_LED_ASSOC,
  255. ATH_LED_TX,
  256. ATH_LED_RX
  257. };
  258. struct ath_led {
  259. struct ath9k_htc_priv *priv;
  260. struct led_classdev led_cdev;
  261. enum ath_led_type led_type;
  262. struct delayed_work brightness_work;
  263. char name[32];
  264. bool registered;
  265. int brightness;
  266. };
  267. struct htc_beacon_config {
  268. u16 beacon_interval;
  269. u16 listen_interval;
  270. u16 dtim_period;
  271. u16 bmiss_timeout;
  272. u8 dtim_count;
  273. };
  274. #define OP_INVALID BIT(0)
  275. #define OP_SCANNING BIT(1)
  276. #define OP_FULL_RESET BIT(2)
  277. #define OP_LED_ASSOCIATED BIT(3)
  278. #define OP_LED_ON BIT(4)
  279. #define OP_PREAMBLE_SHORT BIT(5)
  280. #define OP_PROTECT_ENABLE BIT(6)
  281. #define OP_TXAGGR BIT(7)
  282. #define OP_ASSOCIATED BIT(8)
  283. #define OP_ENABLE_BEACON BIT(9)
  284. #define OP_LED_DEINIT BIT(10)
  285. #define OP_UNPLUGGED BIT(11)
  286. struct ath9k_htc_priv {
  287. struct device *dev;
  288. struct ieee80211_hw *hw;
  289. struct ath_hw *ah;
  290. struct htc_target *htc;
  291. struct wmi *wmi;
  292. enum htc_endpoint_id wmi_cmd_ep;
  293. enum htc_endpoint_id beacon_ep;
  294. enum htc_endpoint_id cab_ep;
  295. enum htc_endpoint_id uapsd_ep;
  296. enum htc_endpoint_id mgmt_ep;
  297. enum htc_endpoint_id data_be_ep;
  298. enum htc_endpoint_id data_bk_ep;
  299. enum htc_endpoint_id data_vi_ep;
  300. enum htc_endpoint_id data_vo_ep;
  301. u16 op_flags;
  302. u16 curtxpow;
  303. u16 txpowlimit;
  304. u16 nvifs;
  305. u16 nstations;
  306. u16 seq_no;
  307. u32 bmiss_cnt;
  308. struct sk_buff *beacon;
  309. spinlock_t beacon_lock;
  310. bool tx_queues_stop;
  311. spinlock_t tx_lock;
  312. struct ieee80211_vif *vif;
  313. struct htc_beacon_config cur_beacon_conf;
  314. unsigned int rxfilter;
  315. struct tasklet_struct wmi_tasklet;
  316. struct tasklet_struct rx_tasklet;
  317. struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
  318. struct ath9k_htc_rx rx;
  319. struct tasklet_struct tx_tasklet;
  320. struct sk_buff_head tx_queue;
  321. struct ath9k_htc_aggr_work aggr_work;
  322. struct delayed_work ath9k_aggr_work;
  323. struct delayed_work ath9k_ani_work;
  324. struct work_struct ps_work;
  325. struct mutex htc_pm_lock;
  326. unsigned long ps_usecount;
  327. bool ps_enabled;
  328. bool ps_idle;
  329. struct ath_led radio_led;
  330. struct ath_led assoc_led;
  331. struct ath_led tx_led;
  332. struct ath_led rx_led;
  333. struct delayed_work ath9k_led_blink_work;
  334. int led_on_duration;
  335. int led_off_duration;
  336. int led_on_cnt;
  337. int led_off_cnt;
  338. int hwq_map[ATH9K_WME_AC_VO+1];
  339. #ifdef CONFIG_ATH9K_HTC_DEBUGFS
  340. struct ath9k_debug debug;
  341. #endif
  342. struct ath9k_htc_target_rate tgt_rate;
  343. struct mutex mutex;
  344. };
  345. static inline void ath_read_cachesize(struct ath_common *common, int *csz)
  346. {
  347. common->bus_ops->read_cachesize(common, csz);
  348. }
  349. void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
  350. struct ieee80211_vif *vif);
  351. void ath9k_htc_swba(struct ath9k_htc_priv *priv, u8 beacon_pending);
  352. void ath9k_htc_beacon_update(struct ath9k_htc_priv *priv,
  353. struct ieee80211_vif *vif);
  354. void ath9k_htc_rxep(void *priv, struct sk_buff *skb,
  355. enum htc_endpoint_id ep_id);
  356. void ath9k_htc_txep(void *priv, struct sk_buff *skb, enum htc_endpoint_id ep_id,
  357. bool txok);
  358. void ath9k_htc_station_work(struct work_struct *work);
  359. void ath9k_htc_aggr_work(struct work_struct *work);
  360. void ath9k_ani_work(struct work_struct *work);;
  361. int ath9k_tx_init(struct ath9k_htc_priv *priv);
  362. void ath9k_tx_tasklet(unsigned long data);
  363. int ath9k_htc_tx_start(struct ath9k_htc_priv *priv, struct sk_buff *skb);
  364. void ath9k_tx_cleanup(struct ath9k_htc_priv *priv);
  365. bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv,
  366. enum ath9k_tx_queue_subtype qtype);
  367. int get_hw_qnum(u16 queue, int *hwq_map);
  368. int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
  369. struct ath9k_tx_queue_info *qinfo);
  370. int ath9k_rx_init(struct ath9k_htc_priv *priv);
  371. void ath9k_rx_cleanup(struct ath9k_htc_priv *priv);
  372. void ath9k_host_rx_init(struct ath9k_htc_priv *priv);
  373. void ath9k_rx_tasklet(unsigned long data);
  374. u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv);
  375. void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv);
  376. void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv);
  377. void ath9k_ps_work(struct work_struct *work);
  378. void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv);
  379. void ath9k_init_leds(struct ath9k_htc_priv *priv);
  380. void ath9k_deinit_leds(struct ath9k_htc_priv *priv);
  381. int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
  382. u16 devid);
  383. void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug);
  384. #ifdef CONFIG_PM
  385. int ath9k_htc_resume(struct htc_target *htc_handle);
  386. #endif
  387. #ifdef CONFIG_ATH9K_HTC_DEBUGFS
  388. int ath9k_htc_debug_create_root(void);
  389. void ath9k_htc_debug_remove_root(void);
  390. int ath9k_htc_init_debug(struct ath_hw *ah);
  391. void ath9k_htc_exit_debug(struct ath_hw *ah);
  392. #else
  393. static inline int ath9k_htc_debug_create_root(void) { return 0; };
  394. static inline void ath9k_htc_debug_remove_root(void) {};
  395. static inline int ath9k_htc_init_debug(struct ath_hw *ah) { return 0; };
  396. static inline void ath9k_htc_exit_debug(struct ath_hw *ah) {};
  397. #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
  398. #endif /* HTC_H */