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
;
192 /* WMM MODE 1 for enabled; 0 for disabled */
195 /* Set if PHY config is in progress */
198 /* XXX need to convert this to handle multiple interfaces */
200 u8 capture_bssid
[ETH_ALEN
];
201 struct sk_buff
*beacon_skb
;
204 * This FJ worker has to be global as it is scheduled from the
205 * RX handler. At this point we don't know which interface it
206 * belongs to until the list of bssids waiting to complete join
209 struct work_struct finalize_join_worker
;
211 /* Tasklet to reclaim TX descriptors and buffers after tx */
212 struct tasklet_struct tx_reclaim_task
;
214 /* Work thread to serialize configuration requests */
215 struct workqueue_struct
*config_wq
;
216 struct completion
*hostcmd_wait
;
217 struct completion
*tx_wait
;
220 /* Per interface specific private data */
222 /* backpointer to parent config block */
223 struct mwl8k_priv
*priv
;
225 /* BSS config of AP or IBSS from mac80211*/
226 struct ieee80211_bss_conf bss_info
;
228 /* BSSID of AP or IBSS */
230 u8 mac_addr
[ETH_ALEN
];
233 * Subset of supported legacy rates.
234 * Intersection of AP and STA supported rates.
236 struct ieee80211_rate legacy_rates
[12];
238 /* number of supported legacy rates */
241 /* Index into station database.Returned by update_sta_db call */
244 /* Non AMPDU sequence number assigned by driver */
248 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
250 static const struct ieee80211_channel mwl8k_channels
[] = {
251 { .center_freq
= 2412, .hw_value
= 1, },
252 { .center_freq
= 2417, .hw_value
= 2, },
253 { .center_freq
= 2422, .hw_value
= 3, },
254 { .center_freq
= 2427, .hw_value
= 4, },
255 { .center_freq
= 2432, .hw_value
= 5, },
256 { .center_freq
= 2437, .hw_value
= 6, },
257 { .center_freq
= 2442, .hw_value
= 7, },
258 { .center_freq
= 2447, .hw_value
= 8, },
259 { .center_freq
= 2452, .hw_value
= 9, },
260 { .center_freq
= 2457, .hw_value
= 10, },
261 { .center_freq
= 2462, .hw_value
= 11, },
264 static const struct ieee80211_rate mwl8k_rates
[] = {
265 { .bitrate
= 10, .hw_value
= 2, },
266 { .bitrate
= 20, .hw_value
= 4, },
267 { .bitrate
= 55, .hw_value
= 11, },
268 { .bitrate
= 60, .hw_value
= 12, },
269 { .bitrate
= 90, .hw_value
= 18, },
270 { .bitrate
= 110, .hw_value
= 22, },
271 { .bitrate
= 120, .hw_value
= 24, },
272 { .bitrate
= 180, .hw_value
= 36, },
273 { .bitrate
= 240, .hw_value
= 48, },
274 { .bitrate
= 360, .hw_value
= 72, },
275 { .bitrate
= 480, .hw_value
= 96, },
276 { .bitrate
= 540, .hw_value
= 108, },
280 #define MWL8K_WMM_ENABLE 1
281 #define MWL8K_WMM_DISABLE 0
285 /* Short Slot: 9us slot time */
286 #define MWL8K_SHORT_SLOTTIME 1
288 /* Long slot: 20us slot time */
289 #define MWL8K_LONG_SLOTTIME 0
291 /* Set or get info from Firmware */
292 #define MWL8K_CMD_SET 0x0001
293 #define MWL8K_CMD_GET 0x0000
295 /* Firmware command codes */
296 #define MWL8K_CMD_CODE_DNLD 0x0001
297 #define MWL8K_CMD_GET_HW_SPEC 0x0003
298 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
299 #define MWL8K_CMD_GET_STAT 0x0014
300 #define MWL8K_CMD_RADIO_CONTROL 0x001c
301 #define MWL8K_CMD_RF_TX_POWER 0x001e
302 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
303 #define MWL8K_CMD_SET_POST_SCAN 0x0108
304 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
305 #define MWL8K_CMD_SET_AID 0x010d
306 #define MWL8K_CMD_SET_RATE 0x0110
307 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
308 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
309 #define MWL8K_CMD_SET_SLOT 0x0114
310 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
311 #define MWL8K_CMD_SET_WMM_MODE 0x0123
312 #define MWL8K_CMD_MIMO_CONFIG 0x0125
313 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
314 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
315 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
316 #define MWL8K_CMD_UPDATE_STADB 0x1123
318 static const char *mwl8k_cmd_name(u16 cmd
, char *buf
, int bufsize
)
320 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
321 snprintf(buf, bufsize, "%s", #x);\
324 switch (cmd
& ~0x8000) {
325 MWL8K_CMDNAME(CODE_DNLD
);
326 MWL8K_CMDNAME(GET_HW_SPEC
);
327 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
328 MWL8K_CMDNAME(GET_STAT
);
329 MWL8K_CMDNAME(RADIO_CONTROL
);
330 MWL8K_CMDNAME(RF_TX_POWER
);
331 MWL8K_CMDNAME(SET_PRE_SCAN
);
332 MWL8K_CMDNAME(SET_POST_SCAN
);
333 MWL8K_CMDNAME(SET_RF_CHANNEL
);
334 MWL8K_CMDNAME(SET_AID
);
335 MWL8K_CMDNAME(SET_RATE
);
336 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
337 MWL8K_CMDNAME(RTS_THRESHOLD
);
338 MWL8K_CMDNAME(SET_SLOT
);
339 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
340 MWL8K_CMDNAME(SET_WMM_MODE
);
341 MWL8K_CMDNAME(MIMO_CONFIG
);
342 MWL8K_CMDNAME(USE_FIXED_RATE
);
343 MWL8K_CMDNAME(ENABLE_SNIFFER
);
344 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
345 MWL8K_CMDNAME(UPDATE_STADB
);
347 snprintf(buf
, bufsize
, "0x%x", cmd
);
354 /* Hardware and firmware reset */
355 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
357 iowrite32(MWL8K_H2A_INT_RESET
,
358 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
359 iowrite32(MWL8K_H2A_INT_RESET
,
360 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
364 /* Release fw image */
365 static void mwl8k_release_fw(struct firmware
**fw
)
369 release_firmware(*fw
);
373 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
375 mwl8k_release_fw(&priv
->fw
.ucode
);
376 mwl8k_release_fw(&priv
->fw
.helper
);
379 /* Request fw image */
380 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
381 const char *fname
, struct firmware
**fw
)
383 /* release current image */
385 mwl8k_release_fw(fw
);
387 return request_firmware((const struct firmware
**)fw
,
388 fname
, &priv
->pdev
->dev
);
391 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, u32 part_num
)
396 priv
->part_num
= part_num
;
398 snprintf(filename
, sizeof(filename
),
399 "mwl8k/helper_%u.fw", priv
->part_num
);
401 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.helper
);
404 "%s Error requesting helper firmware file %s\n",
405 pci_name(priv
->pdev
), filename
);
409 snprintf(filename
, sizeof(filename
),
410 "mwl8k/fmimage_%u.fw", priv
->part_num
);
412 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.ucode
);
414 printk(KERN_ERR
"%s Error requesting firmware file %s\n",
415 pci_name(priv
->pdev
), filename
);
416 mwl8k_release_fw(&priv
->fw
.helper
);
423 struct mwl8k_cmd_pkt
{
429 } __attribute__((packed
));
435 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
437 void __iomem
*regs
= priv
->regs
;
442 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
443 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
446 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
447 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
448 iowrite32(MWL8K_H2A_INT_DOORBELL
,
449 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
450 iowrite32(MWL8K_H2A_INT_DUMMY
,
451 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
458 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
459 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
460 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
468 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
471 * Clear 'command done' interrupt bit.
477 status
= ioread32(priv
->regs
+
478 MWL8K_HIU_A2H_INTERRUPT_STATUS
);
479 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
480 iowrite32(~MWL8K_A2H_INT_OPC_DONE
,
481 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
482 ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
492 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
493 const u8
*data
, size_t length
)
495 struct mwl8k_cmd_pkt
*cmd
;
499 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
503 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
509 int block_size
= length
> 256 ? 256 : length
;
511 memcpy(cmd
->payload
, data
+ done
, block_size
);
512 cmd
->length
= cpu_to_le16(block_size
);
514 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
515 sizeof(*cmd
) + block_size
);
520 length
-= block_size
;
525 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
533 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
534 const u8
*data
, size_t length
)
536 unsigned char *buffer
;
537 int may_continue
, rc
= 0;
538 u32 done
, prev_block_size
;
540 buffer
= kmalloc(1024, GFP_KERNEL
);
547 while (may_continue
> 0) {
550 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
551 if (block_size
& 1) {
555 done
+= prev_block_size
;
556 length
-= prev_block_size
;
559 if (block_size
> 1024 || block_size
> length
) {
569 if (block_size
== 0) {
576 prev_block_size
= block_size
;
577 memcpy(buffer
, data
+ done
, block_size
);
579 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
584 if (!rc
&& length
!= 0)
592 static int mwl8k_load_firmware(struct mwl8k_priv
*priv
)
596 const u8
*ucode
= priv
->fw
.ucode
->data
;
597 size_t ucode_len
= priv
->fw
.ucode
->size
;
598 const u8
*helper
= priv
->fw
.helper
->data
;
599 size_t helper_len
= priv
->fw
.helper
->size
;
601 if (!memcmp(ucode
, "\x01\x00\x00\x00", 4)) {
602 rc
= mwl8k_load_fw_image(priv
, helper
, helper_len
);
604 printk(KERN_ERR
"%s: unable to load firmware "
605 "helper image\n", pci_name(priv
->pdev
));
610 rc
= mwl8k_feed_fw_image(priv
, ucode
, ucode_len
);
612 rc
= mwl8k_load_fw_image(priv
, ucode
, ucode_len
);
616 printk(KERN_ERR
"%s: unable to load firmware data\n",
617 pci_name(priv
->pdev
));
621 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
626 if (ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
)
627 == MWL8K_FWSTA_READY
)
632 return loops
? 0 : -ETIMEDOUT
;
637 * Defines shared between transmission and reception.
639 /* HT control fields for firmware */
644 } __attribute__((packed
));
646 /* Firmware Station database operations */
647 #define MWL8K_STA_DB_ADD_ENTRY 0
648 #define MWL8K_STA_DB_MODIFY_ENTRY 1
649 #define MWL8K_STA_DB_DEL_ENTRY 2
650 #define MWL8K_STA_DB_FLUSH 3
652 /* Peer Entry flags - used to define the type of the peer node */
653 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
655 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
656 #define MWL8K_MCS_BITMAP_SIZE 16
658 struct peer_capability_info
{
659 /* Peer type - AP vs. STA. */
662 /* Basic 802.11 capabilities from assoc resp. */
665 /* Set if peer supports 802.11n high throughput (HT). */
668 /* Valid if HT is supported. */
670 __u8 extended_ht_caps
;
671 struct ewc_ht_info ewc_info
;
673 /* Legacy rate table. Intersection of our rates and peer rates. */
674 __u8 legacy_rates
[MWL8K_IEEE_LEGACY_DATA_RATES
];
676 /* HT rate table. Intersection of our rates and peer rates. */
677 __u8 ht_rates
[MWL8K_MCS_BITMAP_SIZE
];
680 /* If set, interoperability mode, no proprietary extensions. */
684 __le16 amsdu_enabled
;
685 } __attribute__((packed
));
687 /* Inline functions to manipulate QoS field in data descriptor. */
688 static inline u16
mwl8k_qos_setbit_eosp(u16 qos
)
690 u16 val_mask
= 1 << 4;
692 /* End of Service Period Bit 4 */
693 return qos
| val_mask
;
696 static inline u16
mwl8k_qos_setbit_ack(u16 qos
, u8 ack_policy
)
700 u16 qos_mask
= ~(val_mask
<< shift
);
702 /* Ack Policy Bit 5-6 */
703 return (qos
& qos_mask
) | ((ack_policy
& val_mask
) << shift
);
706 static inline u16
mwl8k_qos_setbit_amsdu(u16 qos
)
708 u16 val_mask
= 1 << 7;
710 /* AMSDU present Bit 7 */
711 return qos
| val_mask
;
714 static inline u16
mwl8k_qos_setbit_qlen(u16 qos
, u8 len
)
718 u16 qos_mask
= ~(val_mask
<< shift
);
720 /* Queue Length Bits 8-15 */
721 return (qos
& qos_mask
) | ((len
& val_mask
) << shift
);
724 /* DMA header used by firmware and hardware. */
725 struct mwl8k_dma_data
{
727 struct ieee80211_hdr wh
;
728 } __attribute__((packed
));
730 /* Routines to add/remove DMA header from skb. */
731 static inline int mwl8k_remove_dma_header(struct sk_buff
*skb
)
733 struct mwl8k_dma_data
*tr
= (struct mwl8k_dma_data
*)(skb
->data
);
734 void *dst
, *src
= &tr
->wh
;
735 __le16 fc
= tr
->wh
.frame_control
;
736 int hdrlen
= ieee80211_hdrlen(fc
);
737 u16 space
= sizeof(struct mwl8k_dma_data
) - hdrlen
;
739 dst
= (void *)tr
+ space
;
741 memmove(dst
, src
, hdrlen
);
742 skb_pull(skb
, space
);
748 static inline struct sk_buff
*mwl8k_add_dma_header(struct sk_buff
*skb
)
750 struct ieee80211_hdr
*wh
;
752 struct mwl8k_dma_data
*tr
;
754 wh
= (struct ieee80211_hdr
*)skb
->data
;
755 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
759 * Copy up/down the 802.11 header; the firmware requires
760 * we present a 2-byte payload length followed by a
761 * 4-address header (w/o QoS), followed (optionally) by
762 * any WEP/ExtIV header (but only filled in for CCMP).
764 if (hdrlen
!= sizeof(struct mwl8k_dma_data
))
765 skb_push(skb
, sizeof(struct mwl8k_dma_data
) - hdrlen
);
767 tr
= (struct mwl8k_dma_data
*)skb
->data
;
769 memmove(&tr
->wh
, wh
, hdrlen
);
772 memset(tr
->wh
.addr4
, 0, ETH_ALEN
);
775 * Firmware length is the length of the fully formed "802.11
776 * payload". That is, everything except for the 802.11 header.
777 * This includes all crypto material including the MIC.
779 tr
->fwlen
= cpu_to_le16(pktlen
- hdrlen
);
788 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
790 struct mwl8k_rx_desc
{
794 __le32 pkt_phys_addr
;
795 __le32 next_rx_desc_phys_addr
;
805 } __attribute__((packed
));
807 #define MWL8K_RX_DESCS 256
808 #define MWL8K_RX_MAXSZ 3800
810 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
812 struct mwl8k_priv
*priv
= hw
->priv
;
813 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
817 rxq
->rx_desc_count
= 0;
821 size
= MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
);
824 pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rx_desc_dma
);
825 if (rxq
->rx_desc_area
== NULL
) {
826 printk(KERN_ERR
"%s: failed to alloc RX descriptors\n",
830 memset(rxq
->rx_desc_area
, 0, size
);
832 rxq
->rx_skb
= kmalloc(MWL8K_RX_DESCS
*
833 sizeof(*rxq
->rx_skb
), GFP_KERNEL
);
834 if (rxq
->rx_skb
== NULL
) {
835 printk(KERN_ERR
"%s: failed to alloc RX skbuff list\n",
837 pci_free_consistent(priv
->pdev
, size
,
838 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
841 memset(rxq
->rx_skb
, 0, MWL8K_RX_DESCS
* sizeof(*rxq
->rx_skb
));
843 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
844 struct mwl8k_rx_desc
*rx_desc
;
847 rx_desc
= rxq
->rx_desc_area
+ i
;
848 nexti
= (i
+ 1) % MWL8K_RX_DESCS
;
850 rx_desc
->next_rx_desc_phys_addr
=
851 cpu_to_le32(rxq
->rx_desc_dma
852 + nexti
* sizeof(*rx_desc
));
853 rx_desc
->rx_ctrl
= MWL8K_RX_CTRL_OWNED_BY_HOST
;
859 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
861 struct mwl8k_priv
*priv
= hw
->priv
;
862 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
866 while (rxq
->rx_desc_count
< MWL8K_RX_DESCS
&& limit
--) {
870 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
874 rxq
->rx_desc_count
++;
877 rxq
->rx_tail
= (rx
+ 1) % MWL8K_RX_DESCS
;
879 rxq
->rx_desc_area
[rx
].pkt_phys_addr
=
880 cpu_to_le32(pci_map_single(priv
->pdev
, skb
->data
,
881 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
));
883 rxq
->rx_desc_area
[rx
].pkt_len
= cpu_to_le16(MWL8K_RX_MAXSZ
);
884 rxq
->rx_skb
[rx
] = skb
;
886 rxq
->rx_desc_area
[rx
].rx_ctrl
= 0;
894 /* Must be called only when the card's reception is completely halted */
895 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
897 struct mwl8k_priv
*priv
= hw
->priv
;
898 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
901 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
902 if (rxq
->rx_skb
[i
] != NULL
) {
905 addr
= le32_to_cpu(rxq
->rx_desc_area
[i
].pkt_phys_addr
);
906 pci_unmap_single(priv
->pdev
, addr
, MWL8K_RX_MAXSZ
,
908 kfree_skb(rxq
->rx_skb
[i
]);
909 rxq
->rx_skb
[i
] = NULL
;
916 pci_free_consistent(priv
->pdev
,
917 MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
),
918 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
919 rxq
->rx_desc_area
= NULL
;
924 * Scan a list of BSSIDs to process for finalize join.
925 * Allows for extension to process multiple BSSIDs.
928 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
930 return priv
->capture_beacon
&&
931 ieee80211_is_beacon(wh
->frame_control
) &&
932 !compare_ether_addr(wh
->addr3
, priv
->capture_bssid
);
935 static inline void mwl8k_save_beacon(struct mwl8k_priv
*priv
,
938 priv
->capture_beacon
= false;
939 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
942 * Use GFP_ATOMIC as rxq_process is called from
943 * the primary interrupt handler, memory allocation call
946 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
947 if (priv
->beacon_skb
!= NULL
)
948 queue_work(priv
->config_wq
,
949 &priv
->finalize_join_worker
);
952 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
954 struct mwl8k_priv
*priv
= hw
->priv
;
955 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
959 while (rxq
->rx_desc_count
&& limit
--) {
960 struct mwl8k_rx_desc
*rx_desc
;
962 struct ieee80211_rx_status status
;
964 struct ieee80211_hdr
*wh
;
966 rx_desc
= rxq
->rx_desc_area
+ rxq
->rx_head
;
967 if (!(rx_desc
->rx_ctrl
& MWL8K_RX_CTRL_OWNED_BY_HOST
))
971 skb
= rxq
->rx_skb
[rxq
->rx_head
];
974 rxq
->rx_skb
[rxq
->rx_head
] = NULL
;
976 rxq
->rx_head
= (rxq
->rx_head
+ 1) % MWL8K_RX_DESCS
;
977 rxq
->rx_desc_count
--;
979 addr
= le32_to_cpu(rx_desc
->pkt_phys_addr
);
980 pci_unmap_single(priv
->pdev
, addr
,
981 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
983 skb_put(skb
, le16_to_cpu(rx_desc
->pkt_len
));
984 if (mwl8k_remove_dma_header(skb
)) {
989 wh
= (struct ieee80211_hdr
*)skb
->data
;
992 * Check for pending join operation. save a copy of
993 * the beacon and schedule a tasklet to send finalize
994 * join command to the firmware.
996 if (mwl8k_capture_bssid(priv
, wh
))
997 mwl8k_save_beacon(priv
, skb
);
999 memset(&status
, 0, sizeof(status
));
1001 status
.signal
= -rx_desc
->rssi
;
1002 status
.noise
= -rx_desc
->noise_level
;
1003 status
.qual
= rx_desc
->link_quality
;
1005 status
.rate_idx
= 1;
1007 status
.band
= IEEE80211_BAND_2GHZ
;
1008 status
.freq
= ieee80211_channel_to_frequency(rx_desc
->channel
);
1009 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
1010 ieee80211_rx_irqsafe(hw
, skb
);
1020 * Packet transmission.
1023 /* Transmit queue assignment. */
1025 MWL8K_WME_AC_BK
= 0, /* background access */
1026 MWL8K_WME_AC_BE
= 1, /* best effort access */
1027 MWL8K_WME_AC_VI
= 2, /* video access */
1028 MWL8K_WME_AC_VO
= 3, /* voice access */
1031 /* Transmit packet ACK policy */
1032 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
1033 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1035 #define GET_TXQ(_ac) (\
1036 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
1037 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
1038 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
1041 #define MWL8K_TXD_STATUS_OK 0x00000001
1042 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1043 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1044 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1045 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1047 struct mwl8k_tx_desc
{
1052 __le32 pkt_phys_addr
;
1054 __u8 dest_MAC_addr
[ETH_ALEN
];
1055 __le32 next_tx_desc_phys_addr
;
1060 } __attribute__((packed
));
1062 #define MWL8K_TX_DESCS 128
1064 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1066 struct mwl8k_priv
*priv
= hw
->priv
;
1067 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1071 memset(&txq
->tx_stats
, 0, sizeof(struct ieee80211_tx_queue_stats
));
1072 txq
->tx_stats
.limit
= MWL8K_TX_DESCS
;
1076 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1079 pci_alloc_consistent(priv
->pdev
, size
, &txq
->tx_desc_dma
);
1080 if (txq
->tx_desc_area
== NULL
) {
1081 printk(KERN_ERR
"%s: failed to alloc TX descriptors\n",
1085 memset(txq
->tx_desc_area
, 0, size
);
1087 txq
->tx_skb
= kmalloc(MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
),
1089 if (txq
->tx_skb
== NULL
) {
1090 printk(KERN_ERR
"%s: failed to alloc TX skbuff list\n",
1092 pci_free_consistent(priv
->pdev
, size
,
1093 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1096 memset(txq
->tx_skb
, 0, MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
));
1098 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1099 struct mwl8k_tx_desc
*tx_desc
;
1102 tx_desc
= txq
->tx_desc_area
+ i
;
1103 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1105 tx_desc
->status
= 0;
1106 tx_desc
->next_tx_desc_phys_addr
=
1107 cpu_to_le32(txq
->tx_desc_dma
+
1108 nexti
* sizeof(*tx_desc
));
1114 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1116 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1117 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1118 iowrite32(MWL8K_H2A_INT_DUMMY
,
1119 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1120 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1123 static inline int mwl8k_txq_busy(struct mwl8k_priv
*priv
)
1125 return priv
->pending_tx_pkts
;
1128 struct mwl8k_txq_info
{
1137 static int mwl8k_scan_tx_ring(struct mwl8k_priv
*priv
,
1138 struct mwl8k_txq_info txinfo
[],
1141 int count
, desc
, status
;
1142 struct mwl8k_tx_queue
*txq
;
1143 struct mwl8k_tx_desc
*tx_desc
;
1146 memset(txinfo
, 0, num_queues
* sizeof(struct mwl8k_txq_info
));
1147 spin_lock_bh(&priv
->tx_lock
);
1148 for (count
= 0; count
< num_queues
; count
++) {
1149 txq
= priv
->txq
+ count
;
1150 txinfo
[count
].len
= txq
->tx_stats
.len
;
1151 txinfo
[count
].head
= txq
->tx_head
;
1152 txinfo
[count
].tail
= txq
->tx_tail
;
1153 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1154 tx_desc
= txq
->tx_desc_area
+ desc
;
1155 status
= le32_to_cpu(tx_desc
->status
);
1157 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1158 txinfo
[count
].fw_owned
++;
1160 txinfo
[count
].drv_owned
++;
1162 if (tx_desc
->pkt_len
== 0)
1163 txinfo
[count
].unused
++;
1166 spin_unlock_bh(&priv
->tx_lock
);
1171 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
, u32 delay_ms
)
1173 struct mwl8k_priv
*priv
= hw
->priv
;
1174 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1176 unsigned long timeout
;
1180 if (priv
->tx_wait
!= NULL
)
1181 printk(KERN_ERR
"WARNING Previous TXWaitEmpty instance\n");
1183 spin_lock_bh(&priv
->tx_lock
);
1184 count
= mwl8k_txq_busy(priv
);
1186 priv
->tx_wait
= &cmd_wait
;
1188 mwl8k_tx_start(priv
);
1190 spin_unlock_bh(&priv
->tx_lock
);
1193 struct mwl8k_txq_info txinfo
[4];
1197 timeout
= wait_for_completion_timeout(&cmd_wait
,
1198 msecs_to_jiffies(delay_ms
));
1202 spin_lock_bh(&priv
->tx_lock
);
1203 priv
->tx_wait
= NULL
;
1204 newcount
= mwl8k_txq_busy(priv
);
1205 spin_unlock_bh(&priv
->tx_lock
);
1207 printk(KERN_ERR
"%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
1208 __func__
, __LINE__
, delay_ms
, count
, newcount
);
1210 mwl8k_scan_tx_ring(priv
, txinfo
, 4);
1211 for (index
= 0; index
< 4; index
++)
1213 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
1218 txinfo
[index
].fw_owned
,
1219 txinfo
[index
].drv_owned
,
1220 txinfo
[index
].unused
);
1228 #define MWL8K_TXD_SUCCESS(status) \
1229 ((status) & (MWL8K_TXD_STATUS_OK | \
1230 MWL8K_TXD_STATUS_OK_RETRY | \
1231 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1233 static void mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int force
)
1235 struct mwl8k_priv
*priv
= hw
->priv
;
1236 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1239 while (txq
->tx_stats
.len
> 0) {
1242 struct mwl8k_tx_desc
*tx_desc
;
1245 struct sk_buff
*skb
;
1246 struct ieee80211_tx_info
*info
;
1251 tx_desc
= txq
->tx_desc_area
+ tx
;
1253 status
= le32_to_cpu(tx_desc
->status
);
1255 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1259 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1262 txq
->tx_head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1263 BUG_ON(txq
->tx_stats
.len
== 0);
1264 txq
->tx_stats
.len
--;
1265 priv
->pending_tx_pkts
--;
1267 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1268 size
= le16_to_cpu(tx_desc
->pkt_len
);
1269 skb
= txq
->tx_skb
[tx
].skb
;
1270 txq
->tx_skb
[tx
].skb
= NULL
;
1272 BUG_ON(skb
== NULL
);
1273 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1275 rc
= mwl8k_remove_dma_header(skb
);
1277 /* Mark descriptor as unused */
1278 tx_desc
->pkt_phys_addr
= 0;
1279 tx_desc
->pkt_len
= 0;
1281 if (txq
->tx_skb
[tx
].clone
) {
1282 /* Replace with original skb
1283 * before returning to stack
1284 * as buffer has been cloned
1287 skb
= txq
->tx_skb
[tx
].clone
;
1288 txq
->tx_skb
[tx
].clone
= NULL
;
1292 /* Something has gone wrong here.
1293 * Failed to remove DMA header.
1294 * Print error message and drop packet.
1296 printk(KERN_ERR
"%s: Error removing DMA header from "
1297 "tx skb 0x%p.\n", priv
->name
, skb
);
1303 info
= IEEE80211_SKB_CB(skb
);
1304 ieee80211_tx_info_clear_status(info
);
1305 if (MWL8K_TXD_SUCCESS(status
))
1306 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1308 ieee80211_tx_status_irqsafe(hw
, skb
);
1310 wake
= !priv
->inconfig
&& priv
->radio_on
;
1314 ieee80211_wake_queue(hw
, index
);
1317 /* must be called only when the card's transmit is completely halted */
1318 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1320 struct mwl8k_priv
*priv
= hw
->priv
;
1321 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1323 mwl8k_txq_reclaim(hw
, index
, 1);
1328 pci_free_consistent(priv
->pdev
,
1329 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1330 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1331 txq
->tx_desc_area
= NULL
;
1335 mwl8k_txq_xmit(struct ieee80211_hw
*hw
, int index
, struct sk_buff
*skb
)
1337 struct mwl8k_priv
*priv
= hw
->priv
;
1338 struct ieee80211_tx_info
*tx_info
;
1339 struct ieee80211_hdr
*wh
;
1340 struct mwl8k_tx_queue
*txq
;
1341 struct mwl8k_tx_desc
*tx
;
1342 struct mwl8k_dma_data
*tr
;
1343 struct mwl8k_vif
*mwl8k_vif
;
1344 struct sk_buff
*org_skb
= skb
;
1347 bool qosframe
= false, ampduframe
= false;
1348 bool mcframe
= false, eapolframe
= false;
1349 bool amsduframe
= false;
1352 txq
= priv
->txq
+ index
;
1353 tx
= txq
->tx_desc_area
+ txq
->tx_tail
;
1355 BUG_ON(txq
->tx_skb
[txq
->tx_tail
].skb
!= NULL
);
1358 * Append HW DMA header to start of packet. Drop packet if
1359 * there is not enough space or a failure to unshare/unclone
1362 skb
= mwl8k_add_dma_header(skb
);
1365 printk(KERN_DEBUG
"%s: failed to prepend HW DMA "
1366 "header, dropping TX frame.\n", priv
->name
);
1367 dev_kfree_skb(org_skb
);
1368 return NETDEV_TX_OK
;
1371 tx_info
= IEEE80211_SKB_CB(skb
);
1372 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1373 tr
= (struct mwl8k_dma_data
*)skb
->data
;
1375 fc
= wh
->frame_control
;
1376 qosframe
= ieee80211_is_data_qos(fc
);
1377 mcframe
= is_multicast_ether_addr(wh
->addr1
);
1378 ampduframe
= !!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
);
1380 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1381 u16 seqno
= mwl8k_vif
->seqno
;
1382 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1383 wh
->seq_ctrl
|= cpu_to_le16(seqno
<< 4);
1384 mwl8k_vif
->seqno
= seqno
++ % 4096;
1388 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1390 dma
= pci_map_single(priv
->pdev
, skb
->data
,
1391 skb
->len
, PCI_DMA_TODEVICE
);
1393 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
1394 printk(KERN_DEBUG
"%s: failed to dma map skb, "
1395 "dropping TX frame.\n", priv
->name
);
1397 if (org_skb
!= NULL
)
1398 dev_kfree_skb(org_skb
);
1401 return NETDEV_TX_OK
;
1404 /* Set desc header, cpu bit order. */
1407 tx
->tx_priority
= index
;
1408 tx
->qos_control
= 0;
1410 tx
->peer_id
= mwl8k_vif
->peer_id
;
1412 amsduframe
= !!(qos
& IEEE80211_QOS_CONTROL_A_MSDU_PRESENT
);
1414 /* Setup firmware control bit fields for each frame type. */
1415 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
)) {
1417 qos
= mwl8k_qos_setbit_eosp(qos
);
1418 /* Set Queue size to unspecified */
1419 qos
= mwl8k_qos_setbit_qlen(qos
, 0xff);
1420 } else if (ieee80211_is_data(fc
)) {
1423 tx
->status
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1426 * Tell firmware to not send EAPOL pkts in an
1427 * aggregate. Verify against mac80211 tx path. If
1428 * stack turns off AMPDU for an EAPOL frame this
1429 * check will be removed.
1432 qos
= mwl8k_qos_setbit_ack(qos
,
1433 MWL8K_TXD_ACK_POLICY_NORMAL
);
1435 /* Send pkt in an aggregate if AMPDU frame. */
1437 qos
= mwl8k_qos_setbit_ack(qos
,
1438 MWL8K_TXD_ACK_POLICY_BLOCKACK
);
1440 qos
= mwl8k_qos_setbit_ack(qos
,
1441 MWL8K_TXD_ACK_POLICY_NORMAL
);
1444 qos
= mwl8k_qos_setbit_amsdu(qos
);
1448 /* Convert to little endian */
1449 tx
->qos_control
= cpu_to_le16(qos
);
1450 tx
->status
= cpu_to_le32(tx
->status
);
1451 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
1452 tx
->pkt_len
= cpu_to_le16(skb
->len
);
1454 txq
->tx_skb
[txq
->tx_tail
].skb
= skb
;
1455 txq
->tx_skb
[txq
->tx_tail
].clone
=
1456 skb
== org_skb
? NULL
: org_skb
;
1458 spin_lock_bh(&priv
->tx_lock
);
1460 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_OK
|
1461 MWL8K_TXD_STATUS_FW_OWNED
);
1463 txq
->tx_stats
.len
++;
1464 priv
->pending_tx_pkts
++;
1465 txq
->tx_stats
.count
++;
1468 if (txq
->tx_tail
== MWL8K_TX_DESCS
)
1470 if (txq
->tx_head
== txq
->tx_tail
)
1471 ieee80211_stop_queue(hw
, index
);
1473 if (priv
->inconfig
) {
1475 * Silently queue packet when we are in the middle of
1476 * a config cycle. Notify firmware only if we are
1477 * waiting for TXQs to empty. If a packet is sent
1478 * before .config() is complete, perhaps it is better
1479 * to drop the packet, as the channel is being changed
1480 * and the packet will end up on the wrong channel.
1482 printk(KERN_ERR
"%s(): WARNING TX activity while "
1483 "in config\n", __func__
);
1485 if (priv
->tx_wait
!= NULL
)
1486 mwl8k_tx_start(priv
);
1488 mwl8k_tx_start(priv
);
1490 spin_unlock_bh(&priv
->tx_lock
);
1492 return NETDEV_TX_OK
;
1497 * Command processing.
1500 /* Timeout firmware commands after 2000ms */
1501 #define MWL8K_CMD_TIMEOUT_MS 2000
1503 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
1505 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1506 struct mwl8k_priv
*priv
= hw
->priv
;
1507 void __iomem
*regs
= priv
->regs
;
1508 dma_addr_t dma_addr
;
1509 unsigned int dma_size
;
1511 unsigned long timeout
= 0;
1514 cmd
->result
= 0xFFFF;
1515 dma_size
= le16_to_cpu(cmd
->length
);
1516 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
1517 PCI_DMA_BIDIRECTIONAL
);
1518 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
1521 if (priv
->hostcmd_wait
!= NULL
)
1522 printk(KERN_ERR
"WARNING host command in progress\n");
1524 spin_lock_irq(&priv
->fw_lock
);
1525 priv
->hostcmd_wait
= &cmd_wait
;
1526 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
1527 iowrite32(MWL8K_H2A_INT_DOORBELL
,
1528 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1529 iowrite32(MWL8K_H2A_INT_DUMMY
,
1530 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1531 spin_unlock_irq(&priv
->fw_lock
);
1533 timeout
= wait_for_completion_timeout(&cmd_wait
,
1534 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
1536 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1537 PCI_DMA_BIDIRECTIONAL
);
1540 spin_lock_irq(&priv
->fw_lock
);
1541 priv
->hostcmd_wait
= NULL
;
1542 spin_unlock_irq(&priv
->fw_lock
);
1543 printk(KERN_ERR
"%s: Command %s timeout after %u ms\n",
1545 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1546 MWL8K_CMD_TIMEOUT_MS
);
1549 rc
= cmd
->result
? -EINVAL
: 0;
1551 printk(KERN_ERR
"%s: Command %s error 0x%x\n",
1553 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1563 struct mwl8k_cmd_get_hw_spec
{
1564 struct mwl8k_cmd_pkt header
;
1566 __u8 host_interface
;
1568 __u8 perm_addr
[ETH_ALEN
];
1573 __u8 mcs_bitmap
[16];
1574 __le32 rx_queue_ptr
;
1575 __le32 num_tx_queues
;
1576 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1578 __le32 num_tx_desc_per_queue
;
1579 __le32 total_rx_desc
;
1580 } __attribute__((packed
));
1582 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw
*hw
)
1584 struct mwl8k_priv
*priv
= hw
->priv
;
1585 struct mwl8k_cmd_get_hw_spec
*cmd
;
1589 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1593 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1594 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1596 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1597 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1598 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rx_desc_dma
);
1599 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1600 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1601 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].tx_desc_dma
);
1602 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1603 cmd
->total_rx_desc
= cpu_to_le32(MWL8K_RX_DESCS
);
1605 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1608 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1609 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1610 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1611 priv
->hw_rev
= cmd
->hw_rev
;
1619 * CMD_MAC_MULTICAST_ADR.
1621 struct mwl8k_cmd_mac_multicast_adr
{
1622 struct mwl8k_cmd_pkt header
;
1625 __u8 addr
[0][ETH_ALEN
];
1628 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
1630 static int mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
,
1632 struct dev_addr_list
*mclist
)
1634 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
1637 int size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
1639 cmd
= kzalloc(size
, GFP_KERNEL
);
1643 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
1644 cmd
->header
.length
= cpu_to_le16(size
);
1645 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
1646 cmd
->numaddr
= cpu_to_le16(mc_count
);
1648 while (index
< mc_count
&& mclist
) {
1649 if (mclist
->da_addrlen
!= ETH_ALEN
) {
1651 goto mwl8k_cmd_mac_multicast_adr_exit
;
1653 memcpy(cmd
->addr
[index
++], mclist
->da_addr
, ETH_ALEN
);
1654 mclist
= mclist
->next
;
1657 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1659 mwl8k_cmd_mac_multicast_adr_exit
:
1665 * CMD_802_11_GET_STAT.
1667 struct mwl8k_cmd_802_11_get_stat
{
1668 struct mwl8k_cmd_pkt header
;
1671 } __attribute__((packed
));
1673 #define MWL8K_STAT_ACK_FAILURE 9
1674 #define MWL8K_STAT_RTS_FAILURE 12
1675 #define MWL8K_STAT_FCS_ERROR 24
1676 #define MWL8K_STAT_RTS_SUCCESS 11
1678 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw
*hw
,
1679 struct ieee80211_low_level_stats
*stats
)
1681 struct mwl8k_cmd_802_11_get_stat
*cmd
;
1684 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1688 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
1689 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1690 cmd
->action
= cpu_to_le16(MWL8K_CMD_GET
);
1692 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1694 stats
->dot11ACKFailureCount
=
1695 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
1696 stats
->dot11RTSFailureCount
=
1697 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
1698 stats
->dot11FCSErrorCount
=
1699 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
1700 stats
->dot11RTSSuccessCount
=
1701 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
1709 * CMD_802_11_RADIO_CONTROL.
1711 struct mwl8k_cmd_802_11_radio_control
{
1712 struct mwl8k_cmd_pkt header
;
1716 } __attribute__((packed
));
1719 mwl8k_cmd_802_11_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
1721 struct mwl8k_priv
*priv
= hw
->priv
;
1722 struct mwl8k_cmd_802_11_radio_control
*cmd
;
1725 if (enable
== priv
->radio_on
&& !force
)
1728 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1732 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
1733 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1734 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1735 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
1736 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
1738 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1742 priv
->radio_on
= enable
;
1747 static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw
*hw
)
1749 return mwl8k_cmd_802_11_radio_control(hw
, 0, 0);
1752 static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw
*hw
)
1754 return mwl8k_cmd_802_11_radio_control(hw
, 1, 0);
1758 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
1760 struct mwl8k_priv
*priv
;
1762 if (hw
== NULL
|| hw
->priv
== NULL
)
1766 priv
->radio_short_preamble
= short_preamble
;
1768 return mwl8k_cmd_802_11_radio_control(hw
, 1, 1);
1772 * CMD_802_11_RF_TX_POWER.
1774 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1776 struct mwl8k_cmd_802_11_rf_tx_power
{
1777 struct mwl8k_cmd_pkt header
;
1779 __le16 support_level
;
1780 __le16 current_level
;
1782 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
1783 } __attribute__((packed
));
1785 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
1787 struct mwl8k_cmd_802_11_rf_tx_power
*cmd
;
1790 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1794 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
1795 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1796 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1797 cmd
->support_level
= cpu_to_le16(dBm
);
1799 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1808 struct mwl8k_cmd_set_pre_scan
{
1809 struct mwl8k_cmd_pkt header
;
1810 } __attribute__((packed
));
1812 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
1814 struct mwl8k_cmd_set_pre_scan
*cmd
;
1817 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1821 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
1822 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1824 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1831 * CMD_SET_POST_SCAN.
1833 struct mwl8k_cmd_set_post_scan
{
1834 struct mwl8k_cmd_pkt header
;
1836 __u8 bssid
[ETH_ALEN
];
1837 } __attribute__((packed
));
1840 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, __u8
*mac
)
1842 struct mwl8k_cmd_set_post_scan
*cmd
;
1845 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1849 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
1850 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1852 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
1854 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1861 * CMD_SET_RF_CHANNEL.
1863 struct mwl8k_cmd_set_rf_channel
{
1864 struct mwl8k_cmd_pkt header
;
1866 __u8 current_channel
;
1867 __le32 channel_flags
;
1868 } __attribute__((packed
));
1870 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
1871 struct ieee80211_channel
*channel
)
1873 struct mwl8k_cmd_set_rf_channel
*cmd
;
1876 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1880 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
1881 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1882 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1883 cmd
->current_channel
= channel
->hw_value
;
1884 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1885 cmd
->channel_flags
= cpu_to_le32(0x00000081);
1887 cmd
->channel_flags
= cpu_to_le32(0x00000000);
1889 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1898 struct mwl8k_cmd_set_slot
{
1899 struct mwl8k_cmd_pkt header
;
1902 } __attribute__((packed
));
1904 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, int slot_time
)
1906 struct mwl8k_cmd_set_slot
*cmd
;
1909 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1913 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
1914 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1915 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1916 cmd
->short_slot
= slot_time
== MWL8K_SHORT_SLOTTIME
? 1 : 0;
1918 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1927 struct mwl8k_cmd_mimo_config
{
1928 struct mwl8k_cmd_pkt header
;
1930 __u8 rx_antenna_map
;
1931 __u8 tx_antenna_map
;
1932 } __attribute__((packed
));
1934 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
1936 struct mwl8k_cmd_mimo_config
*cmd
;
1939 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1943 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
1944 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1945 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
1946 cmd
->rx_antenna_map
= rx
;
1947 cmd
->tx_antenna_map
= tx
;
1949 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1956 * CMD_ENABLE_SNIFFER.
1958 struct mwl8k_cmd_enable_sniffer
{
1959 struct mwl8k_cmd_pkt header
;
1961 } __attribute__((packed
));
1963 static int mwl8k_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
1965 struct mwl8k_cmd_enable_sniffer
*cmd
;
1968 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1972 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
1973 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1974 cmd
->action
= cpu_to_le32(!!enable
);
1976 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1983 * CMD_SET_RATEADAPT_MODE.
1985 struct mwl8k_cmd_set_rate_adapt_mode
{
1986 struct mwl8k_cmd_pkt header
;
1989 } __attribute__((packed
));
1991 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw
*hw
, __u16 mode
)
1993 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
1996 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2000 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
2001 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2002 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2003 cmd
->mode
= cpu_to_le16(mode
);
2005 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2014 struct mwl8k_cmd_set_wmm
{
2015 struct mwl8k_cmd_pkt header
;
2017 } __attribute__((packed
));
2019 static int mwl8k_set_wmm(struct ieee80211_hw
*hw
, bool enable
)
2021 struct mwl8k_priv
*priv
= hw
->priv
;
2022 struct mwl8k_cmd_set_wmm
*cmd
;
2025 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2029 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
2030 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2031 cmd
->action
= enable
? cpu_to_le16(MWL8K_CMD_SET
) : 0;
2033 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2037 priv
->wmm_mode
= enable
;
2043 * CMD_SET_RTS_THRESHOLD.
2045 struct mwl8k_cmd_rts_threshold
{
2046 struct mwl8k_cmd_pkt header
;
2049 } __attribute__((packed
));
2051 static int mwl8k_rts_threshold(struct ieee80211_hw
*hw
,
2052 u16 action
, u16
*threshold
)
2054 struct mwl8k_cmd_rts_threshold
*cmd
;
2057 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2061 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
2062 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2063 cmd
->action
= cpu_to_le16(action
);
2064 cmd
->threshold
= cpu_to_le16(*threshold
);
2066 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2073 * CMD_SET_EDCA_PARAMS.
2075 struct mwl8k_cmd_set_edca_params
{
2076 struct mwl8k_cmd_pkt header
;
2078 /* See MWL8K_SET_EDCA_XXX below */
2081 /* TX opportunity in units of 32 us */
2084 /* Log exponent of max contention period: 0...15*/
2087 /* Log exponent of min contention period: 0...15 */
2090 /* Adaptive interframe spacing in units of 32us */
2093 /* TX queue to configure */
2095 } __attribute__((packed
));
2097 #define MWL8K_SET_EDCA_CW 0x01
2098 #define MWL8K_SET_EDCA_TXOP 0x02
2099 #define MWL8K_SET_EDCA_AIFS 0x04
2101 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2102 MWL8K_SET_EDCA_TXOP | \
2103 MWL8K_SET_EDCA_AIFS)
2106 mwl8k_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
2107 __u16 cw_min
, __u16 cw_max
,
2108 __u8 aifs
, __u16 txop
)
2110 struct mwl8k_cmd_set_edca_params
*cmd
;
2113 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2117 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
2118 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2119 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
2120 cmd
->txop
= cpu_to_le16(txop
);
2121 cmd
->log_cw_max
= (u8
)ilog2(cw_max
+ 1);
2122 cmd
->log_cw_min
= (u8
)ilog2(cw_min
+ 1);
2126 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2133 * CMD_FINALIZE_JOIN.
2136 /* FJ beacon buffer size is compiled into the firmware. */
2137 #define MWL8K_FJ_BEACON_MAXLEN 128
2139 struct mwl8k_cmd_finalize_join
{
2140 struct mwl8k_cmd_pkt header
;
2141 __le32 sleep_interval
; /* Number of beacon periods to sleep */
2142 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
2143 } __attribute__((packed
));
2145 static int mwl8k_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
2146 __u16 framelen
, __u16 dtim
)
2148 struct mwl8k_cmd_finalize_join
*cmd
;
2149 struct ieee80211_mgmt
*payload
= frame
;
2157 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2161 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
2162 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2163 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
2165 hdrlen
= ieee80211_hdrlen(payload
->frame_control
);
2167 payload_len
= framelen
> hdrlen
? framelen
- hdrlen
: 0;
2169 /* XXX TBD Might just have to abort and return an error */
2170 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2171 printk(KERN_ERR
"%s(): WARNING: Incomplete beacon "
2172 "sent to firmware. Sz=%u MAX=%u\n", __func__
,
2173 payload_len
, MWL8K_FJ_BEACON_MAXLEN
);
2175 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2176 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
2178 if (payload
&& payload_len
)
2179 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
2181 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2189 struct mwl8k_cmd_update_sta_db
{
2190 struct mwl8k_cmd_pkt header
;
2192 /* See STADB_ACTION_TYPE */
2195 /* Peer MAC address */
2196 __u8 peer_addr
[ETH_ALEN
];
2200 /* Peer info - valid during add/update. */
2201 struct peer_capability_info peer_info
;
2202 } __attribute__((packed
));
2204 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw
*hw
,
2205 struct ieee80211_vif
*vif
, __u32 action
)
2207 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2208 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2209 struct mwl8k_cmd_update_sta_db
*cmd
;
2210 struct peer_capability_info
*peer_info
;
2211 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2215 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2219 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
2220 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2222 cmd
->action
= cpu_to_le32(action
);
2223 peer_info
= &cmd
->peer_info
;
2224 memcpy(cmd
->peer_addr
, mv_vif
->bssid
, ETH_ALEN
);
2227 case MWL8K_STA_DB_ADD_ENTRY
:
2228 case MWL8K_STA_DB_MODIFY_ENTRY
:
2229 /* Build peer_info block */
2230 peer_info
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
2231 peer_info
->basic_caps
= cpu_to_le16(info
->assoc_capability
);
2232 peer_info
->interop
= 1;
2233 peer_info
->amsdu_enabled
= 0;
2235 rates
= peer_info
->legacy_rates
;
2236 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2237 rates
[count
] = bitrates
[count
].hw_value
;
2239 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2241 mv_vif
->peer_id
= peer_info
->station_id
;
2245 case MWL8K_STA_DB_DEL_ENTRY
:
2246 case MWL8K_STA_DB_FLUSH
:
2248 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2250 mv_vif
->peer_id
= 0;
2261 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2263 #define MWL8K_FRAME_PROT_DISABLED 0x00
2264 #define MWL8K_FRAME_PROT_11G 0x07
2265 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2266 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2268 struct mwl8k_cmd_update_set_aid
{
2269 struct mwl8k_cmd_pkt header
;
2272 /* AP's MAC address (BSSID) */
2273 __u8 bssid
[ETH_ALEN
];
2274 __le16 protection_mode
;
2275 __u8 supp_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2276 } __attribute__((packed
));
2278 static int mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
2279 struct ieee80211_vif
*vif
)
2281 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2282 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2283 struct mwl8k_cmd_update_set_aid
*cmd
;
2284 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2289 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2293 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
2294 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2295 cmd
->aid
= cpu_to_le16(info
->aid
);
2297 memcpy(cmd
->bssid
, mv_vif
->bssid
, ETH_ALEN
);
2299 if (info
->use_cts_prot
) {
2300 prot_mode
= MWL8K_FRAME_PROT_11G
;
2302 switch (info
->ht_operation_mode
&
2303 IEEE80211_HT_OP_MODE_PROTECTION
) {
2304 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
2305 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
2307 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
2308 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
2311 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
2315 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
2317 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2318 cmd
->supp_rates
[count
] = bitrates
[count
].hw_value
;
2320 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2329 struct mwl8k_cmd_update_rateset
{
2330 struct mwl8k_cmd_pkt header
;
2331 __u8 legacy_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2333 /* Bitmap for supported MCS codes. */
2334 __u8 mcs_set
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2335 __u8 reserved
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2336 } __attribute__((packed
));
2338 static int mwl8k_update_rateset(struct ieee80211_hw
*hw
,
2339 struct ieee80211_vif
*vif
)
2341 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2342 struct mwl8k_cmd_update_rateset
*cmd
;
2343 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2347 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2351 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
2352 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2354 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2355 cmd
->legacy_rates
[count
] = bitrates
[count
].hw_value
;
2357 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2364 * CMD_USE_FIXED_RATE.
2366 #define MWL8K_RATE_TABLE_SIZE 8
2367 #define MWL8K_UCAST_RATE 0
2368 #define MWL8K_USE_AUTO_RATE 0x0002
2370 struct mwl8k_rate_entry
{
2371 /* Set to 1 if HT rate, 0 if legacy. */
2374 /* Set to 1 to use retry_count field. */
2375 __le32 enable_retry
;
2377 /* Specified legacy rate or MCS. */
2380 /* Number of allowed retries. */
2382 } __attribute__((packed
));
2384 struct mwl8k_rate_table
{
2385 /* 1 to allow specified rate and below */
2386 __le32 allow_rate_drop
;
2388 struct mwl8k_rate_entry rate_entry
[MWL8K_RATE_TABLE_SIZE
];
2389 } __attribute__((packed
));
2391 struct mwl8k_cmd_use_fixed_rate
{
2392 struct mwl8k_cmd_pkt header
;
2394 struct mwl8k_rate_table rate_table
;
2396 /* Unicast, Broadcast or Multicast */
2400 } __attribute__((packed
));
2402 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw
*hw
,
2403 u32 action
, u32 rate_type
, struct mwl8k_rate_table
*rate_table
)
2405 struct mwl8k_cmd_use_fixed_rate
*cmd
;
2409 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2413 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2414 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2416 cmd
->action
= cpu_to_le32(action
);
2417 cmd
->rate_type
= cpu_to_le32(rate_type
);
2419 if (rate_table
!= NULL
) {
2420 /* Copy over each field manually so
2421 * that bitflipping can be done
2423 cmd
->rate_table
.allow_rate_drop
=
2424 cpu_to_le32(rate_table
->allow_rate_drop
);
2425 cmd
->rate_table
.num_rates
=
2426 cpu_to_le32(rate_table
->num_rates
);
2428 for (count
= 0; count
< rate_table
->num_rates
; count
++) {
2429 struct mwl8k_rate_entry
*dst
=
2430 &cmd
->rate_table
.rate_entry
[count
];
2431 struct mwl8k_rate_entry
*src
=
2432 &rate_table
->rate_entry
[count
];
2434 dst
->is_ht_rate
= cpu_to_le32(src
->is_ht_rate
);
2435 dst
->enable_retry
= cpu_to_le32(src
->enable_retry
);
2436 dst
->rate
= cpu_to_le32(src
->rate
);
2437 dst
->retry_count
= cpu_to_le32(src
->retry_count
);
2441 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2449 * Interrupt handling.
2451 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
2453 struct ieee80211_hw
*hw
= dev_id
;
2454 struct mwl8k_priv
*priv
= hw
->priv
;
2457 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2458 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2463 if (status
& MWL8K_A2H_INT_TX_DONE
)
2464 tasklet_schedule(&priv
->tx_reclaim_task
);
2466 if (status
& MWL8K_A2H_INT_RX_READY
) {
2467 while (rxq_process(hw
, 0, 1))
2468 rxq_refill(hw
, 0, 1);
2471 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
2472 if (priv
->hostcmd_wait
!= NULL
) {
2473 complete(priv
->hostcmd_wait
);
2474 priv
->hostcmd_wait
= NULL
;
2478 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
2479 if (!priv
->inconfig
&&
2481 mwl8k_txq_busy(priv
))
2482 mwl8k_tx_start(priv
);
2490 * Core driver operations.
2492 static int mwl8k_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2494 struct mwl8k_priv
*priv
= hw
->priv
;
2495 int index
= skb_get_queue_mapping(skb
);
2498 if (priv
->current_channel
== NULL
) {
2499 printk(KERN_DEBUG
"%s: dropped TX frame since radio "
2500 "disabled\n", priv
->name
);
2502 return NETDEV_TX_OK
;
2505 rc
= mwl8k_txq_xmit(hw
, index
, skb
);
2510 struct mwl8k_work_struct
{
2511 /* Initialized by mwl8k_queue_work(). */
2512 struct work_struct wt
;
2514 /* Required field passed in to mwl8k_queue_work(). */
2515 struct ieee80211_hw
*hw
;
2517 /* Required field passed in to mwl8k_queue_work(). */
2518 int (*wfunc
)(struct work_struct
*w
);
2520 /* Initialized by mwl8k_queue_work(). */
2521 struct completion
*cmd_wait
;
2527 * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
2528 * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
2532 /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
2533 unsigned long timeout_ms
;
2535 /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
2536 u32 txwait_attempts
;
2538 /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
2543 /* Flags controlling behavior of config queue requests */
2545 /* Caller spins while waiting for completion. */
2546 #define MWL8K_WQ_SPIN 0x00000001
2548 /* Wait for TX queues to empty before proceeding with configuration. */
2549 #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
2551 /* Queue request and return immediately. */
2552 #define MWL8K_WQ_POST_REQUEST 0x00000004
2555 * Caller sleeps and waits for task complete notification.
2556 * Do not use in atomic context.
2558 #define MWL8K_WQ_SLEEP 0x00000008
2560 /* Free work struct when task is done. */
2561 #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
2564 * Config request is queued and returns to caller imediately. Use
2565 * this in atomic context. Work struct is freed by mwl8k_queue_work()
2566 * when this flag is set.
2568 #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
2569 MWL8K_WQ_FREE_WORKSTRUCT)
2571 /* Default work queue behavior is to sleep and wait for tx completion. */
2572 #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
2575 * Default config request timeout. Add adjustments to make sure the
2576 * config thread waits long enough for both tx wait and cmd wait before
2580 /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
2581 #define MWL8K_TXWAIT_TIMEOUT_MS 1000
2583 /* Default number of TX wait attempts. */
2584 #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
2586 /* Total time to wait for TXQ to drain. */
2587 #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
2588 MWL8K_WQ_TXWAIT_ATTEMPTS)
2590 /* Scheduling slop. */
2591 #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
2593 #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
2595 MWL8K_OS_SCHEDULE_OVERHEAD_MS)
2597 static void mwl8k_config_thread(struct work_struct
*wt
)
2599 struct mwl8k_work_struct
*worker
= (struct mwl8k_work_struct
*)wt
;
2600 struct ieee80211_hw
*hw
= worker
->hw
;
2601 struct mwl8k_priv
*priv
= hw
->priv
;
2604 spin_lock_irq(&priv
->tx_lock
);
2605 priv
->inconfig
= true;
2606 spin_unlock_irq(&priv
->tx_lock
);
2608 ieee80211_stop_queues(hw
);
2611 * Wait for host queues to drain before doing PHY
2612 * reconfiguration. This avoids interrupting any in-flight
2613 * DMA transfers to the hardware.
2615 if (worker
->options
& MWL8K_WQ_TX_WAIT_EMPTY
) {
2619 u32 tx_wait_attempts
= worker
->txwait_attempts
;
2621 time_remaining
= worker
->tx_timeout_ms
;
2622 if (!tx_wait_attempts
)
2623 tx_wait_attempts
= 1;
2625 timeout
= worker
->tx_timeout_ms
/tx_wait_attempts
;
2629 iter
= tx_wait_attempts
;
2633 if (time_remaining
> timeout
) {
2634 time_remaining
-= timeout
;
2635 wait_time
= timeout
;
2637 wait_time
= time_remaining
;
2642 rc
= mwl8k_tx_wait_empty(hw
, wait_time
);
2644 printk(KERN_ERR
"%s() txwait timeout=%ums "
2645 "Retry:%u/%u\n", __func__
, timeout
,
2646 tx_wait_attempts
- iter
+ 1,
2649 } while (rc
&& --iter
);
2651 rc
= iter
? 0 : -ETIMEDOUT
;
2654 rc
= worker
->wfunc(wt
);
2656 spin_lock_irq(&priv
->tx_lock
);
2657 priv
->inconfig
= false;
2658 if (priv
->pending_tx_pkts
&& priv
->radio_on
)
2659 mwl8k_tx_start(priv
);
2660 spin_unlock_irq(&priv
->tx_lock
);
2661 ieee80211_wake_queues(hw
);
2664 if (worker
->options
& MWL8K_WQ_SLEEP
)
2665 complete(worker
->cmd_wait
);
2667 if (worker
->options
& MWL8K_WQ_FREE_WORKSTRUCT
)
2671 static int mwl8k_queue_work(struct ieee80211_hw
*hw
,
2672 struct mwl8k_work_struct
*worker
,
2673 struct workqueue_struct
*wqueue
,
2674 int (*wfunc
)(struct work_struct
*w
))
2676 unsigned long timeout
= 0;
2679 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
2681 if (!worker
->timeout_ms
)
2682 worker
->timeout_ms
= MWL8K_CONFIG_TIMEOUT_MS
;
2684 if (!worker
->options
)
2685 worker
->options
= MWL8K_WQ_DEFAULT_OPTIONS
;
2687 if (!worker
->txwait_attempts
)
2688 worker
->txwait_attempts
= MWL8K_WQ_TXWAIT_ATTEMPTS
;
2690 if (!worker
->tx_timeout_ms
)
2691 worker
->tx_timeout_ms
= MWL8K_TXWAIT_MS
;
2694 worker
->cmd_wait
= &cmd_wait
;
2696 worker
->wfunc
= wfunc
;
2698 INIT_WORK(&worker
->wt
, mwl8k_config_thread
);
2699 queue_work(wqueue
, &worker
->wt
);
2701 if (worker
->options
& MWL8K_WQ_POST_REQUEST
) {
2704 if (worker
->options
& MWL8K_WQ_SPIN
) {
2705 timeout
= worker
->timeout_ms
;
2706 while (timeout
&& (worker
->rc
> 0)) {
2710 } else if (worker
->options
& MWL8K_WQ_SLEEP
)
2711 timeout
= wait_for_completion_timeout(&cmd_wait
,
2712 msecs_to_jiffies(worker
->timeout_ms
));
2717 cancel_work_sync(&worker
->wt
);
2725 struct mwl8k_start_worker
{
2726 struct mwl8k_work_struct header
;
2729 static int mwl8k_start_wt(struct work_struct
*wt
)
2731 struct mwl8k_start_worker
*worker
= (struct mwl8k_start_worker
*)wt
;
2732 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2733 struct mwl8k_priv
*priv
= hw
->priv
;
2736 if (priv
->vif
!= NULL
) {
2738 goto mwl8k_start_exit
;
2742 if (mwl8k_cmd_802_11_radio_enable(hw
)) {
2744 goto mwl8k_start_exit
;
2747 /* Purge TX/RX HW queues */
2748 if (mwl8k_cmd_set_pre_scan(hw
)) {
2750 goto mwl8k_start_exit
;
2753 if (mwl8k_cmd_set_post_scan(hw
, "\x00\x00\x00\x00\x00\x00")) {
2755 goto mwl8k_start_exit
;
2758 /* Enable firmware rate adaptation */
2759 if (mwl8k_cmd_setrateadaptmode(hw
, 0)) {
2761 goto mwl8k_start_exit
;
2764 /* Disable WMM. WMM gets enabled when stack sends WMM parms */
2765 if (mwl8k_set_wmm(hw
, MWL8K_WMM_DISABLE
)) {
2767 goto mwl8k_start_exit
;
2770 /* Disable sniffer mode */
2771 if (mwl8k_enable_sniffer(hw
, 0))
2778 static int mwl8k_start(struct ieee80211_hw
*hw
)
2780 struct mwl8k_start_worker
*worker
;
2781 struct mwl8k_priv
*priv
= hw
->priv
;
2784 /* Enable tx reclaim tasklet */
2785 tasklet_enable(&priv
->tx_reclaim_task
);
2787 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
2788 IRQF_SHARED
, MWL8K_NAME
, hw
);
2790 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
2793 goto mwl8k_start_disable_tasklet
;
2796 /* Enable interrupts */
2797 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2799 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2800 if (worker
== NULL
) {
2802 goto mwl8k_start_disable_irq
;
2805 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2806 priv
->config_wq
, mwl8k_start_wt
);
2811 if (rc
== -ETIMEDOUT
)
2812 printk(KERN_ERR
"%s() timed out\n", __func__
);
2816 mwl8k_start_disable_irq
:
2817 spin_lock_irq(&priv
->tx_lock
);
2818 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2819 spin_unlock_irq(&priv
->tx_lock
);
2820 free_irq(priv
->pdev
->irq
, hw
);
2822 mwl8k_start_disable_tasklet
:
2823 tasklet_disable(&priv
->tx_reclaim_task
);
2828 struct mwl8k_stop_worker
{
2829 struct mwl8k_work_struct header
;
2832 static int mwl8k_stop_wt(struct work_struct
*wt
)
2834 struct mwl8k_stop_worker
*worker
= (struct mwl8k_stop_worker
*)wt
;
2835 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2837 return mwl8k_cmd_802_11_radio_disable(hw
);
2840 static void mwl8k_stop(struct ieee80211_hw
*hw
)
2843 struct mwl8k_stop_worker
*worker
;
2844 struct mwl8k_priv
*priv
= hw
->priv
;
2847 if (priv
->vif
!= NULL
)
2850 ieee80211_stop_queues(hw
);
2852 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2856 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2857 priv
->config_wq
, mwl8k_stop_wt
);
2859 if (rc
== -ETIMEDOUT
)
2860 printk(KERN_ERR
"%s() timed out\n", __func__
);
2862 /* Disable interrupts */
2863 spin_lock_irq(&priv
->tx_lock
);
2864 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2865 spin_unlock_irq(&priv
->tx_lock
);
2866 free_irq(priv
->pdev
->irq
, hw
);
2868 /* Stop finalize join worker */
2869 cancel_work_sync(&priv
->finalize_join_worker
);
2870 if (priv
->beacon_skb
!= NULL
)
2871 dev_kfree_skb(priv
->beacon_skb
);
2873 /* Stop tx reclaim tasklet */
2874 tasklet_disable(&priv
->tx_reclaim_task
);
2876 /* Stop config thread */
2877 flush_workqueue(priv
->config_wq
);
2879 /* Return all skbs to mac80211 */
2880 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2881 mwl8k_txq_reclaim(hw
, i
, 1);
2884 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
2885 struct ieee80211_if_init_conf
*conf
)
2887 struct mwl8k_priv
*priv
= hw
->priv
;
2888 struct mwl8k_vif
*mwl8k_vif
;
2891 * We only support one active interface at a time.
2893 if (priv
->vif
!= NULL
)
2897 * We only support managed interfaces for now.
2899 if (conf
->type
!= NL80211_IFTYPE_STATION
&&
2900 conf
->type
!= NL80211_IFTYPE_MONITOR
)
2903 /* Clean out driver private area */
2904 mwl8k_vif
= MWL8K_VIF(conf
->vif
);
2905 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
2907 /* Save the mac address */
2908 memcpy(mwl8k_vif
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
2910 /* Back pointer to parent config block */
2911 mwl8k_vif
->priv
= priv
;
2913 /* Setup initial PHY parameters */
2914 memcpy(mwl8k_vif
->legacy_rates
,
2915 priv
->rates
, sizeof(mwl8k_vif
->legacy_rates
));
2916 mwl8k_vif
->legacy_nrates
= ARRAY_SIZE(priv
->rates
);
2918 /* Set Initial sequence number to zero */
2919 mwl8k_vif
->seqno
= 0;
2921 priv
->vif
= conf
->vif
;
2922 priv
->current_channel
= NULL
;
2927 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
2928 struct ieee80211_if_init_conf
*conf
)
2930 struct mwl8k_priv
*priv
= hw
->priv
;
2932 if (priv
->vif
== NULL
)
2938 struct mwl8k_config_worker
{
2939 struct mwl8k_work_struct header
;
2943 static int mwl8k_config_wt(struct work_struct
*wt
)
2945 struct mwl8k_config_worker
*worker
=
2946 (struct mwl8k_config_worker
*)wt
;
2947 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2948 struct ieee80211_conf
*conf
= &hw
->conf
;
2949 struct mwl8k_priv
*priv
= hw
->priv
;
2952 if (mwl8k_cmd_802_11_radio_enable(hw
)) {
2954 goto mwl8k_config_exit
;
2957 priv
->current_channel
= conf
->channel
;
2959 if (mwl8k_cmd_set_rf_channel(hw
, conf
->channel
)) {
2961 goto mwl8k_config_exit
;
2964 if (conf
->power_level
> 18)
2965 conf
->power_level
= 18;
2966 if (mwl8k_cmd_802_11_rf_tx_power(hw
, conf
->power_level
)) {
2968 goto mwl8k_config_exit
;
2971 if (mwl8k_cmd_mimo_config(hw
, 0x7, 0x7))
2978 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
2981 struct mwl8k_config_worker
*worker
;
2982 struct mwl8k_priv
*priv
= hw
->priv
;
2984 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2988 worker
->changed
= changed
;
2989 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2990 priv
->config_wq
, mwl8k_config_wt
);
2991 if (rc
== -ETIMEDOUT
) {
2992 printk(KERN_ERR
"%s() timed out.\n", __func__
);
2999 * mac80211 will crash on anything other than -EINVAL on
3000 * error. Looks like wireless extensions which calls mac80211
3001 * may be the actual culprit...
3003 return rc
? -EINVAL
: 0;
3006 struct mwl8k_bss_info_changed_worker
{
3007 struct mwl8k_work_struct header
;
3008 struct ieee80211_vif
*vif
;
3009 struct ieee80211_bss_conf
*info
;
3013 static int mwl8k_bss_info_changed_wt(struct work_struct
*wt
)
3015 struct mwl8k_bss_info_changed_worker
*worker
=
3016 (struct mwl8k_bss_info_changed_worker
*)wt
;
3017 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3018 struct ieee80211_vif
*vif
= worker
->vif
;
3019 struct ieee80211_bss_conf
*info
= worker
->info
;
3023 struct mwl8k_priv
*priv
= hw
->priv
;
3024 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3026 changed
= worker
->changed
;
3027 priv
->capture_beacon
= false;
3030 memcpy(&mwl8k_vif
->bss_info
, info
,
3031 sizeof(struct ieee80211_bss_conf
));
3034 if (mwl8k_update_rateset(hw
, vif
))
3035 goto mwl8k_bss_info_changed_exit
;
3037 /* Turn on rate adaptation */
3038 if (mwl8k_cmd_use_fixed_rate(hw
, MWL8K_USE_AUTO_RATE
,
3039 MWL8K_UCAST_RATE
, NULL
))
3040 goto mwl8k_bss_info_changed_exit
;
3042 /* Set radio preamble */
3043 if (mwl8k_set_radio_preamble(hw
, info
->use_short_preamble
))
3044 goto mwl8k_bss_info_changed_exit
;
3047 if (mwl8k_cmd_set_slot(hw
, info
->use_short_slot
?
3048 MWL8K_SHORT_SLOTTIME
: MWL8K_LONG_SLOTTIME
))
3049 goto mwl8k_bss_info_changed_exit
;
3051 /* Update peer rate info */
3052 if (mwl8k_cmd_update_sta_db(hw
, vif
,
3053 MWL8K_STA_DB_MODIFY_ENTRY
))
3054 goto mwl8k_bss_info_changed_exit
;
3057 if (mwl8k_cmd_set_aid(hw
, vif
))
3058 goto mwl8k_bss_info_changed_exit
;
3061 * Finalize the join. Tell rx handler to process
3062 * next beacon from our BSSID.
3064 memcpy(priv
->capture_bssid
, mwl8k_vif
->bssid
, ETH_ALEN
);
3065 priv
->capture_beacon
= true;
3067 mwl8k_cmd_update_sta_db(hw
, vif
, MWL8K_STA_DB_DEL_ENTRY
);
3068 memset(&mwl8k_vif
->bss_info
, 0,
3069 sizeof(struct ieee80211_bss_conf
));
3070 memset(mwl8k_vif
->bssid
, 0, ETH_ALEN
);
3073 mwl8k_bss_info_changed_exit
:
3078 static void mwl8k_bss_info_changed(struct ieee80211_hw
*hw
,
3079 struct ieee80211_vif
*vif
,
3080 struct ieee80211_bss_conf
*info
,
3083 struct mwl8k_bss_info_changed_worker
*worker
;
3084 struct mwl8k_priv
*priv
= hw
->priv
;
3085 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
3088 if (changed
& BSS_CHANGED_BSSID
)
3089 memcpy(mv_vif
->bssid
, info
->bssid
, ETH_ALEN
);
3091 if ((changed
& BSS_CHANGED_ASSOC
) == 0)
3094 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3099 worker
->info
= info
;
3100 worker
->changed
= changed
;
3101 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3103 mwl8k_bss_info_changed_wt
);
3105 if (rc
== -ETIMEDOUT
)
3106 printk(KERN_ERR
"%s() timed out\n", __func__
);
3109 struct mwl8k_configure_filter_worker
{
3110 struct mwl8k_work_struct header
;
3111 unsigned int changed_flags
;
3112 unsigned int *total_flags
;
3114 struct dev_addr_list
*mclist
;
3117 #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
3119 static int mwl8k_configure_filter_wt(struct work_struct
*wt
)
3121 struct mwl8k_configure_filter_worker
*worker
=
3122 (struct mwl8k_configure_filter_worker
*)wt
;
3124 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3125 unsigned int changed_flags
= worker
->changed_flags
;
3126 unsigned int *total_flags
= worker
->total_flags
;
3127 int mc_count
= worker
->mc_count
;
3128 struct dev_addr_list
*mclist
= worker
->mclist
;
3130 struct mwl8k_priv
*priv
= hw
->priv
;
3133 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
3134 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
3135 rc
= mwl8k_cmd_set_pre_scan(hw
);
3139 bssid
= "\x00\x00\x00\x00\x00\x00";
3140 if (priv
->vif
!= NULL
)
3141 bssid
= MWL8K_VIF(priv
->vif
)->bssid
;
3143 rc
= mwl8k_cmd_set_post_scan(hw
, bssid
);
3148 goto mwl8k_configure_filter_exit
;
3150 if (mc_count
> priv
->num_mcaddrs
)
3151 mc_count
= priv
->num_mcaddrs
;
3153 rc
= mwl8k_cmd_mac_multicast_adr(hw
, mc_count
, mclist
);
3156 "%s()Error setting multicast addresses\n",
3160 mwl8k_configure_filter_exit
:
3164 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
3165 int mc_count
, struct dev_addr_list
*mclist
)
3167 struct mwl8k_configure_filter_worker
*worker
;
3169 worker
= kzalloc(sizeof(*worker
), GFP_ATOMIC
);
3175 * XXX: This is _HORRIBLY_ broken!!
3177 * No locking, the mclist pointer might be invalid as soon as this
3178 * function returns, something in the list might be invalidated
3179 * once we get to the worker, etc...
3181 worker
->mc_count
= mc_count
;
3182 worker
->mclist
= mclist
;
3187 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
3188 unsigned int changed_flags
,
3189 unsigned int *total_flags
,
3193 struct mwl8k_configure_filter_worker
*worker
= (void *)multicast
;
3194 struct mwl8k_priv
*priv
= hw
->priv
;
3196 /* Clear unsupported feature flags */
3197 *total_flags
&= MWL8K_SUPPORTED_IF_FLAGS
;
3199 if (!(changed_flags
& MWL8K_SUPPORTED_IF_FLAGS
))
3205 worker
->header
.options
= MWL8K_WQ_QUEUE_ONLY
| MWL8K_WQ_TX_WAIT_EMPTY
;
3206 worker
->changed_flags
= changed_flags
;
3207 worker
->total_flags
= total_flags
;
3209 mwl8k_queue_work(hw
, &worker
->header
, priv
->config_wq
,
3210 mwl8k_configure_filter_wt
);
3213 struct mwl8k_set_rts_threshold_worker
{
3214 struct mwl8k_work_struct header
;
3218 static int mwl8k_set_rts_threshold_wt(struct work_struct
*wt
)
3220 struct mwl8k_set_rts_threshold_worker
*worker
=
3221 (struct mwl8k_set_rts_threshold_worker
*)wt
;
3223 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3224 u16 threshold
= (u16
)(worker
->value
);
3227 rc
= mwl8k_rts_threshold(hw
, MWL8K_CMD_SET
, &threshold
);
3232 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3235 struct mwl8k_set_rts_threshold_worker
*worker
;
3236 struct mwl8k_priv
*priv
= hw
->priv
;
3238 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3242 worker
->value
= value
;
3244 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3246 mwl8k_set_rts_threshold_wt
);
3249 if (rc
== -ETIMEDOUT
) {
3250 printk(KERN_ERR
"%s() timed out\n", __func__
);
3257 struct mwl8k_conf_tx_worker
{
3258 struct mwl8k_work_struct header
;
3260 const struct ieee80211_tx_queue_params
*params
;
3263 static int mwl8k_conf_tx_wt(struct work_struct
*wt
)
3265 struct mwl8k_conf_tx_worker
*worker
=
3266 (struct mwl8k_conf_tx_worker
*)wt
;
3268 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3269 u16 queue
= worker
->queue
;
3270 const struct ieee80211_tx_queue_params
*params
= worker
->params
;
3272 struct mwl8k_priv
*priv
= hw
->priv
;
3275 if (priv
->wmm_mode
== MWL8K_WMM_DISABLE
)
3276 if (mwl8k_set_wmm(hw
, MWL8K_WMM_ENABLE
)) {
3278 goto mwl8k_conf_tx_exit
;
3281 if (mwl8k_set_edca_params(hw
, GET_TXQ(queue
), params
->cw_min
,
3282 params
->cw_max
, params
->aifs
, params
->txop
))
3288 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
3289 const struct ieee80211_tx_queue_params
*params
)
3292 struct mwl8k_conf_tx_worker
*worker
;
3293 struct mwl8k_priv
*priv
= hw
->priv
;
3295 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3299 worker
->queue
= queue
;
3300 worker
->params
= params
;
3301 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3302 priv
->config_wq
, mwl8k_conf_tx_wt
);
3304 if (rc
== -ETIMEDOUT
) {
3305 printk(KERN_ERR
"%s() timed out\n", __func__
);
3311 static int mwl8k_get_tx_stats(struct ieee80211_hw
*hw
,
3312 struct ieee80211_tx_queue_stats
*stats
)
3314 struct mwl8k_priv
*priv
= hw
->priv
;
3315 struct mwl8k_tx_queue
*txq
;
3318 spin_lock_bh(&priv
->tx_lock
);
3319 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++) {
3320 txq
= priv
->txq
+ index
;
3321 memcpy(&stats
[index
], &txq
->tx_stats
,
3322 sizeof(struct ieee80211_tx_queue_stats
));
3324 spin_unlock_bh(&priv
->tx_lock
);
3328 struct mwl8k_get_stats_worker
{
3329 struct mwl8k_work_struct header
;
3330 struct ieee80211_low_level_stats
*stats
;
3333 static int mwl8k_get_stats_wt(struct work_struct
*wt
)
3335 struct mwl8k_get_stats_worker
*worker
=
3336 (struct mwl8k_get_stats_worker
*)wt
;
3338 return mwl8k_cmd_802_11_get_stat(worker
->header
.hw
, worker
->stats
);
3341 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
3342 struct ieee80211_low_level_stats
*stats
)
3345 struct mwl8k_get_stats_worker
*worker
;
3346 struct mwl8k_priv
*priv
= hw
->priv
;
3348 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3352 worker
->stats
= stats
;
3353 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3354 priv
->config_wq
, mwl8k_get_stats_wt
);
3357 if (rc
== -ETIMEDOUT
) {
3358 printk(KERN_ERR
"%s() timed out\n", __func__
);
3365 static const struct ieee80211_ops mwl8k_ops
= {
3367 .start
= mwl8k_start
,
3369 .add_interface
= mwl8k_add_interface
,
3370 .remove_interface
= mwl8k_remove_interface
,
3371 .config
= mwl8k_config
,
3372 .bss_info_changed
= mwl8k_bss_info_changed
,
3373 .prepare_multicast
= mwl8k_prepare_multicast
,
3374 .configure_filter
= mwl8k_configure_filter
,
3375 .set_rts_threshold
= mwl8k_set_rts_threshold
,
3376 .conf_tx
= mwl8k_conf_tx
,
3377 .get_tx_stats
= mwl8k_get_tx_stats
,
3378 .get_stats
= mwl8k_get_stats
,
3381 static void mwl8k_tx_reclaim_handler(unsigned long data
)
3384 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*) data
;
3385 struct mwl8k_priv
*priv
= hw
->priv
;
3387 spin_lock_bh(&priv
->tx_lock
);
3388 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3389 mwl8k_txq_reclaim(hw
, i
, 0);
3391 if (priv
->tx_wait
!= NULL
&& mwl8k_txq_busy(priv
) == 0) {
3392 complete(priv
->tx_wait
);
3393 priv
->tx_wait
= NULL
;
3395 spin_unlock_bh(&priv
->tx_lock
);
3398 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
3400 struct mwl8k_priv
*priv
=
3401 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
3402 struct sk_buff
*skb
= priv
->beacon_skb
;
3403 u8 dtim
= MWL8K_VIF(priv
->vif
)->bss_info
.dtim_period
;
3405 mwl8k_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim
);
3408 priv
->beacon_skb
= NULL
;
3411 static int __devinit
mwl8k_probe(struct pci_dev
*pdev
,
3412 const struct pci_device_id
*id
)
3414 struct ieee80211_hw
*hw
;
3415 struct mwl8k_priv
*priv
;
3420 rc
= pci_enable_device(pdev
);
3422 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
3427 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
3429 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
3434 pci_set_master(pdev
);
3436 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
3438 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
3446 priv
->hostcmd_wait
= NULL
;
3447 priv
->tx_wait
= NULL
;
3448 priv
->inconfig
= false;
3449 priv
->wmm_mode
= false;
3450 priv
->pending_tx_pkts
= 0;
3451 strncpy(priv
->name
, MWL8K_NAME
, sizeof(priv
->name
));
3453 spin_lock_init(&priv
->fw_lock
);
3455 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
3456 pci_set_drvdata(pdev
, hw
);
3458 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
3459 if (priv
->regs
== NULL
) {
3460 printk(KERN_ERR
"%s: Cannot map device memory\n", priv
->name
);
3464 memcpy(priv
->channels
, mwl8k_channels
, sizeof(mwl8k_channels
));
3465 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
3466 priv
->band
.channels
= priv
->channels
;
3467 priv
->band
.n_channels
= ARRAY_SIZE(mwl8k_channels
);
3468 priv
->band
.bitrates
= priv
->rates
;
3469 priv
->band
.n_bitrates
= ARRAY_SIZE(mwl8k_rates
);
3470 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
3472 BUILD_BUG_ON(sizeof(priv
->rates
) != sizeof(mwl8k_rates
));
3473 memcpy(priv
->rates
, mwl8k_rates
, sizeof(mwl8k_rates
));
3476 * Extra headroom is the size of the required DMA header
3477 * minus the size of the smallest 802.11 frame (CTS frame).
3479 hw
->extra_tx_headroom
=
3480 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
3482 hw
->channel_change_time
= 10;
3484 hw
->queues
= MWL8K_TX_QUEUES
;
3486 hw
->wiphy
->interface_modes
=
3487 BIT(NL80211_IFTYPE_STATION
) | BIT(NL80211_IFTYPE_MONITOR
);
3489 /* Set rssi and noise values to dBm */
3490 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
| IEEE80211_HW_NOISE_DBM
;
3491 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
3494 /* Set default radio state and preamble */
3496 priv
->radio_short_preamble
= 0;
3498 /* Finalize join worker */
3499 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
3501 /* TX reclaim tasklet */
3502 tasklet_init(&priv
->tx_reclaim_task
,
3503 mwl8k_tx_reclaim_handler
, (unsigned long)hw
);
3504 tasklet_disable(&priv
->tx_reclaim_task
);
3506 /* Config workthread */
3507 priv
->config_wq
= create_singlethread_workqueue("mwl8k_config");
3508 if (priv
->config_wq
== NULL
)
3511 /* Power management cookie */
3512 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
3513 if (priv
->cookie
== NULL
)
3516 rc
= mwl8k_rxq_init(hw
, 0);
3519 rxq_refill(hw
, 0, INT_MAX
);
3521 spin_lock_init(&priv
->tx_lock
);
3523 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
3524 rc
= mwl8k_txq_init(hw
, i
);
3526 goto err_free_queues
;
3529 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3530 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3531 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
3532 iowrite32(0xffffffff, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3534 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
3535 IRQF_SHARED
, MWL8K_NAME
, hw
);
3537 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
3539 goto err_free_queues
;
3542 /* Reset firmware and hardware */
3543 mwl8k_hw_reset(priv
);
3545 /* Ask userland hotplug daemon for the device firmware */
3546 rc
= mwl8k_request_firmware(priv
, (u32
)id
->driver_data
);
3548 printk(KERN_ERR
"%s: Firmware files not found\n", priv
->name
);
3552 /* Load firmware into hardware */
3553 rc
= mwl8k_load_firmware(priv
);
3555 printk(KERN_ERR
"%s: Cannot start firmware\n", priv
->name
);
3556 goto err_stop_firmware
;
3559 /* Reclaim memory once firmware is successfully loaded */
3560 mwl8k_release_firmware(priv
);
3563 * Temporarily enable interrupts. Initial firmware host
3564 * commands use interrupts and avoids polling. Disable
3565 * interrupts when done.
3567 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3569 /* Get config data, mac addrs etc */
3570 rc
= mwl8k_cmd_get_hw_spec(hw
);
3572 printk(KERN_ERR
"%s: Cannot initialise firmware\n", priv
->name
);
3573 goto err_stop_firmware
;
3576 /* Turn radio off */
3577 rc
= mwl8k_cmd_802_11_radio_disable(hw
);
3579 printk(KERN_ERR
"%s: Cannot disable\n", priv
->name
);
3580 goto err_stop_firmware
;
3583 /* Disable interrupts */
3584 spin_lock_irq(&priv
->tx_lock
);
3585 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3586 spin_unlock_irq(&priv
->tx_lock
);
3587 free_irq(priv
->pdev
->irq
, hw
);
3589 rc
= ieee80211_register_hw(hw
);
3591 printk(KERN_ERR
"%s: Cannot register device\n", priv
->name
);
3592 goto err_stop_firmware
;
3595 fw
= (u8
*)&priv
->fw_rev
;
3596 printk(KERN_INFO
"%s: 88W%u %s\n", priv
->name
, priv
->part_num
,
3598 printk(KERN_INFO
"%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
3599 priv
->name
, MWL8K_VERSION
, fw
[3], fw
[2], fw
[1], fw
[0]);
3600 printk(KERN_INFO
"%s: MAC Address: %pM\n", priv
->name
,
3601 hw
->wiphy
->perm_addr
);
3606 mwl8k_hw_reset(priv
);
3607 mwl8k_release_firmware(priv
);
3610 spin_lock_irq(&priv
->tx_lock
);
3611 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3612 spin_unlock_irq(&priv
->tx_lock
);
3613 free_irq(priv
->pdev
->irq
, hw
);
3616 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3617 mwl8k_txq_deinit(hw
, i
);
3618 mwl8k_rxq_deinit(hw
, 0);
3621 if (priv
->cookie
!= NULL
)
3622 pci_free_consistent(priv
->pdev
, 4,
3623 priv
->cookie
, priv
->cookie_dma
);
3625 if (priv
->regs
!= NULL
)
3626 pci_iounmap(pdev
, priv
->regs
);
3628 if (priv
->config_wq
!= NULL
)
3629 destroy_workqueue(priv
->config_wq
);
3631 pci_set_drvdata(pdev
, NULL
);
3632 ieee80211_free_hw(hw
);
3635 pci_release_regions(pdev
);
3636 pci_disable_device(pdev
);
3641 static void __devexit
mwl8k_shutdown(struct pci_dev
*pdev
)
3643 printk(KERN_ERR
"===>%s(%u)\n", __func__
, __LINE__
);
3646 static void __devexit
mwl8k_remove(struct pci_dev
*pdev
)
3648 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
3649 struct mwl8k_priv
*priv
;
3656 ieee80211_stop_queues(hw
);
3658 ieee80211_unregister_hw(hw
);
3660 /* Remove tx reclaim tasklet */
3661 tasklet_kill(&priv
->tx_reclaim_task
);
3663 /* Stop config thread */
3664 destroy_workqueue(priv
->config_wq
);
3667 mwl8k_hw_reset(priv
);
3669 /* Return all skbs to mac80211 */
3670 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3671 mwl8k_txq_reclaim(hw
, i
, 1);
3673 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3674 mwl8k_txq_deinit(hw
, i
);
3676 mwl8k_rxq_deinit(hw
, 0);
3678 pci_free_consistent(priv
->pdev
, 4,
3679 priv
->cookie
, priv
->cookie_dma
);
3681 pci_iounmap(pdev
, priv
->regs
);
3682 pci_set_drvdata(pdev
, NULL
);
3683 ieee80211_free_hw(hw
);
3684 pci_release_regions(pdev
);
3685 pci_disable_device(pdev
);
3688 static struct pci_driver mwl8k_driver
= {
3690 .id_table
= mwl8k_table
,
3691 .probe
= mwl8k_probe
,
3692 .remove
= __devexit_p(mwl8k_remove
),
3693 .shutdown
= __devexit_p(mwl8k_shutdown
),
3696 static int __init
mwl8k_init(void)
3698 return pci_register_driver(&mwl8k_driver
);
3701 static void __exit
mwl8k_exit(void)
3703 pci_unregister_driver(&mwl8k_driver
);
3706 module_init(mwl8k_init
);
3707 module_exit(mwl8k_exit
);