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/sched.h>
16 #include <linux/spinlock.h>
17 #include <linux/list.h>
18 #include <linux/pci.h>
19 #include <linux/delay.h>
20 #include <linux/completion.h>
21 #include <linux/etherdevice.h>
22 #include <net/mac80211.h>
23 #include <linux/moduleparam.h>
24 #include <linux/firmware.h>
25 #include <linux/workqueue.h>
27 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
28 #define MWL8K_NAME KBUILD_MODNAME
29 #define MWL8K_VERSION "0.10"
31 static DEFINE_PCI_DEVICE_TABLE(mwl8k_table
) = {
32 { PCI_VDEVICE(MARVELL
, 0x2a2b), .driver_data
= 8687, },
33 { PCI_VDEVICE(MARVELL
, 0x2a30), .driver_data
= 8687, },
36 MODULE_DEVICE_TABLE(pci
, mwl8k_table
);
38 /* Register definitions */
39 #define MWL8K_HIU_GEN_PTR 0x00000c10
40 #define MWL8K_MODE_STA 0x0000005a
41 #define MWL8K_MODE_AP 0x000000a5
42 #define MWL8K_HIU_INT_CODE 0x00000c14
43 #define MWL8K_FWSTA_READY 0xf0f1f2f4
44 #define MWL8K_FWAP_READY 0xf1f2f4a5
45 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
46 #define MWL8K_HIU_SCRATCH 0x00000c40
48 /* Host->device communications */
49 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
50 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
51 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
52 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
53 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
54 #define MWL8K_H2A_INT_DUMMY (1 << 20)
55 #define MWL8K_H2A_INT_RESET (1 << 15)
56 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
57 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
59 /* Device->host communications */
60 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
61 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
62 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
63 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
64 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
65 #define MWL8K_A2H_INT_DUMMY (1 << 20)
66 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
67 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
68 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
69 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
70 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
71 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
72 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
73 #define MWL8K_A2H_INT_RX_READY (1 << 1)
74 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
76 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
77 MWL8K_A2H_INT_CHNL_SWITCHED | \
78 MWL8K_A2H_INT_QUEUE_EMPTY | \
79 MWL8K_A2H_INT_RADAR_DETECT | \
80 MWL8K_A2H_INT_RADIO_ON | \
81 MWL8K_A2H_INT_RADIO_OFF | \
82 MWL8K_A2H_INT_MAC_EVENT | \
83 MWL8K_A2H_INT_OPC_DONE | \
84 MWL8K_A2H_INT_RX_READY | \
85 MWL8K_A2H_INT_TX_DONE)
87 #define MWL8K_RX_QUEUES 1
88 #define MWL8K_TX_QUEUES 4
90 struct mwl8k_rx_queue
{
93 /* hw receives here */
96 /* refill descs here */
99 struct mwl8k_rx_desc
*rx_desc_area
;
100 dma_addr_t rx_desc_dma
;
101 struct sk_buff
**rx_skb
;
104 struct mwl8k_tx_queue
{
105 /* hw transmits here */
108 /* sw appends here */
111 struct ieee80211_tx_queue_stats tx_stats
;
112 struct mwl8k_tx_desc
*tx_desc_area
;
113 dma_addr_t tx_desc_dma
;
114 struct sk_buff
**tx_skb
;
117 /* Pointers to the firmware data and meta information about it. */
118 struct mwl8k_firmware
{
120 struct firmware
*ucode
;
122 /* Boot helper code */
123 struct firmware
*helper
;
128 struct ieee80211_hw
*hw
;
130 struct pci_dev
*pdev
;
132 /* firmware files and meta data */
133 struct mwl8k_firmware fw
;
136 /* firmware access */
137 struct mutex fw_mutex
;
138 struct task_struct
*fw_mutex_owner
;
140 struct completion
*hostcmd_wait
;
142 /* lock held over TX and TX reap */
145 /* TX quiesce completion, protected by fw_mutex and tx_lock */
146 struct completion
*tx_wait
;
148 struct ieee80211_vif
*vif
;
150 struct ieee80211_channel
*current_channel
;
152 /* power management status cookie from firmware */
154 dma_addr_t cookie_dma
;
161 * Running count of TX packets in flight, to avoid
162 * iterating over the transmit rings each time.
166 struct mwl8k_rx_queue rxq
[MWL8K_RX_QUEUES
];
167 struct mwl8k_tx_queue txq
[MWL8K_TX_QUEUES
];
170 struct ieee80211_supported_band band
;
171 struct ieee80211_channel channels
[14];
172 struct ieee80211_rate rates
[13];
175 bool radio_short_preamble
;
178 /* XXX need to convert this to handle multiple interfaces */
180 u8 capture_bssid
[ETH_ALEN
];
181 struct sk_buff
*beacon_skb
;
184 * This FJ worker has to be global as it is scheduled from the
185 * RX handler. At this point we don't know which interface it
186 * belongs to until the list of bssids waiting to complete join
189 struct work_struct finalize_join_worker
;
191 /* Tasklet to reclaim TX descriptors and buffers after tx */
192 struct tasklet_struct tx_reclaim_task
;
195 /* Per interface specific private data */
197 /* backpointer to parent config block */
198 struct mwl8k_priv
*priv
;
200 /* BSS config of AP or IBSS from mac80211*/
201 struct ieee80211_bss_conf bss_info
;
203 /* BSSID of AP or IBSS */
205 u8 mac_addr
[ETH_ALEN
];
208 * Subset of supported legacy rates.
209 * Intersection of AP and STA supported rates.
211 struct ieee80211_rate legacy_rates
[13];
213 /* number of supported legacy rates */
216 /* Index into station database.Returned by update_sta_db call */
219 /* Non AMPDU sequence number assigned by driver */
223 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
225 static const struct ieee80211_channel mwl8k_channels
[] = {
226 { .center_freq
= 2412, .hw_value
= 1, },
227 { .center_freq
= 2417, .hw_value
= 2, },
228 { .center_freq
= 2422, .hw_value
= 3, },
229 { .center_freq
= 2427, .hw_value
= 4, },
230 { .center_freq
= 2432, .hw_value
= 5, },
231 { .center_freq
= 2437, .hw_value
= 6, },
232 { .center_freq
= 2442, .hw_value
= 7, },
233 { .center_freq
= 2447, .hw_value
= 8, },
234 { .center_freq
= 2452, .hw_value
= 9, },
235 { .center_freq
= 2457, .hw_value
= 10, },
236 { .center_freq
= 2462, .hw_value
= 11, },
239 static const struct ieee80211_rate mwl8k_rates
[] = {
240 { .bitrate
= 10, .hw_value
= 2, },
241 { .bitrate
= 20, .hw_value
= 4, },
242 { .bitrate
= 55, .hw_value
= 11, },
243 { .bitrate
= 110, .hw_value
= 22, },
244 { .bitrate
= 220, .hw_value
= 44, },
245 { .bitrate
= 60, .hw_value
= 12, },
246 { .bitrate
= 90, .hw_value
= 18, },
247 { .bitrate
= 120, .hw_value
= 24, },
248 { .bitrate
= 180, .hw_value
= 36, },
249 { .bitrate
= 240, .hw_value
= 48, },
250 { .bitrate
= 360, .hw_value
= 72, },
251 { .bitrate
= 480, .hw_value
= 96, },
252 { .bitrate
= 540, .hw_value
= 108, },
255 /* Set or get info from Firmware */
256 #define MWL8K_CMD_SET 0x0001
257 #define MWL8K_CMD_GET 0x0000
259 /* Firmware command codes */
260 #define MWL8K_CMD_CODE_DNLD 0x0001
261 #define MWL8K_CMD_GET_HW_SPEC 0x0003
262 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
263 #define MWL8K_CMD_GET_STAT 0x0014
264 #define MWL8K_CMD_RADIO_CONTROL 0x001c
265 #define MWL8K_CMD_RF_TX_POWER 0x001e
266 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
267 #define MWL8K_CMD_SET_POST_SCAN 0x0108
268 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
269 #define MWL8K_CMD_SET_AID 0x010d
270 #define MWL8K_CMD_SET_RATE 0x0110
271 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
272 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
273 #define MWL8K_CMD_SET_SLOT 0x0114
274 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
275 #define MWL8K_CMD_SET_WMM_MODE 0x0123
276 #define MWL8K_CMD_MIMO_CONFIG 0x0125
277 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
278 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
279 #define MWL8K_CMD_SET_MAC_ADDR 0x0202
280 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
281 #define MWL8K_CMD_UPDATE_STADB 0x1123
283 static const char *mwl8k_cmd_name(u16 cmd
, char *buf
, int bufsize
)
285 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
286 snprintf(buf, bufsize, "%s", #x);\
289 switch (cmd
& ~0x8000) {
290 MWL8K_CMDNAME(CODE_DNLD
);
291 MWL8K_CMDNAME(GET_HW_SPEC
);
292 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
293 MWL8K_CMDNAME(GET_STAT
);
294 MWL8K_CMDNAME(RADIO_CONTROL
);
295 MWL8K_CMDNAME(RF_TX_POWER
);
296 MWL8K_CMDNAME(SET_PRE_SCAN
);
297 MWL8K_CMDNAME(SET_POST_SCAN
);
298 MWL8K_CMDNAME(SET_RF_CHANNEL
);
299 MWL8K_CMDNAME(SET_AID
);
300 MWL8K_CMDNAME(SET_RATE
);
301 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
302 MWL8K_CMDNAME(RTS_THRESHOLD
);
303 MWL8K_CMDNAME(SET_SLOT
);
304 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
305 MWL8K_CMDNAME(SET_WMM_MODE
);
306 MWL8K_CMDNAME(MIMO_CONFIG
);
307 MWL8K_CMDNAME(USE_FIXED_RATE
);
308 MWL8K_CMDNAME(ENABLE_SNIFFER
);
309 MWL8K_CMDNAME(SET_MAC_ADDR
);
310 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
311 MWL8K_CMDNAME(UPDATE_STADB
);
313 snprintf(buf
, bufsize
, "0x%x", cmd
);
320 /* Hardware and firmware reset */
321 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
323 iowrite32(MWL8K_H2A_INT_RESET
,
324 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
325 iowrite32(MWL8K_H2A_INT_RESET
,
326 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
330 /* Release fw image */
331 static void mwl8k_release_fw(struct firmware
**fw
)
335 release_firmware(*fw
);
339 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
341 mwl8k_release_fw(&priv
->fw
.ucode
);
342 mwl8k_release_fw(&priv
->fw
.helper
);
345 /* Request fw image */
346 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
347 const char *fname
, struct firmware
**fw
)
349 /* release current image */
351 mwl8k_release_fw(fw
);
353 return request_firmware((const struct firmware
**)fw
,
354 fname
, &priv
->pdev
->dev
);
357 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, u32 part_num
)
362 priv
->part_num
= part_num
;
364 snprintf(filename
, sizeof(filename
),
365 "mwl8k/helper_%u.fw", priv
->part_num
);
367 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.helper
);
369 printk(KERN_ERR
"%s: Error requesting helper firmware "
370 "file %s\n", pci_name(priv
->pdev
), filename
);
374 snprintf(filename
, sizeof(filename
),
375 "mwl8k/fmimage_%u.fw", priv
->part_num
);
377 rc
= mwl8k_request_fw(priv
, filename
, &priv
->fw
.ucode
);
379 printk(KERN_ERR
"%s: Error requesting firmware file %s\n",
380 pci_name(priv
->pdev
), filename
);
381 mwl8k_release_fw(&priv
->fw
.helper
);
388 struct mwl8k_cmd_pkt
{
394 } __attribute__((packed
));
400 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
402 void __iomem
*regs
= priv
->regs
;
406 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
407 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
410 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
411 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
412 iowrite32(MWL8K_H2A_INT_DOORBELL
,
413 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
414 iowrite32(MWL8K_H2A_INT_DUMMY
,
415 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
421 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
422 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
423 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
431 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
433 return loops
? 0 : -ETIMEDOUT
;
436 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
437 const u8
*data
, size_t length
)
439 struct mwl8k_cmd_pkt
*cmd
;
443 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
447 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
453 int block_size
= length
> 256 ? 256 : length
;
455 memcpy(cmd
->payload
, data
+ done
, block_size
);
456 cmd
->length
= cpu_to_le16(block_size
);
458 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
459 sizeof(*cmd
) + block_size
);
464 length
-= block_size
;
469 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
477 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
478 const u8
*data
, size_t length
)
480 unsigned char *buffer
;
481 int may_continue
, rc
= 0;
482 u32 done
, prev_block_size
;
484 buffer
= kmalloc(1024, GFP_KERNEL
);
491 while (may_continue
> 0) {
494 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
495 if (block_size
& 1) {
499 done
+= prev_block_size
;
500 length
-= prev_block_size
;
503 if (block_size
> 1024 || block_size
> length
) {
513 if (block_size
== 0) {
520 prev_block_size
= block_size
;
521 memcpy(buffer
, data
+ done
, block_size
);
523 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
528 if (!rc
&& length
!= 0)
536 static int mwl8k_load_firmware(struct ieee80211_hw
*hw
)
538 struct mwl8k_priv
*priv
= hw
->priv
;
539 struct firmware
*fw
= priv
->fw
.ucode
;
543 if (!memcmp(fw
->data
, "\x01\x00\x00\x00", 4)) {
544 struct firmware
*helper
= priv
->fw
.helper
;
546 if (helper
== NULL
) {
547 printk(KERN_ERR
"%s: helper image needed but none "
548 "given\n", pci_name(priv
->pdev
));
552 rc
= mwl8k_load_fw_image(priv
, helper
->data
, helper
->size
);
554 printk(KERN_ERR
"%s: unable to load firmware "
555 "helper image\n", pci_name(priv
->pdev
));
560 rc
= mwl8k_feed_fw_image(priv
, fw
->data
, fw
->size
);
562 rc
= mwl8k_load_fw_image(priv
, fw
->data
, fw
->size
);
566 printk(KERN_ERR
"%s: unable to load firmware image\n",
567 pci_name(priv
->pdev
));
571 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
576 if (ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
)
577 == MWL8K_FWSTA_READY
)
582 return loops
? 0 : -ETIMEDOUT
;
587 * Defines shared between transmission and reception.
589 /* HT control fields for firmware */
594 } __attribute__((packed
));
596 /* Firmware Station database operations */
597 #define MWL8K_STA_DB_ADD_ENTRY 0
598 #define MWL8K_STA_DB_MODIFY_ENTRY 1
599 #define MWL8K_STA_DB_DEL_ENTRY 2
600 #define MWL8K_STA_DB_FLUSH 3
602 /* Peer Entry flags - used to define the type of the peer node */
603 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
605 #define MWL8K_IEEE_LEGACY_DATA_RATES 13
606 #define MWL8K_MCS_BITMAP_SIZE 16
608 struct peer_capability_info
{
609 /* Peer type - AP vs. STA. */
612 /* Basic 802.11 capabilities from assoc resp. */
615 /* Set if peer supports 802.11n high throughput (HT). */
618 /* Valid if HT is supported. */
620 __u8 extended_ht_caps
;
621 struct ewc_ht_info ewc_info
;
623 /* Legacy rate table. Intersection of our rates and peer rates. */
624 __u8 legacy_rates
[MWL8K_IEEE_LEGACY_DATA_RATES
];
626 /* HT rate table. Intersection of our rates and peer rates. */
627 __u8 ht_rates
[MWL8K_MCS_BITMAP_SIZE
];
630 /* If set, interoperability mode, no proprietary extensions. */
634 __le16 amsdu_enabled
;
635 } __attribute__((packed
));
637 /* Inline functions to manipulate QoS field in data descriptor. */
638 static inline u16
mwl8k_qos_setbit_eosp(u16 qos
)
640 u16 val_mask
= 1 << 4;
642 /* End of Service Period Bit 4 */
643 return qos
| val_mask
;
646 static inline u16
mwl8k_qos_setbit_ack(u16 qos
, u8 ack_policy
)
650 u16 qos_mask
= ~(val_mask
<< shift
);
652 /* Ack Policy Bit 5-6 */
653 return (qos
& qos_mask
) | ((ack_policy
& val_mask
) << shift
);
656 static inline u16
mwl8k_qos_setbit_amsdu(u16 qos
)
658 u16 val_mask
= 1 << 7;
660 /* AMSDU present Bit 7 */
661 return qos
| val_mask
;
664 static inline u16
mwl8k_qos_setbit_qlen(u16 qos
, u8 len
)
668 u16 qos_mask
= ~(val_mask
<< shift
);
670 /* Queue Length Bits 8-15 */
671 return (qos
& qos_mask
) | ((len
& val_mask
) << shift
);
674 /* DMA header used by firmware and hardware. */
675 struct mwl8k_dma_data
{
677 struct ieee80211_hdr wh
;
678 } __attribute__((packed
));
680 /* Routines to add/remove DMA header from skb. */
681 static inline void mwl8k_remove_dma_header(struct sk_buff
*skb
)
683 struct mwl8k_dma_data
*tr
= (struct mwl8k_dma_data
*)skb
->data
;
684 void *dst
, *src
= &tr
->wh
;
685 int hdrlen
= ieee80211_hdrlen(tr
->wh
.frame_control
);
686 u16 space
= sizeof(struct mwl8k_dma_data
) - hdrlen
;
688 dst
= (void *)tr
+ space
;
690 memmove(dst
, src
, hdrlen
);
691 skb_pull(skb
, space
);
695 static inline void mwl8k_add_dma_header(struct sk_buff
*skb
)
697 struct ieee80211_hdr
*wh
;
699 struct mwl8k_dma_data
*tr
;
701 wh
= (struct ieee80211_hdr
*)skb
->data
;
702 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
706 * Copy up/down the 802.11 header; the firmware requires
707 * we present a 2-byte payload length followed by a
708 * 4-address header (w/o QoS), followed (optionally) by
709 * any WEP/ExtIV header (but only filled in for CCMP).
711 if (hdrlen
!= sizeof(struct mwl8k_dma_data
))
712 skb_push(skb
, sizeof(struct mwl8k_dma_data
) - hdrlen
);
714 tr
= (struct mwl8k_dma_data
*)skb
->data
;
716 memmove(&tr
->wh
, wh
, hdrlen
);
719 memset(tr
->wh
.addr4
, 0, ETH_ALEN
);
722 * Firmware length is the length of the fully formed "802.11
723 * payload". That is, everything except for the 802.11 header.
724 * This includes all crypto material including the MIC.
726 tr
->fwlen
= cpu_to_le16(pktlen
- hdrlen
);
733 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
735 struct mwl8k_rx_desc
{
739 __le32 pkt_phys_addr
;
740 __le32 next_rx_desc_phys_addr
;
750 } __attribute__((packed
));
752 #define MWL8K_RX_DESCS 256
753 #define MWL8K_RX_MAXSZ 3800
755 #define RATE_INFO_SHORTPRE 0x8000
756 #define RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
757 #define RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
758 #define RATE_INFO_40MHZ 0x0004
759 #define RATE_INFO_SHORTGI 0x0002
760 #define RATE_INFO_MCS_FORMAT 0x0001
762 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
764 struct mwl8k_priv
*priv
= hw
->priv
;
765 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
769 rxq
->rx_desc_count
= 0;
773 size
= MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
);
776 pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rx_desc_dma
);
777 if (rxq
->rx_desc_area
== NULL
) {
778 printk(KERN_ERR
"%s: failed to alloc RX descriptors\n",
779 wiphy_name(hw
->wiphy
));
782 memset(rxq
->rx_desc_area
, 0, size
);
784 rxq
->rx_skb
= kmalloc(MWL8K_RX_DESCS
*
785 sizeof(*rxq
->rx_skb
), GFP_KERNEL
);
786 if (rxq
->rx_skb
== NULL
) {
787 printk(KERN_ERR
"%s: failed to alloc RX skbuff list\n",
788 wiphy_name(hw
->wiphy
));
789 pci_free_consistent(priv
->pdev
, size
,
790 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
793 memset(rxq
->rx_skb
, 0, MWL8K_RX_DESCS
* sizeof(*rxq
->rx_skb
));
795 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
796 struct mwl8k_rx_desc
*rx_desc
;
799 rx_desc
= rxq
->rx_desc_area
+ i
;
800 nexti
= (i
+ 1) % MWL8K_RX_DESCS
;
802 rx_desc
->next_rx_desc_phys_addr
=
803 cpu_to_le32(rxq
->rx_desc_dma
804 + nexti
* sizeof(*rx_desc
));
805 rx_desc
->rx_ctrl
= MWL8K_RX_CTRL_OWNED_BY_HOST
;
811 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
813 struct mwl8k_priv
*priv
= hw
->priv
;
814 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
818 while (rxq
->rx_desc_count
< MWL8K_RX_DESCS
&& limit
--) {
822 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
826 rxq
->rx_desc_count
++;
829 rxq
->rx_tail
= (rx
+ 1) % MWL8K_RX_DESCS
;
831 rxq
->rx_desc_area
[rx
].pkt_phys_addr
=
832 cpu_to_le32(pci_map_single(priv
->pdev
, skb
->data
,
833 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
));
835 rxq
->rx_desc_area
[rx
].pkt_len
= cpu_to_le16(MWL8K_RX_MAXSZ
);
836 rxq
->rx_skb
[rx
] = skb
;
838 rxq
->rx_desc_area
[rx
].rx_ctrl
= 0;
846 /* Must be called only when the card's reception is completely halted */
847 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
849 struct mwl8k_priv
*priv
= hw
->priv
;
850 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
853 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
854 if (rxq
->rx_skb
[i
] != NULL
) {
857 addr
= le32_to_cpu(rxq
->rx_desc_area
[i
].pkt_phys_addr
);
858 pci_unmap_single(priv
->pdev
, addr
, MWL8K_RX_MAXSZ
,
860 kfree_skb(rxq
->rx_skb
[i
]);
861 rxq
->rx_skb
[i
] = NULL
;
868 pci_free_consistent(priv
->pdev
,
869 MWL8K_RX_DESCS
* sizeof(struct mwl8k_rx_desc
),
870 rxq
->rx_desc_area
, rxq
->rx_desc_dma
);
871 rxq
->rx_desc_area
= NULL
;
876 * Scan a list of BSSIDs to process for finalize join.
877 * Allows for extension to process multiple BSSIDs.
880 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
882 return priv
->capture_beacon
&&
883 ieee80211_is_beacon(wh
->frame_control
) &&
884 !compare_ether_addr(wh
->addr3
, priv
->capture_bssid
);
887 static inline void mwl8k_save_beacon(struct ieee80211_hw
*hw
,
890 struct mwl8k_priv
*priv
= hw
->priv
;
892 priv
->capture_beacon
= false;
893 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
896 * Use GFP_ATOMIC as rxq_process is called from
897 * the primary interrupt handler, memory allocation call
900 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
901 if (priv
->beacon_skb
!= NULL
)
902 ieee80211_queue_work(hw
, &priv
->finalize_join_worker
);
905 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
907 struct mwl8k_priv
*priv
= hw
->priv
;
908 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
912 while (rxq
->rx_desc_count
&& limit
--) {
913 struct mwl8k_rx_desc
*rx_desc
;
915 struct ieee80211_rx_status status
;
917 struct ieee80211_hdr
*wh
;
920 rx_desc
= rxq
->rx_desc_area
+ rxq
->rx_head
;
921 if (!(rx_desc
->rx_ctrl
& MWL8K_RX_CTRL_OWNED_BY_HOST
))
925 skb
= rxq
->rx_skb
[rxq
->rx_head
];
928 rxq
->rx_skb
[rxq
->rx_head
] = NULL
;
930 rxq
->rx_head
= (rxq
->rx_head
+ 1) % MWL8K_RX_DESCS
;
931 rxq
->rx_desc_count
--;
933 addr
= le32_to_cpu(rx_desc
->pkt_phys_addr
);
934 pci_unmap_single(priv
->pdev
, addr
,
935 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
937 skb_put(skb
, le16_to_cpu(rx_desc
->pkt_len
));
938 mwl8k_remove_dma_header(skb
);
940 wh
= (struct ieee80211_hdr
*)skb
->data
;
943 * Check for a pending join operation. Save a
944 * copy of the beacon and schedule a tasklet to
945 * send a FINALIZE_JOIN command to the firmware.
947 if (mwl8k_capture_bssid(priv
, wh
))
948 mwl8k_save_beacon(hw
, skb
);
950 rate_info
= le16_to_cpu(rx_desc
->rate_info
);
952 memset(&status
, 0, sizeof(status
));
954 status
.signal
= -rx_desc
->rssi
;
955 status
.noise
= -rx_desc
->noise_level
;
956 status
.qual
= rx_desc
->link_quality
;
957 status
.antenna
= RATE_INFO_ANTSELECT(rate_info
);
958 status
.rate_idx
= RATE_INFO_RATEID(rate_info
);
960 if (rate_info
& RATE_INFO_SHORTPRE
)
961 status
.flag
|= RX_FLAG_SHORTPRE
;
962 if (rate_info
& RATE_INFO_40MHZ
)
963 status
.flag
|= RX_FLAG_40MHZ
;
964 if (rate_info
& RATE_INFO_SHORTGI
)
965 status
.flag
|= RX_FLAG_SHORT_GI
;
966 if (rate_info
& RATE_INFO_MCS_FORMAT
)
967 status
.flag
|= RX_FLAG_HT
;
968 status
.band
= IEEE80211_BAND_2GHZ
;
969 status
.freq
= ieee80211_channel_to_frequency(rx_desc
->channel
);
970 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
971 ieee80211_rx_irqsafe(hw
, skb
);
981 * Packet transmission.
984 /* Transmit packet ACK policy */
985 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
986 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
988 #define MWL8K_TXD_STATUS_OK 0x00000001
989 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
990 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
991 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
992 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
994 struct mwl8k_tx_desc
{
999 __le32 pkt_phys_addr
;
1001 __u8 dest_MAC_addr
[ETH_ALEN
];
1002 __le32 next_tx_desc_phys_addr
;
1007 } __attribute__((packed
));
1009 #define MWL8K_TX_DESCS 128
1011 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1013 struct mwl8k_priv
*priv
= hw
->priv
;
1014 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1018 memset(&txq
->tx_stats
, 0, sizeof(struct ieee80211_tx_queue_stats
));
1019 txq
->tx_stats
.limit
= MWL8K_TX_DESCS
;
1023 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1026 pci_alloc_consistent(priv
->pdev
, size
, &txq
->tx_desc_dma
);
1027 if (txq
->tx_desc_area
== NULL
) {
1028 printk(KERN_ERR
"%s: failed to alloc TX descriptors\n",
1029 wiphy_name(hw
->wiphy
));
1032 memset(txq
->tx_desc_area
, 0, size
);
1034 txq
->tx_skb
= kmalloc(MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
),
1036 if (txq
->tx_skb
== NULL
) {
1037 printk(KERN_ERR
"%s: failed to alloc TX skbuff list\n",
1038 wiphy_name(hw
->wiphy
));
1039 pci_free_consistent(priv
->pdev
, size
,
1040 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1043 memset(txq
->tx_skb
, 0, MWL8K_TX_DESCS
* sizeof(*txq
->tx_skb
));
1045 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1046 struct mwl8k_tx_desc
*tx_desc
;
1049 tx_desc
= txq
->tx_desc_area
+ i
;
1050 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1052 tx_desc
->status
= 0;
1053 tx_desc
->next_tx_desc_phys_addr
=
1054 cpu_to_le32(txq
->tx_desc_dma
+
1055 nexti
* sizeof(*tx_desc
));
1061 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1063 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1064 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1065 iowrite32(MWL8K_H2A_INT_DUMMY
,
1066 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1067 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1070 struct mwl8k_txq_info
{
1079 static int mwl8k_scan_tx_ring(struct mwl8k_priv
*priv
,
1080 struct mwl8k_txq_info
*txinfo
)
1082 int count
, desc
, status
;
1083 struct mwl8k_tx_queue
*txq
;
1084 struct mwl8k_tx_desc
*tx_desc
;
1087 memset(txinfo
, 0, MWL8K_TX_QUEUES
* sizeof(struct mwl8k_txq_info
));
1089 for (count
= 0; count
< MWL8K_TX_QUEUES
; count
++) {
1090 txq
= priv
->txq
+ count
;
1091 txinfo
[count
].len
= txq
->tx_stats
.len
;
1092 txinfo
[count
].head
= txq
->tx_head
;
1093 txinfo
[count
].tail
= txq
->tx_tail
;
1094 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1095 tx_desc
= txq
->tx_desc_area
+ desc
;
1096 status
= le32_to_cpu(tx_desc
->status
);
1098 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1099 txinfo
[count
].fw_owned
++;
1101 txinfo
[count
].drv_owned
++;
1103 if (tx_desc
->pkt_len
== 0)
1104 txinfo
[count
].unused
++;
1112 * Must be called with priv->fw_mutex held and tx queues stopped.
1114 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
)
1116 struct mwl8k_priv
*priv
= hw
->priv
;
1117 DECLARE_COMPLETION_ONSTACK(tx_wait
);
1119 unsigned long timeout
;
1123 spin_lock_bh(&priv
->tx_lock
);
1124 count
= priv
->pending_tx_pkts
;
1126 priv
->tx_wait
= &tx_wait
;
1127 spin_unlock_bh(&priv
->tx_lock
);
1130 struct mwl8k_txq_info txinfo
[MWL8K_TX_QUEUES
];
1134 timeout
= wait_for_completion_timeout(&tx_wait
,
1135 msecs_to_jiffies(5000));
1139 spin_lock_bh(&priv
->tx_lock
);
1140 priv
->tx_wait
= NULL
;
1141 newcount
= priv
->pending_tx_pkts
;
1142 mwl8k_scan_tx_ring(priv
, txinfo
);
1143 spin_unlock_bh(&priv
->tx_lock
);
1145 printk(KERN_ERR
"%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
1146 __func__
, __LINE__
, count
, newcount
);
1148 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++)
1149 printk(KERN_ERR
"TXQ:%u L:%u H:%u T:%u FW:%u "
1155 txinfo
[index
].fw_owned
,
1156 txinfo
[index
].drv_owned
,
1157 txinfo
[index
].unused
);
1165 #define MWL8K_TXD_SUCCESS(status) \
1166 ((status) & (MWL8K_TXD_STATUS_OK | \
1167 MWL8K_TXD_STATUS_OK_RETRY | \
1168 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1170 static void mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int force
)
1172 struct mwl8k_priv
*priv
= hw
->priv
;
1173 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1176 while (txq
->tx_stats
.len
> 0) {
1178 struct mwl8k_tx_desc
*tx_desc
;
1181 struct sk_buff
*skb
;
1182 struct ieee80211_tx_info
*info
;
1186 tx_desc
= txq
->tx_desc_area
+ tx
;
1188 status
= le32_to_cpu(tx_desc
->status
);
1190 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1194 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1197 txq
->tx_head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1198 BUG_ON(txq
->tx_stats
.len
== 0);
1199 txq
->tx_stats
.len
--;
1200 priv
->pending_tx_pkts
--;
1202 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1203 size
= le16_to_cpu(tx_desc
->pkt_len
);
1204 skb
= txq
->tx_skb
[tx
];
1205 txq
->tx_skb
[tx
] = NULL
;
1207 BUG_ON(skb
== NULL
);
1208 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1210 mwl8k_remove_dma_header(skb
);
1212 /* Mark descriptor as unused */
1213 tx_desc
->pkt_phys_addr
= 0;
1214 tx_desc
->pkt_len
= 0;
1216 info
= IEEE80211_SKB_CB(skb
);
1217 ieee80211_tx_info_clear_status(info
);
1218 if (MWL8K_TXD_SUCCESS(status
))
1219 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1221 ieee80211_tx_status_irqsafe(hw
, skb
);
1226 if (wake
&& priv
->radio_on
&& !mutex_is_locked(&priv
->fw_mutex
))
1227 ieee80211_wake_queue(hw
, index
);
1230 /* must be called only when the card's transmit is completely halted */
1231 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1233 struct mwl8k_priv
*priv
= hw
->priv
;
1234 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1236 mwl8k_txq_reclaim(hw
, index
, 1);
1241 pci_free_consistent(priv
->pdev
,
1242 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1243 txq
->tx_desc_area
, txq
->tx_desc_dma
);
1244 txq
->tx_desc_area
= NULL
;
1248 mwl8k_txq_xmit(struct ieee80211_hw
*hw
, int index
, struct sk_buff
*skb
)
1250 struct mwl8k_priv
*priv
= hw
->priv
;
1251 struct ieee80211_tx_info
*tx_info
;
1252 struct mwl8k_vif
*mwl8k_vif
;
1253 struct ieee80211_hdr
*wh
;
1254 struct mwl8k_tx_queue
*txq
;
1255 struct mwl8k_tx_desc
*tx
;
1261 wh
= (struct ieee80211_hdr
*)skb
->data
;
1262 if (ieee80211_is_data_qos(wh
->frame_control
))
1263 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1267 mwl8k_add_dma_header(skb
);
1268 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1270 tx_info
= IEEE80211_SKB_CB(skb
);
1271 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1273 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1274 u16 seqno
= mwl8k_vif
->seqno
;
1276 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1277 wh
->seq_ctrl
|= cpu_to_le16(seqno
<< 4);
1278 mwl8k_vif
->seqno
= seqno
++ % 4096;
1281 /* Setup firmware control bit fields for each frame type. */
1284 if (ieee80211_is_mgmt(wh
->frame_control
) ||
1285 ieee80211_is_ctl(wh
->frame_control
)) {
1287 qos
= mwl8k_qos_setbit_eosp(qos
);
1288 /* Set Queue size to unspecified */
1289 qos
= mwl8k_qos_setbit_qlen(qos
, 0xff);
1290 } else if (ieee80211_is_data(wh
->frame_control
)) {
1292 if (is_multicast_ether_addr(wh
->addr1
))
1293 txstatus
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1295 /* Send pkt in an aggregate if AMPDU frame. */
1296 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1297 qos
= mwl8k_qos_setbit_ack(qos
,
1298 MWL8K_TXD_ACK_POLICY_BLOCKACK
);
1300 qos
= mwl8k_qos_setbit_ack(qos
,
1301 MWL8K_TXD_ACK_POLICY_NORMAL
);
1303 if (qos
& IEEE80211_QOS_CONTROL_A_MSDU_PRESENT
)
1304 qos
= mwl8k_qos_setbit_amsdu(qos
);
1307 dma
= pci_map_single(priv
->pdev
, skb
->data
,
1308 skb
->len
, PCI_DMA_TODEVICE
);
1310 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
1311 printk(KERN_DEBUG
"%s: failed to dma map skb, "
1312 "dropping TX frame.\n", wiphy_name(hw
->wiphy
));
1314 return NETDEV_TX_OK
;
1317 spin_lock_bh(&priv
->tx_lock
);
1319 txq
= priv
->txq
+ index
;
1321 BUG_ON(txq
->tx_skb
[txq
->tx_tail
] != NULL
);
1322 txq
->tx_skb
[txq
->tx_tail
] = skb
;
1324 tx
= txq
->tx_desc_area
+ txq
->tx_tail
;
1325 tx
->data_rate
= txdatarate
;
1326 tx
->tx_priority
= index
;
1327 tx
->qos_control
= cpu_to_le16(qos
);
1328 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
1329 tx
->pkt_len
= cpu_to_le16(skb
->len
);
1331 tx
->peer_id
= mwl8k_vif
->peer_id
;
1333 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
| txstatus
);
1335 txq
->tx_stats
.count
++;
1336 txq
->tx_stats
.len
++;
1337 priv
->pending_tx_pkts
++;
1340 if (txq
->tx_tail
== MWL8K_TX_DESCS
)
1343 if (txq
->tx_head
== txq
->tx_tail
)
1344 ieee80211_stop_queue(hw
, index
);
1346 mwl8k_tx_start(priv
);
1348 spin_unlock_bh(&priv
->tx_lock
);
1350 return NETDEV_TX_OK
;
1357 * We have the following requirements for issuing firmware commands:
1358 * - Some commands require that the packet transmit path is idle when
1359 * the command is issued. (For simplicity, we'll just quiesce the
1360 * transmit path for every command.)
1361 * - There are certain sequences of commands that need to be issued to
1362 * the hardware sequentially, with no other intervening commands.
1364 * This leads to an implementation of a "firmware lock" as a mutex that
1365 * can be taken recursively, and which is taken by both the low-level
1366 * command submission function (mwl8k_post_cmd) as well as any users of
1367 * that function that require issuing of an atomic sequence of commands,
1368 * and quiesces the transmit path whenever it's taken.
1370 static int mwl8k_fw_lock(struct ieee80211_hw
*hw
)
1372 struct mwl8k_priv
*priv
= hw
->priv
;
1374 if (priv
->fw_mutex_owner
!= current
) {
1377 mutex_lock(&priv
->fw_mutex
);
1378 ieee80211_stop_queues(hw
);
1380 rc
= mwl8k_tx_wait_empty(hw
);
1382 ieee80211_wake_queues(hw
);
1383 mutex_unlock(&priv
->fw_mutex
);
1388 priv
->fw_mutex_owner
= current
;
1391 priv
->fw_mutex_depth
++;
1396 static void mwl8k_fw_unlock(struct ieee80211_hw
*hw
)
1398 struct mwl8k_priv
*priv
= hw
->priv
;
1400 if (!--priv
->fw_mutex_depth
) {
1401 ieee80211_wake_queues(hw
);
1402 priv
->fw_mutex_owner
= NULL
;
1403 mutex_unlock(&priv
->fw_mutex
);
1409 * Command processing.
1412 /* Timeout firmware commands after 2000ms */
1413 #define MWL8K_CMD_TIMEOUT_MS 2000
1415 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
1417 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1418 struct mwl8k_priv
*priv
= hw
->priv
;
1419 void __iomem
*regs
= priv
->regs
;
1420 dma_addr_t dma_addr
;
1421 unsigned int dma_size
;
1423 unsigned long timeout
= 0;
1426 cmd
->result
= 0xffff;
1427 dma_size
= le16_to_cpu(cmd
->length
);
1428 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
1429 PCI_DMA_BIDIRECTIONAL
);
1430 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
1433 rc
= mwl8k_fw_lock(hw
);
1435 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1436 PCI_DMA_BIDIRECTIONAL
);
1440 priv
->hostcmd_wait
= &cmd_wait
;
1441 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
1442 iowrite32(MWL8K_H2A_INT_DOORBELL
,
1443 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1444 iowrite32(MWL8K_H2A_INT_DUMMY
,
1445 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1447 timeout
= wait_for_completion_timeout(&cmd_wait
,
1448 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
1450 priv
->hostcmd_wait
= NULL
;
1452 mwl8k_fw_unlock(hw
);
1454 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1455 PCI_DMA_BIDIRECTIONAL
);
1458 printk(KERN_ERR
"%s: Command %s timeout after %u ms\n",
1459 wiphy_name(hw
->wiphy
),
1460 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1461 MWL8K_CMD_TIMEOUT_MS
);
1464 rc
= cmd
->result
? -EINVAL
: 0;
1466 printk(KERN_ERR
"%s: Command %s error 0x%x\n",
1467 wiphy_name(hw
->wiphy
),
1468 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1469 le16_to_cpu(cmd
->result
));
1478 struct mwl8k_cmd_get_hw_spec
{
1479 struct mwl8k_cmd_pkt header
;
1481 __u8 host_interface
;
1483 __u8 perm_addr
[ETH_ALEN
];
1488 __u8 mcs_bitmap
[16];
1489 __le32 rx_queue_ptr
;
1490 __le32 num_tx_queues
;
1491 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1493 __le32 num_tx_desc_per_queue
;
1494 __le32 total_rx_desc
;
1495 } __attribute__((packed
));
1497 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw
*hw
)
1499 struct mwl8k_priv
*priv
= hw
->priv
;
1500 struct mwl8k_cmd_get_hw_spec
*cmd
;
1504 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1508 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1509 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1511 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1512 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1513 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rx_desc_dma
);
1514 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1515 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1516 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].tx_desc_dma
);
1517 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1518 cmd
->total_rx_desc
= cpu_to_le32(MWL8K_RX_DESCS
);
1520 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1523 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1524 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1525 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1526 priv
->hw_rev
= cmd
->hw_rev
;
1534 * CMD_MAC_MULTICAST_ADR.
1536 struct mwl8k_cmd_mac_multicast_adr
{
1537 struct mwl8k_cmd_pkt header
;
1540 __u8 addr
[0][ETH_ALEN
];
1543 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
1544 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
1545 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1546 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
1548 static struct mwl8k_cmd_pkt
*
1549 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
, int allmulti
,
1550 int mc_count
, struct dev_addr_list
*mclist
)
1552 struct mwl8k_priv
*priv
= hw
->priv
;
1553 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
1556 if (allmulti
|| mc_count
> priv
->num_mcaddrs
) {
1561 size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
1563 cmd
= kzalloc(size
, GFP_ATOMIC
);
1567 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
1568 cmd
->header
.length
= cpu_to_le16(size
);
1569 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED
|
1570 MWL8K_ENABLE_RX_BROADCAST
);
1573 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST
);
1574 } else if (mc_count
) {
1577 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
1578 cmd
->numaddr
= cpu_to_le16(mc_count
);
1579 for (i
= 0; i
< mc_count
&& mclist
; i
++) {
1580 if (mclist
->da_addrlen
!= ETH_ALEN
) {
1584 memcpy(cmd
->addr
[i
], mclist
->da_addr
, ETH_ALEN
);
1585 mclist
= mclist
->next
;
1589 return &cmd
->header
;
1593 * CMD_802_11_GET_STAT.
1595 struct mwl8k_cmd_802_11_get_stat
{
1596 struct mwl8k_cmd_pkt header
;
1598 } __attribute__((packed
));
1600 #define MWL8K_STAT_ACK_FAILURE 9
1601 #define MWL8K_STAT_RTS_FAILURE 12
1602 #define MWL8K_STAT_FCS_ERROR 24
1603 #define MWL8K_STAT_RTS_SUCCESS 11
1605 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw
*hw
,
1606 struct ieee80211_low_level_stats
*stats
)
1608 struct mwl8k_cmd_802_11_get_stat
*cmd
;
1611 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1615 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
1616 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1618 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1620 stats
->dot11ACKFailureCount
=
1621 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
1622 stats
->dot11RTSFailureCount
=
1623 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
1624 stats
->dot11FCSErrorCount
=
1625 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
1626 stats
->dot11RTSSuccessCount
=
1627 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
1635 * CMD_802_11_RADIO_CONTROL.
1637 struct mwl8k_cmd_802_11_radio_control
{
1638 struct mwl8k_cmd_pkt header
;
1642 } __attribute__((packed
));
1645 mwl8k_cmd_802_11_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
1647 struct mwl8k_priv
*priv
= hw
->priv
;
1648 struct mwl8k_cmd_802_11_radio_control
*cmd
;
1651 if (enable
== priv
->radio_on
&& !force
)
1654 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1658 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
1659 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1660 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1661 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
1662 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
1664 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1668 priv
->radio_on
= enable
;
1673 static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw
*hw
)
1675 return mwl8k_cmd_802_11_radio_control(hw
, 0, 0);
1678 static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw
*hw
)
1680 return mwl8k_cmd_802_11_radio_control(hw
, 1, 0);
1684 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
1686 struct mwl8k_priv
*priv
;
1688 if (hw
== NULL
|| hw
->priv
== NULL
)
1692 priv
->radio_short_preamble
= short_preamble
;
1694 return mwl8k_cmd_802_11_radio_control(hw
, 1, 1);
1698 * CMD_802_11_RF_TX_POWER.
1700 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1702 struct mwl8k_cmd_802_11_rf_tx_power
{
1703 struct mwl8k_cmd_pkt header
;
1705 __le16 support_level
;
1706 __le16 current_level
;
1708 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
1709 } __attribute__((packed
));
1711 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
1713 struct mwl8k_cmd_802_11_rf_tx_power
*cmd
;
1716 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1720 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
1721 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1722 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1723 cmd
->support_level
= cpu_to_le16(dBm
);
1725 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1734 struct mwl8k_cmd_set_pre_scan
{
1735 struct mwl8k_cmd_pkt header
;
1736 } __attribute__((packed
));
1738 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
1740 struct mwl8k_cmd_set_pre_scan
*cmd
;
1743 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1747 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
1748 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1750 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1757 * CMD_SET_POST_SCAN.
1759 struct mwl8k_cmd_set_post_scan
{
1760 struct mwl8k_cmd_pkt header
;
1762 __u8 bssid
[ETH_ALEN
];
1763 } __attribute__((packed
));
1766 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, __u8
*mac
)
1768 struct mwl8k_cmd_set_post_scan
*cmd
;
1771 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1775 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
1776 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1778 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
1780 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1787 * CMD_SET_RF_CHANNEL.
1789 struct mwl8k_cmd_set_rf_channel
{
1790 struct mwl8k_cmd_pkt header
;
1792 __u8 current_channel
;
1793 __le32 channel_flags
;
1794 } __attribute__((packed
));
1796 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
1797 struct ieee80211_channel
*channel
)
1799 struct mwl8k_cmd_set_rf_channel
*cmd
;
1802 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1806 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
1807 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1808 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1809 cmd
->current_channel
= channel
->hw_value
;
1810 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1811 cmd
->channel_flags
= cpu_to_le32(0x00000081);
1813 cmd
->channel_flags
= cpu_to_le32(0x00000000);
1815 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1824 struct mwl8k_cmd_set_slot
{
1825 struct mwl8k_cmd_pkt header
;
1828 } __attribute__((packed
));
1830 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, bool short_slot_time
)
1832 struct mwl8k_cmd_set_slot
*cmd
;
1835 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1839 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
1840 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1841 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1842 cmd
->short_slot
= short_slot_time
;
1844 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1853 struct mwl8k_cmd_mimo_config
{
1854 struct mwl8k_cmd_pkt header
;
1856 __u8 rx_antenna_map
;
1857 __u8 tx_antenna_map
;
1858 } __attribute__((packed
));
1860 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
1862 struct mwl8k_cmd_mimo_config
*cmd
;
1865 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1869 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
1870 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1871 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
1872 cmd
->rx_antenna_map
= rx
;
1873 cmd
->tx_antenna_map
= tx
;
1875 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1882 * CMD_ENABLE_SNIFFER.
1884 struct mwl8k_cmd_enable_sniffer
{
1885 struct mwl8k_cmd_pkt header
;
1887 } __attribute__((packed
));
1889 static int mwl8k_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
1891 struct mwl8k_cmd_enable_sniffer
*cmd
;
1894 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1898 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
1899 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1900 cmd
->action
= cpu_to_le32(!!enable
);
1902 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1911 struct mwl8k_cmd_set_mac_addr
{
1912 struct mwl8k_cmd_pkt header
;
1913 __u8 mac_addr
[ETH_ALEN
];
1914 } __attribute__((packed
));
1916 static int mwl8k_set_mac_addr(struct ieee80211_hw
*hw
, u8
*mac
)
1918 struct mwl8k_cmd_set_mac_addr
*cmd
;
1921 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1925 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR
);
1926 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1927 memcpy(cmd
->mac_addr
, mac
, ETH_ALEN
);
1929 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1937 * CMD_SET_RATEADAPT_MODE.
1939 struct mwl8k_cmd_set_rate_adapt_mode
{
1940 struct mwl8k_cmd_pkt header
;
1943 } __attribute__((packed
));
1945 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw
*hw
, __u16 mode
)
1947 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
1950 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1954 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
1955 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1956 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
1957 cmd
->mode
= cpu_to_le16(mode
);
1959 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1968 struct mwl8k_cmd_set_wmm
{
1969 struct mwl8k_cmd_pkt header
;
1971 } __attribute__((packed
));
1973 static int mwl8k_set_wmm(struct ieee80211_hw
*hw
, bool enable
)
1975 struct mwl8k_priv
*priv
= hw
->priv
;
1976 struct mwl8k_cmd_set_wmm
*cmd
;
1979 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1983 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
1984 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1985 cmd
->action
= cpu_to_le16(!!enable
);
1987 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1991 priv
->wmm_enabled
= enable
;
1997 * CMD_SET_RTS_THRESHOLD.
1999 struct mwl8k_cmd_rts_threshold
{
2000 struct mwl8k_cmd_pkt header
;
2003 } __attribute__((packed
));
2005 static int mwl8k_rts_threshold(struct ieee80211_hw
*hw
,
2006 u16 action
, u16 threshold
)
2008 struct mwl8k_cmd_rts_threshold
*cmd
;
2011 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2015 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
2016 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2017 cmd
->action
= cpu_to_le16(action
);
2018 cmd
->threshold
= cpu_to_le16(threshold
);
2020 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2027 * CMD_SET_EDCA_PARAMS.
2029 struct mwl8k_cmd_set_edca_params
{
2030 struct mwl8k_cmd_pkt header
;
2032 /* See MWL8K_SET_EDCA_XXX below */
2035 /* TX opportunity in units of 32 us */
2038 /* Log exponent of max contention period: 0...15*/
2041 /* Log exponent of min contention period: 0...15 */
2044 /* Adaptive interframe spacing in units of 32us */
2047 /* TX queue to configure */
2049 } __attribute__((packed
));
2051 #define MWL8K_SET_EDCA_CW 0x01
2052 #define MWL8K_SET_EDCA_TXOP 0x02
2053 #define MWL8K_SET_EDCA_AIFS 0x04
2055 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2056 MWL8K_SET_EDCA_TXOP | \
2057 MWL8K_SET_EDCA_AIFS)
2060 mwl8k_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
2061 __u16 cw_min
, __u16 cw_max
,
2062 __u8 aifs
, __u16 txop
)
2064 struct mwl8k_cmd_set_edca_params
*cmd
;
2067 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2072 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2075 qnum
^= !(qnum
>> 1);
2077 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
2078 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2079 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
2080 cmd
->txop
= cpu_to_le16(txop
);
2081 cmd
->log_cw_max
= (u8
)ilog2(cw_max
+ 1);
2082 cmd
->log_cw_min
= (u8
)ilog2(cw_min
+ 1);
2086 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2093 * CMD_FINALIZE_JOIN.
2096 /* FJ beacon buffer size is compiled into the firmware. */
2097 #define MWL8K_FJ_BEACON_MAXLEN 128
2099 struct mwl8k_cmd_finalize_join
{
2100 struct mwl8k_cmd_pkt header
;
2101 __le32 sleep_interval
; /* Number of beacon periods to sleep */
2102 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
2103 } __attribute__((packed
));
2105 static int mwl8k_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
2106 __u16 framelen
, __u16 dtim
)
2108 struct mwl8k_cmd_finalize_join
*cmd
;
2109 struct ieee80211_mgmt
*payload
= frame
;
2117 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2121 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
2122 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2123 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
2125 hdrlen
= ieee80211_hdrlen(payload
->frame_control
);
2127 payload_len
= framelen
> hdrlen
? framelen
- hdrlen
: 0;
2129 /* XXX TBD Might just have to abort and return an error */
2130 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2131 printk(KERN_ERR
"%s(): WARNING: Incomplete beacon "
2132 "sent to firmware. Sz=%u MAX=%u\n", __func__
,
2133 payload_len
, MWL8K_FJ_BEACON_MAXLEN
);
2135 if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2136 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
2138 if (payload
&& payload_len
)
2139 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
2141 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2149 struct mwl8k_cmd_update_sta_db
{
2150 struct mwl8k_cmd_pkt header
;
2152 /* See STADB_ACTION_TYPE */
2155 /* Peer MAC address */
2156 __u8 peer_addr
[ETH_ALEN
];
2160 /* Peer info - valid during add/update. */
2161 struct peer_capability_info peer_info
;
2162 } __attribute__((packed
));
2164 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw
*hw
,
2165 struct ieee80211_vif
*vif
, __u32 action
)
2167 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2168 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2169 struct mwl8k_cmd_update_sta_db
*cmd
;
2170 struct peer_capability_info
*peer_info
;
2171 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2175 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2179 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
2180 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2182 cmd
->action
= cpu_to_le32(action
);
2183 peer_info
= &cmd
->peer_info
;
2184 memcpy(cmd
->peer_addr
, mv_vif
->bssid
, ETH_ALEN
);
2187 case MWL8K_STA_DB_ADD_ENTRY
:
2188 case MWL8K_STA_DB_MODIFY_ENTRY
:
2189 /* Build peer_info block */
2190 peer_info
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
2191 peer_info
->basic_caps
= cpu_to_le16(info
->assoc_capability
);
2192 peer_info
->interop
= 1;
2193 peer_info
->amsdu_enabled
= 0;
2195 rates
= peer_info
->legacy_rates
;
2196 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2197 rates
[count
] = bitrates
[count
].hw_value
;
2199 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2201 mv_vif
->peer_id
= peer_info
->station_id
;
2205 case MWL8K_STA_DB_DEL_ENTRY
:
2206 case MWL8K_STA_DB_FLUSH
:
2208 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2210 mv_vif
->peer_id
= 0;
2221 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2223 #define MWL8K_FRAME_PROT_DISABLED 0x00
2224 #define MWL8K_FRAME_PROT_11G 0x07
2225 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2226 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2228 struct mwl8k_cmd_update_set_aid
{
2229 struct mwl8k_cmd_pkt header
;
2232 /* AP's MAC address (BSSID) */
2233 __u8 bssid
[ETH_ALEN
];
2234 __le16 protection_mode
;
2235 __u8 supp_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2236 } __attribute__((packed
));
2238 static int mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
2239 struct ieee80211_vif
*vif
)
2241 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2242 struct ieee80211_bss_conf
*info
= &mv_vif
->bss_info
;
2243 struct mwl8k_cmd_update_set_aid
*cmd
;
2244 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2249 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2253 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
2254 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2255 cmd
->aid
= cpu_to_le16(info
->aid
);
2257 memcpy(cmd
->bssid
, mv_vif
->bssid
, ETH_ALEN
);
2259 if (info
->use_cts_prot
) {
2260 prot_mode
= MWL8K_FRAME_PROT_11G
;
2262 switch (info
->ht_operation_mode
&
2263 IEEE80211_HT_OP_MODE_PROTECTION
) {
2264 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
2265 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
2267 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
2268 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
2271 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
2275 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
2277 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2278 cmd
->supp_rates
[count
] = bitrates
[count
].hw_value
;
2280 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2289 struct mwl8k_cmd_update_rateset
{
2290 struct mwl8k_cmd_pkt header
;
2291 __u8 legacy_rates
[MWL8K_RATE_INDEX_MAX_ARRAY
];
2293 /* Bitmap for supported MCS codes. */
2294 __u8 mcs_set
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2295 __u8 reserved
[MWL8K_IEEE_LEGACY_DATA_RATES
];
2296 } __attribute__((packed
));
2298 static int mwl8k_update_rateset(struct ieee80211_hw
*hw
,
2299 struct ieee80211_vif
*vif
)
2301 struct mwl8k_vif
*mv_vif
= MWL8K_VIF(vif
);
2302 struct mwl8k_cmd_update_rateset
*cmd
;
2303 struct ieee80211_rate
*bitrates
= mv_vif
->legacy_rates
;
2307 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2311 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
2312 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2314 for (count
= 0; count
< mv_vif
->legacy_nrates
; count
++)
2315 cmd
->legacy_rates
[count
] = bitrates
[count
].hw_value
;
2317 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2324 * CMD_USE_FIXED_RATE.
2326 #define MWL8K_RATE_TABLE_SIZE 8
2327 #define MWL8K_UCAST_RATE 0
2328 #define MWL8K_USE_AUTO_RATE 0x0002
2330 struct mwl8k_rate_entry
{
2331 /* Set to 1 if HT rate, 0 if legacy. */
2334 /* Set to 1 to use retry_count field. */
2335 __le32 enable_retry
;
2337 /* Specified legacy rate or MCS. */
2340 /* Number of allowed retries. */
2342 } __attribute__((packed
));
2344 struct mwl8k_rate_table
{
2345 /* 1 to allow specified rate and below */
2346 __le32 allow_rate_drop
;
2348 struct mwl8k_rate_entry rate_entry
[MWL8K_RATE_TABLE_SIZE
];
2349 } __attribute__((packed
));
2351 struct mwl8k_cmd_use_fixed_rate
{
2352 struct mwl8k_cmd_pkt header
;
2354 struct mwl8k_rate_table rate_table
;
2356 /* Unicast, Broadcast or Multicast */
2360 } __attribute__((packed
));
2362 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw
*hw
,
2363 u32 action
, u32 rate_type
, struct mwl8k_rate_table
*rate_table
)
2365 struct mwl8k_cmd_use_fixed_rate
*cmd
;
2369 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2373 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2374 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2376 cmd
->action
= cpu_to_le32(action
);
2377 cmd
->rate_type
= cpu_to_le32(rate_type
);
2379 if (rate_table
!= NULL
) {
2381 * Copy over each field manually so that endian
2382 * conversion can be done.
2384 cmd
->rate_table
.allow_rate_drop
=
2385 cpu_to_le32(rate_table
->allow_rate_drop
);
2386 cmd
->rate_table
.num_rates
=
2387 cpu_to_le32(rate_table
->num_rates
);
2389 for (count
= 0; count
< rate_table
->num_rates
; count
++) {
2390 struct mwl8k_rate_entry
*dst
=
2391 &cmd
->rate_table
.rate_entry
[count
];
2392 struct mwl8k_rate_entry
*src
=
2393 &rate_table
->rate_entry
[count
];
2395 dst
->is_ht_rate
= cpu_to_le32(src
->is_ht_rate
);
2396 dst
->enable_retry
= cpu_to_le32(src
->enable_retry
);
2397 dst
->rate
= cpu_to_le32(src
->rate
);
2398 dst
->retry_count
= cpu_to_le32(src
->retry_count
);
2402 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2410 * Interrupt handling.
2412 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
2414 struct ieee80211_hw
*hw
= dev_id
;
2415 struct mwl8k_priv
*priv
= hw
->priv
;
2418 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2419 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
2424 if (status
& MWL8K_A2H_INT_TX_DONE
)
2425 tasklet_schedule(&priv
->tx_reclaim_task
);
2427 if (status
& MWL8K_A2H_INT_RX_READY
) {
2428 while (rxq_process(hw
, 0, 1))
2429 rxq_refill(hw
, 0, 1);
2432 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
2433 if (priv
->hostcmd_wait
!= NULL
)
2434 complete(priv
->hostcmd_wait
);
2437 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
2438 if (!mutex_is_locked(&priv
->fw_mutex
) &&
2439 priv
->radio_on
&& priv
->pending_tx_pkts
)
2440 mwl8k_tx_start(priv
);
2448 * Core driver operations.
2450 static int mwl8k_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2452 struct mwl8k_priv
*priv
= hw
->priv
;
2453 int index
= skb_get_queue_mapping(skb
);
2456 if (priv
->current_channel
== NULL
) {
2457 printk(KERN_DEBUG
"%s: dropped TX frame since radio "
2458 "disabled\n", wiphy_name(hw
->wiphy
));
2460 return NETDEV_TX_OK
;
2463 rc
= mwl8k_txq_xmit(hw
, index
, skb
);
2468 static int mwl8k_start(struct ieee80211_hw
*hw
)
2470 struct mwl8k_priv
*priv
= hw
->priv
;
2473 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
2474 IRQF_SHARED
, MWL8K_NAME
, hw
);
2476 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
2477 wiphy_name(hw
->wiphy
));
2481 /* Enable tx reclaim tasklet */
2482 tasklet_enable(&priv
->tx_reclaim_task
);
2484 /* Enable interrupts */
2485 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2487 rc
= mwl8k_fw_lock(hw
);
2489 rc
= mwl8k_cmd_802_11_radio_enable(hw
);
2492 rc
= mwl8k_cmd_set_pre_scan(hw
);
2495 rc
= mwl8k_cmd_set_post_scan(hw
,
2496 "\x00\x00\x00\x00\x00\x00");
2499 rc
= mwl8k_cmd_setrateadaptmode(hw
, 0);
2502 rc
= mwl8k_set_wmm(hw
, 0);
2505 rc
= mwl8k_enable_sniffer(hw
, 0);
2507 mwl8k_fw_unlock(hw
);
2511 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2512 free_irq(priv
->pdev
->irq
, hw
);
2513 tasklet_disable(&priv
->tx_reclaim_task
);
2519 static void mwl8k_stop(struct ieee80211_hw
*hw
)
2521 struct mwl8k_priv
*priv
= hw
->priv
;
2524 mwl8k_cmd_802_11_radio_disable(hw
);
2526 ieee80211_stop_queues(hw
);
2528 /* Disable interrupts */
2529 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
2530 free_irq(priv
->pdev
->irq
, hw
);
2532 /* Stop finalize join worker */
2533 cancel_work_sync(&priv
->finalize_join_worker
);
2534 if (priv
->beacon_skb
!= NULL
)
2535 dev_kfree_skb(priv
->beacon_skb
);
2537 /* Stop tx reclaim tasklet */
2538 tasklet_disable(&priv
->tx_reclaim_task
);
2540 /* Return all skbs to mac80211 */
2541 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2542 mwl8k_txq_reclaim(hw
, i
, 1);
2545 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
2546 struct ieee80211_if_init_conf
*conf
)
2548 struct mwl8k_priv
*priv
= hw
->priv
;
2549 struct mwl8k_vif
*mwl8k_vif
;
2552 * We only support one active interface at a time.
2554 if (priv
->vif
!= NULL
)
2558 * We only support managed interfaces for now.
2560 if (conf
->type
!= NL80211_IFTYPE_STATION
)
2563 /* Clean out driver private area */
2564 mwl8k_vif
= MWL8K_VIF(conf
->vif
);
2565 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
2567 /* Set and save the mac address */
2568 mwl8k_set_mac_addr(hw
, conf
->mac_addr
);
2569 memcpy(mwl8k_vif
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
2571 /* Back pointer to parent config block */
2572 mwl8k_vif
->priv
= priv
;
2574 /* Setup initial PHY parameters */
2575 memcpy(mwl8k_vif
->legacy_rates
,
2576 priv
->rates
, sizeof(mwl8k_vif
->legacy_rates
));
2577 mwl8k_vif
->legacy_nrates
= ARRAY_SIZE(priv
->rates
);
2579 /* Set Initial sequence number to zero */
2580 mwl8k_vif
->seqno
= 0;
2582 priv
->vif
= conf
->vif
;
2583 priv
->current_channel
= NULL
;
2588 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
2589 struct ieee80211_if_init_conf
*conf
)
2591 struct mwl8k_priv
*priv
= hw
->priv
;
2593 if (priv
->vif
== NULL
)
2596 mwl8k_set_mac_addr(hw
, "\x00\x00\x00\x00\x00\x00");
2601 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
2603 struct ieee80211_conf
*conf
= &hw
->conf
;
2604 struct mwl8k_priv
*priv
= hw
->priv
;
2607 if (conf
->flags
& IEEE80211_CONF_IDLE
) {
2608 mwl8k_cmd_802_11_radio_disable(hw
);
2609 priv
->current_channel
= NULL
;
2613 rc
= mwl8k_fw_lock(hw
);
2617 rc
= mwl8k_cmd_802_11_radio_enable(hw
);
2621 rc
= mwl8k_cmd_set_rf_channel(hw
, conf
->channel
);
2625 priv
->current_channel
= conf
->channel
;
2627 if (conf
->power_level
> 18)
2628 conf
->power_level
= 18;
2629 rc
= mwl8k_cmd_802_11_rf_tx_power(hw
, conf
->power_level
);
2633 if (mwl8k_cmd_mimo_config(hw
, 0x7, 0x7))
2637 mwl8k_fw_unlock(hw
);
2642 static void mwl8k_bss_info_changed(struct ieee80211_hw
*hw
,
2643 struct ieee80211_vif
*vif
,
2644 struct ieee80211_bss_conf
*info
,
2647 struct mwl8k_priv
*priv
= hw
->priv
;
2648 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
2651 if (changed
& BSS_CHANGED_BSSID
)
2652 memcpy(mwl8k_vif
->bssid
, info
->bssid
, ETH_ALEN
);
2654 if ((changed
& BSS_CHANGED_ASSOC
) == 0)
2657 priv
->capture_beacon
= false;
2659 rc
= mwl8k_fw_lock(hw
);
2664 memcpy(&mwl8k_vif
->bss_info
, info
,
2665 sizeof(struct ieee80211_bss_conf
));
2668 rc
= mwl8k_update_rateset(hw
, vif
);
2672 /* Turn on rate adaptation */
2673 rc
= mwl8k_cmd_use_fixed_rate(hw
, MWL8K_USE_AUTO_RATE
,
2674 MWL8K_UCAST_RATE
, NULL
);
2678 /* Set radio preamble */
2679 rc
= mwl8k_set_radio_preamble(hw
, info
->use_short_preamble
);
2684 rc
= mwl8k_cmd_set_slot(hw
, info
->use_short_slot
);
2688 /* Update peer rate info */
2689 rc
= mwl8k_cmd_update_sta_db(hw
, vif
,
2690 MWL8K_STA_DB_MODIFY_ENTRY
);
2695 rc
= mwl8k_cmd_set_aid(hw
, vif
);
2700 * Finalize the join. Tell rx handler to process
2701 * next beacon from our BSSID.
2703 memcpy(priv
->capture_bssid
, mwl8k_vif
->bssid
, ETH_ALEN
);
2704 priv
->capture_beacon
= true;
2706 rc
= mwl8k_cmd_update_sta_db(hw
, vif
, MWL8K_STA_DB_DEL_ENTRY
);
2707 memset(&mwl8k_vif
->bss_info
, 0,
2708 sizeof(struct ieee80211_bss_conf
));
2709 memset(mwl8k_vif
->bssid
, 0, ETH_ALEN
);
2713 mwl8k_fw_unlock(hw
);
2716 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
2717 int mc_count
, struct dev_addr_list
*mclist
)
2719 struct mwl8k_cmd_pkt
*cmd
;
2722 * Synthesize and return a command packet that programs the
2723 * hardware multicast address filter. At this point we don't
2724 * know whether FIF_ALLMULTI is being requested, but if it is,
2725 * we'll end up throwing this packet away and creating a new
2726 * one in mwl8k_configure_filter().
2728 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 0, mc_count
, mclist
);
2730 return (unsigned long)cmd
;
2733 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
2734 unsigned int changed_flags
,
2735 unsigned int *total_flags
,
2738 struct mwl8k_priv
*priv
= hw
->priv
;
2739 struct mwl8k_cmd_pkt
*cmd
;
2741 /* Clear unsupported feature flags */
2742 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
2744 if (mwl8k_fw_lock(hw
))
2747 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
2748 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
) {
2750 * Disable the BSS filter.
2752 mwl8k_cmd_set_pre_scan(hw
);
2757 * Enable the BSS filter.
2759 * If there is an active STA interface, use that
2760 * interface's BSSID, otherwise use a dummy one
2761 * (where the OUI part needs to be nonzero for
2762 * the BSSID to be accepted by POST_SCAN).
2764 bssid
= "\x01\x00\x00\x00\x00\x00";
2765 if (priv
->vif
!= NULL
)
2766 bssid
= MWL8K_VIF(priv
->vif
)->bssid
;
2768 mwl8k_cmd_set_post_scan(hw
, bssid
);
2772 cmd
= (void *)(unsigned long)multicast
;
2775 * If FIF_ALLMULTI is being requested, throw away the command
2776 * packet that ->prepare_multicast() built and replace it with
2777 * a command packet that enables reception of all multicast
2780 if (*total_flags
& FIF_ALLMULTI
) {
2782 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 1, 0, NULL
);
2786 mwl8k_post_cmd(hw
, cmd
);
2790 mwl8k_fw_unlock(hw
);
2793 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
2795 return mwl8k_rts_threshold(hw
, MWL8K_CMD_SET
, value
);
2798 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
2799 const struct ieee80211_tx_queue_params
*params
)
2801 struct mwl8k_priv
*priv
= hw
->priv
;
2804 rc
= mwl8k_fw_lock(hw
);
2806 if (!priv
->wmm_enabled
)
2807 rc
= mwl8k_set_wmm(hw
, 1);
2810 rc
= mwl8k_set_edca_params(hw
, queue
,
2816 mwl8k_fw_unlock(hw
);
2822 static int mwl8k_get_tx_stats(struct ieee80211_hw
*hw
,
2823 struct ieee80211_tx_queue_stats
*stats
)
2825 struct mwl8k_priv
*priv
= hw
->priv
;
2826 struct mwl8k_tx_queue
*txq
;
2829 spin_lock_bh(&priv
->tx_lock
);
2830 for (index
= 0; index
< MWL8K_TX_QUEUES
; index
++) {
2831 txq
= priv
->txq
+ index
;
2832 memcpy(&stats
[index
], &txq
->tx_stats
,
2833 sizeof(struct ieee80211_tx_queue_stats
));
2835 spin_unlock_bh(&priv
->tx_lock
);
2840 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
2841 struct ieee80211_low_level_stats
*stats
)
2843 return mwl8k_cmd_802_11_get_stat(hw
, stats
);
2846 static const struct ieee80211_ops mwl8k_ops
= {
2848 .start
= mwl8k_start
,
2850 .add_interface
= mwl8k_add_interface
,
2851 .remove_interface
= mwl8k_remove_interface
,
2852 .config
= mwl8k_config
,
2853 .bss_info_changed
= mwl8k_bss_info_changed
,
2854 .prepare_multicast
= mwl8k_prepare_multicast
,
2855 .configure_filter
= mwl8k_configure_filter
,
2856 .set_rts_threshold
= mwl8k_set_rts_threshold
,
2857 .conf_tx
= mwl8k_conf_tx
,
2858 .get_tx_stats
= mwl8k_get_tx_stats
,
2859 .get_stats
= mwl8k_get_stats
,
2862 static void mwl8k_tx_reclaim_handler(unsigned long data
)
2865 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*) data
;
2866 struct mwl8k_priv
*priv
= hw
->priv
;
2868 spin_lock_bh(&priv
->tx_lock
);
2869 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2870 mwl8k_txq_reclaim(hw
, i
, 0);
2872 if (priv
->tx_wait
!= NULL
&& !priv
->pending_tx_pkts
) {
2873 complete(priv
->tx_wait
);
2874 priv
->tx_wait
= NULL
;
2876 spin_unlock_bh(&priv
->tx_lock
);
2879 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
2881 struct mwl8k_priv
*priv
=
2882 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
2883 struct sk_buff
*skb
= priv
->beacon_skb
;
2884 u8 dtim
= MWL8K_VIF(priv
->vif
)->bss_info
.dtim_period
;
2886 mwl8k_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim
);
2889 priv
->beacon_skb
= NULL
;
2892 static int __devinit
mwl8k_probe(struct pci_dev
*pdev
,
2893 const struct pci_device_id
*id
)
2895 static int printed_version
= 0;
2896 struct ieee80211_hw
*hw
;
2897 struct mwl8k_priv
*priv
;
2901 if (!printed_version
) {
2902 printk(KERN_INFO
"%s version %s\n", MWL8K_DESC
, MWL8K_VERSION
);
2903 printed_version
= 1;
2906 rc
= pci_enable_device(pdev
);
2908 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
2913 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
2915 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
2920 pci_set_master(pdev
);
2922 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
2924 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
2932 priv
->wmm_enabled
= false;
2933 priv
->pending_tx_pkts
= 0;
2935 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
2936 pci_set_drvdata(pdev
, hw
);
2938 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
2939 if (priv
->regs
== NULL
) {
2940 printk(KERN_ERR
"%s: Cannot map device memory\n",
2941 wiphy_name(hw
->wiphy
));
2945 memcpy(priv
->channels
, mwl8k_channels
, sizeof(mwl8k_channels
));
2946 priv
->band
.band
= IEEE80211_BAND_2GHZ
;
2947 priv
->band
.channels
= priv
->channels
;
2948 priv
->band
.n_channels
= ARRAY_SIZE(mwl8k_channels
);
2949 priv
->band
.bitrates
= priv
->rates
;
2950 priv
->band
.n_bitrates
= ARRAY_SIZE(mwl8k_rates
);
2951 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
2953 BUILD_BUG_ON(sizeof(priv
->rates
) != sizeof(mwl8k_rates
));
2954 memcpy(priv
->rates
, mwl8k_rates
, sizeof(mwl8k_rates
));
2957 * Extra headroom is the size of the required DMA header
2958 * minus the size of the smallest 802.11 frame (CTS frame).
2960 hw
->extra_tx_headroom
=
2961 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
2963 hw
->channel_change_time
= 10;
2965 hw
->queues
= MWL8K_TX_QUEUES
;
2967 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
2969 /* Set rssi and noise values to dBm */
2970 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
| IEEE80211_HW_NOISE_DBM
;
2971 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
2974 /* Set default radio state and preamble */
2976 priv
->radio_short_preamble
= 0;
2978 /* Finalize join worker */
2979 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
2981 /* TX reclaim tasklet */
2982 tasklet_init(&priv
->tx_reclaim_task
,
2983 mwl8k_tx_reclaim_handler
, (unsigned long)hw
);
2984 tasklet_disable(&priv
->tx_reclaim_task
);
2986 /* Power management cookie */
2987 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
2988 if (priv
->cookie
== NULL
)
2991 rc
= mwl8k_rxq_init(hw
, 0);
2994 rxq_refill(hw
, 0, INT_MAX
);
2996 mutex_init(&priv
->fw_mutex
);
2997 priv
->fw_mutex_owner
= NULL
;
2998 priv
->fw_mutex_depth
= 0;
2999 priv
->hostcmd_wait
= NULL
;
3001 spin_lock_init(&priv
->tx_lock
);
3003 priv
->tx_wait
= NULL
;
3005 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
3006 rc
= mwl8k_txq_init(hw
, i
);
3008 goto err_free_queues
;
3011 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3012 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3013 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
3014 iowrite32(0xffffffff, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3016 rc
= request_irq(priv
->pdev
->irq
, &mwl8k_interrupt
,
3017 IRQF_SHARED
, MWL8K_NAME
, hw
);
3019 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
3020 wiphy_name(hw
->wiphy
));
3021 goto err_free_queues
;
3024 /* Reset firmware and hardware */
3025 mwl8k_hw_reset(priv
);
3027 /* Ask userland hotplug daemon for the device firmware */
3028 rc
= mwl8k_request_firmware(priv
, (u32
)id
->driver_data
);
3030 printk(KERN_ERR
"%s: Firmware files not found\n",
3031 wiphy_name(hw
->wiphy
));
3035 /* Load firmware into hardware */
3036 rc
= mwl8k_load_firmware(hw
);
3038 printk(KERN_ERR
"%s: Cannot start firmware\n",
3039 wiphy_name(hw
->wiphy
));
3040 goto err_stop_firmware
;
3043 /* Reclaim memory once firmware is successfully loaded */
3044 mwl8k_release_firmware(priv
);
3047 * Temporarily enable interrupts. Initial firmware host
3048 * commands use interrupts and avoids polling. Disable
3049 * interrupts when done.
3051 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3053 /* Get config data, mac addrs etc */
3054 rc
= mwl8k_cmd_get_hw_spec(hw
);
3056 printk(KERN_ERR
"%s: Cannot initialise firmware\n",
3057 wiphy_name(hw
->wiphy
));
3058 goto err_stop_firmware
;
3061 /* Turn radio off */
3062 rc
= mwl8k_cmd_802_11_radio_disable(hw
);
3064 printk(KERN_ERR
"%s: Cannot disable\n", wiphy_name(hw
->wiphy
));
3065 goto err_stop_firmware
;
3068 /* Clear MAC address */
3069 rc
= mwl8k_set_mac_addr(hw
, "\x00\x00\x00\x00\x00\x00");
3071 printk(KERN_ERR
"%s: Cannot clear MAC address\n",
3072 wiphy_name(hw
->wiphy
));
3073 goto err_stop_firmware
;
3076 /* Disable interrupts */
3077 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3078 free_irq(priv
->pdev
->irq
, hw
);
3080 rc
= ieee80211_register_hw(hw
);
3082 printk(KERN_ERR
"%s: Cannot register device\n",
3083 wiphy_name(hw
->wiphy
));
3084 goto err_stop_firmware
;
3087 printk(KERN_INFO
"%s: 88w%u v%d, %pM, firmware version %u.%u.%u.%u\n",
3088 wiphy_name(hw
->wiphy
), priv
->part_num
, priv
->hw_rev
,
3089 hw
->wiphy
->perm_addr
,
3090 (priv
->fw_rev
>> 24) & 0xff, (priv
->fw_rev
>> 16) & 0xff,
3091 (priv
->fw_rev
>> 8) & 0xff, priv
->fw_rev
& 0xff);
3096 mwl8k_hw_reset(priv
);
3097 mwl8k_release_firmware(priv
);
3100 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3101 free_irq(priv
->pdev
->irq
, hw
);
3104 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3105 mwl8k_txq_deinit(hw
, i
);
3106 mwl8k_rxq_deinit(hw
, 0);
3109 if (priv
->cookie
!= NULL
)
3110 pci_free_consistent(priv
->pdev
, 4,
3111 priv
->cookie
, priv
->cookie_dma
);
3113 if (priv
->regs
!= NULL
)
3114 pci_iounmap(pdev
, priv
->regs
);
3116 pci_set_drvdata(pdev
, NULL
);
3117 ieee80211_free_hw(hw
);
3120 pci_release_regions(pdev
);
3121 pci_disable_device(pdev
);
3126 static void __devexit
mwl8k_shutdown(struct pci_dev
*pdev
)
3128 printk(KERN_ERR
"===>%s(%u)\n", __func__
, __LINE__
);
3131 static void __devexit
mwl8k_remove(struct pci_dev
*pdev
)
3133 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
3134 struct mwl8k_priv
*priv
;
3141 ieee80211_stop_queues(hw
);
3143 ieee80211_unregister_hw(hw
);
3145 /* Remove tx reclaim tasklet */
3146 tasklet_kill(&priv
->tx_reclaim_task
);
3149 mwl8k_hw_reset(priv
);
3151 /* Return all skbs to mac80211 */
3152 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3153 mwl8k_txq_reclaim(hw
, i
, 1);
3155 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3156 mwl8k_txq_deinit(hw
, i
);
3158 mwl8k_rxq_deinit(hw
, 0);
3160 pci_free_consistent(priv
->pdev
, 4, priv
->cookie
, priv
->cookie_dma
);
3162 pci_iounmap(pdev
, priv
->regs
);
3163 pci_set_drvdata(pdev
, NULL
);
3164 ieee80211_free_hw(hw
);
3165 pci_release_regions(pdev
);
3166 pci_disable_device(pdev
);
3169 static struct pci_driver mwl8k_driver
= {
3171 .id_table
= mwl8k_table
,
3172 .probe
= mwl8k_probe
,
3173 .remove
= __devexit_p(mwl8k_remove
),
3174 .shutdown
= __devexit_p(mwl8k_shutdown
),
3177 static int __init
mwl8k_init(void)
3179 return pci_register_driver(&mwl8k_driver
);
3182 static void __exit
mwl8k_exit(void)
3184 pci_unregister_driver(&mwl8k_driver
);
3187 module_init(mwl8k_init
);
3188 module_exit(mwl8k_exit
);
3190 MODULE_DESCRIPTION(MWL8K_DESC
);
3191 MODULE_VERSION(MWL8K_VERSION
);
3192 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3193 MODULE_LICENSE("GPL");