carl9170.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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 <linux/hw_random.h>
  46. #include <net/cfg80211.h>
  47. #include <net/mac80211.h>
  48. #include <linux/usb.h>
  49. #ifdef CONFIG_CARL9170_LEDS
  50. #include <linux/leds.h>
  51. #endif /* CONFIG_CARL9170_LEDS */
  52. #ifdef CONFIG_CARL9170_WPC
  53. #include <linux/input.h>
  54. #endif /* CONFIG_CARL9170_WPC */
  55. #include "eeprom.h"
  56. #include "wlan.h"
  57. #include "hw.h"
  58. #include "fwdesc.h"
  59. #include "fwcmd.h"
  60. #include "../regd.h"
  61. #ifdef CONFIG_CARL9170_DEBUGFS
  62. #include "debug.h"
  63. #endif /* CONFIG_CARL9170_DEBUGFS */
  64. #define CARL9170FW_NAME "carl9170-1.fw"
  65. #define PAYLOAD_MAX (CARL9170_MAX_CMD_LEN / 4 - 1)
  66. static const u8 ar9170_qmap[__AR9170_NUM_TXQ] = { 3, 2, 1, 0 };
  67. #define CARL9170_MAX_RX_BUFFER_SIZE 8192
  68. enum carl9170_device_state {
  69. CARL9170_UNKNOWN_STATE,
  70. CARL9170_STOPPED,
  71. CARL9170_IDLE,
  72. CARL9170_STARTED,
  73. };
  74. #define WME_BA_BMP_SIZE 64
  75. #define CARL9170_TX_USER_RATE_TRIES 3
  76. #define TID_TO_WME_AC(_tid) \
  77. ((((_tid) == 0) || ((_tid) == 3)) ? IEEE80211_AC_BE : \
  78. (((_tid) == 1) || ((_tid) == 2)) ? IEEE80211_AC_BK : \
  79. (((_tid) == 4) || ((_tid) == 5)) ? IEEE80211_AC_VI : \
  80. IEEE80211_AC_VO)
  81. #define SEQ_DIFF(_start, _seq) \
  82. (((_start) - (_seq)) & 0x0fff)
  83. #define SEQ_PREV(_seq) \
  84. (((_seq) - 1) & 0x0fff)
  85. #define SEQ_NEXT(_seq) \
  86. (((_seq) + 1) & 0x0fff)
  87. #define BAW_WITHIN(_start, _bawsz, _seqno) \
  88. ((((_seqno) - (_start)) & 0xfff) < (_bawsz))
  89. enum carl9170_tid_state {
  90. CARL9170_TID_STATE_INVALID,
  91. CARL9170_TID_STATE_KILLED,
  92. CARL9170_TID_STATE_SHUTDOWN,
  93. CARL9170_TID_STATE_SUSPEND,
  94. CARL9170_TID_STATE_PROGRESS,
  95. CARL9170_TID_STATE_IDLE,
  96. CARL9170_TID_STATE_XMIT,
  97. };
  98. #define CARL9170_BAW_BITS (2 * WME_BA_BMP_SIZE)
  99. #define CARL9170_BAW_SIZE (BITS_TO_LONGS(CARL9170_BAW_BITS))
  100. #define CARL9170_BAW_LEN (DIV_ROUND_UP(CARL9170_BAW_BITS, BITS_PER_BYTE))
  101. struct carl9170_sta_tid {
  102. /* must be the first entry! */
  103. struct list_head list;
  104. /* temporary list for RCU unlink procedure */
  105. struct list_head tmp_list;
  106. /* lock for the following data structures */
  107. spinlock_t lock;
  108. unsigned int counter;
  109. enum carl9170_tid_state state;
  110. u8 tid; /* TID number ( 0 - 15 ) */
  111. u16 max; /* max. AMPDU size */
  112. u16 snx; /* awaiting _next_ frame */
  113. u16 hsn; /* highest _queued_ sequence */
  114. u16 bsn; /* base of the tx/agg bitmap */
  115. unsigned long bitmap[CARL9170_BAW_SIZE];
  116. /* Preaggregation reorder queue */
  117. struct sk_buff_head queue;
  118. struct ieee80211_sta *sta;
  119. struct ieee80211_vif *vif;
  120. };
  121. #define CARL9170_QUEUE_TIMEOUT 256
  122. #define CARL9170_BUMP_QUEUE 1000
  123. #define CARL9170_TX_TIMEOUT 2500
  124. #define CARL9170_JANITOR_DELAY 128
  125. #define CARL9170_QUEUE_STUCK_TIMEOUT 5500
  126. #define CARL9170_STAT_WORK 30000
  127. #define CARL9170_NUM_TX_AGG_MAX 30
  128. /*
  129. * Tradeoff between stability/latency and speed.
  130. *
  131. * AR9170_TXQ_DEPTH is devised by dividing the amount of available
  132. * tx buffers with the size of a full ethernet frame + overhead.
  133. *
  134. * Naturally: The higher the limit, the faster the device CAN send.
  135. * However, even a slight over-commitment at the wrong time and the
  136. * hardware is doomed to send all already-queued frames at suboptimal
  137. * rates. This in turn leads to an enormous amount of unsuccessful
  138. * retries => Latency goes up, whereas the throughput goes down. CRASH!
  139. */
  140. #define CARL9170_NUM_TX_LIMIT_HARD ((AR9170_TXQ_DEPTH * 3) / 2)
  141. #define CARL9170_NUM_TX_LIMIT_SOFT (AR9170_TXQ_DEPTH)
  142. struct carl9170_tx_queue_stats {
  143. unsigned int count;
  144. unsigned int limit;
  145. unsigned int len;
  146. };
  147. struct carl9170_vif {
  148. unsigned int id;
  149. struct ieee80211_vif __rcu *vif;
  150. };
  151. struct carl9170_vif_info {
  152. struct list_head list;
  153. bool active;
  154. unsigned int id;
  155. struct sk_buff *beacon;
  156. bool enable_beacon;
  157. };
  158. #define AR9170_NUM_RX_URBS 16
  159. #define AR9170_NUM_RX_URBS_MUL 2
  160. #define AR9170_NUM_TX_URBS 8
  161. #define AR9170_NUM_RX_URBS_POOL (AR9170_NUM_RX_URBS_MUL * AR9170_NUM_RX_URBS)
  162. enum carl9170_device_features {
  163. CARL9170_WPS_BUTTON = BIT(0),
  164. CARL9170_ONE_LED = BIT(1),
  165. };
  166. #ifdef CONFIG_CARL9170_LEDS
  167. struct ar9170;
  168. struct carl9170_led {
  169. struct ar9170 *ar;
  170. struct led_classdev l;
  171. char name[32];
  172. unsigned int toggled;
  173. bool last_state;
  174. bool registered;
  175. };
  176. #endif /* CONFIG_CARL9170_LEDS */
  177. enum carl9170_restart_reasons {
  178. CARL9170_RR_NO_REASON = 0,
  179. CARL9170_RR_FATAL_FIRMWARE_ERROR,
  180. CARL9170_RR_TOO_MANY_FIRMWARE_ERRORS,
  181. CARL9170_RR_WATCHDOG,
  182. CARL9170_RR_STUCK_TX,
  183. CARL9170_RR_UNRESPONSIVE_DEVICE,
  184. CARL9170_RR_COMMAND_TIMEOUT,
  185. CARL9170_RR_TOO_MANY_PHY_ERRORS,
  186. CARL9170_RR_LOST_RSP,
  187. CARL9170_RR_INVALID_RSP,
  188. CARL9170_RR_USER_REQUEST,
  189. __CARL9170_RR_LAST,
  190. };
  191. enum carl9170_erp_modes {
  192. CARL9170_ERP_INVALID,
  193. CARL9170_ERP_AUTO,
  194. CARL9170_ERP_MAC80211,
  195. CARL9170_ERP_OFF,
  196. CARL9170_ERP_CTS,
  197. CARL9170_ERP_RTS,
  198. __CARL9170_ERP_NUM,
  199. };
  200. struct ar9170 {
  201. struct ath_common common;
  202. struct ieee80211_hw *hw;
  203. struct mutex mutex;
  204. enum carl9170_device_state state;
  205. spinlock_t state_lock;
  206. enum carl9170_restart_reasons last_reason;
  207. bool registered;
  208. /* USB */
  209. struct usb_device *udev;
  210. struct usb_interface *intf;
  211. struct usb_anchor rx_anch;
  212. struct usb_anchor rx_work;
  213. struct usb_anchor rx_pool;
  214. struct usb_anchor tx_wait;
  215. struct usb_anchor tx_anch;
  216. struct usb_anchor tx_cmd;
  217. struct usb_anchor tx_err;
  218. struct tasklet_struct usb_tasklet;
  219. atomic_t tx_cmd_urbs;
  220. atomic_t tx_anch_urbs;
  221. atomic_t rx_anch_urbs;
  222. atomic_t rx_work_urbs;
  223. atomic_t rx_pool_urbs;
  224. kernel_ulong_t features;
  225. bool usb_ep_cmd_is_bulk;
  226. /* firmware settings */
  227. struct completion fw_load_wait;
  228. struct completion fw_boot_wait;
  229. struct {
  230. const struct carl9170fw_desc_head *desc;
  231. const struct firmware *fw;
  232. unsigned int offset;
  233. unsigned int address;
  234. unsigned int cmd_bufs;
  235. unsigned int api_version;
  236. unsigned int vif_num;
  237. unsigned int err_counter;
  238. unsigned int bug_counter;
  239. u32 beacon_addr;
  240. unsigned int beacon_max_len;
  241. bool rx_stream;
  242. bool tx_stream;
  243. bool rx_filter;
  244. bool hw_counters;
  245. unsigned int mem_blocks;
  246. unsigned int mem_block_size;
  247. unsigned int rx_size;
  248. unsigned int tx_seq_table;
  249. bool ba_filter;
  250. bool disable_offload_fw;
  251. } fw;
  252. /* interface configuration combinations */
  253. struct ieee80211_iface_limit if_comb_limits[1];
  254. struct ieee80211_iface_combination if_combs[1];
  255. /* reset / stuck frames/queue detection */
  256. struct work_struct restart_work;
  257. struct work_struct ping_work;
  258. unsigned int restart_counter;
  259. unsigned long queue_stop_timeout[__AR9170_NUM_TXQ];
  260. unsigned long max_queue_stop_timeout[__AR9170_NUM_TXQ];
  261. bool needs_full_reset;
  262. bool force_usb_reset;
  263. atomic_t pending_restarts;
  264. /* interface mode settings */
  265. struct list_head vif_list;
  266. unsigned long vif_bitmap;
  267. unsigned int vifs;
  268. struct carl9170_vif vif_priv[AR9170_MAX_VIRTUAL_MAC];
  269. /* beaconing */
  270. spinlock_t beacon_lock;
  271. unsigned int global_pretbtt;
  272. unsigned int global_beacon_int;
  273. struct carl9170_vif_info __rcu *beacon_iter;
  274. unsigned int beacon_enabled;
  275. /* cryptographic engine */
  276. u64 usedkeys;
  277. bool rx_software_decryption;
  278. bool disable_offload;
  279. /* filter settings */
  280. u64 cur_mc_hash;
  281. u32 cur_filter;
  282. unsigned int filter_state;
  283. unsigned int rx_filter_caps;
  284. bool sniffer_enabled;
  285. /* MAC */
  286. enum carl9170_erp_modes erp_mode;
  287. /* PHY */
  288. struct ieee80211_channel *channel;
  289. unsigned int num_channels;
  290. int noise[4];
  291. unsigned int chan_fail;
  292. unsigned int total_chan_fail;
  293. u8 heavy_clip;
  294. u8 ht_settings;
  295. struct {
  296. u64 active; /* usec */
  297. u64 cca; /* usec */
  298. u64 tx_time; /* usec */
  299. u64 rx_total;
  300. u64 rx_overrun;
  301. } tally;
  302. struct delayed_work stat_work;
  303. struct survey_info *survey;
  304. /* power calibration data */
  305. u8 power_5G_leg[4];
  306. u8 power_2G_cck[4];
  307. u8 power_2G_ofdm[4];
  308. u8 power_5G_ht20[8];
  309. u8 power_5G_ht40[8];
  310. u8 power_2G_ht20[8];
  311. u8 power_2G_ht40[8];
  312. #ifdef CONFIG_CARL9170_LEDS
  313. /* LED */
  314. struct delayed_work led_work;
  315. struct carl9170_led leds[AR9170_NUM_LEDS];
  316. #endif /* CONFIG_CARL9170_LEDS */
  317. /* qos queue settings */
  318. spinlock_t tx_stats_lock;
  319. struct carl9170_tx_queue_stats tx_stats[__AR9170_NUM_TXQ];
  320. struct ieee80211_tx_queue_params edcf[5];
  321. struct completion tx_flush;
  322. /* CMD */
  323. int cmd_seq;
  324. int readlen;
  325. u8 *readbuf;
  326. spinlock_t cmd_lock;
  327. struct completion cmd_wait;
  328. union {
  329. __le32 cmd_buf[PAYLOAD_MAX + 1];
  330. struct carl9170_cmd cmd;
  331. struct carl9170_rsp rsp;
  332. };
  333. /* statistics */
  334. unsigned int tx_dropped;
  335. unsigned int tx_ack_failures;
  336. unsigned int tx_fcs_errors;
  337. unsigned int rx_dropped;
  338. /* EEPROM */
  339. struct ar9170_eeprom eeprom;
  340. /* tx queuing */
  341. struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
  342. struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
  343. struct delayed_work tx_janitor;
  344. unsigned long tx_janitor_last_run;
  345. bool tx_schedule;
  346. /* tx ampdu */
  347. struct work_struct ampdu_work;
  348. spinlock_t tx_ampdu_list_lock;
  349. struct carl9170_sta_tid __rcu *tx_ampdu_iter;
  350. struct list_head tx_ampdu_list;
  351. atomic_t tx_ampdu_upload;
  352. atomic_t tx_ampdu_scheduler;
  353. atomic_t tx_total_pending;
  354. atomic_t tx_total_queued;
  355. unsigned int tx_ampdu_list_len;
  356. int current_density;
  357. int current_factor;
  358. bool tx_ampdu_schedule;
  359. /* internal memory management */
  360. spinlock_t mem_lock;
  361. unsigned long *mem_bitmap;
  362. atomic_t mem_free_blocks;
  363. atomic_t mem_allocs;
  364. /* rxstream mpdu merge */
  365. struct ar9170_rx_head rx_plcp;
  366. bool rx_has_plcp;
  367. struct sk_buff *rx_failover;
  368. int rx_failover_missing;
  369. u32 ampdu_ref;
  370. /* FIFO for collecting outstanding BlockAckRequest */
  371. struct list_head bar_list[__AR9170_NUM_TXQ];
  372. spinlock_t bar_list_lock[__AR9170_NUM_TXQ];
  373. #ifdef CONFIG_CARL9170_WPC
  374. struct {
  375. bool pbc_state;
  376. struct input_dev *pbc;
  377. char name[32];
  378. char phys[32];
  379. } wps;
  380. #endif /* CONFIG_CARL9170_WPC */
  381. #ifdef CONFIG_CARL9170_DEBUGFS
  382. struct carl9170_debug debug;
  383. struct dentry *debug_dir;
  384. #endif /* CONFIG_CARL9170_DEBUGFS */
  385. /* PSM */
  386. struct work_struct ps_work;
  387. struct {
  388. unsigned int dtim_counter;
  389. unsigned long last_beacon;
  390. unsigned long last_action;
  391. unsigned long last_slept;
  392. unsigned int sleep_ms;
  393. unsigned int off_override;
  394. bool state;
  395. } ps;
  396. #ifdef CONFIG_CARL9170_HWRNG
  397. # define CARL9170_HWRNG_CACHE_SIZE CARL9170_MAX_CMD_PAYLOAD_LEN
  398. struct {
  399. struct hwrng rng;
  400. bool initialized;
  401. char name[30 + 1];
  402. u16 cache[CARL9170_HWRNG_CACHE_SIZE / sizeof(u16)];
  403. unsigned int cache_idx;
  404. } rng;
  405. #endif /* CONFIG_CARL9170_HWRNG */
  406. };
  407. enum carl9170_ps_off_override_reasons {
  408. PS_OFF_VIF = BIT(0),
  409. PS_OFF_BCN = BIT(1),
  410. };
  411. struct carl9170_bar_list_entry {
  412. struct list_head list;
  413. struct rcu_head head;
  414. struct sk_buff *skb;
  415. };
  416. struct carl9170_ba_stats {
  417. u8 ampdu_len;
  418. u8 ampdu_ack_len;
  419. bool clear;
  420. bool req;
  421. };
  422. struct carl9170_sta_info {
  423. bool ht_sta;
  424. bool sleeping;
  425. atomic_t pending_frames;
  426. unsigned int ampdu_max_len;
  427. struct carl9170_sta_tid __rcu *agg[IEEE80211_NUM_TIDS];
  428. struct carl9170_ba_stats stats[IEEE80211_NUM_TIDS];
  429. };
  430. struct carl9170_tx_info {
  431. unsigned long timeout;
  432. struct ar9170 *ar;
  433. struct kref ref;
  434. };
  435. #define CHK_DEV_STATE(a, s) (((struct ar9170 *)a)->state >= (s))
  436. #define IS_INITIALIZED(a) (CHK_DEV_STATE(a, CARL9170_STOPPED))
  437. #define IS_ACCEPTING_CMD(a) (CHK_DEV_STATE(a, CARL9170_IDLE))
  438. #define IS_STARTED(a) (CHK_DEV_STATE(a, CARL9170_STARTED))
  439. static inline void __carl9170_set_state(struct ar9170 *ar,
  440. enum carl9170_device_state newstate)
  441. {
  442. ar->state = newstate;
  443. }
  444. static inline void carl9170_set_state(struct ar9170 *ar,
  445. enum carl9170_device_state newstate)
  446. {
  447. unsigned long flags;
  448. spin_lock_irqsave(&ar->state_lock, flags);
  449. __carl9170_set_state(ar, newstate);
  450. spin_unlock_irqrestore(&ar->state_lock, flags);
  451. }
  452. static inline void carl9170_set_state_when(struct ar9170 *ar,
  453. enum carl9170_device_state min, enum carl9170_device_state newstate)
  454. {
  455. unsigned long flags;
  456. spin_lock_irqsave(&ar->state_lock, flags);
  457. if (CHK_DEV_STATE(ar, min))
  458. __carl9170_set_state(ar, newstate);
  459. spin_unlock_irqrestore(&ar->state_lock, flags);
  460. }
  461. /* exported interface */
  462. void *carl9170_alloc(size_t priv_size);
  463. int carl9170_register(struct ar9170 *ar);
  464. void carl9170_unregister(struct ar9170 *ar);
  465. void carl9170_free(struct ar9170 *ar);
  466. void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
  467. void carl9170_ps_check(struct ar9170 *ar);
  468. /* USB back-end */
  469. int carl9170_usb_open(struct ar9170 *ar);
  470. void carl9170_usb_stop(struct ar9170 *ar);
  471. void carl9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb);
  472. void carl9170_usb_handle_tx_err(struct ar9170 *ar);
  473. int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids,
  474. u32 plen, void *payload, u32 rlen, void *resp);
  475. int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
  476. const bool free_buf);
  477. int carl9170_usb_restart(struct ar9170 *ar);
  478. void carl9170_usb_reset(struct ar9170 *ar);
  479. /* MAC */
  480. int carl9170_init_mac(struct ar9170 *ar);
  481. int carl9170_set_qos(struct ar9170 *ar);
  482. int carl9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
  483. int carl9170_mod_virtual_mac(struct ar9170 *ar, const unsigned int id,
  484. const u8 *mac);
  485. int carl9170_set_operating_mode(struct ar9170 *ar);
  486. int carl9170_set_beacon_timers(struct ar9170 *ar);
  487. int carl9170_set_dyn_sifs_ack(struct ar9170 *ar);
  488. int carl9170_set_rts_cts_rate(struct ar9170 *ar);
  489. int carl9170_set_ampdu_settings(struct ar9170 *ar);
  490. int carl9170_set_slot_time(struct ar9170 *ar);
  491. int carl9170_set_mac_rates(struct ar9170 *ar);
  492. int carl9170_set_hwretry_limit(struct ar9170 *ar, const u32 max_retry);
  493. int carl9170_upload_key(struct ar9170 *ar, const u8 id, const u8 *mac,
  494. const u8 ktype, const u8 keyidx, const u8 *keydata, const int keylen);
  495. int carl9170_disable_key(struct ar9170 *ar, const u8 id);
  496. int carl9170_set_mac_tpc(struct ar9170 *ar, struct ieee80211_channel *channel);
  497. /* RX */
  498. void carl9170_rx(struct ar9170 *ar, void *buf, unsigned int len);
  499. void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
  500. /* TX */
  501. void carl9170_op_tx(struct ieee80211_hw *hw,
  502. struct ieee80211_tx_control *control,
  503. struct sk_buff *skb);
  504. void carl9170_tx_janitor(struct work_struct *work);
  505. void carl9170_tx_process_status(struct ar9170 *ar,
  506. const struct carl9170_rsp *cmd);
  507. void carl9170_tx_status(struct ar9170 *ar, struct sk_buff *skb,
  508. const bool success);
  509. void carl9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
  510. void carl9170_tx_drop(struct ar9170 *ar, struct sk_buff *skb);
  511. void carl9170_tx_scheduler(struct ar9170 *ar);
  512. void carl9170_tx_get_skb(struct sk_buff *skb);
  513. int carl9170_tx_put_skb(struct sk_buff *skb);
  514. int carl9170_update_beacon(struct ar9170 *ar, const bool submit);
  515. /* LEDs */
  516. #ifdef CONFIG_CARL9170_LEDS
  517. int carl9170_led_register(struct ar9170 *ar);
  518. void carl9170_led_unregister(struct ar9170 *ar);
  519. #endif /* CONFIG_CARL9170_LEDS */
  520. int carl9170_led_init(struct ar9170 *ar);
  521. int carl9170_led_set_state(struct ar9170 *ar, const u32 led_state);
  522. /* PHY / RF */
  523. int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
  524. enum nl80211_channel_type bw);
  525. int carl9170_get_noisefloor(struct ar9170 *ar);
  526. /* FW */
  527. int carl9170_parse_firmware(struct ar9170 *ar);
  528. extern struct ieee80211_rate __carl9170_ratetable[];
  529. extern int modparam_noht;
  530. static inline struct ar9170 *carl9170_get_priv(struct carl9170_vif *carl_vif)
  531. {
  532. return container_of(carl_vif, struct ar9170,
  533. vif_priv[carl_vif->id]);
  534. }
  535. static inline struct ieee80211_hdr *carl9170_get_hdr(struct sk_buff *skb)
  536. {
  537. return (void *)((struct _carl9170_tx_superframe *)
  538. skb->data)->frame_data;
  539. }
  540. static inline u16 get_seq_h(struct ieee80211_hdr *hdr)
  541. {
  542. return le16_to_cpu(hdr->seq_ctrl) >> 4;
  543. }
  544. static inline u16 carl9170_get_seq(struct sk_buff *skb)
  545. {
  546. return get_seq_h(carl9170_get_hdr(skb));
  547. }
  548. static inline u16 get_tid_h(struct ieee80211_hdr *hdr)
  549. {
  550. return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
  551. }
  552. static inline u16 carl9170_get_tid(struct sk_buff *skb)
  553. {
  554. return get_tid_h(carl9170_get_hdr(skb));
  555. }
  556. static inline struct ieee80211_vif *
  557. carl9170_get_vif(struct carl9170_vif_info *priv)
  558. {
  559. return container_of((void *)priv, struct ieee80211_vif, drv_priv);
  560. }
  561. /* Protected by ar->mutex or RCU */
  562. static inline struct ieee80211_vif *carl9170_get_main_vif(struct ar9170 *ar)
  563. {
  564. struct carl9170_vif_info *cvif;
  565. list_for_each_entry_rcu(cvif, &ar->vif_list, list) {
  566. if (cvif->active)
  567. return carl9170_get_vif(cvif);
  568. }
  569. return NULL;
  570. }
  571. static inline bool is_main_vif(struct ar9170 *ar, struct ieee80211_vif *vif)
  572. {
  573. bool ret;
  574. rcu_read_lock();
  575. ret = (carl9170_get_main_vif(ar) == vif);
  576. rcu_read_unlock();
  577. return ret;
  578. }
  579. #endif /* __CARL9170_H */