htc.h 11 KB

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