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];
189 /* RF preamble: Short, Long or Auto */
193 /* WMM MODE 1 for enabled; 0 for disabled */
196 /* Set if PHY config is in progress */
199 /* XXX need to convert this to handle multiple interfaces */
201 u8 capture_bssid
[ETH_ALEN
];
202 struct sk_buff
*beacon_skb
;
205 * This FJ worker has to be global as it is scheduled from the
206 * RX handler. At this point we don't know which interface it
207 * belongs to until the list of bssids waiting to complete join
210 struct work_struct finalize_join_worker
;
212 /* Tasklet to reclaim TX descriptors and buffers after tx */
213 struct tasklet_struct tx_reclaim_task
;
215 /* Work thread to serialize configuration requests */
216 struct workqueue_struct
*config_wq
;
217 struct completion
*hostcmd_wait
;
218 struct completion
*tx_wait
;
221 /* Per interface specific private data */
223 /* backpointer to parent config block */
224 struct mwl8k_priv
*priv
;
226 /* BSS config of AP or IBSS from mac80211*/
227 struct ieee80211_bss_conf bss_info
;
229 /* BSSID of AP or IBSS */
231 u8 mac_addr
[ETH_ALEN
];
234 * Subset of supported legacy rates.
235 * Intersection of AP and STA supported rates.
237 struct ieee80211_rate legacy_rates
[12];
239 /* number of supported legacy rates */
242 /* Index into station database.Returned by update_sta_db call */
245 /* Non AMPDU sequence number assigned by driver */
249 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
251 static const struct ieee80211_channel mwl8k_channels
[] = {
252 { .center_freq
= 2412, .hw_value
= 1, },
253 { .center_freq
= 2417, .hw_value
= 2, },
254 { .center_freq
= 2422, .hw_value
= 3, },
255 { .center_freq
= 2427, .hw_value
= 4, },
256 { .center_freq
= 2432, .hw_value
= 5, },
257 { .center_freq
= 2437, .hw_value
= 6, },
258 { .center_freq
= 2442, .hw_value
= 7, },
259 { .center_freq
= 2447, .hw_value
= 8, },
260 { .center_freq
= 2452, .hw_value
= 9, },
261 { .center_freq
= 2457, .hw_value
= 10, },
262 { .center_freq
= 2462, .hw_value
= 11, },
265 static const struct ieee80211_rate mwl8k_rates
[] = {
266 { .bitrate
= 10, .hw_value
= 2, },
267 { .bitrate
= 20, .hw_value
= 4, },
268 { .bitrate
= 55, .hw_value
= 11, },
269 { .bitrate
= 60, .hw_value
= 12, },
270 { .bitrate
= 90, .hw_value
= 18, },
271 { .bitrate
= 110, .hw_value
= 22, },
272 { .bitrate
= 120, .hw_value
= 24, },
273 { .bitrate
= 180, .hw_value
= 36, },
274 { .bitrate
= 240, .hw_value
= 48, },
275 { .bitrate
= 360, .hw_value
= 72, },
276 { .bitrate
= 480, .hw_value
= 96, },
277 { .bitrate
= 540, .hw_value
= 108, },
281 #define MWL8K_RADIO_FORCE 0x2
282 #define MWL8K_RADIO_ENABLE 0x1
283 #define MWL8K_RADIO_DISABLE 0x0
284 #define MWL8K_RADIO_AUTO_PREAMBLE 0x0005
285 #define MWL8K_RADIO_SHORT_PREAMBLE 0x0003
286 #define MWL8K_RADIO_LONG_PREAMBLE 0x0001
289 #define MWL8K_WMM_ENABLE 1
290 #define MWL8K_WMM_DISABLE 0
292 #define MWL8K_RADIO_DEFAULT_PREAMBLE MWL8K_RADIO_LONG_PREAMBLE
296 /* Short Slot: 9us slot time */
297 #define MWL8K_SHORT_SLOTTIME 1
299 /* Long slot: 20us slot time */
300 #define MWL8K_LONG_SLOTTIME 0
302 /* Set or get info from Firmware */
303 #define MWL8K_CMD_SET 0x0001
304 #define MWL8K_CMD_GET 0x0000
306 /* Firmware command codes */
307 #define MWL8K_CMD_CODE_DNLD 0x0001
308 #define MWL8K_CMD_GET_HW_SPEC 0x0003
309 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
310 #define MWL8K_CMD_GET_STAT 0x0014
311 #define MWL8K_CMD_RADIO_CONTROL 0x001c
312 #define MWL8K_CMD_RF_TX_POWER 0x001e
313 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
314 #define MWL8K_CMD_SET_POST_SCAN 0x0108
315 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
316 #define MWL8K_CMD_SET_AID 0x010d
317 #define MWL8K_CMD_SET_RATE 0x0110
318 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
319 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
320 #define MWL8K_CMD_SET_SLOT 0x0114
321 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
322 #define MWL8K_CMD_SET_WMM_MODE 0x0123
323 #define MWL8K_CMD_MIMO_CONFIG 0x0125
324 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
325 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
326 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
327 #define MWL8K_CMD_UPDATE_STADB 0x1123
329 static const char *mwl8k_cmd_name(u16 cmd
, char *buf
, int bufsize
)
331 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
332 snprintf(buf, bufsize, "%s", #x);\
335 switch (cmd
& ~0x8000) {
336 MWL8K_CMDNAME(CODE_DNLD
);
337 MWL8K_CMDNAME(GET_HW_SPEC
);
338 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
339 MWL8K_CMDNAME(GET_STAT
);
340 MWL8K_CMDNAME(RADIO_CONTROL
);
341 MWL8K_CMDNAME(RF_TX_POWER
);
342 MWL8K_CMDNAME(SET_PRE_SCAN
);
343 MWL8K_CMDNAME(SET_POST_SCAN
);
344 MWL8K_CMDNAME(SET_RF_CHANNEL
);
345 MWL8K_CMDNAME(SET_AID
);
346 MWL8K_CMDNAME(SET_RATE
);
347 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
348 MWL8K_CMDNAME(RTS_THRESHOLD
);
349 MWL8K_CMDNAME(SET_SLOT
);
350 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
351 MWL8K_CMDNAME(SET_WMM_MODE
);
352 MWL8K_CMDNAME(MIMO_CONFIG
);
353 MWL8K_CMDNAME(USE_FIXED_RATE
);
354 MWL8K_CMDNAME(ENABLE_SNIFFER
);
355 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
356 MWL8K_CMDNAME(UPDATE_STADB
);
358 snprintf(buf
, bufsize
, "0x%x", cmd
);
365 /* Hardware and firmware reset */
366 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
368 iowrite32(MWL8K_H2A_INT_RESET
,
369 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
370 iowrite32(MWL8K_H2A_INT_RESET
,
371 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
375 /* Release fw image */
376 static void mwl8k_release_fw(struct firmware
**fw
)
380 release_firmware(*fw
);
384 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
386 mwl8k_release_fw(&priv
->fw
.ucode
);
387 mwl8k_release_fw(&priv
->fw
.helper
);
390 /* Request fw image */
391 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
392 const char *fname
, struct firmware
**fw
)
394 /* release current image */
396 mwl8k_release_fw(fw
);
398 return request_firmware((const struct firmware
**)fw
,
399 fname
, &priv
->pdev
->dev
);
402 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, u32 part_num
)
407 priv
->part_num
= part_num
;
409 snprintf(filename
, sizeof(filename
),
410 "mwl8k/helper_%u.fw", priv
->part_num
);
412 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.helper
);
415 "%s Error requesting helper firmware file %s\n",
416 pci_name(priv
->pdev
), filename
);
420 snprintf(filename
, sizeof(filename
),
421 "mwl8k/fmimage_%u.fw", priv
->part_num
);
423 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.ucode
);
425 printk(KERN_ERR
"%s Error requesting firmware file %s\n",
426 pci_name(priv
->pdev
), filename
);
427 mwl8k_release_fw(&priv
->fw
.helper
);
434 struct mwl8k_cmd_pkt
{
440 } __attribute__((packed
));
446 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
448 void __iomem
*regs
= priv
->regs
;
453 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
454 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
457 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
458 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
459 iowrite32(MWL8K_H2A_INT_DOORBELL
,
460 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
461 iowrite32(MWL8K_H2A_INT_DUMMY
,
462 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
469 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
470 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
471 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
479 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
482 * Clear 'command done' interrupt bit.
488 status
= ioread32(priv
->regs
+
489 MWL8K_HIU_A2H_INTERRUPT_STATUS
);
490 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
491 iowrite32(~MWL8K_A2H_INT_OPC_DONE
,
492 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
493 ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
503 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
504 const u8
*data
, size_t length
)
506 struct mwl8k_cmd_pkt
*cmd
;
510 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
514 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
520 int block_size
= length
> 256 ? 256 : length
;
522 memcpy(cmd
->payload
, data
+ done
, block_size
);
523 cmd
->length
= cpu_to_le16(block_size
);
525 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
526 sizeof(*cmd
) + block_size
);
531 length
-= block_size
;
536 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
544 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
545 const u8
*data
, size_t length
)
547 unsigned char *buffer
;
548 int may_continue
, rc
= 0;
549 u32 done
, prev_block_size
;
551 buffer
= kmalloc(1024, GFP_KERNEL
);
558 while (may_continue
> 0) {
561 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
562 if (block_size
& 1) {
566 done
+= prev_block_size
;
567 length
-= prev_block_size
;
570 if (block_size
> 1024 || block_size
> length
) {
580 if (block_size
== 0) {
587 prev_block_size
= block_size
;
588 memcpy(buffer
, data
+ done
, block_size
);
590 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
595 if (!rc
&& length
!= 0)
603 static int mwl8k_load_firmware(struct mwl8k_priv
*priv
)
607 const u8
*ucode
= priv
->fw
.ucode
->data
;
608 size_t ucode_len
= priv
->fw
.ucode
->size
;
609 const u8
*helper
= priv
->fw
.helper
->data
;
610 size_t helper_len
= priv
->fw
.helper
->size
;
612 if (!memcmp(ucode
, "\x01\x00\x00\x00", 4)) {
613 rc
= mwl8k_load_fw_image(priv
, helper
, helper_len
);
615 printk(KERN_ERR
"%s: unable to load firmware "
616 "helper image\n", pci_name(priv
->pdev
));
621 rc
= mwl8k_feed_fw_image(priv
, ucode
, ucode_len
);
623 rc
= mwl8k_load_fw_image(priv
, ucode
, ucode_len
);
627 printk(KERN_ERR
"%s: unable to load firmware data\n",
628 pci_name(priv
->pdev
));
632 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
637 if (ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
)
638 == MWL8K_FWSTA_READY
)
643 return loops
? 0 : -ETIMEDOUT
;
648 * Defines shared between transmission and reception.
650 /* HT control fields for firmware */
655 } __attribute__((packed
));
657 /* Firmware Station database operations */
658 #define MWL8K_STA_DB_ADD_ENTRY 0
659 #define MWL8K_STA_DB_MODIFY_ENTRY 1
660 #define MWL8K_STA_DB_DEL_ENTRY 2
661 #define MWL8K_STA_DB_FLUSH 3
663 /* Peer Entry flags - used to define the type of the peer node */
664 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
666 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
667 #define MWL8K_MCS_BITMAP_SIZE 16
669 struct peer_capability_info
{
670 /* Peer type - AP vs. STA. */
673 /* Basic 802.11 capabilities from assoc resp. */
676 /* Set if peer supports 802.11n high throughput (HT). */
679 /* Valid if HT is supported. */
681 __u8 extended_ht_caps
;
682 struct ewc_ht_info ewc_info
;
684 /* Legacy rate table. Intersection of our rates and peer rates. */
685 __u8 legacy_rates
[MWL8K_IEEE_LEGACY_DATA_RATES
];
687 /* HT rate table. Intersection of our rates and peer rates. */
688 __u8 ht_rates
[MWL8K_MCS_BITMAP_SIZE
];
691 /* If set, interoperability mode, no proprietary extensions. */
695 __le16 amsdu_enabled
;
696 } __attribute__((packed
));
698 /* Inline functions to manipulate QoS field in data descriptor. */
699 static inline u16
mwl8k_qos_setbit_eosp(u16 qos
)
701 u16 val_mask
= 1 << 4;
703 /* End of Service Period Bit 4 */
704 return qos
| val_mask
;
707 static inline u16
mwl8k_qos_setbit_ack(u16 qos
, u8 ack_policy
)
711 u16 qos_mask
= ~(val_mask
<< shift
);
713 /* Ack Policy Bit 5-6 */
714 return (qos
& qos_mask
) | ((ack_policy
& val_mask
) << shift
);
717 static inline u16
mwl8k_qos_setbit_amsdu(u16 qos
)
719 u16 val_mask
= 1 << 7;
721 /* AMSDU present Bit 7 */
722 return qos
| val_mask
;
725 static inline u16
mwl8k_qos_setbit_qlen(u16 qos
, u8 len
)
729 u16 qos_mask
= ~(val_mask
<< shift
);
731 /* Queue Length Bits 8-15 */
732 return (qos
& qos_mask
) | ((len
& val_mask
) << shift
);
735 /* DMA header used by firmware and hardware. */
736 struct mwl8k_dma_data
{
738 struct ieee80211_hdr wh
;
739 } __attribute__((packed
));
741 /* Routines to add/remove DMA header from skb. */
742 static inline int mwl8k_remove_dma_header(struct sk_buff
*skb
)
744 struct mwl8k_dma_data
*tr
= (struct mwl8k_dma_data
*)(skb
->data
);
745 void *dst
, *src
= &tr
->wh
;
746 __le16 fc
= tr
->wh
.frame_control
;
747 int hdrlen
= ieee80211_hdrlen(fc
);
748 u16 space
= sizeof(struct mwl8k_dma_data
) - hdrlen
;
750 dst
= (void *)tr
+ space
;
752 memmove(dst
, src
, hdrlen
);
753 skb_pull(skb
, space
);
759 static inline struct sk_buff
*mwl8k_add_dma_header(struct sk_buff
*skb
)
761 struct ieee80211_hdr
*wh
;
763 struct mwl8k_dma_data
*tr
;
765 wh
= (struct ieee80211_hdr
*)skb
->data
;
766 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
770 * Copy up/down the 802.11 header; the firmware requires
771 * we present a 2-byte payload length followed by a
772 * 4-address header (w/o QoS), followed (optionally) by
773 * any WEP/ExtIV header (but only filled in for CCMP).
775 if (hdrlen
!= sizeof(struct mwl8k_dma_data
))
776 skb_push(skb
, sizeof(struct mwl8k_dma_data
) - hdrlen
);
778 tr
= (struct mwl8k_dma_data
*)skb
->data
;
780 memmove(&tr
->wh
, wh
, hdrlen
);
783 memset(tr
->wh
.addr4
, 0, ETH_ALEN
);
786 * Firmware length is the length of the fully formed "802.11
787 * payload". That is, everything except for the 802.11 header.
788 * This includes all crypto material including the MIC.
790 tr
->fwlen
= cpu_to_le16(pktlen
- hdrlen
);
799 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
801 struct mwl8k_rx_desc
{
805 __le32 pkt_phys_addr
;
806 __le32 next_rx_desc_phys_addr
;
816 } __attribute__((packed
));
818 #define MWL8K_RX_DESCS 256
819 #define MWL8K_RX_MAXSZ 3800
821 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
823 struct mwl8k_priv
*priv
= hw
->priv
;
824 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
828 rxq
->rx_desc_count
= 0;
832 size
= MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
);
835 pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rx_desc_dma
);
836 if (rxq
->rx_desc_area
== NULL
) {
837 printk(KERN_ERR
"%s: failed to alloc RX descriptors\n",
841 memset(rxq
->rx_desc_area
, 0, size
);
843 rxq
->rx_skb
= kmalloc(MWL8K_RX_DESCS
*
844 sizeof(*rxq
->rx_skb
), GFP_KERNEL
);
845 if (rxq
->rx_skb
== NULL
) {
846 printk(KERN_ERR
"%s: failed to alloc RX skbuff list\n",
848 pci_free_consistent(priv
->pdev
, size
,
849 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
852 memset(rxq
->rx_skb
, 0, MWL8K_RX_DESCS
* sizeof(*rxq
->rx_skb
));
854 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
855 struct mwl8k_rx_desc
*rx_desc
;
858 rx_desc
= rxq
->rx_desc_area
+ i
;
859 nexti
= (i
+ 1) % MWL8K_RX_DESCS
;
861 rx_desc
->next_rx_desc_phys_addr
=
862 cpu_to_le32(rxq
->rx_desc_dma
863 + nexti
* sizeof(*rx_desc
));
864 rx_desc
->rx_ctrl
= MWL8K_RX_CTRL_OWNED_BY_HOST
;
870 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
872 struct mwl8k_priv
*priv
= hw
->priv
;
873 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
877 while (rxq
->rx_desc_count
< MWL8K_RX_DESCS
&& limit
--) {
881 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
885 rxq
->rx_desc_count
++;
888 rxq
->rx_tail
= (rx
+ 1) % MWL8K_RX_DESCS
;
890 rxq
->rx_desc_area
[rx
].pkt_phys_addr
=
891 cpu_to_le32(pci_map_single(priv
->pdev
, skb
->data
,
892 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
));
894 rxq
->rx_desc_area
[rx
].pkt_len
= cpu_to_le16(MWL8K_RX_MAXSZ
);
895 rxq
->rx_skb
[rx
] = skb
;
897 rxq
->rx_desc_area
[rx
].rx_ctrl
= 0;
905 /* Must be called only when the card's reception is completely halted */
906 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
908 struct mwl8k_priv
*priv
= hw
->priv
;
909 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
912 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
913 if (rxq
->rx_skb
[i
] != NULL
) {
916 addr
= le32_to_cpu(rxq
->rx_desc_area
[i
].pkt_phys_addr
);
917 pci_unmap_single(priv
->pdev
, addr
, MWL8K_RX_MAXSZ
,
919 kfree_skb(rxq
->rx_skb
[i
]);
920 rxq
->rx_skb
[i
] = NULL
;
927 pci_free_consistent(priv
->pdev
,
928 MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
),
929 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
930 rxq
->rx_desc_area
= NULL
;
935 * Scan a list of BSSIDs to process for finalize join.
936 * Allows for extension to process multiple BSSIDs.
939 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
941 return priv
->capture_beacon
&&
942 ieee80211_is_beacon(wh
->frame_control
) &&
943 !compare_ether_addr(wh
->addr3
, priv
->capture_bssid
);
946 static inline void mwl8k_save_beacon(struct mwl8k_priv
*priv
,
949 priv
->capture_beacon
= false;
950 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
953 * Use GFP_ATOMIC as rxq_process is called from
954 * the primary interrupt handler, memory allocation call
957 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
958 if (priv
->beacon_skb
!= NULL
)
959 queue_work(priv
->config_wq
,
960 &priv
->finalize_join_worker
);
963 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
965 struct mwl8k_priv
*priv
= hw
->priv
;
966 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
970 while (rxq
->rx_desc_count
&& limit
--) {
971 struct mwl8k_rx_desc
*rx_desc
;
973 struct ieee80211_rx_status status
;
975 struct ieee80211_hdr
*wh
;
977 rx_desc
= rxq
->rx_desc_area
+ rxq
->rx_head
;
978 if (!(rx_desc
->rx_ctrl
& MWL8K_RX_CTRL_OWNED_BY_HOST
))
982 skb
= rxq
->rx_skb
[rxq
->rx_head
];
985 rxq
->rx_skb
[rxq
->rx_head
] = NULL
;
987 rxq
->rx_head
= (rxq
->rx_head
+ 1) % MWL8K_RX_DESCS
;
988 rxq
->rx_desc_count
--;
990 addr
= le32_to_cpu(rx_desc
->pkt_phys_addr
);
991 pci_unmap_single(priv
->pdev
, addr
,
992 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
994 skb_put(skb
, le16_to_cpu(rx_desc
->pkt_len
));
995 if (mwl8k_remove_dma_header(skb
)) {
1000 wh
= (struct ieee80211_hdr
*)skb
->data
;
1003 * Check for pending join operation. save a copy of
1004 * the beacon and schedule a tasklet to send finalize
1005 * join command to the firmware.
1007 if (mwl8k_capture_bssid(priv
, wh
))
1008 mwl8k_save_beacon(priv
, skb
);
1010 memset(&status
, 0, sizeof(status
));
1012 status
.signal
= -rx_desc
->rssi
;
1013 status
.noise
= -rx_desc
->noise_level
;
1014 status
.qual
= rx_desc
->link_quality
;
1016 status
.rate_idx
= 1;
1018 status
.band
= IEEE80211_BAND_2GHZ
;
1019 status
.freq
= ieee80211_channel_to_frequency(rx_desc
->channel
);
1020 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
1021 ieee80211_rx_irqsafe(hw
, skb
);
1031 * Packet transmission.
1034 /* Transmit queue assignment. */
1036 MWL8K_WME_AC_BK
= 0, /* background access */
1037 MWL8K_WME_AC_BE
= 1, /* best effort access */
1038 MWL8K_WME_AC_VI
= 2, /* video access */
1039 MWL8K_WME_AC_VO
= 3, /* voice access */
1042 /* Transmit packet ACK policy */
1043 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
1044 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1046 #define GET_TXQ(_ac) (\
1047 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
1048 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
1049 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
1052 #define MWL8K_TXD_STATUS_OK 0x00000001
1053 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1054 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1055 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1056 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1058 struct mwl8k_tx_desc
{
1063 __le32 pkt_phys_addr
;
1065 __u8 dest_MAC_addr
[ETH_ALEN
];
1066 __le32 next_tx_desc_phys_addr
;
1071 } __attribute__((packed
));
1073 #define MWL8K_TX_DESCS 128
1075 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1077 struct mwl8k_priv
*priv
= hw
->priv
;
1078 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1082 memset(&txq
->tx_stats
, 0, sizeof(struct ieee80211_tx_queue_stats
));
1083 txq
->tx_stats
.limit
= MWL8K_TX_DESCS
;
1087 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1090 pci_alloc_consistent(priv
->pdev
, size
, &txq
->tx_desc_dma
);
1091 if (txq
->tx_desc_area
== NULL
) {
1092 printk(KERN_ERR
"%s: failed to alloc TX descriptors\n",
1096 memset(txq
->tx_desc_area
, 0, size
);
1098 txq
->tx_skb
= kmalloc(MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
),
1100 if (txq
->tx_skb
== NULL
) {
1101 printk(KERN_ERR
"%s: failed to alloc TX skbuff list\n",
1103 pci_free_consistent(priv
->pdev
, size
,
1104 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1107 memset(txq
->tx_skb
, 0, MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
));
1109 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1110 struct mwl8k_tx_desc
*tx_desc
;
1113 tx_desc
= txq
->tx_desc_area
+ i
;
1114 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1116 tx_desc
->status
= 0;
1117 tx_desc
->next_tx_desc_phys_addr
=
1118 cpu_to_le32(txq
->tx_desc_dma
+
1119 nexti
* sizeof(*tx_desc
));
1125 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1127 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1128 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1129 iowrite32(MWL8K_H2A_INT_DUMMY
,
1130 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1131 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1134 static inline int mwl8k_txq_busy(struct mwl8k_priv
*priv
)
1136 return priv
->pending_tx_pkts
;
1139 struct mwl8k_txq_info
{
1148 static int mwl8k_scan_tx_ring(struct mwl8k_priv
*priv
,
1149 struct mwl8k_txq_info txinfo
[],
1152 int count
, desc
, status
;
1153 struct mwl8k_tx_queue
*txq
;
1154 struct mwl8k_tx_desc
*tx_desc
;
1157 memset(txinfo
, 0, num_queues
* sizeof(struct mwl8k_txq_info
));
1158 spin_lock_bh(&priv
->tx_lock
);
1159 for (count
= 0; count
< num_queues
; count
++) {
1160 txq
= priv
->txq
+ count
;
1161 txinfo
[count
].len
= txq
->tx_stats
.len
;
1162 txinfo
[count
].head
= txq
->tx_head
;
1163 txinfo
[count
].tail
= txq
->tx_tail
;
1164 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1165 tx_desc
= txq
->tx_desc_area
+ desc
;
1166 status
= le32_to_cpu(tx_desc
->status
);
1168 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1169 txinfo
[count
].fw_owned
++;
1171 txinfo
[count
].drv_owned
++;
1173 if (tx_desc
->pkt_len
== 0)
1174 txinfo
[count
].unused
++;
1177 spin_unlock_bh(&priv
->tx_lock
);
1182 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
, u32 delay_ms
)
1184 struct mwl8k_priv
*priv
= hw
->priv
;
1185 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1187 unsigned long timeout
;
1191 if (priv
->tx_wait
!= NULL
)
1192 printk(KERN_ERR
"WARNING Previous TXWaitEmpty instance\n");
1194 spin_lock_bh(&priv
->tx_lock
);
1195 count
= mwl8k_txq_busy(priv
);
1197 priv
->tx_wait
= &cmd_wait
;
1198 if (priv
->radio_state
)
1199 mwl8k_tx_start(priv
);
1201 spin_unlock_bh(&priv
->tx_lock
);
1204 struct mwl8k_txq_info txinfo
[4];
1208 timeout
= wait_for_completion_timeout(&cmd_wait
,
1209 msecs_to_jiffies(delay_ms
));
1213 spin_lock_bh(&priv
->tx_lock
);
1214 priv
->tx_wait
= NULL
;
1215 newcount
= mwl8k_txq_busy(priv
);
1216 spin_unlock_bh(&priv
->tx_lock
);
1218 printk(KERN_ERR
"%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
1219 __func__
, __LINE__
, delay_ms
, count
, newcount
);
1221 mwl8k_scan_tx_ring(priv
, txinfo
, 4);
1222 for (index
= 0; index
< 4; index
++)
1224 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
1229 txinfo
[index
].fw_owned
,
1230 txinfo
[index
].drv_owned
,
1231 txinfo
[index
].unused
);
1239 #define MWL8K_TXD_SUCCESS(status) \
1240 ((status) & (MWL8K_TXD_STATUS_OK | \
1241 MWL8K_TXD_STATUS_OK_RETRY | \
1242 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1244 static void mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int force
)
1246 struct mwl8k_priv
*priv
= hw
->priv
;
1247 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1250 while (txq
->tx_stats
.len
> 0) {
1253 struct mwl8k_tx_desc
*tx_desc
;
1256 struct sk_buff
*skb
;
1257 struct ieee80211_tx_info
*info
;
1262 tx_desc
= txq
->tx_desc_area
+ tx
;
1264 status
= le32_to_cpu(tx_desc
->status
);
1266 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1270 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1273 txq
->tx_head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1274 BUG_ON(txq
->tx_stats
.len
== 0);
1275 txq
->tx_stats
.len
--;
1276 priv
->pending_tx_pkts
--;
1278 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1279 size
= le16_to_cpu(tx_desc
->pkt_len
);
1280 skb
= txq
->tx_skb
[tx
].skb
;
1281 txq
->tx_skb
[tx
].skb
= NULL
;
1283 BUG_ON(skb
== NULL
);
1284 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1286 rc
= mwl8k_remove_dma_header(skb
);
1288 /* Mark descriptor as unused */
1289 tx_desc
->pkt_phys_addr
= 0;
1290 tx_desc
->pkt_len
= 0;
1292 if (txq
->tx_skb
[tx
].clone
) {
1293 /* Replace with original skb
1294 * before returning to stack
1295 * as buffer has been cloned
1298 skb
= txq
->tx_skb
[tx
].clone
;
1299 txq
->tx_skb
[tx
].clone
= NULL
;
1303 /* Something has gone wrong here.
1304 * Failed to remove DMA header.
1305 * Print error message and drop packet.
1307 printk(KERN_ERR
"%s: Error removing DMA header from "
1308 "tx skb 0x%p.\n", priv
->name
, skb
);
1314 info
= IEEE80211_SKB_CB(skb
);
1315 ieee80211_tx_info_clear_status(info
);
1316 if (MWL8K_TXD_SUCCESS(status
))
1317 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1319 ieee80211_tx_status_irqsafe(hw
, skb
);
1321 wake
= !priv
->inconfig
&& priv
->radio_state
;
1325 ieee80211_wake_queue(hw
, index
);
1328 /* must be called only when the card's transmit is completely halted */
1329 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1331 struct mwl8k_priv
*priv
= hw
->priv
;
1332 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1334 mwl8k_txq_reclaim(hw
, index
, 1);
1339 pci_free_consistent(priv
->pdev
,
1340 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1341 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1342 txq
->tx_desc_area
= NULL
;
1346 mwl8k_txq_xmit(struct ieee80211_hw
*hw
, int index
, struct sk_buff
*skb
)
1348 struct mwl8k_priv
*priv
= hw
->priv
;
1349 struct ieee80211_tx_info
*tx_info
;
1350 struct ieee80211_hdr
*wh
;
1351 struct mwl8k_tx_queue
*txq
;
1352 struct mwl8k_tx_desc
*tx
;
1353 struct mwl8k_dma_data
*tr
;
1354 struct mwl8k_vif
*mwl8k_vif
;
1355 struct sk_buff
*org_skb
= skb
;
1358 bool qosframe
= false, ampduframe
= false;
1359 bool mcframe
= false, eapolframe
= false;
1360 bool amsduframe
= false;
1363 txq
= priv
->txq
+ index
;
1364 tx
= txq
->tx_desc_area
+ txq
->tx_tail
;
1366 BUG_ON(txq
->tx_skb
[txq
->tx_tail
].skb
!= NULL
);
1369 * Append HW DMA header to start of packet. Drop packet if
1370 * there is not enough space or a failure to unshare/unclone
1373 skb
= mwl8k_add_dma_header(skb
);
1376 printk(KERN_DEBUG
"%s: failed to prepend HW DMA "
1377 "header, dropping TX frame.\n", priv
->name
);
1378 dev_kfree_skb(org_skb
);
1379 return NETDEV_TX_OK
;
1382 tx_info
= IEEE80211_SKB_CB(skb
);
1383 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1384 tr
= (struct mwl8k_dma_data
*)skb
->data
;
1386 fc
= wh
->frame_control
;
1387 qosframe
= ieee80211_is_data_qos(fc
);
1388 mcframe
= is_multicast_ether_addr(wh
->addr1
);
1389 ampduframe
= !!(tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
);
1391 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1392 u16 seqno
= mwl8k_vif
->seqno
;
1393 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1394 wh
->seq_ctrl
|= cpu_to_le16(seqno
<< 4);
1395 mwl8k_vif
->seqno
= seqno
++ % 4096;
1399 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1401 dma
= pci_map_single(priv
->pdev
, skb
->data
,
1402 skb
->len
, PCI_DMA_TODEVICE
);
1404 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
1405 printk(KERN_DEBUG
"%s: failed to dma map skb, "
1406 "dropping TX frame.\n", priv
->name
);
1408 if (org_skb
!= NULL
)
1409 dev_kfree_skb(org_skb
);
1412 return NETDEV_TX_OK
;
1415 /* Set desc header, cpu bit order. */
1418 tx
->tx_priority
= index
;
1419 tx
->qos_control
= 0;
1421 tx
->peer_id
= mwl8k_vif
->peer_id
;
1423 amsduframe
= !!(qos
& IEEE80211_QOS_CONTROL_A_MSDU_PRESENT
);
1425 /* Setup firmware control bit fields for each frame type. */
1426 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
)) {
1428 qos
= mwl8k_qos_setbit_eosp(qos
);
1429 /* Set Queue size to unspecified */
1430 qos
= mwl8k_qos_setbit_qlen(qos
, 0xff);
1431 } else if (ieee80211_is_data(fc
)) {
1434 tx
->status
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1437 * Tell firmware to not send EAPOL pkts in an
1438 * aggregate. Verify against mac80211 tx path. If
1439 * stack turns off AMPDU for an EAPOL frame this
1440 * check will be removed.
1443 qos
= mwl8k_qos_setbit_ack(qos
,
1444 MWL8K_TXD_ACK_POLICY_NORMAL
);
1446 /* Send pkt in an aggregate if AMPDU frame. */
1448 qos
= mwl8k_qos_setbit_ack(qos
,
1449 MWL8K_TXD_ACK_POLICY_BLOCKACK
);
1451 qos
= mwl8k_qos_setbit_ack(qos
,
1452 MWL8K_TXD_ACK_POLICY_NORMAL
);
1455 qos
= mwl8k_qos_setbit_amsdu(qos
);
1459 /* Convert to little endian */
1460 tx
->qos_control
= cpu_to_le16(qos
);
1461 tx
->status
= cpu_to_le32(tx
->status
);
1462 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
1463 tx
->pkt_len
= cpu_to_le16(skb
->len
);
1465 txq
->tx_skb
[txq
->tx_tail
].skb
= skb
;
1466 txq
->tx_skb
[txq
->tx_tail
].clone
=
1467 skb
== org_skb
? NULL
: org_skb
;
1469 spin_lock_bh(&priv
->tx_lock
);
1471 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_OK
|
1472 MWL8K_TXD_STATUS_FW_OWNED
);
1474 txq
->tx_stats
.len
++;
1475 priv
->pending_tx_pkts
++;
1476 txq
->tx_stats
.count
++;
1479 if (txq
->tx_tail
== MWL8K_TX_DESCS
)
1481 if (txq
->tx_head
== txq
->tx_tail
)
1482 ieee80211_stop_queue(hw
, index
);
1484 if (priv
->inconfig
) {
1486 * Silently queue packet when we are in the middle of
1487 * a config cycle. Notify firmware only if we are
1488 * waiting for TXQs to empty. If a packet is sent
1489 * before .config() is complete, perhaps it is better
1490 * to drop the packet, as the channel is being changed
1491 * and the packet will end up on the wrong channel.
1493 printk(KERN_ERR
"%s(): WARNING TX activity while "
1494 "in config\n", __func__
);
1496 if (priv
->tx_wait
!= NULL
)
1497 mwl8k_tx_start(priv
);
1499 mwl8k_tx_start(priv
);
1501 spin_unlock_bh(&priv
->tx_lock
);
1503 return NETDEV_TX_OK
;
1508 * Command processing.
1511 /* Timeout firmware commands after 2000ms */
1512 #define MWL8K_CMD_TIMEOUT_MS 2000
1514 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
1516 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1517 struct mwl8k_priv
*priv
= hw
->priv
;
1518 void __iomem
*regs
= priv
->regs
;
1519 dma_addr_t dma_addr
;
1520 unsigned int dma_size
;
1522 unsigned long timeout
= 0;
1525 cmd
->result
= 0xFFFF;
1526 dma_size
= le16_to_cpu(cmd
->length
);
1527 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
1528 PCI_DMA_BIDIRECTIONAL
);
1529 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
1532 if (priv
->hostcmd_wait
!= NULL
)
1533 printk(KERN_ERR
"WARNING host command in progress\n");
1535 spin_lock_irq(&priv
->fw_lock
);
1536 priv
->hostcmd_wait
= &cmd_wait
;
1537 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
1538 iowrite32(MWL8K_H2A_INT_DOORBELL
,
1539 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1540 iowrite32(MWL8K_H2A_INT_DUMMY
,
1541 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1542 spin_unlock_irq(&priv
->fw_lock
);
1544 timeout
= wait_for_completion_timeout(&cmd_wait
,
1545 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
1547 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1548 PCI_DMA_BIDIRECTIONAL
);
1551 spin_lock_irq(&priv
->fw_lock
);
1552 priv
->hostcmd_wait
= NULL
;
1553 spin_unlock_irq(&priv
->fw_lock
);
1554 printk(KERN_ERR
"%s: Command %s timeout after %u ms\n",
1556 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1557 MWL8K_CMD_TIMEOUT_MS
);
1560 rc
= cmd
->result
? -EINVAL
: 0;
1562 printk(KERN_ERR
"%s: Command %s error 0x%x\n",
1564 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1574 struct mwl8k_cmd_get_hw_spec
{
1575 struct mwl8k_cmd_pkt header
;
1577 __u8 host_interface
;
1579 __u8 perm_addr
[ETH_ALEN
];
1584 __u8 mcs_bitmap
[16];
1585 __le32 rx_queue_ptr
;
1586 __le32 num_tx_queues
;
1587 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1589 __le32 num_tx_desc_per_queue
;
1590 __le32 total_rx_desc
;
1591 } __attribute__((packed
));
1593 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw
*hw
)
1595 struct mwl8k_priv
*priv
= hw
->priv
;
1596 struct mwl8k_cmd_get_hw_spec
*cmd
;
1600 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1604 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1605 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1607 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1608 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1609 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rx_desc_dma
);
1610 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1611 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1612 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].tx_desc_dma
);
1613 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1614 cmd
->total_rx_desc
= cpu_to_le32(MWL8K_RX_DESCS
);
1616 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1619 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1620 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1621 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1622 priv
->hw_rev
= cmd
->hw_rev
;
1630 * CMD_MAC_MULTICAST_ADR.
1632 struct mwl8k_cmd_mac_multicast_adr
{
1633 struct mwl8k_cmd_pkt header
;
1636 __u8 addr
[0][ETH_ALEN
];
1639 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
1641 static int mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
,
1643 struct dev_addr_list
*mclist
)
1645 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
1648 int size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
1650 cmd
= kzalloc(size
, GFP_KERNEL
);
1654 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
1655 cmd
->header
.length
= cpu_to_le16(size
);
1656 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
1657 cmd
->numaddr
= cpu_to_le16(mc_count
);
1659 while (index
< mc_count
&& mclist
) {
1660 if (mclist
->da_addrlen
!= ETH_ALEN
) {
1662 goto mwl8k_cmd_mac_multicast_adr_exit
;
1664 memcpy(cmd
->addr
[index
++], mclist
->da_addr
, ETH_ALEN
);
1665 mclist
= mclist
->next
;
1668 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1670 mwl8k_cmd_mac_multicast_adr_exit
:
1676 * CMD_802_11_GET_STAT.
1678 struct mwl8k_cmd_802_11_get_stat
{
1679 struct mwl8k_cmd_pkt header
;
1682 } __attribute__((packed
));
1684 #define MWL8K_STAT_ACK_FAILURE 9
1685 #define MWL8K_STAT_RTS_FAILURE 12
1686 #define MWL8K_STAT_FCS_ERROR 24
1687 #define MWL8K_STAT_RTS_SUCCESS 11
1689 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw
*hw
,
1690 struct ieee80211_low_level_stats
*stats
)
1692 struct mwl8k_cmd_802_11_get_stat
*cmd
;
1695 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1699 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
1700 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1701 cmd
->action
= cpu_to_le16(MWL8K_CMD_GET
);
1703 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1705 stats
->dot11ACKFailureCount
=
1706 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
1707 stats
->dot11RTSFailureCount
=
1708 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
1709 stats
->dot11FCSErrorCount
=
1710 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
1711 stats
->dot11RTSSuccessCount
=
1712 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
1720 * CMD_802_11_RADIO_CONTROL.
1722 struct mwl8k_cmd_802_11_radio_control
{
1723 struct mwl8k_cmd_pkt header
;
1727 } __attribute__((packed
));
1729 static int mwl8k_cmd_802_11_radio_control(struct ieee80211_hw
*hw
, int enable
)
1731 struct mwl8k_priv
*priv
= hw
->priv
;
1732 struct mwl8k_cmd_802_11_radio_control
*cmd
;
1735 if (((enable
& MWL8K_RADIO_ENABLE
) == priv
->radio_state
) &&
1736 !(enable
& MWL8K_RADIO_FORCE
))
1739 enable
&= MWL8K_RADIO_ENABLE
;
1741 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1745 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
1746 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1747 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1748 cmd
->control
= cpu_to_le16(priv
->radio_preamble
);
1749 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
1751 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1755 priv
->radio_state
= enable
;
1761 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
1763 struct mwl8k_priv
*priv
;
1765 if (hw
== NULL
|| hw
->priv
== NULL
)
1769 priv
->radio_preamble
= (short_preamble
?
1770 MWL8K_RADIO_SHORT_PREAMBLE
:
1771 MWL8K_RADIO_LONG_PREAMBLE
);
1773 return mwl8k_cmd_802_11_radio_control(hw
,
1774 MWL8K_RADIO_ENABLE
| MWL8K_RADIO_FORCE
);
1778 * CMD_802_11_RF_TX_POWER.
1780 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1782 struct mwl8k_cmd_802_11_rf_tx_power
{
1783 struct mwl8k_cmd_pkt header
;
1785 __le16 support_level
;
1786 __le16 current_level
;
1788 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
1789 } __attribute__((packed
));
1791 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
1793 struct mwl8k_cmd_802_11_rf_tx_power
*cmd
;
1796 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1800 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
1801 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1802 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1803 cmd
->support_level
= cpu_to_le16(dBm
);
1805 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1814 struct mwl8k_cmd_set_pre_scan
{
1815 struct mwl8k_cmd_pkt header
;
1816 } __attribute__((packed
));
1818 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
1820 struct mwl8k_cmd_set_pre_scan
*cmd
;
1823 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1827 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
1828 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1830 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1837 * CMD_SET_POST_SCAN.
1839 struct mwl8k_cmd_set_post_scan
{
1840 struct mwl8k_cmd_pkt header
;
1842 __u8 bssid
[ETH_ALEN
];
1843 } __attribute__((packed
));
1846 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, __u8
*mac
)
1848 struct mwl8k_cmd_set_post_scan
*cmd
;
1851 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1855 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
1856 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1858 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
1860 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1867 * CMD_SET_RF_CHANNEL.
1869 struct mwl8k_cmd_set_rf_channel
{
1870 struct mwl8k_cmd_pkt header
;
1872 __u8 current_channel
;
1873 __le32 channel_flags
;
1874 } __attribute__((packed
));
1876 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
1877 struct ieee80211_channel
*channel
)
1879 struct mwl8k_cmd_set_rf_channel
*cmd
;
1882 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1886 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
1887 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1888 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1889 cmd
->current_channel
= channel
->hw_value
;
1890 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1891 cmd
->channel_flags
= cpu_to_le32(0x00000081);
1893 cmd
->channel_flags
= cpu_to_le32(0x00000000);
1895 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1904 struct mwl8k_cmd_set_slot
{
1905 struct mwl8k_cmd_pkt header
;
1908 } __attribute__((packed
));
1910 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, int slot_time
)
1912 struct mwl8k_cmd_set_slot
*cmd
;
1915 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1919 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
1920 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1921 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1922 cmd
->short_slot
= slot_time
== MWL8K_SHORT_SLOTTIME
? 1 : 0;
1924 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1933 struct mwl8k_cmd_mimo_config
{
1934 struct mwl8k_cmd_pkt header
;
1936 __u8 rx_antenna_map
;
1937 __u8 tx_antenna_map
;
1938 } __attribute__((packed
));
1940 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
1942 struct mwl8k_cmd_mimo_config
*cmd
;
1945 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1949 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
1950 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1951 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
1952 cmd
->rx_antenna_map
= rx
;
1953 cmd
->tx_antenna_map
= tx
;
1955 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1962 * CMD_ENABLE_SNIFFER.
1964 struct mwl8k_cmd_enable_sniffer
{
1965 struct mwl8k_cmd_pkt header
;
1967 } __attribute__((packed
));
1969 static int mwl8k_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
1971 struct mwl8k_cmd_enable_sniffer
*cmd
;
1974 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1978 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
1979 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1980 cmd
->action
= cpu_to_le32(!!enable
);
1982 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1989 * CMD_SET_RATEADAPT_MODE.
1991 struct mwl8k_cmd_set_rate_adapt_mode
{
1992 struct mwl8k_cmd_pkt header
;
1995 } __attribute__((packed
));
1997 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw
*hw
, __u16 mode
)
1999 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
2002 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2006 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
2007 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2008 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2009 cmd
->mode
= cpu_to_le16(mode
);
2011 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2020 struct mwl8k_cmd_set_wmm
{
2021 struct mwl8k_cmd_pkt header
;
2023 } __attribute__((packed
));
2025 static int mwl8k_set_wmm(struct ieee80211_hw
*hw
, bool enable
)
2027 struct mwl8k_priv
*priv
= hw
->priv
;
2028 struct mwl8k_cmd_set_wmm
*cmd
;
2031 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2035 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
2036 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2037 cmd
->action
= enable
? cpu_to_le16(MWL8K_CMD_SET
) : 0;
2039 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2043 priv
->wmm_mode
= enable
;
2049 * CMD_SET_RTS_THRESHOLD.
2051 struct mwl8k_cmd_rts_threshold
{
2052 struct mwl8k_cmd_pkt header
;
2055 } __attribute__((packed
));
2057 static int mwl8k_rts_threshold(struct ieee80211_hw
*hw
,
2058 u16 action
, u16
*threshold
)
2060 struct mwl8k_cmd_rts_threshold
*cmd
;
2063 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2067 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
2068 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2069 cmd
->action
= cpu_to_le16(action
);
2070 cmd
->threshold
= cpu_to_le16(*threshold
);
2072 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2079 * CMD_SET_EDCA_PARAMS.
2081 struct mwl8k_cmd_set_edca_params
{
2082 struct mwl8k_cmd_pkt header
;
2084 /* See MWL8K_SET_EDCA_XXX below */
2087 /* TX opportunity in units of 32 us */
2090 /* Log exponent of max contention period: 0...15*/
2093 /* Log exponent of min contention period: 0...15 */
2096 /* Adaptive interframe spacing in units of 32us */
2099 /* TX queue to configure */
2101 } __attribute__((packed
));
2103 #define MWL8K_SET_EDCA_CW 0x01
2104 #define MWL8K_SET_EDCA_TXOP 0x02
2105 #define MWL8K_SET_EDCA_AIFS 0x04
2107 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2108 MWL8K_SET_EDCA_TXOP | \
2109 MWL8K_SET_EDCA_AIFS)
2112 mwl8k_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
2113 __u16 cw_min
, __u16 cw_max
,
2114 __u8 aifs
, __u16 txop
)
2116 struct mwl8k_cmd_set_edca_params
*cmd
;
2119 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2123 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
2124 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2125 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
2126 cmd
->txop
= cpu_to_le16(txop
);
2127 cmd
->log_cw_max
= (u8
)ilog2(cw_max
+ 1);
2128 cmd
->log_cw_min
= (u8
)ilog2(cw_min
+ 1);
2132 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2139 * CMD_FINALIZE_JOIN.
2142 /* FJ beacon buffer size is compiled into the firmware. */
2143 #define MWL8K_FJ_BEACON_MAXLEN 128
2145 struct mwl8k_cmd_finalize_join
{
2146 struct mwl8k_cmd_pkt header
;
2147 __le32 sleep_interval
; /* Number of beacon periods to sleep */
2148 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
2149 } __attribute__((packed
));
2151 static int mwl8k_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
2152 __u16 framelen
, __u16 dtim
)
2154 struct mwl8k_cmd_finalize_join
*cmd
;
2155 struct ieee80211_mgmt
*payload
= frame
;
2163 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2167 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
2168 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2169 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
2171 hdrlen
= ieee80211_hdrlen(payload
->frame_control
);
2173 payload_len
= framelen
> hdrlen
? framelen
- hdrlen
: 0;
2175 /* XXX TBD Might just have to abort and return an error */
2176 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2177 printk(KERN_ERR
"%s(): WARNING: Incomplete beacon "
2178 "sent to firmware. Sz=%u MAX=%u\n", __func__
,
2179 payload_len
, MWL8K_FJ_BEACON_MAXLEN
);
2181 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2182 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
2184 if (payload
&& payload_len
)
2185 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
2187 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2195 struct mwl8k_cmd_update_sta_db
{
2196 struct mwl8k_cmd_pkt header
;
2198 /* See STADB_ACTION_TYPE */
2201 /* Peer MAC address */
2202 __u8 peer_addr
[ETH_ALEN
];
2206 /* Peer info - valid during add/update. */
2207 struct peer_capability_info peer_info
;
2208 } __attribute__((packed
));
2210 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw
*hw
,
2211 struct ieee80211_vif
*vif
, __u32 action
)
2213 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2214 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2215 struct mwl8k_cmd_update_sta_db
*cmd
;
2216 struct peer_capability_info
*peer_info
;
2217 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2221 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2225 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
2226 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2228 cmd
->action
= cpu_to_le32(action
);
2229 peer_info
= &cmd
->peer_info
;
2230 memcpy(cmd
->peer_addr
, mv_vif
->bssid
, ETH_ALEN
);
2233 case MWL8K_STA_DB_ADD_ENTRY
:
2234 case MWL8K_STA_DB_MODIFY_ENTRY
:
2235 /* Build peer_info block */
2236 peer_info
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
2237 peer_info
->basic_caps
= cpu_to_le16(info
->assoc_capability
);
2238 peer_info
->interop
= 1;
2239 peer_info
->amsdu_enabled
= 0;
2241 rates
= peer_info
->legacy_rates
;
2242 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2243 rates
[count
] = bitrates
[count
].hw_value
;
2245 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2247 mv_vif
->peer_id
= peer_info
->station_id
;
2251 case MWL8K_STA_DB_DEL_ENTRY
:
2252 case MWL8K_STA_DB_FLUSH
:
2254 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2256 mv_vif
->peer_id
= 0;
2267 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2269 #define MWL8K_FRAME_PROT_DISABLED 0x00
2270 #define MWL8K_FRAME_PROT_11G 0x07
2271 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2272 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2274 struct mwl8k_cmd_update_set_aid
{
2275 struct mwl8k_cmd_pkt header
;
2278 /* AP's MAC address (BSSID) */
2279 __u8 bssid
[ETH_ALEN
];
2280 __le16 protection_mode
;
2281 __u8 supp_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2282 } __attribute__((packed
));
2284 static int mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
2285 struct ieee80211_vif
*vif
)
2287 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2288 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2289 struct mwl8k_cmd_update_set_aid
*cmd
;
2290 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2295 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2299 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
2300 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2301 cmd
->aid
= cpu_to_le16(info
->aid
);
2303 memcpy(cmd
->bssid
, mv_vif
->bssid
, ETH_ALEN
);
2305 if (info
->use_cts_prot
) {
2306 prot_mode
= MWL8K_FRAME_PROT_11G
;
2308 switch (info
->ht_operation_mode
&
2309 IEEE80211_HT_OP_MODE_PROTECTION
) {
2310 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
2311 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
2313 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
2314 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
2317 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
2321 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
2323 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2324 cmd
->supp_rates
[count
] = bitrates
[count
].hw_value
;
2326 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2335 struct mwl8k_cmd_update_rateset
{
2336 struct mwl8k_cmd_pkt header
;
2337 __u8 legacy_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2339 /* Bitmap for supported MCS codes. */
2340 __u8 mcs_set
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2341 __u8 reserved
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2342 } __attribute__((packed
));
2344 static int mwl8k_update_rateset(struct ieee80211_hw
*hw
,
2345 struct ieee80211_vif
*vif
)
2347 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2348 struct mwl8k_cmd_update_rateset
*cmd
;
2349 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2353 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2357 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
2358 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2360 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2361 cmd
->legacy_rates
[count
] = bitrates
[count
].hw_value
;
2363 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2370 * CMD_USE_FIXED_RATE.
2372 #define MWL8K_RATE_TABLE_SIZE 8
2373 #define MWL8K_UCAST_RATE 0
2374 #define MWL8K_USE_AUTO_RATE 0x0002
2376 struct mwl8k_rate_entry
{
2377 /* Set to 1 if HT rate, 0 if legacy. */
2380 /* Set to 1 to use retry_count field. */
2381 __le32 enable_retry
;
2383 /* Specified legacy rate or MCS. */
2386 /* Number of allowed retries. */
2388 } __attribute__((packed
));
2390 struct mwl8k_rate_table
{
2391 /* 1 to allow specified rate and below */
2392 __le32 allow_rate_drop
;
2394 struct mwl8k_rate_entry rate_entry
[MWL8K_RATE_TABLE_SIZE
];
2395 } __attribute__((packed
));
2397 struct mwl8k_cmd_use_fixed_rate
{
2398 struct mwl8k_cmd_pkt header
;
2400 struct mwl8k_rate_table rate_table
;
2402 /* Unicast, Broadcast or Multicast */
2406 } __attribute__((packed
));
2408 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw
*hw
,
2409 u32 action
, u32 rate_type
, struct mwl8k_rate_table
*rate_table
)
2411 struct mwl8k_cmd_use_fixed_rate
*cmd
;
2415 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2419 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2420 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2422 cmd
->action
= cpu_to_le32(action
);
2423 cmd
->rate_type
= cpu_to_le32(rate_type
);
2425 if (rate_table
!= NULL
) {
2426 /* Copy over each field manually so
2427 * that bitflipping can be done
2429 cmd
->rate_table
.allow_rate_drop
=
2430 cpu_to_le32(rate_table
->allow_rate_drop
);
2431 cmd
->rate_table
.num_rates
=
2432 cpu_to_le32(rate_table
->num_rates
);
2434 for (count
= 0; count
< rate_table
->num_rates
; count
++) {
2435 struct mwl8k_rate_entry
*dst
=
2436 &cmd
->rate_table
.rate_entry
[count
];
2437 struct mwl8k_rate_entry
*src
=
2438 &rate_table
->rate_entry
[count
];
2440 dst
->is_ht_rate
= cpu_to_le32(src
->is_ht_rate
);
2441 dst
->enable_retry
= cpu_to_le32(src
->enable_retry
);
2442 dst
->rate
= cpu_to_le32(src
->rate
);
2443 dst
->retry_count
= cpu_to_le32(src
->retry_count
);
2447 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2455 * Interrupt handling.
2457 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
2459 struct ieee80211_hw
*hw
= dev_id
;
2460 struct mwl8k_priv
*priv
= hw
->priv
;
2463 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2464 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2469 if (status
& MWL8K_A2H_INT_TX_DONE
)
2470 tasklet_schedule(&priv
->tx_reclaim_task
);
2472 if (status
& MWL8K_A2H_INT_RX_READY
) {
2473 while (rxq_process(hw
, 0, 1))
2474 rxq_refill(hw
, 0, 1);
2477 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
2478 if (priv
->hostcmd_wait
!= NULL
) {
2479 complete(priv
->hostcmd_wait
);
2480 priv
->hostcmd_wait
= NULL
;
2484 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
2485 if (!priv
->inconfig
&&
2486 priv
->radio_state
&&
2487 mwl8k_txq_busy(priv
))
2488 mwl8k_tx_start(priv
);
2496 * Core driver operations.
2498 static int mwl8k_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2500 struct mwl8k_priv
*priv
= hw
->priv
;
2501 int index
= skb_get_queue_mapping(skb
);
2504 if (priv
->current_channel
== NULL
) {
2505 printk(KERN_DEBUG
"%s: dropped TX frame since radio "
2506 "disabled\n", priv
->name
);
2508 return NETDEV_TX_OK
;
2511 rc
= mwl8k_txq_xmit(hw
, index
, skb
);
2516 struct mwl8k_work_struct
{
2517 /* Initialized by mwl8k_queue_work(). */
2518 struct work_struct wt
;
2520 /* Required field passed in to mwl8k_queue_work(). */
2521 struct ieee80211_hw
*hw
;
2523 /* Required field passed in to mwl8k_queue_work(). */
2524 int (*wfunc
)(struct work_struct
*w
);
2526 /* Initialized by mwl8k_queue_work(). */
2527 struct completion
*cmd_wait
;
2533 * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
2534 * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
2538 /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
2539 unsigned long timeout_ms
;
2541 /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
2542 u32 txwait_attempts
;
2544 /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
2549 /* Flags controlling behavior of config queue requests */
2551 /* Caller spins while waiting for completion. */
2552 #define MWL8K_WQ_SPIN 0x00000001
2554 /* Wait for TX queues to empty before proceeding with configuration. */
2555 #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
2557 /* Queue request and return immediately. */
2558 #define MWL8K_WQ_POST_REQUEST 0x00000004
2561 * Caller sleeps and waits for task complete notification.
2562 * Do not use in atomic context.
2564 #define MWL8K_WQ_SLEEP 0x00000008
2566 /* Free work struct when task is done. */
2567 #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
2570 * Config request is queued and returns to caller imediately. Use
2571 * this in atomic context. Work struct is freed by mwl8k_queue_work()
2572 * when this flag is set.
2574 #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
2575 MWL8K_WQ_FREE_WORKSTRUCT)
2577 /* Default work queue behavior is to sleep and wait for tx completion. */
2578 #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
2581 * Default config request timeout. Add adjustments to make sure the
2582 * config thread waits long enough for both tx wait and cmd wait before
2586 /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
2587 #define MWL8K_TXWAIT_TIMEOUT_MS 1000
2589 /* Default number of TX wait attempts. */
2590 #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
2592 /* Total time to wait for TXQ to drain. */
2593 #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
2594 MWL8K_WQ_TXWAIT_ATTEMPTS)
2596 /* Scheduling slop. */
2597 #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
2599 #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
2601 MWL8K_OS_SCHEDULE_OVERHEAD_MS)
2603 static void mwl8k_config_thread(struct work_struct
*wt
)
2605 struct mwl8k_work_struct
*worker
= (struct mwl8k_work_struct
*)wt
;
2606 struct ieee80211_hw
*hw
= worker
->hw
;
2607 struct mwl8k_priv
*priv
= hw
->priv
;
2610 spin_lock_irq(&priv
->tx_lock
);
2611 priv
->inconfig
= true;
2612 spin_unlock_irq(&priv
->tx_lock
);
2614 ieee80211_stop_queues(hw
);
2617 * Wait for host queues to drain before doing PHY
2618 * reconfiguration. This avoids interrupting any in-flight
2619 * DMA transfers to the hardware.
2621 if (worker
->options
& MWL8K_WQ_TX_WAIT_EMPTY
) {
2625 u32 tx_wait_attempts
= worker
->txwait_attempts
;
2627 time_remaining
= worker
->tx_timeout_ms
;
2628 if (!tx_wait_attempts
)
2629 tx_wait_attempts
= 1;
2631 timeout
= worker
->tx_timeout_ms
/tx_wait_attempts
;
2635 iter
= tx_wait_attempts
;
2639 if (time_remaining
> timeout
) {
2640 time_remaining
-= timeout
;
2641 wait_time
= timeout
;
2643 wait_time
= time_remaining
;
2648 rc
= mwl8k_tx_wait_empty(hw
, wait_time
);
2650 printk(KERN_ERR
"%s() txwait timeout=%ums "
2651 "Retry:%u/%u\n", __func__
, timeout
,
2652 tx_wait_attempts
- iter
+ 1,
2655 } while (rc
&& --iter
);
2657 rc
= iter
? 0 : -ETIMEDOUT
;
2660 rc
= worker
->wfunc(wt
);
2662 spin_lock_irq(&priv
->tx_lock
);
2663 priv
->inconfig
= false;
2664 if (priv
->pending_tx_pkts
&& priv
->radio_state
)
2665 mwl8k_tx_start(priv
);
2666 spin_unlock_irq(&priv
->tx_lock
);
2667 ieee80211_wake_queues(hw
);
2670 if (worker
->options
& MWL8K_WQ_SLEEP
)
2671 complete(worker
->cmd_wait
);
2673 if (worker
->options
& MWL8K_WQ_FREE_WORKSTRUCT
)
2677 static int mwl8k_queue_work(struct ieee80211_hw
*hw
,
2678 struct mwl8k_work_struct
*worker
,
2679 struct workqueue_struct
*wqueue
,
2680 int (*wfunc
)(struct work_struct
*w
))
2682 unsigned long timeout
= 0;
2685 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
2687 if (!worker
->timeout_ms
)
2688 worker
->timeout_ms
= MWL8K_CONFIG_TIMEOUT_MS
;
2690 if (!worker
->options
)
2691 worker
->options
= MWL8K_WQ_DEFAULT_OPTIONS
;
2693 if (!worker
->txwait_attempts
)
2694 worker
->txwait_attempts
= MWL8K_WQ_TXWAIT_ATTEMPTS
;
2696 if (!worker
->tx_timeout_ms
)
2697 worker
->tx_timeout_ms
= MWL8K_TXWAIT_MS
;
2700 worker
->cmd_wait
= &cmd_wait
;
2702 worker
->wfunc
= wfunc
;
2704 INIT_WORK(&worker
->wt
, mwl8k_config_thread
);
2705 queue_work(wqueue
, &worker
->wt
);
2707 if (worker
->options
& MWL8K_WQ_POST_REQUEST
) {
2710 if (worker
->options
& MWL8K_WQ_SPIN
) {
2711 timeout
= worker
->timeout_ms
;
2712 while (timeout
&& (worker
->rc
> 0)) {
2716 } else if (worker
->options
& MWL8K_WQ_SLEEP
)
2717 timeout
= wait_for_completion_timeout(&cmd_wait
,
2718 msecs_to_jiffies(worker
->timeout_ms
));
2723 cancel_work_sync(&worker
->wt
);
2731 struct mwl8k_start_worker
{
2732 struct mwl8k_work_struct header
;
2735 static int mwl8k_start_wt(struct work_struct
*wt
)
2737 struct mwl8k_start_worker
*worker
= (struct mwl8k_start_worker
*)wt
;
2738 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2739 struct mwl8k_priv
*priv
= hw
->priv
;
2742 if (priv
->vif
!= NULL
) {
2744 goto mwl8k_start_exit
;
2748 if (mwl8k_cmd_802_11_radio_control(hw
, MWL8K_RADIO_ENABLE
)) {
2750 goto mwl8k_start_exit
;
2753 /* Purge TX/RX HW queues */
2754 if (mwl8k_cmd_set_pre_scan(hw
)) {
2756 goto mwl8k_start_exit
;
2759 if (mwl8k_cmd_set_post_scan(hw
, "\x00\x00\x00\x00\x00\x00")) {
2761 goto mwl8k_start_exit
;
2764 /* Enable firmware rate adaptation */
2765 if (mwl8k_cmd_setrateadaptmode(hw
, 0)) {
2767 goto mwl8k_start_exit
;
2770 /* Disable WMM. WMM gets enabled when stack sends WMM parms */
2771 if (mwl8k_set_wmm(hw
, MWL8K_WMM_DISABLE
)) {
2773 goto mwl8k_start_exit
;
2776 /* Disable sniffer mode */
2777 if (mwl8k_enable_sniffer(hw
, 0))
2784 static int mwl8k_start(struct ieee80211_hw
*hw
)
2786 struct mwl8k_start_worker
*worker
;
2787 struct mwl8k_priv
*priv
= hw
->priv
;
2790 /* Enable tx reclaim tasklet */
2791 tasklet_enable(&priv
->tx_reclaim_task
);
2793 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
2794 IRQF_SHARED
, MWL8K_NAME
, hw
);
2796 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
2799 goto mwl8k_start_disable_tasklet
;
2802 /* Enable interrupts */
2803 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2805 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2806 if (worker
== NULL
) {
2808 goto mwl8k_start_disable_irq
;
2811 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2812 priv
->config_wq
, mwl8k_start_wt
);
2817 if (rc
== -ETIMEDOUT
)
2818 printk(KERN_ERR
"%s() timed out\n", __func__
);
2822 mwl8k_start_disable_irq
:
2823 spin_lock_irq(&priv
->tx_lock
);
2824 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2825 spin_unlock_irq(&priv
->tx_lock
);
2826 free_irq(priv
->pdev
->irq
, hw
);
2828 mwl8k_start_disable_tasklet
:
2829 tasklet_disable(&priv
->tx_reclaim_task
);
2834 struct mwl8k_stop_worker
{
2835 struct mwl8k_work_struct header
;
2838 static int mwl8k_stop_wt(struct work_struct
*wt
)
2840 struct mwl8k_stop_worker
*worker
= (struct mwl8k_stop_worker
*)wt
;
2841 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2844 rc
= mwl8k_cmd_802_11_radio_control(hw
, MWL8K_RADIO_DISABLE
);
2849 static void mwl8k_stop(struct ieee80211_hw
*hw
)
2852 struct mwl8k_stop_worker
*worker
;
2853 struct mwl8k_priv
*priv
= hw
->priv
;
2856 if (priv
->vif
!= NULL
)
2859 ieee80211_stop_queues(hw
);
2861 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2865 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2866 priv
->config_wq
, mwl8k_stop_wt
);
2868 if (rc
== -ETIMEDOUT
)
2869 printk(KERN_ERR
"%s() timed out\n", __func__
);
2871 /* Disable interrupts */
2872 spin_lock_irq(&priv
->tx_lock
);
2873 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2874 spin_unlock_irq(&priv
->tx_lock
);
2875 free_irq(priv
->pdev
->irq
, hw
);
2877 /* Stop finalize join worker */
2878 cancel_work_sync(&priv
->finalize_join_worker
);
2879 if (priv
->beacon_skb
!= NULL
)
2880 dev_kfree_skb(priv
->beacon_skb
);
2882 /* Stop tx reclaim tasklet */
2883 tasklet_disable(&priv
->tx_reclaim_task
);
2885 /* Stop config thread */
2886 flush_workqueue(priv
->config_wq
);
2888 /* Return all skbs to mac80211 */
2889 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2890 mwl8k_txq_reclaim(hw
, i
, 1);
2893 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
2894 struct ieee80211_if_init_conf
*conf
)
2896 struct mwl8k_priv
*priv
= hw
->priv
;
2897 struct mwl8k_vif
*mwl8k_vif
;
2900 * We only support one active interface at a time.
2902 if (priv
->vif
!= NULL
)
2906 * We only support managed interfaces for now.
2908 if (conf
->type
!= NL80211_IFTYPE_STATION
&&
2909 conf
->type
!= NL80211_IFTYPE_MONITOR
)
2912 /* Clean out driver private area */
2913 mwl8k_vif
= MWL8K_VIF(conf
->vif
);
2914 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
2916 /* Save the mac address */
2917 memcpy(mwl8k_vif
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
2919 /* Back pointer to parent config block */
2920 mwl8k_vif
->priv
= priv
;
2922 /* Setup initial PHY parameters */
2923 memcpy(mwl8k_vif
->legacy_rates
,
2924 priv
->rates
, sizeof(mwl8k_vif
->legacy_rates
));
2925 mwl8k_vif
->legacy_nrates
= ARRAY_SIZE(priv
->rates
);
2927 /* Set Initial sequence number to zero */
2928 mwl8k_vif
->seqno
= 0;
2930 priv
->vif
= conf
->vif
;
2931 priv
->current_channel
= NULL
;
2936 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
2937 struct ieee80211_if_init_conf
*conf
)
2939 struct mwl8k_priv
*priv
= hw
->priv
;
2941 if (priv
->vif
== NULL
)
2947 struct mwl8k_config_worker
{
2948 struct mwl8k_work_struct header
;
2952 static int mwl8k_config_wt(struct work_struct
*wt
)
2954 struct mwl8k_config_worker
*worker
=
2955 (struct mwl8k_config_worker
*)wt
;
2956 struct ieee80211_hw
*hw
= worker
->header
.hw
;
2957 struct ieee80211_conf
*conf
= &hw
->conf
;
2958 struct mwl8k_priv
*priv
= hw
->priv
;
2961 if (mwl8k_cmd_802_11_radio_control(hw
, MWL8K_RADIO_ENABLE
)) {
2963 goto mwl8k_config_exit
;
2966 priv
->current_channel
= conf
->channel
;
2968 if (mwl8k_cmd_set_rf_channel(hw
, conf
->channel
)) {
2970 goto mwl8k_config_exit
;
2973 if (conf
->power_level
> 18)
2974 conf
->power_level
= 18;
2975 if (mwl8k_cmd_802_11_rf_tx_power(hw
, conf
->power_level
)) {
2977 goto mwl8k_config_exit
;
2980 if (mwl8k_cmd_mimo_config(hw
, 0x7, 0x7))
2987 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
2990 struct mwl8k_config_worker
*worker
;
2991 struct mwl8k_priv
*priv
= hw
->priv
;
2993 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
2997 worker
->changed
= changed
;
2998 rc
= mwl8k_queue_work(hw
, &worker
->header
,
2999 priv
->config_wq
, mwl8k_config_wt
);
3000 if (rc
== -ETIMEDOUT
) {
3001 printk(KERN_ERR
"%s() timed out.\n", __func__
);
3008 * mac80211 will crash on anything other than -EINVAL on
3009 * error. Looks like wireless extensions which calls mac80211
3010 * may be the actual culprit...
3012 return rc
? -EINVAL
: 0;
3015 struct mwl8k_bss_info_changed_worker
{
3016 struct mwl8k_work_struct header
;
3017 struct ieee80211_vif
*vif
;
3018 struct ieee80211_bss_conf
*info
;
3022 static int mwl8k_bss_info_changed_wt(struct work_struct
*wt
)
3024 struct mwl8k_bss_info_changed_worker
*worker
=
3025 (struct mwl8k_bss_info_changed_worker
*)wt
;
3026 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3027 struct ieee80211_vif
*vif
= worker
->vif
;
3028 struct ieee80211_bss_conf
*info
= worker
->info
;
3032 struct mwl8k_priv
*priv
= hw
->priv
;
3033 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3035 changed
= worker
->changed
;
3036 priv
->capture_beacon
= false;
3039 memcpy(&mwl8k_vif
->bss_info
, info
,
3040 sizeof(struct ieee80211_bss_conf
));
3043 if (mwl8k_update_rateset(hw
, vif
))
3044 goto mwl8k_bss_info_changed_exit
;
3046 /* Turn on rate adaptation */
3047 if (mwl8k_cmd_use_fixed_rate(hw
, MWL8K_USE_AUTO_RATE
,
3048 MWL8K_UCAST_RATE
, NULL
))
3049 goto mwl8k_bss_info_changed_exit
;
3051 /* Set radio preamble */
3052 if (mwl8k_set_radio_preamble(hw
,
3053 info
->use_short_preamble
))
3054 goto mwl8k_bss_info_changed_exit
;
3057 if (mwl8k_cmd_set_slot(hw
, info
->use_short_slot
?
3058 MWL8K_SHORT_SLOTTIME
: MWL8K_LONG_SLOTTIME
))
3059 goto mwl8k_bss_info_changed_exit
;
3061 /* Update peer rate info */
3062 if (mwl8k_cmd_update_sta_db(hw
, vif
,
3063 MWL8K_STA_DB_MODIFY_ENTRY
))
3064 goto mwl8k_bss_info_changed_exit
;
3067 if (mwl8k_cmd_set_aid(hw
, vif
))
3068 goto mwl8k_bss_info_changed_exit
;
3071 * Finalize the join. Tell rx handler to process
3072 * next beacon from our BSSID.
3074 memcpy(priv
->capture_bssid
, mwl8k_vif
->bssid
, ETH_ALEN
);
3075 priv
->capture_beacon
= true;
3077 mwl8k_cmd_update_sta_db(hw
, vif
, MWL8K_STA_DB_DEL_ENTRY
);
3078 memset(&mwl8k_vif
->bss_info
, 0,
3079 sizeof(struct ieee80211_bss_conf
));
3080 memset(mwl8k_vif
->bssid
, 0, ETH_ALEN
);
3083 mwl8k_bss_info_changed_exit
:
3088 static void mwl8k_bss_info_changed(struct ieee80211_hw
*hw
,
3089 struct ieee80211_vif
*vif
,
3090 struct ieee80211_bss_conf
*info
,
3093 struct mwl8k_bss_info_changed_worker
*worker
;
3094 struct mwl8k_priv
*priv
= hw
->priv
;
3095 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
3098 if (changed
& BSS_CHANGED_BSSID
)
3099 memcpy(mv_vif
->bssid
, info
->bssid
, ETH_ALEN
);
3101 if ((changed
& BSS_CHANGED_ASSOC
) == 0)
3104 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3109 worker
->info
= info
;
3110 worker
->changed
= changed
;
3111 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3113 mwl8k_bss_info_changed_wt
);
3115 if (rc
== -ETIMEDOUT
)
3116 printk(KERN_ERR
"%s() timed out\n", __func__
);
3119 struct mwl8k_configure_filter_worker
{
3120 struct mwl8k_work_struct header
;
3121 unsigned int changed_flags
;
3122 unsigned int *total_flags
;
3124 struct dev_addr_list
*mclist
;
3127 #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
3129 static int mwl8k_configure_filter_wt(struct work_struct
*wt
)
3131 struct mwl8k_configure_filter_worker
*worker
=
3132 (struct mwl8k_configure_filter_worker
*)wt
;
3134 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3135 unsigned int changed_flags
= worker
->changed_flags
;
3136 unsigned int *total_flags
= worker
->total_flags
;
3137 int mc_count
= worker
->mc_count
;
3138 struct dev_addr_list
*mclist
= worker
->mclist
;
3140 struct mwl8k_priv
*priv
= hw
->priv
;
3143 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
3144 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
3145 rc
= mwl8k_cmd_set_pre_scan(hw
);
3149 bssid
= "\x00\x00\x00\x00\x00\x00";
3150 if (priv
->vif
!= NULL
)
3151 bssid
= MWL8K_VIF(priv
->vif
)->bssid
;
3153 rc
= mwl8k_cmd_set_post_scan(hw
, bssid
);
3158 goto mwl8k_configure_filter_exit
;
3160 if (mc_count
> priv
->num_mcaddrs
)
3161 mc_count
= priv
->num_mcaddrs
;
3163 rc
= mwl8k_cmd_mac_multicast_adr(hw
, mc_count
, mclist
);
3166 "%s()Error setting multicast addresses\n",
3170 mwl8k_configure_filter_exit
:
3174 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
3175 int mc_count
, struct dev_addr_list
*mclist
)
3177 struct mwl8k_configure_filter_worker
*worker
;
3179 worker
= kzalloc(sizeof(*worker
), GFP_ATOMIC
);
3185 * XXX: This is _HORRIBLY_ broken!!
3187 * No locking, the mclist pointer might be invalid as soon as this
3188 * function returns, something in the list might be invalidated
3189 * once we get to the worker, etc...
3191 worker
->mc_count
= mc_count
;
3192 worker
->mclist
= mclist
;
3197 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
3198 unsigned int changed_flags
,
3199 unsigned int *total_flags
,
3203 struct mwl8k_configure_filter_worker
*worker
= (void *)multicast
;
3204 struct mwl8k_priv
*priv
= hw
->priv
;
3206 /* Clear unsupported feature flags */
3207 *total_flags
&= MWL8K_SUPPORTED_IF_FLAGS
;
3209 if (!(changed_flags
& MWL8K_SUPPORTED_IF_FLAGS
))
3215 worker
->header
.options
= MWL8K_WQ_QUEUE_ONLY
| MWL8K_WQ_TX_WAIT_EMPTY
;
3216 worker
->changed_flags
= changed_flags
;
3217 worker
->total_flags
= total_flags
;
3219 mwl8k_queue_work(hw
, &worker
->header
, priv
->config_wq
,
3220 mwl8k_configure_filter_wt
);
3223 struct mwl8k_set_rts_threshold_worker
{
3224 struct mwl8k_work_struct header
;
3228 static int mwl8k_set_rts_threshold_wt(struct work_struct
*wt
)
3230 struct mwl8k_set_rts_threshold_worker
*worker
=
3231 (struct mwl8k_set_rts_threshold_worker
*)wt
;
3233 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3234 u16 threshold
= (u16
)(worker
->value
);
3237 rc
= mwl8k_rts_threshold(hw
, MWL8K_CMD_SET
, &threshold
);
3242 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3245 struct mwl8k_set_rts_threshold_worker
*worker
;
3246 struct mwl8k_priv
*priv
= hw
->priv
;
3248 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3252 worker
->value
= value
;
3254 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3256 mwl8k_set_rts_threshold_wt
);
3259 if (rc
== -ETIMEDOUT
) {
3260 printk(KERN_ERR
"%s() timed out\n", __func__
);
3267 struct mwl8k_conf_tx_worker
{
3268 struct mwl8k_work_struct header
;
3270 const struct ieee80211_tx_queue_params
*params
;
3273 static int mwl8k_conf_tx_wt(struct work_struct
*wt
)
3275 struct mwl8k_conf_tx_worker
*worker
=
3276 (struct mwl8k_conf_tx_worker
*)wt
;
3278 struct ieee80211_hw
*hw
= worker
->header
.hw
;
3279 u16 queue
= worker
->queue
;
3280 const struct ieee80211_tx_queue_params
*params
= worker
->params
;
3282 struct mwl8k_priv
*priv
= hw
->priv
;
3285 if (priv
->wmm_mode
== MWL8K_WMM_DISABLE
)
3286 if (mwl8k_set_wmm(hw
, MWL8K_WMM_ENABLE
)) {
3288 goto mwl8k_conf_tx_exit
;
3291 if (mwl8k_set_edca_params(hw
, GET_TXQ(queue
), params
->cw_min
,
3292 params
->cw_max
, params
->aifs
, params
->txop
))
3298 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
3299 const struct ieee80211_tx_queue_params
*params
)
3302 struct mwl8k_conf_tx_worker
*worker
;
3303 struct mwl8k_priv
*priv
= hw
->priv
;
3305 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3309 worker
->queue
= queue
;
3310 worker
->params
= params
;
3311 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3312 priv
->config_wq
, mwl8k_conf_tx_wt
);
3314 if (rc
== -ETIMEDOUT
) {
3315 printk(KERN_ERR
"%s() timed out\n", __func__
);
3321 static int mwl8k_get_tx_stats(struct ieee80211_hw
*hw
,
3322 struct ieee80211_tx_queue_stats
*stats
)
3324 struct mwl8k_priv
*priv
= hw
->priv
;
3325 struct mwl8k_tx_queue
*txq
;
3328 spin_lock_bh(&priv
->tx_lock
);
3329 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++) {
3330 txq
= priv
->txq
+ index
;
3331 memcpy(&stats
[index
], &txq
->tx_stats
,
3332 sizeof(struct ieee80211_tx_queue_stats
));
3334 spin_unlock_bh(&priv
->tx_lock
);
3338 struct mwl8k_get_stats_worker
{
3339 struct mwl8k_work_struct header
;
3340 struct ieee80211_low_level_stats
*stats
;
3343 static int mwl8k_get_stats_wt(struct work_struct
*wt
)
3345 struct mwl8k_get_stats_worker
*worker
=
3346 (struct mwl8k_get_stats_worker
*)wt
;
3348 return mwl8k_cmd_802_11_get_stat(worker
->header
.hw
, worker
->stats
);
3351 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
3352 struct ieee80211_low_level_stats
*stats
)
3355 struct mwl8k_get_stats_worker
*worker
;
3356 struct mwl8k_priv
*priv
= hw
->priv
;
3358 worker
= kzalloc(sizeof(*worker
), GFP_KERNEL
);
3362 worker
->stats
= stats
;
3363 rc
= mwl8k_queue_work(hw
, &worker
->header
,
3364 priv
->config_wq
, mwl8k_get_stats_wt
);
3367 if (rc
== -ETIMEDOUT
) {
3368 printk(KERN_ERR
"%s() timed out\n", __func__
);
3375 static const struct ieee80211_ops mwl8k_ops
= {
3377 .start
= mwl8k_start
,
3379 .add_interface
= mwl8k_add_interface
,
3380 .remove_interface
= mwl8k_remove_interface
,
3381 .config
= mwl8k_config
,
3382 .bss_info_changed
= mwl8k_bss_info_changed
,
3383 .prepare_multicast
= mwl8k_prepare_multicast
,
3384 .configure_filter
= mwl8k_configure_filter
,
3385 .set_rts_threshold
= mwl8k_set_rts_threshold
,
3386 .conf_tx
= mwl8k_conf_tx
,
3387 .get_tx_stats
= mwl8k_get_tx_stats
,
3388 .get_stats
= mwl8k_get_stats
,
3391 static void mwl8k_tx_reclaim_handler(unsigned long data
)
3394 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*) data
;
3395 struct mwl8k_priv
*priv
= hw
->priv
;
3397 spin_lock_bh(&priv
->tx_lock
);
3398 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3399 mwl8k_txq_reclaim(hw
, i
, 0);
3401 if (priv
->tx_wait
!= NULL
&& mwl8k_txq_busy(priv
) == 0) {
3402 complete(priv
->tx_wait
);
3403 priv
->tx_wait
= NULL
;
3405 spin_unlock_bh(&priv
->tx_lock
);
3408 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
3410 struct mwl8k_priv
*priv
=
3411 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
3412 struct sk_buff
*skb
= priv
->beacon_skb
;
3413 u8 dtim
= MWL8K_VIF(priv
->vif
)->bss_info
.dtim_period
;
3415 mwl8k_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim
);
3418 priv
->beacon_skb
= NULL
;
3421 static int __devinit
mwl8k_probe(struct pci_dev
*pdev
,
3422 const struct pci_device_id
*id
)
3424 struct ieee80211_hw
*hw
;
3425 struct mwl8k_priv
*priv
;
3430 rc
= pci_enable_device(pdev
);
3432 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
3437 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
3439 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
3444 pci_set_master(pdev
);
3446 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
3448 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
3456 priv
->hostcmd_wait
= NULL
;
3457 priv
->tx_wait
= NULL
;
3458 priv
->inconfig
= false;
3459 priv
->wmm_mode
= false;
3460 priv
->pending_tx_pkts
= 0;
3461 strncpy(priv
->name
, MWL8K_NAME
, sizeof(priv
->name
));
3463 spin_lock_init(&priv
->fw_lock
);
3465 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
3466 pci_set_drvdata(pdev
, hw
);
3468 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
3469 if (priv
->regs
== NULL
) {
3470 printk(KERN_ERR
"%s: Cannot map device memory\n", priv
->name
);
3474 memcpy(priv
->channels
, mwl8k_channels
, sizeof(mwl8k_channels
));
3475 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
3476 priv
->band
.channels
= priv
->channels
;
3477 priv
->band
.n_channels
= ARRAY_SIZE(mwl8k_channels
);
3478 priv
->band
.bitrates
= priv
->rates
;
3479 priv
->band
.n_bitrates
= ARRAY_SIZE(mwl8k_rates
);
3480 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
3482 BUILD_BUG_ON(sizeof(priv
->rates
) != sizeof(mwl8k_rates
));
3483 memcpy(priv
->rates
, mwl8k_rates
, sizeof(mwl8k_rates
));
3486 * Extra headroom is the size of the required DMA header
3487 * minus the size of the smallest 802.11 frame (CTS frame).
3489 hw
->extra_tx_headroom
=
3490 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
3492 hw
->channel_change_time
= 10;
3494 hw
->queues
= MWL8K_TX_QUEUES
;
3496 hw
->wiphy
->interface_modes
=
3497 BIT(NL80211_IFTYPE_STATION
) | BIT(NL80211_IFTYPE_MONITOR
);
3499 /* Set rssi and noise values to dBm */
3500 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
| IEEE80211_HW_NOISE_DBM
;
3501 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
3504 /* Set default radio state and preamble */
3505 priv
->radio_preamble
= MWL8K_RADIO_DEFAULT_PREAMBLE
;
3506 priv
->radio_state
= MWL8K_RADIO_DISABLE
;
3508 /* Finalize join worker */
3509 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
3511 /* TX reclaim tasklet */
3512 tasklet_init(&priv
->tx_reclaim_task
,
3513 mwl8k_tx_reclaim_handler
, (unsigned long)hw
);
3514 tasklet_disable(&priv
->tx_reclaim_task
);
3516 /* Config workthread */
3517 priv
->config_wq
= create_singlethread_workqueue("mwl8k_config");
3518 if (priv
->config_wq
== NULL
)
3521 /* Power management cookie */
3522 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
3523 if (priv
->cookie
== NULL
)
3526 rc
= mwl8k_rxq_init(hw
, 0);
3529 rxq_refill(hw
, 0, INT_MAX
);
3531 spin_lock_init(&priv
->tx_lock
);
3533 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
3534 rc
= mwl8k_txq_init(hw
, i
);
3536 goto err_free_queues
;
3539 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3540 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3541 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
3542 iowrite32(0xffffffff, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3544 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
3545 IRQF_SHARED
, MWL8K_NAME
, hw
);
3547 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
3549 goto err_free_queues
;
3552 /* Reset firmware and hardware */
3553 mwl8k_hw_reset(priv
);
3555 /* Ask userland hotplug daemon for the device firmware */
3556 rc
= mwl8k_request_firmware(priv
, (u32
)id
->driver_data
);
3558 printk(KERN_ERR
"%s: Firmware files not found\n", priv
->name
);
3562 /* Load firmware into hardware */
3563 rc
= mwl8k_load_firmware(priv
);
3565 printk(KERN_ERR
"%s: Cannot start firmware\n", priv
->name
);
3566 goto err_stop_firmware
;
3569 /* Reclaim memory once firmware is successfully loaded */
3570 mwl8k_release_firmware(priv
);
3573 * Temporarily enable interrupts. Initial firmware host
3574 * commands use interrupts and avoids polling. Disable
3575 * interrupts when done.
3577 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3579 /* Get config data, mac addrs etc */
3580 rc
= mwl8k_cmd_get_hw_spec(hw
);
3582 printk(KERN_ERR
"%s: Cannot initialise firmware\n", priv
->name
);
3583 goto err_stop_firmware
;
3586 /* Turn radio off */
3587 rc
= mwl8k_cmd_802_11_radio_control(hw
, MWL8K_RADIO_DISABLE
);
3589 printk(KERN_ERR
"%s: Cannot disable\n", priv
->name
);
3590 goto err_stop_firmware
;
3593 /* Disable interrupts */
3594 spin_lock_irq(&priv
->tx_lock
);
3595 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3596 spin_unlock_irq(&priv
->tx_lock
);
3597 free_irq(priv
->pdev
->irq
, hw
);
3599 rc
= ieee80211_register_hw(hw
);
3601 printk(KERN_ERR
"%s: Cannot register device\n", priv
->name
);
3602 goto err_stop_firmware
;
3605 fw
= (u8
*)&priv
->fw_rev
;
3606 printk(KERN_INFO
"%s: 88W%u %s\n", priv
->name
, priv
->part_num
,
3608 printk(KERN_INFO
"%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
3609 priv
->name
, MWL8K_VERSION
, fw
[3], fw
[2], fw
[1], fw
[0]);
3610 printk(KERN_INFO
"%s: MAC Address: %pM\n", priv
->name
,
3611 hw
->wiphy
->perm_addr
);
3616 mwl8k_hw_reset(priv
);
3617 mwl8k_release_firmware(priv
);
3620 spin_lock_irq(&priv
->tx_lock
);
3621 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3622 spin_unlock_irq(&priv
->tx_lock
);
3623 free_irq(priv
->pdev
->irq
, hw
);
3626 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3627 mwl8k_txq_deinit(hw
, i
);
3628 mwl8k_rxq_deinit(hw
, 0);
3631 if (priv
->cookie
!= NULL
)
3632 pci_free_consistent(priv
->pdev
, 4,
3633 priv
->cookie
, priv
->cookie_dma
);
3635 if (priv
->regs
!= NULL
)
3636 pci_iounmap(pdev
, priv
->regs
);
3638 if (priv
->config_wq
!= NULL
)
3639 destroy_workqueue(priv
->config_wq
);
3641 pci_set_drvdata(pdev
, NULL
);
3642 ieee80211_free_hw(hw
);
3645 pci_release_regions(pdev
);
3646 pci_disable_device(pdev
);
3651 static void __devexit
mwl8k_shutdown(struct pci_dev
*pdev
)
3653 printk(KERN_ERR
"===>%s(%u)\n", __func__
, __LINE__
);
3656 static void __devexit
mwl8k_remove(struct pci_dev
*pdev
)
3658 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
3659 struct mwl8k_priv
*priv
;
3666 ieee80211_stop_queues(hw
);
3668 ieee80211_unregister_hw(hw
);
3670 /* Remove tx reclaim tasklet */
3671 tasklet_kill(&priv
->tx_reclaim_task
);
3673 /* Stop config thread */
3674 destroy_workqueue(priv
->config_wq
);
3677 mwl8k_hw_reset(priv
);
3679 /* Return all skbs to mac80211 */
3680 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3681 mwl8k_txq_reclaim(hw
, i
, 1);
3683 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3684 mwl8k_txq_deinit(hw
, i
);
3686 mwl8k_rxq_deinit(hw
, 0);
3688 pci_free_consistent(priv
->pdev
, 4,
3689 priv
->cookie
, priv
->cookie_dma
);
3691 pci_iounmap(pdev
, priv
->regs
);
3692 pci_set_drvdata(pdev
, NULL
);
3693 ieee80211_free_hw(hw
);
3694 pci_release_regions(pdev
);
3695 pci_disable_device(pdev
);
3698 static struct pci_driver mwl8k_driver
= {
3700 .id_table
= mwl8k_table
,
3701 .probe
= mwl8k_probe
,
3702 .remove
= __devexit_p(mwl8k_remove
),
3703 .shutdown
= __devexit_p(mwl8k_shutdown
),
3706 static int __init
mwl8k_init(void)
3708 return pci_register_driver(&mwl8k_driver
);
3711 static void __exit
mwl8k_exit(void)
3713 pci_unregister_driver(&mwl8k_driver
);
3716 module_init(mwl8k_init
);
3717 module_exit(mwl8k_exit
);