2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008-2009 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.10"
30 static DEFINE_PCI_DEVICE_TABLE(mwl8k_table
) = {
31 { PCI_VDEVICE(MARVELL
, 0x2a2b), .driver_data
= 8687, },
32 { PCI_VDEVICE(MARVELL
, 0x2a30), .driver_data
= 8687, },
35 MODULE_DEVICE_TABLE(pci
, mwl8k_table
);
37 /* Register definitions */
38 #define MWL8K_HIU_GEN_PTR 0x00000c10
39 #define MWL8K_MODE_STA 0x0000005a
40 #define MWL8K_MODE_AP 0x000000a5
41 #define MWL8K_HIU_INT_CODE 0x00000c14
42 #define MWL8K_FWSTA_READY 0xf0f1f2f4
43 #define MWL8K_FWAP_READY 0xf1f2f4a5
44 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
45 #define MWL8K_HIU_SCRATCH 0x00000c40
47 /* Host->device communications */
48 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
49 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
50 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
51 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
52 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
53 #define MWL8K_H2A_INT_DUMMY (1 << 20)
54 #define MWL8K_H2A_INT_RESET (1 << 15)
55 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
56 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
58 /* Device->host communications */
59 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
60 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
61 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
62 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
63 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
64 #define MWL8K_A2H_INT_DUMMY (1 << 20)
65 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
66 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
67 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
68 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
69 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
70 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
71 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
72 #define MWL8K_A2H_INT_RX_READY (1 << 1)
73 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
75 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
76 MWL8K_A2H_INT_CHNL_SWITCHED | \
77 MWL8K_A2H_INT_QUEUE_EMPTY | \
78 MWL8K_A2H_INT_RADAR_DETECT | \
79 MWL8K_A2H_INT_RADIO_ON | \
80 MWL8K_A2H_INT_RADIO_OFF | \
81 MWL8K_A2H_INT_MAC_EVENT | \
82 MWL8K_A2H_INT_OPC_DONE | \
83 MWL8K_A2H_INT_RX_READY | \
84 MWL8K_A2H_INT_TX_DONE)
86 /* WME stream classes */
87 #define WME_AC_BE 0 /* best effort */
88 #define WME_AC_BK 1 /* background */
89 #define WME_AC_VI 2 /* video */
90 #define WME_AC_VO 3 /* voice */
92 #define MWL8K_RX_QUEUES 1
93 #define MWL8K_TX_QUEUES 4
95 struct mwl8k_rx_queue
{
98 /* hw receives here */
101 /* refill descs here */
104 struct mwl8k_rx_desc
*rx_desc_area
;
105 dma_addr_t rx_desc_dma
;
106 struct sk_buff
**rx_skb
;
109 struct mwl8k_tx_queue
{
110 /* hw transmits here */
113 /* sw appends here */
116 struct ieee80211_tx_queue_stats tx_stats
;
117 struct mwl8k_tx_desc
*tx_desc_area
;
118 dma_addr_t tx_desc_dma
;
119 struct sk_buff
**tx_skb
;
122 /* Pointers to the firmware data and meta information about it. */
123 struct mwl8k_firmware
{
125 struct firmware
*ucode
;
127 /* Boot helper code */
128 struct firmware
*helper
;
133 struct ieee80211_hw
*hw
;
135 struct pci_dev
*pdev
;
137 /* firmware files and meta data */
138 struct mwl8k_firmware fw
;
141 /* firmware access */
142 struct mutex fw_mutex
;
143 struct task_struct
*fw_mutex_owner
;
145 struct completion
*hostcmd_wait
;
147 /* lock held over TX and TX reap */
150 /* TX quiesce completion, protected by fw_mutex and tx_lock */
151 struct completion
*tx_wait
;
153 struct ieee80211_vif
*vif
;
155 struct ieee80211_channel
*current_channel
;
157 /* power management status cookie from firmware */
159 dma_addr_t cookie_dma
;
166 * Running count of TX packets in flight, to avoid
167 * iterating over the transmit rings each time.
171 struct mwl8k_rx_queue rxq
[MWL8K_RX_QUEUES
];
172 struct mwl8k_tx_queue txq
[MWL8K_TX_QUEUES
];
175 struct ieee80211_supported_band band
;
176 struct ieee80211_channel channels
[14];
177 struct ieee80211_rate rates
[12];
180 bool radio_short_preamble
;
183 /* XXX need to convert this to handle multiple interfaces */
185 u8 capture_bssid
[ETH_ALEN
];
186 struct sk_buff
*beacon_skb
;
189 * This FJ worker has to be global as it is scheduled from the
190 * RX handler. At this point we don't know which interface it
191 * belongs to until the list of bssids waiting to complete join
194 struct work_struct finalize_join_worker
;
196 /* Tasklet to reclaim TX descriptors and buffers after tx */
197 struct tasklet_struct tx_reclaim_task
;
200 /* Per interface specific private data */
202 /* backpointer to parent config block */
203 struct mwl8k_priv
*priv
;
205 /* BSS config of AP or IBSS from mac80211*/
206 struct ieee80211_bss_conf bss_info
;
208 /* BSSID of AP or IBSS */
210 u8 mac_addr
[ETH_ALEN
];
213 * Subset of supported legacy rates.
214 * Intersection of AP and STA supported rates.
216 struct ieee80211_rate legacy_rates
[12];
218 /* number of supported legacy rates */
221 /* Index into station database.Returned by update_sta_db call */
224 /* Non AMPDU sequence number assigned by driver */
228 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
230 static const struct ieee80211_channel mwl8k_channels
[] = {
231 { .center_freq
= 2412, .hw_value
= 1, },
232 { .center_freq
= 2417, .hw_value
= 2, },
233 { .center_freq
= 2422, .hw_value
= 3, },
234 { .center_freq
= 2427, .hw_value
= 4, },
235 { .center_freq
= 2432, .hw_value
= 5, },
236 { .center_freq
= 2437, .hw_value
= 6, },
237 { .center_freq
= 2442, .hw_value
= 7, },
238 { .center_freq
= 2447, .hw_value
= 8, },
239 { .center_freq
= 2452, .hw_value
= 9, },
240 { .center_freq
= 2457, .hw_value
= 10, },
241 { .center_freq
= 2462, .hw_value
= 11, },
244 static const struct ieee80211_rate mwl8k_rates
[] = {
245 { .bitrate
= 10, .hw_value
= 2, },
246 { .bitrate
= 20, .hw_value
= 4, },
247 { .bitrate
= 55, .hw_value
= 11, },
248 { .bitrate
= 60, .hw_value
= 12, },
249 { .bitrate
= 90, .hw_value
= 18, },
250 { .bitrate
= 110, .hw_value
= 22, },
251 { .bitrate
= 120, .hw_value
= 24, },
252 { .bitrate
= 180, .hw_value
= 36, },
253 { .bitrate
= 240, .hw_value
= 48, },
254 { .bitrate
= 360, .hw_value
= 72, },
255 { .bitrate
= 480, .hw_value
= 96, },
256 { .bitrate
= 540, .hw_value
= 108, },
259 /* Set or get info from Firmware */
260 #define MWL8K_CMD_SET 0x0001
261 #define MWL8K_CMD_GET 0x0000
263 /* Firmware command codes */
264 #define MWL8K_CMD_CODE_DNLD 0x0001
265 #define MWL8K_CMD_GET_HW_SPEC 0x0003
266 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
267 #define MWL8K_CMD_GET_STAT 0x0014
268 #define MWL8K_CMD_RADIO_CONTROL 0x001c
269 #define MWL8K_CMD_RF_TX_POWER 0x001e
270 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
271 #define MWL8K_CMD_SET_POST_SCAN 0x0108
272 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
273 #define MWL8K_CMD_SET_AID 0x010d
274 #define MWL8K_CMD_SET_RATE 0x0110
275 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
276 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
277 #define MWL8K_CMD_SET_SLOT 0x0114
278 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
279 #define MWL8K_CMD_SET_WMM_MODE 0x0123
280 #define MWL8K_CMD_MIMO_CONFIG 0x0125
281 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
282 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
283 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
284 #define MWL8K_CMD_UPDATE_STADB 0x1123
286 static const char *mwl8k_cmd_name(u16 cmd
, char *buf
, int bufsize
)
288 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
289 snprintf(buf, bufsize, "%s", #x);\
292 switch (cmd
& ~0x8000) {
293 MWL8K_CMDNAME(CODE_DNLD
);
294 MWL8K_CMDNAME(GET_HW_SPEC
);
295 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
296 MWL8K_CMDNAME(GET_STAT
);
297 MWL8K_CMDNAME(RADIO_CONTROL
);
298 MWL8K_CMDNAME(RF_TX_POWER
);
299 MWL8K_CMDNAME(SET_PRE_SCAN
);
300 MWL8K_CMDNAME(SET_POST_SCAN
);
301 MWL8K_CMDNAME(SET_RF_CHANNEL
);
302 MWL8K_CMDNAME(SET_AID
);
303 MWL8K_CMDNAME(SET_RATE
);
304 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
305 MWL8K_CMDNAME(RTS_THRESHOLD
);
306 MWL8K_CMDNAME(SET_SLOT
);
307 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
308 MWL8K_CMDNAME(SET_WMM_MODE
);
309 MWL8K_CMDNAME(MIMO_CONFIG
);
310 MWL8K_CMDNAME(USE_FIXED_RATE
);
311 MWL8K_CMDNAME(ENABLE_SNIFFER
);
312 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
313 MWL8K_CMDNAME(UPDATE_STADB
);
315 snprintf(buf
, bufsize
, "0x%x", cmd
);
322 /* Hardware and firmware reset */
323 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
325 iowrite32(MWL8K_H2A_INT_RESET
,
326 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
327 iowrite32(MWL8K_H2A_INT_RESET
,
328 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
332 /* Release fw image */
333 static void mwl8k_release_fw(struct firmware
**fw
)
337 release_firmware(*fw
);
341 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
343 mwl8k_release_fw(&priv
->fw
.ucode
);
344 mwl8k_release_fw(&priv
->fw
.helper
);
347 /* Request fw image */
348 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
349 const char *fname
, struct firmware
**fw
)
351 /* release current image */
353 mwl8k_release_fw(fw
);
355 return request_firmware((const struct firmware
**)fw
,
356 fname
, &priv
->pdev
->dev
);
359 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, u32 part_num
)
364 priv
->part_num
= part_num
;
366 snprintf(filename
, sizeof(filename
),
367 "mwl8k/helper_%u.fw", priv
->part_num
);
369 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.helper
);
371 printk(KERN_ERR
"%s: Error requesting helper firmware "
372 "file %s\n", pci_name(priv
->pdev
), filename
);
376 snprintf(filename
, sizeof(filename
),
377 "mwl8k/fmimage_%u.fw", priv
->part_num
);
379 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.ucode
);
381 printk(KERN_ERR
"%s: Error requesting firmware file %s\n",
382 pci_name(priv
->pdev
), filename
);
383 mwl8k_release_fw(&priv
->fw
.helper
);
390 struct mwl8k_cmd_pkt
{
396 } __attribute__((packed
));
402 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
404 void __iomem
*regs
= priv
->regs
;
408 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
409 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
412 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
413 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
414 iowrite32(MWL8K_H2A_INT_DOORBELL
,
415 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
416 iowrite32(MWL8K_H2A_INT_DUMMY
,
417 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
423 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
424 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
425 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
432 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
434 return loops
? 0 : -ETIMEDOUT
;
437 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
438 const u8
*data
, size_t length
)
440 struct mwl8k_cmd_pkt
*cmd
;
444 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
448 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
454 int block_size
= length
> 256 ? 256 : length
;
456 memcpy(cmd
->payload
, data
+ done
, block_size
);
457 cmd
->length
= cpu_to_le16(block_size
);
459 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
460 sizeof(*cmd
) + block_size
);
465 length
-= block_size
;
470 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
478 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
479 const u8
*data
, size_t length
)
481 unsigned char *buffer
;
482 int may_continue
, rc
= 0;
483 u32 done
, prev_block_size
;
485 buffer
= kmalloc(1024, GFP_KERNEL
);
492 while (may_continue
> 0) {
495 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
496 if (block_size
& 1) {
500 done
+= prev_block_size
;
501 length
-= prev_block_size
;
504 if (block_size
> 1024 || block_size
> length
) {
514 if (block_size
== 0) {
521 prev_block_size
= block_size
;
522 memcpy(buffer
, data
+ done
, block_size
);
524 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
529 if (!rc
&& length
!= 0)
537 static int mwl8k_load_firmware(struct ieee80211_hw
*hw
)
539 struct mwl8k_priv
*priv
= hw
->priv
;
540 struct firmware
*fw
= priv
->fw
.ucode
;
544 if (!memcmp(fw
->data
, "\x01\x00\x00\x00", 4)) {
545 struct firmware
*helper
= priv
->fw
.helper
;
547 if (helper
== NULL
) {
548 printk(KERN_ERR
"%s: helper image needed but none "
549 "given\n", pci_name(priv
->pdev
));
553 rc
= mwl8k_load_fw_image(priv
, helper
->data
, helper
->size
);
555 printk(KERN_ERR
"%s: unable to load firmware "
556 "helper image\n", pci_name(priv
->pdev
));
561 rc
= mwl8k_feed_fw_image(priv
, fw
->data
, fw
->size
);
563 rc
= mwl8k_load_fw_image(priv
, fw
->data
, fw
->size
);
567 printk(KERN_ERR
"%s: unable to load firmware image\n",
568 pci_name(priv
->pdev
));
572 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
577 if (ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
)
578 == MWL8K_FWSTA_READY
)
583 return loops
? 0 : -ETIMEDOUT
;
588 * Defines shared between transmission and reception.
590 /* HT control fields for firmware */
595 } __attribute__((packed
));
597 /* Firmware Station database operations */
598 #define MWL8K_STA_DB_ADD_ENTRY 0
599 #define MWL8K_STA_DB_MODIFY_ENTRY 1
600 #define MWL8K_STA_DB_DEL_ENTRY 2
601 #define MWL8K_STA_DB_FLUSH 3
603 /* Peer Entry flags - used to define the type of the peer node */
604 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
606 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
607 #define MWL8K_MCS_BITMAP_SIZE 16
609 struct peer_capability_info
{
610 /* Peer type - AP vs. STA. */
613 /* Basic 802.11 capabilities from assoc resp. */
616 /* Set if peer supports 802.11n high throughput (HT). */
619 /* Valid if HT is supported. */
621 __u8 extended_ht_caps
;
622 struct ewc_ht_info ewc_info
;
624 /* Legacy rate table. Intersection of our rates and peer rates. */
625 __u8 legacy_rates
[MWL8K_IEEE_LEGACY_DATA_RATES
];
627 /* HT rate table. Intersection of our rates and peer rates. */
628 __u8 ht_rates
[MWL8K_MCS_BITMAP_SIZE
];
631 /* If set, interoperability mode, no proprietary extensions. */
635 __le16 amsdu_enabled
;
636 } __attribute__((packed
));
638 /* Inline functions to manipulate QoS field in data descriptor. */
639 static inline u16
mwl8k_qos_setbit_eosp(u16 qos
)
641 u16 val_mask
= 1 << 4;
643 /* End of Service Period Bit 4 */
644 return qos
| val_mask
;
647 static inline u16
mwl8k_qos_setbit_ack(u16 qos
, u8 ack_policy
)
651 u16 qos_mask
= ~(val_mask
<< shift
);
653 /* Ack Policy Bit 5-6 */
654 return (qos
& qos_mask
) | ((ack_policy
& val_mask
) << shift
);
657 static inline u16
mwl8k_qos_setbit_amsdu(u16 qos
)
659 u16 val_mask
= 1 << 7;
661 /* AMSDU present Bit 7 */
662 return qos
| val_mask
;
665 static inline u16
mwl8k_qos_setbit_qlen(u16 qos
, u8 len
)
669 u16 qos_mask
= ~(val_mask
<< shift
);
671 /* Queue Length Bits 8-15 */
672 return (qos
& qos_mask
) | ((len
& val_mask
) << shift
);
675 /* DMA header used by firmware and hardware. */
676 struct mwl8k_dma_data
{
678 struct ieee80211_hdr wh
;
679 } __attribute__((packed
));
681 /* Routines to add/remove DMA header from skb. */
682 static inline void mwl8k_remove_dma_header(struct sk_buff
*skb
)
684 struct mwl8k_dma_data
*tr
= (struct mwl8k_dma_data
*)skb
->data
;
685 void *dst
, *src
= &tr
->wh
;
686 int hdrlen
= ieee80211_hdrlen(tr
->wh
.frame_control
);
687 u16 space
= sizeof(struct mwl8k_dma_data
) - hdrlen
;
689 dst
= (void *)tr
+ space
;
691 memmove(dst
, src
, hdrlen
);
692 skb_pull(skb
, space
);
696 static inline void mwl8k_add_dma_header(struct sk_buff
*skb
)
698 struct ieee80211_hdr
*wh
;
700 struct mwl8k_dma_data
*tr
;
702 wh
= (struct ieee80211_hdr
*)skb
->data
;
703 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
707 * Copy up/down the 802.11 header; the firmware requires
708 * we present a 2-byte payload length followed by a
709 * 4-address header (w/o QoS), followed (optionally) by
710 * any WEP/ExtIV header (but only filled in for CCMP).
712 if (hdrlen
!= sizeof(struct mwl8k_dma_data
))
713 skb_push(skb
, sizeof(struct mwl8k_dma_data
) - hdrlen
);
715 tr
= (struct mwl8k_dma_data
*)skb
->data
;
717 memmove(&tr
->wh
, wh
, hdrlen
);
720 memset(tr
->wh
.addr4
, 0, ETH_ALEN
);
723 * Firmware length is the length of the fully formed "802.11
724 * payload". That is, everything except for the 802.11 header.
725 * This includes all crypto material including the MIC.
727 tr
->fwlen
= cpu_to_le16(pktlen
- hdrlen
);
734 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
736 struct mwl8k_rx_desc
{
740 __le32 pkt_phys_addr
;
741 __le32 next_rx_desc_phys_addr
;
751 } __attribute__((packed
));
753 #define MWL8K_RX_DESCS 256
754 #define MWL8K_RX_MAXSZ 3800
756 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
758 struct mwl8k_priv
*priv
= hw
->priv
;
759 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
763 rxq
->rx_desc_count
= 0;
767 size
= MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
);
770 pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rx_desc_dma
);
771 if (rxq
->rx_desc_area
== NULL
) {
772 printk(KERN_ERR
"%s: failed to alloc RX descriptors\n",
773 wiphy_name(hw
->wiphy
));
776 memset(rxq
->rx_desc_area
, 0, size
);
778 rxq
->rx_skb
= kmalloc(MWL8K_RX_DESCS
*
779 sizeof(*rxq
->rx_skb
), GFP_KERNEL
);
780 if (rxq
->rx_skb
== NULL
) {
781 printk(KERN_ERR
"%s: failed to alloc RX skbuff list\n",
782 wiphy_name(hw
->wiphy
));
783 pci_free_consistent(priv
->pdev
, size
,
784 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
787 memset(rxq
->rx_skb
, 0, MWL8K_RX_DESCS
* sizeof(*rxq
->rx_skb
));
789 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
790 struct mwl8k_rx_desc
*rx_desc
;
793 rx_desc
= rxq
->rx_desc_area
+ i
;
794 nexti
= (i
+ 1) % MWL8K_RX_DESCS
;
796 rx_desc
->next_rx_desc_phys_addr
=
797 cpu_to_le32(rxq
->rx_desc_dma
798 + nexti
* sizeof(*rx_desc
));
799 rx_desc
->rx_ctrl
= MWL8K_RX_CTRL_OWNED_BY_HOST
;
805 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
807 struct mwl8k_priv
*priv
= hw
->priv
;
808 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
812 while (rxq
->rx_desc_count
< MWL8K_RX_DESCS
&& limit
--) {
816 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
820 rxq
->rx_desc_count
++;
823 rxq
->rx_tail
= (rx
+ 1) % MWL8K_RX_DESCS
;
825 rxq
->rx_desc_area
[rx
].pkt_phys_addr
=
826 cpu_to_le32(pci_map_single(priv
->pdev
, skb
->data
,
827 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
));
829 rxq
->rx_desc_area
[rx
].pkt_len
= cpu_to_le16(MWL8K_RX_MAXSZ
);
830 rxq
->rx_skb
[rx
] = skb
;
832 rxq
->rx_desc_area
[rx
].rx_ctrl
= 0;
840 /* Must be called only when the card's reception is completely halted */
841 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
843 struct mwl8k_priv
*priv
= hw
->priv
;
844 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
847 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
848 if (rxq
->rx_skb
[i
] != NULL
) {
851 addr
= le32_to_cpu(rxq
->rx_desc_area
[i
].pkt_phys_addr
);
852 pci_unmap_single(priv
->pdev
, addr
, MWL8K_RX_MAXSZ
,
854 kfree_skb(rxq
->rx_skb
[i
]);
855 rxq
->rx_skb
[i
] = NULL
;
862 pci_free_consistent(priv
->pdev
,
863 MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
),
864 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
865 rxq
->rx_desc_area
= NULL
;
870 * Scan a list of BSSIDs to process for finalize join.
871 * Allows for extension to process multiple BSSIDs.
874 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
876 return priv
->capture_beacon
&&
877 ieee80211_is_beacon(wh
->frame_control
) &&
878 !compare_ether_addr(wh
->addr3
, priv
->capture_bssid
);
881 static inline void mwl8k_save_beacon(struct ieee80211_hw
*hw
,
884 struct mwl8k_priv
*priv
= hw
->priv
;
886 priv
->capture_beacon
= false;
887 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
890 * Use GFP_ATOMIC as rxq_process is called from
891 * the primary interrupt handler, memory allocation call
894 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
895 if (priv
->beacon_skb
!= NULL
)
896 ieee80211_queue_work(hw
, &priv
->finalize_join_worker
);
899 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
901 struct mwl8k_priv
*priv
= hw
->priv
;
902 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
906 while (rxq
->rx_desc_count
&& limit
--) {
907 struct mwl8k_rx_desc
*rx_desc
;
909 struct ieee80211_rx_status status
;
911 struct ieee80211_hdr
*wh
;
913 rx_desc
= rxq
->rx_desc_area
+ rxq
->rx_head
;
914 if (!(rx_desc
->rx_ctrl
& MWL8K_RX_CTRL_OWNED_BY_HOST
))
918 skb
= rxq
->rx_skb
[rxq
->rx_head
];
921 rxq
->rx_skb
[rxq
->rx_head
] = NULL
;
923 rxq
->rx_head
= (rxq
->rx_head
+ 1) % MWL8K_RX_DESCS
;
924 rxq
->rx_desc_count
--;
926 addr
= le32_to_cpu(rx_desc
->pkt_phys_addr
);
927 pci_unmap_single(priv
->pdev
, addr
,
928 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
930 skb_put(skb
, le16_to_cpu(rx_desc
->pkt_len
));
931 mwl8k_remove_dma_header(skb
);
933 wh
= (struct ieee80211_hdr
*)skb
->data
;
936 * Check for a pending join operation. Save a
937 * copy of the beacon and schedule a tasklet to
938 * send a FINALIZE_JOIN command to the firmware.
940 if (mwl8k_capture_bssid(priv
, wh
))
941 mwl8k_save_beacon(hw
, skb
);
943 memset(&status
, 0, sizeof(status
));
945 status
.signal
= -rx_desc
->rssi
;
946 status
.noise
= -rx_desc
->noise_level
;
947 status
.qual
= rx_desc
->link_quality
;
951 status
.band
= IEEE80211_BAND_2GHZ
;
952 status
.freq
= ieee80211_channel_to_frequency(rx_desc
->channel
);
953 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
954 ieee80211_rx_irqsafe(hw
, skb
);
964 * Packet transmission.
967 /* Transmit queue assignment. */
969 MWL8K_WME_AC_BK
= 0, /* background access */
970 MWL8K_WME_AC_BE
= 1, /* best effort access */
971 MWL8K_WME_AC_VI
= 2, /* video access */
972 MWL8K_WME_AC_VO
= 3, /* voice access */
975 /* Transmit packet ACK policy */
976 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
977 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
979 #define GET_TXQ(_ac) (\
980 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
981 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
982 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
985 #define MWL8K_TXD_STATUS_OK 0x00000001
986 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
987 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
988 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
989 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
991 struct mwl8k_tx_desc
{
996 __le32 pkt_phys_addr
;
998 __u8 dest_MAC_addr
[ETH_ALEN
];
999 __le32 next_tx_desc_phys_addr
;
1004 } __attribute__((packed
));
1006 #define MWL8K_TX_DESCS 128
1008 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1010 struct mwl8k_priv
*priv
= hw
->priv
;
1011 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1015 memset(&txq
->tx_stats
, 0, sizeof(struct ieee80211_tx_queue_stats
));
1016 txq
->tx_stats
.limit
= MWL8K_TX_DESCS
;
1020 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1023 pci_alloc_consistent(priv
->pdev
, size
, &txq
->tx_desc_dma
);
1024 if (txq
->tx_desc_area
== NULL
) {
1025 printk(KERN_ERR
"%s: failed to alloc TX descriptors\n",
1026 wiphy_name(hw
->wiphy
));
1029 memset(txq
->tx_desc_area
, 0, size
);
1031 txq
->tx_skb
= kmalloc(MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
),
1033 if (txq
->tx_skb
== NULL
) {
1034 printk(KERN_ERR
"%s: failed to alloc TX skbuff list\n",
1035 wiphy_name(hw
->wiphy
));
1036 pci_free_consistent(priv
->pdev
, size
,
1037 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1040 memset(txq
->tx_skb
, 0, MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
));
1042 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1043 struct mwl8k_tx_desc
*tx_desc
;
1046 tx_desc
= txq
->tx_desc_area
+ i
;
1047 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1049 tx_desc
->status
= 0;
1050 tx_desc
->next_tx_desc_phys_addr
=
1051 cpu_to_le32(txq
->tx_desc_dma
+
1052 nexti
* sizeof(*tx_desc
));
1058 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1060 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1061 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1062 iowrite32(MWL8K_H2A_INT_DUMMY
,
1063 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1064 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1067 struct mwl8k_txq_info
{
1076 static int mwl8k_scan_tx_ring(struct mwl8k_priv
*priv
,
1077 struct mwl8k_txq_info
*txinfo
)
1079 int count
, desc
, status
;
1080 struct mwl8k_tx_queue
*txq
;
1081 struct mwl8k_tx_desc
*tx_desc
;
1084 memset(txinfo
, 0, MWL8K_TX_QUEUES
* sizeof(struct mwl8k_txq_info
));
1086 for (count
= 0; count
< MWL8K_TX_QUEUES
; count
++) {
1087 txq
= priv
->txq
+ count
;
1088 txinfo
[count
].len
= txq
->tx_stats
.len
;
1089 txinfo
[count
].head
= txq
->tx_head
;
1090 txinfo
[count
].tail
= txq
->tx_tail
;
1091 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1092 tx_desc
= txq
->tx_desc_area
+ desc
;
1093 status
= le32_to_cpu(tx_desc
->status
);
1095 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1096 txinfo
[count
].fw_owned
++;
1098 txinfo
[count
].drv_owned
++;
1100 if (tx_desc
->pkt_len
== 0)
1101 txinfo
[count
].unused
++;
1109 * Must be called with priv->fw_mutex held and tx queues stopped.
1111 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
)
1113 struct mwl8k_priv
*priv
= hw
->priv
;
1114 DECLARE_COMPLETION_ONSTACK(tx_wait
);
1116 unsigned long timeout
;
1120 spin_lock_bh(&priv
->tx_lock
);
1121 count
= priv
->pending_tx_pkts
;
1123 priv
->tx_wait
= &tx_wait
;
1124 spin_unlock_bh(&priv
->tx_lock
);
1127 struct mwl8k_txq_info txinfo
[MWL8K_TX_QUEUES
];
1131 timeout
= wait_for_completion_timeout(&tx_wait
,
1132 msecs_to_jiffies(5000));
1136 spin_lock_bh(&priv
->tx_lock
);
1137 priv
->tx_wait
= NULL
;
1138 newcount
= priv
->pending_tx_pkts
;
1139 mwl8k_scan_tx_ring(priv
, txinfo
);
1140 spin_unlock_bh(&priv
->tx_lock
);
1142 printk(KERN_ERR
"%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
1143 __func__
, __LINE__
, count
, newcount
);
1145 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++)
1146 printk(KERN_ERR
"TXQ:%u L:%u H:%u T:%u FW:%u "
1152 txinfo
[index
].fw_owned
,
1153 txinfo
[index
].drv_owned
,
1154 txinfo
[index
].unused
);
1162 #define MWL8K_TXD_SUCCESS(status) \
1163 ((status) & (MWL8K_TXD_STATUS_OK | \
1164 MWL8K_TXD_STATUS_OK_RETRY | \
1165 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1167 static void mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int force
)
1169 struct mwl8k_priv
*priv
= hw
->priv
;
1170 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1173 while (txq
->tx_stats
.len
> 0) {
1175 struct mwl8k_tx_desc
*tx_desc
;
1178 struct sk_buff
*skb
;
1179 struct ieee80211_tx_info
*info
;
1183 tx_desc
= txq
->tx_desc_area
+ tx
;
1185 status
= le32_to_cpu(tx_desc
->status
);
1187 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1191 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1194 txq
->tx_head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1195 BUG_ON(txq
->tx_stats
.len
== 0);
1196 txq
->tx_stats
.len
--;
1197 priv
->pending_tx_pkts
--;
1199 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1200 size
= le16_to_cpu(tx_desc
->pkt_len
);
1201 skb
= txq
->tx_skb
[tx
];
1202 txq
->tx_skb
[tx
] = NULL
;
1204 BUG_ON(skb
== NULL
);
1205 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1207 mwl8k_remove_dma_header(skb
);
1209 /* Mark descriptor as unused */
1210 tx_desc
->pkt_phys_addr
= 0;
1211 tx_desc
->pkt_len
= 0;
1213 info
= IEEE80211_SKB_CB(skb
);
1214 ieee80211_tx_info_clear_status(info
);
1215 if (MWL8K_TXD_SUCCESS(status
))
1216 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1218 ieee80211_tx_status_irqsafe(hw
, skb
);
1223 if (wake
&& priv
->radio_on
&& !mutex_is_locked(&priv
->fw_mutex
))
1224 ieee80211_wake_queue(hw
, index
);
1227 /* must be called only when the card's transmit is completely halted */
1228 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1230 struct mwl8k_priv
*priv
= hw
->priv
;
1231 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1233 mwl8k_txq_reclaim(hw
, index
, 1);
1238 pci_free_consistent(priv
->pdev
,
1239 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1240 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1241 txq
->tx_desc_area
= NULL
;
1245 mwl8k_txq_xmit(struct ieee80211_hw
*hw
, int index
, struct sk_buff
*skb
)
1247 struct mwl8k_priv
*priv
= hw
->priv
;
1248 struct ieee80211_tx_info
*tx_info
;
1249 struct mwl8k_vif
*mwl8k_vif
;
1250 struct ieee80211_hdr
*wh
;
1251 struct mwl8k_tx_queue
*txq
;
1252 struct mwl8k_tx_desc
*tx
;
1258 wh
= (struct ieee80211_hdr
*)skb
->data
;
1259 if (ieee80211_is_data_qos(wh
->frame_control
))
1260 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1264 mwl8k_add_dma_header(skb
);
1265 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1267 tx_info
= IEEE80211_SKB_CB(skb
);
1268 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1270 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1271 u16 seqno
= mwl8k_vif
->seqno
;
1273 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1274 wh
->seq_ctrl
|= cpu_to_le16(seqno
<< 4);
1275 mwl8k_vif
->seqno
= seqno
++ % 4096;
1278 /* Setup firmware control bit fields for each frame type. */
1281 if (ieee80211_is_mgmt(wh
->frame_control
) ||
1282 ieee80211_is_ctl(wh
->frame_control
)) {
1284 qos
= mwl8k_qos_setbit_eosp(qos
);
1285 /* Set Queue size to unspecified */
1286 qos
= mwl8k_qos_setbit_qlen(qos
, 0xff);
1287 } else if (ieee80211_is_data(wh
->frame_control
)) {
1289 if (is_multicast_ether_addr(wh
->addr1
))
1290 txstatus
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1292 /* Send pkt in an aggregate if AMPDU frame. */
1293 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1294 qos
= mwl8k_qos_setbit_ack(qos
,
1295 MWL8K_TXD_ACK_POLICY_BLOCKACK
);
1297 qos
= mwl8k_qos_setbit_ack(qos
,
1298 MWL8K_TXD_ACK_POLICY_NORMAL
);
1300 if (qos
& IEEE80211_QOS_CONTROL_A_MSDU_PRESENT
)
1301 qos
= mwl8k_qos_setbit_amsdu(qos
);
1304 dma
= pci_map_single(priv
->pdev
, skb
->data
,
1305 skb
->len
, PCI_DMA_TODEVICE
);
1307 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
1308 printk(KERN_DEBUG
"%s: failed to dma map skb, "
1309 "dropping TX frame.\n", wiphy_name(hw
->wiphy
));
1311 return NETDEV_TX_OK
;
1314 spin_lock_bh(&priv
->tx_lock
);
1316 txq
= priv
->txq
+ index
;
1318 BUG_ON(txq
->tx_skb
[txq
->tx_tail
] != NULL
);
1319 txq
->tx_skb
[txq
->tx_tail
] = skb
;
1321 tx
= txq
->tx_desc_area
+ txq
->tx_tail
;
1322 tx
->data_rate
= txdatarate
;
1323 tx
->tx_priority
= index
;
1324 tx
->qos_control
= cpu_to_le16(qos
);
1325 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
1326 tx
->pkt_len
= cpu_to_le16(skb
->len
);
1328 tx
->peer_id
= mwl8k_vif
->peer_id
;
1330 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
| txstatus
);
1332 txq
->tx_stats
.count
++;
1333 txq
->tx_stats
.len
++;
1334 priv
->pending_tx_pkts
++;
1337 if (txq
->tx_tail
== MWL8K_TX_DESCS
)
1340 if (txq
->tx_head
== txq
->tx_tail
)
1341 ieee80211_stop_queue(hw
, index
);
1343 mwl8k_tx_start(priv
);
1345 spin_unlock_bh(&priv
->tx_lock
);
1347 return NETDEV_TX_OK
;
1354 * We have the following requirements for issuing firmware commands:
1355 * - Some commands require that the packet transmit path is idle when
1356 * the command is issued. (For simplicity, we'll just quiesce the
1357 * transmit path for every command.)
1358 * - There are certain sequences of commands that need to be issued to
1359 * the hardware sequentially, with no other intervening commands.
1361 * This leads to an implementation of a "firmware lock" as a mutex that
1362 * can be taken recursively, and which is taken by both the low-level
1363 * command submission function (mwl8k_post_cmd) as well as any users of
1364 * that function that require issuing of an atomic sequence of commands,
1365 * and quiesces the transmit path whenever it's taken.
1367 static int mwl8k_fw_lock(struct ieee80211_hw
*hw
)
1369 struct mwl8k_priv
*priv
= hw
->priv
;
1371 if (priv
->fw_mutex_owner
!= current
) {
1374 mutex_lock(&priv
->fw_mutex
);
1375 ieee80211_stop_queues(hw
);
1377 rc
= mwl8k_tx_wait_empty(hw
);
1379 ieee80211_wake_queues(hw
);
1380 mutex_unlock(&priv
->fw_mutex
);
1385 priv
->fw_mutex_owner
= current
;
1388 priv
->fw_mutex_depth
++;
1393 static void mwl8k_fw_unlock(struct ieee80211_hw
*hw
)
1395 struct mwl8k_priv
*priv
= hw
->priv
;
1397 if (!--priv
->fw_mutex_depth
) {
1398 ieee80211_wake_queues(hw
);
1399 priv
->fw_mutex_owner
= NULL
;
1400 mutex_unlock(&priv
->fw_mutex
);
1406 * Command processing.
1409 /* Timeout firmware commands after 2000ms */
1410 #define MWL8K_CMD_TIMEOUT_MS 2000
1412 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
1414 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1415 struct mwl8k_priv
*priv
= hw
->priv
;
1416 void __iomem
*regs
= priv
->regs
;
1417 dma_addr_t dma_addr
;
1418 unsigned int dma_size
;
1420 unsigned long timeout
= 0;
1423 cmd
->result
= 0xffff;
1424 dma_size
= le16_to_cpu(cmd
->length
);
1425 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
1426 PCI_DMA_BIDIRECTIONAL
);
1427 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
1430 rc
= mwl8k_fw_lock(hw
);
1432 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1433 PCI_DMA_BIDIRECTIONAL
);
1437 priv
->hostcmd_wait
= &cmd_wait
;
1438 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
1439 iowrite32(MWL8K_H2A_INT_DOORBELL
,
1440 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1441 iowrite32(MWL8K_H2A_INT_DUMMY
,
1442 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1444 timeout
= wait_for_completion_timeout(&cmd_wait
,
1445 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
1447 priv
->hostcmd_wait
= NULL
;
1449 mwl8k_fw_unlock(hw
);
1451 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1452 PCI_DMA_BIDIRECTIONAL
);
1455 printk(KERN_ERR
"%s: Command %s timeout after %u ms\n",
1456 wiphy_name(hw
->wiphy
),
1457 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1458 MWL8K_CMD_TIMEOUT_MS
);
1461 rc
= cmd
->result
? -EINVAL
: 0;
1463 printk(KERN_ERR
"%s: Command %s error 0x%x\n",
1464 wiphy_name(hw
->wiphy
),
1465 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1466 le16_to_cpu(cmd
->result
));
1475 struct mwl8k_cmd_get_hw_spec
{
1476 struct mwl8k_cmd_pkt header
;
1478 __u8 host_interface
;
1480 __u8 perm_addr
[ETH_ALEN
];
1485 __u8 mcs_bitmap
[16];
1486 __le32 rx_queue_ptr
;
1487 __le32 num_tx_queues
;
1488 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1490 __le32 num_tx_desc_per_queue
;
1491 __le32 total_rx_desc
;
1492 } __attribute__((packed
));
1494 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw
*hw
)
1496 struct mwl8k_priv
*priv
= hw
->priv
;
1497 struct mwl8k_cmd_get_hw_spec
*cmd
;
1501 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1505 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1506 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1508 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1509 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1510 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rx_desc_dma
);
1511 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1512 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1513 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].tx_desc_dma
);
1514 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1515 cmd
->total_rx_desc
= cpu_to_le32(MWL8K_RX_DESCS
);
1517 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1520 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1521 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1522 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1523 priv
->hw_rev
= cmd
->hw_rev
;
1531 * CMD_MAC_MULTICAST_ADR.
1533 struct mwl8k_cmd_mac_multicast_adr
{
1534 struct mwl8k_cmd_pkt header
;
1537 __u8 addr
[0][ETH_ALEN
];
1540 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
1541 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
1542 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1543 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
1545 static struct mwl8k_cmd_pkt
*
1546 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
,
1547 int mc_count
, struct dev_addr_list
*mclist
)
1549 struct mwl8k_priv
*priv
= hw
->priv
;
1550 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
1555 if (mc_count
> priv
->num_mcaddrs
) {
1560 size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
1562 cmd
= kzalloc(size
, GFP_ATOMIC
);
1566 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
1567 cmd
->header
.length
= cpu_to_le16(size
);
1568 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED
|
1569 MWL8K_ENABLE_RX_BROADCAST
);
1572 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST
);
1573 } else if (mc_count
) {
1576 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
1577 cmd
->numaddr
= cpu_to_le16(mc_count
);
1578 for (i
= 0; i
< mc_count
&& mclist
; i
++) {
1579 if (mclist
->da_addrlen
!= ETH_ALEN
) {
1583 memcpy(cmd
->addr
[i
], mclist
->da_addr
, ETH_ALEN
);
1584 mclist
= mclist
->next
;
1588 return &cmd
->header
;
1592 * CMD_802_11_GET_STAT.
1594 struct mwl8k_cmd_802_11_get_stat
{
1595 struct mwl8k_cmd_pkt header
;
1597 } __attribute__((packed
));
1599 #define MWL8K_STAT_ACK_FAILURE 9
1600 #define MWL8K_STAT_RTS_FAILURE 12
1601 #define MWL8K_STAT_FCS_ERROR 24
1602 #define MWL8K_STAT_RTS_SUCCESS 11
1604 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw
*hw
,
1605 struct ieee80211_low_level_stats
*stats
)
1607 struct mwl8k_cmd_802_11_get_stat
*cmd
;
1610 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1614 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
1615 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1617 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1619 stats
->dot11ACKFailureCount
=
1620 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
1621 stats
->dot11RTSFailureCount
=
1622 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
1623 stats
->dot11FCSErrorCount
=
1624 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
1625 stats
->dot11RTSSuccessCount
=
1626 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
1634 * CMD_802_11_RADIO_CONTROL.
1636 struct mwl8k_cmd_802_11_radio_control
{
1637 struct mwl8k_cmd_pkt header
;
1641 } __attribute__((packed
));
1644 mwl8k_cmd_802_11_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
1646 struct mwl8k_priv
*priv
= hw
->priv
;
1647 struct mwl8k_cmd_802_11_radio_control
*cmd
;
1650 if (enable
== priv
->radio_on
&& !force
)
1653 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1657 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
1658 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1659 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1660 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
1661 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
1663 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1667 priv
->radio_on
= enable
;
1672 static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw
*hw
)
1674 return mwl8k_cmd_802_11_radio_control(hw
, 0, 0);
1677 static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw
*hw
)
1679 return mwl8k_cmd_802_11_radio_control(hw
, 1, 0);
1683 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
1685 struct mwl8k_priv
*priv
;
1687 if (hw
== NULL
|| hw
->priv
== NULL
)
1691 priv
->radio_short_preamble
= short_preamble
;
1693 return mwl8k_cmd_802_11_radio_control(hw
, 1, 1);
1697 * CMD_802_11_RF_TX_POWER.
1699 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1701 struct mwl8k_cmd_802_11_rf_tx_power
{
1702 struct mwl8k_cmd_pkt header
;
1704 __le16 support_level
;
1705 __le16 current_level
;
1707 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
1708 } __attribute__((packed
));
1710 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
1712 struct mwl8k_cmd_802_11_rf_tx_power
*cmd
;
1715 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1719 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
1720 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1721 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1722 cmd
->support_level
= cpu_to_le16(dBm
);
1724 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1733 struct mwl8k_cmd_set_pre_scan
{
1734 struct mwl8k_cmd_pkt header
;
1735 } __attribute__((packed
));
1737 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
1739 struct mwl8k_cmd_set_pre_scan
*cmd
;
1742 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1746 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
1747 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1749 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1756 * CMD_SET_POST_SCAN.
1758 struct mwl8k_cmd_set_post_scan
{
1759 struct mwl8k_cmd_pkt header
;
1761 __u8 bssid
[ETH_ALEN
];
1762 } __attribute__((packed
));
1765 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, __u8
*mac
)
1767 struct mwl8k_cmd_set_post_scan
*cmd
;
1770 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1774 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
1775 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1777 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
1779 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1786 * CMD_SET_RF_CHANNEL.
1788 struct mwl8k_cmd_set_rf_channel
{
1789 struct mwl8k_cmd_pkt header
;
1791 __u8 current_channel
;
1792 __le32 channel_flags
;
1793 } __attribute__((packed
));
1795 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
1796 struct ieee80211_channel
*channel
)
1798 struct mwl8k_cmd_set_rf_channel
*cmd
;
1801 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1805 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
1806 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1807 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1808 cmd
->current_channel
= channel
->hw_value
;
1809 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1810 cmd
->channel_flags
= cpu_to_le32(0x00000081);
1812 cmd
->channel_flags
= cpu_to_le32(0x00000000);
1814 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1823 struct mwl8k_cmd_set_slot
{
1824 struct mwl8k_cmd_pkt header
;
1827 } __attribute__((packed
));
1829 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, bool short_slot_time
)
1831 struct mwl8k_cmd_set_slot
*cmd
;
1834 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1838 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
1839 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1840 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1841 cmd
->short_slot
= short_slot_time
;
1843 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1852 struct mwl8k_cmd_mimo_config
{
1853 struct mwl8k_cmd_pkt header
;
1855 __u8 rx_antenna_map
;
1856 __u8 tx_antenna_map
;
1857 } __attribute__((packed
));
1859 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
1861 struct mwl8k_cmd_mimo_config
*cmd
;
1864 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1868 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
1869 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1870 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
1871 cmd
->rx_antenna_map
= rx
;
1872 cmd
->tx_antenna_map
= tx
;
1874 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1881 * CMD_ENABLE_SNIFFER.
1883 struct mwl8k_cmd_enable_sniffer
{
1884 struct mwl8k_cmd_pkt header
;
1886 } __attribute__((packed
));
1888 static int mwl8k_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
1890 struct mwl8k_cmd_enable_sniffer
*cmd
;
1893 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1897 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
1898 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1899 cmd
->action
= cpu_to_le32(!!enable
);
1901 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1908 * CMD_SET_RATEADAPT_MODE.
1910 struct mwl8k_cmd_set_rate_adapt_mode
{
1911 struct mwl8k_cmd_pkt header
;
1914 } __attribute__((packed
));
1916 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw
*hw
, __u16 mode
)
1918 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
1921 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1925 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
1926 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1927 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1928 cmd
->mode
= cpu_to_le16(mode
);
1930 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1939 struct mwl8k_cmd_set_wmm
{
1940 struct mwl8k_cmd_pkt header
;
1942 } __attribute__((packed
));
1944 static int mwl8k_set_wmm(struct ieee80211_hw
*hw
, bool enable
)
1946 struct mwl8k_priv
*priv
= hw
->priv
;
1947 struct mwl8k_cmd_set_wmm
*cmd
;
1950 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1954 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
1955 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1956 cmd
->action
= cpu_to_le16(!!enable
);
1958 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1962 priv
->wmm_enabled
= enable
;
1968 * CMD_SET_RTS_THRESHOLD.
1970 struct mwl8k_cmd_rts_threshold
{
1971 struct mwl8k_cmd_pkt header
;
1974 } __attribute__((packed
));
1976 static int mwl8k_rts_threshold(struct ieee80211_hw
*hw
,
1977 u16 action
, u16 threshold
)
1979 struct mwl8k_cmd_rts_threshold
*cmd
;
1982 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1986 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
1987 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1988 cmd
->action
= cpu_to_le16(action
);
1989 cmd
->threshold
= cpu_to_le16(threshold
);
1991 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1998 * CMD_SET_EDCA_PARAMS.
2000 struct mwl8k_cmd_set_edca_params
{
2001 struct mwl8k_cmd_pkt header
;
2003 /* See MWL8K_SET_EDCA_XXX below */
2006 /* TX opportunity in units of 32 us */
2009 /* Log exponent of max contention period: 0...15*/
2012 /* Log exponent of min contention period: 0...15 */
2015 /* Adaptive interframe spacing in units of 32us */
2018 /* TX queue to configure */
2020 } __attribute__((packed
));
2022 #define MWL8K_SET_EDCA_CW 0x01
2023 #define MWL8K_SET_EDCA_TXOP 0x02
2024 #define MWL8K_SET_EDCA_AIFS 0x04
2026 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2027 MWL8K_SET_EDCA_TXOP | \
2028 MWL8K_SET_EDCA_AIFS)
2031 mwl8k_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
2032 __u16 cw_min
, __u16 cw_max
,
2033 __u8 aifs
, __u16 txop
)
2035 struct mwl8k_cmd_set_edca_params
*cmd
;
2038 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2042 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
2043 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2044 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
2045 cmd
->txop
= cpu_to_le16(txop
);
2046 cmd
->log_cw_max
= (u8
)ilog2(cw_max
+ 1);
2047 cmd
->log_cw_min
= (u8
)ilog2(cw_min
+ 1);
2051 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2058 * CMD_FINALIZE_JOIN.
2061 /* FJ beacon buffer size is compiled into the firmware. */
2062 #define MWL8K_FJ_BEACON_MAXLEN 128
2064 struct mwl8k_cmd_finalize_join
{
2065 struct mwl8k_cmd_pkt header
;
2066 __le32 sleep_interval
; /* Number of beacon periods to sleep */
2067 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
2068 } __attribute__((packed
));
2070 static int mwl8k_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
2071 __u16 framelen
, __u16 dtim
)
2073 struct mwl8k_cmd_finalize_join
*cmd
;
2074 struct ieee80211_mgmt
*payload
= frame
;
2082 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2086 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
2087 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2088 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
2090 hdrlen
= ieee80211_hdrlen(payload
->frame_control
);
2092 payload_len
= framelen
> hdrlen
? framelen
- hdrlen
: 0;
2094 /* XXX TBD Might just have to abort and return an error */
2095 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2096 printk(KERN_ERR
"%s(): WARNING: Incomplete beacon "
2097 "sent to firmware. Sz=%u MAX=%u\n", __func__
,
2098 payload_len
, MWL8K_FJ_BEACON_MAXLEN
);
2100 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2101 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
2103 if (payload
&& payload_len
)
2104 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
2106 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2114 struct mwl8k_cmd_update_sta_db
{
2115 struct mwl8k_cmd_pkt header
;
2117 /* See STADB_ACTION_TYPE */
2120 /* Peer MAC address */
2121 __u8 peer_addr
[ETH_ALEN
];
2125 /* Peer info - valid during add/update. */
2126 struct peer_capability_info peer_info
;
2127 } __attribute__((packed
));
2129 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw
*hw
,
2130 struct ieee80211_vif
*vif
, __u32 action
)
2132 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2133 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2134 struct mwl8k_cmd_update_sta_db
*cmd
;
2135 struct peer_capability_info
*peer_info
;
2136 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2140 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2144 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
2145 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2147 cmd
->action
= cpu_to_le32(action
);
2148 peer_info
= &cmd
->peer_info
;
2149 memcpy(cmd
->peer_addr
, mv_vif
->bssid
, ETH_ALEN
);
2152 case MWL8K_STA_DB_ADD_ENTRY
:
2153 case MWL8K_STA_DB_MODIFY_ENTRY
:
2154 /* Build peer_info block */
2155 peer_info
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
2156 peer_info
->basic_caps
= cpu_to_le16(info
->assoc_capability
);
2157 peer_info
->interop
= 1;
2158 peer_info
->amsdu_enabled
= 0;
2160 rates
= peer_info
->legacy_rates
;
2161 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2162 rates
[count
] = bitrates
[count
].hw_value
;
2164 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2166 mv_vif
->peer_id
= peer_info
->station_id
;
2170 case MWL8K_STA_DB_DEL_ENTRY
:
2171 case MWL8K_STA_DB_FLUSH
:
2173 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2175 mv_vif
->peer_id
= 0;
2186 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2188 #define MWL8K_FRAME_PROT_DISABLED 0x00
2189 #define MWL8K_FRAME_PROT_11G 0x07
2190 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2191 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2193 struct mwl8k_cmd_update_set_aid
{
2194 struct mwl8k_cmd_pkt header
;
2197 /* AP's MAC address (BSSID) */
2198 __u8 bssid
[ETH_ALEN
];
2199 __le16 protection_mode
;
2200 __u8 supp_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2201 } __attribute__((packed
));
2203 static int mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
2204 struct ieee80211_vif
*vif
)
2206 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2207 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2208 struct mwl8k_cmd_update_set_aid
*cmd
;
2209 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2214 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2218 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
2219 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2220 cmd
->aid
= cpu_to_le16(info
->aid
);
2222 memcpy(cmd
->bssid
, mv_vif
->bssid
, ETH_ALEN
);
2224 if (info
->use_cts_prot
) {
2225 prot_mode
= MWL8K_FRAME_PROT_11G
;
2227 switch (info
->ht_operation_mode
&
2228 IEEE80211_HT_OP_MODE_PROTECTION
) {
2229 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
2230 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
2232 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
2233 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
2236 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
2240 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
2242 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2243 cmd
->supp_rates
[count
] = bitrates
[count
].hw_value
;
2245 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2254 struct mwl8k_cmd_update_rateset
{
2255 struct mwl8k_cmd_pkt header
;
2256 __u8 legacy_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2258 /* Bitmap for supported MCS codes. */
2259 __u8 mcs_set
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2260 __u8 reserved
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2261 } __attribute__((packed
));
2263 static int mwl8k_update_rateset(struct ieee80211_hw
*hw
,
2264 struct ieee80211_vif
*vif
)
2266 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2267 struct mwl8k_cmd_update_rateset
*cmd
;
2268 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2272 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2276 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
2277 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2279 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2280 cmd
->legacy_rates
[count
] = bitrates
[count
].hw_value
;
2282 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2289 * CMD_USE_FIXED_RATE.
2291 #define MWL8K_RATE_TABLE_SIZE 8
2292 #define MWL8K_UCAST_RATE 0
2293 #define MWL8K_USE_AUTO_RATE 0x0002
2295 struct mwl8k_rate_entry
{
2296 /* Set to 1 if HT rate, 0 if legacy. */
2299 /* Set to 1 to use retry_count field. */
2300 __le32 enable_retry
;
2302 /* Specified legacy rate or MCS. */
2305 /* Number of allowed retries. */
2307 } __attribute__((packed
));
2309 struct mwl8k_rate_table
{
2310 /* 1 to allow specified rate and below */
2311 __le32 allow_rate_drop
;
2313 struct mwl8k_rate_entry rate_entry
[MWL8K_RATE_TABLE_SIZE
];
2314 } __attribute__((packed
));
2316 struct mwl8k_cmd_use_fixed_rate
{
2317 struct mwl8k_cmd_pkt header
;
2319 struct mwl8k_rate_table rate_table
;
2321 /* Unicast, Broadcast or Multicast */
2325 } __attribute__((packed
));
2327 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw
*hw
,
2328 u32 action
, u32 rate_type
, struct mwl8k_rate_table
*rate_table
)
2330 struct mwl8k_cmd_use_fixed_rate
*cmd
;
2334 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2338 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2339 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2341 cmd
->action
= cpu_to_le32(action
);
2342 cmd
->rate_type
= cpu_to_le32(rate_type
);
2344 if (rate_table
!= NULL
) {
2346 * Copy over each field manually so that endian
2347 * conversion can be done.
2349 cmd
->rate_table
.allow_rate_drop
=
2350 cpu_to_le32(rate_table
->allow_rate_drop
);
2351 cmd
->rate_table
.num_rates
=
2352 cpu_to_le32(rate_table
->num_rates
);
2354 for (count
= 0; count
< rate_table
->num_rates
; count
++) {
2355 struct mwl8k_rate_entry
*dst
=
2356 &cmd
->rate_table
.rate_entry
[count
];
2357 struct mwl8k_rate_entry
*src
=
2358 &rate_table
->rate_entry
[count
];
2360 dst
->is_ht_rate
= cpu_to_le32(src
->is_ht_rate
);
2361 dst
->enable_retry
= cpu_to_le32(src
->enable_retry
);
2362 dst
->rate
= cpu_to_le32(src
->rate
);
2363 dst
->retry_count
= cpu_to_le32(src
->retry_count
);
2367 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2375 * Interrupt handling.
2377 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
2379 struct ieee80211_hw
*hw
= dev_id
;
2380 struct mwl8k_priv
*priv
= hw
->priv
;
2383 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2384 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2389 if (status
& MWL8K_A2H_INT_TX_DONE
)
2390 tasklet_schedule(&priv
->tx_reclaim_task
);
2392 if (status
& MWL8K_A2H_INT_RX_READY
) {
2393 while (rxq_process(hw
, 0, 1))
2394 rxq_refill(hw
, 0, 1);
2397 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
2398 if (priv
->hostcmd_wait
!= NULL
)
2399 complete(priv
->hostcmd_wait
);
2402 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
2403 if (!mutex_is_locked(&priv
->fw_mutex
) &&
2404 priv
->radio_on
&& priv
->pending_tx_pkts
)
2405 mwl8k_tx_start(priv
);
2413 * Core driver operations.
2415 static int mwl8k_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2417 struct mwl8k_priv
*priv
= hw
->priv
;
2418 int index
= skb_get_queue_mapping(skb
);
2421 if (priv
->current_channel
== NULL
) {
2422 printk(KERN_DEBUG
"%s: dropped TX frame since radio "
2423 "disabled\n", wiphy_name(hw
->wiphy
));
2425 return NETDEV_TX_OK
;
2428 rc
= mwl8k_txq_xmit(hw
, index
, skb
);
2433 static int mwl8k_start(struct ieee80211_hw
*hw
)
2435 struct mwl8k_priv
*priv
= hw
->priv
;
2438 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
2439 IRQF_SHARED
, MWL8K_NAME
, hw
);
2441 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
2442 wiphy_name(hw
->wiphy
));
2446 /* Enable tx reclaim tasklet */
2447 tasklet_enable(&priv
->tx_reclaim_task
);
2449 /* Enable interrupts */
2450 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2452 rc
= mwl8k_fw_lock(hw
);
2454 rc
= mwl8k_cmd_802_11_radio_enable(hw
);
2457 rc
= mwl8k_cmd_set_pre_scan(hw
);
2460 rc
= mwl8k_cmd_set_post_scan(hw
,
2461 "\x00\x00\x00\x00\x00\x00");
2464 rc
= mwl8k_cmd_setrateadaptmode(hw
, 0);
2467 rc
= mwl8k_set_wmm(hw
, 0);
2470 rc
= mwl8k_enable_sniffer(hw
, 0);
2472 mwl8k_fw_unlock(hw
);
2476 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2477 free_irq(priv
->pdev
->irq
, hw
);
2478 tasklet_disable(&priv
->tx_reclaim_task
);
2484 static void mwl8k_stop(struct ieee80211_hw
*hw
)
2486 struct mwl8k_priv
*priv
= hw
->priv
;
2489 mwl8k_cmd_802_11_radio_disable(hw
);
2491 ieee80211_stop_queues(hw
);
2493 /* Disable interrupts */
2494 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2495 free_irq(priv
->pdev
->irq
, hw
);
2497 /* Stop finalize join worker */
2498 cancel_work_sync(&priv
->finalize_join_worker
);
2499 if (priv
->beacon_skb
!= NULL
)
2500 dev_kfree_skb(priv
->beacon_skb
);
2502 /* Stop tx reclaim tasklet */
2503 tasklet_disable(&priv
->tx_reclaim_task
);
2505 /* Return all skbs to mac80211 */
2506 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2507 mwl8k_txq_reclaim(hw
, i
, 1);
2510 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
2511 struct ieee80211_if_init_conf
*conf
)
2513 struct mwl8k_priv
*priv
= hw
->priv
;
2514 struct mwl8k_vif
*mwl8k_vif
;
2517 * We only support one active interface at a time.
2519 if (priv
->vif
!= NULL
)
2523 * We only support managed interfaces for now.
2525 if (conf
->type
!= NL80211_IFTYPE_STATION
)
2528 /* Clean out driver private area */
2529 mwl8k_vif
= MWL8K_VIF(conf
->vif
);
2530 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
2532 /* Save the mac address */
2533 memcpy(mwl8k_vif
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
2535 /* Back pointer to parent config block */
2536 mwl8k_vif
->priv
= priv
;
2538 /* Setup initial PHY parameters */
2539 memcpy(mwl8k_vif
->legacy_rates
,
2540 priv
->rates
, sizeof(mwl8k_vif
->legacy_rates
));
2541 mwl8k_vif
->legacy_nrates
= ARRAY_SIZE(priv
->rates
);
2543 /* Set Initial sequence number to zero */
2544 mwl8k_vif
->seqno
= 0;
2546 priv
->vif
= conf
->vif
;
2547 priv
->current_channel
= NULL
;
2552 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
2553 struct ieee80211_if_init_conf
*conf
)
2555 struct mwl8k_priv
*priv
= hw
->priv
;
2557 if (priv
->vif
== NULL
)
2563 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
2565 struct ieee80211_conf
*conf
= &hw
->conf
;
2566 struct mwl8k_priv
*priv
= hw
->priv
;
2569 if (conf
->flags
& IEEE80211_CONF_IDLE
) {
2570 mwl8k_cmd_802_11_radio_disable(hw
);
2571 priv
->current_channel
= NULL
;
2575 rc
= mwl8k_fw_lock(hw
);
2579 rc
= mwl8k_cmd_802_11_radio_enable(hw
);
2583 rc
= mwl8k_cmd_set_rf_channel(hw
, conf
->channel
);
2587 priv
->current_channel
= conf
->channel
;
2589 if (conf
->power_level
> 18)
2590 conf
->power_level
= 18;
2591 rc
= mwl8k_cmd_802_11_rf_tx_power(hw
, conf
->power_level
);
2595 if (mwl8k_cmd_mimo_config(hw
, 0x7, 0x7))
2599 mwl8k_fw_unlock(hw
);
2604 static void mwl8k_bss_info_changed(struct ieee80211_hw
*hw
,
2605 struct ieee80211_vif
*vif
,
2606 struct ieee80211_bss_conf
*info
,
2609 struct mwl8k_priv
*priv
= hw
->priv
;
2610 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
2613 if (changed
& BSS_CHANGED_BSSID
)
2614 memcpy(mwl8k_vif
->bssid
, info
->bssid
, ETH_ALEN
);
2616 if ((changed
& BSS_CHANGED_ASSOC
) == 0)
2619 priv
->capture_beacon
= false;
2621 rc
= mwl8k_fw_lock(hw
);
2626 memcpy(&mwl8k_vif
->bss_info
, info
,
2627 sizeof(struct ieee80211_bss_conf
));
2630 rc
= mwl8k_update_rateset(hw
, vif
);
2634 /* Turn on rate adaptation */
2635 rc
= mwl8k_cmd_use_fixed_rate(hw
, MWL8K_USE_AUTO_RATE
,
2636 MWL8K_UCAST_RATE
, NULL
);
2640 /* Set radio preamble */
2641 rc
= mwl8k_set_radio_preamble(hw
, info
->use_short_preamble
);
2646 rc
= mwl8k_cmd_set_slot(hw
, info
->use_short_slot
);
2650 /* Update peer rate info */
2651 rc
= mwl8k_cmd_update_sta_db(hw
, vif
,
2652 MWL8K_STA_DB_MODIFY_ENTRY
);
2657 rc
= mwl8k_cmd_set_aid(hw
, vif
);
2662 * Finalize the join. Tell rx handler to process
2663 * next beacon from our BSSID.
2665 memcpy(priv
->capture_bssid
, mwl8k_vif
->bssid
, ETH_ALEN
);
2666 priv
->capture_beacon
= true;
2668 rc
= mwl8k_cmd_update_sta_db(hw
, vif
, MWL8K_STA_DB_DEL_ENTRY
);
2669 memset(&mwl8k_vif
->bss_info
, 0,
2670 sizeof(struct ieee80211_bss_conf
));
2671 memset(mwl8k_vif
->bssid
, 0, ETH_ALEN
);
2675 mwl8k_fw_unlock(hw
);
2678 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
2679 int mc_count
, struct dev_addr_list
*mclist
)
2681 struct mwl8k_cmd_pkt
*cmd
;
2683 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, mc_count
, mclist
);
2685 return (unsigned long)cmd
;
2688 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
2689 unsigned int changed_flags
,
2690 unsigned int *total_flags
,
2693 struct mwl8k_priv
*priv
= hw
->priv
;
2694 struct mwl8k_cmd_pkt
*multicast_adr_cmd
;
2696 /* Clear unsupported feature flags */
2697 *total_flags
&= FIF_BCN_PRBRESP_PROMISC
;
2699 if (mwl8k_fw_lock(hw
))
2702 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
2703 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
2704 mwl8k_cmd_set_pre_scan(hw
);
2708 bssid
= "\x00\x00\x00\x00\x00\x00";
2709 if (priv
->vif
!= NULL
)
2710 bssid
= MWL8K_VIF(priv
->vif
)->bssid
;
2712 mwl8k_cmd_set_post_scan(hw
, bssid
);
2716 multicast_adr_cmd
= (void *)(unsigned long)multicast
;
2717 if (multicast_adr_cmd
!= NULL
) {
2718 mwl8k_post_cmd(hw
, multicast_adr_cmd
);
2719 kfree(multicast_adr_cmd
);
2722 mwl8k_fw_unlock(hw
);
2725 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
2727 return mwl8k_rts_threshold(hw
, MWL8K_CMD_SET
, value
);
2730 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
2731 const struct ieee80211_tx_queue_params
*params
)
2733 struct mwl8k_priv
*priv
= hw
->priv
;
2736 rc
= mwl8k_fw_lock(hw
);
2738 if (!priv
->wmm_enabled
)
2739 rc
= mwl8k_set_wmm(hw
, 1);
2742 rc
= mwl8k_set_edca_params(hw
, queue
,
2748 mwl8k_fw_unlock(hw
);
2754 static int mwl8k_get_tx_stats(struct ieee80211_hw
*hw
,
2755 struct ieee80211_tx_queue_stats
*stats
)
2757 struct mwl8k_priv
*priv
= hw
->priv
;
2758 struct mwl8k_tx_queue
*txq
;
2761 spin_lock_bh(&priv
->tx_lock
);
2762 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++) {
2763 txq
= priv
->txq
+ index
;
2764 memcpy(&stats
[index
], &txq
->tx_stats
,
2765 sizeof(struct ieee80211_tx_queue_stats
));
2767 spin_unlock_bh(&priv
->tx_lock
);
2772 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
2773 struct ieee80211_low_level_stats
*stats
)
2775 return mwl8k_cmd_802_11_get_stat(hw
, stats
);
2778 static const struct ieee80211_ops mwl8k_ops
= {
2780 .start
= mwl8k_start
,
2782 .add_interface
= mwl8k_add_interface
,
2783 .remove_interface
= mwl8k_remove_interface
,
2784 .config
= mwl8k_config
,
2785 .bss_info_changed
= mwl8k_bss_info_changed
,
2786 .prepare_multicast
= mwl8k_prepare_multicast
,
2787 .configure_filter
= mwl8k_configure_filter
,
2788 .set_rts_threshold
= mwl8k_set_rts_threshold
,
2789 .conf_tx
= mwl8k_conf_tx
,
2790 .get_tx_stats
= mwl8k_get_tx_stats
,
2791 .get_stats
= mwl8k_get_stats
,
2794 static void mwl8k_tx_reclaim_handler(unsigned long data
)
2797 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*) data
;
2798 struct mwl8k_priv
*priv
= hw
->priv
;
2800 spin_lock_bh(&priv
->tx_lock
);
2801 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2802 mwl8k_txq_reclaim(hw
, i
, 0);
2804 if (priv
->tx_wait
!= NULL
&& !priv
->pending_tx_pkts
) {
2805 complete(priv
->tx_wait
);
2806 priv
->tx_wait
= NULL
;
2808 spin_unlock_bh(&priv
->tx_lock
);
2811 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
2813 struct mwl8k_priv
*priv
=
2814 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
2815 struct sk_buff
*skb
= priv
->beacon_skb
;
2816 u8 dtim
= MWL8K_VIF(priv
->vif
)->bss_info
.dtim_period
;
2818 mwl8k_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim
);
2821 priv
->beacon_skb
= NULL
;
2824 static int __devinit
mwl8k_probe(struct pci_dev
*pdev
,
2825 const struct pci_device_id
*id
)
2827 static int printed_version
= 0;
2828 struct ieee80211_hw
*hw
;
2829 struct mwl8k_priv
*priv
;
2833 if (!printed_version
) {
2834 printk(KERN_INFO
"%s version %s\n", MWL8K_DESC
, MWL8K_VERSION
);
2835 printed_version
= 1;
2838 rc
= pci_enable_device(pdev
);
2840 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
2845 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
2847 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
2852 pci_set_master(pdev
);
2854 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
2856 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
2864 priv
->wmm_enabled
= false;
2865 priv
->pending_tx_pkts
= 0;
2867 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
2868 pci_set_drvdata(pdev
, hw
);
2870 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
2871 if (priv
->regs
== NULL
) {
2872 printk(KERN_ERR
"%s: Cannot map device memory\n",
2873 wiphy_name(hw
->wiphy
));
2877 memcpy(priv
->channels
, mwl8k_channels
, sizeof(mwl8k_channels
));
2878 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
2879 priv
->band
.channels
= priv
->channels
;
2880 priv
->band
.n_channels
= ARRAY_SIZE(mwl8k_channels
);
2881 priv
->band
.bitrates
= priv
->rates
;
2882 priv
->band
.n_bitrates
= ARRAY_SIZE(mwl8k_rates
);
2883 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
2885 BUILD_BUG_ON(sizeof(priv
->rates
) != sizeof(mwl8k_rates
));
2886 memcpy(priv
->rates
, mwl8k_rates
, sizeof(mwl8k_rates
));
2889 * Extra headroom is the size of the required DMA header
2890 * minus the size of the smallest 802.11 frame (CTS frame).
2892 hw
->extra_tx_headroom
=
2893 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
2895 hw
->channel_change_time
= 10;
2897 hw
->queues
= MWL8K_TX_QUEUES
;
2899 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
2901 /* Set rssi and noise values to dBm */
2902 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
| IEEE80211_HW_NOISE_DBM
;
2903 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
2906 /* Set default radio state and preamble */
2908 priv
->radio_short_preamble
= 0;
2910 /* Finalize join worker */
2911 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
2913 /* TX reclaim tasklet */
2914 tasklet_init(&priv
->tx_reclaim_task
,
2915 mwl8k_tx_reclaim_handler
, (unsigned long)hw
);
2916 tasklet_disable(&priv
->tx_reclaim_task
);
2918 /* Power management cookie */
2919 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
2920 if (priv
->cookie
== NULL
)
2923 rc
= mwl8k_rxq_init(hw
, 0);
2926 rxq_refill(hw
, 0, INT_MAX
);
2928 mutex_init(&priv
->fw_mutex
);
2929 priv
->fw_mutex_owner
= NULL
;
2930 priv
->fw_mutex_depth
= 0;
2931 priv
->hostcmd_wait
= NULL
;
2933 spin_lock_init(&priv
->tx_lock
);
2935 priv
->tx_wait
= NULL
;
2937 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
2938 rc
= mwl8k_txq_init(hw
, i
);
2940 goto err_free_queues
;
2943 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2944 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2945 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
2946 iowrite32(0xffffffff, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
2948 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
2949 IRQF_SHARED
, MWL8K_NAME
, hw
);
2951 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
2952 wiphy_name(hw
->wiphy
));
2953 goto err_free_queues
;
2956 /* Reset firmware and hardware */
2957 mwl8k_hw_reset(priv
);
2959 /* Ask userland hotplug daemon for the device firmware */
2960 rc
= mwl8k_request_firmware(priv
, (u32
)id
->driver_data
);
2962 printk(KERN_ERR
"%s: Firmware files not found\n",
2963 wiphy_name(hw
->wiphy
));
2967 /* Load firmware into hardware */
2968 rc
= mwl8k_load_firmware(hw
);
2970 printk(KERN_ERR
"%s: Cannot start firmware\n",
2971 wiphy_name(hw
->wiphy
));
2972 goto err_stop_firmware
;
2975 /* Reclaim memory once firmware is successfully loaded */
2976 mwl8k_release_firmware(priv
);
2979 * Temporarily enable interrupts. Initial firmware host
2980 * commands use interrupts and avoids polling. Disable
2981 * interrupts when done.
2983 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2985 /* Get config data, mac addrs etc */
2986 rc
= mwl8k_cmd_get_hw_spec(hw
);
2988 printk(KERN_ERR
"%s: Cannot initialise firmware\n",
2989 wiphy_name(hw
->wiphy
));
2990 goto err_stop_firmware
;
2993 /* Turn radio off */
2994 rc
= mwl8k_cmd_802_11_radio_disable(hw
);
2996 printk(KERN_ERR
"%s: Cannot disable\n", wiphy_name(hw
->wiphy
));
2997 goto err_stop_firmware
;
3000 /* Disable interrupts */
3001 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3002 free_irq(priv
->pdev
->irq
, hw
);
3004 rc
= ieee80211_register_hw(hw
);
3006 printk(KERN_ERR
"%s: Cannot register device\n",
3007 wiphy_name(hw
->wiphy
));
3008 goto err_stop_firmware
;
3011 printk(KERN_INFO
"%s: 88w%u v%d, %pM, firmware version %u.%u.%u.%u\n",
3012 wiphy_name(hw
->wiphy
), priv
->part_num
, priv
->hw_rev
,
3013 hw
->wiphy
->perm_addr
,
3014 (priv
->fw_rev
>> 24) & 0xff, (priv
->fw_rev
>> 16) & 0xff,
3015 (priv
->fw_rev
>> 8) & 0xff, priv
->fw_rev
& 0xff);
3020 mwl8k_hw_reset(priv
);
3021 mwl8k_release_firmware(priv
);
3024 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3025 free_irq(priv
->pdev
->irq
, hw
);
3028 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3029 mwl8k_txq_deinit(hw
, i
);
3030 mwl8k_rxq_deinit(hw
, 0);
3033 if (priv
->cookie
!= NULL
)
3034 pci_free_consistent(priv
->pdev
, 4,
3035 priv
->cookie
, priv
->cookie_dma
);
3037 if (priv
->regs
!= NULL
)
3038 pci_iounmap(pdev
, priv
->regs
);
3040 pci_set_drvdata(pdev
, NULL
);
3041 ieee80211_free_hw(hw
);
3044 pci_release_regions(pdev
);
3045 pci_disable_device(pdev
);
3050 static void __devexit
mwl8k_shutdown(struct pci_dev
*pdev
)
3052 printk(KERN_ERR
"===>%s(%u)\n", __func__
, __LINE__
);
3055 static void __devexit
mwl8k_remove(struct pci_dev
*pdev
)
3057 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
3058 struct mwl8k_priv
*priv
;
3065 ieee80211_stop_queues(hw
);
3067 ieee80211_unregister_hw(hw
);
3069 /* Remove tx reclaim tasklet */
3070 tasklet_kill(&priv
->tx_reclaim_task
);
3073 mwl8k_hw_reset(priv
);
3075 /* Return all skbs to mac80211 */
3076 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3077 mwl8k_txq_reclaim(hw
, i
, 1);
3079 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3080 mwl8k_txq_deinit(hw
, i
);
3082 mwl8k_rxq_deinit(hw
, 0);
3084 pci_free_consistent(priv
->pdev
, 4, priv
->cookie
, priv
->cookie_dma
);
3086 pci_iounmap(pdev
, priv
->regs
);
3087 pci_set_drvdata(pdev
, NULL
);
3088 ieee80211_free_hw(hw
);
3089 pci_release_regions(pdev
);
3090 pci_disable_device(pdev
);
3093 static struct pci_driver mwl8k_driver
= {
3095 .id_table
= mwl8k_table
,
3096 .probe
= mwl8k_probe
,
3097 .remove
= __devexit_p(mwl8k_remove
),
3098 .shutdown
= __devexit_p(mwl8k_shutdown
),
3101 static int __init
mwl8k_init(void)
3103 return pci_register_driver(&mwl8k_driver
);
3106 static void __exit
mwl8k_exit(void)
3108 pci_unregister_driver(&mwl8k_driver
);
3111 module_init(mwl8k_init
);
3112 module_exit(mwl8k_exit
);
3114 MODULE_DESCRIPTION(MWL8K_DESC
);
3115 MODULE_VERSION(MWL8K_VERSION
);
3116 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3117 MODULE_LICENSE("GPL");