carl9170.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /*
  2. * Atheros CARL9170 driver
  3. *
  4. * Driver specific definitions
  5. *
  6. * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  7. * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; see the file COPYING. If not, see
  21. * http://www.gnu.org/licenses/.
  22. *
  23. * This file incorporates work covered by the following copyright and
  24. * permission notice:
  25. * Copyright (c) 2007-2008 Atheros Communications, Inc.
  26. *
  27. * Permission to use, copy, modify, and/or distribute this software for any
  28. * purpose with or without fee is hereby granted, provided that the above
  29. * copyright notice and this permission notice appear in all copies.
  30. *
  31. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  32. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  33. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  34. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  35. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  36. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  37. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  38. */
  39. #ifndef __CARL9170_H
  40. #define __CARL9170_H
  41. #include <linux/kernel.h>
  42. #include <linux/firmware.h>
  43. #include <linux/completion.h>
  44. #include <linux/spinlock.h>
  45. #include <net/cfg80211.h>
  46. #include <net/mac80211.h>
  47. #include <linux/usb.h>
  48. #ifdef CONFIG_CARL9170_LEDS
  49. #include <linux/leds.h>
  50. #endif /* CONFIG_CARL9170_LEDS */
  51. #ifdef CONFIG_CARL9170_WPC
  52. #include <linux/input.h>
  53. #endif /* CONFIG_CARL9170_WPC */
  54. #include "eeprom.h"
  55. #include "wlan.h"
  56. #include "hw.h"
  57. #include "fwdesc.h"
  58. #include "fwcmd.h"
  59. #include "../regd.h"
  60. #ifdef CONFIG_CARL9170_DEBUGFS
  61. #include "debug.h"
  62. #endif /* CONFIG_CARL9170_DEBUGFS */
  63. #define CARL9170FW_NAME "carl9170-1.fw"
  64. #define PAYLOAD_MAX (CARL9170_MAX_CMD_LEN / 4 - 1)
  65. enum carl9170_rf_init_mode {
  66. CARL9170_RFI_NONE,
  67. CARL9170_RFI_WARM,
  68. CARL9170_RFI_COLD,
  69. };
  70. #define CARL9170_MAX_RX_BUFFER_SIZE 8192
  71. enum carl9170_device_state {
  72. CARL9170_UNKNOWN_STATE,
  73. CARL9170_STOPPED,
  74. CARL9170_IDLE,
  75. CARL9170_STARTED,
  76. };
  77. #define CARL9170_NUM_TID 16
  78. #define WME_BA_BMP_SIZE 64
  79. #define CARL9170_TX_USER_RATE_TRIES 3
  80. #define WME_AC_BE 2
  81. #define WME_AC_BK 3
  82. #define WME_AC_VI 1
  83. #define WME_AC_VO 0
  84. #define TID_TO_WME_AC(_tid) \
  85. ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \
  86. (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK : \
  87. (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \
  88. WME_AC_VO)
  89. #define SEQ_DIFF(_start, _seq) \
  90. (((_start) - (_seq)) & 0x0fff)
  91. #define SEQ_PREV(_seq) \
  92. (((_seq) - 1) & 0x0fff)
  93. #define SEQ_NEXT(_seq) \
  94. (((_seq) + 1) & 0x0fff)
  95. #define BAW_WITHIN(_start, _bawsz, _seqno) \
  96. ((((_seqno) - (_start)) & 0xfff) < (_bawsz))
  97. enum carl9170_tid_state {
  98. CARL9170_TID_STATE_INVALID,
  99. CARL9170_TID_STATE_KILLED,
  100. CARL9170_TID_STATE_SHUTDOWN,
  101. CARL9170_TID_STATE_SUSPEND,
  102. CARL9170_TID_STATE_PROGRESS,
  103. CARL9170_TID_STATE_IDLE,
  104. CARL9170_TID_STATE_XMIT,
  105. };
  106. #define CARL9170_BAW_BITS (2 * WME_BA_BMP_SIZE)
  107. #define CARL9170_BAW_SIZE (BITS_TO_LONGS(CARL9170_BAW_BITS))
  108. #define CARL9170_BAW_LEN (DIV_ROUND_UP(CARL9170_BAW_BITS, BITS_PER_BYTE))
  109. struct carl9170_sta_tid {
  110. /* must be the first entry! */
  111. struct list_head list;
  112. /* temporary list for RCU unlink procedure */
  113. struct list_head tmp_list;
  114. /* lock for the following data structures */
  115. spinlock_t lock;
  116. unsigned int counter;
  117. enum carl9170_tid_state state;
  118. u8 tid; /* TID number ( 0 - 15 ) */
  119. u16 max; /* max. AMPDU size */
  120. u16 snx; /* awaiting _next_ frame */
  121. u16 hsn; /* highest _queued_ sequence */
  122. u16 bsn; /* base of the tx/agg bitmap */
  123. unsigned long bitmap[CARL9170_BAW_SIZE];
  124. /* Preaggregation reorder queue */
  125. struct sk_buff_head queue;
  126. };
  127. #define CARL9170_QUEUE_TIMEOUT 256
  128. #define CARL9170_BUMP_QUEUE 1000
  129. #define CARL9170_TX_TIMEOUT 2500
  130. #define CARL9170_JANITOR_DELAY 128
  131. #define CARL9170_QUEUE_STUCK_TIMEOUT 5500
  132. #define CARL9170_NUM_TX_AGG_MAX 30
  133. /*
  134. * Tradeoff between stability/latency and speed.
  135. *
  136. * AR9170_TXQ_DEPTH is devised by dividing the amount of available
  137. * tx buffers with the size of a full ethernet frame + overhead.
  138. *
  139. * Naturally: The higher the limit, the faster the device CAN send.
  140. * However, even a slight over-commitment at the wrong time and the
  141. * hardware is doomed to send all already-queued frames at suboptimal
  142. * rates. This in turn leads to an enourmous amount of unsuccessful
  143. * retries => Latency goes up, whereas the throughput goes down. CRASH!
  144. */
  145. #define CARL9170_NUM_TX_LIMIT_HARD ((AR9170_TXQ_DEPTH * 3) / 2)
  146. #define CARL9170_NUM_TX_LIMIT_SOFT (AR9170_TXQ_DEPTH)
  147. struct carl9170_tx_queue_stats {
  148. unsigned int count;
  149. unsigned int limit;
  150. unsigned int len;
  151. };
  152. struct carl9170_vif {
  153. unsigned int id;
  154. struct ieee80211_vif *vif;
  155. };
  156. struct carl9170_vif_info {
  157. struct list_head list;
  158. bool active;
  159. unsigned int id;
  160. struct sk_buff *beacon;
  161. bool enable_beacon;
  162. };
  163. #define AR9170_NUM_RX_URBS 16
  164. #define AR9170_NUM_RX_URBS_MUL 2
  165. #define AR9170_NUM_TX_URBS 8
  166. #define AR9170_NUM_RX_URBS_POOL (AR9170_NUM_RX_URBS_MUL * AR9170_NUM_RX_URBS)
  167. enum carl9170_device_features {
  168. CARL9170_WPS_BUTTON = BIT(0),
  169. CARL9170_ONE_LED = BIT(1),
  170. };
  171. #ifdef CONFIG_CARL9170_LEDS
  172. struct ar9170;
  173. struct carl9170_led {
  174. struct ar9170 *ar;
  175. struct led_classdev l;
  176. char name[32];
  177. unsigned int toggled;
  178. bool last_state;
  179. bool registered;
  180. };
  181. #endif /* CONFIG_CARL9170_LEDS */
  182. enum carl9170_restart_reasons {
  183. CARL9170_RR_NO_REASON = 0,
  184. CARL9170_RR_FATAL_FIRMWARE_ERROR,
  185. CARL9170_RR_TOO_MANY_FIRMWARE_ERRORS,
  186. CARL9170_RR_WATCHDOG,
  187. CARL9170_RR_STUCK_TX,
  188. CARL9170_RR_UNRESPONSIVE_DEVICE,
  189. CARL9170_RR_COMMAND_TIMEOUT,
  190. CARL9170_RR_TOO_MANY_PHY_ERRORS,
  191. CARL9170_RR_LOST_RSP,
  192. CARL9170_RR_INVALID_RSP,
  193. CARL9170_RR_USER_REQUEST,
  194. __CARL9170_RR_LAST,
  195. };
  196. enum carl9170_erp_modes {
  197. CARL9170_ERP_INVALID,
  198. CARL9170_ERP_AUTO,
  199. CARL9170_ERP_MAC80211,
  200. CARL9170_ERP_OFF,
  201. CARL9170_ERP_CTS,
  202. CARL9170_ERP_RTS,
  203. __CARL9170_ERP_NUM,
  204. };
  205. struct ar9170 {
  206. struct ath_common common;
  207. struct ieee80211_hw *hw;
  208. struct mutex mutex;
  209. enum carl9170_device_state state;
  210. spinlock_t state_lock;
  211. enum carl9170_restart_reasons last_reason;
  212. bool registered;
  213. /* USB */
  214. struct usb_device *udev;
  215. struct usb_interface *intf;
  216. struct usb_anchor rx_anch;
  217. struct usb_anchor rx_work;
  218. struct usb_anchor rx_pool;
  219. struct usb_anchor tx_wait;
  220. struct usb_anchor tx_anch;
  221. struct usb_anchor tx_cmd;
  222. struct usb_anchor tx_err;
  223. struct tasklet_struct usb_tasklet;
  224. atomic_t tx_cmd_urbs;
  225. atomic_t tx_anch_urbs;
  226. atomic_t rx_anch_urbs;
  227. atomic_t rx_work_urbs;
  228. atomic_t rx_pool_urbs;
  229. kernel_ulong_t features;
  230. /* firmware settings */
  231. struct completion fw_load_wait;
  232. struct completion fw_boot_wait;
  233. struct {
  234. const struct carl9170fw_desc_head *desc;
  235. const struct firmware *fw;
  236. unsigned int offset;
  237. unsigned int address;
  238. unsigned int cmd_bufs;
  239. unsigned int api_version;
  240. unsigned int vif_num;
  241. unsigned int err_counter;
  242. unsigned int bug_counter;
  243. u32 beacon_addr;
  244. unsigned int beacon_max_len;
  245. bool rx_stream;
  246. bool tx_stream;
  247. bool rx_filter;
  248. unsigned int mem_blocks;
  249. unsigned int mem_block_size;
  250. unsigned int rx_size;
  251. } fw;
  252. /* reset / stuck frames/queue detection */
  253. struct work_struct restart_work;
  254. struct work_struct ping_work;
  255. unsigned int restart_counter;
  256. unsigned long queue_stop_timeout[__AR9170_NUM_TXQ];
  257. unsigned long max_queue_stop_timeout[__AR9170_NUM_TXQ];
  258. bool needs_full_reset;
  259. atomic_t pending_restarts;
  260. /* interface mode settings */
  261. struct list_head vif_list;
  262. unsigned long vif_bitmap;
  263. unsigned int vifs;
  264. struct carl9170_vif vif_priv[AR9170_MAX_VIRTUAL_MAC];
  265. /* beaconing */
  266. spinlock_t beacon_lock;
  267. unsigned int global_pretbtt;
  268. unsigned int global_beacon_int;
  269. struct carl9170_vif_info *beacon_iter;
  270. unsigned int beacon_enabled;
  271. /* cryptographic engine */
  272. u64 usedkeys;
  273. bool rx_software_decryption;
  274. bool disable_offload;
  275. /* filter settings */
  276. u64 cur_mc_hash;
  277. u32 cur_filter;
  278. unsigned int filter_state;
  279. unsigned int rx_filter_caps;
  280. bool sniffer_enabled;
  281. /* MAC */
  282. enum carl9170_erp_modes erp_mode;
  283. /* PHY */
  284. struct ieee80211_channel *channel;
  285. int noise[4];
  286. unsigned int chan_fail;
  287. unsigned int total_chan_fail;
  288. u8 heavy_clip;
  289. u8 ht_settings;
  290. /* power calibration data */
  291. u8 power_5G_leg[4];
  292. u8 power_2G_cck[4];
  293. u8 power_2G_ofdm[4];
  294. u8 power_5G_ht20[8];
  295. u8 power_5G_ht40[8];
  296. u8 power_2G_ht20[8];
  297. u8 power_2G_ht40[8];
  298. #ifdef CONFIG_CARL9170_LEDS
  299. /* LED */
  300. struct delayed_work led_work;
  301. struct carl9170_led leds[AR9170_NUM_LEDS];
  302. #endif /* CONFIG_CARL9170_LEDS */
  303. /* qos queue settings */
  304. spinlock_t tx_stats_lock;
  305. struct carl9170_tx_queue_stats tx_stats[__AR9170_NUM_TXQ];
  306. struct ieee80211_tx_queue_params edcf[5];
  307. struct completion tx_flush;
  308. /* CMD */
  309. int cmd_seq;
  310. int readlen;
  311. u8 *readbuf;
  312. spinlock_t cmd_lock;
  313. struct completion cmd_wait;
  314. union {
  315. __le32 cmd_buf[PAYLOAD_MAX + 1];
  316. struct carl9170_cmd cmd;
  317. struct carl9170_rsp rsp;
  318. };
  319. /* statistics */
  320. unsigned int tx_dropped;
  321. unsigned int tx_ack_failures;
  322. unsigned int tx_fcs_errors;
  323. unsigned int rx_dropped;
  324. /* EEPROM */
  325. struct ar9170_eeprom eeprom;
  326. /* tx queuing */
  327. struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
  328. struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
  329. struct delayed_work tx_janitor;
  330. unsigned long tx_janitor_last_run;
  331. bool tx_schedule;
  332. /* tx ampdu */
  333. struct work_struct ampdu_work;
  334. spinlock_t tx_ampdu_list_lock;
  335. struct carl9170_sta_tid *tx_ampdu_iter;
  336. struct list_head tx_ampdu_list;
  337. atomic_t tx_ampdu_upload;
  338. atomic_t tx_ampdu_scheduler;
  339. atomic_t tx_total_pending;
  340. atomic_t tx_total_queued;
  341. unsigned int tx_ampdu_list_len;
  342. int current_density;
  343. int current_factor;
  344. bool tx_ampdu_schedule;
  345. /* internal memory management */
  346. spinlock_t mem_lock;
  347. unsigned long *mem_bitmap;
  348. atomic_t mem_free_blocks;
  349. atomic_t mem_allocs;
  350. /* rxstream mpdu merge */
  351. struct ar9170_rx_head rx_plcp;
  352. bool rx_has_plcp;
  353. struct sk_buff *rx_failover;
  354. int rx_failover_missing;
  355. #ifdef CONFIG_CARL9170_WPC
  356. struct {
  357. bool pbc_state;
  358. struct input_dev *pbc;
  359. char name[32];
  360. char phys[32];
  361. } wps;
  362. #endif /* CONFIG_CARL9170_WPC */
  363. #ifdef CONFIG_CARL9170_DEBUGFS
  364. struct carl9170_debug debug;
  365. struct dentry *debug_dir;
  366. #endif /* CONFIG_CARL9170_DEBUGFS */
  367. /* PSM */
  368. struct work_struct ps_work;
  369. struct {
  370. unsigned int dtim_counter;
  371. unsigned long last_beacon;
  372. unsigned long last_action;
  373. unsigned long last_slept;
  374. unsigned int sleep_ms;
  375. unsigned int off_override;
  376. bool state;
  377. } ps;
  378. };
  379. enum carl9170_ps_off_override_reasons {
  380. PS_OFF_VIF = BIT(0),
  381. PS_OFF_BCN = BIT(1),
  382. PS_OFF_5GHZ = BIT(2),
  383. };
  384. struct carl9170_ba_stats {
  385. u8 ampdu_len;
  386. u8 ampdu_ack_len;
  387. bool clear;
  388. };
  389. struct carl9170_sta_info {
  390. bool ht_sta;
  391. unsigned int ampdu_max_len;
  392. struct carl9170_sta_tid *agg[CARL9170_NUM_TID];
  393. struct carl9170_ba_stats stats[CARL9170_NUM_TID];
  394. };
  395. struct carl9170_tx_info {
  396. unsigned long timeout;
  397. struct ar9170 *ar;
  398. struct kref ref;
  399. };
  400. #define CHK_DEV_STATE(a, s) (((struct ar9170 *)a)->state >= (s))
  401. #define IS_INITIALIZED(a) (CHK_DEV_STATE(a, CARL9170_STOPPED))
  402. #define IS_ACCEPTING_CMD(a) (CHK_DEV_STATE(a, CARL9170_IDLE))
  403. #define IS_STARTED(a) (CHK_DEV_STATE(a, CARL9170_STARTED))
  404. static inline void __carl9170_set_state(struct ar9170 *ar,
  405. enum carl9170_device_state newstate)
  406. {
  407. ar->state = newstate;
  408. }
  409. static inline void carl9170_set_state(struct ar9170 *ar,
  410. enum carl9170_device_state newstate)
  411. {
  412. unsigned long flags;
  413. spin_lock_irqsave(&ar->state_lock, flags);
  414. __carl9170_set_state(ar, newstate);
  415. spin_unlock_irqrestore(&ar->state_lock, flags);
  416. }
  417. static inline void carl9170_set_state_when(struct ar9170 *ar,
  418. enum carl9170_device_state min, enum carl9170_device_state newstate)
  419. {
  420. unsigned long flags;
  421. spin_lock_irqsave(&ar->state_lock, flags);
  422. if (CHK_DEV_STATE(ar, min))
  423. __carl9170_set_state(ar, newstate);
  424. spin_unlock_irqrestore(&ar->state_lock, flags);
  425. }
  426. /* exported interface */
  427. void *carl9170_alloc(size_t priv_size);
  428. int carl9170_register(struct ar9170 *ar);
  429. void carl9170_unregister(struct ar9170 *ar);
  430. void carl9170_free(struct ar9170 *ar);
  431. void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
  432. void carl9170_ps_check(struct ar9170 *ar);
  433. /* USB back-end */
  434. int carl9170_usb_open(struct ar9170 *ar);
  435. void carl9170_usb_stop(struct ar9170 *ar);
  436. void carl9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb);
  437. void carl9170_usb_handle_tx_err(struct ar9170 *ar);
  438. int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids,
  439. u32 plen, void *payload, u32 rlen, void *resp);
  440. int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
  441. const bool free_buf);
  442. int carl9170_usb_restart(struct ar9170 *ar);
  443. void carl9170_usb_reset(struct ar9170 *ar);
  444. /* MAC */
  445. int carl9170_init_mac(struct ar9170 *ar);
  446. int carl9170_set_qos(struct ar9170 *ar);
  447. int carl9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
  448. int carl9170_mod_virtual_mac(struct ar9170 *ar, const unsigned int id,
  449. const u8 *mac);
  450. int carl9170_set_operating_mode(struct ar9170 *ar);
  451. int carl9170_set_beacon_timers(struct ar9170 *ar);
  452. int carl9170_set_dyn_sifs_ack(struct ar9170 *ar);
  453. int carl9170_set_rts_cts_rate(struct ar9170 *ar);
  454. int carl9170_set_ampdu_settings(struct ar9170 *ar);
  455. int carl9170_set_slot_time(struct ar9170 *ar);
  456. int carl9170_set_mac_rates(struct ar9170 *ar);
  457. int carl9170_set_hwretry_limit(struct ar9170 *ar, const u32 max_retry);
  458. int carl9170_update_beacon(struct ar9170 *ar, const bool submit);
  459. int carl9170_upload_key(struct ar9170 *ar, const u8 id, const u8 *mac,
  460. const u8 ktype, const u8 keyidx, const u8 *keydata, const int keylen);
  461. int carl9170_disable_key(struct ar9170 *ar, const u8 id);
  462. /* RX */
  463. void carl9170_rx(struct ar9170 *ar, void *buf, unsigned int len);
  464. void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
  465. /* TX */
  466. int carl9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  467. void carl9170_tx_janitor(struct work_struct *work);
  468. void carl9170_tx_process_status(struct ar9170 *ar,
  469. const struct carl9170_rsp *cmd);
  470. void carl9170_tx_status(struct ar9170 *ar, struct sk_buff *skb,
  471. const bool success);
  472. void carl9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
  473. void carl9170_tx_drop(struct ar9170 *ar, struct sk_buff *skb);
  474. void carl9170_tx_scheduler(struct ar9170 *ar);
  475. void carl9170_tx_get_skb(struct sk_buff *skb);
  476. int carl9170_tx_put_skb(struct sk_buff *skb);
  477. /* LEDs */
  478. #ifdef CONFIG_CARL9170_LEDS
  479. int carl9170_led_register(struct ar9170 *ar);
  480. void carl9170_led_unregister(struct ar9170 *ar);
  481. #endif /* CONFIG_CARL9170_LEDS */
  482. int carl9170_led_init(struct ar9170 *ar);
  483. int carl9170_led_set_state(struct ar9170 *ar, const u32 led_state);
  484. /* PHY / RF */
  485. int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
  486. enum nl80211_channel_type bw, enum carl9170_rf_init_mode rfi);
  487. int carl9170_get_noisefloor(struct ar9170 *ar);
  488. /* FW */
  489. int carl9170_parse_firmware(struct ar9170 *ar);
  490. int carl9170_fw_fix_eeprom(struct ar9170 *ar);
  491. extern struct ieee80211_rate __carl9170_ratetable[];
  492. extern int modparam_noht;
  493. static inline struct ar9170 *carl9170_get_priv(struct carl9170_vif *carl_vif)
  494. {
  495. return container_of(carl_vif, struct ar9170,
  496. vif_priv[carl_vif->id]);
  497. }
  498. static inline struct ieee80211_hdr *carl9170_get_hdr(struct sk_buff *skb)
  499. {
  500. return (void *)((struct _carl9170_tx_superframe *)
  501. skb->data)->frame_data;
  502. }
  503. static inline u16 get_seq_h(struct ieee80211_hdr *hdr)
  504. {
  505. return le16_to_cpu(hdr->seq_ctrl) >> 4;
  506. }
  507. static inline u16 carl9170_get_seq(struct sk_buff *skb)
  508. {
  509. return get_seq_h(carl9170_get_hdr(skb));
  510. }
  511. static inline u16 get_tid_h(struct ieee80211_hdr *hdr)
  512. {
  513. return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
  514. }
  515. static inline u16 carl9170_get_tid(struct sk_buff *skb)
  516. {
  517. return get_tid_h(carl9170_get_hdr(skb));
  518. }
  519. static inline struct ieee80211_vif *
  520. carl9170_get_vif(struct carl9170_vif_info *priv)
  521. {
  522. return container_of((void *)priv, struct ieee80211_vif, drv_priv);
  523. }
  524. /* Protected by ar->mutex or RCU */
  525. static inline struct ieee80211_vif *carl9170_get_main_vif(struct ar9170 *ar)
  526. {
  527. struct carl9170_vif_info *cvif;
  528. list_for_each_entry_rcu(cvif, &ar->vif_list, list) {
  529. if (cvif->active)
  530. return carl9170_get_vif(cvif);
  531. }
  532. return NULL;
  533. }
  534. static inline bool is_main_vif(struct ar9170 *ar, struct ieee80211_vif *vif)
  535. {
  536. bool ret;
  537. rcu_read_lock();
  538. ret = (carl9170_get_main_vif(ar) == vif);
  539. rcu_read_unlock();
  540. return ret;
  541. }
  542. #endif /* __CARL9170_H */