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
;
116 * The DMA engine requires a modification to the payload.
117 * If the skbuff is shared/cloned, it needs to be unshared.
118 * This method is used to ensure the stack always gets back
119 * the skbuff it sent for transmission.
121 struct sk_buff
*clone
;
125 struct mwl8k_tx_queue
{
126 /* hw transmits here */
129 /* sw appends here */
132 struct ieee80211_tx_queue_stats tx_stats
;
133 struct mwl8k_tx_desc
*tx_desc_area
;
134 dma_addr_t tx_desc_dma
;
135 struct mwl8k_skb
*tx_skb
;
138 /* Pointers to the firmware data and meta information about it. */
139 struct mwl8k_firmware
{
141 struct firmware
*ucode
;
143 /* Boot helper code */
144 struct firmware
*helper
;
149 struct ieee80211_hw
*hw
;
151 struct pci_dev
*pdev
;
153 /* firmware access lock */
156 /* firmware files and meta data */
157 struct mwl8k_firmware fw
;
160 /* lock held over TX and TX reap */
163 struct ieee80211_vif
*vif
;
165 struct ieee80211_channel
*current_channel
;
167 /* power management status cookie from firmware */
169 dma_addr_t cookie_dma
;
176 * Running count of TX packets in flight, to avoid
177 * iterating over the transmit rings each time.
181 struct mwl8k_rx_queue rxq
[MWL8K_RX_QUEUES
];
182 struct mwl8k_tx_queue txq
[MWL8K_TX_QUEUES
];
185 struct ieee80211_supported_band band
;
186 struct ieee80211_channel channels
[14];
187 struct ieee80211_rate rates
[12];
190 bool radio_short_preamble
;
193 /* Set if PHY config is in progress */
196 /* XXX need to convert this to handle multiple interfaces */
198 u8 capture_bssid
[ETH_ALEN
];
199 struct sk_buff
*beacon_skb
;
202 * This FJ worker has to be global as it is scheduled from the
203 * RX handler. At this point we don't know which interface it
204 * belongs to until the list of bssids waiting to complete join
207 struct work_struct finalize_join_worker
;
209 /* Tasklet to reclaim TX descriptors and buffers after tx */
210 struct tasklet_struct tx_reclaim_task
;
212 /* Work thread to serialize configuration requests */
213 struct workqueue_struct
*config_wq
;
214 struct completion
*hostcmd_wait
;
215 struct completion
*tx_wait
;
218 /* Per interface specific private data */
220 /* backpointer to parent config block */
221 struct mwl8k_priv
*priv
;
223 /* BSS config of AP or IBSS from mac80211*/
224 struct ieee80211_bss_conf bss_info
;
226 /* BSSID of AP or IBSS */
228 u8 mac_addr
[ETH_ALEN
];
231 * Subset of supported legacy rates.
232 * Intersection of AP and STA supported rates.
234 struct ieee80211_rate legacy_rates
[12];
236 /* number of supported legacy rates */
239 /* Index into station database.Returned by update_sta_db call */
242 /* Non AMPDU sequence number assigned by driver */
246 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
248 static const struct ieee80211_channel mwl8k_channels
[] = {
249 { .center_freq
= 2412, .hw_value
= 1, },
250 { .center_freq
= 2417, .hw_value
= 2, },
251 { .center_freq
= 2422, .hw_value
= 3, },
252 { .center_freq
= 2427, .hw_value
= 4, },
253 { .center_freq
= 2432, .hw_value
= 5, },
254 { .center_freq
= 2437, .hw_value
= 6, },
255 { .center_freq
= 2442, .hw_value
= 7, },
256 { .center_freq
= 2447, .hw_value
= 8, },
257 { .center_freq
= 2452, .hw_value
= 9, },
258 { .center_freq
= 2457, .hw_value
= 10, },
259 { .center_freq
= 2462, .hw_value
= 11, },
262 static const struct ieee80211_rate mwl8k_rates
[] = {
263 { .bitrate
= 10, .hw_value
= 2, },
264 { .bitrate
= 20, .hw_value
= 4, },
265 { .bitrate
= 55, .hw_value
= 11, },
266 { .bitrate
= 60, .hw_value
= 12, },
267 { .bitrate
= 90, .hw_value
= 18, },
268 { .bitrate
= 110, .hw_value
= 22, },
269 { .bitrate
= 120, .hw_value
= 24, },
270 { .bitrate
= 180, .hw_value
= 36, },
271 { .bitrate
= 240, .hw_value
= 48, },
272 { .bitrate
= 360, .hw_value
= 72, },
273 { .bitrate
= 480, .hw_value
= 96, },
274 { .bitrate
= 540, .hw_value
= 108, },
277 /* Set or get info from Firmware */
278 #define MWL8K_CMD_SET 0x0001
279 #define MWL8K_CMD_GET 0x0000
281 /* Firmware command codes */
282 #define MWL8K_CMD_CODE_DNLD 0x0001
283 #define MWL8K_CMD_GET_HW_SPEC 0x0003
284 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
285 #define MWL8K_CMD_GET_STAT 0x0014
286 #define MWL8K_CMD_RADIO_CONTROL 0x001c
287 #define MWL8K_CMD_RF_TX_POWER 0x001e
288 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
289 #define MWL8K_CMD_SET_POST_SCAN 0x0108
290 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
291 #define MWL8K_CMD_SET_AID 0x010d
292 #define MWL8K_CMD_SET_RATE 0x0110
293 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
294 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
295 #define MWL8K_CMD_SET_SLOT 0x0114
296 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
297 #define MWL8K_CMD_SET_WMM_MODE 0x0123
298 #define MWL8K_CMD_MIMO_CONFIG 0x0125
299 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
300 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
301 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
302 #define MWL8K_CMD_UPDATE_STADB 0x1123
304 static const char *mwl8k_cmd_name(u16 cmd
, char *buf
, int bufsize
)
306 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
307 snprintf(buf, bufsize, "%s", #x);\
310 switch (cmd
& ~0x8000) {
311 MWL8K_CMDNAME(CODE_DNLD
);
312 MWL8K_CMDNAME(GET_HW_SPEC
);
313 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
314 MWL8K_CMDNAME(GET_STAT
);
315 MWL8K_CMDNAME(RADIO_CONTROL
);
316 MWL8K_CMDNAME(RF_TX_POWER
);
317 MWL8K_CMDNAME(SET_PRE_SCAN
);
318 MWL8K_CMDNAME(SET_POST_SCAN
);
319 MWL8K_CMDNAME(SET_RF_CHANNEL
);
320 MWL8K_CMDNAME(SET_AID
);
321 MWL8K_CMDNAME(SET_RATE
);
322 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
323 MWL8K_CMDNAME(RTS_THRESHOLD
);
324 MWL8K_CMDNAME(SET_SLOT
);
325 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
326 MWL8K_CMDNAME(SET_WMM_MODE
);
327 MWL8K_CMDNAME(MIMO_CONFIG
);
328 MWL8K_CMDNAME(USE_FIXED_RATE
);
329 MWL8K_CMDNAME(ENABLE_SNIFFER
);
330 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
331 MWL8K_CMDNAME(UPDATE_STADB
);
333 snprintf(buf
, bufsize
, "0x%x", cmd
);
340 /* Hardware and firmware reset */
341 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
343 iowrite32(MWL8K_H2A_INT_RESET
,
344 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
345 iowrite32(MWL8K_H2A_INT_RESET
,
346 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
350 /* Release fw image */
351 static void mwl8k_release_fw(struct firmware
**fw
)
355 release_firmware(*fw
);
359 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
361 mwl8k_release_fw(&priv
->fw
.ucode
);
362 mwl8k_release_fw(&priv
->fw
.helper
);
365 /* Request fw image */
366 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
367 const char *fname
, struct firmware
**fw
)
369 /* release current image */
371 mwl8k_release_fw(fw
);
373 return request_firmware((const struct firmware
**)fw
,
374 fname
, &priv
->pdev
->dev
);
377 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, u32 part_num
)
382 priv
->part_num
= part_num
;
384 snprintf(filename
, sizeof(filename
),
385 "mwl8k/helper_%u.fw", priv
->part_num
);
387 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.helper
);
390 "%s Error requesting helper firmware file %s\n",
391 pci_name(priv
->pdev
), filename
);
395 snprintf(filename
, sizeof(filename
),
396 "mwl8k/fmimage_%u.fw", priv
->part_num
);
398 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.ucode
);
400 printk(KERN_ERR
"%s Error requesting firmware file %s\n",
401 pci_name(priv
->pdev
), filename
);
402 mwl8k_release_fw(&priv
->fw
.helper
);
409 struct mwl8k_cmd_pkt
{
415 } __attribute__((packed
));
421 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
423 void __iomem
*regs
= priv
->regs
;
428 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
429 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
432 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
433 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
434 iowrite32(MWL8K_H2A_INT_DOORBELL
,
435 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
436 iowrite32(MWL8K_H2A_INT_DUMMY
,
437 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
444 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
445 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
446 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
454 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
457 * Clear 'command done' interrupt bit.
463 status
= ioread32(priv
->regs
+
464 MWL8K_HIU_A2H_INTERRUPT_STATUS
);
465 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
466 iowrite32(~MWL8K_A2H_INT_OPC_DONE
,
467 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
468 ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
478 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
479 const u8
*data
, size_t length
)
481 struct mwl8k_cmd_pkt
*cmd
;
485 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
489 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
495 int block_size
= length
> 256 ? 256 : length
;
497 memcpy(cmd
->payload
, data
+ done
, block_size
);
498 cmd
->length
= cpu_to_le16(block_size
);
500 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
501 sizeof(*cmd
) + block_size
);
506 length
-= block_size
;
511 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
519 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
520 const u8
*data
, size_t length
)
522 unsigned char *buffer
;
523 int may_continue
, rc
= 0;
524 u32 done
, prev_block_size
;
526 buffer
= kmalloc(1024, GFP_KERNEL
);
533 while (may_continue
> 0) {
536 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
537 if (block_size
& 1) {
541 done
+= prev_block_size
;
542 length
-= prev_block_size
;
545 if (block_size
> 1024 || block_size
> length
) {
555 if (block_size
== 0) {
562 prev_block_size
= block_size
;
563 memcpy(buffer
, data
+ done
, block_size
);
565 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
570 if (!rc
&& length
!= 0)
578 static int mwl8k_load_firmware(struct mwl8k_priv
*priv
)
582 const u8
*ucode
= priv
->fw
.ucode
->data
;
583 size_t ucode_len
= priv
->fw
.ucode
->size
;
584 const u8
*helper
= priv
->fw
.helper
->data
;
585 size_t helper_len
= priv
->fw
.helper
->size
;
587 if (!memcmp(ucode
, "\x01\x00\x00\x00", 4)) {
588 rc
= mwl8k_load_fw_image(priv
, helper
, helper_len
);
590 printk(KERN_ERR
"%s: unable to load firmware "
591 "helper image\n", pci_name(priv
->pdev
));
596 rc
= mwl8k_feed_fw_image(priv
, ucode
, ucode_len
);
598 rc
= mwl8k_load_fw_image(priv
, ucode
, ucode_len
);
602 printk(KERN_ERR
"%s: unable to load firmware data\n",
603 pci_name(priv
->pdev
));
607 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
612 if (ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
)
613 == MWL8K_FWSTA_READY
)
618 return loops
? 0 : -ETIMEDOUT
;
623 * Defines shared between transmission and reception.
625 /* HT control fields for firmware */
630 } __attribute__((packed
));
632 /* Firmware Station database operations */
633 #define MWL8K_STA_DB_ADD_ENTRY 0
634 #define MWL8K_STA_DB_MODIFY_ENTRY 1
635 #define MWL8K_STA_DB_DEL_ENTRY 2
636 #define MWL8K_STA_DB_FLUSH 3
638 /* Peer Entry flags - used to define the type of the peer node */
639 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
641 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
642 #define MWL8K_MCS_BITMAP_SIZE 16
644 struct peer_capability_info
{
645 /* Peer type - AP vs. STA. */
648 /* Basic 802.11 capabilities from assoc resp. */
651 /* Set if peer supports 802.11n high throughput (HT). */
654 /* Valid if HT is supported. */
656 __u8 extended_ht_caps
;
657 struct ewc_ht_info ewc_info
;
659 /* Legacy rate table. Intersection of our rates and peer rates. */
660 __u8 legacy_rates
[MWL8K_IEEE_LEGACY_DATA_RATES
];
662 /* HT rate table. Intersection of our rates and peer rates. */
663 __u8 ht_rates
[MWL8K_MCS_BITMAP_SIZE
];
666 /* If set, interoperability mode, no proprietary extensions. */
670 __le16 amsdu_enabled
;
671 } __attribute__((packed
));
673 /* Inline functions to manipulate QoS field in data descriptor. */
674 static inline u16
mwl8k_qos_setbit_eosp(u16 qos
)
676 u16 val_mask
= 1 << 4;
678 /* End of Service Period Bit 4 */
679 return qos
| val_mask
;
682 static inline u16
mwl8k_qos_setbit_ack(u16 qos
, u8 ack_policy
)
686 u16 qos_mask
= ~(val_mask
<< shift
);
688 /* Ack Policy Bit 5-6 */
689 return (qos
& qos_mask
) | ((ack_policy
& val_mask
) << shift
);
692 static inline u16
mwl8k_qos_setbit_amsdu(u16 qos
)
694 u16 val_mask
= 1 << 7;
696 /* AMSDU present Bit 7 */
697 return qos
| val_mask
;
700 static inline u16
mwl8k_qos_setbit_qlen(u16 qos
, u8 len
)
704 u16 qos_mask
= ~(val_mask
<< shift
);
706 /* Queue Length Bits 8-15 */
707 return (qos
& qos_mask
) | ((len
& val_mask
) << shift
);
710 /* DMA header used by firmware and hardware. */
711 struct mwl8k_dma_data
{
713 struct ieee80211_hdr wh
;
714 } __attribute__((packed
));
716 /* Routines to add/remove DMA header from skb. */
717 static inline int mwl8k_remove_dma_header(struct sk_buff
*skb
)
719 struct mwl8k_dma_data
*tr
= (struct mwl8k_dma_data
*)(skb
->data
);
720 void *dst
, *src
= &tr
->wh
;
721 __le16 fc
= tr
->wh
.frame_control
;
722 int hdrlen
= ieee80211_hdrlen(fc
);
723 u16 space
= sizeof(struct mwl8k_dma_data
) - hdrlen
;
725 dst
= (void *)tr
+ space
;
727 memmove(dst
, src
, hdrlen
);
728 skb_pull(skb
, space
);
734 static inline struct sk_buff
*mwl8k_add_dma_header(struct sk_buff
*skb
)
736 struct ieee80211_hdr
*wh
;
738 struct mwl8k_dma_data
*tr
;
740 wh
= (struct ieee80211_hdr
*)skb
->data
;
741 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
745 * Copy up/down the 802.11 header; the firmware requires
746 * we present a 2-byte payload length followed by a
747 * 4-address header (w/o QoS), followed (optionally) by
748 * any WEP/ExtIV header (but only filled in for CCMP).
750 if (hdrlen
!= sizeof(struct mwl8k_dma_data
))
751 skb_push(skb
, sizeof(struct mwl8k_dma_data
) - hdrlen
);
753 tr
= (struct mwl8k_dma_data
*)skb
->data
;
755 memmove(&tr
->wh
, wh
, hdrlen
);
758 memset(tr
->wh
.addr4
, 0, ETH_ALEN
);
761 * Firmware length is the length of the fully formed "802.11
762 * payload". That is, everything except for the 802.11 header.
763 * This includes all crypto material including the MIC.
765 tr
->fwlen
= cpu_to_le16(pktlen
- hdrlen
);
774 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
776 struct mwl8k_rx_desc
{
780 __le32 pkt_phys_addr
;
781 __le32 next_rx_desc_phys_addr
;
791 } __attribute__((packed
));
793 #define MWL8K_RX_DESCS 256
794 #define MWL8K_RX_MAXSZ 3800
796 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
798 struct mwl8k_priv
*priv
= hw
->priv
;
799 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
803 rxq
->rx_desc_count
= 0;
807 size
= MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
);
810 pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rx_desc_dma
);
811 if (rxq
->rx_desc_area
== NULL
) {
812 printk(KERN_ERR
"%s: failed to alloc RX descriptors\n",
816 memset(rxq
->rx_desc_area
, 0, size
);
818 rxq
->rx_skb
= kmalloc(MWL8K_RX_DESCS
*
819 sizeof(*rxq
->rx_skb
), GFP_KERNEL
);
820 if (rxq
->rx_skb
== NULL
) {
821 printk(KERN_ERR
"%s: failed to alloc RX skbuff list\n",
823 pci_free_consistent(priv
->pdev
, size
,
824 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
827 memset(rxq
->rx_skb
, 0, MWL8K_RX_DESCS
* sizeof(*rxq
->rx_skb
));
829 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
830 struct mwl8k_rx_desc
*rx_desc
;
833 rx_desc
= rxq
->rx_desc_area
+ i
;
834 nexti
= (i
+ 1) % MWL8K_RX_DESCS
;
836 rx_desc
->next_rx_desc_phys_addr
=
837 cpu_to_le32(rxq
->rx_desc_dma
838 + nexti
* sizeof(*rx_desc
));
839 rx_desc
->rx_ctrl
= MWL8K_RX_CTRL_OWNED_BY_HOST
;
845 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
847 struct mwl8k_priv
*priv
= hw
->priv
;
848 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
852 while (rxq
->rx_desc_count
< MWL8K_RX_DESCS
&& limit
--) {
856 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
860 rxq
->rx_desc_count
++;
863 rxq
->rx_tail
= (rx
+ 1) % MWL8K_RX_DESCS
;
865 rxq
->rx_desc_area
[rx
].pkt_phys_addr
=
866 cpu_to_le32(pci_map_single(priv
->pdev
, skb
->data
,
867 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
));
869 rxq
->rx_desc_area
[rx
].pkt_len
= cpu_to_le16(MWL8K_RX_MAXSZ
);
870 rxq
->rx_skb
[rx
] = skb
;
872 rxq
->rx_desc_area
[rx
].rx_ctrl
= 0;
880 /* Must be called only when the card's reception is completely halted */
881 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
883 struct mwl8k_priv
*priv
= hw
->priv
;
884 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
887 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
888 if (rxq
->rx_skb
[i
] != NULL
) {
891 addr
= le32_to_cpu(rxq
->rx_desc_area
[i
].pkt_phys_addr
);
892 pci_unmap_single(priv
->pdev
, addr
, MWL8K_RX_MAXSZ
,
894 kfree_skb(rxq
->rx_skb
[i
]);
895 rxq
->rx_skb
[i
] = NULL
;
902 pci_free_consistent(priv
->pdev
,
903 MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
),
904 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
905 rxq
->rx_desc_area
= NULL
;
910 * Scan a list of BSSIDs to process for finalize join.
911 * Allows for extension to process multiple BSSIDs.
914 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
916 return priv
->capture_beacon
&&
917 ieee80211_is_beacon(wh
->frame_control
) &&
918 !compare_ether_addr(wh
->addr3
, priv
->capture_bssid
);
921 static inline void mwl8k_save_beacon(struct mwl8k_priv
*priv
,
924 priv
->capture_beacon
= false;
925 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
928 * Use GFP_ATOMIC as rxq_process is called from
929 * the primary interrupt handler, memory allocation call
932 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
933 if (priv
->beacon_skb
!= NULL
)
934 queue_work(priv
->config_wq
,
935 &priv
->finalize_join_worker
);
938 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
940 struct mwl8k_priv
*priv
= hw
->priv
;
941 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
945 while (rxq
->rx_desc_count
&& limit
--) {
946 struct mwl8k_rx_desc
*rx_desc
;
948 struct ieee80211_rx_status status
;
950 struct ieee80211_hdr
*wh
;
952 rx_desc
= rxq
->rx_desc_area
+ rxq
->rx_head
;
953 if (!(rx_desc
->rx_ctrl
& MWL8K_RX_CTRL_OWNED_BY_HOST
))
957 skb
= rxq
->rx_skb
[rxq
->rx_head
];
960 rxq
->rx_skb
[rxq
->rx_head
] = NULL
;
962 rxq
->rx_head
= (rxq
->rx_head
+ 1) % MWL8K_RX_DESCS
;
963 rxq
->rx_desc_count
--;
965 addr
= le32_to_cpu(rx_desc
->pkt_phys_addr
);
966 pci_unmap_single(priv
->pdev
, addr
,
967 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
969 skb_put(skb
, le16_to_cpu(rx_desc
->pkt_len
));
970 if (mwl8k_remove_dma_header(skb
)) {
975 wh
= (struct ieee80211_hdr
*)skb
->data
;
978 * Check for pending join operation. save a copy of
979 * the beacon and schedule a tasklet to send finalize
980 * join command to the firmware.
982 if (mwl8k_capture_bssid(priv
, wh
))
983 mwl8k_save_beacon(priv
, skb
);
985 memset(&status
, 0, sizeof(status
));
987 status
.signal
= -rx_desc
->rssi
;
988 status
.noise
= -rx_desc
->noise_level
;
989 status
.qual
= rx_desc
->link_quality
;
993 status
.band
= IEEE80211_BAND_2GHZ
;
994 status
.freq
= ieee80211_channel_to_frequency(rx_desc
->channel
);
995 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
996 ieee80211_rx_irqsafe(hw
, skb
);
1006 * Packet transmission.
1009 /* Transmit queue assignment. */
1011 MWL8K_WME_AC_BK
= 0, /* background access */
1012 MWL8K_WME_AC_BE
= 1, /* best effort access */
1013 MWL8K_WME_AC_VI
= 2, /* video access */
1014 MWL8K_WME_AC_VO
= 3, /* voice access */
1017 /* Transmit packet ACK policy */
1018 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
1019 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1021 #define GET_TXQ(_ac) (\
1022 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
1023 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
1024 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
1027 #define MWL8K_TXD_STATUS_OK 0x00000001
1028 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1029 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1030 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1031 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1033 struct mwl8k_tx_desc
{
1038 __le32 pkt_phys_addr
;
1040 __u8 dest_MAC_addr
[ETH_ALEN
];
1041 __le32 next_tx_desc_phys_addr
;
1046 } __attribute__((packed
));
1048 #define MWL8K_TX_DESCS 128
1050 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1052 struct mwl8k_priv
*priv
= hw
->priv
;
1053 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1057 memset(&txq
->tx_stats
, 0, sizeof(struct ieee80211_tx_queue_stats
));
1058 txq
->tx_stats
.limit
= MWL8K_TX_DESCS
;
1062 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1065 pci_alloc_consistent(priv
->pdev
, size
, &txq
->tx_desc_dma
);
1066 if (txq
->tx_desc_area
== NULL
) {
1067 printk(KERN_ERR
"%s: failed to alloc TX descriptors\n",
1071 memset(txq
->tx_desc_area
, 0, size
);
1073 txq
->tx_skb
= kmalloc(MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
),
1075 if (txq
->tx_skb
== NULL
) {
1076 printk(KERN_ERR
"%s: failed to alloc TX skbuff list\n",
1078 pci_free_consistent(priv
->pdev
, size
,
1079 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1082 memset(txq
->tx_skb
, 0, MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
));
1084 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1085 struct mwl8k_tx_desc
*tx_desc
;
1088 tx_desc
= txq
->tx_desc_area
+ i
;
1089 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1091 tx_desc
->status
= 0;
1092 tx_desc
->next_tx_desc_phys_addr
=
1093 cpu_to_le32(txq
->tx_desc_dma
+
1094 nexti
* sizeof(*tx_desc
));
1100 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1102 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1103 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1104 iowrite32(MWL8K_H2A_INT_DUMMY
,
1105 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1106 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1109 static inline int mwl8k_txq_busy(struct mwl8k_priv
*priv
)
1111 return priv
->pending_tx_pkts
;
1114 struct mwl8k_txq_info
{
1123 static int mwl8k_scan_tx_ring(struct mwl8k_priv
*priv
,
1124 struct mwl8k_txq_info txinfo
[],
1127 int count
, desc
, status
;
1128 struct mwl8k_tx_queue
*txq
;
1129 struct mwl8k_tx_desc
*tx_desc
;
1132 memset(txinfo
, 0, num_queues
* sizeof(struct mwl8k_txq_info
));
1133 spin_lock_bh(&priv
->tx_lock
);
1134 for (count
= 0; count
< num_queues
; count
++) {
1135 txq
= priv
->txq
+ count
;
1136 txinfo
[count
].len
= txq
->tx_stats
.len
;
1137 txinfo
[count
].head
= txq
->tx_head
;
1138 txinfo
[count
].tail
= txq
->tx_tail
;
1139 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1140 tx_desc
= txq
->tx_desc_area
+ desc
;
1141 status
= le32_to_cpu(tx_desc
->status
);
1143 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1144 txinfo
[count
].fw_owned
++;
1146 txinfo
[count
].drv_owned
++;
1148 if (tx_desc
->pkt_len
== 0)
1149 txinfo
[count
].unused
++;
1152 spin_unlock_bh(&priv
->tx_lock
);
1157 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
, u32 delay_ms
)
1159 struct mwl8k_priv
*priv
= hw
->priv
;
1160 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1162 unsigned long timeout
;
1166 if (priv
->tx_wait
!= NULL
)
1167 printk(KERN_ERR
"WARNING Previous TXWaitEmpty instance\n");
1169 spin_lock_bh(&priv
->tx_lock
);
1170 count
= mwl8k_txq_busy(priv
);
1172 priv
->tx_wait
= &cmd_wait
;
1174 mwl8k_tx_start(priv
);
1176 spin_unlock_bh(&priv
->tx_lock
);
1179 struct mwl8k_txq_info txinfo
[4];
1183 timeout
= wait_for_completion_timeout(&cmd_wait
,
1184 msecs_to_jiffies(delay_ms
));
1188 spin_lock_bh(&priv
->tx_lock
);
1189 priv
->tx_wait
= NULL
;
1190 newcount
= mwl8k_txq_busy(priv
);
1191 spin_unlock_bh(&priv
->tx_lock
);
1193 printk(KERN_ERR
"%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
1194 __func__
, __LINE__
, delay_ms
, count
, newcount
);
1196 mwl8k_scan_tx_ring(priv
, txinfo
, 4);
1197 for (index
= 0; index
< 4; index
++)
1199 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
1204 txinfo
[index
].fw_owned
,
1205 txinfo
[index
].drv_owned
,
1206 txinfo
[index
].unused
);
1214 #define MWL8K_TXD_SUCCESS(status) \
1215 ((status) & (MWL8K_TXD_STATUS_OK | \
1216 MWL8K_TXD_STATUS_OK_RETRY | \
1217 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1219 static void mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int force
)
1221 struct mwl8k_priv
*priv
= hw
->priv
;
1222 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1225 while (txq
->tx_stats
.len
> 0) {
1228 struct mwl8k_tx_desc
*tx_desc
;
1231 struct sk_buff
*skb
;
1232 struct ieee80211_tx_info
*info
;
1237 tx_desc
= txq
->tx_desc_area
+ tx
;
1239 status
= le32_to_cpu(tx_desc
->status
);
1241 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1245 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1248 txq
->tx_head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1249 BUG_ON(txq
->tx_stats
.len
== 0);
1250 txq
->tx_stats
.len
--;
1251 priv
->pending_tx_pkts
--;
1253 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1254 size
= le16_to_cpu(tx_desc
->pkt_len
);
1255 skb
= txq
->tx_skb
[tx
].skb
;
1256 txq
->tx_skb
[tx
].skb
= NULL
;
1258 BUG_ON(skb
== NULL
);
1259 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1261 rc
= mwl8k_remove_dma_header(skb
);
1263 /* Mark descriptor as unused */
1264 tx_desc
->pkt_phys_addr
= 0;
1265 tx_desc
->pkt_len
= 0;
1267 if (txq
->tx_skb
[tx
].clone
) {
1268 /* Replace with original skb
1269 * before returning to stack
1270 * as buffer has been cloned
1273 skb
= txq
->tx_skb
[tx
].clone
;
1274 txq
->tx_skb
[tx
].clone
= NULL
;
1278 /* Something has gone wrong here.
1279 * Failed to remove DMA header.
1280 * Print error message and drop packet.
1282 printk(KERN_ERR
"%s: Error removing DMA header from "
1283 "tx skb 0x%p.\n", priv
->name
, skb
);
1289 info
= IEEE80211_SKB_CB(skb
);
1290 ieee80211_tx_info_clear_status(info
);
1291 if (MWL8K_TXD_SUCCESS(status
))
1292 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1294 ieee80211_tx_status_irqsafe(hw
, skb
);
1296 wake
= !priv
->inconfig
&& priv
->radio_on
;
1300 ieee80211_wake_queue(hw
, index
);
1303 /* must be called only when the card's transmit is completely halted */
1304 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1306 struct mwl8k_priv
*priv
= hw
->priv
;
1307 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1309 mwl8k_txq_reclaim(hw
, index
, 1);
1314 pci_free_consistent(priv
->pdev
,
1315 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1316 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1317 txq
->tx_desc_area
= NULL
;
1321 mwl8k_txq_xmit(struct ieee80211_hw
*hw
, int index
, struct sk_buff
*skb
)
1323 struct mwl8k_priv
*priv
= hw
->priv
;
1324 struct ieee80211_tx_info
*tx_info
;
1325 struct ieee80211_hdr
*wh
;
1326 struct mwl8k_tx_queue
*txq
;
1327 struct mwl8k_tx_desc
*tx
;
1328 struct mwl8k_dma_data
*tr
;
1329 struct mwl8k_vif
*mwl8k_vif
;
1330 struct sk_buff
*org_skb
= skb
;
1333 bool qosframe
= false, ampduframe
= false;
1334 bool mcframe
= false, eapolframe
= false;
1335 bool amsduframe
= false;
1338 txq
= priv
->txq
+ index
;
1339 tx
= txq
->tx_desc_area
+ txq
->tx_tail
;
1341 BUG_ON(txq
->tx_skb
[txq
->tx_tail
].skb
!= NULL
);
1344 * Append HW DMA header to start of packet. Drop packet if
1345 * there is not enough space or a failure to unshare/unclone
1348 skb
= mwl8k_add_dma_header(skb
);
1351 printk(KERN_DEBUG
"%s: failed to prepend HW DMA "
1352 "header, dropping TX frame.\n", priv
->name
);
1353 dev_kfree_skb(org_skb
);
1354 return NETDEV_TX_OK
;
1357 tx_info
= IEEE80211_SKB_CB(skb
);
1358 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1359 tr
= (struct mwl8k_dma_data
*)skb
->data
;
1361 fc
= wh
->frame_control
;
1362 qosframe
= ieee80211_is_data_qos(fc
);
1363 mcframe
= is_multicast_ether_addr(wh
->addr1
);
1364 ampduframe
= !!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
);
1366 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1367 u16 seqno
= mwl8k_vif
->seqno
;
1368 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1369 wh
->seq_ctrl
|= cpu_to_le16(seqno
<< 4);
1370 mwl8k_vif
->seqno
= seqno
++ % 4096;
1374 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1376 dma
= pci_map_single(priv
->pdev
, skb
->data
,
1377 skb
->len
, PCI_DMA_TODEVICE
);
1379 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
1380 printk(KERN_DEBUG
"%s: failed to dma map skb, "
1381 "dropping TX frame.\n", priv
->name
);
1383 if (org_skb
!= NULL
)
1384 dev_kfree_skb(org_skb
);
1387 return NETDEV_TX_OK
;
1390 /* Set desc header, cpu bit order. */
1393 tx
->tx_priority
= index
;
1394 tx
->qos_control
= 0;
1396 tx
->peer_id
= mwl8k_vif
->peer_id
;
1398 amsduframe
= !!(qos
& IEEE80211_QOS_CONTROL_A_MSDU_PRESENT
);
1400 /* Setup firmware control bit fields for each frame type. */
1401 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
)) {
1403 qos
= mwl8k_qos_setbit_eosp(qos
);
1404 /* Set Queue size to unspecified */
1405 qos
= mwl8k_qos_setbit_qlen(qos
, 0xff);
1406 } else if (ieee80211_is_data(fc
)) {
1409 tx
->status
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1412 * Tell firmware to not send EAPOL pkts in an
1413 * aggregate. Verify against mac80211 tx path. If
1414 * stack turns off AMPDU for an EAPOL frame this
1415 * check will be removed.
1418 qos
= mwl8k_qos_setbit_ack(qos
,
1419 MWL8K_TXD_ACK_POLICY_NORMAL
);
1421 /* Send pkt in an aggregate if AMPDU frame. */
1423 qos
= mwl8k_qos_setbit_ack(qos
,
1424 MWL8K_TXD_ACK_POLICY_BLOCKACK
);
1426 qos
= mwl8k_qos_setbit_ack(qos
,
1427 MWL8K_TXD_ACK_POLICY_NORMAL
);
1430 qos
= mwl8k_qos_setbit_amsdu(qos
);
1434 /* Convert to little endian */
1435 tx
->qos_control
= cpu_to_le16(qos
);
1436 tx
->status
= cpu_to_le32(tx
->status
);
1437 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
1438 tx
->pkt_len
= cpu_to_le16(skb
->len
);
1440 txq
->tx_skb
[txq
->tx_tail
].skb
= skb
;
1441 txq
->tx_skb
[txq
->tx_tail
].clone
=
1442 skb
== org_skb
? NULL
: org_skb
;
1444 spin_lock_bh(&priv
->tx_lock
);
1446 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_OK
|
1447 MWL8K_TXD_STATUS_FW_OWNED
);
1449 txq
->tx_stats
.len
++;
1450 priv
->pending_tx_pkts
++;
1451 txq
->tx_stats
.count
++;
1454 if (txq
->tx_tail
== MWL8K_TX_DESCS
)
1456 if (txq
->tx_head
== txq
->tx_tail
)
1457 ieee80211_stop_queue(hw
, index
);
1459 if (priv
->inconfig
) {
1461 * Silently queue packet when we are in the middle of
1462 * a config cycle. Notify firmware only if we are
1463 * waiting for TXQs to empty. If a packet is sent
1464 * before .config() is complete, perhaps it is better
1465 * to drop the packet, as the channel is being changed
1466 * and the packet will end up on the wrong channel.
1468 printk(KERN_ERR
"%s(): WARNING TX activity while "
1469 "in config\n", __func__
);
1471 if (priv
->tx_wait
!= NULL
)
1472 mwl8k_tx_start(priv
);
1474 mwl8k_tx_start(priv
);
1476 spin_unlock_bh(&priv
->tx_lock
);
1478 return NETDEV_TX_OK
;
1483 * Command processing.
1486 /* Timeout firmware commands after 2000ms */
1487 #define MWL8K_CMD_TIMEOUT_MS 2000
1489 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
1491 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1492 struct mwl8k_priv
*priv
= hw
->priv
;
1493 void __iomem
*regs
= priv
->regs
;
1494 dma_addr_t dma_addr
;
1495 unsigned int dma_size
;
1497 unsigned long timeout
= 0;
1500 cmd
->result
= 0xFFFF;
1501 dma_size
= le16_to_cpu(cmd
->length
);
1502 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
1503 PCI_DMA_BIDIRECTIONAL
);
1504 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
1507 if (priv
->hostcmd_wait
!= NULL
)
1508 printk(KERN_ERR
"WARNING host command in progress\n");
1510 spin_lock_irq(&priv
->fw_lock
);
1511 priv
->hostcmd_wait
= &cmd_wait
;
1512 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
1513 iowrite32(MWL8K_H2A_INT_DOORBELL
,
1514 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1515 iowrite32(MWL8K_H2A_INT_DUMMY
,
1516 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1517 spin_unlock_irq(&priv
->fw_lock
);
1519 timeout
= wait_for_completion_timeout(&cmd_wait
,
1520 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
1522 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1523 PCI_DMA_BIDIRECTIONAL
);
1526 spin_lock_irq(&priv
->fw_lock
);
1527 priv
->hostcmd_wait
= NULL
;
1528 spin_unlock_irq(&priv
->fw_lock
);
1529 printk(KERN_ERR
"%s: Command %s timeout after %u ms\n",
1531 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1532 MWL8K_CMD_TIMEOUT_MS
);
1535 rc
= cmd
->result
? -EINVAL
: 0;
1537 printk(KERN_ERR
"%s: Command %s error 0x%x\n",
1539 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1549 struct mwl8k_cmd_get_hw_spec
{
1550 struct mwl8k_cmd_pkt header
;
1552 __u8 host_interface
;
1554 __u8 perm_addr
[ETH_ALEN
];
1559 __u8 mcs_bitmap
[16];
1560 __le32 rx_queue_ptr
;
1561 __le32 num_tx_queues
;
1562 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1564 __le32 num_tx_desc_per_queue
;
1565 __le32 total_rx_desc
;
1566 } __attribute__((packed
));
1568 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw
*hw
)
1570 struct mwl8k_priv
*priv
= hw
->priv
;
1571 struct mwl8k_cmd_get_hw_spec
*cmd
;
1575 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1579 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1580 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1582 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1583 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1584 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rx_desc_dma
);
1585 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1586 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1587 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].tx_desc_dma
);
1588 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1589 cmd
->total_rx_desc
= cpu_to_le32(MWL8K_RX_DESCS
);
1591 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1594 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1595 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1596 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1597 priv
->hw_rev
= cmd
->hw_rev
;
1605 * CMD_MAC_MULTICAST_ADR.
1607 struct mwl8k_cmd_mac_multicast_adr
{
1608 struct mwl8k_cmd_pkt header
;
1611 __u8 addr
[0][ETH_ALEN
];
1614 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
1616 static int mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
,
1618 struct dev_addr_list
*mclist
)
1620 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
1623 int size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
1625 cmd
= kzalloc(size
, GFP_KERNEL
);
1629 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
1630 cmd
->header
.length
= cpu_to_le16(size
);
1631 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
1632 cmd
->numaddr
= cpu_to_le16(mc_count
);
1634 while (index
< mc_count
&& mclist
) {
1635 if (mclist
->da_addrlen
!= ETH_ALEN
) {
1637 goto mwl8k_cmd_mac_multicast_adr_exit
;
1639 memcpy(cmd
->addr
[index
++], mclist
->da_addr
, ETH_ALEN
);
1640 mclist
= mclist
->next
;
1643 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1645 mwl8k_cmd_mac_multicast_adr_exit
:
1651 * CMD_802_11_GET_STAT.
1653 struct mwl8k_cmd_802_11_get_stat
{
1654 struct mwl8k_cmd_pkt header
;
1657 } __attribute__((packed
));
1659 #define MWL8K_STAT_ACK_FAILURE 9
1660 #define MWL8K_STAT_RTS_FAILURE 12
1661 #define MWL8K_STAT_FCS_ERROR 24
1662 #define MWL8K_STAT_RTS_SUCCESS 11
1664 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw
*hw
,
1665 struct ieee80211_low_level_stats
*stats
)
1667 struct mwl8k_cmd_802_11_get_stat
*cmd
;
1670 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1674 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
1675 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1676 cmd
->action
= cpu_to_le16(MWL8K_CMD_GET
);
1678 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1680 stats
->dot11ACKFailureCount
=
1681 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
1682 stats
->dot11RTSFailureCount
=
1683 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
1684 stats
->dot11FCSErrorCount
=
1685 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
1686 stats
->dot11RTSSuccessCount
=
1687 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
1695 * CMD_802_11_RADIO_CONTROL.
1697 struct mwl8k_cmd_802_11_radio_control
{
1698 struct mwl8k_cmd_pkt header
;
1702 } __attribute__((packed
));
1705 mwl8k_cmd_802_11_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
1707 struct mwl8k_priv
*priv
= hw
->priv
;
1708 struct mwl8k_cmd_802_11_radio_control
*cmd
;
1711 if (enable
== priv
->radio_on
&& !force
)
1714 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1718 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
1719 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1720 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1721 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
1722 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
1724 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1728 priv
->radio_on
= enable
;
1733 static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw
*hw
)
1735 return mwl8k_cmd_802_11_radio_control(hw
, 0, 0);
1738 static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw
*hw
)
1740 return mwl8k_cmd_802_11_radio_control(hw
, 1, 0);
1744 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
1746 struct mwl8k_priv
*priv
;
1748 if (hw
== NULL
|| hw
->priv
== NULL
)
1752 priv
->radio_short_preamble
= short_preamble
;
1754 return mwl8k_cmd_802_11_radio_control(hw
, 1, 1);
1758 * CMD_802_11_RF_TX_POWER.
1760 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1762 struct mwl8k_cmd_802_11_rf_tx_power
{
1763 struct mwl8k_cmd_pkt header
;
1765 __le16 support_level
;
1766 __le16 current_level
;
1768 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
1769 } __attribute__((packed
));
1771 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
1773 struct mwl8k_cmd_802_11_rf_tx_power
*cmd
;
1776 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1780 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
1781 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1782 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1783 cmd
->support_level
= cpu_to_le16(dBm
);
1785 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1794 struct mwl8k_cmd_set_pre_scan
{
1795 struct mwl8k_cmd_pkt header
;
1796 } __attribute__((packed
));
1798 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
1800 struct mwl8k_cmd_set_pre_scan
*cmd
;
1803 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1807 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
1808 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1810 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1817 * CMD_SET_POST_SCAN.
1819 struct mwl8k_cmd_set_post_scan
{
1820 struct mwl8k_cmd_pkt header
;
1822 __u8 bssid
[ETH_ALEN
];
1823 } __attribute__((packed
));
1826 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, __u8
*mac
)
1828 struct mwl8k_cmd_set_post_scan
*cmd
;
1831 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1835 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
1836 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1838 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
1840 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1847 * CMD_SET_RF_CHANNEL.
1849 struct mwl8k_cmd_set_rf_channel
{
1850 struct mwl8k_cmd_pkt header
;
1852 __u8 current_channel
;
1853 __le32 channel_flags
;
1854 } __attribute__((packed
));
1856 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
1857 struct ieee80211_channel
*channel
)
1859 struct mwl8k_cmd_set_rf_channel
*cmd
;
1862 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1866 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
1867 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1868 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1869 cmd
->current_channel
= channel
->hw_value
;
1870 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1871 cmd
->channel_flags
= cpu_to_le32(0x00000081);
1873 cmd
->channel_flags
= cpu_to_le32(0x00000000);
1875 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1884 struct mwl8k_cmd_set_slot
{
1885 struct mwl8k_cmd_pkt header
;
1888 } __attribute__((packed
));
1890 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, bool short_slot_time
)
1892 struct mwl8k_cmd_set_slot
*cmd
;
1895 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1899 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
1900 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1901 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1902 cmd
->short_slot
= short_slot_time
;
1904 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1913 struct mwl8k_cmd_mimo_config
{
1914 struct mwl8k_cmd_pkt header
;
1916 __u8 rx_antenna_map
;
1917 __u8 tx_antenna_map
;
1918 } __attribute__((packed
));
1920 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
1922 struct mwl8k_cmd_mimo_config
*cmd
;
1925 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1929 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
1930 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1931 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
1932 cmd
->rx_antenna_map
= rx
;
1933 cmd
->tx_antenna_map
= tx
;
1935 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1942 * CMD_ENABLE_SNIFFER.
1944 struct mwl8k_cmd_enable_sniffer
{
1945 struct mwl8k_cmd_pkt header
;
1947 } __attribute__((packed
));
1949 static int mwl8k_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
1951 struct mwl8k_cmd_enable_sniffer
*cmd
;
1954 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1958 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
1959 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1960 cmd
->action
= cpu_to_le32(!!enable
);
1962 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1969 * CMD_SET_RATEADAPT_MODE.
1971 struct mwl8k_cmd_set_rate_adapt_mode
{
1972 struct mwl8k_cmd_pkt header
;
1975 } __attribute__((packed
));
1977 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw
*hw
, __u16 mode
)
1979 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
1982 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1986 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
1987 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1988 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1989 cmd
->mode
= cpu_to_le16(mode
);
1991 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2000 struct mwl8k_cmd_set_wmm
{
2001 struct mwl8k_cmd_pkt header
;
2003 } __attribute__((packed
));
2005 static int mwl8k_set_wmm(struct ieee80211_hw
*hw
, bool enable
)
2007 struct mwl8k_priv
*priv
= hw
->priv
;
2008 struct mwl8k_cmd_set_wmm
*cmd
;
2011 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2015 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
2016 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2017 cmd
->action
= cpu_to_le16(!!enable
);
2019 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2023 priv
->wmm_enabled
= enable
;
2029 * CMD_SET_RTS_THRESHOLD.
2031 struct mwl8k_cmd_rts_threshold
{
2032 struct mwl8k_cmd_pkt header
;
2035 } __attribute__((packed
));
2037 static int mwl8k_rts_threshold(struct ieee80211_hw
*hw
,
2038 u16 action
, u16
*threshold
)
2040 struct mwl8k_cmd_rts_threshold
*cmd
;
2043 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2047 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
2048 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2049 cmd
->action
= cpu_to_le16(action
);
2050 cmd
->threshold
= cpu_to_le16(*threshold
);
2052 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2059 * CMD_SET_EDCA_PARAMS.
2061 struct mwl8k_cmd_set_edca_params
{
2062 struct mwl8k_cmd_pkt header
;
2064 /* See MWL8K_SET_EDCA_XXX below */
2067 /* TX opportunity in units of 32 us */
2070 /* Log exponent of max contention period: 0...15*/
2073 /* Log exponent of min contention period: 0...15 */
2076 /* Adaptive interframe spacing in units of 32us */
2079 /* TX queue to configure */
2081 } __attribute__((packed
));
2083 #define MWL8K_SET_EDCA_CW 0x01
2084 #define MWL8K_SET_EDCA_TXOP 0x02
2085 #define MWL8K_SET_EDCA_AIFS 0x04
2087 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2088 MWL8K_SET_EDCA_TXOP | \
2089 MWL8K_SET_EDCA_AIFS)
2092 mwl8k_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
2093 __u16 cw_min
, __u16 cw_max
,
2094 __u8 aifs
, __u16 txop
)
2096 struct mwl8k_cmd_set_edca_params
*cmd
;
2099 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2103 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
2104 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2105 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
2106 cmd
->txop
= cpu_to_le16(txop
);
2107 cmd
->log_cw_max
= (u8
)ilog2(cw_max
+ 1);
2108 cmd
->log_cw_min
= (u8
)ilog2(cw_min
+ 1);
2112 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2119 * CMD_FINALIZE_JOIN.
2122 /* FJ beacon buffer size is compiled into the firmware. */
2123 #define MWL8K_FJ_BEACON_MAXLEN 128
2125 struct mwl8k_cmd_finalize_join
{
2126 struct mwl8k_cmd_pkt header
;
2127 __le32 sleep_interval
; /* Number of beacon periods to sleep */
2128 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
2129 } __attribute__((packed
));
2131 static int mwl8k_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
2132 __u16 framelen
, __u16 dtim
)
2134 struct mwl8k_cmd_finalize_join
*cmd
;
2135 struct ieee80211_mgmt
*payload
= frame
;
2143 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2147 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
2148 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2149 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
2151 hdrlen
= ieee80211_hdrlen(payload
->frame_control
);
2153 payload_len
= framelen
> hdrlen
? framelen
- hdrlen
: 0;
2155 /* XXX TBD Might just have to abort and return an error */
2156 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2157 printk(KERN_ERR
"%s(): WARNING: Incomplete beacon "
2158 "sent to firmware. Sz=%u MAX=%u\n", __func__
,
2159 payload_len
, MWL8K_FJ_BEACON_MAXLEN
);
2161 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2162 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
2164 if (payload
&& payload_len
)
2165 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
2167 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2175 struct mwl8k_cmd_update_sta_db
{
2176 struct mwl8k_cmd_pkt header
;
2178 /* See STADB_ACTION_TYPE */
2181 /* Peer MAC address */
2182 __u8 peer_addr
[ETH_ALEN
];
2186 /* Peer info - valid during add/update. */
2187 struct peer_capability_info peer_info
;
2188 } __attribute__((packed
));
2190 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw
*hw
,
2191 struct ieee80211_vif
*vif
, __u32 action
)
2193 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2194 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2195 struct mwl8k_cmd_update_sta_db
*cmd
;
2196 struct peer_capability_info
*peer_info
;
2197 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2201 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2205 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
2206 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2208 cmd
->action
= cpu_to_le32(action
);
2209 peer_info
= &cmd
->peer_info
;
2210 memcpy(cmd
->peer_addr
, mv_vif
->bssid
, ETH_ALEN
);
2213 case MWL8K_STA_DB_ADD_ENTRY
:
2214 case MWL8K_STA_DB_MODIFY_ENTRY
:
2215 /* Build peer_info block */
2216 peer_info
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
2217 peer_info
->basic_caps
= cpu_to_le16(info
->assoc_capability
);
2218 peer_info
->interop
= 1;
2219 peer_info
->amsdu_enabled
= 0;
2221 rates
= peer_info
->legacy_rates
;
2222 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2223 rates
[count
] = bitrates
[count
].hw_value
;
2225 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2227 mv_vif
->peer_id
= peer_info
->station_id
;
2231 case MWL8K_STA_DB_DEL_ENTRY
:
2232 case MWL8K_STA_DB_FLUSH
:
2234 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2236 mv_vif
->peer_id
= 0;
2247 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2249 #define MWL8K_FRAME_PROT_DISABLED 0x00
2250 #define MWL8K_FRAME_PROT_11G 0x07
2251 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2252 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2254 struct mwl8k_cmd_update_set_aid
{
2255 struct mwl8k_cmd_pkt header
;
2258 /* AP's MAC address (BSSID) */
2259 __u8 bssid
[ETH_ALEN
];
2260 __le16 protection_mode
;
2261 __u8 supp_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2262 } __attribute__((packed
));
2264 static int mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
2265 struct ieee80211_vif
*vif
)
2267 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2268 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2269 struct mwl8k_cmd_update_set_aid
*cmd
;
2270 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2275 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2279 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
2280 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2281 cmd
->aid
= cpu_to_le16(info
->aid
);
2283 memcpy(cmd
->bssid
, mv_vif
->bssid
, ETH_ALEN
);
2285 if (info
->use_cts_prot
) {
2286 prot_mode
= MWL8K_FRAME_PROT_11G
;
2288 switch (info
->ht_operation_mode
&
2289 IEEE80211_HT_OP_MODE_PROTECTION
) {
2290 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
2291 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
2293 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
2294 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
2297 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
2301 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
2303 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2304 cmd
->supp_rates
[count
] = bitrates
[count
].hw_value
;
2306 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2315 struct mwl8k_cmd_update_rateset
{
2316 struct mwl8k_cmd_pkt header
;
2317 __u8 legacy_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2319 /* Bitmap for supported MCS codes. */
2320 __u8 mcs_set
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2321 __u8 reserved
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2322 } __attribute__((packed
));
2324 static int mwl8k_update_rateset(struct ieee80211_hw
*hw
,
2325 struct ieee80211_vif
*vif
)
2327 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2328 struct mwl8k_cmd_update_rateset
*cmd
;
2329 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2333 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2337 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
2338 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2340 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2341 cmd
->legacy_rates
[count
] = bitrates
[count
].hw_value
;
2343 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2350 * CMD_USE_FIXED_RATE.
2352 #define MWL8K_RATE_TABLE_SIZE 8
2353 #define MWL8K_UCAST_RATE 0
2354 #define MWL8K_USE_AUTO_RATE 0x0002
2356 struct mwl8k_rate_entry
{
2357 /* Set to 1 if HT rate, 0 if legacy. */
2360 /* Set to 1 to use retry_count field. */
2361 __le32 enable_retry
;
2363 /* Specified legacy rate or MCS. */
2366 /* Number of allowed retries. */
2368 } __attribute__((packed
));
2370 struct mwl8k_rate_table
{
2371 /* 1 to allow specified rate and below */
2372 __le32 allow_rate_drop
;
2374 struct mwl8k_rate_entry rate_entry
[MWL8K_RATE_TABLE_SIZE
];
2375 } __attribute__((packed
));
2377 struct mwl8k_cmd_use_fixed_rate
{
2378 struct mwl8k_cmd_pkt header
;
2380 struct mwl8k_rate_table rate_table
;
2382 /* Unicast, Broadcast or Multicast */
2386 } __attribute__((packed
));
2388 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw
*hw
,
2389 u32 action
, u32 rate_type
, struct mwl8k_rate_table
*rate_table
)
2391 struct mwl8k_cmd_use_fixed_rate
*cmd
;
2395 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2399 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2400 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2402 cmd
->action
= cpu_to_le32(action
);
2403 cmd
->rate_type
= cpu_to_le32(rate_type
);
2405 if (rate_table
!= NULL
) {
2406 /* Copy over each field manually so
2407 * that bitflipping can be done
2409 cmd
->rate_table
.allow_rate_drop
=
2410 cpu_to_le32(rate_table
->allow_rate_drop
);
2411 cmd
->rate_table
.num_rates
=
2412 cpu_to_le32(rate_table
->num_rates
);
2414 for (count
= 0; count
< rate_table
->num_rates
; count
++) {
2415 struct mwl8k_rate_entry
*dst
=
2416 &cmd
->rate_table
.rate_entry
[count
];
2417 struct mwl8k_rate_entry
*src
=
2418 &rate_table
->rate_entry
[count
];
2420 dst
->is_ht_rate
= cpu_to_le32(src
->is_ht_rate
);
2421 dst
->enable_retry
= cpu_to_le32(src
->enable_retry
);
2422 dst
->rate
= cpu_to_le32(src
->rate
);
2423 dst
->retry_count
= cpu_to_le32(src
->retry_count
);
2427 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2435 * Interrupt handling.
2437 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
2439 struct ieee80211_hw
*hw
= dev_id
;
2440 struct mwl8k_priv
*priv
= hw
->priv
;
2443 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2444 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2449 if (status
& MWL8K_A2H_INT_TX_DONE
)
2450 tasklet_schedule(&priv
->tx_reclaim_task
);
2452 if (status
& MWL8K_A2H_INT_RX_READY
) {
2453 while (rxq_process(hw
, 0, 1))
2454 rxq_refill(hw
, 0, 1);
2457 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
2458 if (priv
->hostcmd_wait
!= NULL
) {
2459 complete(priv
->hostcmd_wait
);
2460 priv
->hostcmd_wait
= NULL
;
2464 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
2465 if (!priv
->inconfig
&&
2467 mwl8k_txq_busy(priv
))
2468 mwl8k_tx_start(priv
);
2476 * Core driver operations.
2478 static int mwl8k_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2480 struct mwl8k_priv
*priv
= hw
->priv
;
2481 int index
= skb_get_queue_mapping(skb
);
2484 if (priv
->current_channel
== NULL
) {
2485 printk(KERN_DEBUG
"%s: dropped TX frame since radio "
2486 "disabled\n", priv
->name
);
2488 return NETDEV_TX_OK
;
2491 rc
= mwl8k_txq_xmit(hw
, index
, skb
);
2496 struct mwl8k_work_struct
{
2497 /* Initialized by mwl8k_queue_work(). */
2498 struct work_struct wt
;
2500 /* Required field passed in to mwl8k_queue_work(). */
2501 struct ieee80211_hw
*hw
;
2503 /* Required field passed in to mwl8k_queue_work(). */
2504 int (*wfunc
)(struct work_struct
*w
);
2506 /* Initialized by mwl8k_queue_work(). */
2507 struct completion
*cmd_wait
;
2513 * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
2514 * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
2518 /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
2519 unsigned long timeout_ms
;
2521 /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
2522 u32 txwait_attempts
;
2524 /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
2529 /* Flags controlling behavior of config queue requests */
2531 /* Caller spins while waiting for completion. */
2532 #define MWL8K_WQ_SPIN 0x00000001
2534 /* Wait for TX queues to empty before proceeding with configuration. */
2535 #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
2537 /* Queue request and return immediately. */
2538 #define MWL8K_WQ_POST_REQUEST 0x00000004
2541 * Caller sleeps and waits for task complete notification.
2542 * Do not use in atomic context.
2544 #define MWL8K_WQ_SLEEP 0x00000008
2546 /* Free work struct when task is done. */
2547 #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
2550 * Config request is queued and returns to caller imediately. Use
2551 * this in atomic context. Work struct is freed by mwl8k_queue_work()
2552 * when this flag is set.
2554 #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
2555 MWL8K_WQ_FREE_WORKSTRUCT)
2557 /* Default work queue behavior is to sleep and wait for tx completion. */
2558 #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
2561 * Default config request timeout. Add adjustments to make sure the
2562 * config thread waits long enough for both tx wait and cmd wait before
2566 /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
2567 #define MWL8K_TXWAIT_TIMEOUT_MS 1000
2569 /* Default number of TX wait attempts. */
2570 #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
2572 /* Total time to wait for TXQ to drain. */
2573 #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
2574 MWL8K_WQ_TXWAIT_ATTEMPTS)
2576 /* Scheduling slop. */
2577 #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
2579 #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
2581 MWL8K_OS_SCHEDULE_OVERHEAD_MS)
2583 static void mwl8k_config_thread(struct work_struct
*wt
)
2585 struct mwl8k_work_struct
*worker
= (struct mwl8k_work_struct
*)wt
;
2586 struct ieee80211_hw
*hw
= worker
->hw
;
2587 struct mwl8k_priv
*priv
= hw
->priv
;
2590 spin_lock_irq(&priv
->tx_lock
);
2591 priv
->inconfig
= true;
2592 spin_unlock_irq(&priv
->tx_lock
);
2594 ieee80211_stop_queues(hw
);
2597 * Wait for host queues to drain before doing PHY
2598 * reconfiguration. This avoids interrupting any in-flight
2599 * DMA transfers to the hardware.
2601 if (worker
->options
& MWL8K_WQ_TX_WAIT_EMPTY
) {
2605 u32 tx_wait_attempts
= worker
->txwait_attempts
;
2607 time_remaining
= worker
->tx_timeout_ms
;
2608 if (!tx_wait_attempts
)
2609 tx_wait_attempts
= 1;
2611 timeout
= worker
->tx_timeout_ms
/tx_wait_attempts
;
2615 iter
= tx_wait_attempts
;
2619 if (time_remaining
> timeout
) {
2620 time_remaining
-= timeout
;
2621 wait_time
= timeout
;
2623 wait_time
= time_remaining
;
2628 rc
= mwl8k_tx_wait_empty(hw
, wait_time
);
2630 printk(KERN_ERR
"%s() txwait timeout=%ums "
2631 "Retry:%u/%u\n", __func__
, timeout
,
2632 tx_wait_attempts
- iter
+ 1,
2635 } while (rc
&& --iter
);
2637 rc
= iter
? 0 : -ETIMEDOUT
;
2640 rc
= worker
->wfunc(wt
);
2642 spin_lock_irq(&priv
->tx_lock
);
2643 priv
->inconfig
= false;
2644 if (priv
->pending_tx_pkts
&& priv
->radio_on
)
2645 mwl8k_tx_start(priv
);
2646 spin_unlock_irq(&priv
->tx_lock
);
2647 ieee80211_wake_queues(hw
);
2650 if (worker
->options
& MWL8K_WQ_SLEEP
)
2651 complete(worker
->cmd_wait
);
2653 if (worker
->options
& MWL8K_WQ_FREE_WORKSTRUCT
)
2657 static int mwl8k_queue_work(struct ieee80211_hw
*hw
,
2658 struct mwl8k_work_struct
*worker
,
2659 struct workqueue_struct
*wqueue
,
2660 int (*wfunc
)(struct work_struct
*w
))
2662 unsigned long timeout
= 0;
2665 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
2667 if (!worker
->timeout_ms
)
2668 worker
->timeout_ms
= MWL8K_CONFIG_TIMEOUT_MS
;
2670 if (!worker
->options
)
2671 worker
->options
= MWL8K_WQ_DEFAULT_OPTIONS
;
2673 if (!worker
->txwait_attempts
)
2674 worker
->txwait_attempts
= MWL8K_WQ_TXWAIT_ATTEMPTS
;
2676 if (!worker
->tx_timeout_ms
)
2677 worker
->tx_timeout_ms
= MWL8K_TXWAIT_MS
;
2680 worker
->cmd_wait
= &cmd_wait
;
2682 worker
->wfunc
= wfunc
;
2684 INIT_WORK(&worker
->wt
, mwl8k_config_thread
);
2685 queue_work(wqueue
, &worker
->wt
);
2687 if (worker
->options
& MWL8K_WQ_POST_REQUEST
) {
2690 if (worker
->options
& MWL8K_WQ_SPIN
) {
2691 timeout
= worker
->timeout_ms
;
2692 while (timeout
&& (worker
->rc
> 0)) {
2696 } else if (worker
->options
& MWL8K_WQ_SLEEP
)
2697 timeout
= wait_for_completion_timeout(&cmd_wait
,
2698 msecs_to_jiffies(worker
->timeout_ms
));
2703 cancel_work_sync(&worker
->wt
);
2711 struct mwl8k_start_worker
{
2712 struct mwl8k_work_struct header
;
2715 static int mwl8k_start_wt(struct work_struct
*wt
)
2717 struct mwl8k_start_worker
*worker
= (struct mwl8k_start_worker
*)wt
;
2718 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2719 struct mwl8k_priv
*priv
= hw
->priv
;
2722 if (priv
->vif
!= NULL
) {
2724 goto mwl8k_start_exit
;
2728 if (mwl8k_cmd_802_11_radio_enable(hw
)) {
2730 goto mwl8k_start_exit
;
2733 /* Purge TX/RX HW queues */
2734 if (mwl8k_cmd_set_pre_scan(hw
)) {
2736 goto mwl8k_start_exit
;
2739 if (mwl8k_cmd_set_post_scan(hw
, "\x00\x00\x00\x00\x00\x00")) {
2741 goto mwl8k_start_exit
;
2744 /* Enable firmware rate adaptation */
2745 if (mwl8k_cmd_setrateadaptmode(hw
, 0)) {
2747 goto mwl8k_start_exit
;
2750 /* Disable WMM. WMM gets enabled when stack sends WMM parms */
2751 if (mwl8k_set_wmm(hw
, 0)) {
2753 goto mwl8k_start_exit
;
2756 /* Disable sniffer mode */
2757 if (mwl8k_enable_sniffer(hw
, 0))
2764 static int mwl8k_start(struct ieee80211_hw
*hw
)
2766 struct mwl8k_start_worker
*worker
;
2767 struct mwl8k_priv
*priv
= hw
->priv
;
2770 /* Enable tx reclaim tasklet */
2771 tasklet_enable(&priv
->tx_reclaim_task
);
2773 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
2774 IRQF_SHARED
, MWL8K_NAME
, hw
);
2776 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
2779 goto mwl8k_start_disable_tasklet
;
2782 /* Enable interrupts */
2783 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2785 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2786 if (worker
== NULL
) {
2788 goto mwl8k_start_disable_irq
;
2791 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2792 priv
->config_wq
, mwl8k_start_wt
);
2797 if (rc
== -ETIMEDOUT
)
2798 printk(KERN_ERR
"%s() timed out\n", __func__
);
2802 mwl8k_start_disable_irq
:
2803 spin_lock_irq(&priv
->tx_lock
);
2804 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2805 spin_unlock_irq(&priv
->tx_lock
);
2806 free_irq(priv
->pdev
->irq
, hw
);
2808 mwl8k_start_disable_tasklet
:
2809 tasklet_disable(&priv
->tx_reclaim_task
);
2814 struct mwl8k_stop_worker
{
2815 struct mwl8k_work_struct header
;
2818 static int mwl8k_stop_wt(struct work_struct
*wt
)
2820 struct mwl8k_stop_worker
*worker
= (struct mwl8k_stop_worker
*)wt
;
2821 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2823 return mwl8k_cmd_802_11_radio_disable(hw
);
2826 static void mwl8k_stop(struct ieee80211_hw
*hw
)
2829 struct mwl8k_stop_worker
*worker
;
2830 struct mwl8k_priv
*priv
= hw
->priv
;
2833 if (priv
->vif
!= NULL
)
2836 ieee80211_stop_queues(hw
);
2838 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2842 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2843 priv
->config_wq
, mwl8k_stop_wt
);
2845 if (rc
== -ETIMEDOUT
)
2846 printk(KERN_ERR
"%s() timed out\n", __func__
);
2848 /* Disable interrupts */
2849 spin_lock_irq(&priv
->tx_lock
);
2850 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2851 spin_unlock_irq(&priv
->tx_lock
);
2852 free_irq(priv
->pdev
->irq
, hw
);
2854 /* Stop finalize join worker */
2855 cancel_work_sync(&priv
->finalize_join_worker
);
2856 if (priv
->beacon_skb
!= NULL
)
2857 dev_kfree_skb(priv
->beacon_skb
);
2859 /* Stop tx reclaim tasklet */
2860 tasklet_disable(&priv
->tx_reclaim_task
);
2862 /* Stop config thread */
2863 flush_workqueue(priv
->config_wq
);
2865 /* Return all skbs to mac80211 */
2866 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2867 mwl8k_txq_reclaim(hw
, i
, 1);
2870 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
2871 struct ieee80211_if_init_conf
*conf
)
2873 struct mwl8k_priv
*priv
= hw
->priv
;
2874 struct mwl8k_vif
*mwl8k_vif
;
2877 * We only support one active interface at a time.
2879 if (priv
->vif
!= NULL
)
2883 * We only support managed interfaces for now.
2885 if (conf
->type
!= NL80211_IFTYPE_STATION
&&
2886 conf
->type
!= NL80211_IFTYPE_MONITOR
)
2889 /* Clean out driver private area */
2890 mwl8k_vif
= MWL8K_VIF(conf
->vif
);
2891 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
2893 /* Save the mac address */
2894 memcpy(mwl8k_vif
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
2896 /* Back pointer to parent config block */
2897 mwl8k_vif
->priv
= priv
;
2899 /* Setup initial PHY parameters */
2900 memcpy(mwl8k_vif
->legacy_rates
,
2901 priv
->rates
, sizeof(mwl8k_vif
->legacy_rates
));
2902 mwl8k_vif
->legacy_nrates
= ARRAY_SIZE(priv
->rates
);
2904 /* Set Initial sequence number to zero */
2905 mwl8k_vif
->seqno
= 0;
2907 priv
->vif
= conf
->vif
;
2908 priv
->current_channel
= NULL
;
2913 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
2914 struct ieee80211_if_init_conf
*conf
)
2916 struct mwl8k_priv
*priv
= hw
->priv
;
2918 if (priv
->vif
== NULL
)
2924 struct mwl8k_config_worker
{
2925 struct mwl8k_work_struct header
;
2929 static int mwl8k_config_wt(struct work_struct
*wt
)
2931 struct mwl8k_config_worker
*worker
=
2932 (struct mwl8k_config_worker
*)wt
;
2933 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2934 struct ieee80211_conf
*conf
= &hw
->conf
;
2935 struct mwl8k_priv
*priv
= hw
->priv
;
2938 if (mwl8k_cmd_802_11_radio_enable(hw
)) {
2940 goto mwl8k_config_exit
;
2943 priv
->current_channel
= conf
->channel
;
2945 if (mwl8k_cmd_set_rf_channel(hw
, conf
->channel
)) {
2947 goto mwl8k_config_exit
;
2950 if (conf
->power_level
> 18)
2951 conf
->power_level
= 18;
2952 if (mwl8k_cmd_802_11_rf_tx_power(hw
, conf
->power_level
)) {
2954 goto mwl8k_config_exit
;
2957 if (mwl8k_cmd_mimo_config(hw
, 0x7, 0x7))
2964 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
2967 struct mwl8k_config_worker
*worker
;
2968 struct mwl8k_priv
*priv
= hw
->priv
;
2970 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2974 worker
->changed
= changed
;
2975 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2976 priv
->config_wq
, mwl8k_config_wt
);
2977 if (rc
== -ETIMEDOUT
) {
2978 printk(KERN_ERR
"%s() timed out.\n", __func__
);
2985 * mac80211 will crash on anything other than -EINVAL on
2986 * error. Looks like wireless extensions which calls mac80211
2987 * may be the actual culprit...
2989 return rc
? -EINVAL
: 0;
2992 struct mwl8k_bss_info_changed_worker
{
2993 struct mwl8k_work_struct header
;
2994 struct ieee80211_vif
*vif
;
2995 struct ieee80211_bss_conf
*info
;
2999 static int mwl8k_bss_info_changed_wt(struct work_struct
*wt
)
3001 struct mwl8k_bss_info_changed_worker
*worker
=
3002 (struct mwl8k_bss_info_changed_worker
*)wt
;
3003 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3004 struct ieee80211_vif
*vif
= worker
->vif
;
3005 struct ieee80211_bss_conf
*info
= worker
->info
;
3009 struct mwl8k_priv
*priv
= hw
->priv
;
3010 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3012 changed
= worker
->changed
;
3013 priv
->capture_beacon
= false;
3016 memcpy(&mwl8k_vif
->bss_info
, info
,
3017 sizeof(struct ieee80211_bss_conf
));
3020 if (mwl8k_update_rateset(hw
, vif
))
3021 goto mwl8k_bss_info_changed_exit
;
3023 /* Turn on rate adaptation */
3024 if (mwl8k_cmd_use_fixed_rate(hw
, MWL8K_USE_AUTO_RATE
,
3025 MWL8K_UCAST_RATE
, NULL
))
3026 goto mwl8k_bss_info_changed_exit
;
3028 /* Set radio preamble */
3029 if (mwl8k_set_radio_preamble(hw
, info
->use_short_preamble
))
3030 goto mwl8k_bss_info_changed_exit
;
3033 if (mwl8k_cmd_set_slot(hw
, info
->use_short_slot
))
3034 goto mwl8k_bss_info_changed_exit
;
3036 /* Update peer rate info */
3037 if (mwl8k_cmd_update_sta_db(hw
, vif
,
3038 MWL8K_STA_DB_MODIFY_ENTRY
))
3039 goto mwl8k_bss_info_changed_exit
;
3042 if (mwl8k_cmd_set_aid(hw
, vif
))
3043 goto mwl8k_bss_info_changed_exit
;
3046 * Finalize the join. Tell rx handler to process
3047 * next beacon from our BSSID.
3049 memcpy(priv
->capture_bssid
, mwl8k_vif
->bssid
, ETH_ALEN
);
3050 priv
->capture_beacon
= true;
3052 mwl8k_cmd_update_sta_db(hw
, vif
, MWL8K_STA_DB_DEL_ENTRY
);
3053 memset(&mwl8k_vif
->bss_info
, 0,
3054 sizeof(struct ieee80211_bss_conf
));
3055 memset(mwl8k_vif
->bssid
, 0, ETH_ALEN
);
3058 mwl8k_bss_info_changed_exit
:
3063 static void mwl8k_bss_info_changed(struct ieee80211_hw
*hw
,
3064 struct ieee80211_vif
*vif
,
3065 struct ieee80211_bss_conf
*info
,
3068 struct mwl8k_bss_info_changed_worker
*worker
;
3069 struct mwl8k_priv
*priv
= hw
->priv
;
3070 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
3073 if (changed
& BSS_CHANGED_BSSID
)
3074 memcpy(mv_vif
->bssid
, info
->bssid
, ETH_ALEN
);
3076 if ((changed
& BSS_CHANGED_ASSOC
) == 0)
3079 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3084 worker
->info
= info
;
3085 worker
->changed
= changed
;
3086 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3088 mwl8k_bss_info_changed_wt
);
3090 if (rc
== -ETIMEDOUT
)
3091 printk(KERN_ERR
"%s() timed out\n", __func__
);
3094 struct mwl8k_configure_filter_worker
{
3095 struct mwl8k_work_struct header
;
3096 unsigned int changed_flags
;
3097 unsigned int *total_flags
;
3099 struct dev_addr_list
*mclist
;
3102 #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
3104 static int mwl8k_configure_filter_wt(struct work_struct
*wt
)
3106 struct mwl8k_configure_filter_worker
*worker
=
3107 (struct mwl8k_configure_filter_worker
*)wt
;
3109 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3110 unsigned int changed_flags
= worker
->changed_flags
;
3111 unsigned int *total_flags
= worker
->total_flags
;
3112 int mc_count
= worker
->mc_count
;
3113 struct dev_addr_list
*mclist
= worker
->mclist
;
3115 struct mwl8k_priv
*priv
= hw
->priv
;
3118 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
3119 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
3120 rc
= mwl8k_cmd_set_pre_scan(hw
);
3124 bssid
= "\x00\x00\x00\x00\x00\x00";
3125 if (priv
->vif
!= NULL
)
3126 bssid
= MWL8K_VIF(priv
->vif
)->bssid
;
3128 rc
= mwl8k_cmd_set_post_scan(hw
, bssid
);
3133 goto mwl8k_configure_filter_exit
;
3135 if (mc_count
> priv
->num_mcaddrs
)
3136 mc_count
= priv
->num_mcaddrs
;
3138 rc
= mwl8k_cmd_mac_multicast_adr(hw
, mc_count
, mclist
);
3141 "%s()Error setting multicast addresses\n",
3145 mwl8k_configure_filter_exit
:
3149 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
3150 int mc_count
, struct dev_addr_list
*mclist
)
3152 struct mwl8k_configure_filter_worker
*worker
;
3154 worker
= kzalloc(sizeof(*worker
), GFP_ATOMIC
);
3160 * XXX: This is _HORRIBLY_ broken!!
3162 * No locking, the mclist pointer might be invalid as soon as this
3163 * function returns, something in the list might be invalidated
3164 * once we get to the worker, etc...
3166 worker
->mc_count
= mc_count
;
3167 worker
->mclist
= mclist
;
3172 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
3173 unsigned int changed_flags
,
3174 unsigned int *total_flags
,
3178 struct mwl8k_configure_filter_worker
*worker
= (void *)multicast
;
3179 struct mwl8k_priv
*priv
= hw
->priv
;
3181 /* Clear unsupported feature flags */
3182 *total_flags
&= MWL8K_SUPPORTED_IF_FLAGS
;
3184 if (!(changed_flags
& MWL8K_SUPPORTED_IF_FLAGS
))
3190 worker
->header
.options
= MWL8K_WQ_QUEUE_ONLY
| MWL8K_WQ_TX_WAIT_EMPTY
;
3191 worker
->changed_flags
= changed_flags
;
3192 worker
->total_flags
= total_flags
;
3194 mwl8k_queue_work(hw
, &worker
->header
, priv
->config_wq
,
3195 mwl8k_configure_filter_wt
);
3198 struct mwl8k_set_rts_threshold_worker
{
3199 struct mwl8k_work_struct header
;
3203 static int mwl8k_set_rts_threshold_wt(struct work_struct
*wt
)
3205 struct mwl8k_set_rts_threshold_worker
*worker
=
3206 (struct mwl8k_set_rts_threshold_worker
*)wt
;
3208 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3209 u16 threshold
= (u16
)(worker
->value
);
3212 rc
= mwl8k_rts_threshold(hw
, MWL8K_CMD_SET
, &threshold
);
3217 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3220 struct mwl8k_set_rts_threshold_worker
*worker
;
3221 struct mwl8k_priv
*priv
= hw
->priv
;
3223 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3227 worker
->value
= value
;
3229 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3231 mwl8k_set_rts_threshold_wt
);
3234 if (rc
== -ETIMEDOUT
) {
3235 printk(KERN_ERR
"%s() timed out\n", __func__
);
3242 struct mwl8k_conf_tx_worker
{
3243 struct mwl8k_work_struct header
;
3245 const struct ieee80211_tx_queue_params
*params
;
3248 static int mwl8k_conf_tx_wt(struct work_struct
*wt
)
3250 struct mwl8k_conf_tx_worker
*worker
=
3251 (struct mwl8k_conf_tx_worker
*)wt
;
3253 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3254 u16 queue
= worker
->queue
;
3255 const struct ieee80211_tx_queue_params
*params
= worker
->params
;
3257 struct mwl8k_priv
*priv
= hw
->priv
;
3260 if (!priv
->wmm_enabled
) {
3261 if (mwl8k_set_wmm(hw
, 1)) {
3263 goto mwl8k_conf_tx_exit
;
3267 if (mwl8k_set_edca_params(hw
, GET_TXQ(queue
), params
->cw_min
,
3268 params
->cw_max
, params
->aifs
, params
->txop
))
3274 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
3275 const struct ieee80211_tx_queue_params
*params
)
3278 struct mwl8k_conf_tx_worker
*worker
;
3279 struct mwl8k_priv
*priv
= hw
->priv
;
3281 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3285 worker
->queue
= queue
;
3286 worker
->params
= params
;
3287 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3288 priv
->config_wq
, mwl8k_conf_tx_wt
);
3290 if (rc
== -ETIMEDOUT
) {
3291 printk(KERN_ERR
"%s() timed out\n", __func__
);
3297 static int mwl8k_get_tx_stats(struct ieee80211_hw
*hw
,
3298 struct ieee80211_tx_queue_stats
*stats
)
3300 struct mwl8k_priv
*priv
= hw
->priv
;
3301 struct mwl8k_tx_queue
*txq
;
3304 spin_lock_bh(&priv
->tx_lock
);
3305 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++) {
3306 txq
= priv
->txq
+ index
;
3307 memcpy(&stats
[index
], &txq
->tx_stats
,
3308 sizeof(struct ieee80211_tx_queue_stats
));
3310 spin_unlock_bh(&priv
->tx_lock
);
3314 struct mwl8k_get_stats_worker
{
3315 struct mwl8k_work_struct header
;
3316 struct ieee80211_low_level_stats
*stats
;
3319 static int mwl8k_get_stats_wt(struct work_struct
*wt
)
3321 struct mwl8k_get_stats_worker
*worker
=
3322 (struct mwl8k_get_stats_worker
*)wt
;
3324 return mwl8k_cmd_802_11_get_stat(worker
->header
.hw
, worker
->stats
);
3327 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
3328 struct ieee80211_low_level_stats
*stats
)
3331 struct mwl8k_get_stats_worker
*worker
;
3332 struct mwl8k_priv
*priv
= hw
->priv
;
3334 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3338 worker
->stats
= stats
;
3339 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3340 priv
->config_wq
, mwl8k_get_stats_wt
);
3343 if (rc
== -ETIMEDOUT
) {
3344 printk(KERN_ERR
"%s() timed out\n", __func__
);
3351 static const struct ieee80211_ops mwl8k_ops
= {
3353 .start
= mwl8k_start
,
3355 .add_interface
= mwl8k_add_interface
,
3356 .remove_interface
= mwl8k_remove_interface
,
3357 .config
= mwl8k_config
,
3358 .bss_info_changed
= mwl8k_bss_info_changed
,
3359 .prepare_multicast
= mwl8k_prepare_multicast
,
3360 .configure_filter
= mwl8k_configure_filter
,
3361 .set_rts_threshold
= mwl8k_set_rts_threshold
,
3362 .conf_tx
= mwl8k_conf_tx
,
3363 .get_tx_stats
= mwl8k_get_tx_stats
,
3364 .get_stats
= mwl8k_get_stats
,
3367 static void mwl8k_tx_reclaim_handler(unsigned long data
)
3370 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*) data
;
3371 struct mwl8k_priv
*priv
= hw
->priv
;
3373 spin_lock_bh(&priv
->tx_lock
);
3374 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3375 mwl8k_txq_reclaim(hw
, i
, 0);
3377 if (priv
->tx_wait
!= NULL
&& mwl8k_txq_busy(priv
) == 0) {
3378 complete(priv
->tx_wait
);
3379 priv
->tx_wait
= NULL
;
3381 spin_unlock_bh(&priv
->tx_lock
);
3384 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
3386 struct mwl8k_priv
*priv
=
3387 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
3388 struct sk_buff
*skb
= priv
->beacon_skb
;
3389 u8 dtim
= MWL8K_VIF(priv
->vif
)->bss_info
.dtim_period
;
3391 mwl8k_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim
);
3394 priv
->beacon_skb
= NULL
;
3397 static int __devinit
mwl8k_probe(struct pci_dev
*pdev
,
3398 const struct pci_device_id
*id
)
3400 struct ieee80211_hw
*hw
;
3401 struct mwl8k_priv
*priv
;
3406 rc
= pci_enable_device(pdev
);
3408 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
3413 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
3415 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
3420 pci_set_master(pdev
);
3422 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
3424 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
3432 priv
->hostcmd_wait
= NULL
;
3433 priv
->tx_wait
= NULL
;
3434 priv
->inconfig
= false;
3435 priv
->wmm_enabled
= false;
3436 priv
->pending_tx_pkts
= 0;
3437 strncpy(priv
->name
, MWL8K_NAME
, sizeof(priv
->name
));
3439 spin_lock_init(&priv
->fw_lock
);
3441 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
3442 pci_set_drvdata(pdev
, hw
);
3444 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
3445 if (priv
->regs
== NULL
) {
3446 printk(KERN_ERR
"%s: Cannot map device memory\n", priv
->name
);
3450 memcpy(priv
->channels
, mwl8k_channels
, sizeof(mwl8k_channels
));
3451 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
3452 priv
->band
.channels
= priv
->channels
;
3453 priv
->band
.n_channels
= ARRAY_SIZE(mwl8k_channels
);
3454 priv
->band
.bitrates
= priv
->rates
;
3455 priv
->band
.n_bitrates
= ARRAY_SIZE(mwl8k_rates
);
3456 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
3458 BUILD_BUG_ON(sizeof(priv
->rates
) != sizeof(mwl8k_rates
));
3459 memcpy(priv
->rates
, mwl8k_rates
, sizeof(mwl8k_rates
));
3462 * Extra headroom is the size of the required DMA header
3463 * minus the size of the smallest 802.11 frame (CTS frame).
3465 hw
->extra_tx_headroom
=
3466 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
3468 hw
->channel_change_time
= 10;
3470 hw
->queues
= MWL8K_TX_QUEUES
;
3472 hw
->wiphy
->interface_modes
=
3473 BIT(NL80211_IFTYPE_STATION
) | BIT(NL80211_IFTYPE_MONITOR
);
3475 /* Set rssi and noise values to dBm */
3476 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
| IEEE80211_HW_NOISE_DBM
;
3477 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
3480 /* Set default radio state and preamble */
3482 priv
->radio_short_preamble
= 0;
3484 /* Finalize join worker */
3485 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
3487 /* TX reclaim tasklet */
3488 tasklet_init(&priv
->tx_reclaim_task
,
3489 mwl8k_tx_reclaim_handler
, (unsigned long)hw
);
3490 tasklet_disable(&priv
->tx_reclaim_task
);
3492 /* Config workthread */
3493 priv
->config_wq
= create_singlethread_workqueue("mwl8k_config");
3494 if (priv
->config_wq
== NULL
)
3497 /* Power management cookie */
3498 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
3499 if (priv
->cookie
== NULL
)
3502 rc
= mwl8k_rxq_init(hw
, 0);
3505 rxq_refill(hw
, 0, INT_MAX
);
3507 spin_lock_init(&priv
->tx_lock
);
3509 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
3510 rc
= mwl8k_txq_init(hw
, i
);
3512 goto err_free_queues
;
3515 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3516 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3517 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
3518 iowrite32(0xffffffff, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3520 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
3521 IRQF_SHARED
, MWL8K_NAME
, hw
);
3523 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
3525 goto err_free_queues
;
3528 /* Reset firmware and hardware */
3529 mwl8k_hw_reset(priv
);
3531 /* Ask userland hotplug daemon for the device firmware */
3532 rc
= mwl8k_request_firmware(priv
, (u32
)id
->driver_data
);
3534 printk(KERN_ERR
"%s: Firmware files not found\n", priv
->name
);
3538 /* Load firmware into hardware */
3539 rc
= mwl8k_load_firmware(priv
);
3541 printk(KERN_ERR
"%s: Cannot start firmware\n", priv
->name
);
3542 goto err_stop_firmware
;
3545 /* Reclaim memory once firmware is successfully loaded */
3546 mwl8k_release_firmware(priv
);
3549 * Temporarily enable interrupts. Initial firmware host
3550 * commands use interrupts and avoids polling. Disable
3551 * interrupts when done.
3553 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3555 /* Get config data, mac addrs etc */
3556 rc
= mwl8k_cmd_get_hw_spec(hw
);
3558 printk(KERN_ERR
"%s: Cannot initialise firmware\n", priv
->name
);
3559 goto err_stop_firmware
;
3562 /* Turn radio off */
3563 rc
= mwl8k_cmd_802_11_radio_disable(hw
);
3565 printk(KERN_ERR
"%s: Cannot disable\n", priv
->name
);
3566 goto err_stop_firmware
;
3569 /* Disable interrupts */
3570 spin_lock_irq(&priv
->tx_lock
);
3571 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3572 spin_unlock_irq(&priv
->tx_lock
);
3573 free_irq(priv
->pdev
->irq
, hw
);
3575 rc
= ieee80211_register_hw(hw
);
3577 printk(KERN_ERR
"%s: Cannot register device\n", priv
->name
);
3578 goto err_stop_firmware
;
3581 fw
= (u8
*)&priv
->fw_rev
;
3582 printk(KERN_INFO
"%s: 88W%u %s\n", priv
->name
, priv
->part_num
,
3584 printk(KERN_INFO
"%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
3585 priv
->name
, MWL8K_VERSION
, fw
[3], fw
[2], fw
[1], fw
[0]);
3586 printk(KERN_INFO
"%s: MAC Address: %pM\n", priv
->name
,
3587 hw
->wiphy
->perm_addr
);
3592 mwl8k_hw_reset(priv
);
3593 mwl8k_release_firmware(priv
);
3596 spin_lock_irq(&priv
->tx_lock
);
3597 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3598 spin_unlock_irq(&priv
->tx_lock
);
3599 free_irq(priv
->pdev
->irq
, hw
);
3602 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3603 mwl8k_txq_deinit(hw
, i
);
3604 mwl8k_rxq_deinit(hw
, 0);
3607 if (priv
->cookie
!= NULL
)
3608 pci_free_consistent(priv
->pdev
, 4,
3609 priv
->cookie
, priv
->cookie_dma
);
3611 if (priv
->regs
!= NULL
)
3612 pci_iounmap(pdev
, priv
->regs
);
3614 if (priv
->config_wq
!= NULL
)
3615 destroy_workqueue(priv
->config_wq
);
3617 pci_set_drvdata(pdev
, NULL
);
3618 ieee80211_free_hw(hw
);
3621 pci_release_regions(pdev
);
3622 pci_disable_device(pdev
);
3627 static void __devexit
mwl8k_shutdown(struct pci_dev
*pdev
)
3629 printk(KERN_ERR
"===>%s(%u)\n", __func__
, __LINE__
);
3632 static void __devexit
mwl8k_remove(struct pci_dev
*pdev
)
3634 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
3635 struct mwl8k_priv
*priv
;
3642 ieee80211_stop_queues(hw
);
3644 ieee80211_unregister_hw(hw
);
3646 /* Remove tx reclaim tasklet */
3647 tasklet_kill(&priv
->tx_reclaim_task
);
3649 /* Stop config thread */
3650 destroy_workqueue(priv
->config_wq
);
3653 mwl8k_hw_reset(priv
);
3655 /* Return all skbs to mac80211 */
3656 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3657 mwl8k_txq_reclaim(hw
, i
, 1);
3659 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3660 mwl8k_txq_deinit(hw
, i
);
3662 mwl8k_rxq_deinit(hw
, 0);
3664 pci_free_consistent(priv
->pdev
, 4,
3665 priv
->cookie
, priv
->cookie_dma
);
3667 pci_iounmap(pdev
, priv
->regs
);
3668 pci_set_drvdata(pdev
, NULL
);
3669 ieee80211_free_hw(hw
);
3670 pci_release_regions(pdev
);
3671 pci_disable_device(pdev
);
3674 static struct pci_driver mwl8k_driver
= {
3676 .id_table
= mwl8k_table
,
3677 .probe
= mwl8k_probe
,
3678 .remove
= __devexit_p(mwl8k_remove
),
3679 .shutdown
= __devexit_p(mwl8k_shutdown
),
3682 static int __init
mwl8k_init(void)
3684 return pci_register_driver(&mwl8k_driver
);
3687 static void __exit
mwl8k_exit(void)
3689 pci_unregister_driver(&mwl8k_driver
);
3692 module_init(mwl8k_init
);
3693 module_exit(mwl8k_exit
);