htc.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. enum htc_opmode opmode;
  112. u8 myaddr[ETH_ALEN];
  113. u8 bssid[ETH_ALEN];
  114. u32 flags;
  115. u32 flags_ext;
  116. u16 ps_sta;
  117. u16 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. u16 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. u32 capflags;
  171. struct ath9k_htc_rate rates;
  172. };
  173. struct ath9k_htc_target_stats {
  174. u32 tx_shortretry;
  175. u32 tx_longretry;
  176. u32 tx_xretries;
  177. u32 ht_txunaggr_xretry;
  178. u32 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. };
  228. struct ath_rx_stats {
  229. u32 skb_allocated;
  230. u32 skb_completed;
  231. u32 skb_dropped;
  232. };
  233. struct ath9k_debug {
  234. struct dentry *debugfs_phy;
  235. struct dentry *debugfs_tgt_stats;
  236. struct dentry *debugfs_xmit;
  237. struct dentry *debugfs_recv;
  238. struct ath_tx_stats tx_stats;
  239. struct ath_rx_stats rx_stats;
  240. u32 txrate;
  241. };
  242. #else
  243. #define TX_STAT_INC(c) do { } while (0)
  244. #define RX_STAT_INC(c) do { } while (0)
  245. #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
  246. #define ATH_LED_PIN_DEF 1
  247. #define ATH_LED_PIN_9287 8
  248. #define ATH_LED_PIN_9271 15
  249. #define ATH_LED_ON_DURATION_IDLE 350 /* in msecs */
  250. #define ATH_LED_OFF_DURATION_IDLE 250 /* in msecs */
  251. enum ath_led_type {
  252. ATH_LED_RADIO,
  253. ATH_LED_ASSOC,
  254. ATH_LED_TX,
  255. ATH_LED_RX
  256. };
  257. struct ath_led {
  258. struct ath9k_htc_priv *priv;
  259. struct led_classdev led_cdev;
  260. enum ath_led_type led_type;
  261. struct delayed_work brightness_work;
  262. char name[32];
  263. bool registered;
  264. int brightness;
  265. };
  266. #define OP_INVALID BIT(0)
  267. #define OP_SCANNING BIT(1)
  268. #define OP_FULL_RESET BIT(2)
  269. #define OP_LED_ASSOCIATED BIT(3)
  270. #define OP_LED_ON BIT(4)
  271. #define OP_PREAMBLE_SHORT BIT(5)
  272. #define OP_PROTECT_ENABLE BIT(6)
  273. #define OP_TXAGGR BIT(7)
  274. #define OP_ASSOCIATED BIT(8)
  275. #define OP_ENABLE_BEACON BIT(9)
  276. #define OP_LED_DEINIT BIT(10)
  277. struct ath9k_htc_priv {
  278. struct device *dev;
  279. struct ieee80211_hw *hw;
  280. struct ath_hw *ah;
  281. struct htc_target *htc;
  282. struct wmi *wmi;
  283. enum htc_endpoint_id wmi_cmd_ep;
  284. enum htc_endpoint_id beacon_ep;
  285. enum htc_endpoint_id cab_ep;
  286. enum htc_endpoint_id uapsd_ep;
  287. enum htc_endpoint_id mgmt_ep;
  288. enum htc_endpoint_id data_be_ep;
  289. enum htc_endpoint_id data_bk_ep;
  290. enum htc_endpoint_id data_vi_ep;
  291. enum htc_endpoint_id data_vo_ep;
  292. u16 op_flags;
  293. u16 curtxpow;
  294. u16 txpowlimit;
  295. u16 nvifs;
  296. u16 nstations;
  297. u16 seq_no;
  298. u32 bmiss_cnt;
  299. struct sk_buff *beacon;
  300. spinlock_t beacon_lock;
  301. bool tx_queues_stop;
  302. spinlock_t tx_lock;
  303. struct ieee80211_vif *vif;
  304. unsigned int rxfilter;
  305. struct tasklet_struct wmi_tasklet;
  306. struct tasklet_struct rx_tasklet;
  307. struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
  308. struct ath9k_htc_rx rx;
  309. struct tasklet_struct tx_tasklet;
  310. struct sk_buff_head tx_queue;
  311. struct ath9k_htc_aggr_work aggr_work;
  312. struct delayed_work ath9k_aggr_work;
  313. struct delayed_work ath9k_ani_work;
  314. struct ath_led radio_led;
  315. struct ath_led assoc_led;
  316. struct ath_led tx_led;
  317. struct ath_led rx_led;
  318. struct delayed_work ath9k_led_blink_work;
  319. int led_on_duration;
  320. int led_off_duration;
  321. int led_on_cnt;
  322. int led_off_cnt;
  323. int hwq_map[ATH9K_WME_AC_VO+1];
  324. #ifdef CONFIG_ATH9K_HTC_DEBUGFS
  325. struct ath9k_debug debug;
  326. #endif
  327. struct ath9k_htc_target_rate tgt_rate;
  328. struct mutex mutex;
  329. };
  330. static inline void ath_read_cachesize(struct ath_common *common, int *csz)
  331. {
  332. common->bus_ops->read_cachesize(common, csz);
  333. }
  334. void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
  335. struct ieee80211_vif *vif,
  336. struct ieee80211_bss_conf *bss_conf);
  337. void ath9k_htc_swba(struct ath9k_htc_priv *priv, u8 beacon_pending);
  338. void ath9k_htc_beacon_update(struct ath9k_htc_priv *priv,
  339. struct ieee80211_vif *vif);
  340. void ath9k_htc_rxep(void *priv, struct sk_buff *skb,
  341. enum htc_endpoint_id ep_id);
  342. void ath9k_htc_txep(void *priv, struct sk_buff *skb, enum htc_endpoint_id ep_id,
  343. bool txok);
  344. void ath9k_htc_station_work(struct work_struct *work);
  345. void ath9k_htc_aggr_work(struct work_struct *work);
  346. void ath9k_ani_work(struct work_struct *work);;
  347. int ath9k_tx_init(struct ath9k_htc_priv *priv);
  348. void ath9k_tx_tasklet(unsigned long data);
  349. int ath9k_htc_tx_start(struct ath9k_htc_priv *priv, struct sk_buff *skb);
  350. void ath9k_tx_cleanup(struct ath9k_htc_priv *priv);
  351. bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv,
  352. enum ath9k_tx_queue_subtype qtype);
  353. int get_hw_qnum(u16 queue, int *hwq_map);
  354. int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
  355. struct ath9k_tx_queue_info *qinfo);
  356. int ath9k_rx_init(struct ath9k_htc_priv *priv);
  357. void ath9k_rx_cleanup(struct ath9k_htc_priv *priv);
  358. void ath9k_host_rx_init(struct ath9k_htc_priv *priv);
  359. void ath9k_rx_tasklet(unsigned long data);
  360. u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv);
  361. void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv);
  362. void ath9k_init_leds(struct ath9k_htc_priv *priv);
  363. void ath9k_deinit_leds(struct ath9k_htc_priv *priv);
  364. int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
  365. u16 devid);
  366. void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug);
  367. #ifdef CONFIG_PM
  368. int ath9k_htc_resume(struct htc_target *htc_handle);
  369. #endif
  370. #ifdef CONFIG_ATH9K_HTC_DEBUGFS
  371. int ath9k_htc_debug_create_root(void);
  372. void ath9k_htc_debug_remove_root(void);
  373. int ath9k_htc_init_debug(struct ath_hw *ah);
  374. void ath9k_htc_exit_debug(struct ath_hw *ah);
  375. #else
  376. static inline int ath9k_htc_debug_create_root(void) { return 0; };
  377. static inline void ath9k_htc_debug_remove_root(void) {};
  378. static inline int ath9k_htc_init_debug(struct ath_hw *ah) { return 0; };
  379. static inline void ath9k_htc_exit_debug(struct ath_hw *ah) {};
  380. #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
  381. #endif /* HTC_H */