Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
carl9170.h
Go to the documentation of this file.
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 
42 #include <linux/kernel.h>
43 #include <linux/firmware.h>
44 #include <linux/completion.h>
45 #include <linux/spinlock.h>
46 #include <linux/hw_random.h>
47 #include <net/cfg80211.h>
48 #include <net/mac80211.h>
49 #include <linux/usb.h>
50 #ifdef CONFIG_CARL9170_LEDS
51 #include <linux/leds.h>
52 #endif /* CONFIG_CARL9170_LEDS */
53 #ifdef CONFIG_CARL9170_WPC
54 #include <linux/input.h>
55 #endif /* CONFIG_CARL9170_WPC */
56 #include "eeprom.h"
57 #include "wlan.h"
58 #include "hw.h"
59 #include "fwdesc.h"
60 #include "fwcmd.h"
61 #include "../regd.h"
62 
63 #ifdef CONFIG_CARL9170_DEBUGFS
64 #include "debug.h"
65 #endif /* CONFIG_CARL9170_DEBUGFS */
66 
67 #define CARL9170FW_NAME "carl9170-1.fw"
68 
69 #define PAYLOAD_MAX (CARL9170_MAX_CMD_LEN / 4 - 1)
70 
71 static const u8 ar9170_qmap[__AR9170_NUM_TXQ] = { 3, 2, 1, 0 };
72 
77 };
78 
79 #define CARL9170_MAX_RX_BUFFER_SIZE 8192
80 
86 };
87 
88 #define CARL9170_NUM_TID 16
89 #define WME_BA_BMP_SIZE 64
90 #define CARL9170_TX_USER_RATE_TRIES 3
91 
92 #define WME_AC_BE 2
93 #define WME_AC_BK 3
94 #define WME_AC_VI 1
95 #define WME_AC_VO 0
96 
97 #define TID_TO_WME_AC(_tid) \
98  ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \
99  (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK : \
100  (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \
101  WME_AC_VO)
102 
103 #define SEQ_DIFF(_start, _seq) \
104  (((_start) - (_seq)) & 0x0fff)
105 #define SEQ_PREV(_seq) \
106  (((_seq) - 1) & 0x0fff)
107 #define SEQ_NEXT(_seq) \
108  (((_seq) + 1) & 0x0fff)
109 #define BAW_WITHIN(_start, _bawsz, _seqno) \
110  ((((_seqno) - (_start)) & 0xfff) < (_bawsz))
111 
120 };
121 
122 #define CARL9170_BAW_BITS (2 * WME_BA_BMP_SIZE)
123 #define CARL9170_BAW_SIZE (BITS_TO_LONGS(CARL9170_BAW_BITS))
124 #define CARL9170_BAW_LEN (DIV_ROUND_UP(CARL9170_BAW_BITS, BITS_PER_BYTE))
125 
127  /* must be the first entry! */
128  struct list_head list;
129 
130  /* temporary list for RCU unlink procedure */
132 
133  /* lock for the following data structures */
135 
136  unsigned int counter;
138  u8 tid; /* TID number ( 0 - 15 ) */
139  u16 max; /* max. AMPDU size */
140 
141  u16 snx; /* awaiting _next_ frame */
142  u16 hsn; /* highest _queued_ sequence */
143  u16 bsn; /* base of the tx/agg bitmap */
144  unsigned long bitmap[CARL9170_BAW_SIZE];
145 
146  /* Preaggregation reorder queue */
148 };
149 
150 #define CARL9170_QUEUE_TIMEOUT 256
151 #define CARL9170_BUMP_QUEUE 1000
152 #define CARL9170_TX_TIMEOUT 2500
153 #define CARL9170_JANITOR_DELAY 128
154 #define CARL9170_QUEUE_STUCK_TIMEOUT 5500
155 #define CARL9170_STAT_WORK 30000
156 
157 #define CARL9170_NUM_TX_AGG_MAX 30
158 
159 /*
160  * Tradeoff between stability/latency and speed.
161  *
162  * AR9170_TXQ_DEPTH is devised by dividing the amount of available
163  * tx buffers with the size of a full ethernet frame + overhead.
164  *
165  * Naturally: The higher the limit, the faster the device CAN send.
166  * However, even a slight over-commitment at the wrong time and the
167  * hardware is doomed to send all already-queued frames at suboptimal
168  * rates. This in turn leads to an enormous amount of unsuccessful
169  * retries => Latency goes up, whereas the throughput goes down. CRASH!
170  */
171 #define CARL9170_NUM_TX_LIMIT_HARD ((AR9170_TXQ_DEPTH * 3) / 2)
172 #define CARL9170_NUM_TX_LIMIT_SOFT (AR9170_TXQ_DEPTH)
173 
175  unsigned int count;
176  unsigned int limit;
177  unsigned int len;
178 };
179 
180 struct carl9170_vif {
181  unsigned int id;
183 };
184 
186  struct list_head list;
187  bool active;
188  unsigned int id;
189  struct sk_buff *beacon;
191 };
192 
193 #define AR9170_NUM_RX_URBS 16
194 #define AR9170_NUM_RX_URBS_MUL 2
195 #define AR9170_NUM_TX_URBS 8
196 #define AR9170_NUM_RX_URBS_POOL (AR9170_NUM_RX_URBS_MUL * AR9170_NUM_RX_URBS)
197 
201 };
202 
203 #ifdef CONFIG_CARL9170_LEDS
204 struct ar9170;
205 
206 struct carl9170_led {
207  struct ar9170 *ar;
208  struct led_classdev l;
209  char name[32];
210  unsigned int toggled;
211  bool last_state;
212  bool registered;
213 };
214 #endif /* CONFIG_CARL9170_LEDS */
215 
228 
230 };
231 
240 };
241 
242 struct ar9170 {
244  struct ieee80211_hw *hw;
245  struct mutex mutex;
250 
251  /* USB */
252  struct usb_device *udev;
254  struct usb_anchor rx_anch;
255  struct usb_anchor rx_work;
256  struct usb_anchor rx_pool;
257  struct usb_anchor tx_wait;
258  struct usb_anchor tx_anch;
259  struct usb_anchor tx_cmd;
260  struct usb_anchor tx_err;
268 
269  /* firmware settings */
272  struct {
273  const struct carl9170fw_desc_head *desc;
274  const struct firmware *fw;
275  unsigned int offset;
276  unsigned int address;
277  unsigned int cmd_bufs;
278  unsigned int api_version;
279  unsigned int vif_num;
280  unsigned int err_counter;
281  unsigned int bug_counter;
283  unsigned int beacon_max_len;
284  bool rx_stream;
285  bool tx_stream;
286  bool rx_filter;
288  unsigned int mem_blocks;
289  unsigned int mem_block_size;
290  unsigned int rx_size;
291  unsigned int tx_seq_table;
292  bool ba_filter;
293  } fw;
294 
295  /* interface configuration combinations */
298 
299  /* reset / stuck frames/queue detection */
302  unsigned int restart_counter;
308 
309  /* interface mode settings */
311  unsigned long vif_bitmap;
312  unsigned int vifs;
314 
315  /* beaconing */
317  unsigned int global_pretbtt;
318  unsigned int global_beacon_int;
320  unsigned int beacon_enabled;
321 
322  /* cryptographic engine */
326 
327  /* filter settings */
330  unsigned int filter_state;
331  unsigned int rx_filter_caps;
333 
334  /* MAC */
336 
337  /* PHY */
339  unsigned int num_channels;
340  int noise[4];
341  unsigned int chan_fail;
342  unsigned int total_chan_fail;
345  struct {
346  u64 active; /* usec */
347  u64 cca; /* usec */
348  u64 tx_time; /* usec */
351  } tally;
354 
355  /* power calibration data */
363 
364 #ifdef CONFIG_CARL9170_LEDS
365  /* LED */
366  struct delayed_work led_work;
367  struct carl9170_led leds[AR9170_NUM_LEDS];
368 #endif /* CONFIG_CARL9170_LEDS */
369 
370  /* qos queue settings */
375 
376  /* CMD */
377  int cmd_seq;
378  int readlen;
382  union {
386  };
387 
388  /* statistics */
389  unsigned int tx_dropped;
390  unsigned int tx_ack_failures;
391  unsigned int tx_fcs_errors;
392  unsigned int rx_dropped;
393 
394  /* EEPROM */
396 
397  /* tx queuing */
401  unsigned long tx_janitor_last_run;
403 
404  /* tx ampdu */
413  unsigned int tx_ampdu_list_len;
417 
418  /* internal memory management */
420  unsigned long *mem_bitmap;
423 
424  /* rxstream mpdu merge */
430 
431  /* FIFO for collecting outstanding BlockAckRequest */
434 
435 #ifdef CONFIG_CARL9170_WPC
436  struct {
437  bool pbc_state;
438  struct input_dev *pbc;
439  char name[32];
440  char phys[32];
441  } wps;
442 #endif /* CONFIG_CARL9170_WPC */
443 
444 #ifdef CONFIG_CARL9170_DEBUGFS
445  struct carl9170_debug debug;
446  struct dentry *debug_dir;
447 #endif /* CONFIG_CARL9170_DEBUGFS */
448 
449  /* PSM */
451  struct {
452  unsigned int dtim_counter;
453  unsigned long last_beacon;
454  unsigned long last_action;
455  unsigned long last_slept;
456  unsigned int sleep_ms;
457  unsigned int off_override;
458  bool state;
459  } ps;
460 
461 #ifdef CONFIG_CARL9170_HWRNG
462 # define CARL9170_HWRNG_CACHE_SIZE CARL9170_MAX_CMD_PAYLOAD_LEN
463  struct {
464  struct hwrng rng;
465  bool initialized;
466  char name[30 + 1];
467  u16 cache[CARL9170_HWRNG_CACHE_SIZE / sizeof(u16)];
468  unsigned int cache_idx;
469  } rng;
470 #endif /* CONFIG_CARL9170_HWRNG */
471 };
472 
476 };
477 
479  struct list_head list;
480  struct rcu_head head;
481  struct sk_buff *skb;
482 };
483 
487  bool clear;
488  bool req;
489 };
490 
492  bool ht_sta;
493  bool sleeping;
495  unsigned int ampdu_max_len;
498 };
499 
501  unsigned long timeout;
502  struct ar9170 *ar;
503  struct kref ref;
504 };
505 
506 #define CHK_DEV_STATE(a, s) (((struct ar9170 *)a)->state >= (s))
507 #define IS_INITIALIZED(a) (CHK_DEV_STATE(a, CARL9170_STOPPED))
508 #define IS_ACCEPTING_CMD(a) (CHK_DEV_STATE(a, CARL9170_IDLE))
509 #define IS_STARTED(a) (CHK_DEV_STATE(a, CARL9170_STARTED))
510 
511 static inline void __carl9170_set_state(struct ar9170 *ar,
512  enum carl9170_device_state newstate)
513 {
514  ar->state = newstate;
515 }
516 
517 static inline void carl9170_set_state(struct ar9170 *ar,
518  enum carl9170_device_state newstate)
519 {
520  unsigned long flags;
521 
522  spin_lock_irqsave(&ar->state_lock, flags);
523  __carl9170_set_state(ar, newstate);
524  spin_unlock_irqrestore(&ar->state_lock, flags);
525 }
526 
527 static inline void carl9170_set_state_when(struct ar9170 *ar,
528  enum carl9170_device_state min, enum carl9170_device_state newstate)
529 {
530  unsigned long flags;
531 
532  spin_lock_irqsave(&ar->state_lock, flags);
533  if (CHK_DEV_STATE(ar, min))
534  __carl9170_set_state(ar, newstate);
535  spin_unlock_irqrestore(&ar->state_lock, flags);
536 }
537 
538 /* exported interface */
539 void *carl9170_alloc(size_t priv_size);
540 int carl9170_register(struct ar9170 *ar);
541 void carl9170_unregister(struct ar9170 *ar);
542 void carl9170_free(struct ar9170 *ar);
543 void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
544 void carl9170_ps_check(struct ar9170 *ar);
545 
546 /* USB back-end */
547 int carl9170_usb_open(struct ar9170 *ar);
548 void carl9170_usb_stop(struct ar9170 *ar);
549 void carl9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb);
550 void carl9170_usb_handle_tx_err(struct ar9170 *ar);
551 int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids,
552  u32 plen, void *payload, u32 rlen, void *resp);
553 int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
554  const bool free_buf);
555 int carl9170_usb_restart(struct ar9170 *ar);
556 void carl9170_usb_reset(struct ar9170 *ar);
557 
558 /* MAC */
559 int carl9170_init_mac(struct ar9170 *ar);
560 int carl9170_set_qos(struct ar9170 *ar);
561 int carl9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
562 int carl9170_mod_virtual_mac(struct ar9170 *ar, const unsigned int id,
563  const u8 *mac);
564 int carl9170_set_operating_mode(struct ar9170 *ar);
565 int carl9170_set_beacon_timers(struct ar9170 *ar);
566 int carl9170_set_dyn_sifs_ack(struct ar9170 *ar);
567 int carl9170_set_rts_cts_rate(struct ar9170 *ar);
568 int carl9170_set_ampdu_settings(struct ar9170 *ar);
569 int carl9170_set_slot_time(struct ar9170 *ar);
570 int carl9170_set_mac_rates(struct ar9170 *ar);
571 int carl9170_set_hwretry_limit(struct ar9170 *ar, const u32 max_retry);
572 int carl9170_upload_key(struct ar9170 *ar, const u8 id, const u8 *mac,
573  const u8 ktype, const u8 keyidx, const u8 *keydata, const int keylen);
574 int carl9170_disable_key(struct ar9170 *ar, const u8 id);
575 int carl9170_set_mac_tpc(struct ar9170 *ar, struct ieee80211_channel *channel);
576 
577 /* RX */
578 void carl9170_rx(struct ar9170 *ar, void *buf, unsigned int len);
579 void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
580 
581 /* TX */
582 void carl9170_op_tx(struct ieee80211_hw *hw,
584  struct sk_buff *skb);
585 void carl9170_tx_janitor(struct work_struct *work);
586 void carl9170_tx_process_status(struct ar9170 *ar,
587  const struct carl9170_rsp *cmd);
588 void carl9170_tx_status(struct ar9170 *ar, struct sk_buff *skb,
589  const bool success);
590 void carl9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
591 void carl9170_tx_drop(struct ar9170 *ar, struct sk_buff *skb);
592 void carl9170_tx_scheduler(struct ar9170 *ar);
593 void carl9170_tx_get_skb(struct sk_buff *skb);
594 int carl9170_tx_put_skb(struct sk_buff *skb);
595 int carl9170_update_beacon(struct ar9170 *ar, const bool submit);
596 
597 /* LEDs */
598 #ifdef CONFIG_CARL9170_LEDS
599 int carl9170_led_register(struct ar9170 *ar);
600 void carl9170_led_unregister(struct ar9170 *ar);
601 #endif /* CONFIG_CARL9170_LEDS */
602 int carl9170_led_init(struct ar9170 *ar);
603 int carl9170_led_set_state(struct ar9170 *ar, const u32 led_state);
604 
605 /* PHY / RF */
606 int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
607  enum nl80211_channel_type bw, enum carl9170_rf_init_mode rfi);
608 int carl9170_get_noisefloor(struct ar9170 *ar);
609 
610 /* FW */
611 int carl9170_parse_firmware(struct ar9170 *ar);
612 
613 extern struct ieee80211_rate __carl9170_ratetable[];
614 extern int modparam_noht;
615 
616 static inline struct ar9170 *carl9170_get_priv(struct carl9170_vif *carl_vif)
617 {
618  return container_of(carl_vif, struct ar9170,
619  vif_priv[carl_vif->id]);
620 }
621 
622 static inline struct ieee80211_hdr *carl9170_get_hdr(struct sk_buff *skb)
623 {
624  return (void *)((struct _carl9170_tx_superframe *)
625  skb->data)->frame_data;
626 }
627 
628 static inline u16 get_seq_h(struct ieee80211_hdr *hdr)
629 {
630  return le16_to_cpu(hdr->seq_ctrl) >> 4;
631 }
632 
633 static inline u16 carl9170_get_seq(struct sk_buff *skb)
634 {
635  return get_seq_h(carl9170_get_hdr(skb));
636 }
637 
638 static inline u16 get_tid_h(struct ieee80211_hdr *hdr)
639 {
640  return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
641 }
642 
643 static inline u16 carl9170_get_tid(struct sk_buff *skb)
644 {
645  return get_tid_h(carl9170_get_hdr(skb));
646 }
647 
648 static inline struct ieee80211_vif *
649 carl9170_get_vif(struct carl9170_vif_info *priv)
650 {
651  return container_of((void *)priv, struct ieee80211_vif, drv_priv);
652 }
653 
654 /* Protected by ar->mutex or RCU */
655 static inline struct ieee80211_vif *carl9170_get_main_vif(struct ar9170 *ar)
656 {
657  struct carl9170_vif_info *cvif;
658 
659  list_for_each_entry_rcu(cvif, &ar->vif_list, list) {
660  if (cvif->active)
661  return carl9170_get_vif(cvif);
662  }
663 
664  return NULL;
665 }
666 
667 static inline bool is_main_vif(struct ar9170 *ar, struct ieee80211_vif *vif)
668 {
669  bool ret;
670 
671  rcu_read_lock();
672  ret = (carl9170_get_main_vif(ar) == vif);
673  rcu_read_unlock();
674  return ret;
675 }
676 
677 #endif /* __CARL9170_H */