htc.h 13 KB

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