2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008 Marvell Semiconductor Inc.
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/spinlock.h>
16 #include <linux/list.h>
17 #include <linux/pci.h>
18 #include <linux/delay.h>
19 #include <linux/completion.h>
20 #include <linux/etherdevice.h>
21 #include <net/mac80211.h>
22 #include <linux/moduleparam.h>
23 #include <linux/firmware.h>
24 #include <linux/workqueue.h>
26 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
27 #define MWL8K_NAME KBUILD_MODNAME
28 #define MWL8K_VERSION "0.9.1"
30 MODULE_DESCRIPTION(MWL8K_DESC
);
31 MODULE_VERSION(MWL8K_VERSION
);
32 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
33 MODULE_LICENSE("GPL");
35 static DEFINE_PCI_DEVICE_TABLE(mwl8k_table
) = {
36 { PCI_VDEVICE(MARVELL
, 0x2a2b), .driver_data
= 8687, },
37 { PCI_VDEVICE(MARVELL
, 0x2a30), .driver_data
= 8687, },
40 MODULE_DEVICE_TABLE(pci
, mwl8k_table
);
42 /* Register definitions */
43 #define MWL8K_HIU_GEN_PTR 0x00000c10
44 #define MWL8K_MODE_STA 0x0000005a
45 #define MWL8K_MODE_AP 0x000000a5
46 #define MWL8K_HIU_INT_CODE 0x00000c14
47 #define MWL8K_FWSTA_READY 0xf0f1f2f4
48 #define MWL8K_FWAP_READY 0xf1f2f4a5
49 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
50 #define MWL8K_HIU_SCRATCH 0x00000c40
52 /* Host->device communications */
53 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
54 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
55 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
56 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
57 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
58 #define MWL8K_H2A_INT_DUMMY (1 << 20)
59 #define MWL8K_H2A_INT_RESET (1 << 15)
60 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
61 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
63 /* Device->host communications */
64 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
65 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
66 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
67 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
68 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
69 #define MWL8K_A2H_INT_DUMMY (1 << 20)
70 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
71 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
72 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
73 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
74 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
75 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
76 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
77 #define MWL8K_A2H_INT_RX_READY (1 << 1)
78 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
80 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
81 MWL8K_A2H_INT_CHNL_SWITCHED | \
82 MWL8K_A2H_INT_QUEUE_EMPTY | \
83 MWL8K_A2H_INT_RADAR_DETECT | \
84 MWL8K_A2H_INT_RADIO_ON | \
85 MWL8K_A2H_INT_RADIO_OFF | \
86 MWL8K_A2H_INT_MAC_EVENT | \
87 MWL8K_A2H_INT_OPC_DONE | \
88 MWL8K_A2H_INT_RX_READY | \
89 MWL8K_A2H_INT_TX_DONE)
91 /* WME stream classes */
92 #define WME_AC_BE 0 /* best effort */
93 #define WME_AC_BK 1 /* background */
94 #define WME_AC_VI 2 /* video */
95 #define WME_AC_VO 3 /* voice */
97 #define MWL8K_RX_QUEUES 1
98 #define MWL8K_TX_QUEUES 4
100 struct mwl8k_rx_queue
{
103 /* hw receives here */
106 /* refill descs here */
109 struct mwl8k_rx_desc
*rx_desc_area
;
110 dma_addr_t rx_desc_dma
;
111 struct sk_buff
**rx_skb
;
114 struct mwl8k_tx_queue
{
115 /* hw transmits here */
118 /* sw appends here */
121 struct ieee80211_tx_queue_stats tx_stats
;
122 struct mwl8k_tx_desc
*tx_desc_area
;
123 dma_addr_t tx_desc_dma
;
124 struct sk_buff
**tx_skb
;
127 /* Pointers to the firmware data and meta information about it. */
128 struct mwl8k_firmware
{
130 struct firmware
*ucode
;
132 /* Boot helper code */
133 struct firmware
*helper
;
138 struct ieee80211_hw
*hw
;
140 struct pci_dev
*pdev
;
142 /* firmware access lock */
145 /* firmware files and meta data */
146 struct mwl8k_firmware fw
;
149 /* lock held over TX and TX reap */
152 struct ieee80211_vif
*vif
;
154 struct ieee80211_channel
*current_channel
;
156 /* power management status cookie from firmware */
158 dma_addr_t cookie_dma
;
165 * Running count of TX packets in flight, to avoid
166 * iterating over the transmit rings each time.
170 struct mwl8k_rx_queue rxq
[MWL8K_RX_QUEUES
];
171 struct mwl8k_tx_queue txq
[MWL8K_TX_QUEUES
];
174 struct ieee80211_supported_band band
;
175 struct ieee80211_channel channels
[14];
176 struct ieee80211_rate rates
[12];
179 bool radio_short_preamble
;
182 /* Set if PHY config is in progress */
185 /* XXX need to convert this to handle multiple interfaces */
187 u8 capture_bssid
[ETH_ALEN
];
188 struct sk_buff
*beacon_skb
;
191 * This FJ worker has to be global as it is scheduled from the
192 * RX handler. At this point we don't know which interface it
193 * belongs to until the list of bssids waiting to complete join
196 struct work_struct finalize_join_worker
;
198 /* Tasklet to reclaim TX descriptors and buffers after tx */
199 struct tasklet_struct tx_reclaim_task
;
201 /* Work thread to serialize configuration requests */
202 struct workqueue_struct
*config_wq
;
203 struct completion
*hostcmd_wait
;
204 struct completion
*tx_wait
;
207 /* Per interface specific private data */
209 /* backpointer to parent config block */
210 struct mwl8k_priv
*priv
;
212 /* BSS config of AP or IBSS from mac80211*/
213 struct ieee80211_bss_conf bss_info
;
215 /* BSSID of AP or IBSS */
217 u8 mac_addr
[ETH_ALEN
];
220 * Subset of supported legacy rates.
221 * Intersection of AP and STA supported rates.
223 struct ieee80211_rate legacy_rates
[12];
225 /* number of supported legacy rates */
228 /* Index into station database.Returned by update_sta_db call */
231 /* Non AMPDU sequence number assigned by driver */
235 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
237 static const struct ieee80211_channel mwl8k_channels
[] = {
238 { .center_freq
= 2412, .hw_value
= 1, },
239 { .center_freq
= 2417, .hw_value
= 2, },
240 { .center_freq
= 2422, .hw_value
= 3, },
241 { .center_freq
= 2427, .hw_value
= 4, },
242 { .center_freq
= 2432, .hw_value
= 5, },
243 { .center_freq
= 2437, .hw_value
= 6, },
244 { .center_freq
= 2442, .hw_value
= 7, },
245 { .center_freq
= 2447, .hw_value
= 8, },
246 { .center_freq
= 2452, .hw_value
= 9, },
247 { .center_freq
= 2457, .hw_value
= 10, },
248 { .center_freq
= 2462, .hw_value
= 11, },
251 static const struct ieee80211_rate mwl8k_rates
[] = {
252 { .bitrate
= 10, .hw_value
= 2, },
253 { .bitrate
= 20, .hw_value
= 4, },
254 { .bitrate
= 55, .hw_value
= 11, },
255 { .bitrate
= 60, .hw_value
= 12, },
256 { .bitrate
= 90, .hw_value
= 18, },
257 { .bitrate
= 110, .hw_value
= 22, },
258 { .bitrate
= 120, .hw_value
= 24, },
259 { .bitrate
= 180, .hw_value
= 36, },
260 { .bitrate
= 240, .hw_value
= 48, },
261 { .bitrate
= 360, .hw_value
= 72, },
262 { .bitrate
= 480, .hw_value
= 96, },
263 { .bitrate
= 540, .hw_value
= 108, },
266 /* Set or get info from Firmware */
267 #define MWL8K_CMD_SET 0x0001
268 #define MWL8K_CMD_GET 0x0000
270 /* Firmware command codes */
271 #define MWL8K_CMD_CODE_DNLD 0x0001
272 #define MWL8K_CMD_GET_HW_SPEC 0x0003
273 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
274 #define MWL8K_CMD_GET_STAT 0x0014
275 #define MWL8K_CMD_RADIO_CONTROL 0x001c
276 #define MWL8K_CMD_RF_TX_POWER 0x001e
277 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
278 #define MWL8K_CMD_SET_POST_SCAN 0x0108
279 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
280 #define MWL8K_CMD_SET_AID 0x010d
281 #define MWL8K_CMD_SET_RATE 0x0110
282 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
283 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
284 #define MWL8K_CMD_SET_SLOT 0x0114
285 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
286 #define MWL8K_CMD_SET_WMM_MODE 0x0123
287 #define MWL8K_CMD_MIMO_CONFIG 0x0125
288 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
289 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
290 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
291 #define MWL8K_CMD_UPDATE_STADB 0x1123
293 static const char *mwl8k_cmd_name(u16 cmd
, char *buf
, int bufsize
)
295 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
296 snprintf(buf, bufsize, "%s", #x);\
299 switch (cmd
& ~0x8000) {
300 MWL8K_CMDNAME(CODE_DNLD
);
301 MWL8K_CMDNAME(GET_HW_SPEC
);
302 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
303 MWL8K_CMDNAME(GET_STAT
);
304 MWL8K_CMDNAME(RADIO_CONTROL
);
305 MWL8K_CMDNAME(RF_TX_POWER
);
306 MWL8K_CMDNAME(SET_PRE_SCAN
);
307 MWL8K_CMDNAME(SET_POST_SCAN
);
308 MWL8K_CMDNAME(SET_RF_CHANNEL
);
309 MWL8K_CMDNAME(SET_AID
);
310 MWL8K_CMDNAME(SET_RATE
);
311 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
312 MWL8K_CMDNAME(RTS_THRESHOLD
);
313 MWL8K_CMDNAME(SET_SLOT
);
314 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
315 MWL8K_CMDNAME(SET_WMM_MODE
);
316 MWL8K_CMDNAME(MIMO_CONFIG
);
317 MWL8K_CMDNAME(USE_FIXED_RATE
);
318 MWL8K_CMDNAME(ENABLE_SNIFFER
);
319 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
320 MWL8K_CMDNAME(UPDATE_STADB
);
322 snprintf(buf
, bufsize
, "0x%x", cmd
);
329 /* Hardware and firmware reset */
330 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
332 iowrite32(MWL8K_H2A_INT_RESET
,
333 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
334 iowrite32(MWL8K_H2A_INT_RESET
,
335 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
339 /* Release fw image */
340 static void mwl8k_release_fw(struct firmware
**fw
)
344 release_firmware(*fw
);
348 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
350 mwl8k_release_fw(&priv
->fw
.ucode
);
351 mwl8k_release_fw(&priv
->fw
.helper
);
354 /* Request fw image */
355 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
356 const char *fname
, struct firmware
**fw
)
358 /* release current image */
360 mwl8k_release_fw(fw
);
362 return request_firmware((const struct firmware
**)fw
,
363 fname
, &priv
->pdev
->dev
);
366 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, u32 part_num
)
371 priv
->part_num
= part_num
;
373 snprintf(filename
, sizeof(filename
),
374 "mwl8k/helper_%u.fw", priv
->part_num
);
376 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.helper
);
379 "%s Error requesting helper firmware file %s\n",
380 pci_name(priv
->pdev
), filename
);
384 snprintf(filename
, sizeof(filename
),
385 "mwl8k/fmimage_%u.fw", priv
->part_num
);
387 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.ucode
);
389 printk(KERN_ERR
"%s Error requesting firmware file %s\n",
390 pci_name(priv
->pdev
), filename
);
391 mwl8k_release_fw(&priv
->fw
.helper
);
398 struct mwl8k_cmd_pkt
{
404 } __attribute__((packed
));
410 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
412 void __iomem
*regs
= priv
->regs
;
416 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
417 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
420 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
421 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
422 iowrite32(MWL8K_H2A_INT_DOORBELL
,
423 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
424 iowrite32(MWL8K_H2A_INT_DUMMY
,
425 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
431 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
432 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
433 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
440 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
442 return loops
? 0 : -ETIMEDOUT
;
445 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
446 const u8
*data
, size_t length
)
448 struct mwl8k_cmd_pkt
*cmd
;
452 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
456 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
462 int block_size
= length
> 256 ? 256 : length
;
464 memcpy(cmd
->payload
, data
+ done
, block_size
);
465 cmd
->length
= cpu_to_le16(block_size
);
467 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
468 sizeof(*cmd
) + block_size
);
473 length
-= block_size
;
478 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
486 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
487 const u8
*data
, size_t length
)
489 unsigned char *buffer
;
490 int may_continue
, rc
= 0;
491 u32 done
, prev_block_size
;
493 buffer
= kmalloc(1024, GFP_KERNEL
);
500 while (may_continue
> 0) {
503 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
504 if (block_size
& 1) {
508 done
+= prev_block_size
;
509 length
-= prev_block_size
;
512 if (block_size
> 1024 || block_size
> length
) {
522 if (block_size
== 0) {
529 prev_block_size
= block_size
;
530 memcpy(buffer
, data
+ done
, block_size
);
532 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
537 if (!rc
&& length
!= 0)
545 static int mwl8k_load_firmware(struct mwl8k_priv
*priv
)
549 const u8
*ucode
= priv
->fw
.ucode
->data
;
550 size_t ucode_len
= priv
->fw
.ucode
->size
;
551 const u8
*helper
= priv
->fw
.helper
->data
;
552 size_t helper_len
= priv
->fw
.helper
->size
;
554 if (!memcmp(ucode
, "\x01\x00\x00\x00", 4)) {
555 rc
= mwl8k_load_fw_image(priv
, helper
, helper_len
);
557 printk(KERN_ERR
"%s: unable to load firmware "
558 "helper image\n", pci_name(priv
->pdev
));
563 rc
= mwl8k_feed_fw_image(priv
, ucode
, ucode_len
);
565 rc
= mwl8k_load_fw_image(priv
, ucode
, ucode_len
);
569 printk(KERN_ERR
"%s: unable to load firmware data\n",
570 pci_name(priv
->pdev
));
574 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
579 if (ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
)
580 == MWL8K_FWSTA_READY
)
585 return loops
? 0 : -ETIMEDOUT
;
590 * Defines shared between transmission and reception.
592 /* HT control fields for firmware */
597 } __attribute__((packed
));
599 /* Firmware Station database operations */
600 #define MWL8K_STA_DB_ADD_ENTRY 0
601 #define MWL8K_STA_DB_MODIFY_ENTRY 1
602 #define MWL8K_STA_DB_DEL_ENTRY 2
603 #define MWL8K_STA_DB_FLUSH 3
605 /* Peer Entry flags - used to define the type of the peer node */
606 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
608 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
609 #define MWL8K_MCS_BITMAP_SIZE 16
611 struct peer_capability_info
{
612 /* Peer type - AP vs. STA. */
615 /* Basic 802.11 capabilities from assoc resp. */
618 /* Set if peer supports 802.11n high throughput (HT). */
621 /* Valid if HT is supported. */
623 __u8 extended_ht_caps
;
624 struct ewc_ht_info ewc_info
;
626 /* Legacy rate table. Intersection of our rates and peer rates. */
627 __u8 legacy_rates
[MWL8K_IEEE_LEGACY_DATA_RATES
];
629 /* HT rate table. Intersection of our rates and peer rates. */
630 __u8 ht_rates
[MWL8K_MCS_BITMAP_SIZE
];
633 /* If set, interoperability mode, no proprietary extensions. */
637 __le16 amsdu_enabled
;
638 } __attribute__((packed
));
640 /* Inline functions to manipulate QoS field in data descriptor. */
641 static inline u16
mwl8k_qos_setbit_eosp(u16 qos
)
643 u16 val_mask
= 1 << 4;
645 /* End of Service Period Bit 4 */
646 return qos
| val_mask
;
649 static inline u16
mwl8k_qos_setbit_ack(u16 qos
, u8 ack_policy
)
653 u16 qos_mask
= ~(val_mask
<< shift
);
655 /* Ack Policy Bit 5-6 */
656 return (qos
& qos_mask
) | ((ack_policy
& val_mask
) << shift
);
659 static inline u16
mwl8k_qos_setbit_amsdu(u16 qos
)
661 u16 val_mask
= 1 << 7;
663 /* AMSDU present Bit 7 */
664 return qos
| val_mask
;
667 static inline u16
mwl8k_qos_setbit_qlen(u16 qos
, u8 len
)
671 u16 qos_mask
= ~(val_mask
<< shift
);
673 /* Queue Length Bits 8-15 */
674 return (qos
& qos_mask
) | ((len
& val_mask
) << shift
);
677 /* DMA header used by firmware and hardware. */
678 struct mwl8k_dma_data
{
680 struct ieee80211_hdr wh
;
681 } __attribute__((packed
));
683 /* Routines to add/remove DMA header from skb. */
684 static inline void mwl8k_remove_dma_header(struct sk_buff
*skb
)
686 struct mwl8k_dma_data
*tr
= (struct mwl8k_dma_data
*)skb
->data
;
687 void *dst
, *src
= &tr
->wh
;
688 int hdrlen
= ieee80211_hdrlen(tr
->wh
.frame_control
);
689 u16 space
= sizeof(struct mwl8k_dma_data
) - hdrlen
;
691 dst
= (void *)tr
+ space
;
693 memmove(dst
, src
, hdrlen
);
694 skb_pull(skb
, space
);
698 static inline void mwl8k_add_dma_header(struct sk_buff
*skb
)
700 struct ieee80211_hdr
*wh
;
702 struct mwl8k_dma_data
*tr
;
704 wh
= (struct ieee80211_hdr
*)skb
->data
;
705 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
709 * Copy up/down the 802.11 header; the firmware requires
710 * we present a 2-byte payload length followed by a
711 * 4-address header (w/o QoS), followed (optionally) by
712 * any WEP/ExtIV header (but only filled in for CCMP).
714 if (hdrlen
!= sizeof(struct mwl8k_dma_data
))
715 skb_push(skb
, sizeof(struct mwl8k_dma_data
) - hdrlen
);
717 tr
= (struct mwl8k_dma_data
*)skb
->data
;
719 memmove(&tr
->wh
, wh
, hdrlen
);
722 memset(tr
->wh
.addr4
, 0, ETH_ALEN
);
725 * Firmware length is the length of the fully formed "802.11
726 * payload". That is, everything except for the 802.11 header.
727 * This includes all crypto material including the MIC.
729 tr
->fwlen
= cpu_to_le16(pktlen
- hdrlen
);
736 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
738 struct mwl8k_rx_desc
{
742 __le32 pkt_phys_addr
;
743 __le32 next_rx_desc_phys_addr
;
753 } __attribute__((packed
));
755 #define MWL8K_RX_DESCS 256
756 #define MWL8K_RX_MAXSZ 3800
758 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
760 struct mwl8k_priv
*priv
= hw
->priv
;
761 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
765 rxq
->rx_desc_count
= 0;
769 size
= MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
);
772 pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rx_desc_dma
);
773 if (rxq
->rx_desc_area
== NULL
) {
774 printk(KERN_ERR
"%s: failed to alloc RX descriptors\n",
778 memset(rxq
->rx_desc_area
, 0, size
);
780 rxq
->rx_skb
= kmalloc(MWL8K_RX_DESCS
*
781 sizeof(*rxq
->rx_skb
), GFP_KERNEL
);
782 if (rxq
->rx_skb
== NULL
) {
783 printk(KERN_ERR
"%s: failed to alloc RX skbuff list\n",
785 pci_free_consistent(priv
->pdev
, size
,
786 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
789 memset(rxq
->rx_skb
, 0, MWL8K_RX_DESCS
* sizeof(*rxq
->rx_skb
));
791 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
792 struct mwl8k_rx_desc
*rx_desc
;
795 rx_desc
= rxq
->rx_desc_area
+ i
;
796 nexti
= (i
+ 1) % MWL8K_RX_DESCS
;
798 rx_desc
->next_rx_desc_phys_addr
=
799 cpu_to_le32(rxq
->rx_desc_dma
800 + nexti
* sizeof(*rx_desc
));
801 rx_desc
->rx_ctrl
= MWL8K_RX_CTRL_OWNED_BY_HOST
;
807 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
809 struct mwl8k_priv
*priv
= hw
->priv
;
810 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
814 while (rxq
->rx_desc_count
< MWL8K_RX_DESCS
&& limit
--) {
818 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
822 rxq
->rx_desc_count
++;
825 rxq
->rx_tail
= (rx
+ 1) % MWL8K_RX_DESCS
;
827 rxq
->rx_desc_area
[rx
].pkt_phys_addr
=
828 cpu_to_le32(pci_map_single(priv
->pdev
, skb
->data
,
829 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
));
831 rxq
->rx_desc_area
[rx
].pkt_len
= cpu_to_le16(MWL8K_RX_MAXSZ
);
832 rxq
->rx_skb
[rx
] = skb
;
834 rxq
->rx_desc_area
[rx
].rx_ctrl
= 0;
842 /* Must be called only when the card's reception is completely halted */
843 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
845 struct mwl8k_priv
*priv
= hw
->priv
;
846 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
849 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
850 if (rxq
->rx_skb
[i
] != NULL
) {
853 addr
= le32_to_cpu(rxq
->rx_desc_area
[i
].pkt_phys_addr
);
854 pci_unmap_single(priv
->pdev
, addr
, MWL8K_RX_MAXSZ
,
856 kfree_skb(rxq
->rx_skb
[i
]);
857 rxq
->rx_skb
[i
] = NULL
;
864 pci_free_consistent(priv
->pdev
,
865 MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
),
866 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
867 rxq
->rx_desc_area
= NULL
;
872 * Scan a list of BSSIDs to process for finalize join.
873 * Allows for extension to process multiple BSSIDs.
876 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
878 return priv
->capture_beacon
&&
879 ieee80211_is_beacon(wh
->frame_control
) &&
880 !compare_ether_addr(wh
->addr3
, priv
->capture_bssid
);
883 static inline void mwl8k_save_beacon(struct mwl8k_priv
*priv
,
886 priv
->capture_beacon
= false;
887 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
890 * Use GFP_ATOMIC as rxq_process is called from
891 * the primary interrupt handler, memory allocation call
894 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
895 if (priv
->beacon_skb
!= NULL
)
896 queue_work(priv
->config_wq
,
897 &priv
->finalize_join_worker
);
900 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
902 struct mwl8k_priv
*priv
= hw
->priv
;
903 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
907 while (rxq
->rx_desc_count
&& limit
--) {
908 struct mwl8k_rx_desc
*rx_desc
;
910 struct ieee80211_rx_status status
;
912 struct ieee80211_hdr
*wh
;
914 rx_desc
= rxq
->rx_desc_area
+ rxq
->rx_head
;
915 if (!(rx_desc
->rx_ctrl
& MWL8K_RX_CTRL_OWNED_BY_HOST
))
919 skb
= rxq
->rx_skb
[rxq
->rx_head
];
922 rxq
->rx_skb
[rxq
->rx_head
] = NULL
;
924 rxq
->rx_head
= (rxq
->rx_head
+ 1) % MWL8K_RX_DESCS
;
925 rxq
->rx_desc_count
--;
927 addr
= le32_to_cpu(rx_desc
->pkt_phys_addr
);
928 pci_unmap_single(priv
->pdev
, addr
,
929 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
931 skb_put(skb
, le16_to_cpu(rx_desc
->pkt_len
));
932 mwl8k_remove_dma_header(skb
);
934 wh
= (struct ieee80211_hdr
*)skb
->data
;
937 * Check for pending join operation. save a copy of
938 * the beacon and schedule a tasklet to send finalize
939 * join command to the firmware.
941 if (mwl8k_capture_bssid(priv
, wh
))
942 mwl8k_save_beacon(priv
, skb
);
944 memset(&status
, 0, sizeof(status
));
946 status
.signal
= -rx_desc
->rssi
;
947 status
.noise
= -rx_desc
->noise_level
;
948 status
.qual
= rx_desc
->link_quality
;
952 status
.band
= IEEE80211_BAND_2GHZ
;
953 status
.freq
= ieee80211_channel_to_frequency(rx_desc
->channel
);
954 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
955 ieee80211_rx_irqsafe(hw
, skb
);
965 * Packet transmission.
968 /* Transmit queue assignment. */
970 MWL8K_WME_AC_BK
= 0, /* background access */
971 MWL8K_WME_AC_BE
= 1, /* best effort access */
972 MWL8K_WME_AC_VI
= 2, /* video access */
973 MWL8K_WME_AC_VO
= 3, /* voice access */
976 /* Transmit packet ACK policy */
977 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
978 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
980 #define GET_TXQ(_ac) (\
981 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
982 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
983 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
986 #define MWL8K_TXD_STATUS_OK 0x00000001
987 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
988 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
989 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
990 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
992 struct mwl8k_tx_desc
{
997 __le32 pkt_phys_addr
;
999 __u8 dest_MAC_addr
[ETH_ALEN
];
1000 __le32 next_tx_desc_phys_addr
;
1005 } __attribute__((packed
));
1007 #define MWL8K_TX_DESCS 128
1009 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1011 struct mwl8k_priv
*priv
= hw
->priv
;
1012 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1016 memset(&txq
->tx_stats
, 0, sizeof(struct ieee80211_tx_queue_stats
));
1017 txq
->tx_stats
.limit
= MWL8K_TX_DESCS
;
1021 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1024 pci_alloc_consistent(priv
->pdev
, size
, &txq
->tx_desc_dma
);
1025 if (txq
->tx_desc_area
== NULL
) {
1026 printk(KERN_ERR
"%s: failed to alloc TX descriptors\n",
1030 memset(txq
->tx_desc_area
, 0, size
);
1032 txq
->tx_skb
= kmalloc(MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
),
1034 if (txq
->tx_skb
== NULL
) {
1035 printk(KERN_ERR
"%s: failed to alloc TX skbuff list\n",
1037 pci_free_consistent(priv
->pdev
, size
,
1038 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1041 memset(txq
->tx_skb
, 0, MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
));
1043 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1044 struct mwl8k_tx_desc
*tx_desc
;
1047 tx_desc
= txq
->tx_desc_area
+ i
;
1048 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1050 tx_desc
->status
= 0;
1051 tx_desc
->next_tx_desc_phys_addr
=
1052 cpu_to_le32(txq
->tx_desc_dma
+
1053 nexti
* sizeof(*tx_desc
));
1059 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1061 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1062 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1063 iowrite32(MWL8K_H2A_INT_DUMMY
,
1064 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1065 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1068 static inline int mwl8k_txq_busy(struct mwl8k_priv
*priv
)
1070 return priv
->pending_tx_pkts
;
1073 struct mwl8k_txq_info
{
1082 static int mwl8k_scan_tx_ring(struct mwl8k_priv
*priv
,
1083 struct mwl8k_txq_info
*txinfo
)
1085 int count
, desc
, status
;
1086 struct mwl8k_tx_queue
*txq
;
1087 struct mwl8k_tx_desc
*tx_desc
;
1090 memset(txinfo
, 0, MWL8K_TX_QUEUES
* sizeof(struct mwl8k_txq_info
));
1092 spin_lock_bh(&priv
->tx_lock
);
1093 for (count
= 0; count
< MWL8K_TX_QUEUES
; count
++) {
1094 txq
= priv
->txq
+ count
;
1095 txinfo
[count
].len
= txq
->tx_stats
.len
;
1096 txinfo
[count
].head
= txq
->tx_head
;
1097 txinfo
[count
].tail
= txq
->tx_tail
;
1098 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1099 tx_desc
= txq
->tx_desc_area
+ desc
;
1100 status
= le32_to_cpu(tx_desc
->status
);
1102 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1103 txinfo
[count
].fw_owned
++;
1105 txinfo
[count
].drv_owned
++;
1107 if (tx_desc
->pkt_len
== 0)
1108 txinfo
[count
].unused
++;
1111 spin_unlock_bh(&priv
->tx_lock
);
1116 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
, u32 delay_ms
)
1118 struct mwl8k_priv
*priv
= hw
->priv
;
1119 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1121 unsigned long timeout
;
1125 if (priv
->tx_wait
!= NULL
)
1126 printk(KERN_ERR
"WARNING Previous TXWaitEmpty instance\n");
1128 spin_lock_bh(&priv
->tx_lock
);
1129 count
= mwl8k_txq_busy(priv
);
1131 priv
->tx_wait
= &cmd_wait
;
1133 mwl8k_tx_start(priv
);
1135 spin_unlock_bh(&priv
->tx_lock
);
1138 struct mwl8k_txq_info txinfo
[MWL8K_TX_QUEUES
];
1142 timeout
= wait_for_completion_timeout(&cmd_wait
,
1143 msecs_to_jiffies(delay_ms
));
1147 spin_lock_bh(&priv
->tx_lock
);
1148 priv
->tx_wait
= NULL
;
1149 newcount
= mwl8k_txq_busy(priv
);
1150 spin_unlock_bh(&priv
->tx_lock
);
1152 printk(KERN_ERR
"%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
1153 __func__
, __LINE__
, delay_ms
, count
, newcount
);
1155 mwl8k_scan_tx_ring(priv
, txinfo
);
1156 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++)
1158 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
1163 txinfo
[index
].fw_owned
,
1164 txinfo
[index
].drv_owned
,
1165 txinfo
[index
].unused
);
1173 #define MWL8K_TXD_SUCCESS(status) \
1174 ((status) & (MWL8K_TXD_STATUS_OK | \
1175 MWL8K_TXD_STATUS_OK_RETRY | \
1176 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1178 static void mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int force
)
1180 struct mwl8k_priv
*priv
= hw
->priv
;
1181 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1184 while (txq
->tx_stats
.len
> 0) {
1186 struct mwl8k_tx_desc
*tx_desc
;
1189 struct sk_buff
*skb
;
1190 struct ieee80211_tx_info
*info
;
1194 tx_desc
= txq
->tx_desc_area
+ tx
;
1196 status
= le32_to_cpu(tx_desc
->status
);
1198 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1202 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1205 txq
->tx_head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1206 BUG_ON(txq
->tx_stats
.len
== 0);
1207 txq
->tx_stats
.len
--;
1208 priv
->pending_tx_pkts
--;
1210 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1211 size
= le16_to_cpu(tx_desc
->pkt_len
);
1212 skb
= txq
->tx_skb
[tx
];
1213 txq
->tx_skb
[tx
] = NULL
;
1215 BUG_ON(skb
== NULL
);
1216 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1218 mwl8k_remove_dma_header(skb
);
1220 /* Mark descriptor as unused */
1221 tx_desc
->pkt_phys_addr
= 0;
1222 tx_desc
->pkt_len
= 0;
1224 info
= IEEE80211_SKB_CB(skb
);
1225 ieee80211_tx_info_clear_status(info
);
1226 if (MWL8K_TXD_SUCCESS(status
))
1227 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1229 ieee80211_tx_status_irqsafe(hw
, skb
);
1231 wake
= !priv
->inconfig
&& priv
->radio_on
;
1235 ieee80211_wake_queue(hw
, index
);
1238 /* must be called only when the card's transmit is completely halted */
1239 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1241 struct mwl8k_priv
*priv
= hw
->priv
;
1242 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1244 mwl8k_txq_reclaim(hw
, index
, 1);
1249 pci_free_consistent(priv
->pdev
,
1250 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1251 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1252 txq
->tx_desc_area
= NULL
;
1256 mwl8k_txq_xmit(struct ieee80211_hw
*hw
, int index
, struct sk_buff
*skb
)
1258 struct mwl8k_priv
*priv
= hw
->priv
;
1259 struct ieee80211_tx_info
*tx_info
;
1260 struct mwl8k_vif
*mwl8k_vif
;
1261 struct ieee80211_hdr
*wh
;
1262 struct mwl8k_tx_queue
*txq
;
1263 struct mwl8k_tx_desc
*tx
;
1269 wh
= (struct ieee80211_hdr
*)skb
->data
;
1270 if (ieee80211_is_data_qos(wh
->frame_control
))
1271 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1275 mwl8k_add_dma_header(skb
);
1276 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1278 tx_info
= IEEE80211_SKB_CB(skb
);
1279 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1281 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1282 u16 seqno
= mwl8k_vif
->seqno
;
1284 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1285 wh
->seq_ctrl
|= cpu_to_le16(seqno
<< 4);
1286 mwl8k_vif
->seqno
= seqno
++ % 4096;
1289 /* Setup firmware control bit fields for each frame type. */
1292 if (ieee80211_is_mgmt(wh
->frame_control
) ||
1293 ieee80211_is_ctl(wh
->frame_control
)) {
1295 qos
= mwl8k_qos_setbit_eosp(qos
);
1296 /* Set Queue size to unspecified */
1297 qos
= mwl8k_qos_setbit_qlen(qos
, 0xff);
1298 } else if (ieee80211_is_data(wh
->frame_control
)) {
1300 if (is_multicast_ether_addr(wh
->addr1
))
1301 txstatus
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1303 /* Send pkt in an aggregate if AMPDU frame. */
1304 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1305 qos
= mwl8k_qos_setbit_ack(qos
,
1306 MWL8K_TXD_ACK_POLICY_BLOCKACK
);
1308 qos
= mwl8k_qos_setbit_ack(qos
,
1309 MWL8K_TXD_ACK_POLICY_NORMAL
);
1311 if (qos
& IEEE80211_QOS_CONTROL_A_MSDU_PRESENT
)
1312 qos
= mwl8k_qos_setbit_amsdu(qos
);
1315 dma
= pci_map_single(priv
->pdev
, skb
->data
,
1316 skb
->len
, PCI_DMA_TODEVICE
);
1318 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
1319 printk(KERN_DEBUG
"%s: failed to dma map skb, "
1320 "dropping TX frame.\n", priv
->name
);
1322 return NETDEV_TX_OK
;
1325 spin_lock_bh(&priv
->tx_lock
);
1327 txq
= priv
->txq
+ index
;
1329 BUG_ON(txq
->tx_skb
[txq
->tx_tail
] != NULL
);
1330 txq
->tx_skb
[txq
->tx_tail
] = skb
;
1332 tx
= txq
->tx_desc_area
+ txq
->tx_tail
;
1333 tx
->data_rate
= txdatarate
;
1334 tx
->tx_priority
= index
;
1335 tx
->qos_control
= cpu_to_le16(qos
);
1336 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
1337 tx
->pkt_len
= cpu_to_le16(skb
->len
);
1339 tx
->peer_id
= mwl8k_vif
->peer_id
;
1341 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
| txstatus
);
1343 txq
->tx_stats
.count
++;
1344 txq
->tx_stats
.len
++;
1345 priv
->pending_tx_pkts
++;
1348 if (txq
->tx_tail
== MWL8K_TX_DESCS
)
1351 if (txq
->tx_head
== txq
->tx_tail
)
1352 ieee80211_stop_queue(hw
, index
);
1354 mwl8k_tx_start(priv
);
1356 spin_unlock_bh(&priv
->tx_lock
);
1358 return NETDEV_TX_OK
;
1363 * Command processing.
1366 /* Timeout firmware commands after 2000ms */
1367 #define MWL8K_CMD_TIMEOUT_MS 2000
1369 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
1371 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1372 struct mwl8k_priv
*priv
= hw
->priv
;
1373 void __iomem
*regs
= priv
->regs
;
1374 dma_addr_t dma_addr
;
1375 unsigned int dma_size
;
1377 unsigned long timeout
= 0;
1380 cmd
->result
= 0xFFFF;
1381 dma_size
= le16_to_cpu(cmd
->length
);
1382 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
1383 PCI_DMA_BIDIRECTIONAL
);
1384 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
1387 if (priv
->hostcmd_wait
!= NULL
)
1388 printk(KERN_ERR
"WARNING host command in progress\n");
1390 spin_lock_irq(&priv
->fw_lock
);
1391 priv
->hostcmd_wait
= &cmd_wait
;
1392 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
1393 iowrite32(MWL8K_H2A_INT_DOORBELL
,
1394 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1395 iowrite32(MWL8K_H2A_INT_DUMMY
,
1396 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1397 spin_unlock_irq(&priv
->fw_lock
);
1399 timeout
= wait_for_completion_timeout(&cmd_wait
,
1400 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
1402 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1403 PCI_DMA_BIDIRECTIONAL
);
1406 spin_lock_irq(&priv
->fw_lock
);
1407 priv
->hostcmd_wait
= NULL
;
1408 spin_unlock_irq(&priv
->fw_lock
);
1409 printk(KERN_ERR
"%s: Command %s timeout after %u ms\n",
1411 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1412 MWL8K_CMD_TIMEOUT_MS
);
1415 rc
= cmd
->result
? -EINVAL
: 0;
1417 printk(KERN_ERR
"%s: Command %s error 0x%x\n",
1419 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1429 struct mwl8k_cmd_get_hw_spec
{
1430 struct mwl8k_cmd_pkt header
;
1432 __u8 host_interface
;
1434 __u8 perm_addr
[ETH_ALEN
];
1439 __u8 mcs_bitmap
[16];
1440 __le32 rx_queue_ptr
;
1441 __le32 num_tx_queues
;
1442 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1444 __le32 num_tx_desc_per_queue
;
1445 __le32 total_rx_desc
;
1446 } __attribute__((packed
));
1448 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw
*hw
)
1450 struct mwl8k_priv
*priv
= hw
->priv
;
1451 struct mwl8k_cmd_get_hw_spec
*cmd
;
1455 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1459 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1460 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1462 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1463 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1464 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rx_desc_dma
);
1465 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1466 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1467 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].tx_desc_dma
);
1468 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1469 cmd
->total_rx_desc
= cpu_to_le32(MWL8K_RX_DESCS
);
1471 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1474 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1475 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1476 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1477 priv
->hw_rev
= cmd
->hw_rev
;
1485 * CMD_MAC_MULTICAST_ADR.
1487 struct mwl8k_cmd_mac_multicast_adr
{
1488 struct mwl8k_cmd_pkt header
;
1491 __u8 addr
[0][ETH_ALEN
];
1494 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
1496 static struct mwl8k_cmd_pkt
*
1497 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
,
1498 int mc_count
, struct dev_addr_list
*mclist
)
1500 struct mwl8k_priv
*priv
= hw
->priv
;
1501 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
1505 if (mc_count
> priv
->num_mcaddrs
)
1506 mc_count
= priv
->num_mcaddrs
;
1508 size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
1510 cmd
= kzalloc(size
, GFP_ATOMIC
);
1514 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
1515 cmd
->header
.length
= cpu_to_le16(size
);
1516 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
1517 cmd
->numaddr
= cpu_to_le16(mc_count
);
1519 for (i
= 0; i
< mc_count
&& mclist
; i
++) {
1520 if (mclist
->da_addrlen
!= ETH_ALEN
) {
1524 memcpy(cmd
->addr
[i
], mclist
->da_addr
, ETH_ALEN
);
1525 mclist
= mclist
->next
;
1528 return &cmd
->header
;
1532 * CMD_802_11_GET_STAT.
1534 struct mwl8k_cmd_802_11_get_stat
{
1535 struct mwl8k_cmd_pkt header
;
1538 } __attribute__((packed
));
1540 #define MWL8K_STAT_ACK_FAILURE 9
1541 #define MWL8K_STAT_RTS_FAILURE 12
1542 #define MWL8K_STAT_FCS_ERROR 24
1543 #define MWL8K_STAT_RTS_SUCCESS 11
1545 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw
*hw
,
1546 struct ieee80211_low_level_stats
*stats
)
1548 struct mwl8k_cmd_802_11_get_stat
*cmd
;
1551 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1555 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
1556 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1557 cmd
->action
= cpu_to_le16(MWL8K_CMD_GET
);
1559 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1561 stats
->dot11ACKFailureCount
=
1562 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
1563 stats
->dot11RTSFailureCount
=
1564 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
1565 stats
->dot11FCSErrorCount
=
1566 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
1567 stats
->dot11RTSSuccessCount
=
1568 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
1576 * CMD_802_11_RADIO_CONTROL.
1578 struct mwl8k_cmd_802_11_radio_control
{
1579 struct mwl8k_cmd_pkt header
;
1583 } __attribute__((packed
));
1586 mwl8k_cmd_802_11_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
1588 struct mwl8k_priv
*priv
= hw
->priv
;
1589 struct mwl8k_cmd_802_11_radio_control
*cmd
;
1592 if (enable
== priv
->radio_on
&& !force
)
1595 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1599 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
1600 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1601 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1602 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
1603 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
1605 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1609 priv
->radio_on
= enable
;
1614 static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw
*hw
)
1616 return mwl8k_cmd_802_11_radio_control(hw
, 0, 0);
1619 static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw
*hw
)
1621 return mwl8k_cmd_802_11_radio_control(hw
, 1, 0);
1625 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
1627 struct mwl8k_priv
*priv
;
1629 if (hw
== NULL
|| hw
->priv
== NULL
)
1633 priv
->radio_short_preamble
= short_preamble
;
1635 return mwl8k_cmd_802_11_radio_control(hw
, 1, 1);
1639 * CMD_802_11_RF_TX_POWER.
1641 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1643 struct mwl8k_cmd_802_11_rf_tx_power
{
1644 struct mwl8k_cmd_pkt header
;
1646 __le16 support_level
;
1647 __le16 current_level
;
1649 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
1650 } __attribute__((packed
));
1652 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
1654 struct mwl8k_cmd_802_11_rf_tx_power
*cmd
;
1657 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1661 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
1662 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1663 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1664 cmd
->support_level
= cpu_to_le16(dBm
);
1666 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1675 struct mwl8k_cmd_set_pre_scan
{
1676 struct mwl8k_cmd_pkt header
;
1677 } __attribute__((packed
));
1679 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
1681 struct mwl8k_cmd_set_pre_scan
*cmd
;
1684 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1688 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
1689 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1691 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1698 * CMD_SET_POST_SCAN.
1700 struct mwl8k_cmd_set_post_scan
{
1701 struct mwl8k_cmd_pkt header
;
1703 __u8 bssid
[ETH_ALEN
];
1704 } __attribute__((packed
));
1707 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, __u8
*mac
)
1709 struct mwl8k_cmd_set_post_scan
*cmd
;
1712 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1716 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
1717 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1719 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
1721 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1728 * CMD_SET_RF_CHANNEL.
1730 struct mwl8k_cmd_set_rf_channel
{
1731 struct mwl8k_cmd_pkt header
;
1733 __u8 current_channel
;
1734 __le32 channel_flags
;
1735 } __attribute__((packed
));
1737 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
1738 struct ieee80211_channel
*channel
)
1740 struct mwl8k_cmd_set_rf_channel
*cmd
;
1743 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1747 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
1748 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1749 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1750 cmd
->current_channel
= channel
->hw_value
;
1751 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1752 cmd
->channel_flags
= cpu_to_le32(0x00000081);
1754 cmd
->channel_flags
= cpu_to_le32(0x00000000);
1756 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1765 struct mwl8k_cmd_set_slot
{
1766 struct mwl8k_cmd_pkt header
;
1769 } __attribute__((packed
));
1771 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, bool short_slot_time
)
1773 struct mwl8k_cmd_set_slot
*cmd
;
1776 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1780 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
1781 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1782 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1783 cmd
->short_slot
= short_slot_time
;
1785 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1794 struct mwl8k_cmd_mimo_config
{
1795 struct mwl8k_cmd_pkt header
;
1797 __u8 rx_antenna_map
;
1798 __u8 tx_antenna_map
;
1799 } __attribute__((packed
));
1801 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
1803 struct mwl8k_cmd_mimo_config
*cmd
;
1806 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1810 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
1811 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1812 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
1813 cmd
->rx_antenna_map
= rx
;
1814 cmd
->tx_antenna_map
= tx
;
1816 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1823 * CMD_ENABLE_SNIFFER.
1825 struct mwl8k_cmd_enable_sniffer
{
1826 struct mwl8k_cmd_pkt header
;
1828 } __attribute__((packed
));
1830 static int mwl8k_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
1832 struct mwl8k_cmd_enable_sniffer
*cmd
;
1835 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1839 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
1840 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1841 cmd
->action
= cpu_to_le32(!!enable
);
1843 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1850 * CMD_SET_RATEADAPT_MODE.
1852 struct mwl8k_cmd_set_rate_adapt_mode
{
1853 struct mwl8k_cmd_pkt header
;
1856 } __attribute__((packed
));
1858 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw
*hw
, __u16 mode
)
1860 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
1863 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1867 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
1868 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1869 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1870 cmd
->mode
= cpu_to_le16(mode
);
1872 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1881 struct mwl8k_cmd_set_wmm
{
1882 struct mwl8k_cmd_pkt header
;
1884 } __attribute__((packed
));
1886 static int mwl8k_set_wmm(struct ieee80211_hw
*hw
, bool enable
)
1888 struct mwl8k_priv
*priv
= hw
->priv
;
1889 struct mwl8k_cmd_set_wmm
*cmd
;
1892 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1896 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
1897 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1898 cmd
->action
= cpu_to_le16(!!enable
);
1900 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1904 priv
->wmm_enabled
= enable
;
1910 * CMD_SET_RTS_THRESHOLD.
1912 struct mwl8k_cmd_rts_threshold
{
1913 struct mwl8k_cmd_pkt header
;
1916 } __attribute__((packed
));
1918 static int mwl8k_rts_threshold(struct ieee80211_hw
*hw
,
1919 u16 action
, u16
*threshold
)
1921 struct mwl8k_cmd_rts_threshold
*cmd
;
1924 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1928 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
1929 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1930 cmd
->action
= cpu_to_le16(action
);
1931 cmd
->threshold
= cpu_to_le16(*threshold
);
1933 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1940 * CMD_SET_EDCA_PARAMS.
1942 struct mwl8k_cmd_set_edca_params
{
1943 struct mwl8k_cmd_pkt header
;
1945 /* See MWL8K_SET_EDCA_XXX below */
1948 /* TX opportunity in units of 32 us */
1951 /* Log exponent of max contention period: 0...15*/
1954 /* Log exponent of min contention period: 0...15 */
1957 /* Adaptive interframe spacing in units of 32us */
1960 /* TX queue to configure */
1962 } __attribute__((packed
));
1964 #define MWL8K_SET_EDCA_CW 0x01
1965 #define MWL8K_SET_EDCA_TXOP 0x02
1966 #define MWL8K_SET_EDCA_AIFS 0x04
1968 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
1969 MWL8K_SET_EDCA_TXOP | \
1970 MWL8K_SET_EDCA_AIFS)
1973 mwl8k_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
1974 __u16 cw_min
, __u16 cw_max
,
1975 __u8 aifs
, __u16 txop
)
1977 struct mwl8k_cmd_set_edca_params
*cmd
;
1980 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1984 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
1985 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1986 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
1987 cmd
->txop
= cpu_to_le16(txop
);
1988 cmd
->log_cw_max
= (u8
)ilog2(cw_max
+ 1);
1989 cmd
->log_cw_min
= (u8
)ilog2(cw_min
+ 1);
1993 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2000 * CMD_FINALIZE_JOIN.
2003 /* FJ beacon buffer size is compiled into the firmware. */
2004 #define MWL8K_FJ_BEACON_MAXLEN 128
2006 struct mwl8k_cmd_finalize_join
{
2007 struct mwl8k_cmd_pkt header
;
2008 __le32 sleep_interval
; /* Number of beacon periods to sleep */
2009 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
2010 } __attribute__((packed
));
2012 static int mwl8k_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
2013 __u16 framelen
, __u16 dtim
)
2015 struct mwl8k_cmd_finalize_join
*cmd
;
2016 struct ieee80211_mgmt
*payload
= frame
;
2024 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2028 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
2029 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2030 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
2032 hdrlen
= ieee80211_hdrlen(payload
->frame_control
);
2034 payload_len
= framelen
> hdrlen
? framelen
- hdrlen
: 0;
2036 /* XXX TBD Might just have to abort and return an error */
2037 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2038 printk(KERN_ERR
"%s(): WARNING: Incomplete beacon "
2039 "sent to firmware. Sz=%u MAX=%u\n", __func__
,
2040 payload_len
, MWL8K_FJ_BEACON_MAXLEN
);
2042 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2043 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
2045 if (payload
&& payload_len
)
2046 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
2048 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2056 struct mwl8k_cmd_update_sta_db
{
2057 struct mwl8k_cmd_pkt header
;
2059 /* See STADB_ACTION_TYPE */
2062 /* Peer MAC address */
2063 __u8 peer_addr
[ETH_ALEN
];
2067 /* Peer info - valid during add/update. */
2068 struct peer_capability_info peer_info
;
2069 } __attribute__((packed
));
2071 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw
*hw
,
2072 struct ieee80211_vif
*vif
, __u32 action
)
2074 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2075 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2076 struct mwl8k_cmd_update_sta_db
*cmd
;
2077 struct peer_capability_info
*peer_info
;
2078 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2082 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2086 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
2087 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2089 cmd
->action
= cpu_to_le32(action
);
2090 peer_info
= &cmd
->peer_info
;
2091 memcpy(cmd
->peer_addr
, mv_vif
->bssid
, ETH_ALEN
);
2094 case MWL8K_STA_DB_ADD_ENTRY
:
2095 case MWL8K_STA_DB_MODIFY_ENTRY
:
2096 /* Build peer_info block */
2097 peer_info
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
2098 peer_info
->basic_caps
= cpu_to_le16(info
->assoc_capability
);
2099 peer_info
->interop
= 1;
2100 peer_info
->amsdu_enabled
= 0;
2102 rates
= peer_info
->legacy_rates
;
2103 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2104 rates
[count
] = bitrates
[count
].hw_value
;
2106 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2108 mv_vif
->peer_id
= peer_info
->station_id
;
2112 case MWL8K_STA_DB_DEL_ENTRY
:
2113 case MWL8K_STA_DB_FLUSH
:
2115 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2117 mv_vif
->peer_id
= 0;
2128 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2130 #define MWL8K_FRAME_PROT_DISABLED 0x00
2131 #define MWL8K_FRAME_PROT_11G 0x07
2132 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2133 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2135 struct mwl8k_cmd_update_set_aid
{
2136 struct mwl8k_cmd_pkt header
;
2139 /* AP's MAC address (BSSID) */
2140 __u8 bssid
[ETH_ALEN
];
2141 __le16 protection_mode
;
2142 __u8 supp_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2143 } __attribute__((packed
));
2145 static int mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
2146 struct ieee80211_vif
*vif
)
2148 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2149 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2150 struct mwl8k_cmd_update_set_aid
*cmd
;
2151 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2156 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2160 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
2161 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2162 cmd
->aid
= cpu_to_le16(info
->aid
);
2164 memcpy(cmd
->bssid
, mv_vif
->bssid
, ETH_ALEN
);
2166 if (info
->use_cts_prot
) {
2167 prot_mode
= MWL8K_FRAME_PROT_11G
;
2169 switch (info
->ht_operation_mode
&
2170 IEEE80211_HT_OP_MODE_PROTECTION
) {
2171 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
2172 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
2174 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
2175 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
2178 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
2182 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
2184 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2185 cmd
->supp_rates
[count
] = bitrates
[count
].hw_value
;
2187 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2196 struct mwl8k_cmd_update_rateset
{
2197 struct mwl8k_cmd_pkt header
;
2198 __u8 legacy_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2200 /* Bitmap for supported MCS codes. */
2201 __u8 mcs_set
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2202 __u8 reserved
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2203 } __attribute__((packed
));
2205 static int mwl8k_update_rateset(struct ieee80211_hw
*hw
,
2206 struct ieee80211_vif
*vif
)
2208 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2209 struct mwl8k_cmd_update_rateset
*cmd
;
2210 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2214 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2218 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
2219 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2221 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2222 cmd
->legacy_rates
[count
] = bitrates
[count
].hw_value
;
2224 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2231 * CMD_USE_FIXED_RATE.
2233 #define MWL8K_RATE_TABLE_SIZE 8
2234 #define MWL8K_UCAST_RATE 0
2235 #define MWL8K_USE_AUTO_RATE 0x0002
2237 struct mwl8k_rate_entry
{
2238 /* Set to 1 if HT rate, 0 if legacy. */
2241 /* Set to 1 to use retry_count field. */
2242 __le32 enable_retry
;
2244 /* Specified legacy rate or MCS. */
2247 /* Number of allowed retries. */
2249 } __attribute__((packed
));
2251 struct mwl8k_rate_table
{
2252 /* 1 to allow specified rate and below */
2253 __le32 allow_rate_drop
;
2255 struct mwl8k_rate_entry rate_entry
[MWL8K_RATE_TABLE_SIZE
];
2256 } __attribute__((packed
));
2258 struct mwl8k_cmd_use_fixed_rate
{
2259 struct mwl8k_cmd_pkt header
;
2261 struct mwl8k_rate_table rate_table
;
2263 /* Unicast, Broadcast or Multicast */
2267 } __attribute__((packed
));
2269 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw
*hw
,
2270 u32 action
, u32 rate_type
, struct mwl8k_rate_table
*rate_table
)
2272 struct mwl8k_cmd_use_fixed_rate
*cmd
;
2276 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2280 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2281 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2283 cmd
->action
= cpu_to_le32(action
);
2284 cmd
->rate_type
= cpu_to_le32(rate_type
);
2286 if (rate_table
!= NULL
) {
2287 /* Copy over each field manually so
2288 * that bitflipping can be done
2290 cmd
->rate_table
.allow_rate_drop
=
2291 cpu_to_le32(rate_table
->allow_rate_drop
);
2292 cmd
->rate_table
.num_rates
=
2293 cpu_to_le32(rate_table
->num_rates
);
2295 for (count
= 0; count
< rate_table
->num_rates
; count
++) {
2296 struct mwl8k_rate_entry
*dst
=
2297 &cmd
->rate_table
.rate_entry
[count
];
2298 struct mwl8k_rate_entry
*src
=
2299 &rate_table
->rate_entry
[count
];
2301 dst
->is_ht_rate
= cpu_to_le32(src
->is_ht_rate
);
2302 dst
->enable_retry
= cpu_to_le32(src
->enable_retry
);
2303 dst
->rate
= cpu_to_le32(src
->rate
);
2304 dst
->retry_count
= cpu_to_le32(src
->retry_count
);
2308 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2316 * Interrupt handling.
2318 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
2320 struct ieee80211_hw
*hw
= dev_id
;
2321 struct mwl8k_priv
*priv
= hw
->priv
;
2324 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2325 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2330 if (status
& MWL8K_A2H_INT_TX_DONE
)
2331 tasklet_schedule(&priv
->tx_reclaim_task
);
2333 if (status
& MWL8K_A2H_INT_RX_READY
) {
2334 while (rxq_process(hw
, 0, 1))
2335 rxq_refill(hw
, 0, 1);
2338 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
2339 if (priv
->hostcmd_wait
!= NULL
) {
2340 complete(priv
->hostcmd_wait
);
2341 priv
->hostcmd_wait
= NULL
;
2345 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
2346 if (!priv
->inconfig
&&
2348 mwl8k_txq_busy(priv
))
2349 mwl8k_tx_start(priv
);
2357 * Core driver operations.
2359 static int mwl8k_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2361 struct mwl8k_priv
*priv
= hw
->priv
;
2362 int index
= skb_get_queue_mapping(skb
);
2365 if (priv
->current_channel
== NULL
) {
2366 printk(KERN_DEBUG
"%s: dropped TX frame since radio "
2367 "disabled\n", priv
->name
);
2369 return NETDEV_TX_OK
;
2372 rc
= mwl8k_txq_xmit(hw
, index
, skb
);
2377 struct mwl8k_work_struct
{
2378 /* Initialized by mwl8k_queue_work(). */
2379 struct work_struct wt
;
2381 /* Required field passed in to mwl8k_queue_work(). */
2382 struct ieee80211_hw
*hw
;
2384 /* Required field passed in to mwl8k_queue_work(). */
2385 int (*wfunc
)(struct work_struct
*w
);
2387 /* Initialized by mwl8k_queue_work(). */
2388 struct completion
*cmd_wait
;
2394 * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
2395 * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
2399 /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
2400 unsigned long timeout_ms
;
2402 /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
2403 u32 txwait_attempts
;
2405 /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
2410 /* Flags controlling behavior of config queue requests */
2412 /* Caller spins while waiting for completion. */
2413 #define MWL8K_WQ_SPIN 0x00000001
2415 /* Wait for TX queues to empty before proceeding with configuration. */
2416 #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
2418 /* Queue request and return immediately. */
2419 #define MWL8K_WQ_POST_REQUEST 0x00000004
2422 * Caller sleeps and waits for task complete notification.
2423 * Do not use in atomic context.
2425 #define MWL8K_WQ_SLEEP 0x00000008
2427 /* Free work struct when task is done. */
2428 #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
2431 * Config request is queued and returns to caller imediately. Use
2432 * this in atomic context. Work struct is freed by mwl8k_queue_work()
2433 * when this flag is set.
2435 #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
2436 MWL8K_WQ_FREE_WORKSTRUCT)
2438 /* Default work queue behavior is to sleep and wait for tx completion. */
2439 #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
2442 * Default config request timeout. Add adjustments to make sure the
2443 * config thread waits long enough for both tx wait and cmd wait before
2447 /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
2448 #define MWL8K_TXWAIT_TIMEOUT_MS 1000
2450 /* Default number of TX wait attempts. */
2451 #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
2453 /* Total time to wait for TXQ to drain. */
2454 #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
2455 MWL8K_WQ_TXWAIT_ATTEMPTS)
2457 /* Scheduling slop. */
2458 #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
2460 #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
2462 MWL8K_OS_SCHEDULE_OVERHEAD_MS)
2464 static void mwl8k_config_thread(struct work_struct
*wt
)
2466 struct mwl8k_work_struct
*worker
= (struct mwl8k_work_struct
*)wt
;
2467 struct ieee80211_hw
*hw
= worker
->hw
;
2468 struct mwl8k_priv
*priv
= hw
->priv
;
2471 spin_lock_irq(&priv
->tx_lock
);
2472 priv
->inconfig
= true;
2473 spin_unlock_irq(&priv
->tx_lock
);
2475 ieee80211_stop_queues(hw
);
2478 * Wait for host queues to drain before doing PHY
2479 * reconfiguration. This avoids interrupting any in-flight
2480 * DMA transfers to the hardware.
2482 if (worker
->options
& MWL8K_WQ_TX_WAIT_EMPTY
) {
2486 u32 tx_wait_attempts
= worker
->txwait_attempts
;
2488 time_remaining
= worker
->tx_timeout_ms
;
2489 if (!tx_wait_attempts
)
2490 tx_wait_attempts
= 1;
2492 timeout
= worker
->tx_timeout_ms
/tx_wait_attempts
;
2496 iter
= tx_wait_attempts
;
2500 if (time_remaining
> timeout
) {
2501 time_remaining
-= timeout
;
2502 wait_time
= timeout
;
2504 wait_time
= time_remaining
;
2509 rc
= mwl8k_tx_wait_empty(hw
, wait_time
);
2511 printk(KERN_ERR
"%s() txwait timeout=%ums "
2512 "Retry:%u/%u\n", __func__
, timeout
,
2513 tx_wait_attempts
- iter
+ 1,
2516 } while (rc
&& --iter
);
2518 rc
= iter
? 0 : -ETIMEDOUT
;
2521 rc
= worker
->wfunc(wt
);
2523 spin_lock_irq(&priv
->tx_lock
);
2524 priv
->inconfig
= false;
2525 if (priv
->pending_tx_pkts
&& priv
->radio_on
)
2526 mwl8k_tx_start(priv
);
2527 spin_unlock_irq(&priv
->tx_lock
);
2528 ieee80211_wake_queues(hw
);
2531 if (worker
->options
& MWL8K_WQ_SLEEP
)
2532 complete(worker
->cmd_wait
);
2534 if (worker
->options
& MWL8K_WQ_FREE_WORKSTRUCT
)
2538 static int mwl8k_queue_work(struct ieee80211_hw
*hw
,
2539 struct mwl8k_work_struct
*worker
,
2540 struct workqueue_struct
*wqueue
,
2541 int (*wfunc
)(struct work_struct
*w
))
2543 unsigned long timeout
= 0;
2546 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
2548 if (!worker
->timeout_ms
)
2549 worker
->timeout_ms
= MWL8K_CONFIG_TIMEOUT_MS
;
2551 if (!worker
->options
)
2552 worker
->options
= MWL8K_WQ_DEFAULT_OPTIONS
;
2554 if (!worker
->txwait_attempts
)
2555 worker
->txwait_attempts
= MWL8K_WQ_TXWAIT_ATTEMPTS
;
2557 if (!worker
->tx_timeout_ms
)
2558 worker
->tx_timeout_ms
= MWL8K_TXWAIT_MS
;
2561 worker
->cmd_wait
= &cmd_wait
;
2563 worker
->wfunc
= wfunc
;
2565 INIT_WORK(&worker
->wt
, mwl8k_config_thread
);
2566 queue_work(wqueue
, &worker
->wt
);
2568 if (worker
->options
& MWL8K_WQ_POST_REQUEST
) {
2571 if (worker
->options
& MWL8K_WQ_SPIN
) {
2572 timeout
= worker
->timeout_ms
;
2573 while (timeout
&& (worker
->rc
> 0)) {
2577 } else if (worker
->options
& MWL8K_WQ_SLEEP
)
2578 timeout
= wait_for_completion_timeout(&cmd_wait
,
2579 msecs_to_jiffies(worker
->timeout_ms
));
2584 cancel_work_sync(&worker
->wt
);
2592 struct mwl8k_start_worker
{
2593 struct mwl8k_work_struct header
;
2596 static int mwl8k_start_wt(struct work_struct
*wt
)
2598 struct mwl8k_start_worker
*worker
= (struct mwl8k_start_worker
*)wt
;
2599 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2600 struct mwl8k_priv
*priv
= hw
->priv
;
2603 if (priv
->vif
!= NULL
) {
2605 goto mwl8k_start_exit
;
2609 if (mwl8k_cmd_802_11_radio_enable(hw
)) {
2611 goto mwl8k_start_exit
;
2614 /* Purge TX/RX HW queues */
2615 if (mwl8k_cmd_set_pre_scan(hw
)) {
2617 goto mwl8k_start_exit
;
2620 if (mwl8k_cmd_set_post_scan(hw
, "\x00\x00\x00\x00\x00\x00")) {
2622 goto mwl8k_start_exit
;
2625 /* Enable firmware rate adaptation */
2626 if (mwl8k_cmd_setrateadaptmode(hw
, 0)) {
2628 goto mwl8k_start_exit
;
2631 /* Disable WMM. WMM gets enabled when stack sends WMM parms */
2632 if (mwl8k_set_wmm(hw
, 0)) {
2634 goto mwl8k_start_exit
;
2637 /* Disable sniffer mode */
2638 if (mwl8k_enable_sniffer(hw
, 0))
2645 static int mwl8k_start(struct ieee80211_hw
*hw
)
2647 struct mwl8k_start_worker
*worker
;
2648 struct mwl8k_priv
*priv
= hw
->priv
;
2651 /* Enable tx reclaim tasklet */
2652 tasklet_enable(&priv
->tx_reclaim_task
);
2654 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
2655 IRQF_SHARED
, MWL8K_NAME
, hw
);
2657 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
2660 goto mwl8k_start_disable_tasklet
;
2663 /* Enable interrupts */
2664 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2666 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2667 if (worker
== NULL
) {
2669 goto mwl8k_start_disable_irq
;
2672 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2673 priv
->config_wq
, mwl8k_start_wt
);
2678 if (rc
== -ETIMEDOUT
)
2679 printk(KERN_ERR
"%s() timed out\n", __func__
);
2683 mwl8k_start_disable_irq
:
2684 spin_lock_irq(&priv
->tx_lock
);
2685 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2686 spin_unlock_irq(&priv
->tx_lock
);
2687 free_irq(priv
->pdev
->irq
, hw
);
2689 mwl8k_start_disable_tasklet
:
2690 tasklet_disable(&priv
->tx_reclaim_task
);
2695 struct mwl8k_stop_worker
{
2696 struct mwl8k_work_struct header
;
2699 static int mwl8k_stop_wt(struct work_struct
*wt
)
2701 struct mwl8k_stop_worker
*worker
= (struct mwl8k_stop_worker
*)wt
;
2702 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2704 return mwl8k_cmd_802_11_radio_disable(hw
);
2707 static void mwl8k_stop(struct ieee80211_hw
*hw
)
2710 struct mwl8k_stop_worker
*worker
;
2711 struct mwl8k_priv
*priv
= hw
->priv
;
2714 if (priv
->vif
!= NULL
)
2717 ieee80211_stop_queues(hw
);
2719 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2723 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2724 priv
->config_wq
, mwl8k_stop_wt
);
2726 if (rc
== -ETIMEDOUT
)
2727 printk(KERN_ERR
"%s() timed out\n", __func__
);
2729 /* Disable interrupts */
2730 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2731 free_irq(priv
->pdev
->irq
, hw
);
2733 /* Stop finalize join worker */
2734 cancel_work_sync(&priv
->finalize_join_worker
);
2735 if (priv
->beacon_skb
!= NULL
)
2736 dev_kfree_skb(priv
->beacon_skb
);
2738 /* Stop tx reclaim tasklet */
2739 tasklet_disable(&priv
->tx_reclaim_task
);
2741 /* Stop config thread */
2742 flush_workqueue(priv
->config_wq
);
2744 /* Return all skbs to mac80211 */
2745 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2746 mwl8k_txq_reclaim(hw
, i
, 1);
2749 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
2750 struct ieee80211_if_init_conf
*conf
)
2752 struct mwl8k_priv
*priv
= hw
->priv
;
2753 struct mwl8k_vif
*mwl8k_vif
;
2756 * We only support one active interface at a time.
2758 if (priv
->vif
!= NULL
)
2762 * We only support managed interfaces for now.
2764 if (conf
->type
!= NL80211_IFTYPE_STATION
)
2767 /* Clean out driver private area */
2768 mwl8k_vif
= MWL8K_VIF(conf
->vif
);
2769 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
2771 /* Save the mac address */
2772 memcpy(mwl8k_vif
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
2774 /* Back pointer to parent config block */
2775 mwl8k_vif
->priv
= priv
;
2777 /* Setup initial PHY parameters */
2778 memcpy(mwl8k_vif
->legacy_rates
,
2779 priv
->rates
, sizeof(mwl8k_vif
->legacy_rates
));
2780 mwl8k_vif
->legacy_nrates
= ARRAY_SIZE(priv
->rates
);
2782 /* Set Initial sequence number to zero */
2783 mwl8k_vif
->seqno
= 0;
2785 priv
->vif
= conf
->vif
;
2786 priv
->current_channel
= NULL
;
2791 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
2792 struct ieee80211_if_init_conf
*conf
)
2794 struct mwl8k_priv
*priv
= hw
->priv
;
2796 if (priv
->vif
== NULL
)
2802 struct mwl8k_config_worker
{
2803 struct mwl8k_work_struct header
;
2807 static int mwl8k_config_wt(struct work_struct
*wt
)
2809 struct mwl8k_config_worker
*worker
=
2810 (struct mwl8k_config_worker
*)wt
;
2811 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2812 struct ieee80211_conf
*conf
= &hw
->conf
;
2813 struct mwl8k_priv
*priv
= hw
->priv
;
2816 if (conf
->flags
& IEEE80211_CONF_IDLE
) {
2817 mwl8k_cmd_802_11_radio_disable(hw
);
2818 priv
->current_channel
= NULL
;
2819 goto mwl8k_config_exit
;
2822 if (mwl8k_cmd_802_11_radio_enable(hw
)) {
2824 goto mwl8k_config_exit
;
2827 priv
->current_channel
= conf
->channel
;
2829 if (mwl8k_cmd_set_rf_channel(hw
, conf
->channel
)) {
2831 goto mwl8k_config_exit
;
2834 if (conf
->power_level
> 18)
2835 conf
->power_level
= 18;
2836 if (mwl8k_cmd_802_11_rf_tx_power(hw
, conf
->power_level
)) {
2838 goto mwl8k_config_exit
;
2841 if (mwl8k_cmd_mimo_config(hw
, 0x7, 0x7))
2848 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
2851 struct mwl8k_config_worker
*worker
;
2852 struct mwl8k_priv
*priv
= hw
->priv
;
2854 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2858 worker
->changed
= changed
;
2859 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2860 priv
->config_wq
, mwl8k_config_wt
);
2861 if (rc
== -ETIMEDOUT
) {
2862 printk(KERN_ERR
"%s() timed out.\n", __func__
);
2869 * mac80211 will crash on anything other than -EINVAL on
2870 * error. Looks like wireless extensions which calls mac80211
2871 * may be the actual culprit...
2873 return rc
? -EINVAL
: 0;
2876 struct mwl8k_bss_info_changed_worker
{
2877 struct mwl8k_work_struct header
;
2878 struct ieee80211_vif
*vif
;
2879 struct ieee80211_bss_conf
*info
;
2883 static int mwl8k_bss_info_changed_wt(struct work_struct
*wt
)
2885 struct mwl8k_bss_info_changed_worker
*worker
=
2886 (struct mwl8k_bss_info_changed_worker
*)wt
;
2887 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2888 struct ieee80211_vif
*vif
= worker
->vif
;
2889 struct ieee80211_bss_conf
*info
= worker
->info
;
2893 struct mwl8k_priv
*priv
= hw
->priv
;
2894 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
2896 changed
= worker
->changed
;
2897 priv
->capture_beacon
= false;
2900 memcpy(&mwl8k_vif
->bss_info
, info
,
2901 sizeof(struct ieee80211_bss_conf
));
2904 if (mwl8k_update_rateset(hw
, vif
))
2905 goto mwl8k_bss_info_changed_exit
;
2907 /* Turn on rate adaptation */
2908 if (mwl8k_cmd_use_fixed_rate(hw
, MWL8K_USE_AUTO_RATE
,
2909 MWL8K_UCAST_RATE
, NULL
))
2910 goto mwl8k_bss_info_changed_exit
;
2912 /* Set radio preamble */
2913 if (mwl8k_set_radio_preamble(hw
, info
->use_short_preamble
))
2914 goto mwl8k_bss_info_changed_exit
;
2917 if (mwl8k_cmd_set_slot(hw
, info
->use_short_slot
))
2918 goto mwl8k_bss_info_changed_exit
;
2920 /* Update peer rate info */
2921 if (mwl8k_cmd_update_sta_db(hw
, vif
,
2922 MWL8K_STA_DB_MODIFY_ENTRY
))
2923 goto mwl8k_bss_info_changed_exit
;
2926 if (mwl8k_cmd_set_aid(hw
, vif
))
2927 goto mwl8k_bss_info_changed_exit
;
2930 * Finalize the join. Tell rx handler to process
2931 * next beacon from our BSSID.
2933 memcpy(priv
->capture_bssid
, mwl8k_vif
->bssid
, ETH_ALEN
);
2934 priv
->capture_beacon
= true;
2936 mwl8k_cmd_update_sta_db(hw
, vif
, MWL8K_STA_DB_DEL_ENTRY
);
2937 memset(&mwl8k_vif
->bss_info
, 0,
2938 sizeof(struct ieee80211_bss_conf
));
2939 memset(mwl8k_vif
->bssid
, 0, ETH_ALEN
);
2942 mwl8k_bss_info_changed_exit
:
2947 static void mwl8k_bss_info_changed(struct ieee80211_hw
*hw
,
2948 struct ieee80211_vif
*vif
,
2949 struct ieee80211_bss_conf
*info
,
2952 struct mwl8k_bss_info_changed_worker
*worker
;
2953 struct mwl8k_priv
*priv
= hw
->priv
;
2954 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2957 if (changed
& BSS_CHANGED_BSSID
)
2958 memcpy(mv_vif
->bssid
, info
->bssid
, ETH_ALEN
);
2960 if ((changed
& BSS_CHANGED_ASSOC
) == 0)
2963 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2968 worker
->info
= info
;
2969 worker
->changed
= changed
;
2970 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2972 mwl8k_bss_info_changed_wt
);
2974 if (rc
== -ETIMEDOUT
)
2975 printk(KERN_ERR
"%s() timed out\n", __func__
);
2978 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
2979 int mc_count
, struct dev_addr_list
*mclist
)
2981 struct mwl8k_cmd_pkt
*cmd
;
2983 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, mc_count
, mclist
);
2985 return (unsigned long)cmd
;
2988 struct mwl8k_configure_filter_worker
{
2989 struct mwl8k_work_struct header
;
2990 unsigned int changed_flags
;
2991 unsigned int total_flags
;
2992 struct mwl8k_cmd_pkt
*multicast_adr_cmd
;
2995 #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
2997 static int mwl8k_configure_filter_wt(struct work_struct
*wt
)
2999 struct mwl8k_configure_filter_worker
*worker
=
3000 (struct mwl8k_configure_filter_worker
*)wt
;
3001 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3002 struct mwl8k_priv
*priv
= hw
->priv
;
3005 if (worker
->changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
3006 if (worker
->total_flags
& FIF_BCN_PRBRESP_PROMISC
)
3007 rc
= mwl8k_cmd_set_pre_scan(hw
);
3011 bssid
= "\x00\x00\x00\x00\x00\x00";
3012 if (priv
->vif
!= NULL
)
3013 bssid
= MWL8K_VIF(priv
->vif
)->bssid
;
3015 rc
= mwl8k_cmd_set_post_scan(hw
, bssid
);
3019 if (!rc
&& worker
->multicast_adr_cmd
!= NULL
)
3020 rc
= mwl8k_post_cmd(hw
, worker
->multicast_adr_cmd
);
3021 kfree(worker
->multicast_adr_cmd
);
3026 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
3027 unsigned int changed_flags
,
3028 unsigned int *total_flags
,
3031 struct mwl8k_priv
*priv
= hw
->priv
;
3032 struct mwl8k_configure_filter_worker
*worker
;
3034 /* Clear unsupported feature flags */
3035 *total_flags
&= MWL8K_SUPPORTED_IF_FLAGS
;
3037 if (!(changed_flags
& MWL8K_SUPPORTED_IF_FLAGS
))
3040 worker
= kzalloc(sizeof(*worker
), GFP_ATOMIC
);
3044 worker
->changed_flags
= changed_flags
;
3045 worker
->total_flags
= *total_flags
;
3046 worker
->multicast_adr_cmd
= (void *)(unsigned long)multicast
;
3048 mwl8k_queue_work(hw
, &worker
->header
, priv
->config_wq
,
3049 mwl8k_configure_filter_wt
);
3052 struct mwl8k_set_rts_threshold_worker
{
3053 struct mwl8k_work_struct header
;
3057 static int mwl8k_set_rts_threshold_wt(struct work_struct
*wt
)
3059 struct mwl8k_set_rts_threshold_worker
*worker
=
3060 (struct mwl8k_set_rts_threshold_worker
*)wt
;
3062 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3063 u16 threshold
= (u16
)(worker
->value
);
3066 rc
= mwl8k_rts_threshold(hw
, MWL8K_CMD_SET
, &threshold
);
3071 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3074 struct mwl8k_set_rts_threshold_worker
*worker
;
3075 struct mwl8k_priv
*priv
= hw
->priv
;
3077 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3081 worker
->value
= value
;
3083 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3085 mwl8k_set_rts_threshold_wt
);
3088 if (rc
== -ETIMEDOUT
) {
3089 printk(KERN_ERR
"%s() timed out\n", __func__
);
3096 struct mwl8k_conf_tx_worker
{
3097 struct mwl8k_work_struct header
;
3099 const struct ieee80211_tx_queue_params
*params
;
3102 static int mwl8k_conf_tx_wt(struct work_struct
*wt
)
3104 struct mwl8k_conf_tx_worker
*worker
=
3105 (struct mwl8k_conf_tx_worker
*)wt
;
3107 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3108 u16 queue
= worker
->queue
;
3109 const struct ieee80211_tx_queue_params
*params
= worker
->params
;
3111 struct mwl8k_priv
*priv
= hw
->priv
;
3114 if (!priv
->wmm_enabled
) {
3115 if (mwl8k_set_wmm(hw
, 1)) {
3117 goto mwl8k_conf_tx_exit
;
3121 if (mwl8k_set_edca_params(hw
, GET_TXQ(queue
), params
->cw_min
,
3122 params
->cw_max
, params
->aifs
, params
->txop
))
3128 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
3129 const struct ieee80211_tx_queue_params
*params
)
3132 struct mwl8k_conf_tx_worker
*worker
;
3133 struct mwl8k_priv
*priv
= hw
->priv
;
3135 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3139 worker
->queue
= queue
;
3140 worker
->params
= params
;
3141 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3142 priv
->config_wq
, mwl8k_conf_tx_wt
);
3144 if (rc
== -ETIMEDOUT
) {
3145 printk(KERN_ERR
"%s() timed out\n", __func__
);
3151 static int mwl8k_get_tx_stats(struct ieee80211_hw
*hw
,
3152 struct ieee80211_tx_queue_stats
*stats
)
3154 struct mwl8k_priv
*priv
= hw
->priv
;
3155 struct mwl8k_tx_queue
*txq
;
3158 spin_lock_bh(&priv
->tx_lock
);
3159 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++) {
3160 txq
= priv
->txq
+ index
;
3161 memcpy(&stats
[index
], &txq
->tx_stats
,
3162 sizeof(struct ieee80211_tx_queue_stats
));
3164 spin_unlock_bh(&priv
->tx_lock
);
3168 struct mwl8k_get_stats_worker
{
3169 struct mwl8k_work_struct header
;
3170 struct ieee80211_low_level_stats
*stats
;
3173 static int mwl8k_get_stats_wt(struct work_struct
*wt
)
3175 struct mwl8k_get_stats_worker
*worker
=
3176 (struct mwl8k_get_stats_worker
*)wt
;
3178 return mwl8k_cmd_802_11_get_stat(worker
->header
.hw
, worker
->stats
);
3181 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
3182 struct ieee80211_low_level_stats
*stats
)
3185 struct mwl8k_get_stats_worker
*worker
;
3186 struct mwl8k_priv
*priv
= hw
->priv
;
3188 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3192 worker
->stats
= stats
;
3193 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3194 priv
->config_wq
, mwl8k_get_stats_wt
);
3197 if (rc
== -ETIMEDOUT
) {
3198 printk(KERN_ERR
"%s() timed out\n", __func__
);
3205 static const struct ieee80211_ops mwl8k_ops
= {
3207 .start
= mwl8k_start
,
3209 .add_interface
= mwl8k_add_interface
,
3210 .remove_interface
= mwl8k_remove_interface
,
3211 .config
= mwl8k_config
,
3212 .bss_info_changed
= mwl8k_bss_info_changed
,
3213 .prepare_multicast
= mwl8k_prepare_multicast
,
3214 .configure_filter
= mwl8k_configure_filter
,
3215 .set_rts_threshold
= mwl8k_set_rts_threshold
,
3216 .conf_tx
= mwl8k_conf_tx
,
3217 .get_tx_stats
= mwl8k_get_tx_stats
,
3218 .get_stats
= mwl8k_get_stats
,
3221 static void mwl8k_tx_reclaim_handler(unsigned long data
)
3224 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*) data
;
3225 struct mwl8k_priv
*priv
= hw
->priv
;
3227 spin_lock_bh(&priv
->tx_lock
);
3228 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3229 mwl8k_txq_reclaim(hw
, i
, 0);
3231 if (priv
->tx_wait
!= NULL
&& mwl8k_txq_busy(priv
) == 0) {
3232 complete(priv
->tx_wait
);
3233 priv
->tx_wait
= NULL
;
3235 spin_unlock_bh(&priv
->tx_lock
);
3238 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
3240 struct mwl8k_priv
*priv
=
3241 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
3242 struct sk_buff
*skb
= priv
->beacon_skb
;
3243 u8 dtim
= MWL8K_VIF(priv
->vif
)->bss_info
.dtim_period
;
3245 mwl8k_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim
);
3248 priv
->beacon_skb
= NULL
;
3251 static int __devinit
mwl8k_probe(struct pci_dev
*pdev
,
3252 const struct pci_device_id
*id
)
3254 struct ieee80211_hw
*hw
;
3255 struct mwl8k_priv
*priv
;
3260 rc
= pci_enable_device(pdev
);
3262 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
3267 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
3269 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
3274 pci_set_master(pdev
);
3276 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
3278 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
3286 priv
->hostcmd_wait
= NULL
;
3287 priv
->tx_wait
= NULL
;
3288 priv
->inconfig
= false;
3289 priv
->wmm_enabled
= false;
3290 priv
->pending_tx_pkts
= 0;
3291 strncpy(priv
->name
, MWL8K_NAME
, sizeof(priv
->name
));
3293 spin_lock_init(&priv
->fw_lock
);
3295 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
3296 pci_set_drvdata(pdev
, hw
);
3298 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
3299 if (priv
->regs
== NULL
) {
3300 printk(KERN_ERR
"%s: Cannot map device memory\n", priv
->name
);
3304 memcpy(priv
->channels
, mwl8k_channels
, sizeof(mwl8k_channels
));
3305 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
3306 priv
->band
.channels
= priv
->channels
;
3307 priv
->band
.n_channels
= ARRAY_SIZE(mwl8k_channels
);
3308 priv
->band
.bitrates
= priv
->rates
;
3309 priv
->band
.n_bitrates
= ARRAY_SIZE(mwl8k_rates
);
3310 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
3312 BUILD_BUG_ON(sizeof(priv
->rates
) != sizeof(mwl8k_rates
));
3313 memcpy(priv
->rates
, mwl8k_rates
, sizeof(mwl8k_rates
));
3316 * Extra headroom is the size of the required DMA header
3317 * minus the size of the smallest 802.11 frame (CTS frame).
3319 hw
->extra_tx_headroom
=
3320 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
3322 hw
->channel_change_time
= 10;
3324 hw
->queues
= MWL8K_TX_QUEUES
;
3326 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
3328 /* Set rssi and noise values to dBm */
3329 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
| IEEE80211_HW_NOISE_DBM
;
3330 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
3333 /* Set default radio state and preamble */
3335 priv
->radio_short_preamble
= 0;
3337 /* Finalize join worker */
3338 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
3340 /* TX reclaim tasklet */
3341 tasklet_init(&priv
->tx_reclaim_task
,
3342 mwl8k_tx_reclaim_handler
, (unsigned long)hw
);
3343 tasklet_disable(&priv
->tx_reclaim_task
);
3345 /* Config workthread */
3346 priv
->config_wq
= create_singlethread_workqueue("mwl8k_config");
3347 if (priv
->config_wq
== NULL
)
3350 /* Power management cookie */
3351 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
3352 if (priv
->cookie
== NULL
)
3355 rc
= mwl8k_rxq_init(hw
, 0);
3358 rxq_refill(hw
, 0, INT_MAX
);
3360 spin_lock_init(&priv
->tx_lock
);
3362 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
3363 rc
= mwl8k_txq_init(hw
, i
);
3365 goto err_free_queues
;
3368 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3369 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3370 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
3371 iowrite32(0xffffffff, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3373 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
3374 IRQF_SHARED
, MWL8K_NAME
, hw
);
3376 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
3378 goto err_free_queues
;
3381 /* Reset firmware and hardware */
3382 mwl8k_hw_reset(priv
);
3384 /* Ask userland hotplug daemon for the device firmware */
3385 rc
= mwl8k_request_firmware(priv
, (u32
)id
->driver_data
);
3387 printk(KERN_ERR
"%s: Firmware files not found\n", priv
->name
);
3391 /* Load firmware into hardware */
3392 rc
= mwl8k_load_firmware(priv
);
3394 printk(KERN_ERR
"%s: Cannot start firmware\n", priv
->name
);
3395 goto err_stop_firmware
;
3398 /* Reclaim memory once firmware is successfully loaded */
3399 mwl8k_release_firmware(priv
);
3402 * Temporarily enable interrupts. Initial firmware host
3403 * commands use interrupts and avoids polling. Disable
3404 * interrupts when done.
3406 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3408 /* Get config data, mac addrs etc */
3409 rc
= mwl8k_cmd_get_hw_spec(hw
);
3411 printk(KERN_ERR
"%s: Cannot initialise firmware\n", priv
->name
);
3412 goto err_stop_firmware
;
3415 /* Turn radio off */
3416 rc
= mwl8k_cmd_802_11_radio_disable(hw
);
3418 printk(KERN_ERR
"%s: Cannot disable\n", priv
->name
);
3419 goto err_stop_firmware
;
3422 /* Disable interrupts */
3423 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3424 free_irq(priv
->pdev
->irq
, hw
);
3426 rc
= ieee80211_register_hw(hw
);
3428 printk(KERN_ERR
"%s: Cannot register device\n", priv
->name
);
3429 goto err_stop_firmware
;
3432 fw
= (u8
*)&priv
->fw_rev
;
3433 printk(KERN_INFO
"%s: 88W%u %s\n", priv
->name
, priv
->part_num
,
3435 printk(KERN_INFO
"%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
3436 priv
->name
, MWL8K_VERSION
, fw
[3], fw
[2], fw
[1], fw
[0]);
3437 printk(KERN_INFO
"%s: MAC Address: %pM\n", priv
->name
,
3438 hw
->wiphy
->perm_addr
);
3443 mwl8k_hw_reset(priv
);
3444 mwl8k_release_firmware(priv
);
3447 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3448 free_irq(priv
->pdev
->irq
, hw
);
3451 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3452 mwl8k_txq_deinit(hw
, i
);
3453 mwl8k_rxq_deinit(hw
, 0);
3456 if (priv
->cookie
!= NULL
)
3457 pci_free_consistent(priv
->pdev
, 4,
3458 priv
->cookie
, priv
->cookie_dma
);
3460 if (priv
->regs
!= NULL
)
3461 pci_iounmap(pdev
, priv
->regs
);
3463 if (priv
->config_wq
!= NULL
)
3464 destroy_workqueue(priv
->config_wq
);
3466 pci_set_drvdata(pdev
, NULL
);
3467 ieee80211_free_hw(hw
);
3470 pci_release_regions(pdev
);
3471 pci_disable_device(pdev
);
3476 static void __devexit
mwl8k_shutdown(struct pci_dev
*pdev
)
3478 printk(KERN_ERR
"===>%s(%u)\n", __func__
, __LINE__
);
3481 static void __devexit
mwl8k_remove(struct pci_dev
*pdev
)
3483 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
3484 struct mwl8k_priv
*priv
;
3491 ieee80211_stop_queues(hw
);
3493 ieee80211_unregister_hw(hw
);
3495 /* Remove tx reclaim tasklet */
3496 tasklet_kill(&priv
->tx_reclaim_task
);
3498 /* Stop config thread */
3499 destroy_workqueue(priv
->config_wq
);
3502 mwl8k_hw_reset(priv
);
3504 /* Return all skbs to mac80211 */
3505 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3506 mwl8k_txq_reclaim(hw
, i
, 1);
3508 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3509 mwl8k_txq_deinit(hw
, i
);
3511 mwl8k_rxq_deinit(hw
, 0);
3513 pci_free_consistent(priv
->pdev
, 4,
3514 priv
->cookie
, priv
->cookie_dma
);
3516 pci_iounmap(pdev
, priv
->regs
);
3517 pci_set_drvdata(pdev
, NULL
);
3518 ieee80211_free_hw(hw
);
3519 pci_release_regions(pdev
);
3520 pci_disable_device(pdev
);
3523 static struct pci_driver mwl8k_driver
= {
3525 .id_table
= mwl8k_table
,
3526 .probe
= mwl8k_probe
,
3527 .remove
= __devexit_p(mwl8k_remove
),
3528 .shutdown
= __devexit_p(mwl8k_shutdown
),
3531 static int __init
mwl8k_init(void)
3533 return pci_register_driver(&mwl8k_driver
);
3536 static void __exit
mwl8k_exit(void)
3538 pci_unregister_driver(&mwl8k_driver
);
3541 module_init(mwl8k_init
);
3542 module_exit(mwl8k_exit
);