2 * Atheros AR9170 driver
4 * mac80211 interaction code
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, Christian Lamparter <chunkeey@web.de>
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.
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.
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/.
23 * This file incorporates work covered by the following copyright and
25 * Copyright (c) 2007-2008 Atheros Communications, Inc.
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.
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.
43 * By the looks of things: these devices share a lot of things like
44 * EEPROM layout/design and PHY code with other Atheros WIFI products.
45 * So this driver/library will eventually become ath9k code... or vice versa ;-)
48 #include <linux/init.h>
49 #include <linux/module.h>
50 #include <linux/etherdevice.h>
51 #include <net/mac80211.h>
56 static int modparam_nohwcrypt
;
57 module_param_named(nohwcrypt
, modparam_nohwcrypt
, bool, S_IRUGO
);
58 MODULE_PARM_DESC(nohwcrypt
, "Disable hardware encryption.");
59 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
60 MODULE_LICENSE("GPL");
61 MODULE_DESCRIPTION("Atheros shared code for AR9170 wireless devices");
63 #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \
64 .bitrate = (_bitrate), \
66 .hw_value = (_hw_rate) | (_txpidx) << 4, \
69 static struct ieee80211_rate __ar9170_ratetable
[] = {
71 RATE(20, 1, 1, IEEE80211_RATE_SHORT_PREAMBLE
),
72 RATE(55, 2, 2, IEEE80211_RATE_SHORT_PREAMBLE
),
73 RATE(110, 3, 3, IEEE80211_RATE_SHORT_PREAMBLE
),
85 #define ar9170_g_ratetable (__ar9170_ratetable + 0)
86 #define ar9170_g_ratetable_size 12
87 #define ar9170_a_ratetable (__ar9170_ratetable + 4)
88 #define ar9170_a_ratetable_size 8
91 * NB: The hw_value is used as an index into the ar9170_phy_freq_params
92 * array in phy.c so that we don't have to do frequency lookups!
94 #define CHAN(_freq, _idx) { \
95 .center_freq = (_freq), \
97 .max_power = 18, /* XXX */ \
100 static struct ieee80211_channel ar9170_2ghz_chantable
[] = {
117 static struct ieee80211_channel ar9170_5ghz_chantable
[] = {
156 static struct ieee80211_supported_band ar9170_band_2GHz
= {
157 .channels
= ar9170_2ghz_chantable
,
158 .n_channels
= ARRAY_SIZE(ar9170_2ghz_chantable
),
159 .bitrates
= ar9170_g_ratetable
,
160 .n_bitrates
= ar9170_g_ratetable_size
,
163 #ifdef AR9170_QUEUE_DEBUG
165 * In case some wants works with AR9170's crazy tx_status queueing techniques.
166 * He might need this rather useful probing function.
168 * NOTE: caller must hold the queue's spinlock!
171 static void ar9170_print_txheader(struct ar9170
*ar
, struct sk_buff
*skb
)
173 struct ar9170_tx_control
*txc
= (void *) skb
->data
;
174 struct ieee80211_hdr
*hdr
= (void *)txc
->frame_data
;
176 printk(KERN_DEBUG
"%s: => FRAME [skb:%p, queue:%d, DA:[%pM] "
177 "mac_control:%04x, phy_control:%08x]\n",
178 wiphy_name(ar
->hw
->wiphy
), skb
, skb_get_queue_mapping(skb
),
179 ieee80211_get_DA(hdr
), le16_to_cpu(txc
->mac_control
),
180 le32_to_cpu(txc
->phy_control
));
183 static void ar9170_dump_station_tx_status_queue(struct ar9170
*ar
,
184 struct sk_buff_head
*queue
)
189 printk(KERN_DEBUG
"---[ cut here ]---\n");
190 printk(KERN_DEBUG
"%s: %d entries in tx_status queue.\n",
191 wiphy_name(ar
->hw
->wiphy
), skb_queue_len(queue
));
193 skb_queue_walk(queue
, skb
) {
194 struct ar9170_tx_control
*txc
= (void *) skb
->data
;
195 struct ieee80211_hdr
*hdr
= (void *)txc
->frame_data
;
197 printk(KERN_DEBUG
"index:%d => \n", i
);
198 ar9170_print_txheader(ar
, skb
);
200 printk(KERN_DEBUG
"---[ end ]---\n");
202 #endif /* AR9170_QUEUE_DEBUG */
204 static struct ieee80211_supported_band ar9170_band_5GHz
= {
205 .channels
= ar9170_5ghz_chantable
,
206 .n_channels
= ARRAY_SIZE(ar9170_5ghz_chantable
),
207 .bitrates
= ar9170_a_ratetable
,
208 .n_bitrates
= ar9170_a_ratetable_size
,
211 void ar9170_handle_tx_status(struct ar9170
*ar
, struct sk_buff
*skb
,
212 bool valid_status
, u16 tx_status
)
214 struct ieee80211_tx_info
*txinfo
;
215 unsigned int retries
= 0, queue
= skb_get_queue_mapping(skb
);
218 spin_lock_irqsave(&ar
->tx_stats_lock
, flags
);
219 ar
->tx_stats
[queue
].len
--;
220 if (ieee80211_queue_stopped(ar
->hw
, queue
))
221 ieee80211_wake_queue(ar
->hw
, queue
);
222 spin_unlock_irqrestore(&ar
->tx_stats_lock
, flags
);
224 txinfo
= IEEE80211_SKB_CB(skb
);
225 ieee80211_tx_info_clear_status(txinfo
);
228 case AR9170_TX_STATUS_RETRY
:
230 case AR9170_TX_STATUS_COMPLETE
:
231 txinfo
->flags
|= IEEE80211_TX_STAT_ACK
;
234 case AR9170_TX_STATUS_FAILED
:
235 retries
= ar
->hw
->conf
.long_frame_max_tx_count
;
239 printk(KERN_ERR
"%s: invalid tx_status response (%x).\n",
240 wiphy_name(ar
->hw
->wiphy
), tx_status
);
245 txinfo
->status
.rates
[0].count
= retries
+ 1;
247 skb_pull(skb
, sizeof(struct ar9170_tx_control
));
248 ieee80211_tx_status_irqsafe(ar
->hw
, skb
);
250 EXPORT_SYMBOL_GPL(ar9170_handle_tx_status
);
252 static struct sk_buff
*ar9170_find_skb_in_queue(struct ar9170
*ar
,
255 struct sk_buff_head
*q
)
260 spin_lock_irqsave(&q
->lock
, flags
);
261 skb_queue_walk(q
, skb
) {
262 struct ar9170_tx_control
*txc
= (void *) skb
->data
;
263 struct ieee80211_hdr
*hdr
= (void *) txc
->frame_data
;
264 u32 txc_queue
= (le32_to_cpu(txc
->phy_control
) &
265 AR9170_TX_PHY_QOS_MASK
) >>
266 AR9170_TX_PHY_QOS_SHIFT
;
268 if ((queue
!= txc_queue
) ||
269 (compare_ether_addr(ieee80211_get_DA(hdr
), mac
)))
272 __skb_unlink(skb
, q
);
273 spin_unlock_irqrestore(&q
->lock
, flags
);
276 spin_unlock_irqrestore(&q
->lock
, flags
);
280 static struct sk_buff
*ar9170_find_queued_skb(struct ar9170
*ar
, const u8
*mac
,
283 struct ieee80211_sta
*sta
;
287 * Unfortunately, the firmware does not tell to which (queued) frame
288 * this transmission status report belongs to.
290 * So we have to make risky guesses - with the scarce information
291 * the firmware provided (-> destination MAC, and phy_control) -
292 * and hope that we picked the right one...
295 sta
= ieee80211_find_sta(ar
->hw
, mac
);
298 struct ar9170_sta_info
*sta_priv
= (void *) sta
->drv_priv
;
299 skb
= skb_dequeue(&sta_priv
->tx_status
[queue
]);
306 /* scan the waste queue for candidates */
307 skb
= ar9170_find_skb_in_queue(ar
, mac
, queue
,
308 &ar
->global_tx_status_waste
);
310 /* so it still _must_ be in the global list. */
311 skb
= ar9170_find_skb_in_queue(ar
, mac
, queue
,
312 &ar
->global_tx_status
);
315 #ifdef AR9170_QUEUE_DEBUG
316 if (unlikely((!skb
) && net_ratelimit())) {
317 printk(KERN_ERR
"%s: ESS:[%pM] does not have any "
318 "outstanding frames in this queue (%d).\n",
319 wiphy_name(ar
->hw
->wiphy
), mac
, queue
);
321 #endif /* AR9170_QUEUE_DEBUG */
326 * This worker tries to keep the global tx_status queue empty.
327 * So we can guarantee that incoming tx_status reports for
328 * unregistered stations are always synced with the actual
329 * frame - which we think - belongs to.
332 static void ar9170_tx_status_janitor(struct work_struct
*work
)
334 struct ar9170
*ar
= container_of(work
, struct ar9170
,
335 tx_status_janitor
.work
);
338 if (unlikely(!IS_STARTED(ar
)))
341 mutex_lock(&ar
->mutex
);
342 /* recycle the garbage back to mac80211... one by one. */
343 while ((skb
= skb_dequeue(&ar
->global_tx_status_waste
))) {
344 #ifdef AR9170_QUEUE_DEBUG
345 printk(KERN_DEBUG
"%s: dispose queued frame =>\n",
346 wiphy_name(ar
->hw
->wiphy
));
347 ar9170_print_txheader(ar
, skb
);
348 #endif /* AR9170_QUEUE_DEBUG */
349 ar9170_handle_tx_status(ar
, skb
, false,
350 AR9170_TX_STATUS_FAILED
);
353 while ((skb
= skb_dequeue(&ar
->global_tx_status
))) {
354 #ifdef AR9170_QUEUE_DEBUG
355 printk(KERN_DEBUG
"%s: moving frame into waste queue =>\n",
356 wiphy_name(ar
->hw
->wiphy
));
358 ar9170_print_txheader(ar
, skb
);
359 #endif /* AR9170_QUEUE_DEBUG */
360 skb_queue_tail(&ar
->global_tx_status_waste
, skb
);
363 /* recall the janitor in 100ms - if there's garbage in the can. */
364 if (skb_queue_len(&ar
->global_tx_status_waste
) > 0)
365 queue_delayed_work(ar
->hw
->workqueue
, &ar
->tx_status_janitor
,
366 msecs_to_jiffies(100));
368 mutex_unlock(&ar
->mutex
);
371 static void ar9170_handle_command_response(struct ar9170
*ar
,
374 struct ar9170_cmd_response
*cmd
= (void *) buf
;
376 if ((cmd
->type
& 0xc0) != 0xc0) {
377 ar
->callback_cmd(ar
, len
, buf
);
381 /* hardware event handlers */
385 * TX status notification:
386 * bytes: 0c c1 XX YY M1 M2 M3 M4 M5 M6 R4 R3 R2 R1 S2 S1
390 * M1-M6 is the MAC address
391 * R1-R4 is the transmit rate
392 * S1-S2 is the transmit status
396 u32 queue
= (le32_to_cpu(cmd
->tx_status
.rate
) &
397 AR9170_TX_PHY_QOS_MASK
) >> AR9170_TX_PHY_QOS_SHIFT
;
399 skb
= ar9170_find_queued_skb(ar
, cmd
->tx_status
.dst
, queue
);
403 ar9170_handle_tx_status(ar
, skb
, true,
404 le16_to_cpu(cmd
->tx_status
.status
));
412 if (ar
->vif
&& ar
->vif
->type
== NL80211_IFTYPE_AP
)
413 queue_work(ar
->hw
->workqueue
, &ar
->beacon_work
);
418 * (IBSS) beacon send notification
419 * bytes: 04 c2 XX YY B4 B3 B2 B1
423 * B1-B4 "should" be the number of send out beacons.
428 /* End of Atim Window */
433 /* BlockACK events */
437 /* Watchdog Interrupt */
441 /* retransmission issue / SIFS/EIFS collision ?! */
445 printk(KERN_INFO
"received unhandled event %x\n", cmd
->type
);
446 print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE
, buf
, len
);
452 * If the frame alignment is right (or the kernel has
453 * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there
454 * is only a single MPDU in the USB frame, then we can
455 * submit to mac80211 the SKB directly. However, since
456 * there may be multiple packets in one SKB in stream
457 * mode, and we need to observe the proper ordering,
458 * this is non-trivial.
460 static void ar9170_handle_mpdu(struct ar9170
*ar
, u8
*buf
, int len
)
463 struct ar9170_rx_head
*head
= (void *)buf
;
464 struct ar9170_rx_tail
*tail
;
465 struct ieee80211_rx_status status
;
467 u8 error
, antennas
= 0, decrypt
;
471 if (unlikely(!IS_STARTED(ar
)))
476 mpdu_len
-= sizeof(struct ar9170_rx_head
);
477 mpdu_len
-= sizeof(struct ar9170_rx_tail
);
478 BUILD_BUG_ON(sizeof(struct ar9170_rx_head
) != 12);
479 BUILD_BUG_ON(sizeof(struct ar9170_rx_tail
) != 24);
481 if (mpdu_len
<= FCS_LEN
)
484 tail
= (void *)(buf
+ sizeof(struct ar9170_rx_head
) + mpdu_len
);
486 for (i
= 0; i
< 3; i
++)
487 if (tail
->rssi
[i
] != 0x80)
490 /* post-process RSSI */
491 for (i
= 0; i
< 7; i
++)
492 if (tail
->rssi
[i
] & 0x80)
493 tail
->rssi
[i
] = ((tail
->rssi
[i
] & 0x7f) + 1) & 0x7f;
495 memset(&status
, 0, sizeof(status
));
497 status
.band
= ar
->channel
->band
;
498 status
.freq
= ar
->channel
->center_freq
;
499 status
.signal
= ar
->noise
[0] + tail
->rssi_combined
;
500 status
.noise
= ar
->noise
[0];
501 status
.antenna
= antennas
;
503 switch (tail
->status
& AR9170_RX_STATUS_MODULATION_MASK
) {
504 case AR9170_RX_STATUS_MODULATION_CCK
:
505 if (tail
->status
& AR9170_RX_STATUS_SHORT_PREAMBLE
)
506 status
.flag
|= RX_FLAG_SHORTPRE
;
507 switch (head
->plcp
[0]) {
521 if ((!ar
->sniffer_enabled
) && (net_ratelimit()))
522 printk(KERN_ERR
"%s: invalid plcp cck rate "
523 "(%x).\n", wiphy_name(ar
->hw
->wiphy
),
528 case AR9170_RX_STATUS_MODULATION_OFDM
:
529 switch (head
->plcp
[0] & 0xF) {
555 if ((!ar
->sniffer_enabled
) && (net_ratelimit()))
556 printk(KERN_ERR
"%s: invalid plcp ofdm rate "
557 "(%x).\n", wiphy_name(ar
->hw
->wiphy
),
561 if (status
.band
== IEEE80211_BAND_2GHZ
)
562 status
.rate_idx
+= 4;
564 case AR9170_RX_STATUS_MODULATION_HT
:
565 case AR9170_RX_STATUS_MODULATION_DUPOFDM
:
569 printk(KERN_ERR
"%s: invalid modulation\n",
570 wiphy_name(ar
->hw
->wiphy
));
576 if (error
& AR9170_RX_ERROR_MMIC
) {
577 status
.flag
|= RX_FLAG_MMIC_ERROR
;
578 error
&= ~AR9170_RX_ERROR_MMIC
;
581 if (error
& AR9170_RX_ERROR_PLCP
) {
582 status
.flag
|= RX_FLAG_FAILED_PLCP_CRC
;
583 error
&= ~AR9170_RX_ERROR_PLCP
;
586 if (error
& AR9170_RX_ERROR_FCS
) {
587 status
.flag
|= RX_FLAG_FAILED_FCS_CRC
;
588 error
&= ~AR9170_RX_ERROR_FCS
;
591 decrypt
= ar9170_get_decrypt_type(tail
);
592 if (!(decrypt
& AR9170_RX_ENC_SOFTWARE
) &&
593 decrypt
!= AR9170_ENC_ALG_NONE
)
594 status
.flag
|= RX_FLAG_DECRYPTED
;
596 /* ignore wrong RA errors */
597 error
&= ~AR9170_RX_ERROR_WRONG_RA
;
599 if (error
& AR9170_RX_ERROR_DECRYPT
) {
600 error
&= ~AR9170_RX_ERROR_DECRYPT
;
603 * Rx decryption is done in place,
604 * the original data is lost anyway.
609 /* drop any other error frames */
610 if ((error
) && (net_ratelimit())) {
611 printk(KERN_DEBUG
"%s: errors: %#x\n",
612 wiphy_name(ar
->hw
->wiphy
), error
);
616 buf
+= sizeof(struct ar9170_rx_head
);
619 if (ieee80211_is_data_qos(fc
) ^ ieee80211_has_a4(fc
))
624 skb
= dev_alloc_skb(mpdu_len
+ reserved
);
628 skb_reserve(skb
, reserved
);
629 memcpy(skb_put(skb
, mpdu_len
), buf
, mpdu_len
);
630 ieee80211_rx_irqsafe(ar
->hw
, skb
, &status
);
635 * It looks like AR9170 supports more than just the USB transport interface.
636 * Unfortunately, there is no available information what parts of the
637 * precendent and following code fragments is device specific and what not.
638 * For now, everything stays here, until some SPI chips pop up.
640 void ar9170_rx(struct ar9170
*ar
, struct sk_buff
*skb
)
642 unsigned int i
, tlen
, resplen
;
649 int clen
= tbuf
[1] << 8 | tbuf
[0];
650 int wlen
= (clen
+ 3) & ~3;
653 * parse stream (if any)
655 if (tbuf
[2] != 0 || tbuf
[3] != 0x4e) {
656 printk(KERN_ERR
"%s: missing tag!\n",
657 wiphy_name(ar
->hw
->wiphy
));
660 if (wlen
> tlen
- 4) {
661 printk(KERN_ERR
"%s: invalid RX (%d, %d, %d)\n",
662 wiphy_name(ar
->hw
->wiphy
), clen
, wlen
, tlen
);
663 print_hex_dump(KERN_DEBUG
, "data: ",
665 16, 1, tbuf
, tlen
, true);
675 /* weird thing, but this is the same in the original driver */
676 while (resplen
> 2 && i
< 12 &&
677 respbuf
[0] == 0xff && respbuf
[1] == 0xff) {
686 /* found the 6 * 0xffff marker? */
688 ar9170_handle_command_response(ar
, respbuf
, resplen
);
690 ar9170_handle_mpdu(ar
, respbuf
, resplen
);
694 printk(KERN_ERR
"%s: buffer remains!\n",
695 wiphy_name(ar
->hw
->wiphy
));
697 EXPORT_SYMBOL_GPL(ar9170_rx
);
699 #define AR9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \
701 queue.aifs = ai_fs; \
702 queue.cw_min = cwmin; \
703 queue.cw_max = cwmax; \
704 queue.txop = _txop; \
707 static int ar9170_op_start(struct ieee80211_hw
*hw
)
709 struct ar9170
*ar
= hw
->priv
;
712 mutex_lock(&ar
->mutex
);
714 /* reinitialize queues statistics */
715 memset(&ar
->tx_stats
, 0, sizeof(ar
->tx_stats
));
716 for (i
= 0; i
< ARRAY_SIZE(ar
->tx_stats
); i
++)
717 ar
->tx_stats
[i
].limit
= 8;
719 /* reset QoS defaults */
720 AR9170_FILL_QUEUE(ar
->edcf
[0], 3, 15, 1023, 0); /* BEST EFFORT*/
721 AR9170_FILL_QUEUE(ar
->edcf
[1], 7, 15, 1023, 0); /* BACKGROUND */
722 AR9170_FILL_QUEUE(ar
->edcf
[2], 2, 7, 15, 94); /* VIDEO */
723 AR9170_FILL_QUEUE(ar
->edcf
[3], 2, 3, 7, 47); /* VOICE */
724 AR9170_FILL_QUEUE(ar
->edcf
[4], 2, 3, 7, 0); /* SPECIAL */
730 err
= ar9170_init_mac(ar
);
734 err
= ar9170_set_qos(ar
);
738 err
= ar9170_init_phy(ar
, IEEE80211_BAND_2GHZ
);
742 err
= ar9170_init_rf(ar
);
747 err
= ar9170_write_reg(ar
, 0x1c3d30, 0x100);
751 ar
->state
= AR9170_STARTED
;
754 mutex_unlock(&ar
->mutex
);
758 static void ar9170_op_stop(struct ieee80211_hw
*hw
)
760 struct ar9170
*ar
= hw
->priv
;
763 ar
->state
= AR9170_IDLE
;
765 mutex_lock(&ar
->mutex
);
767 cancel_delayed_work_sync(&ar
->tx_status_janitor
);
768 cancel_work_sync(&ar
->filter_config_work
);
769 cancel_work_sync(&ar
->beacon_work
);
770 skb_queue_purge(&ar
->global_tx_status_waste
);
771 skb_queue_purge(&ar
->global_tx_status
);
773 if (IS_ACCEPTING_CMD(ar
)) {
774 ar9170_set_leds_state(ar
, 0);
777 ar9170_write_reg(ar
, 0x1c3d30, 0);
781 mutex_unlock(&ar
->mutex
);
784 int ar9170_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
786 struct ar9170
*ar
= hw
->priv
;
787 struct ieee80211_hdr
*hdr
;
788 struct ar9170_tx_control
*txc
;
789 struct ieee80211_tx_info
*info
;
790 struct ieee80211_rate
*rate
= NULL
;
791 struct ieee80211_tx_rate
*txrate
;
792 unsigned int queue
= skb_get_queue_mapping(skb
);
793 unsigned long flags
= 0;
794 struct ar9170_sta_info
*sta_info
= NULL
;
801 if (unlikely(!IS_STARTED(ar
)))
804 hdr
= (void *)skb
->data
;
805 info
= IEEE80211_SKB_CB(skb
);
808 spin_lock_irqsave(&ar
->tx_stats_lock
, flags
);
809 if (ar
->tx_stats
[queue
].limit
< ar
->tx_stats
[queue
].len
) {
810 spin_unlock_irqrestore(&ar
->tx_stats_lock
, flags
);
814 ar
->tx_stats
[queue
].len
++;
815 ar
->tx_stats
[queue
].count
++;
816 if (ar
->tx_stats
[queue
].limit
== ar
->tx_stats
[queue
].len
)
817 ieee80211_stop_queue(hw
, queue
);
819 spin_unlock_irqrestore(&ar
->tx_stats_lock
, flags
);
821 txc
= (void *)skb_push(skb
, sizeof(*txc
));
823 tx_status
= (((info
->flags
& IEEE80211_TX_CTL_RATE_CTRL_PROBE
) != 0) ||
824 ((info
->flags
& IEEE80211_TX_CTL_REQ_TX_STATUS
) != 0));
826 if (info
->control
.hw_key
) {
827 icv
= info
->control
.hw_key
->icv_len
;
829 switch (info
->control
.hw_key
->alg
) {
831 keytype
= AR9170_TX_MAC_ENCR_RC4
;
834 keytype
= AR9170_TX_MAC_ENCR_RC4
;
837 keytype
= AR9170_TX_MAC_ENCR_AES
;
846 txc
->length
= cpu_to_le16(len
+ icv
+ 4);
848 txc
->mac_control
= cpu_to_le16(AR9170_TX_MAC_HW_DURATION
|
849 AR9170_TX_MAC_BACKOFF
);
850 txc
->mac_control
|= cpu_to_le16(ar9170_qos_hwmap
[queue
] <<
851 AR9170_TX_MAC_QOS_SHIFT
);
852 txc
->mac_control
|= cpu_to_le16(keytype
);
853 txc
->phy_control
= cpu_to_le32(0);
855 if (info
->flags
& IEEE80211_TX_CTL_NO_ACK
)
856 txc
->mac_control
|= cpu_to_le16(AR9170_TX_MAC_NO_ACK
);
858 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
)
859 txc
->mac_control
|= cpu_to_le16(AR9170_TX_MAC_AGGR
);
861 txrate
= &info
->control
.rates
[0];
863 if (txrate
->flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
)
864 txc
->mac_control
|= cpu_to_le16(AR9170_TX_MAC_PROT_CTS
);
865 else if (txrate
->flags
& IEEE80211_TX_RC_USE_RTS_CTS
)
866 txc
->mac_control
|= cpu_to_le16(AR9170_TX_MAC_PROT_RTS
);
868 if (txrate
->flags
& IEEE80211_TX_RC_GREEN_FIELD
)
869 txc
->phy_control
|= cpu_to_le32(AR9170_TX_PHY_GREENFIELD
);
871 if (txrate
->flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
872 txc
->phy_control
|= cpu_to_le32(AR9170_TX_PHY_SHORT_PREAMBLE
);
874 if (txrate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
875 txc
->phy_control
|= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ
);
876 /* this works because 40 MHz is 2 and dup is 3 */
877 if (txrate
->flags
& IEEE80211_TX_RC_DUP_DATA
)
878 txc
->phy_control
|= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ_DUP
);
880 if (txrate
->flags
& IEEE80211_TX_RC_SHORT_GI
)
881 txc
->phy_control
|= cpu_to_le32(AR9170_TX_PHY_SHORT_GI
);
883 if (txrate
->flags
& IEEE80211_TX_RC_MCS
) {
887 r
<<= AR9170_TX_PHY_MCS_SHIFT
;
888 if (WARN_ON(r
& ~AR9170_TX_PHY_MCS_MASK
))
890 txc
->phy_control
|= cpu_to_le32(r
& AR9170_TX_PHY_MCS_MASK
);
891 txc
->phy_control
|= cpu_to_le32(AR9170_TX_PHY_MOD_HT
);
893 if (txrate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
) {
894 if (info
->band
== IEEE80211_BAND_5GHZ
)
895 txpower
= ar
->power_5G_ht40
;
897 txpower
= ar
->power_2G_ht40
;
899 if (info
->band
== IEEE80211_BAND_5GHZ
)
900 txpower
= ar
->power_5G_ht20
;
902 txpower
= ar
->power_2G_ht20
;
905 power
= txpower
[(txrate
->idx
) & 7];
910 u8 idx
= txrate
->idx
;
912 if (info
->band
!= IEEE80211_BAND_2GHZ
) {
914 txpower
= ar
->power_5G_leg
;
915 mod
= AR9170_TX_PHY_MOD_OFDM
;
918 txpower
= ar
->power_2G_cck
;
919 mod
= AR9170_TX_PHY_MOD_CCK
;
921 mod
= AR9170_TX_PHY_MOD_OFDM
;
922 txpower
= ar
->power_2G_ofdm
;
926 rate
= &__ar9170_ratetable
[idx
];
928 phyrate
= rate
->hw_value
& 0xF;
929 power
= txpower
[(rate
->hw_value
& 0x30) >> 4];
930 phyrate
<<= AR9170_TX_PHY_MCS_SHIFT
;
932 txc
->phy_control
|= cpu_to_le32(mod
);
933 txc
->phy_control
|= cpu_to_le32(phyrate
);
936 power
<<= AR9170_TX_PHY_TX_PWR_SHIFT
;
937 power
&= AR9170_TX_PHY_TX_PWR_MASK
;
938 txc
->phy_control
|= cpu_to_le32(power
);
941 if (ar
->eeprom
.tx_mask
== 1) {
942 chains
= AR9170_TX_PHY_TXCHAIN_1
;
944 chains
= AR9170_TX_PHY_TXCHAIN_2
;
946 /* >= 36M legacy OFDM - use only one chain */
947 if (rate
&& rate
->bitrate
>= 360)
948 chains
= AR9170_TX_PHY_TXCHAIN_1
;
950 txc
->phy_control
|= cpu_to_le32(chains
<< AR9170_TX_PHY_TXCHAIN_SHIFT
);
953 txc
->mac_control
|= cpu_to_le16(AR9170_TX_MAC_RATE_PROBE
);
956 * Putting the QoS queue bits into an unexplored territory is
957 * certainly not elegant.
959 * In my defense: This idea provides a reasonable way to
960 * smuggle valuable information to the tx_status callback.
961 * Also, the idea behind this bit-abuse came straight from
962 * the original driver code.
966 cpu_to_le32(queue
<< AR9170_TX_PHY_QOS_SHIFT
);
968 if (info
->control
.sta
) {
969 sta_info
= (void *) info
->control
.sta
->drv_priv
;
970 skb_queue_tail(&sta_info
->tx_status
[queue
], skb
);
972 skb_queue_tail(&ar
->global_tx_status
, skb
);
974 queue_delayed_work(ar
->hw
->workqueue
,
975 &ar
->tx_status_janitor
,
976 msecs_to_jiffies(100));
980 err
= ar
->tx(ar
, skb
, tx_status
, 0);
981 if (unlikely(tx_status
&& err
)) {
982 if (info
->control
.sta
)
983 skb_unlink(skb
, &sta_info
->tx_status
[queue
]);
985 skb_unlink(skb
, &ar
->global_tx_status
);
991 spin_lock_irqsave(&ar
->tx_stats_lock
, flags
);
992 ar
->tx_stats
[queue
].len
--;
993 ar
->tx_stats
[queue
].count
--;
994 spin_unlock_irqrestore(&ar
->tx_stats_lock
, flags
);
1001 static int ar9170_op_add_interface(struct ieee80211_hw
*hw
,
1002 struct ieee80211_if_init_conf
*conf
)
1004 struct ar9170
*ar
= hw
->priv
;
1007 mutex_lock(&ar
->mutex
);
1014 ar
->vif
= conf
->vif
;
1015 memcpy(ar
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
1017 if (modparam_nohwcrypt
|| (ar
->vif
->type
!= NL80211_IFTYPE_STATION
)) {
1018 ar
->rx_software_decryption
= true;
1019 ar
->disable_offload
= true;
1023 ar
->want_filter
= AR9170_MAC_REG_FTF_DEFAULTS
;
1024 err
= ar9170_update_frame_filter(ar
);
1028 err
= ar9170_set_operating_mode(ar
);
1031 mutex_unlock(&ar
->mutex
);
1035 static void ar9170_op_remove_interface(struct ieee80211_hw
*hw
,
1036 struct ieee80211_if_init_conf
*conf
)
1038 struct ar9170
*ar
= hw
->priv
;
1040 mutex_lock(&ar
->mutex
);
1042 ar
->want_filter
= 0;
1043 ar9170_update_frame_filter(ar
);
1044 ar9170_set_beacon_timers(ar
);
1045 dev_kfree_skb(ar
->beacon
);
1047 ar
->sniffer_enabled
= false;
1048 ar
->rx_software_decryption
= false;
1049 ar9170_set_operating_mode(ar
);
1050 mutex_unlock(&ar
->mutex
);
1053 static int ar9170_op_config(struct ieee80211_hw
*hw
, u32 changed
)
1055 struct ar9170
*ar
= hw
->priv
;
1058 mutex_lock(&ar
->mutex
);
1060 if (changed
& IEEE80211_CONF_CHANGE_RADIO_ENABLED
) {
1065 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
1070 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1075 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1080 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
1082 * is it long_frame_max_tx_count or short_frame_max_tx_count?
1085 err
= ar9170_set_hwretry_limit(ar
,
1086 ar
->hw
->conf
.long_frame_max_tx_count
);
1091 if (changed
& IEEE80211_CONF_CHANGE_BEACON_INTERVAL
) {
1092 err
= ar9170_set_beacon_timers(ar
);
1097 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1098 err
= ar9170_set_channel(ar
, hw
->conf
.channel
,
1099 AR9170_RFI_NONE
, AR9170_BW_20
);
1102 /* adjust slot time for 5 GHz */
1103 if (hw
->conf
.channel
->band
== IEEE80211_BAND_5GHZ
)
1104 err
= ar9170_write_reg(ar
, AR9170_MAC_REG_SLOT_TIME
,
1109 mutex_unlock(&ar
->mutex
);
1113 static int ar9170_op_config_interface(struct ieee80211_hw
*hw
,
1114 struct ieee80211_vif
*vif
,
1115 struct ieee80211_if_conf
*conf
)
1117 struct ar9170
*ar
= hw
->priv
;
1120 mutex_lock(&ar
->mutex
);
1122 if (conf
->changed
& IEEE80211_IFCC_BSSID
) {
1123 memcpy(ar
->bssid
, conf
->bssid
, ETH_ALEN
);
1124 err
= ar9170_set_operating_mode(ar
);
1127 if (conf
->changed
& IEEE80211_IFCC_BEACON
) {
1128 err
= ar9170_update_beacon(ar
);
1132 err
= ar9170_set_beacon_timers(ar
);
1136 mutex_unlock(&ar
->mutex
);
1140 static void ar9170_set_filters(struct work_struct
*work
)
1142 struct ar9170
*ar
= container_of(work
, struct ar9170
,
1143 filter_config_work
);
1146 mutex_lock(&ar
->mutex
);
1147 if (unlikely(!IS_STARTED(ar
)))
1150 if (ar
->filter_changed
& AR9170_FILTER_CHANGED_PROMISC
) {
1151 err
= ar9170_set_operating_mode(ar
);
1156 if (ar
->filter_changed
& AR9170_FILTER_CHANGED_MULTICAST
) {
1157 err
= ar9170_update_multicast(ar
);
1162 if (ar
->filter_changed
& AR9170_FILTER_CHANGED_FRAMEFILTER
)
1163 err
= ar9170_update_frame_filter(ar
);
1166 mutex_unlock(&ar
->mutex
);
1169 static void ar9170_op_configure_filter(struct ieee80211_hw
*hw
,
1170 unsigned int changed_flags
,
1171 unsigned int *new_flags
,
1172 int mc_count
, struct dev_mc_list
*mclist
)
1174 struct ar9170
*ar
= hw
->priv
;
1176 /* mask supported flags */
1177 *new_flags
&= FIF_ALLMULTI
| FIF_CONTROL
| FIF_BCN_PRBRESP_PROMISC
|
1181 * We can support more by setting the sniffer bit and
1182 * then checking the error flags, later.
1185 if (changed_flags
& FIF_ALLMULTI
) {
1186 if (*new_flags
& FIF_ALLMULTI
) {
1187 ar
->want_mc_hash
= ~0ULL;
1192 /* always get broadcast frames */
1193 mchash
= 1ULL << (0xff>>2);
1195 for (i
= 0; i
< mc_count
; i
++) {
1196 if (WARN_ON(!mclist
))
1198 mchash
|= 1ULL << (mclist
->dmi_addr
[5] >> 2);
1199 mclist
= mclist
->next
;
1201 ar
->want_mc_hash
= mchash
;
1203 ar
->filter_changed
|= AR9170_FILTER_CHANGED_MULTICAST
;
1206 if (changed_flags
& FIF_CONTROL
) {
1207 u32 filter
= AR9170_MAC_REG_FTF_PSPOLL
|
1208 AR9170_MAC_REG_FTF_RTS
|
1209 AR9170_MAC_REG_FTF_CTS
|
1210 AR9170_MAC_REG_FTF_ACK
|
1211 AR9170_MAC_REG_FTF_CFE
|
1212 AR9170_MAC_REG_FTF_CFE_ACK
;
1214 if (*new_flags
& FIF_CONTROL
)
1215 ar
->want_filter
= ar
->cur_filter
| filter
;
1217 ar
->want_filter
= ar
->cur_filter
& ~filter
;
1219 ar
->filter_changed
|= AR9170_FILTER_CHANGED_FRAMEFILTER
;
1222 if (changed_flags
& FIF_PROMISC_IN_BSS
) {
1223 ar
->sniffer_enabled
= ((*new_flags
) & FIF_PROMISC_IN_BSS
) != 0;
1224 ar
->filter_changed
|= AR9170_FILTER_CHANGED_PROMISC
;
1227 if (likely(IS_STARTED(ar
)))
1228 queue_work(ar
->hw
->workqueue
, &ar
->filter_config_work
);
1231 static void ar9170_op_bss_info_changed(struct ieee80211_hw
*hw
,
1232 struct ieee80211_vif
*vif
,
1233 struct ieee80211_bss_conf
*bss_conf
,
1236 struct ar9170
*ar
= hw
->priv
;
1239 mutex_lock(&ar
->mutex
);
1241 ar9170_regwrite_begin(ar
);
1243 if (changed
& BSS_CHANGED_ASSOC
) {
1244 ar
->state
= bss_conf
->assoc
? AR9170_ASSOCIATED
: ar
->state
;
1246 #ifndef CONFIG_AR9170_LEDS
1247 /* enable assoc LED. */
1248 err
= ar9170_set_leds_state(ar
, bss_conf
->assoc
? 2 : 0);
1249 #endif /* CONFIG_AR9170_LEDS */
1252 if (changed
& BSS_CHANGED_HT
) {
1257 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1260 if (bss_conf
->use_short_slot
)
1263 ar9170_regwrite(AR9170_MAC_REG_SLOT_TIME
, slottime
<< 10);
1266 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1269 if (hw
->conf
.channel
->band
== IEEE80211_BAND_5GHZ
) {
1270 ofdm
= bss_conf
->basic_rates
;
1273 /* four cck rates */
1274 cck
= bss_conf
->basic_rates
& 0xf;
1275 ofdm
= bss_conf
->basic_rates
>> 4;
1277 ar9170_regwrite(AR9170_MAC_REG_BASIC_RATE
,
1281 ar9170_regwrite_finish();
1282 err
= ar9170_regwrite_result();
1283 mutex_unlock(&ar
->mutex
);
1286 static u64
ar9170_op_get_tsf(struct ieee80211_hw
*hw
)
1288 struct ar9170
*ar
= hw
->priv
;
1294 mutex_lock(&ar
->mutex
);
1295 err
= ar9170_read_reg(ar
, AR9170_MAC_REG_TSF_L
, &tsf_low
);
1297 err
= ar9170_read_reg(ar
, AR9170_MAC_REG_TSF_H
, &tsf_high
);
1298 mutex_unlock(&ar
->mutex
);
1304 tsf
= (tsf
<< 32) | tsf_low
;
1308 static int ar9170_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1309 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
1310 struct ieee80211_key_conf
*key
)
1312 struct ar9170
*ar
= hw
->priv
;
1316 if ((!ar
->vif
) || (ar
->disable_offload
))
1321 if (key
->keylen
== LEN_WEP40
)
1322 ktype
= AR9170_ENC_ALG_WEP64
;
1324 ktype
= AR9170_ENC_ALG_WEP128
;
1327 ktype
= AR9170_ENC_ALG_TKIP
;
1330 ktype
= AR9170_ENC_ALG_AESCCMP
;
1336 mutex_lock(&ar
->mutex
);
1337 if (cmd
== SET_KEY
) {
1338 if (unlikely(!IS_STARTED(ar
))) {
1343 /* group keys need all-zeroes address */
1344 if (!(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1347 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) {
1348 for (i
= 0; i
< 64; i
++)
1349 if (!(ar
->usedkeys
& BIT(i
)))
1352 ar
->rx_software_decryption
= true;
1353 ar9170_set_operating_mode(ar
);
1358 i
= 64 + key
->keyidx
;
1361 key
->hw_key_idx
= i
;
1363 err
= ar9170_upload_key(ar
, i
, sta
? sta
->addr
: NULL
, ktype
, 0,
1364 key
->key
, min_t(u8
, 16, key
->keylen
));
1368 if (key
->alg
== ALG_TKIP
) {
1369 err
= ar9170_upload_key(ar
, i
, sta
? sta
->addr
: NULL
,
1370 ktype
, 1, key
->key
+ 16, 16);
1375 * hardware is not capable generating the MMIC
1376 * for fragmented frames!
1378 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1382 ar
->usedkeys
|= BIT(i
);
1384 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1386 if (unlikely(!IS_STARTED(ar
))) {
1387 /* The device is gone... together with the key ;-) */
1392 err
= ar9170_disable_key(ar
, key
->hw_key_idx
);
1396 if (key
->hw_key_idx
< 64) {
1397 ar
->usedkeys
&= ~BIT(key
->hw_key_idx
);
1399 err
= ar9170_upload_key(ar
, key
->hw_key_idx
, NULL
,
1400 AR9170_ENC_ALG_NONE
, 0,
1405 if (key
->alg
== ALG_TKIP
) {
1406 err
= ar9170_upload_key(ar
, key
->hw_key_idx
,
1408 AR9170_ENC_ALG_NONE
, 1,
1417 ar9170_regwrite_begin(ar
);
1418 ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_L
, ar
->usedkeys
);
1419 ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_H
, ar
->usedkeys
>> 32);
1420 ar9170_regwrite_finish();
1421 err
= ar9170_regwrite_result();
1424 mutex_unlock(&ar
->mutex
);
1429 static void ar9170_sta_notify(struct ieee80211_hw
*hw
,
1430 struct ieee80211_vif
*vif
,
1431 enum sta_notify_cmd cmd
,
1432 struct ieee80211_sta
*sta
)
1434 struct ar9170
*ar
= hw
->priv
;
1435 struct ar9170_sta_info
*info
= (void *) sta
->drv_priv
;
1436 struct sk_buff
*skb
;
1440 case STA_NOTIFY_ADD
:
1441 for (i
= 0; i
< ar
->hw
->queues
; i
++)
1442 skb_queue_head_init(&info
->tx_status
[i
]);
1445 case STA_NOTIFY_REMOVE
:
1448 * transfer all outstanding frames that need a tx_status
1449 * reports to the global tx_status queue
1452 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
1453 while ((skb
= skb_dequeue(&info
->tx_status
[i
]))) {
1454 #ifdef AR9170_QUEUE_DEBUG
1455 printk(KERN_DEBUG
"%s: queueing frame in "
1456 "global tx_status queue =>\n",
1457 wiphy_name(ar
->hw
->wiphy
));
1459 ar9170_print_txheader(ar
, skb
);
1460 #endif /* AR9170_QUEUE_DEBUG */
1461 skb_queue_tail(&ar
->global_tx_status
, skb
);
1464 queue_delayed_work(ar
->hw
->workqueue
, &ar
->tx_status_janitor
,
1465 msecs_to_jiffies(100));
1473 static int ar9170_get_stats(struct ieee80211_hw
*hw
,
1474 struct ieee80211_low_level_stats
*stats
)
1476 struct ar9170
*ar
= hw
->priv
;
1480 mutex_lock(&ar
->mutex
);
1481 err
= ar9170_read_reg(ar
, AR9170_MAC_REG_TX_RETRY
, &val
);
1482 ar
->stats
.dot11ACKFailureCount
+= val
;
1484 memcpy(stats
, &ar
->stats
, sizeof(*stats
));
1485 mutex_unlock(&ar
->mutex
);
1490 static int ar9170_get_tx_stats(struct ieee80211_hw
*hw
,
1491 struct ieee80211_tx_queue_stats
*tx_stats
)
1493 struct ar9170
*ar
= hw
->priv
;
1495 spin_lock_bh(&ar
->tx_stats_lock
);
1496 memcpy(tx_stats
, ar
->tx_stats
, sizeof(tx_stats
[0]) * hw
->queues
);
1497 spin_unlock_bh(&ar
->tx_stats_lock
);
1502 static int ar9170_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1503 const struct ieee80211_tx_queue_params
*param
)
1505 struct ar9170
*ar
= hw
->priv
;
1508 mutex_lock(&ar
->mutex
);
1509 if ((param
) && !(queue
> ar
->hw
->queues
)) {
1510 memcpy(&ar
->edcf
[ar9170_qos_hwmap
[queue
]],
1511 param
, sizeof(*param
));
1513 ret
= ar9170_set_qos(ar
);
1517 mutex_unlock(&ar
->mutex
);
1521 static const struct ieee80211_ops ar9170_ops
= {
1522 .start
= ar9170_op_start
,
1523 .stop
= ar9170_op_stop
,
1525 .add_interface
= ar9170_op_add_interface
,
1526 .remove_interface
= ar9170_op_remove_interface
,
1527 .config
= ar9170_op_config
,
1528 .config_interface
= ar9170_op_config_interface
,
1529 .configure_filter
= ar9170_op_configure_filter
,
1530 .conf_tx
= ar9170_conf_tx
,
1531 .bss_info_changed
= ar9170_op_bss_info_changed
,
1532 .get_tsf
= ar9170_op_get_tsf
,
1533 .set_key
= ar9170_set_key
,
1534 .sta_notify
= ar9170_sta_notify
,
1535 .get_stats
= ar9170_get_stats
,
1536 .get_tx_stats
= ar9170_get_tx_stats
,
1539 void *ar9170_alloc(size_t priv_size
)
1541 struct ieee80211_hw
*hw
;
1545 hw
= ieee80211_alloc_hw(priv_size
, &ar9170_ops
);
1547 return ERR_PTR(-ENOMEM
);
1552 mutex_init(&ar
->mutex
);
1553 spin_lock_init(&ar
->cmdlock
);
1554 spin_lock_init(&ar
->tx_stats_lock
);
1555 skb_queue_head_init(&ar
->global_tx_status
);
1556 skb_queue_head_init(&ar
->global_tx_status_waste
);
1557 INIT_WORK(&ar
->filter_config_work
, ar9170_set_filters
);
1558 INIT_WORK(&ar
->beacon_work
, ar9170_new_beacon
);
1559 INIT_DELAYED_WORK(&ar
->tx_status_janitor
, ar9170_tx_status_janitor
);
1561 /* all hw supports 2.4 GHz, so set channel to 1 by default */
1562 ar
->channel
= &ar9170_2ghz_chantable
[0];
1564 /* first part of wiphy init */
1565 ar
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
1566 BIT(NL80211_IFTYPE_WDS
) |
1567 BIT(NL80211_IFTYPE_ADHOC
);
1568 ar
->hw
->flags
|= IEEE80211_HW_RX_INCLUDES_FCS
|
1569 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
|
1570 IEEE80211_HW_SIGNAL_DBM
|
1571 IEEE80211_HW_NOISE_DBM
;
1573 ar
->hw
->queues
= __AR9170_NUM_TXQ
;
1574 ar
->hw
->extra_tx_headroom
= 8;
1575 ar
->hw
->sta_data_size
= sizeof(struct ar9170_sta_info
);
1577 ar
->hw
->max_rates
= 1;
1578 ar
->hw
->max_rate_tries
= 3;
1580 for (i
= 0; i
< ARRAY_SIZE(ar
->noise
); i
++)
1581 ar
->noise
[i
] = -95; /* ATH_DEFAULT_NOISE_FLOOR */
1585 EXPORT_SYMBOL_GPL(ar9170_alloc
);
1587 static int ar9170_read_eeprom(struct ar9170
*ar
)
1589 #define RW 8 /* number of words to read at once */
1590 #define RB (sizeof(u32) * RW)
1591 DECLARE_MAC_BUF(mbuf
);
1592 u8
*eeprom
= (void *)&ar
->eeprom
;
1593 u8
*addr
= ar
->eeprom
.mac_address
;
1595 int i
, j
, err
, bands
= 0;
1597 BUILD_BUG_ON(sizeof(ar
->eeprom
) & 3);
1599 BUILD_BUG_ON(RB
> AR9170_MAX_CMD_LEN
- 4);
1601 /* don't want to handle trailing remains */
1602 BUILD_BUG_ON(sizeof(ar
->eeprom
) % RB
);
1605 for (i
= 0; i
< sizeof(ar
->eeprom
)/RB
; i
++) {
1606 for (j
= 0; j
< RW
; j
++)
1607 offsets
[j
] = cpu_to_le32(AR9170_EEPROM_START
+
1610 err
= ar
->exec_cmd(ar
, AR9170_CMD_RREG
,
1611 RB
, (u8
*) &offsets
,
1612 RB
, eeprom
+ RB
* i
);
1620 if (ar
->eeprom
.length
== cpu_to_le16(0xFFFF))
1623 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_2GHZ
) {
1624 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &ar9170_band_2GHz
;
1627 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_5GHZ
) {
1628 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &ar9170_band_5GHz
;
1632 * I measured this, a bandswitch takes roughly
1633 * 135 ms and a frequency switch about 80.
1635 * FIXME: measure these values again once EEPROM settings
1636 * are used, that will influence them!
1639 ar
->hw
->channel_change_time
= 135 * 1000;
1641 ar
->hw
->channel_change_time
= 80 * 1000;
1643 /* second part of wiphy init */
1644 SET_IEEE80211_PERM_ADDR(ar
->hw
, addr
);
1646 return bands
? 0 : -EINVAL
;
1649 int ar9170_register(struct ar9170
*ar
, struct device
*pdev
)
1653 /* try to read EEPROM, init MAC addr */
1654 err
= ar9170_read_eeprom(ar
);
1658 err
= ieee80211_register_hw(ar
->hw
);
1662 err
= ar9170_init_leds(ar
);
1666 #ifdef CONFIG_AR9170_LEDS
1667 err
= ar9170_register_leds(ar
);
1670 #endif /* CONFIG_AR9170_LEDS */
1672 dev_info(pdev
, "Atheros AR9170 is registered as '%s'\n",
1673 wiphy_name(ar
->hw
->wiphy
));
1678 ieee80211_unregister_hw(ar
->hw
);
1683 EXPORT_SYMBOL_GPL(ar9170_register
);
1685 void ar9170_unregister(struct ar9170
*ar
)
1687 #ifdef CONFIG_AR9170_LEDS
1688 ar9170_unregister_leds(ar
);
1689 #endif /* CONFIG_AR9170_LEDS */
1691 ieee80211_unregister_hw(ar
->hw
);
1692 mutex_destroy(&ar
->mutex
);
1694 EXPORT_SYMBOL_GPL(ar9170_unregister
);
1696 static int __init
ar9170_init(void)
1698 if (modparam_nohwcrypt
)
1699 printk(KERN_INFO
"ar9170: cryptographic acceleration "
1705 static void __exit
ar9170_exit(void)
1710 module_init(ar9170_init
);
1711 module_exit(ar9170_exit
);