htc.h 14 KB

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