carl9170.h 18 KB

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