ar9170.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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_MAX_BA_RETRY 5
  99. #define AR9170_NUM_TID 16
  100. #define WME_BA_BMP_SIZE 64
  101. #define AR9170_NUM_MAX_AGG_LEN (2 * WME_BA_BMP_SIZE)
  102. #define WME_AC_BE 2
  103. #define WME_AC_BK 3
  104. #define WME_AC_VI 1
  105. #define WME_AC_VO 0
  106. #define TID_TO_WME_AC(_tid) \
  107. ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \
  108. (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK : \
  109. (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \
  110. WME_AC_VO)
  111. #define BAW_WITHIN(_start, _bawsz, _seqno) \
  112. ((((_seqno) - (_start)) & 0xfff) < (_bawsz))
  113. enum ar9170_tid_state {
  114. AR9170_TID_STATE_INVALID,
  115. AR9170_TID_STATE_SHUTDOWN,
  116. AR9170_TID_STATE_PROGRESS,
  117. AR9170_TID_STATE_COMPLETE,
  118. };
  119. struct ar9170_sta_tid {
  120. struct list_head list;
  121. struct sk_buff_head queue;
  122. u8 addr[ETH_ALEN];
  123. u16 ssn;
  124. u16 tid;
  125. enum ar9170_tid_state state;
  126. bool active;
  127. u8 retry;
  128. };
  129. #define AR9170_QUEUE_TIMEOUT 64
  130. #define AR9170_TX_TIMEOUT 8
  131. #define AR9170_BA_TIMEOUT 4
  132. #define AR9170_JANITOR_DELAY 128
  133. #define AR9170_TX_INVALID_RATE 0xffffffff
  134. #define AR9170_NUM_TX_STATUS 128
  135. #define AR9170_NUM_TX_AGG_MAX 30
  136. struct ar9170 {
  137. struct ieee80211_hw *hw;
  138. struct ath_common common;
  139. struct mutex mutex;
  140. enum ar9170_device_state state;
  141. unsigned long bad_hw_nagger;
  142. int (*open)(struct ar9170 *);
  143. void (*stop)(struct ar9170 *);
  144. int (*tx)(struct ar9170 *, struct sk_buff *);
  145. int (*exec_cmd)(struct ar9170 *, enum ar9170_cmd, u32 ,
  146. void *, u32 , void *);
  147. void (*callback_cmd)(struct ar9170 *, u32 , void *);
  148. int (*flush)(struct ar9170 *);
  149. /* interface mode settings */
  150. struct ieee80211_vif *vif;
  151. /* beaconing */
  152. struct sk_buff *beacon;
  153. struct work_struct beacon_work;
  154. bool enable_beacon;
  155. /* cryptographic engine */
  156. u64 usedkeys;
  157. bool rx_software_decryption;
  158. bool disable_offload;
  159. /* filter settings */
  160. u64 cur_mc_hash;
  161. u32 cur_filter;
  162. unsigned int filter_state;
  163. bool sniffer_enabled;
  164. /* PHY */
  165. struct ieee80211_channel *channel;
  166. int noise[4];
  167. /* power calibration data */
  168. u8 power_5G_leg[4];
  169. u8 power_2G_cck[4];
  170. u8 power_2G_ofdm[4];
  171. u8 power_5G_ht20[8];
  172. u8 power_5G_ht40[8];
  173. u8 power_2G_ht20[8];
  174. u8 power_2G_ht40[8];
  175. u8 phy_heavy_clip;
  176. #ifdef CONFIG_AR9170_LEDS
  177. struct delayed_work led_work;
  178. struct ar9170_led leds[AR9170_NUM_LEDS];
  179. #endif /* CONFIG_AR9170_LEDS */
  180. /* qos queue settings */
  181. spinlock_t tx_stats_lock;
  182. struct ieee80211_tx_queue_stats tx_stats[5];
  183. struct ieee80211_tx_queue_params edcf[5];
  184. spinlock_t cmdlock;
  185. __le32 cmdbuf[PAYLOAD_MAX + 1];
  186. /* MAC statistics */
  187. struct ieee80211_low_level_stats stats;
  188. /* EEPROM */
  189. struct ar9170_eeprom eeprom;
  190. /* tx queues - as seen by hw - */
  191. struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
  192. struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
  193. struct delayed_work tx_janitor;
  194. /* tx ampdu */
  195. struct sk_buff_head tx_status_ampdu;
  196. spinlock_t tx_ampdu_list_lock;
  197. struct list_head tx_ampdu_list;
  198. atomic_t tx_ampdu_pending;
  199. /* rxstream mpdu merge */
  200. struct ar9170_rxstream_mpdu_merge rx_mpdu;
  201. struct sk_buff *rx_failover;
  202. int rx_failover_missing;
  203. /* (cached) HW A-MPDU settings */
  204. u8 global_ampdu_density;
  205. u8 global_ampdu_factor;
  206. };
  207. struct ar9170_sta_info {
  208. struct ar9170_sta_tid agg[AR9170_NUM_TID];
  209. unsigned int ampdu_max_len;
  210. };
  211. #define AR9170_TX_FLAG_WAIT_FOR_ACK BIT(0)
  212. #define AR9170_TX_FLAG_NO_ACK BIT(1)
  213. #define AR9170_TX_FLAG_BLOCK_ACK BIT(2)
  214. struct ar9170_tx_info {
  215. unsigned long timeout;
  216. unsigned int flags;
  217. };
  218. #define IS_STARTED(a) (((struct ar9170 *)a)->state >= AR9170_STARTED)
  219. #define IS_ACCEPTING_CMD(a) (((struct ar9170 *)a)->state >= AR9170_IDLE)
  220. /* exported interface */
  221. void *ar9170_alloc(size_t priv_size);
  222. int ar9170_register(struct ar9170 *ar, struct device *pdev);
  223. void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb);
  224. void ar9170_unregister(struct ar9170 *ar);
  225. void ar9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
  226. void ar9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
  227. int ar9170_nag_limiter(struct ar9170 *ar);
  228. /* MAC */
  229. int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  230. int ar9170_init_mac(struct ar9170 *ar);
  231. int ar9170_set_qos(struct ar9170 *ar);
  232. int ar9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
  233. int ar9170_update_frame_filter(struct ar9170 *ar, const u32 filter);
  234. int ar9170_set_operating_mode(struct ar9170 *ar);
  235. int ar9170_set_beacon_timers(struct ar9170 *ar);
  236. int ar9170_set_dyn_sifs_ack(struct ar9170 *ar);
  237. int ar9170_set_slot_time(struct ar9170 *ar);
  238. int ar9170_set_basic_rates(struct ar9170 *ar);
  239. int ar9170_set_hwretry_limit(struct ar9170 *ar, u32 max_retry);
  240. int ar9170_update_beacon(struct ar9170 *ar);
  241. void ar9170_new_beacon(struct work_struct *work);
  242. int ar9170_upload_key(struct ar9170 *ar, u8 id, const u8 *mac, u8 ktype,
  243. u8 keyidx, u8 *keydata, int keylen);
  244. int ar9170_disable_key(struct ar9170 *ar, u8 id);
  245. /* LEDs */
  246. #ifdef CONFIG_AR9170_LEDS
  247. int ar9170_register_leds(struct ar9170 *ar);
  248. void ar9170_unregister_leds(struct ar9170 *ar);
  249. #endif /* CONFIG_AR9170_LEDS */
  250. int ar9170_init_leds(struct ar9170 *ar);
  251. int ar9170_set_leds_state(struct ar9170 *ar, u32 led_state);
  252. /* PHY / RF */
  253. int ar9170_init_phy(struct ar9170 *ar, enum ieee80211_band band);
  254. int ar9170_init_rf(struct ar9170 *ar);
  255. int ar9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
  256. enum ar9170_rf_init_mode rfi, enum ar9170_bw bw);
  257. #endif /* __AR9170_H */