ar9170.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Atheros AR9170 driver
  3. *
  4. * Driver specific definitions
  5. *
  6. * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; see the file COPYING. If not, see
  20. * http://www.gnu.org/licenses/.
  21. *
  22. * This file incorporates work covered by the following copyright and
  23. * permission notice:
  24. * Copyright (c) 2007-2008 Atheros Communications, Inc.
  25. *
  26. * Permission to use, copy, modify, and/or distribute this software for any
  27. * purpose with or without fee is hereby granted, provided that the above
  28. * copyright notice and this permission notice appear in all copies.
  29. *
  30. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  31. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  32. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  33. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  34. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  35. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  36. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  37. */
  38. #ifndef __AR9170_H
  39. #define __AR9170_H
  40. #include <linux/completion.h>
  41. #include <linux/spinlock.h>
  42. #include <net/cfg80211.h>
  43. #include <net/mac80211.h>
  44. #ifdef CONFIG_AR9170_LEDS
  45. #include <linux/leds.h>
  46. #endif /* CONFIG_AR9170_LEDS */
  47. #include "eeprom.h"
  48. #include "hw.h"
  49. #include "../regd.h"
  50. #define PAYLOAD_MAX (AR9170_MAX_CMD_LEN/4 - 1)
  51. enum ar9170_bw {
  52. AR9170_BW_20,
  53. AR9170_BW_40_BELOW,
  54. AR9170_BW_40_ABOVE,
  55. __AR9170_NUM_BW,
  56. };
  57. static inline enum ar9170_bw nl80211_to_ar9170(enum nl80211_channel_type type)
  58. {
  59. switch (type) {
  60. case NL80211_CHAN_NO_HT:
  61. case NL80211_CHAN_HT20:
  62. return AR9170_BW_20;
  63. case NL80211_CHAN_HT40MINUS:
  64. return AR9170_BW_40_BELOW;
  65. case NL80211_CHAN_HT40PLUS:
  66. return AR9170_BW_40_ABOVE;
  67. default:
  68. BUG();
  69. }
  70. }
  71. enum ar9170_rf_init_mode {
  72. AR9170_RFI_NONE,
  73. AR9170_RFI_WARM,
  74. AR9170_RFI_COLD,
  75. };
  76. #define AR9170_MAX_RX_BUFFER_SIZE 8192
  77. #ifdef CONFIG_AR9170_LEDS
  78. struct ar9170;
  79. struct ar9170_led {
  80. struct ar9170 *ar;
  81. struct led_classdev l;
  82. char name[32];
  83. unsigned int toggled;
  84. bool last_state;
  85. bool registered;
  86. };
  87. #endif /* CONFIG_AR9170_LEDS */
  88. enum ar9170_device_state {
  89. AR9170_UNKNOWN_STATE,
  90. AR9170_STOPPED,
  91. AR9170_IDLE,
  92. AR9170_STARTED,
  93. };
  94. struct ar9170_rxstream_mpdu_merge {
  95. struct ar9170_rx_head plcp;
  96. bool has_plcp;
  97. };
  98. #define AR9170_NUM_TID 16
  99. #define WME_BA_BMP_SIZE 64
  100. #define AR9170_NUM_MAX_AGG_LEN (2 * WME_BA_BMP_SIZE)
  101. #define WME_AC_BE 2
  102. #define WME_AC_BK 3
  103. #define WME_AC_VI 1
  104. #define WME_AC_VO 0
  105. #define TID_TO_WME_AC(_tid) \
  106. ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \
  107. (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK : \
  108. (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \
  109. WME_AC_VO)
  110. #define BAW_WITHIN(_start, _bawsz, _seqno) \
  111. ((((_seqno) - (_start)) & 0xfff) < (_bawsz))
  112. enum ar9170_tid_state {
  113. AR9170_TID_STATE_INVALID,
  114. AR9170_TID_STATE_SHUTDOWN,
  115. AR9170_TID_STATE_PROGRESS,
  116. AR9170_TID_STATE_COMPLETE,
  117. };
  118. struct ar9170_sta_tid {
  119. struct list_head list;
  120. struct sk_buff_head queue;
  121. u8 addr[ETH_ALEN];
  122. u16 ssn;
  123. u16 tid;
  124. enum ar9170_tid_state state;
  125. bool active;
  126. };
  127. struct ar9170_tx_queue_stats {
  128. unsigned int len;
  129. unsigned int limit;
  130. unsigned int count;
  131. };
  132. #define AR9170_QUEUE_TIMEOUT 64
  133. #define AR9170_TX_TIMEOUT 8
  134. #define AR9170_BA_TIMEOUT 4
  135. #define AR9170_JANITOR_DELAY 128
  136. #define AR9170_TX_INVALID_RATE 0xffffffff
  137. #define AR9170_NUM_TX_STATUS 128
  138. #define AR9170_NUM_TX_AGG_MAX 30
  139. #define AR9170_NUM_TX_LIMIT_HARD AR9170_TXQ_DEPTH
  140. #define AR9170_NUM_TX_LIMIT_SOFT (AR9170_TXQ_DEPTH - 10)
  141. struct ar9170 {
  142. struct ieee80211_hw *hw;
  143. struct ath_common common;
  144. struct mutex mutex;
  145. enum ar9170_device_state state;
  146. bool registered;
  147. unsigned long bad_hw_nagger;
  148. int (*open)(struct ar9170 *);
  149. void (*stop)(struct ar9170 *);
  150. int (*tx)(struct ar9170 *, struct sk_buff *);
  151. int (*exec_cmd)(struct ar9170 *, enum ar9170_cmd, u32 ,
  152. void *, u32 , void *);
  153. void (*callback_cmd)(struct ar9170 *, u32 , void *);
  154. int (*flush)(struct ar9170 *);
  155. /* interface mode settings */
  156. struct ieee80211_vif *vif;
  157. /* beaconing */
  158. struct sk_buff *beacon;
  159. struct work_struct beacon_work;
  160. bool enable_beacon;
  161. /* cryptographic engine */
  162. u64 usedkeys;
  163. bool rx_software_decryption;
  164. bool disable_offload;
  165. /* filter settings */
  166. u64 cur_mc_hash;
  167. u32 cur_filter;
  168. unsigned int filter_state;
  169. bool sniffer_enabled;
  170. /* PHY */
  171. struct ieee80211_channel *channel;
  172. int noise[4];
  173. /* power calibration data */
  174. u8 power_5G_leg[4];
  175. u8 power_2G_cck[4];
  176. u8 power_2G_ofdm[4];
  177. u8 power_5G_ht20[8];
  178. u8 power_5G_ht40[8];
  179. u8 power_2G_ht20[8];
  180. u8 power_2G_ht40[8];
  181. u8 phy_heavy_clip;
  182. #ifdef CONFIG_AR9170_LEDS
  183. struct delayed_work led_work;
  184. struct ar9170_led leds[AR9170_NUM_LEDS];
  185. #endif /* CONFIG_AR9170_LEDS */
  186. /* qos queue settings */
  187. spinlock_t tx_stats_lock;
  188. struct ar9170_tx_queue_stats tx_stats[5];
  189. struct ieee80211_tx_queue_params edcf[5];
  190. spinlock_t cmdlock;
  191. __le32 cmdbuf[PAYLOAD_MAX + 1];
  192. /* MAC statistics */
  193. struct ieee80211_low_level_stats stats;
  194. /* EEPROM */
  195. struct ar9170_eeprom eeprom;
  196. /* tx queues - as seen by hw - */
  197. struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
  198. struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
  199. struct delayed_work tx_janitor;
  200. /* tx ampdu */
  201. struct sk_buff_head tx_status_ampdu;
  202. spinlock_t tx_ampdu_list_lock;
  203. struct list_head tx_ampdu_list;
  204. atomic_t tx_ampdu_pending;
  205. /* rxstream mpdu merge */
  206. struct ar9170_rxstream_mpdu_merge rx_mpdu;
  207. struct sk_buff *rx_failover;
  208. int rx_failover_missing;
  209. /* (cached) HW A-MPDU settings */
  210. u8 global_ampdu_density;
  211. u8 global_ampdu_factor;
  212. };
  213. struct ar9170_sta_info {
  214. struct ar9170_sta_tid agg[AR9170_NUM_TID];
  215. unsigned int ampdu_max_len;
  216. };
  217. struct ar9170_tx_info {
  218. unsigned long timeout;
  219. };
  220. #define IS_STARTED(a) (((struct ar9170 *)a)->state >= AR9170_STARTED)
  221. #define IS_ACCEPTING_CMD(a) (((struct ar9170 *)a)->state >= AR9170_IDLE)
  222. /* exported interface */
  223. void *ar9170_alloc(size_t priv_size);
  224. int ar9170_register(struct ar9170 *ar, struct device *pdev);
  225. void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb);
  226. void ar9170_unregister(struct ar9170 *ar);
  227. void ar9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
  228. void ar9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
  229. int ar9170_nag_limiter(struct ar9170 *ar);
  230. /* MAC */
  231. int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  232. int ar9170_init_mac(struct ar9170 *ar);
  233. int ar9170_set_qos(struct ar9170 *ar);
  234. int ar9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
  235. int ar9170_update_frame_filter(struct ar9170 *ar, const u32 filter);
  236. int ar9170_set_operating_mode(struct ar9170 *ar);
  237. int ar9170_set_beacon_timers(struct ar9170 *ar);
  238. int ar9170_set_dyn_sifs_ack(struct ar9170 *ar);
  239. int ar9170_set_slot_time(struct ar9170 *ar);
  240. int ar9170_set_basic_rates(struct ar9170 *ar);
  241. int ar9170_set_hwretry_limit(struct ar9170 *ar, u32 max_retry);
  242. int ar9170_update_beacon(struct ar9170 *ar);
  243. void ar9170_new_beacon(struct work_struct *work);
  244. int ar9170_upload_key(struct ar9170 *ar, u8 id, const u8 *mac, u8 ktype,
  245. u8 keyidx, u8 *keydata, int keylen);
  246. int ar9170_disable_key(struct ar9170 *ar, u8 id);
  247. /* LEDs */
  248. #ifdef CONFIG_AR9170_LEDS
  249. int ar9170_register_leds(struct ar9170 *ar);
  250. void ar9170_unregister_leds(struct ar9170 *ar);
  251. #endif /* CONFIG_AR9170_LEDS */
  252. int ar9170_init_leds(struct ar9170 *ar);
  253. int ar9170_set_leds_state(struct ar9170 *ar, u32 led_state);
  254. /* PHY / RF */
  255. int ar9170_init_phy(struct ar9170 *ar, enum ieee80211_band band);
  256. int ar9170_init_rf(struct ar9170 *ar);
  257. int ar9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
  258. enum ar9170_rf_init_mode rfi, enum ar9170_bw bw);
  259. #endif /* __AR9170_H */