carl9170.h 18 KB

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