2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008, 2009, 2010 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 <linux/slab.h>
23 #include <net/mac80211.h>
24 #include <linux/moduleparam.h>
25 #include <linux/firmware.h>
26 #include <linux/workqueue.h>
28 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
29 #define MWL8K_NAME KBUILD_MODNAME
30 #define MWL8K_VERSION "0.12"
32 /* Module parameters */
33 static unsigned ap_mode_default
;
34 module_param(ap_mode_default
, bool, 0);
35 MODULE_PARM_DESC(ap_mode_default
,
36 "Set to 1 to make ap mode the default instead of sta mode");
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
92 void (*rxd_init
)(void *rxd
, dma_addr_t next_dma_addr
);
93 void (*rxd_refill
)(void *rxd
, dma_addr_t addr
, int len
);
94 int (*rxd_process
)(void *rxd
, struct ieee80211_rx_status
*status
,
95 __le16
*qos
, s8
*noise
);
98 struct mwl8k_device_info
{
103 struct rxd_ops
*ap_rxd_ops
;
107 struct mwl8k_rx_queue
{
110 /* hw receives here */
113 /* refill descs here */
120 DEFINE_DMA_UNMAP_ADDR(dma
);
124 struct mwl8k_tx_queue
{
125 /* hw transmits here */
128 /* sw appends here */
132 struct mwl8k_tx_desc
*txd
;
134 struct sk_buff
**skb
;
138 struct ieee80211_hw
*hw
;
139 struct pci_dev
*pdev
;
141 struct mwl8k_device_info
*device_info
;
147 const struct firmware
*fw_helper
;
148 const struct firmware
*fw_ucode
;
150 /* hardware/firmware parameters */
152 struct rxd_ops
*rxd_ops
;
153 struct ieee80211_supported_band band_24
;
154 struct ieee80211_channel channels_24
[14];
155 struct ieee80211_rate rates_24
[14];
156 struct ieee80211_supported_band band_50
;
157 struct ieee80211_channel channels_50
[4];
158 struct ieee80211_rate rates_50
[9];
159 u32 ap_macids_supported
;
160 u32 sta_macids_supported
;
162 /* firmware access */
163 struct mutex fw_mutex
;
164 struct task_struct
*fw_mutex_owner
;
166 struct completion
*hostcmd_wait
;
168 /* lock held over TX and TX reap */
171 /* TX quiesce completion, protected by fw_mutex and tx_lock */
172 struct completion
*tx_wait
;
174 /* List of interfaces. */
176 struct list_head vif_list
;
178 /* power management status cookie from firmware */
180 dma_addr_t cookie_dma
;
187 * Running count of TX packets in flight, to avoid
188 * iterating over the transmit rings each time.
192 struct mwl8k_rx_queue rxq
[MWL8K_RX_QUEUES
];
193 struct mwl8k_tx_queue txq
[MWL8K_TX_QUEUES
];
196 bool radio_short_preamble
;
197 bool sniffer_enabled
;
200 /* XXX need to convert this to handle multiple interfaces */
202 u8 capture_bssid
[ETH_ALEN
];
203 struct sk_buff
*beacon_skb
;
206 * This FJ worker has to be global as it is scheduled from the
207 * RX handler. At this point we don't know which interface it
208 * belongs to until the list of bssids waiting to complete join
211 struct work_struct finalize_join_worker
;
213 /* Tasklet to perform TX reclaim. */
214 struct tasklet_struct poll_tx_task
;
216 /* Tasklet to perform RX. */
217 struct tasklet_struct poll_rx_task
;
219 /* Most recently reported noise in dBm */
223 * preserve the queue configurations so they can be restored if/when
224 * the firmware image is swapped.
226 struct ieee80211_tx_queue_params wmm_params
[MWL8K_TX_QUEUES
];
228 /* async firmware loading state */
232 struct completion firmware_loading_complete
;
235 #define MAX_WEP_KEY_LEN 13
236 #define NUM_WEP_KEYS 4
238 /* Per interface specific private data */
240 struct list_head list
;
241 struct ieee80211_vif
*vif
;
243 /* Firmware macid for this vif. */
246 /* Non AMPDU sequence number assigned by driver. */
252 u8 key
[sizeof(struct ieee80211_key_conf
) + MAX_WEP_KEY_LEN
];
253 } wep_key_conf
[NUM_WEP_KEYS
];
258 /* A flag to indicate is HW crypto is enabled for this bssid */
259 bool is_hw_crypto_enabled
;
261 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
262 #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
265 /* Index into station database. Returned by UPDATE_STADB. */
268 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
270 static const struct ieee80211_channel mwl8k_channels_24
[] = {
271 { .center_freq
= 2412, .hw_value
= 1, },
272 { .center_freq
= 2417, .hw_value
= 2, },
273 { .center_freq
= 2422, .hw_value
= 3, },
274 { .center_freq
= 2427, .hw_value
= 4, },
275 { .center_freq
= 2432, .hw_value
= 5, },
276 { .center_freq
= 2437, .hw_value
= 6, },
277 { .center_freq
= 2442, .hw_value
= 7, },
278 { .center_freq
= 2447, .hw_value
= 8, },
279 { .center_freq
= 2452, .hw_value
= 9, },
280 { .center_freq
= 2457, .hw_value
= 10, },
281 { .center_freq
= 2462, .hw_value
= 11, },
282 { .center_freq
= 2467, .hw_value
= 12, },
283 { .center_freq
= 2472, .hw_value
= 13, },
284 { .center_freq
= 2484, .hw_value
= 14, },
287 static const struct ieee80211_rate mwl8k_rates_24
[] = {
288 { .bitrate
= 10, .hw_value
= 2, },
289 { .bitrate
= 20, .hw_value
= 4, },
290 { .bitrate
= 55, .hw_value
= 11, },
291 { .bitrate
= 110, .hw_value
= 22, },
292 { .bitrate
= 220, .hw_value
= 44, },
293 { .bitrate
= 60, .hw_value
= 12, },
294 { .bitrate
= 90, .hw_value
= 18, },
295 { .bitrate
= 120, .hw_value
= 24, },
296 { .bitrate
= 180, .hw_value
= 36, },
297 { .bitrate
= 240, .hw_value
= 48, },
298 { .bitrate
= 360, .hw_value
= 72, },
299 { .bitrate
= 480, .hw_value
= 96, },
300 { .bitrate
= 540, .hw_value
= 108, },
301 { .bitrate
= 720, .hw_value
= 144, },
304 static const struct ieee80211_channel mwl8k_channels_50
[] = {
305 { .center_freq
= 5180, .hw_value
= 36, },
306 { .center_freq
= 5200, .hw_value
= 40, },
307 { .center_freq
= 5220, .hw_value
= 44, },
308 { .center_freq
= 5240, .hw_value
= 48, },
311 static const struct ieee80211_rate mwl8k_rates_50
[] = {
312 { .bitrate
= 60, .hw_value
= 12, },
313 { .bitrate
= 90, .hw_value
= 18, },
314 { .bitrate
= 120, .hw_value
= 24, },
315 { .bitrate
= 180, .hw_value
= 36, },
316 { .bitrate
= 240, .hw_value
= 48, },
317 { .bitrate
= 360, .hw_value
= 72, },
318 { .bitrate
= 480, .hw_value
= 96, },
319 { .bitrate
= 540, .hw_value
= 108, },
320 { .bitrate
= 720, .hw_value
= 144, },
323 /* Set or get info from Firmware */
324 #define MWL8K_CMD_GET 0x0000
325 #define MWL8K_CMD_SET 0x0001
326 #define MWL8K_CMD_SET_LIST 0x0002
328 /* Firmware command codes */
329 #define MWL8K_CMD_CODE_DNLD 0x0001
330 #define MWL8K_CMD_GET_HW_SPEC 0x0003
331 #define MWL8K_CMD_SET_HW_SPEC 0x0004
332 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
333 #define MWL8K_CMD_GET_STAT 0x0014
334 #define MWL8K_CMD_RADIO_CONTROL 0x001c
335 #define MWL8K_CMD_RF_TX_POWER 0x001e
336 #define MWL8K_CMD_TX_POWER 0x001f
337 #define MWL8K_CMD_RF_ANTENNA 0x0020
338 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
339 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
340 #define MWL8K_CMD_SET_POST_SCAN 0x0108
341 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
342 #define MWL8K_CMD_SET_AID 0x010d
343 #define MWL8K_CMD_SET_RATE 0x0110
344 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
345 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
346 #define MWL8K_CMD_SET_SLOT 0x0114
347 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
348 #define MWL8K_CMD_SET_WMM_MODE 0x0123
349 #define MWL8K_CMD_MIMO_CONFIG 0x0125
350 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
351 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
352 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
353 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
354 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
355 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
356 #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
357 #define MWL8K_CMD_UPDATE_STADB 0x1123
359 static const char *mwl8k_cmd_name(__le16 cmd
, char *buf
, int bufsize
)
361 u16 command
= le16_to_cpu(cmd
);
363 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
364 snprintf(buf, bufsize, "%s", #x);\
367 switch (command
& ~0x8000) {
368 MWL8K_CMDNAME(CODE_DNLD
);
369 MWL8K_CMDNAME(GET_HW_SPEC
);
370 MWL8K_CMDNAME(SET_HW_SPEC
);
371 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
372 MWL8K_CMDNAME(GET_STAT
);
373 MWL8K_CMDNAME(RADIO_CONTROL
);
374 MWL8K_CMDNAME(RF_TX_POWER
);
375 MWL8K_CMDNAME(TX_POWER
);
376 MWL8K_CMDNAME(RF_ANTENNA
);
377 MWL8K_CMDNAME(SET_BEACON
);
378 MWL8K_CMDNAME(SET_PRE_SCAN
);
379 MWL8K_CMDNAME(SET_POST_SCAN
);
380 MWL8K_CMDNAME(SET_RF_CHANNEL
);
381 MWL8K_CMDNAME(SET_AID
);
382 MWL8K_CMDNAME(SET_RATE
);
383 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
384 MWL8K_CMDNAME(RTS_THRESHOLD
);
385 MWL8K_CMDNAME(SET_SLOT
);
386 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
387 MWL8K_CMDNAME(SET_WMM_MODE
);
388 MWL8K_CMDNAME(MIMO_CONFIG
);
389 MWL8K_CMDNAME(USE_FIXED_RATE
);
390 MWL8K_CMDNAME(ENABLE_SNIFFER
);
391 MWL8K_CMDNAME(SET_MAC_ADDR
);
392 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
393 MWL8K_CMDNAME(BSS_START
);
394 MWL8K_CMDNAME(SET_NEW_STN
);
395 MWL8K_CMDNAME(UPDATE_ENCRYPTION
);
396 MWL8K_CMDNAME(UPDATE_STADB
);
398 snprintf(buf
, bufsize
, "0x%x", cmd
);
405 /* Hardware and firmware reset */
406 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
408 iowrite32(MWL8K_H2A_INT_RESET
,
409 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
410 iowrite32(MWL8K_H2A_INT_RESET
,
411 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
415 /* Release fw image */
416 static void mwl8k_release_fw(const struct firmware
**fw
)
420 release_firmware(*fw
);
424 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
426 mwl8k_release_fw(&priv
->fw_ucode
);
427 mwl8k_release_fw(&priv
->fw_helper
);
430 /* states for asynchronous f/w loading */
431 static void mwl8k_fw_state_machine(const struct firmware
*fw
, void *context
);
434 FW_STATE_LOADING_PREF
,
435 FW_STATE_LOADING_ALT
,
439 /* Request fw image */
440 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
441 const char *fname
, const struct firmware
**fw
,
444 /* release current image */
446 mwl8k_release_fw(fw
);
449 return request_firmware_nowait(THIS_MODULE
, 1, fname
,
450 &priv
->pdev
->dev
, GFP_KERNEL
,
451 priv
, mwl8k_fw_state_machine
);
453 return request_firmware(fw
, fname
, &priv
->pdev
->dev
);
456 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, char *fw_image
,
459 struct mwl8k_device_info
*di
= priv
->device_info
;
462 if (di
->helper_image
!= NULL
) {
464 rc
= mwl8k_request_fw(priv
, di
->helper_image
,
465 &priv
->fw_helper
, true);
467 rc
= mwl8k_request_fw(priv
, di
->helper_image
,
468 &priv
->fw_helper
, false);
470 printk(KERN_ERR
"%s: Error requesting helper fw %s\n",
471 pci_name(priv
->pdev
), di
->helper_image
);
479 * if we get here, no helper image is needed. Skip the
480 * FW_STATE_INIT state.
482 priv
->fw_state
= FW_STATE_LOADING_PREF
;
483 rc
= mwl8k_request_fw(priv
, fw_image
,
487 rc
= mwl8k_request_fw(priv
, fw_image
,
488 &priv
->fw_ucode
, false);
490 printk(KERN_ERR
"%s: Error requesting firmware file %s\n",
491 pci_name(priv
->pdev
), fw_image
);
492 mwl8k_release_fw(&priv
->fw_helper
);
499 struct mwl8k_cmd_pkt
{
512 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
514 void __iomem
*regs
= priv
->regs
;
518 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
519 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
522 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
523 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
524 iowrite32(MWL8K_H2A_INT_DOORBELL
,
525 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
526 iowrite32(MWL8K_H2A_INT_DUMMY
,
527 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
533 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
534 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
535 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
543 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
545 return loops
? 0 : -ETIMEDOUT
;
548 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
549 const u8
*data
, size_t length
)
551 struct mwl8k_cmd_pkt
*cmd
;
555 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
559 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
566 int block_size
= length
> 256 ? 256 : length
;
568 memcpy(cmd
->payload
, data
+ done
, block_size
);
569 cmd
->length
= cpu_to_le16(block_size
);
571 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
572 sizeof(*cmd
) + block_size
);
577 length
-= block_size
;
582 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
590 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
591 const u8
*data
, size_t length
)
593 unsigned char *buffer
;
594 int may_continue
, rc
= 0;
595 u32 done
, prev_block_size
;
597 buffer
= kmalloc(1024, GFP_KERNEL
);
604 while (may_continue
> 0) {
607 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
608 if (block_size
& 1) {
612 done
+= prev_block_size
;
613 length
-= prev_block_size
;
616 if (block_size
> 1024 || block_size
> length
) {
626 if (block_size
== 0) {
633 prev_block_size
= block_size
;
634 memcpy(buffer
, data
+ done
, block_size
);
636 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
641 if (!rc
&& length
!= 0)
649 static int mwl8k_load_firmware(struct ieee80211_hw
*hw
)
651 struct mwl8k_priv
*priv
= hw
->priv
;
652 const struct firmware
*fw
= priv
->fw_ucode
;
656 if (!memcmp(fw
->data
, "\x01\x00\x00\x00", 4)) {
657 const struct firmware
*helper
= priv
->fw_helper
;
659 if (helper
== NULL
) {
660 printk(KERN_ERR
"%s: helper image needed but none "
661 "given\n", pci_name(priv
->pdev
));
665 rc
= mwl8k_load_fw_image(priv
, helper
->data
, helper
->size
);
667 printk(KERN_ERR
"%s: unable to load firmware "
668 "helper image\n", pci_name(priv
->pdev
));
673 rc
= mwl8k_feed_fw_image(priv
, fw
->data
, fw
->size
);
675 rc
= mwl8k_load_fw_image(priv
, fw
->data
, fw
->size
);
679 printk(KERN_ERR
"%s: unable to load firmware image\n",
680 pci_name(priv
->pdev
));
684 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
690 ready_code
= ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
691 if (ready_code
== MWL8K_FWAP_READY
) {
694 } else if (ready_code
== MWL8K_FWSTA_READY
) {
703 return loops
? 0 : -ETIMEDOUT
;
707 /* DMA header used by firmware and hardware. */
708 struct mwl8k_dma_data
{
710 struct ieee80211_hdr wh
;
714 /* Routines to add/remove DMA header from skb. */
715 static inline void mwl8k_remove_dma_header(struct sk_buff
*skb
, __le16 qos
)
717 struct mwl8k_dma_data
*tr
;
720 tr
= (struct mwl8k_dma_data
*)skb
->data
;
721 hdrlen
= ieee80211_hdrlen(tr
->wh
.frame_control
);
723 if (hdrlen
!= sizeof(tr
->wh
)) {
724 if (ieee80211_is_data_qos(tr
->wh
.frame_control
)) {
725 memmove(tr
->data
- hdrlen
, &tr
->wh
, hdrlen
- 2);
726 *((__le16
*)(tr
->data
- 2)) = qos
;
728 memmove(tr
->data
- hdrlen
, &tr
->wh
, hdrlen
);
732 if (hdrlen
!= sizeof(*tr
))
733 skb_pull(skb
, sizeof(*tr
) - hdrlen
);
737 mwl8k_add_dma_header(struct sk_buff
*skb
, int tail_pad
)
739 struct ieee80211_hdr
*wh
;
742 struct mwl8k_dma_data
*tr
;
745 * Add a firmware DMA header; the firmware requires that we
746 * present a 2-byte payload length followed by a 4-address
747 * header (without QoS field), followed (optionally) by any
748 * WEP/ExtIV header (but only filled in for CCMP).
750 wh
= (struct ieee80211_hdr
*)skb
->data
;
752 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
753 reqd_hdrlen
= sizeof(*tr
);
755 if (hdrlen
!= reqd_hdrlen
)
756 skb_push(skb
, reqd_hdrlen
- hdrlen
);
758 if (ieee80211_is_data_qos(wh
->frame_control
))
759 hdrlen
-= IEEE80211_QOS_CTL_LEN
;
761 tr
= (struct mwl8k_dma_data
*)skb
->data
;
763 memmove(&tr
->wh
, wh
, hdrlen
);
764 if (hdrlen
!= sizeof(tr
->wh
))
765 memset(((void *)&tr
->wh
) + hdrlen
, 0, sizeof(tr
->wh
) - hdrlen
);
768 * Firmware length is the length of the fully formed "802.11
769 * payload". That is, everything except for the 802.11 header.
770 * This includes all crypto material including the MIC.
772 tr
->fwlen
= cpu_to_le16(skb
->len
- sizeof(*tr
) + tail_pad
);
775 static void mwl8k_encapsulate_tx_frame(struct sk_buff
*skb
)
777 struct ieee80211_hdr
*wh
;
778 struct ieee80211_tx_info
*tx_info
;
779 struct ieee80211_key_conf
*key_conf
;
782 wh
= (struct ieee80211_hdr
*)skb
->data
;
784 tx_info
= IEEE80211_SKB_CB(skb
);
787 if (ieee80211_is_data(wh
->frame_control
))
788 key_conf
= tx_info
->control
.hw_key
;
791 * Make sure the packet header is in the DMA header format (4-address
792 * without QoS), the necessary crypto padding between the header and the
793 * payload has already been provided by mac80211, but it doesn't add tail
794 * padding when HW crypto is enabled.
796 * We have the following trailer padding requirements:
797 * - WEP: 4 trailer bytes (ICV)
798 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
799 * - CCMP: 8 trailer bytes (MIC)
802 if (key_conf
!= NULL
) {
803 switch (key_conf
->cipher
) {
804 case WLAN_CIPHER_SUITE_WEP40
:
805 case WLAN_CIPHER_SUITE_WEP104
:
808 case WLAN_CIPHER_SUITE_TKIP
:
811 case WLAN_CIPHER_SUITE_CCMP
:
816 mwl8k_add_dma_header(skb
, data_pad
);
820 * Packet reception for 88w8366 AP firmware.
822 struct mwl8k_rxd_8366_ap
{
826 __le32 pkt_phys_addr
;
827 __le32 next_rxd_phys_addr
;
831 __le32 hw_noise_floor_info
;
840 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
841 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
842 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
844 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
846 /* 8366 AP rx_status bits */
847 #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
848 #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
849 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
850 #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
851 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
853 static void mwl8k_rxd_8366_ap_init(void *_rxd
, dma_addr_t next_dma_addr
)
855 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
857 rxd
->next_rxd_phys_addr
= cpu_to_le32(next_dma_addr
);
858 rxd
->rx_ctrl
= MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST
;
861 static void mwl8k_rxd_8366_ap_refill(void *_rxd
, dma_addr_t addr
, int len
)
863 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
865 rxd
->pkt_len
= cpu_to_le16(len
);
866 rxd
->pkt_phys_addr
= cpu_to_le32(addr
);
872 mwl8k_rxd_8366_ap_process(void *_rxd
, struct ieee80211_rx_status
*status
,
873 __le16
*qos
, s8
*noise
)
875 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
877 if (!(rxd
->rx_ctrl
& MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST
))
881 memset(status
, 0, sizeof(*status
));
883 status
->signal
= -rxd
->rssi
;
884 *noise
= -rxd
->noise_floor
;
886 if (rxd
->rate
& MWL8K_8366_AP_RATE_INFO_MCS_FORMAT
) {
887 status
->flag
|= RX_FLAG_HT
;
888 if (rxd
->rate
& MWL8K_8366_AP_RATE_INFO_40MHZ
)
889 status
->flag
|= RX_FLAG_40MHZ
;
890 status
->rate_idx
= MWL8K_8366_AP_RATE_INFO_RATEID(rxd
->rate
);
894 for (i
= 0; i
< ARRAY_SIZE(mwl8k_rates_24
); i
++) {
895 if (mwl8k_rates_24
[i
].hw_value
== rxd
->rate
) {
896 status
->rate_idx
= i
;
902 if (rxd
->channel
> 14) {
903 status
->band
= IEEE80211_BAND_5GHZ
;
904 if (!(status
->flag
& RX_FLAG_HT
))
905 status
->rate_idx
-= 5;
907 status
->band
= IEEE80211_BAND_2GHZ
;
909 status
->freq
= ieee80211_channel_to_frequency(rxd
->channel
,
912 *qos
= rxd
->qos_control
;
914 if ((rxd
->rx_status
!= MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR
) &&
915 (rxd
->rx_status
& MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK
) &&
916 (rxd
->rx_status
& MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR
))
917 status
->flag
|= RX_FLAG_MMIC_ERROR
;
919 return le16_to_cpu(rxd
->pkt_len
);
922 static struct rxd_ops rxd_8366_ap_ops
= {
923 .rxd_size
= sizeof(struct mwl8k_rxd_8366_ap
),
924 .rxd_init
= mwl8k_rxd_8366_ap_init
,
925 .rxd_refill
= mwl8k_rxd_8366_ap_refill
,
926 .rxd_process
= mwl8k_rxd_8366_ap_process
,
930 * Packet reception for STA firmware.
932 struct mwl8k_rxd_sta
{
936 __le32 pkt_phys_addr
;
937 __le32 next_rxd_phys_addr
;
949 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
950 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
951 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
952 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
953 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
954 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
956 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
957 #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
959 #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
960 /* Key is uploaded only in failure case */
961 #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
963 static void mwl8k_rxd_sta_init(void *_rxd
, dma_addr_t next_dma_addr
)
965 struct mwl8k_rxd_sta
*rxd
= _rxd
;
967 rxd
->next_rxd_phys_addr
= cpu_to_le32(next_dma_addr
);
968 rxd
->rx_ctrl
= MWL8K_STA_RX_CTRL_OWNED_BY_HOST
;
971 static void mwl8k_rxd_sta_refill(void *_rxd
, dma_addr_t addr
, int len
)
973 struct mwl8k_rxd_sta
*rxd
= _rxd
;
975 rxd
->pkt_len
= cpu_to_le16(len
);
976 rxd
->pkt_phys_addr
= cpu_to_le32(addr
);
982 mwl8k_rxd_sta_process(void *_rxd
, struct ieee80211_rx_status
*status
,
983 __le16
*qos
, s8
*noise
)
985 struct mwl8k_rxd_sta
*rxd
= _rxd
;
988 if (!(rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_OWNED_BY_HOST
))
992 rate_info
= le16_to_cpu(rxd
->rate_info
);
994 memset(status
, 0, sizeof(*status
));
996 status
->signal
= -rxd
->rssi
;
997 *noise
= -rxd
->noise_level
;
998 status
->antenna
= MWL8K_STA_RATE_INFO_ANTSELECT(rate_info
);
999 status
->rate_idx
= MWL8K_STA_RATE_INFO_RATEID(rate_info
);
1001 if (rate_info
& MWL8K_STA_RATE_INFO_SHORTPRE
)
1002 status
->flag
|= RX_FLAG_SHORTPRE
;
1003 if (rate_info
& MWL8K_STA_RATE_INFO_40MHZ
)
1004 status
->flag
|= RX_FLAG_40MHZ
;
1005 if (rate_info
& MWL8K_STA_RATE_INFO_SHORTGI
)
1006 status
->flag
|= RX_FLAG_SHORT_GI
;
1007 if (rate_info
& MWL8K_STA_RATE_INFO_MCS_FORMAT
)
1008 status
->flag
|= RX_FLAG_HT
;
1010 if (rxd
->channel
> 14) {
1011 status
->band
= IEEE80211_BAND_5GHZ
;
1012 if (!(status
->flag
& RX_FLAG_HT
))
1013 status
->rate_idx
-= 5;
1015 status
->band
= IEEE80211_BAND_2GHZ
;
1017 status
->freq
= ieee80211_channel_to_frequency(rxd
->channel
,
1020 *qos
= rxd
->qos_control
;
1021 if ((rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_DECRYPT_ERROR
) &&
1022 (rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_DEC_ERR_TYPE
))
1023 status
->flag
|= RX_FLAG_MMIC_ERROR
;
1025 return le16_to_cpu(rxd
->pkt_len
);
1028 static struct rxd_ops rxd_sta_ops
= {
1029 .rxd_size
= sizeof(struct mwl8k_rxd_sta
),
1030 .rxd_init
= mwl8k_rxd_sta_init
,
1031 .rxd_refill
= mwl8k_rxd_sta_refill
,
1032 .rxd_process
= mwl8k_rxd_sta_process
,
1036 #define MWL8K_RX_DESCS 256
1037 #define MWL8K_RX_MAXSZ 3800
1039 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
1041 struct mwl8k_priv
*priv
= hw
->priv
;
1042 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1050 size
= MWL8K_RX_DESCS
* priv
->rxd_ops
->rxd_size
;
1052 rxq
->rxd
= pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rxd_dma
);
1053 if (rxq
->rxd
== NULL
) {
1054 wiphy_err(hw
->wiphy
, "failed to alloc RX descriptors\n");
1057 memset(rxq
->rxd
, 0, size
);
1059 rxq
->buf
= kmalloc(MWL8K_RX_DESCS
* sizeof(*rxq
->buf
), GFP_KERNEL
);
1060 if (rxq
->buf
== NULL
) {
1061 wiphy_err(hw
->wiphy
, "failed to alloc RX skbuff list\n");
1062 pci_free_consistent(priv
->pdev
, size
, rxq
->rxd
, rxq
->rxd_dma
);
1065 memset(rxq
->buf
, 0, MWL8K_RX_DESCS
* sizeof(*rxq
->buf
));
1067 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
1071 dma_addr_t next_dma_addr
;
1073 desc_size
= priv
->rxd_ops
->rxd_size
;
1074 rxd
= rxq
->rxd
+ (i
* priv
->rxd_ops
->rxd_size
);
1077 if (nexti
== MWL8K_RX_DESCS
)
1079 next_dma_addr
= rxq
->rxd_dma
+ (nexti
* desc_size
);
1081 priv
->rxd_ops
->rxd_init(rxd
, next_dma_addr
);
1087 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
1089 struct mwl8k_priv
*priv
= hw
->priv
;
1090 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1094 while (rxq
->rxd_count
< MWL8K_RX_DESCS
&& limit
--) {
1095 struct sk_buff
*skb
;
1100 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
1104 addr
= pci_map_single(priv
->pdev
, skb
->data
,
1105 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
);
1109 if (rxq
->tail
== MWL8K_RX_DESCS
)
1111 rxq
->buf
[rx
].skb
= skb
;
1112 dma_unmap_addr_set(&rxq
->buf
[rx
], dma
, addr
);
1114 rxd
= rxq
->rxd
+ (rx
* priv
->rxd_ops
->rxd_size
);
1115 priv
->rxd_ops
->rxd_refill(rxd
, addr
, MWL8K_RX_MAXSZ
);
1123 /* Must be called only when the card's reception is completely halted */
1124 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
1126 struct mwl8k_priv
*priv
= hw
->priv
;
1127 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1130 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
1131 if (rxq
->buf
[i
].skb
!= NULL
) {
1132 pci_unmap_single(priv
->pdev
,
1133 dma_unmap_addr(&rxq
->buf
[i
], dma
),
1134 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
1135 dma_unmap_addr_set(&rxq
->buf
[i
], dma
, 0);
1137 kfree_skb(rxq
->buf
[i
].skb
);
1138 rxq
->buf
[i
].skb
= NULL
;
1145 pci_free_consistent(priv
->pdev
,
1146 MWL8K_RX_DESCS
* priv
->rxd_ops
->rxd_size
,
1147 rxq
->rxd
, rxq
->rxd_dma
);
1153 * Scan a list of BSSIDs to process for finalize join.
1154 * Allows for extension to process multiple BSSIDs.
1157 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
1159 return priv
->capture_beacon
&&
1160 ieee80211_is_beacon(wh
->frame_control
) &&
1161 !compare_ether_addr(wh
->addr3
, priv
->capture_bssid
);
1164 static inline void mwl8k_save_beacon(struct ieee80211_hw
*hw
,
1165 struct sk_buff
*skb
)
1167 struct mwl8k_priv
*priv
= hw
->priv
;
1169 priv
->capture_beacon
= false;
1170 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
1173 * Use GFP_ATOMIC as rxq_process is called from
1174 * the primary interrupt handler, memory allocation call
1177 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
1178 if (priv
->beacon_skb
!= NULL
)
1179 ieee80211_queue_work(hw
, &priv
->finalize_join_worker
);
1182 static inline struct mwl8k_vif
*mwl8k_find_vif_bss(struct list_head
*vif_list
,
1185 struct mwl8k_vif
*mwl8k_vif
;
1187 list_for_each_entry(mwl8k_vif
,
1189 if (memcmp(bssid
, mwl8k_vif
->bssid
,
1197 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
1199 struct mwl8k_priv
*priv
= hw
->priv
;
1200 struct mwl8k_vif
*mwl8k_vif
= NULL
;
1201 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1205 while (rxq
->rxd_count
&& limit
--) {
1206 struct sk_buff
*skb
;
1209 struct ieee80211_rx_status status
;
1210 struct ieee80211_hdr
*wh
;
1213 skb
= rxq
->buf
[rxq
->head
].skb
;
1217 rxd
= rxq
->rxd
+ (rxq
->head
* priv
->rxd_ops
->rxd_size
);
1219 pkt_len
= priv
->rxd_ops
->rxd_process(rxd
, &status
, &qos
,
1224 rxq
->buf
[rxq
->head
].skb
= NULL
;
1226 pci_unmap_single(priv
->pdev
,
1227 dma_unmap_addr(&rxq
->buf
[rxq
->head
], dma
),
1228 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
1229 dma_unmap_addr_set(&rxq
->buf
[rxq
->head
], dma
, 0);
1232 if (rxq
->head
== MWL8K_RX_DESCS
)
1237 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1240 * Check for a pending join operation. Save a
1241 * copy of the beacon and schedule a tasklet to
1242 * send a FINALIZE_JOIN command to the firmware.
1244 if (mwl8k_capture_bssid(priv
, (void *)skb
->data
))
1245 mwl8k_save_beacon(hw
, skb
);
1247 if (ieee80211_has_protected(wh
->frame_control
)) {
1249 /* Check if hw crypto has been enabled for
1250 * this bss. If yes, set the status flags
1253 mwl8k_vif
= mwl8k_find_vif_bss(&priv
->vif_list
,
1256 if (mwl8k_vif
!= NULL
&&
1257 mwl8k_vif
->is_hw_crypto_enabled
== true) {
1259 * When MMIC ERROR is encountered
1260 * by the firmware, payload is
1261 * dropped and only 32 bytes of
1262 * mwl8k Firmware header is sent
1265 * We need to add four bytes of
1266 * key information. In it
1267 * MAC80211 expects keyidx set to
1268 * 0 for triggering Counter
1269 * Measure of MMIC failure.
1271 if (status
.flag
& RX_FLAG_MMIC_ERROR
) {
1272 struct mwl8k_dma_data
*tr
;
1273 tr
= (struct mwl8k_dma_data
*)skb
->data
;
1274 memset((void *)&(tr
->data
), 0, 4);
1278 if (!ieee80211_is_auth(wh
->frame_control
))
1279 status
.flag
|= RX_FLAG_IV_STRIPPED
|
1281 RX_FLAG_MMIC_STRIPPED
;
1285 skb_put(skb
, pkt_len
);
1286 mwl8k_remove_dma_header(skb
, qos
);
1287 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
1288 ieee80211_rx_irqsafe(hw
, skb
);
1298 * Packet transmission.
1301 #define MWL8K_TXD_STATUS_OK 0x00000001
1302 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1303 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1304 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1305 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1307 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1308 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1309 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1310 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1311 #define MWL8K_QOS_EOSP 0x0010
1313 struct mwl8k_tx_desc
{
1318 __le32 pkt_phys_addr
;
1320 __u8 dest_MAC_addr
[ETH_ALEN
];
1321 __le32 next_txd_phys_addr
;
1328 #define MWL8K_TX_DESCS 128
1330 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1332 struct mwl8k_priv
*priv
= hw
->priv
;
1333 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1341 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1343 txq
->txd
= pci_alloc_consistent(priv
->pdev
, size
, &txq
->txd_dma
);
1344 if (txq
->txd
== NULL
) {
1345 wiphy_err(hw
->wiphy
, "failed to alloc TX descriptors\n");
1348 memset(txq
->txd
, 0, size
);
1350 txq
->skb
= kmalloc(MWL8K_TX_DESCS
* sizeof(*txq
->skb
), GFP_KERNEL
);
1351 if (txq
->skb
== NULL
) {
1352 wiphy_err(hw
->wiphy
, "failed to alloc TX skbuff list\n");
1353 pci_free_consistent(priv
->pdev
, size
, txq
->txd
, txq
->txd_dma
);
1356 memset(txq
->skb
, 0, MWL8K_TX_DESCS
* sizeof(*txq
->skb
));
1358 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1359 struct mwl8k_tx_desc
*tx_desc
;
1362 tx_desc
= txq
->txd
+ i
;
1363 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1365 tx_desc
->status
= 0;
1366 tx_desc
->next_txd_phys_addr
=
1367 cpu_to_le32(txq
->txd_dma
+ nexti
* sizeof(*tx_desc
));
1373 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1375 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1376 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1377 iowrite32(MWL8K_H2A_INT_DUMMY
,
1378 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1379 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1382 static void mwl8k_dump_tx_rings(struct ieee80211_hw
*hw
)
1384 struct mwl8k_priv
*priv
= hw
->priv
;
1387 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
1388 struct mwl8k_tx_queue
*txq
= priv
->txq
+ i
;
1394 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1395 struct mwl8k_tx_desc
*tx_desc
= txq
->txd
+ desc
;
1398 status
= le32_to_cpu(tx_desc
->status
);
1399 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1404 if (tx_desc
->pkt_len
== 0)
1408 wiphy_err(hw
->wiphy
,
1409 "txq[%d] len=%d head=%d tail=%d "
1410 "fw_owned=%d drv_owned=%d unused=%d\n",
1412 txq
->len
, txq
->head
, txq
->tail
,
1413 fw_owned
, drv_owned
, unused
);
1418 * Must be called with priv->fw_mutex held and tx queues stopped.
1420 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1422 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
)
1424 struct mwl8k_priv
*priv
= hw
->priv
;
1425 DECLARE_COMPLETION_ONSTACK(tx_wait
);
1432 * The TX queues are stopped at this point, so this test
1433 * doesn't need to take ->tx_lock.
1435 if (!priv
->pending_tx_pkts
)
1441 spin_lock_bh(&priv
->tx_lock
);
1442 priv
->tx_wait
= &tx_wait
;
1445 unsigned long timeout
;
1447 oldcount
= priv
->pending_tx_pkts
;
1449 spin_unlock_bh(&priv
->tx_lock
);
1450 timeout
= wait_for_completion_timeout(&tx_wait
,
1451 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS
));
1452 spin_lock_bh(&priv
->tx_lock
);
1455 WARN_ON(priv
->pending_tx_pkts
);
1457 wiphy_notice(hw
->wiphy
, "tx rings drained\n");
1462 if (priv
->pending_tx_pkts
< oldcount
) {
1463 wiphy_notice(hw
->wiphy
,
1464 "waiting for tx rings to drain (%d -> %d pkts)\n",
1465 oldcount
, priv
->pending_tx_pkts
);
1470 priv
->tx_wait
= NULL
;
1472 wiphy_err(hw
->wiphy
, "tx rings stuck for %d ms\n",
1473 MWL8K_TX_WAIT_TIMEOUT_MS
);
1474 mwl8k_dump_tx_rings(hw
);
1478 spin_unlock_bh(&priv
->tx_lock
);
1483 #define MWL8K_TXD_SUCCESS(status) \
1484 ((status) & (MWL8K_TXD_STATUS_OK | \
1485 MWL8K_TXD_STATUS_OK_RETRY | \
1486 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1489 mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int limit
, int force
)
1491 struct mwl8k_priv
*priv
= hw
->priv
;
1492 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1496 while (txq
->len
> 0 && limit
--) {
1498 struct mwl8k_tx_desc
*tx_desc
;
1501 struct sk_buff
*skb
;
1502 struct ieee80211_tx_info
*info
;
1506 tx_desc
= txq
->txd
+ tx
;
1508 status
= le32_to_cpu(tx_desc
->status
);
1510 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1514 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1517 txq
->head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1518 BUG_ON(txq
->len
== 0);
1520 priv
->pending_tx_pkts
--;
1522 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1523 size
= le16_to_cpu(tx_desc
->pkt_len
);
1525 txq
->skb
[tx
] = NULL
;
1527 BUG_ON(skb
== NULL
);
1528 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1530 mwl8k_remove_dma_header(skb
, tx_desc
->qos_control
);
1532 /* Mark descriptor as unused */
1533 tx_desc
->pkt_phys_addr
= 0;
1534 tx_desc
->pkt_len
= 0;
1536 info
= IEEE80211_SKB_CB(skb
);
1537 ieee80211_tx_info_clear_status(info
);
1538 if (MWL8K_TXD_SUCCESS(status
))
1539 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1541 ieee80211_tx_status_irqsafe(hw
, skb
);
1546 if (processed
&& priv
->radio_on
&& !mutex_is_locked(&priv
->fw_mutex
))
1547 ieee80211_wake_queue(hw
, index
);
1552 /* must be called only when the card's transmit is completely halted */
1553 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1555 struct mwl8k_priv
*priv
= hw
->priv
;
1556 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1558 mwl8k_txq_reclaim(hw
, index
, INT_MAX
, 1);
1563 pci_free_consistent(priv
->pdev
,
1564 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1565 txq
->txd
, txq
->txd_dma
);
1570 mwl8k_txq_xmit(struct ieee80211_hw
*hw
, int index
, struct sk_buff
*skb
)
1572 struct mwl8k_priv
*priv
= hw
->priv
;
1573 struct ieee80211_tx_info
*tx_info
;
1574 struct mwl8k_vif
*mwl8k_vif
;
1575 struct ieee80211_hdr
*wh
;
1576 struct mwl8k_tx_queue
*txq
;
1577 struct mwl8k_tx_desc
*tx
;
1583 wh
= (struct ieee80211_hdr
*)skb
->data
;
1584 if (ieee80211_is_data_qos(wh
->frame_control
))
1585 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1590 mwl8k_encapsulate_tx_frame(skb
);
1592 mwl8k_add_dma_header(skb
, 0);
1594 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1596 tx_info
= IEEE80211_SKB_CB(skb
);
1597 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1599 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1600 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1601 wh
->seq_ctrl
|= cpu_to_le16(mwl8k_vif
->seqno
);
1602 mwl8k_vif
->seqno
+= 0x10;
1605 /* Setup firmware control bit fields for each frame type. */
1608 if (ieee80211_is_mgmt(wh
->frame_control
) ||
1609 ieee80211_is_ctl(wh
->frame_control
)) {
1611 qos
|= MWL8K_QOS_QLEN_UNSPEC
| MWL8K_QOS_EOSP
;
1612 } else if (ieee80211_is_data(wh
->frame_control
)) {
1614 if (is_multicast_ether_addr(wh
->addr1
))
1615 txstatus
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1617 qos
&= ~MWL8K_QOS_ACK_POLICY_MASK
;
1618 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1619 qos
|= MWL8K_QOS_ACK_POLICY_BLOCKACK
;
1621 qos
|= MWL8K_QOS_ACK_POLICY_NORMAL
;
1624 dma
= pci_map_single(priv
->pdev
, skb
->data
,
1625 skb
->len
, PCI_DMA_TODEVICE
);
1627 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
1628 wiphy_debug(hw
->wiphy
,
1629 "failed to dma map skb, dropping TX frame.\n");
1631 return NETDEV_TX_OK
;
1634 spin_lock_bh(&priv
->tx_lock
);
1636 txq
= priv
->txq
+ index
;
1638 BUG_ON(txq
->skb
[txq
->tail
] != NULL
);
1639 txq
->skb
[txq
->tail
] = skb
;
1641 tx
= txq
->txd
+ txq
->tail
;
1642 tx
->data_rate
= txdatarate
;
1643 tx
->tx_priority
= index
;
1644 tx
->qos_control
= cpu_to_le16(qos
);
1645 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
1646 tx
->pkt_len
= cpu_to_le16(skb
->len
);
1648 if (!priv
->ap_fw
&& tx_info
->control
.sta
!= NULL
)
1649 tx
->peer_id
= MWL8K_STA(tx_info
->control
.sta
)->peer_id
;
1653 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
| txstatus
);
1656 priv
->pending_tx_pkts
++;
1659 if (txq
->tail
== MWL8K_TX_DESCS
)
1662 if (txq
->head
== txq
->tail
)
1663 ieee80211_stop_queue(hw
, index
);
1665 mwl8k_tx_start(priv
);
1667 spin_unlock_bh(&priv
->tx_lock
);
1669 return NETDEV_TX_OK
;
1676 * We have the following requirements for issuing firmware commands:
1677 * - Some commands require that the packet transmit path is idle when
1678 * the command is issued. (For simplicity, we'll just quiesce the
1679 * transmit path for every command.)
1680 * - There are certain sequences of commands that need to be issued to
1681 * the hardware sequentially, with no other intervening commands.
1683 * This leads to an implementation of a "firmware lock" as a mutex that
1684 * can be taken recursively, and which is taken by both the low-level
1685 * command submission function (mwl8k_post_cmd) as well as any users of
1686 * that function that require issuing of an atomic sequence of commands,
1687 * and quiesces the transmit path whenever it's taken.
1689 static int mwl8k_fw_lock(struct ieee80211_hw
*hw
)
1691 struct mwl8k_priv
*priv
= hw
->priv
;
1693 if (priv
->fw_mutex_owner
!= current
) {
1696 mutex_lock(&priv
->fw_mutex
);
1697 ieee80211_stop_queues(hw
);
1699 rc
= mwl8k_tx_wait_empty(hw
);
1701 ieee80211_wake_queues(hw
);
1702 mutex_unlock(&priv
->fw_mutex
);
1707 priv
->fw_mutex_owner
= current
;
1710 priv
->fw_mutex_depth
++;
1715 static void mwl8k_fw_unlock(struct ieee80211_hw
*hw
)
1717 struct mwl8k_priv
*priv
= hw
->priv
;
1719 if (!--priv
->fw_mutex_depth
) {
1720 ieee80211_wake_queues(hw
);
1721 priv
->fw_mutex_owner
= NULL
;
1722 mutex_unlock(&priv
->fw_mutex
);
1728 * Command processing.
1731 /* Timeout firmware commands after 10s */
1732 #define MWL8K_CMD_TIMEOUT_MS 10000
1734 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
1736 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1737 struct mwl8k_priv
*priv
= hw
->priv
;
1738 void __iomem
*regs
= priv
->regs
;
1739 dma_addr_t dma_addr
;
1740 unsigned int dma_size
;
1742 unsigned long timeout
= 0;
1745 cmd
->result
= (__force __le16
) 0xffff;
1746 dma_size
= le16_to_cpu(cmd
->length
);
1747 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
1748 PCI_DMA_BIDIRECTIONAL
);
1749 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
1752 rc
= mwl8k_fw_lock(hw
);
1754 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1755 PCI_DMA_BIDIRECTIONAL
);
1759 priv
->hostcmd_wait
= &cmd_wait
;
1760 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
1761 iowrite32(MWL8K_H2A_INT_DOORBELL
,
1762 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1763 iowrite32(MWL8K_H2A_INT_DUMMY
,
1764 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1766 timeout
= wait_for_completion_timeout(&cmd_wait
,
1767 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
1769 priv
->hostcmd_wait
= NULL
;
1771 mwl8k_fw_unlock(hw
);
1773 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1774 PCI_DMA_BIDIRECTIONAL
);
1777 wiphy_err(hw
->wiphy
, "Command %s timeout after %u ms\n",
1778 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1779 MWL8K_CMD_TIMEOUT_MS
);
1784 ms
= MWL8K_CMD_TIMEOUT_MS
- jiffies_to_msecs(timeout
);
1786 rc
= cmd
->result
? -EINVAL
: 0;
1788 wiphy_err(hw
->wiphy
, "Command %s error 0x%x\n",
1789 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1790 le16_to_cpu(cmd
->result
));
1792 wiphy_notice(hw
->wiphy
, "Command %s took %d ms\n",
1793 mwl8k_cmd_name(cmd
->code
,
1801 static int mwl8k_post_pervif_cmd(struct ieee80211_hw
*hw
,
1802 struct ieee80211_vif
*vif
,
1803 struct mwl8k_cmd_pkt
*cmd
)
1806 cmd
->macid
= MWL8K_VIF(vif
)->macid
;
1807 return mwl8k_post_cmd(hw
, cmd
);
1811 * Setup code shared between STA and AP firmware images.
1813 static void mwl8k_setup_2ghz_band(struct ieee80211_hw
*hw
)
1815 struct mwl8k_priv
*priv
= hw
->priv
;
1817 BUILD_BUG_ON(sizeof(priv
->channels_24
) != sizeof(mwl8k_channels_24
));
1818 memcpy(priv
->channels_24
, mwl8k_channels_24
, sizeof(mwl8k_channels_24
));
1820 BUILD_BUG_ON(sizeof(priv
->rates_24
) != sizeof(mwl8k_rates_24
));
1821 memcpy(priv
->rates_24
, mwl8k_rates_24
, sizeof(mwl8k_rates_24
));
1823 priv
->band_24
.band
= IEEE80211_BAND_2GHZ
;
1824 priv
->band_24
.channels
= priv
->channels_24
;
1825 priv
->band_24
.n_channels
= ARRAY_SIZE(mwl8k_channels_24
);
1826 priv
->band_24
.bitrates
= priv
->rates_24
;
1827 priv
->band_24
.n_bitrates
= ARRAY_SIZE(mwl8k_rates_24
);
1829 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band_24
;
1832 static void mwl8k_setup_5ghz_band(struct ieee80211_hw
*hw
)
1834 struct mwl8k_priv
*priv
= hw
->priv
;
1836 BUILD_BUG_ON(sizeof(priv
->channels_50
) != sizeof(mwl8k_channels_50
));
1837 memcpy(priv
->channels_50
, mwl8k_channels_50
, sizeof(mwl8k_channels_50
));
1839 BUILD_BUG_ON(sizeof(priv
->rates_50
) != sizeof(mwl8k_rates_50
));
1840 memcpy(priv
->rates_50
, mwl8k_rates_50
, sizeof(mwl8k_rates_50
));
1842 priv
->band_50
.band
= IEEE80211_BAND_5GHZ
;
1843 priv
->band_50
.channels
= priv
->channels_50
;
1844 priv
->band_50
.n_channels
= ARRAY_SIZE(mwl8k_channels_50
);
1845 priv
->band_50
.bitrates
= priv
->rates_50
;
1846 priv
->band_50
.n_bitrates
= ARRAY_SIZE(mwl8k_rates_50
);
1848 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &priv
->band_50
;
1852 * CMD_GET_HW_SPEC (STA version).
1854 struct mwl8k_cmd_get_hw_spec_sta
{
1855 struct mwl8k_cmd_pkt header
;
1857 __u8 host_interface
;
1859 __u8 perm_addr
[ETH_ALEN
];
1864 __u8 mcs_bitmap
[16];
1865 __le32 rx_queue_ptr
;
1866 __le32 num_tx_queues
;
1867 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1869 __le32 num_tx_desc_per_queue
;
1873 #define MWL8K_CAP_MAX_AMSDU 0x20000000
1874 #define MWL8K_CAP_GREENFIELD 0x08000000
1875 #define MWL8K_CAP_AMPDU 0x04000000
1876 #define MWL8K_CAP_RX_STBC 0x01000000
1877 #define MWL8K_CAP_TX_STBC 0x00800000
1878 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1879 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1880 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1881 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1882 #define MWL8K_CAP_DELAY_BA 0x00003000
1883 #define MWL8K_CAP_MIMO 0x00000200
1884 #define MWL8K_CAP_40MHZ 0x00000100
1885 #define MWL8K_CAP_BAND_MASK 0x00000007
1886 #define MWL8K_CAP_5GHZ 0x00000004
1887 #define MWL8K_CAP_2GHZ4 0x00000001
1890 mwl8k_set_ht_caps(struct ieee80211_hw
*hw
,
1891 struct ieee80211_supported_band
*band
, u32 cap
)
1896 band
->ht_cap
.ht_supported
= 1;
1898 if (cap
& MWL8K_CAP_MAX_AMSDU
)
1899 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
1900 if (cap
& MWL8K_CAP_GREENFIELD
)
1901 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_GRN_FLD
;
1902 if (cap
& MWL8K_CAP_AMPDU
) {
1903 hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
1904 band
->ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
1905 band
->ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_NONE
;
1907 if (cap
& MWL8K_CAP_RX_STBC
)
1908 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_RX_STBC
;
1909 if (cap
& MWL8K_CAP_TX_STBC
)
1910 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
1911 if (cap
& MWL8K_CAP_SHORTGI_40MHZ
)
1912 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
1913 if (cap
& MWL8K_CAP_SHORTGI_20MHZ
)
1914 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
1915 if (cap
& MWL8K_CAP_DELAY_BA
)
1916 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_DELAY_BA
;
1917 if (cap
& MWL8K_CAP_40MHZ
)
1918 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
1920 rx_streams
= hweight32(cap
& MWL8K_CAP_RX_ANTENNA_MASK
);
1921 tx_streams
= hweight32(cap
& MWL8K_CAP_TX_ANTENNA_MASK
);
1923 band
->ht_cap
.mcs
.rx_mask
[0] = 0xff;
1924 if (rx_streams
>= 2)
1925 band
->ht_cap
.mcs
.rx_mask
[1] = 0xff;
1926 if (rx_streams
>= 3)
1927 band
->ht_cap
.mcs
.rx_mask
[2] = 0xff;
1928 band
->ht_cap
.mcs
.rx_mask
[4] = 0x01;
1929 band
->ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
1931 if (rx_streams
!= tx_streams
) {
1932 band
->ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_RX_DIFF
;
1933 band
->ht_cap
.mcs
.tx_params
|= (tx_streams
- 1) <<
1934 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
1939 mwl8k_set_caps(struct ieee80211_hw
*hw
, u32 caps
)
1941 struct mwl8k_priv
*priv
= hw
->priv
;
1943 if ((caps
& MWL8K_CAP_2GHZ4
) || !(caps
& MWL8K_CAP_BAND_MASK
)) {
1944 mwl8k_setup_2ghz_band(hw
);
1945 if (caps
& MWL8K_CAP_MIMO
)
1946 mwl8k_set_ht_caps(hw
, &priv
->band_24
, caps
);
1949 if (caps
& MWL8K_CAP_5GHZ
) {
1950 mwl8k_setup_5ghz_band(hw
);
1951 if (caps
& MWL8K_CAP_MIMO
)
1952 mwl8k_set_ht_caps(hw
, &priv
->band_50
, caps
);
1956 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw
*hw
)
1958 struct mwl8k_priv
*priv
= hw
->priv
;
1959 struct mwl8k_cmd_get_hw_spec_sta
*cmd
;
1963 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1967 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1968 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1970 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1971 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1972 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rxd_dma
);
1973 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1974 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1975 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].txd_dma
);
1976 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1977 cmd
->total_rxd
= cpu_to_le32(MWL8K_RX_DESCS
);
1979 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1982 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1983 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1984 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1985 priv
->hw_rev
= cmd
->hw_rev
;
1986 mwl8k_set_caps(hw
, le32_to_cpu(cmd
->caps
));
1987 priv
->ap_macids_supported
= 0x00000000;
1988 priv
->sta_macids_supported
= 0x00000001;
1996 * CMD_GET_HW_SPEC (AP version).
1998 struct mwl8k_cmd_get_hw_spec_ap
{
1999 struct mwl8k_cmd_pkt header
;
2001 __u8 host_interface
;
2004 __u8 perm_addr
[ETH_ALEN
];
2015 __le32 fw_api_version
;
2018 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw
*hw
)
2020 struct mwl8k_priv
*priv
= hw
->priv
;
2021 struct mwl8k_cmd_get_hw_spec_ap
*cmd
;
2025 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2029 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
2030 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2032 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
2033 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
2035 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2040 api_version
= le32_to_cpu(cmd
->fw_api_version
);
2041 if (priv
->device_info
->fw_api_ap
!= api_version
) {
2042 printk(KERN_ERR
"%s: Unsupported fw API version for %s."
2043 " Expected %d got %d.\n", MWL8K_NAME
,
2044 priv
->device_info
->part_name
,
2045 priv
->device_info
->fw_api_ap
,
2050 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
2051 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
2052 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
2053 priv
->hw_rev
= cmd
->hw_rev
;
2054 mwl8k_setup_2ghz_band(hw
);
2055 priv
->ap_macids_supported
= 0x000000ff;
2056 priv
->sta_macids_supported
= 0x00000000;
2058 off
= le32_to_cpu(cmd
->wcbbase0
) & 0xffff;
2059 iowrite32(priv
->txq
[0].txd_dma
, priv
->sram
+ off
);
2061 off
= le32_to_cpu(cmd
->rxwrptr
) & 0xffff;
2062 iowrite32(priv
->rxq
[0].rxd_dma
, priv
->sram
+ off
);
2064 off
= le32_to_cpu(cmd
->rxrdptr
) & 0xffff;
2065 iowrite32(priv
->rxq
[0].rxd_dma
, priv
->sram
+ off
);
2067 off
= le32_to_cpu(cmd
->wcbbase1
) & 0xffff;
2068 iowrite32(priv
->txq
[1].txd_dma
, priv
->sram
+ off
);
2070 off
= le32_to_cpu(cmd
->wcbbase2
) & 0xffff;
2071 iowrite32(priv
->txq
[2].txd_dma
, priv
->sram
+ off
);
2073 off
= le32_to_cpu(cmd
->wcbbase3
) & 0xffff;
2074 iowrite32(priv
->txq
[3].txd_dma
, priv
->sram
+ off
);
2085 struct mwl8k_cmd_set_hw_spec
{
2086 struct mwl8k_cmd_pkt header
;
2088 __u8 host_interface
;
2090 __u8 perm_addr
[ETH_ALEN
];
2095 __le32 rx_queue_ptr
;
2096 __le32 num_tx_queues
;
2097 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
2099 __le32 num_tx_desc_per_queue
;
2103 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2104 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2105 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
2107 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw
*hw
)
2109 struct mwl8k_priv
*priv
= hw
->priv
;
2110 struct mwl8k_cmd_set_hw_spec
*cmd
;
2114 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2118 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_HW_SPEC
);
2119 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2121 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
2122 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rxd_dma
);
2123 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
2124 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
2125 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].txd_dma
);
2126 cmd
->flags
= cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT
|
2127 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP
|
2128 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON
);
2129 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
2130 cmd
->total_rxd
= cpu_to_le32(MWL8K_RX_DESCS
);
2132 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2139 * CMD_MAC_MULTICAST_ADR.
2141 struct mwl8k_cmd_mac_multicast_adr
{
2142 struct mwl8k_cmd_pkt header
;
2145 __u8 addr
[0][ETH_ALEN
];
2148 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
2149 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
2150 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2151 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
2153 static struct mwl8k_cmd_pkt
*
2154 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
, int allmulti
,
2155 struct netdev_hw_addr_list
*mc_list
)
2157 struct mwl8k_priv
*priv
= hw
->priv
;
2158 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
2163 mc_count
= netdev_hw_addr_list_count(mc_list
);
2165 if (allmulti
|| mc_count
> priv
->num_mcaddrs
) {
2170 size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
2172 cmd
= kzalloc(size
, GFP_ATOMIC
);
2176 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
2177 cmd
->header
.length
= cpu_to_le16(size
);
2178 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED
|
2179 MWL8K_ENABLE_RX_BROADCAST
);
2182 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST
);
2183 } else if (mc_count
) {
2184 struct netdev_hw_addr
*ha
;
2187 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
2188 cmd
->numaddr
= cpu_to_le16(mc_count
);
2189 netdev_hw_addr_list_for_each(ha
, mc_list
) {
2190 memcpy(cmd
->addr
[i
], ha
->addr
, ETH_ALEN
);
2194 return &cmd
->header
;
2200 struct mwl8k_cmd_get_stat
{
2201 struct mwl8k_cmd_pkt header
;
2205 #define MWL8K_STAT_ACK_FAILURE 9
2206 #define MWL8K_STAT_RTS_FAILURE 12
2207 #define MWL8K_STAT_FCS_ERROR 24
2208 #define MWL8K_STAT_RTS_SUCCESS 11
2210 static int mwl8k_cmd_get_stat(struct ieee80211_hw
*hw
,
2211 struct ieee80211_low_level_stats
*stats
)
2213 struct mwl8k_cmd_get_stat
*cmd
;
2216 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2220 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
2221 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2223 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2225 stats
->dot11ACKFailureCount
=
2226 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
2227 stats
->dot11RTSFailureCount
=
2228 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
2229 stats
->dot11FCSErrorCount
=
2230 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
2231 stats
->dot11RTSSuccessCount
=
2232 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
2240 * CMD_RADIO_CONTROL.
2242 struct mwl8k_cmd_radio_control
{
2243 struct mwl8k_cmd_pkt header
;
2250 mwl8k_cmd_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
2252 struct mwl8k_priv
*priv
= hw
->priv
;
2253 struct mwl8k_cmd_radio_control
*cmd
;
2256 if (enable
== priv
->radio_on
&& !force
)
2259 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2263 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
2264 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2265 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2266 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
2267 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
2269 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2273 priv
->radio_on
= enable
;
2278 static int mwl8k_cmd_radio_disable(struct ieee80211_hw
*hw
)
2280 return mwl8k_cmd_radio_control(hw
, 0, 0);
2283 static int mwl8k_cmd_radio_enable(struct ieee80211_hw
*hw
)
2285 return mwl8k_cmd_radio_control(hw
, 1, 0);
2289 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
2291 struct mwl8k_priv
*priv
= hw
->priv
;
2293 priv
->radio_short_preamble
= short_preamble
;
2295 return mwl8k_cmd_radio_control(hw
, 1, 1);
2301 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2303 struct mwl8k_cmd_rf_tx_power
{
2304 struct mwl8k_cmd_pkt header
;
2306 __le16 support_level
;
2307 __le16 current_level
;
2309 __le16 power_level_list
[MWL8K_RF_TX_POWER_LEVEL_TOTAL
];
2312 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
2314 struct mwl8k_cmd_rf_tx_power
*cmd
;
2317 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2321 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
2322 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2323 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2324 cmd
->support_level
= cpu_to_le16(dBm
);
2326 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2335 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2337 struct mwl8k_cmd_tx_power
{
2338 struct mwl8k_cmd_pkt header
;
2344 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
2345 } __attribute__((packed
));
2347 static int mwl8k_cmd_tx_power(struct ieee80211_hw
*hw
,
2348 struct ieee80211_conf
*conf
,
2351 struct ieee80211_channel
*channel
= conf
->channel
;
2352 struct mwl8k_cmd_tx_power
*cmd
;
2356 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2360 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_TX_POWER
);
2361 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2362 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET_LIST
);
2364 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2365 cmd
->band
= cpu_to_le16(0x1);
2366 else if (channel
->band
== IEEE80211_BAND_5GHZ
)
2367 cmd
->band
= cpu_to_le16(0x4);
2369 cmd
->channel
= channel
->hw_value
;
2371 if (conf
->channel_type
== NL80211_CHAN_NO_HT
||
2372 conf
->channel_type
== NL80211_CHAN_HT20
) {
2373 cmd
->bw
= cpu_to_le16(0x2);
2375 cmd
->bw
= cpu_to_le16(0x4);
2376 if (conf
->channel_type
== NL80211_CHAN_HT40MINUS
)
2377 cmd
->sub_ch
= cpu_to_le16(0x3);
2378 else if (conf
->channel_type
== NL80211_CHAN_HT40PLUS
)
2379 cmd
->sub_ch
= cpu_to_le16(0x1);
2382 for (i
= 0; i
< MWL8K_TX_POWER_LEVEL_TOTAL
; i
++)
2383 cmd
->power_level_list
[i
] = cpu_to_le16(pwr
);
2385 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2394 struct mwl8k_cmd_rf_antenna
{
2395 struct mwl8k_cmd_pkt header
;
2400 #define MWL8K_RF_ANTENNA_RX 1
2401 #define MWL8K_RF_ANTENNA_TX 2
2404 mwl8k_cmd_rf_antenna(struct ieee80211_hw
*hw
, int antenna
, int mask
)
2406 struct mwl8k_cmd_rf_antenna
*cmd
;
2409 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2413 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_ANTENNA
);
2414 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2415 cmd
->antenna
= cpu_to_le16(antenna
);
2416 cmd
->mode
= cpu_to_le16(mask
);
2418 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2427 struct mwl8k_cmd_set_beacon
{
2428 struct mwl8k_cmd_pkt header
;
2433 static int mwl8k_cmd_set_beacon(struct ieee80211_hw
*hw
,
2434 struct ieee80211_vif
*vif
, u8
*beacon
, int len
)
2436 struct mwl8k_cmd_set_beacon
*cmd
;
2439 cmd
= kzalloc(sizeof(*cmd
) + len
, GFP_KERNEL
);
2443 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_BEACON
);
2444 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
) + len
);
2445 cmd
->beacon_len
= cpu_to_le16(len
);
2446 memcpy(cmd
->beacon
, beacon
, len
);
2448 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
2457 struct mwl8k_cmd_set_pre_scan
{
2458 struct mwl8k_cmd_pkt header
;
2461 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
2463 struct mwl8k_cmd_set_pre_scan
*cmd
;
2466 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2470 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
2471 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2473 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2480 * CMD_SET_POST_SCAN.
2482 struct mwl8k_cmd_set_post_scan
{
2483 struct mwl8k_cmd_pkt header
;
2485 __u8 bssid
[ETH_ALEN
];
2489 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, const __u8
*mac
)
2491 struct mwl8k_cmd_set_post_scan
*cmd
;
2494 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2498 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
2499 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2501 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
2503 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2510 * CMD_SET_RF_CHANNEL.
2512 struct mwl8k_cmd_set_rf_channel
{
2513 struct mwl8k_cmd_pkt header
;
2515 __u8 current_channel
;
2516 __le32 channel_flags
;
2519 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
2520 struct ieee80211_conf
*conf
)
2522 struct ieee80211_channel
*channel
= conf
->channel
;
2523 struct mwl8k_cmd_set_rf_channel
*cmd
;
2526 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2530 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
2531 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2532 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2533 cmd
->current_channel
= channel
->hw_value
;
2535 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2536 cmd
->channel_flags
|= cpu_to_le32(0x00000001);
2537 else if (channel
->band
== IEEE80211_BAND_5GHZ
)
2538 cmd
->channel_flags
|= cpu_to_le32(0x00000004);
2540 if (conf
->channel_type
== NL80211_CHAN_NO_HT
||
2541 conf
->channel_type
== NL80211_CHAN_HT20
)
2542 cmd
->channel_flags
|= cpu_to_le32(0x00000080);
2543 else if (conf
->channel_type
== NL80211_CHAN_HT40MINUS
)
2544 cmd
->channel_flags
|= cpu_to_le32(0x000001900);
2545 else if (conf
->channel_type
== NL80211_CHAN_HT40PLUS
)
2546 cmd
->channel_flags
|= cpu_to_le32(0x000000900);
2548 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2557 #define MWL8K_FRAME_PROT_DISABLED 0x00
2558 #define MWL8K_FRAME_PROT_11G 0x07
2559 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2560 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2562 struct mwl8k_cmd_update_set_aid
{
2563 struct mwl8k_cmd_pkt header
;
2566 /* AP's MAC address (BSSID) */
2567 __u8 bssid
[ETH_ALEN
];
2568 __le16 protection_mode
;
2569 __u8 supp_rates
[14];
2572 static void legacy_rate_mask_to_array(u8
*rates
, u32 mask
)
2578 * Clear nonstandard rates 4 and 13.
2582 for (i
= 0, j
= 0; i
< 14; i
++) {
2583 if (mask
& (1 << i
))
2584 rates
[j
++] = mwl8k_rates_24
[i
].hw_value
;
2589 mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
2590 struct ieee80211_vif
*vif
, u32 legacy_rate_mask
)
2592 struct mwl8k_cmd_update_set_aid
*cmd
;
2596 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2600 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
2601 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2602 cmd
->aid
= cpu_to_le16(vif
->bss_conf
.aid
);
2603 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
2605 if (vif
->bss_conf
.use_cts_prot
) {
2606 prot_mode
= MWL8K_FRAME_PROT_11G
;
2608 switch (vif
->bss_conf
.ht_operation_mode
&
2609 IEEE80211_HT_OP_MODE_PROTECTION
) {
2610 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
2611 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
2613 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
2614 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
2617 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
2621 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
2623 legacy_rate_mask_to_array(cmd
->supp_rates
, legacy_rate_mask
);
2625 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2634 struct mwl8k_cmd_set_rate
{
2635 struct mwl8k_cmd_pkt header
;
2636 __u8 legacy_rates
[14];
2638 /* Bitmap for supported MCS codes. */
2644 mwl8k_cmd_set_rate(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
2645 u32 legacy_rate_mask
, u8
*mcs_rates
)
2647 struct mwl8k_cmd_set_rate
*cmd
;
2650 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2654 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
2655 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2656 legacy_rate_mask_to_array(cmd
->legacy_rates
, legacy_rate_mask
);
2657 memcpy(cmd
->mcs_set
, mcs_rates
, 16);
2659 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2666 * CMD_FINALIZE_JOIN.
2668 #define MWL8K_FJ_BEACON_MAXLEN 128
2670 struct mwl8k_cmd_finalize_join
{
2671 struct mwl8k_cmd_pkt header
;
2672 __le32 sleep_interval
; /* Number of beacon periods to sleep */
2673 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
2676 static int mwl8k_cmd_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
2677 int framelen
, int dtim
)
2679 struct mwl8k_cmd_finalize_join
*cmd
;
2680 struct ieee80211_mgmt
*payload
= frame
;
2684 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2688 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
2689 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2690 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
2692 payload_len
= framelen
- ieee80211_hdrlen(payload
->frame_control
);
2693 if (payload_len
< 0)
2695 else if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2696 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
2698 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
2700 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2707 * CMD_SET_RTS_THRESHOLD.
2709 struct mwl8k_cmd_set_rts_threshold
{
2710 struct mwl8k_cmd_pkt header
;
2716 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw
*hw
, int rts_thresh
)
2718 struct mwl8k_cmd_set_rts_threshold
*cmd
;
2721 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2725 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
2726 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2727 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2728 cmd
->threshold
= cpu_to_le16(rts_thresh
);
2730 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2739 struct mwl8k_cmd_set_slot
{
2740 struct mwl8k_cmd_pkt header
;
2745 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, bool short_slot_time
)
2747 struct mwl8k_cmd_set_slot
*cmd
;
2750 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2754 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
2755 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2756 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2757 cmd
->short_slot
= short_slot_time
;
2759 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2766 * CMD_SET_EDCA_PARAMS.
2768 struct mwl8k_cmd_set_edca_params
{
2769 struct mwl8k_cmd_pkt header
;
2771 /* See MWL8K_SET_EDCA_XXX below */
2774 /* TX opportunity in units of 32 us */
2779 /* Log exponent of max contention period: 0...15 */
2782 /* Log exponent of min contention period: 0...15 */
2785 /* Adaptive interframe spacing in units of 32us */
2788 /* TX queue to configure */
2792 /* Log exponent of max contention period: 0...15 */
2795 /* Log exponent of min contention period: 0...15 */
2798 /* Adaptive interframe spacing in units of 32us */
2801 /* TX queue to configure */
2807 #define MWL8K_SET_EDCA_CW 0x01
2808 #define MWL8K_SET_EDCA_TXOP 0x02
2809 #define MWL8K_SET_EDCA_AIFS 0x04
2811 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2812 MWL8K_SET_EDCA_TXOP | \
2813 MWL8K_SET_EDCA_AIFS)
2816 mwl8k_cmd_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
2817 __u16 cw_min
, __u16 cw_max
,
2818 __u8 aifs
, __u16 txop
)
2820 struct mwl8k_priv
*priv
= hw
->priv
;
2821 struct mwl8k_cmd_set_edca_params
*cmd
;
2824 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2828 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
2829 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2830 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
2831 cmd
->txop
= cpu_to_le16(txop
);
2833 cmd
->ap
.log_cw_max
= cpu_to_le32(ilog2(cw_max
+ 1));
2834 cmd
->ap
.log_cw_min
= cpu_to_le32(ilog2(cw_min
+ 1));
2835 cmd
->ap
.aifs
= aifs
;
2838 cmd
->sta
.log_cw_max
= (u8
)ilog2(cw_max
+ 1);
2839 cmd
->sta
.log_cw_min
= (u8
)ilog2(cw_min
+ 1);
2840 cmd
->sta
.aifs
= aifs
;
2841 cmd
->sta
.txq
= qnum
;
2844 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2853 struct mwl8k_cmd_set_wmm_mode
{
2854 struct mwl8k_cmd_pkt header
;
2858 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw
*hw
, bool enable
)
2860 struct mwl8k_priv
*priv
= hw
->priv
;
2861 struct mwl8k_cmd_set_wmm_mode
*cmd
;
2864 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2868 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
2869 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2870 cmd
->action
= cpu_to_le16(!!enable
);
2872 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2876 priv
->wmm_enabled
= enable
;
2884 struct mwl8k_cmd_mimo_config
{
2885 struct mwl8k_cmd_pkt header
;
2887 __u8 rx_antenna_map
;
2888 __u8 tx_antenna_map
;
2891 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
2893 struct mwl8k_cmd_mimo_config
*cmd
;
2896 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2900 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
2901 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2902 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
2903 cmd
->rx_antenna_map
= rx
;
2904 cmd
->tx_antenna_map
= tx
;
2906 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2913 * CMD_USE_FIXED_RATE (STA version).
2915 struct mwl8k_cmd_use_fixed_rate_sta
{
2916 struct mwl8k_cmd_pkt header
;
2918 __le32 allow_rate_drop
;
2922 __le32 enable_retry
;
2931 #define MWL8K_USE_AUTO_RATE 0x0002
2932 #define MWL8K_UCAST_RATE 0
2934 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw
*hw
)
2936 struct mwl8k_cmd_use_fixed_rate_sta
*cmd
;
2939 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2943 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2944 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2945 cmd
->action
= cpu_to_le32(MWL8K_USE_AUTO_RATE
);
2946 cmd
->rate_type
= cpu_to_le32(MWL8K_UCAST_RATE
);
2948 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2955 * CMD_USE_FIXED_RATE (AP version).
2957 struct mwl8k_cmd_use_fixed_rate_ap
{
2958 struct mwl8k_cmd_pkt header
;
2960 __le32 allow_rate_drop
;
2962 struct mwl8k_rate_entry_ap
{
2964 __le32 enable_retry
;
2969 u8 multicast_rate_type
;
2974 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw
*hw
, int mcast
, int mgmt
)
2976 struct mwl8k_cmd_use_fixed_rate_ap
*cmd
;
2979 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2983 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2984 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2985 cmd
->action
= cpu_to_le32(MWL8K_USE_AUTO_RATE
);
2986 cmd
->multicast_rate
= mcast
;
2987 cmd
->management_rate
= mgmt
;
2989 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2996 * CMD_ENABLE_SNIFFER.
2998 struct mwl8k_cmd_enable_sniffer
{
2999 struct mwl8k_cmd_pkt header
;
3003 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
3005 struct mwl8k_cmd_enable_sniffer
*cmd
;
3008 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3012 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
3013 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3014 cmd
->action
= cpu_to_le32(!!enable
);
3016 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3025 struct mwl8k_cmd_set_mac_addr
{
3026 struct mwl8k_cmd_pkt header
;
3030 __u8 mac_addr
[ETH_ALEN
];
3032 __u8 mac_addr
[ETH_ALEN
];
3036 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3037 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3038 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
3039 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
3041 static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw
*hw
,
3042 struct ieee80211_vif
*vif
, u8
*mac
)
3044 struct mwl8k_priv
*priv
= hw
->priv
;
3045 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3046 struct mwl8k_cmd_set_mac_addr
*cmd
;
3050 mac_type
= MWL8K_MAC_TYPE_PRIMARY_AP
;
3051 if (vif
!= NULL
&& vif
->type
== NL80211_IFTYPE_STATION
) {
3052 if (mwl8k_vif
->macid
+ 1 == ffs(priv
->sta_macids_supported
))
3053 mac_type
= MWL8K_MAC_TYPE_PRIMARY_CLIENT
;
3055 mac_type
= MWL8K_MAC_TYPE_SECONDARY_CLIENT
;
3056 } else if (vif
!= NULL
&& vif
->type
== NL80211_IFTYPE_AP
) {
3057 if (mwl8k_vif
->macid
+ 1 == ffs(priv
->ap_macids_supported
))
3058 mac_type
= MWL8K_MAC_TYPE_PRIMARY_AP
;
3060 mac_type
= MWL8K_MAC_TYPE_SECONDARY_AP
;
3063 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3067 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR
);
3068 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3070 cmd
->mbss
.mac_type
= cpu_to_le16(mac_type
);
3071 memcpy(cmd
->mbss
.mac_addr
, mac
, ETH_ALEN
);
3073 memcpy(cmd
->mac_addr
, mac
, ETH_ALEN
);
3076 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3083 * CMD_SET_RATEADAPT_MODE.
3085 struct mwl8k_cmd_set_rate_adapt_mode
{
3086 struct mwl8k_cmd_pkt header
;
3091 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw
*hw
, __u16 mode
)
3093 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
3096 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3100 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
3101 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3102 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
3103 cmd
->mode
= cpu_to_le16(mode
);
3105 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3114 struct mwl8k_cmd_bss_start
{
3115 struct mwl8k_cmd_pkt header
;
3119 static int mwl8k_cmd_bss_start(struct ieee80211_hw
*hw
,
3120 struct ieee80211_vif
*vif
, int enable
)
3122 struct mwl8k_cmd_bss_start
*cmd
;
3125 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3129 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BSS_START
);
3130 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3131 cmd
->enable
= cpu_to_le32(enable
);
3133 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3142 struct mwl8k_cmd_set_new_stn
{
3143 struct mwl8k_cmd_pkt header
;
3149 __le32 legacy_rates
;
3152 __le16 ht_capabilities_info
;
3153 __u8 mac_ht_param_info
;
3155 __u8 control_channel
;
3164 #define MWL8K_STA_ACTION_ADD 0
3165 #define MWL8K_STA_ACTION_REMOVE 2
3167 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw
*hw
,
3168 struct ieee80211_vif
*vif
,
3169 struct ieee80211_sta
*sta
)
3171 struct mwl8k_cmd_set_new_stn
*cmd
;
3175 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3179 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3180 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3181 cmd
->aid
= cpu_to_le16(sta
->aid
);
3182 memcpy(cmd
->mac_addr
, sta
->addr
, ETH_ALEN
);
3183 cmd
->stn_id
= cpu_to_le16(sta
->aid
);
3184 cmd
->action
= cpu_to_le16(MWL8K_STA_ACTION_ADD
);
3185 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
3186 rates
= sta
->supp_rates
[IEEE80211_BAND_2GHZ
];
3188 rates
= sta
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
3189 cmd
->legacy_rates
= cpu_to_le32(rates
);
3190 if (sta
->ht_cap
.ht_supported
) {
3191 cmd
->ht_rates
[0] = sta
->ht_cap
.mcs
.rx_mask
[0];
3192 cmd
->ht_rates
[1] = sta
->ht_cap
.mcs
.rx_mask
[1];
3193 cmd
->ht_rates
[2] = sta
->ht_cap
.mcs
.rx_mask
[2];
3194 cmd
->ht_rates
[3] = sta
->ht_cap
.mcs
.rx_mask
[3];
3195 cmd
->ht_capabilities_info
= cpu_to_le16(sta
->ht_cap
.cap
);
3196 cmd
->mac_ht_param_info
= (sta
->ht_cap
.ampdu_factor
& 3) |
3197 ((sta
->ht_cap
.ampdu_density
& 7) << 2);
3198 cmd
->is_qos_sta
= 1;
3201 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3207 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw
*hw
,
3208 struct ieee80211_vif
*vif
)
3210 struct mwl8k_cmd_set_new_stn
*cmd
;
3213 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3217 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3218 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3219 memcpy(cmd
->mac_addr
, vif
->addr
, ETH_ALEN
);
3221 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3227 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw
*hw
,
3228 struct ieee80211_vif
*vif
, u8
*addr
)
3230 struct mwl8k_cmd_set_new_stn
*cmd
;
3233 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3237 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3238 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3239 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
3240 cmd
->action
= cpu_to_le16(MWL8K_STA_ACTION_REMOVE
);
3242 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3249 * CMD_UPDATE_ENCRYPTION.
3252 #define MAX_ENCR_KEY_LENGTH 16
3253 #define MIC_KEY_LENGTH 8
3255 struct mwl8k_cmd_update_encryption
{
3256 struct mwl8k_cmd_pkt header
;
3263 } __attribute__((packed
));
3265 struct mwl8k_cmd_set_key
{
3266 struct mwl8k_cmd_pkt header
;
3275 __u8 key_material
[MAX_ENCR_KEY_LENGTH
];
3276 __u8 tkip_tx_mic_key
[MIC_KEY_LENGTH
];
3277 __u8 tkip_rx_mic_key
[MIC_KEY_LENGTH
];
3278 __le16 tkip_rsc_low
;
3279 __le32 tkip_rsc_high
;
3280 __le16 tkip_tsc_low
;
3281 __le32 tkip_tsc_high
;
3283 } __attribute__((packed
));
3288 MWL8K_ENCR_REMOVE_KEY
,
3289 MWL8K_ENCR_SET_GROUP_KEY
,
3292 #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
3293 #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
3294 #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
3295 #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
3296 #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
3304 #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
3305 #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
3306 #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
3307 #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
3308 #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
3310 static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw
*hw
,
3311 struct ieee80211_vif
*vif
,
3315 struct mwl8k_cmd_update_encryption
*cmd
;
3318 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3322 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION
);
3323 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3324 cmd
->action
= cpu_to_le32(MWL8K_ENCR_ENABLE
);
3325 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
3326 cmd
->encr_type
= encr_type
;
3328 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3334 static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key
*cmd
,
3336 struct ieee80211_key_conf
*key
)
3338 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION
);
3339 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3340 cmd
->length
= cpu_to_le16(sizeof(*cmd
) -
3341 offsetof(struct mwl8k_cmd_set_key
, length
));
3342 cmd
->key_id
= cpu_to_le32(key
->keyidx
);
3343 cmd
->key_len
= cpu_to_le16(key
->keylen
);
3344 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
3346 switch (key
->cipher
) {
3347 case WLAN_CIPHER_SUITE_WEP40
:
3348 case WLAN_CIPHER_SUITE_WEP104
:
3349 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_WEP
);
3350 if (key
->keyidx
== 0)
3351 cmd
->key_info
= cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY
);
3354 case WLAN_CIPHER_SUITE_TKIP
:
3355 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_TKIP
);
3356 cmd
->key_info
= (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
3357 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE
)
3358 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY
);
3359 cmd
->key_info
|= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
3360 | MWL8K_KEY_FLAG_TSC_VALID
);
3362 case WLAN_CIPHER_SUITE_CCMP
:
3363 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_CCMP
);
3364 cmd
->key_info
= (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
3365 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE
)
3366 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY
);
3375 static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw
*hw
,
3376 struct ieee80211_vif
*vif
,
3378 struct ieee80211_key_conf
*key
)
3380 struct mwl8k_cmd_set_key
*cmd
;
3385 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3387 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3391 rc
= mwl8k_encryption_set_cmd_info(cmd
, addr
, key
);
3397 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
3398 action
= MWL8K_ENCR_SET_KEY
;
3400 action
= MWL8K_ENCR_SET_GROUP_KEY
;
3402 switch (key
->cipher
) {
3403 case WLAN_CIPHER_SUITE_WEP40
:
3404 case WLAN_CIPHER_SUITE_WEP104
:
3405 if (!mwl8k_vif
->wep_key_conf
[idx
].enabled
) {
3406 memcpy(mwl8k_vif
->wep_key_conf
[idx
].key
, key
,
3407 sizeof(*key
) + key
->keylen
);
3408 mwl8k_vif
->wep_key_conf
[idx
].enabled
= 1;
3412 action
= MWL8K_ENCR_SET_KEY
;
3414 case WLAN_CIPHER_SUITE_TKIP
:
3415 keymlen
= MAX_ENCR_KEY_LENGTH
+ 2 * MIC_KEY_LENGTH
;
3417 case WLAN_CIPHER_SUITE_CCMP
:
3418 keymlen
= key
->keylen
;
3425 memcpy(cmd
->key_material
, key
->key
, keymlen
);
3426 cmd
->action
= cpu_to_le32(action
);
3428 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3435 static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw
*hw
,
3436 struct ieee80211_vif
*vif
,
3438 struct ieee80211_key_conf
*key
)
3440 struct mwl8k_cmd_set_key
*cmd
;
3442 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3444 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3448 rc
= mwl8k_encryption_set_cmd_info(cmd
, addr
, key
);
3452 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
3453 WLAN_CIPHER_SUITE_WEP104
)
3454 mwl8k_vif
->wep_key_conf
[key
->keyidx
].enabled
= 0;
3456 cmd
->action
= cpu_to_le32(MWL8K_ENCR_REMOVE_KEY
);
3458 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3465 static int mwl8k_set_key(struct ieee80211_hw
*hw
,
3466 enum set_key_cmd cmd_param
,
3467 struct ieee80211_vif
*vif
,
3468 struct ieee80211_sta
*sta
,
3469 struct ieee80211_key_conf
*key
)
3474 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3476 if (vif
->type
== NL80211_IFTYPE_STATION
)
3480 addr
= hw
->wiphy
->perm_addr
;
3484 if (cmd_param
== SET_KEY
) {
3485 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
3486 rc
= mwl8k_cmd_encryption_set_key(hw
, vif
, addr
, key
);
3490 if ((key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
3491 || (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
))
3492 encr_type
= MWL8K_UPDATE_ENCRYPTION_TYPE_WEP
;
3494 encr_type
= MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED
;
3496 rc
= mwl8k_cmd_update_encryption_enable(hw
, vif
, addr
,
3501 mwl8k_vif
->is_hw_crypto_enabled
= true;
3504 rc
= mwl8k_cmd_encryption_remove_key(hw
, vif
, addr
, key
);
3509 mwl8k_vif
->is_hw_crypto_enabled
= false;
3519 struct ewc_ht_info
{
3525 struct peer_capability_info
{
3526 /* Peer type - AP vs. STA. */
3529 /* Basic 802.11 capabilities from assoc resp. */
3532 /* Set if peer supports 802.11n high throughput (HT). */
3535 /* Valid if HT is supported. */
3537 __u8 extended_ht_caps
;
3538 struct ewc_ht_info ewc_info
;
3540 /* Legacy rate table. Intersection of our rates and peer rates. */
3541 __u8 legacy_rates
[12];
3543 /* HT rate table. Intersection of our rates and peer rates. */
3547 /* If set, interoperability mode, no proprietary extensions. */
3551 __le16 amsdu_enabled
;
3554 struct mwl8k_cmd_update_stadb
{
3555 struct mwl8k_cmd_pkt header
;
3557 /* See STADB_ACTION_TYPE */
3560 /* Peer MAC address */
3561 __u8 peer_addr
[ETH_ALEN
];
3565 /* Peer info - valid during add/update. */
3566 struct peer_capability_info peer_info
;
3569 #define MWL8K_STA_DB_MODIFY_ENTRY 1
3570 #define MWL8K_STA_DB_DEL_ENTRY 2
3572 /* Peer Entry flags - used to define the type of the peer node */
3573 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
3575 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw
*hw
,
3576 struct ieee80211_vif
*vif
,
3577 struct ieee80211_sta
*sta
)
3579 struct mwl8k_cmd_update_stadb
*cmd
;
3580 struct peer_capability_info
*p
;
3584 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3588 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
3589 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3590 cmd
->action
= cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY
);
3591 memcpy(cmd
->peer_addr
, sta
->addr
, ETH_ALEN
);
3593 p
= &cmd
->peer_info
;
3594 p
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
3595 p
->basic_caps
= cpu_to_le16(vif
->bss_conf
.assoc_capability
);
3596 p
->ht_support
= sta
->ht_cap
.ht_supported
;
3597 p
->ht_caps
= cpu_to_le16(sta
->ht_cap
.cap
);
3598 p
->extended_ht_caps
= (sta
->ht_cap
.ampdu_factor
& 3) |
3599 ((sta
->ht_cap
.ampdu_density
& 7) << 2);
3600 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
3601 rates
= sta
->supp_rates
[IEEE80211_BAND_2GHZ
];
3603 rates
= sta
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
3604 legacy_rate_mask_to_array(p
->legacy_rates
, rates
);
3605 memcpy(p
->ht_rates
, sta
->ht_cap
.mcs
.rx_mask
, 16);
3607 p
->amsdu_enabled
= 0;
3609 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3612 return rc
? rc
: p
->station_id
;
3615 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw
*hw
,
3616 struct ieee80211_vif
*vif
, u8
*addr
)
3618 struct mwl8k_cmd_update_stadb
*cmd
;
3621 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3625 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
3626 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3627 cmd
->action
= cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY
);
3628 memcpy(cmd
->peer_addr
, addr
, ETH_ALEN
);
3630 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3638 * Interrupt handling.
3640 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
3642 struct ieee80211_hw
*hw
= dev_id
;
3643 struct mwl8k_priv
*priv
= hw
->priv
;
3646 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3650 if (status
& MWL8K_A2H_INT_TX_DONE
) {
3651 status
&= ~MWL8K_A2H_INT_TX_DONE
;
3652 tasklet_schedule(&priv
->poll_tx_task
);
3655 if (status
& MWL8K_A2H_INT_RX_READY
) {
3656 status
&= ~MWL8K_A2H_INT_RX_READY
;
3657 tasklet_schedule(&priv
->poll_rx_task
);
3661 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3663 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
3664 if (priv
->hostcmd_wait
!= NULL
)
3665 complete(priv
->hostcmd_wait
);
3668 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
3669 if (!mutex_is_locked(&priv
->fw_mutex
) &&
3670 priv
->radio_on
&& priv
->pending_tx_pkts
)
3671 mwl8k_tx_start(priv
);
3677 static void mwl8k_tx_poll(unsigned long data
)
3679 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
3680 struct mwl8k_priv
*priv
= hw
->priv
;
3686 spin_lock_bh(&priv
->tx_lock
);
3688 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3689 limit
-= mwl8k_txq_reclaim(hw
, i
, limit
, 0);
3691 if (!priv
->pending_tx_pkts
&& priv
->tx_wait
!= NULL
) {
3692 complete(priv
->tx_wait
);
3693 priv
->tx_wait
= NULL
;
3696 spin_unlock_bh(&priv
->tx_lock
);
3699 writel(~MWL8K_A2H_INT_TX_DONE
,
3700 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3702 tasklet_schedule(&priv
->poll_tx_task
);
3706 static void mwl8k_rx_poll(unsigned long data
)
3708 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
3709 struct mwl8k_priv
*priv
= hw
->priv
;
3713 limit
-= rxq_process(hw
, 0, limit
);
3714 limit
-= rxq_refill(hw
, 0, limit
);
3717 writel(~MWL8K_A2H_INT_RX_READY
,
3718 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3720 tasklet_schedule(&priv
->poll_rx_task
);
3726 * Core driver operations.
3728 static int mwl8k_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3730 struct mwl8k_priv
*priv
= hw
->priv
;
3731 int index
= skb_get_queue_mapping(skb
);
3734 if (!priv
->radio_on
) {
3735 wiphy_debug(hw
->wiphy
,
3736 "dropped TX frame since radio disabled\n");
3738 return NETDEV_TX_OK
;
3741 rc
= mwl8k_txq_xmit(hw
, index
, skb
);
3746 static int mwl8k_start(struct ieee80211_hw
*hw
)
3748 struct mwl8k_priv
*priv
= hw
->priv
;
3751 rc
= request_irq(priv
->pdev
->irq
, mwl8k_interrupt
,
3752 IRQF_SHARED
, MWL8K_NAME
, hw
);
3754 wiphy_err(hw
->wiphy
, "failed to register IRQ handler\n");
3758 /* Enable TX reclaim and RX tasklets. */
3759 tasklet_enable(&priv
->poll_tx_task
);
3760 tasklet_enable(&priv
->poll_rx_task
);
3762 /* Enable interrupts */
3763 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3765 rc
= mwl8k_fw_lock(hw
);
3767 rc
= mwl8k_cmd_radio_enable(hw
);
3771 rc
= mwl8k_cmd_enable_sniffer(hw
, 0);
3774 rc
= mwl8k_cmd_set_pre_scan(hw
);
3777 rc
= mwl8k_cmd_set_post_scan(hw
,
3778 "\x00\x00\x00\x00\x00\x00");
3782 rc
= mwl8k_cmd_set_rateadapt_mode(hw
, 0);
3785 rc
= mwl8k_cmd_set_wmm_mode(hw
, 0);
3787 mwl8k_fw_unlock(hw
);
3791 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3792 free_irq(priv
->pdev
->irq
, hw
);
3793 tasklet_disable(&priv
->poll_tx_task
);
3794 tasklet_disable(&priv
->poll_rx_task
);
3800 static void mwl8k_stop(struct ieee80211_hw
*hw
)
3802 struct mwl8k_priv
*priv
= hw
->priv
;
3805 mwl8k_cmd_radio_disable(hw
);
3807 ieee80211_stop_queues(hw
);
3809 /* Disable interrupts */
3810 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3811 free_irq(priv
->pdev
->irq
, hw
);
3813 /* Stop finalize join worker */
3814 cancel_work_sync(&priv
->finalize_join_worker
);
3815 if (priv
->beacon_skb
!= NULL
)
3816 dev_kfree_skb(priv
->beacon_skb
);
3818 /* Stop TX reclaim and RX tasklets. */
3819 tasklet_disable(&priv
->poll_tx_task
);
3820 tasklet_disable(&priv
->poll_rx_task
);
3822 /* Return all skbs to mac80211 */
3823 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3824 mwl8k_txq_reclaim(hw
, i
, INT_MAX
, 1);
3827 static int mwl8k_reload_firmware(struct ieee80211_hw
*hw
, char *fw_image
);
3829 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
3830 struct ieee80211_vif
*vif
)
3832 struct mwl8k_priv
*priv
= hw
->priv
;
3833 struct mwl8k_vif
*mwl8k_vif
;
3834 u32 macids_supported
;
3836 struct mwl8k_device_info
*di
;
3839 * Reject interface creation if sniffer mode is active, as
3840 * STA operation is mutually exclusive with hardware sniffer
3841 * mode. (Sniffer mode is only used on STA firmware.)
3843 if (priv
->sniffer_enabled
) {
3844 wiphy_info(hw
->wiphy
,
3845 "unable to create STA interface because sniffer mode is enabled\n");
3849 di
= priv
->device_info
;
3850 switch (vif
->type
) {
3851 case NL80211_IFTYPE_AP
:
3852 if (!priv
->ap_fw
&& di
->fw_image_ap
) {
3853 /* we must load the ap fw to meet this request */
3854 if (!list_empty(&priv
->vif_list
))
3856 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_ap
);
3860 macids_supported
= priv
->ap_macids_supported
;
3862 case NL80211_IFTYPE_STATION
:
3863 if (priv
->ap_fw
&& di
->fw_image_sta
) {
3864 /* we must load the sta fw to meet this request */
3865 if (!list_empty(&priv
->vif_list
))
3867 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_sta
);
3871 macids_supported
= priv
->sta_macids_supported
;
3877 macid
= ffs(macids_supported
& ~priv
->macids_used
);
3881 /* Setup driver private area. */
3882 mwl8k_vif
= MWL8K_VIF(vif
);
3883 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
3884 mwl8k_vif
->vif
= vif
;
3885 mwl8k_vif
->macid
= macid
;
3886 mwl8k_vif
->seqno
= 0;
3887 memcpy(mwl8k_vif
->bssid
, vif
->addr
, ETH_ALEN
);
3888 mwl8k_vif
->is_hw_crypto_enabled
= false;
3890 /* Set the mac address. */
3891 mwl8k_cmd_set_mac_addr(hw
, vif
, vif
->addr
);
3894 mwl8k_cmd_set_new_stn_add_self(hw
, vif
);
3896 priv
->macids_used
|= 1 << mwl8k_vif
->macid
;
3897 list_add_tail(&mwl8k_vif
->list
, &priv
->vif_list
);
3902 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
3903 struct ieee80211_vif
*vif
)
3905 struct mwl8k_priv
*priv
= hw
->priv
;
3906 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3909 mwl8k_cmd_set_new_stn_del(hw
, vif
, vif
->addr
);
3911 mwl8k_cmd_set_mac_addr(hw
, vif
, "\x00\x00\x00\x00\x00\x00");
3913 priv
->macids_used
&= ~(1 << mwl8k_vif
->macid
);
3914 list_del(&mwl8k_vif
->list
);
3917 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
3919 struct ieee80211_conf
*conf
= &hw
->conf
;
3920 struct mwl8k_priv
*priv
= hw
->priv
;
3923 if (conf
->flags
& IEEE80211_CONF_IDLE
) {
3924 mwl8k_cmd_radio_disable(hw
);
3928 rc
= mwl8k_fw_lock(hw
);
3932 rc
= mwl8k_cmd_radio_enable(hw
);
3936 rc
= mwl8k_cmd_set_rf_channel(hw
, conf
);
3940 if (conf
->power_level
> 18)
3941 conf
->power_level
= 18;
3944 rc
= mwl8k_cmd_tx_power(hw
, conf
, conf
->power_level
);
3948 rc
= mwl8k_cmd_rf_antenna(hw
, MWL8K_RF_ANTENNA_RX
, 0x3);
3950 wiphy_warn(hw
->wiphy
, "failed to set # of RX antennas");
3951 rc
= mwl8k_cmd_rf_antenna(hw
, MWL8K_RF_ANTENNA_TX
, 0x7);
3953 wiphy_warn(hw
->wiphy
, "failed to set # of TX antennas");
3956 rc
= mwl8k_cmd_rf_tx_power(hw
, conf
->power_level
);
3959 rc
= mwl8k_cmd_mimo_config(hw
, 0x7, 0x7);
3963 mwl8k_fw_unlock(hw
);
3969 mwl8k_bss_info_changed_sta(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
3970 struct ieee80211_bss_conf
*info
, u32 changed
)
3972 struct mwl8k_priv
*priv
= hw
->priv
;
3973 u32 ap_legacy_rates
;
3974 u8 ap_mcs_rates
[16];
3977 if (mwl8k_fw_lock(hw
))
3981 * No need to capture a beacon if we're no longer associated.
3983 if ((changed
& BSS_CHANGED_ASSOC
) && !vif
->bss_conf
.assoc
)
3984 priv
->capture_beacon
= false;
3987 * Get the AP's legacy and MCS rates.
3989 if (vif
->bss_conf
.assoc
) {
3990 struct ieee80211_sta
*ap
;
3994 ap
= ieee80211_find_sta(vif
, vif
->bss_conf
.bssid
);
4000 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
4001 ap_legacy_rates
= ap
->supp_rates
[IEEE80211_BAND_2GHZ
];
4004 ap
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
4006 memcpy(ap_mcs_rates
, ap
->ht_cap
.mcs
.rx_mask
, 16);
4011 if ((changed
& BSS_CHANGED_ASSOC
) && vif
->bss_conf
.assoc
) {
4012 rc
= mwl8k_cmd_set_rate(hw
, vif
, ap_legacy_rates
, ap_mcs_rates
);
4016 rc
= mwl8k_cmd_use_fixed_rate_sta(hw
);
4021 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4022 rc
= mwl8k_set_radio_preamble(hw
,
4023 vif
->bss_conf
.use_short_preamble
);
4028 if (changed
& BSS_CHANGED_ERP_SLOT
) {
4029 rc
= mwl8k_cmd_set_slot(hw
, vif
->bss_conf
.use_short_slot
);
4034 if (vif
->bss_conf
.assoc
&&
4035 (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_ERP_CTS_PROT
|
4037 rc
= mwl8k_cmd_set_aid(hw
, vif
, ap_legacy_rates
);
4042 if (vif
->bss_conf
.assoc
&&
4043 (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_BEACON_INT
))) {
4045 * Finalize the join. Tell rx handler to process
4046 * next beacon from our BSSID.
4048 memcpy(priv
->capture_bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
4049 priv
->capture_beacon
= true;
4053 mwl8k_fw_unlock(hw
);
4057 mwl8k_bss_info_changed_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4058 struct ieee80211_bss_conf
*info
, u32 changed
)
4062 if (mwl8k_fw_lock(hw
))
4065 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4066 rc
= mwl8k_set_radio_preamble(hw
,
4067 vif
->bss_conf
.use_short_preamble
);
4072 if (changed
& BSS_CHANGED_BASIC_RATES
) {
4077 * Use lowest supported basic rate for multicasts
4078 * and management frames (such as probe responses --
4079 * beacons will always go out at 1 Mb/s).
4081 idx
= ffs(vif
->bss_conf
.basic_rates
);
4085 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
4086 rate
= mwl8k_rates_24
[idx
].hw_value
;
4088 rate
= mwl8k_rates_50
[idx
].hw_value
;
4090 mwl8k_cmd_use_fixed_rate_ap(hw
, rate
, rate
);
4093 if (changed
& (BSS_CHANGED_BEACON_INT
| BSS_CHANGED_BEACON
)) {
4094 struct sk_buff
*skb
;
4096 skb
= ieee80211_beacon_get(hw
, vif
);
4098 mwl8k_cmd_set_beacon(hw
, vif
, skb
->data
, skb
->len
);
4103 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
4104 mwl8k_cmd_bss_start(hw
, vif
, info
->enable_beacon
);
4107 mwl8k_fw_unlock(hw
);
4111 mwl8k_bss_info_changed(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4112 struct ieee80211_bss_conf
*info
, u32 changed
)
4114 struct mwl8k_priv
*priv
= hw
->priv
;
4117 mwl8k_bss_info_changed_sta(hw
, vif
, info
, changed
);
4119 mwl8k_bss_info_changed_ap(hw
, vif
, info
, changed
);
4122 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
4123 struct netdev_hw_addr_list
*mc_list
)
4125 struct mwl8k_cmd_pkt
*cmd
;
4128 * Synthesize and return a command packet that programs the
4129 * hardware multicast address filter. At this point we don't
4130 * know whether FIF_ALLMULTI is being requested, but if it is,
4131 * we'll end up throwing this packet away and creating a new
4132 * one in mwl8k_configure_filter().
4134 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 0, mc_list
);
4136 return (unsigned long)cmd
;
4140 mwl8k_configure_filter_sniffer(struct ieee80211_hw
*hw
,
4141 unsigned int changed_flags
,
4142 unsigned int *total_flags
)
4144 struct mwl8k_priv
*priv
= hw
->priv
;
4147 * Hardware sniffer mode is mutually exclusive with STA
4148 * operation, so refuse to enable sniffer mode if a STA
4149 * interface is active.
4151 if (!list_empty(&priv
->vif_list
)) {
4152 if (net_ratelimit())
4153 wiphy_info(hw
->wiphy
,
4154 "not enabling sniffer mode because STA interface is active\n");
4158 if (!priv
->sniffer_enabled
) {
4159 if (mwl8k_cmd_enable_sniffer(hw
, 1))
4161 priv
->sniffer_enabled
= true;
4164 *total_flags
&= FIF_PROMISC_IN_BSS
| FIF_ALLMULTI
|
4165 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
|
4171 static struct mwl8k_vif
*mwl8k_first_vif(struct mwl8k_priv
*priv
)
4173 if (!list_empty(&priv
->vif_list
))
4174 return list_entry(priv
->vif_list
.next
, struct mwl8k_vif
, list
);
4179 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
4180 unsigned int changed_flags
,
4181 unsigned int *total_flags
,
4184 struct mwl8k_priv
*priv
= hw
->priv
;
4185 struct mwl8k_cmd_pkt
*cmd
= (void *)(unsigned long)multicast
;
4188 * AP firmware doesn't allow fine-grained control over
4189 * the receive filter.
4192 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
4198 * Enable hardware sniffer mode if FIF_CONTROL or
4199 * FIF_OTHER_BSS is requested.
4201 if (*total_flags
& (FIF_CONTROL
| FIF_OTHER_BSS
) &&
4202 mwl8k_configure_filter_sniffer(hw
, changed_flags
, total_flags
)) {
4207 /* Clear unsupported feature flags */
4208 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
4210 if (mwl8k_fw_lock(hw
)) {
4215 if (priv
->sniffer_enabled
) {
4216 mwl8k_cmd_enable_sniffer(hw
, 0);
4217 priv
->sniffer_enabled
= false;
4220 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
4221 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
) {
4223 * Disable the BSS filter.
4225 mwl8k_cmd_set_pre_scan(hw
);
4227 struct mwl8k_vif
*mwl8k_vif
;
4231 * Enable the BSS filter.
4233 * If there is an active STA interface, use that
4234 * interface's BSSID, otherwise use a dummy one
4235 * (where the OUI part needs to be nonzero for
4236 * the BSSID to be accepted by POST_SCAN).
4238 mwl8k_vif
= mwl8k_first_vif(priv
);
4239 if (mwl8k_vif
!= NULL
)
4240 bssid
= mwl8k_vif
->vif
->bss_conf
.bssid
;
4242 bssid
= "\x01\x00\x00\x00\x00\x00";
4244 mwl8k_cmd_set_post_scan(hw
, bssid
);
4249 * If FIF_ALLMULTI is being requested, throw away the command
4250 * packet that ->prepare_multicast() built and replace it with
4251 * a command packet that enables reception of all multicast
4254 if (*total_flags
& FIF_ALLMULTI
) {
4256 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 1, NULL
);
4260 mwl8k_post_cmd(hw
, cmd
);
4264 mwl8k_fw_unlock(hw
);
4267 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
4269 return mwl8k_cmd_set_rts_threshold(hw
, value
);
4272 static int mwl8k_sta_remove(struct ieee80211_hw
*hw
,
4273 struct ieee80211_vif
*vif
,
4274 struct ieee80211_sta
*sta
)
4276 struct mwl8k_priv
*priv
= hw
->priv
;
4279 return mwl8k_cmd_set_new_stn_del(hw
, vif
, sta
->addr
);
4281 return mwl8k_cmd_update_stadb_del(hw
, vif
, sta
->addr
);
4284 static int mwl8k_sta_add(struct ieee80211_hw
*hw
,
4285 struct ieee80211_vif
*vif
,
4286 struct ieee80211_sta
*sta
)
4288 struct mwl8k_priv
*priv
= hw
->priv
;
4291 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4292 struct ieee80211_key_conf
*key
;
4295 ret
= mwl8k_cmd_update_stadb_add(hw
, vif
, sta
);
4297 MWL8K_STA(sta
)->peer_id
= ret
;
4302 ret
= mwl8k_cmd_set_new_stn_add(hw
, vif
, sta
);
4305 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
4306 key
= IEEE80211_KEY_CONF(mwl8k_vif
->wep_key_conf
[i
].key
);
4307 if (mwl8k_vif
->wep_key_conf
[i
].enabled
)
4308 mwl8k_set_key(hw
, SET_KEY
, vif
, sta
, key
);
4313 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
4314 const struct ieee80211_tx_queue_params
*params
)
4316 struct mwl8k_priv
*priv
= hw
->priv
;
4319 rc
= mwl8k_fw_lock(hw
);
4321 BUG_ON(queue
> MWL8K_TX_QUEUES
- 1);
4322 memcpy(&priv
->wmm_params
[queue
], params
, sizeof(*params
));
4324 if (!priv
->wmm_enabled
)
4325 rc
= mwl8k_cmd_set_wmm_mode(hw
, 1);
4328 rc
= mwl8k_cmd_set_edca_params(hw
, queue
,
4334 mwl8k_fw_unlock(hw
);
4340 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
4341 struct ieee80211_low_level_stats
*stats
)
4343 return mwl8k_cmd_get_stat(hw
, stats
);
4346 static int mwl8k_get_survey(struct ieee80211_hw
*hw
, int idx
,
4347 struct survey_info
*survey
)
4349 struct mwl8k_priv
*priv
= hw
->priv
;
4350 struct ieee80211_conf
*conf
= &hw
->conf
;
4355 survey
->channel
= conf
->channel
;
4356 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
4357 survey
->noise
= priv
->noise
;
4363 mwl8k_ampdu_action(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4364 enum ieee80211_ampdu_mlme_action action
,
4365 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
4369 case IEEE80211_AMPDU_RX_START
:
4370 case IEEE80211_AMPDU_RX_STOP
:
4371 if (!(hw
->flags
& IEEE80211_HW_AMPDU_AGGREGATION
))
4379 static const struct ieee80211_ops mwl8k_ops
= {
4381 .start
= mwl8k_start
,
4383 .add_interface
= mwl8k_add_interface
,
4384 .remove_interface
= mwl8k_remove_interface
,
4385 .config
= mwl8k_config
,
4386 .bss_info_changed
= mwl8k_bss_info_changed
,
4387 .prepare_multicast
= mwl8k_prepare_multicast
,
4388 .configure_filter
= mwl8k_configure_filter
,
4389 .set_key
= mwl8k_set_key
,
4390 .set_rts_threshold
= mwl8k_set_rts_threshold
,
4391 .sta_add
= mwl8k_sta_add
,
4392 .sta_remove
= mwl8k_sta_remove
,
4393 .conf_tx
= mwl8k_conf_tx
,
4394 .get_stats
= mwl8k_get_stats
,
4395 .get_survey
= mwl8k_get_survey
,
4396 .ampdu_action
= mwl8k_ampdu_action
,
4399 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
4401 struct mwl8k_priv
*priv
=
4402 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
4403 struct sk_buff
*skb
= priv
->beacon_skb
;
4404 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
4405 int len
= skb
->len
- offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
4406 const u8
*tim
= cfg80211_find_ie(WLAN_EID_TIM
,
4407 mgmt
->u
.beacon
.variable
, len
);
4408 int dtim_period
= 1;
4410 if (tim
&& tim
[1] >= 2)
4411 dtim_period
= tim
[3];
4413 mwl8k_cmd_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim_period
);
4416 priv
->beacon_skb
= NULL
;
4425 #define MWL8K_8366_AP_FW_API 1
4426 #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
4427 #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
4429 static struct mwl8k_device_info mwl8k_info_tbl
[] __devinitdata
= {
4431 .part_name
= "88w8363",
4432 .helper_image
= "mwl8k/helper_8363.fw",
4433 .fw_image_sta
= "mwl8k/fmimage_8363.fw",
4436 .part_name
= "88w8687",
4437 .helper_image
= "mwl8k/helper_8687.fw",
4438 .fw_image_sta
= "mwl8k/fmimage_8687.fw",
4441 .part_name
= "88w8366",
4442 .helper_image
= "mwl8k/helper_8366.fw",
4443 .fw_image_sta
= "mwl8k/fmimage_8366.fw",
4444 .fw_image_ap
= MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API
),
4445 .fw_api_ap
= MWL8K_8366_AP_FW_API
,
4446 .ap_rxd_ops
= &rxd_8366_ap_ops
,
4450 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
4451 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
4452 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
4453 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
4454 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
4455 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
4456 MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API
));
4458 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table
) = {
4459 { PCI_VDEVICE(MARVELL
, 0x2a0a), .driver_data
= MWL8363
, },
4460 { PCI_VDEVICE(MARVELL
, 0x2a0c), .driver_data
= MWL8363
, },
4461 { PCI_VDEVICE(MARVELL
, 0x2a24), .driver_data
= MWL8363
, },
4462 { PCI_VDEVICE(MARVELL
, 0x2a2b), .driver_data
= MWL8687
, },
4463 { PCI_VDEVICE(MARVELL
, 0x2a30), .driver_data
= MWL8687
, },
4464 { PCI_VDEVICE(MARVELL
, 0x2a40), .driver_data
= MWL8366
, },
4465 { PCI_VDEVICE(MARVELL
, 0x2a43), .driver_data
= MWL8366
, },
4468 MODULE_DEVICE_TABLE(pci
, mwl8k_pci_id_table
);
4470 static int mwl8k_request_alt_fw(struct mwl8k_priv
*priv
)
4473 printk(KERN_ERR
"%s: Error requesting preferred fw %s.\n"
4474 "Trying alternative firmware %s\n", pci_name(priv
->pdev
),
4475 priv
->fw_pref
, priv
->fw_alt
);
4476 rc
= mwl8k_request_fw(priv
, priv
->fw_alt
, &priv
->fw_ucode
, true);
4478 printk(KERN_ERR
"%s: Error requesting alt fw %s\n",
4479 pci_name(priv
->pdev
), priv
->fw_alt
);
4485 static int mwl8k_firmware_load_success(struct mwl8k_priv
*priv
);
4486 static void mwl8k_fw_state_machine(const struct firmware
*fw
, void *context
)
4488 struct mwl8k_priv
*priv
= context
;
4489 struct mwl8k_device_info
*di
= priv
->device_info
;
4492 switch (priv
->fw_state
) {
4495 printk(KERN_ERR
"%s: Error requesting helper fw %s\n",
4496 pci_name(priv
->pdev
), di
->helper_image
);
4499 priv
->fw_helper
= fw
;
4500 rc
= mwl8k_request_fw(priv
, priv
->fw_pref
, &priv
->fw_ucode
,
4502 if (rc
&& priv
->fw_alt
) {
4503 rc
= mwl8k_request_alt_fw(priv
);
4506 priv
->fw_state
= FW_STATE_LOADING_ALT
;
4510 priv
->fw_state
= FW_STATE_LOADING_PREF
;
4513 case FW_STATE_LOADING_PREF
:
4516 rc
= mwl8k_request_alt_fw(priv
);
4519 priv
->fw_state
= FW_STATE_LOADING_ALT
;
4523 priv
->fw_ucode
= fw
;
4524 rc
= mwl8k_firmware_load_success(priv
);
4528 complete(&priv
->firmware_loading_complete
);
4532 case FW_STATE_LOADING_ALT
:
4534 printk(KERN_ERR
"%s: Error requesting alt fw %s\n",
4535 pci_name(priv
->pdev
), di
->helper_image
);
4538 priv
->fw_ucode
= fw
;
4539 rc
= mwl8k_firmware_load_success(priv
);
4543 complete(&priv
->firmware_loading_complete
);
4547 printk(KERN_ERR
"%s: Unexpected firmware loading state: %d\n",
4548 MWL8K_NAME
, priv
->fw_state
);
4555 priv
->fw_state
= FW_STATE_ERROR
;
4556 complete(&priv
->firmware_loading_complete
);
4557 device_release_driver(&priv
->pdev
->dev
);
4558 mwl8k_release_firmware(priv
);
4561 static int mwl8k_init_firmware(struct ieee80211_hw
*hw
, char *fw_image
,
4564 struct mwl8k_priv
*priv
= hw
->priv
;
4567 /* Reset firmware and hardware */
4568 mwl8k_hw_reset(priv
);
4570 /* Ask userland hotplug daemon for the device firmware */
4571 rc
= mwl8k_request_firmware(priv
, fw_image
, nowait
);
4573 wiphy_err(hw
->wiphy
, "Firmware files not found\n");
4580 /* Load firmware into hardware */
4581 rc
= mwl8k_load_firmware(hw
);
4583 wiphy_err(hw
->wiphy
, "Cannot start firmware\n");
4585 /* Reclaim memory once firmware is successfully loaded */
4586 mwl8k_release_firmware(priv
);
4591 /* initialize hw after successfully loading a firmware image */
4592 static int mwl8k_probe_hw(struct ieee80211_hw
*hw
)
4594 struct mwl8k_priv
*priv
= hw
->priv
;
4599 priv
->rxd_ops
= priv
->device_info
->ap_rxd_ops
;
4600 if (priv
->rxd_ops
== NULL
) {
4601 wiphy_err(hw
->wiphy
,
4602 "Driver does not have AP firmware image support for this hardware\n");
4603 goto err_stop_firmware
;
4606 priv
->rxd_ops
= &rxd_sta_ops
;
4609 priv
->sniffer_enabled
= false;
4610 priv
->wmm_enabled
= false;
4611 priv
->pending_tx_pkts
= 0;
4613 rc
= mwl8k_rxq_init(hw
, 0);
4615 goto err_stop_firmware
;
4616 rxq_refill(hw
, 0, INT_MAX
);
4618 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
4619 rc
= mwl8k_txq_init(hw
, i
);
4621 goto err_free_queues
;
4624 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4625 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4626 iowrite32(MWL8K_A2H_INT_TX_DONE
| MWL8K_A2H_INT_RX_READY
,
4627 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
4628 iowrite32(0xffffffff, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
4630 rc
= request_irq(priv
->pdev
->irq
, mwl8k_interrupt
,
4631 IRQF_SHARED
, MWL8K_NAME
, hw
);
4633 wiphy_err(hw
->wiphy
, "failed to register IRQ handler\n");
4634 goto err_free_queues
;
4638 * Temporarily enable interrupts. Initial firmware host
4639 * commands use interrupts and avoid polling. Disable
4640 * interrupts when done.
4642 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4644 /* Get config data, mac addrs etc */
4646 rc
= mwl8k_cmd_get_hw_spec_ap(hw
);
4648 rc
= mwl8k_cmd_set_hw_spec(hw
);
4650 rc
= mwl8k_cmd_get_hw_spec_sta(hw
);
4653 wiphy_err(hw
->wiphy
, "Cannot initialise firmware\n");
4657 /* Turn radio off */
4658 rc
= mwl8k_cmd_radio_disable(hw
);
4660 wiphy_err(hw
->wiphy
, "Cannot disable\n");
4664 /* Clear MAC address */
4665 rc
= mwl8k_cmd_set_mac_addr(hw
, NULL
, "\x00\x00\x00\x00\x00\x00");
4667 wiphy_err(hw
->wiphy
, "Cannot clear MAC address\n");
4671 /* Disable interrupts */
4672 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4673 free_irq(priv
->pdev
->irq
, hw
);
4675 wiphy_info(hw
->wiphy
, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
4676 priv
->device_info
->part_name
,
4677 priv
->hw_rev
, hw
->wiphy
->perm_addr
,
4678 priv
->ap_fw
? "AP" : "STA",
4679 (priv
->fw_rev
>> 24) & 0xff, (priv
->fw_rev
>> 16) & 0xff,
4680 (priv
->fw_rev
>> 8) & 0xff, priv
->fw_rev
& 0xff);
4685 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4686 free_irq(priv
->pdev
->irq
, hw
);
4689 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4690 mwl8k_txq_deinit(hw
, i
);
4691 mwl8k_rxq_deinit(hw
, 0);
4694 mwl8k_hw_reset(priv
);
4700 * invoke mwl8k_reload_firmware to change the firmware image after the device
4701 * has already been registered
4703 static int mwl8k_reload_firmware(struct ieee80211_hw
*hw
, char *fw_image
)
4706 struct mwl8k_priv
*priv
= hw
->priv
;
4709 mwl8k_rxq_deinit(hw
, 0);
4711 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4712 mwl8k_txq_deinit(hw
, i
);
4714 rc
= mwl8k_init_firmware(hw
, fw_image
, false);
4718 rc
= mwl8k_probe_hw(hw
);
4722 rc
= mwl8k_start(hw
);
4726 rc
= mwl8k_config(hw
, ~0);
4730 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
4731 rc
= mwl8k_conf_tx(hw
, i
, &priv
->wmm_params
[i
]);
4739 printk(KERN_WARNING
"mwl8k: Failed to reload firmware image.\n");
4743 static int mwl8k_firmware_load_success(struct mwl8k_priv
*priv
)
4745 struct ieee80211_hw
*hw
= priv
->hw
;
4748 rc
= mwl8k_load_firmware(hw
);
4749 mwl8k_release_firmware(priv
);
4751 wiphy_err(hw
->wiphy
, "Cannot start firmware\n");
4756 * Extra headroom is the size of the required DMA header
4757 * minus the size of the smallest 802.11 frame (CTS frame).
4759 hw
->extra_tx_headroom
=
4760 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
4762 hw
->channel_change_time
= 10;
4764 hw
->queues
= MWL8K_TX_QUEUES
;
4766 /* Set rssi values to dBm */
4767 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
;
4768 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
4769 hw
->sta_data_size
= sizeof(struct mwl8k_sta
);
4771 priv
->macids_used
= 0;
4772 INIT_LIST_HEAD(&priv
->vif_list
);
4774 /* Set default radio state and preamble */
4776 priv
->radio_short_preamble
= 0;
4778 /* Finalize join worker */
4779 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
4781 /* TX reclaim and RX tasklets. */
4782 tasklet_init(&priv
->poll_tx_task
, mwl8k_tx_poll
, (unsigned long)hw
);
4783 tasklet_disable(&priv
->poll_tx_task
);
4784 tasklet_init(&priv
->poll_rx_task
, mwl8k_rx_poll
, (unsigned long)hw
);
4785 tasklet_disable(&priv
->poll_rx_task
);
4787 /* Power management cookie */
4788 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
4789 if (priv
->cookie
== NULL
)
4792 mutex_init(&priv
->fw_mutex
);
4793 priv
->fw_mutex_owner
= NULL
;
4794 priv
->fw_mutex_depth
= 0;
4795 priv
->hostcmd_wait
= NULL
;
4797 spin_lock_init(&priv
->tx_lock
);
4799 priv
->tx_wait
= NULL
;
4801 rc
= mwl8k_probe_hw(hw
);
4803 goto err_free_cookie
;
4805 hw
->wiphy
->interface_modes
= 0;
4806 if (priv
->ap_macids_supported
|| priv
->device_info
->fw_image_ap
)
4807 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_AP
);
4808 if (priv
->sta_macids_supported
|| priv
->device_info
->fw_image_sta
)
4809 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_STATION
);
4811 rc
= ieee80211_register_hw(hw
);
4813 wiphy_err(hw
->wiphy
, "Cannot register device\n");
4814 goto err_unprobe_hw
;
4820 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4821 mwl8k_txq_deinit(hw
, i
);
4822 mwl8k_rxq_deinit(hw
, 0);
4825 if (priv
->cookie
!= NULL
)
4826 pci_free_consistent(priv
->pdev
, 4,
4827 priv
->cookie
, priv
->cookie_dma
);
4831 static int __devinit
mwl8k_probe(struct pci_dev
*pdev
,
4832 const struct pci_device_id
*id
)
4834 static int printed_version
;
4835 struct ieee80211_hw
*hw
;
4836 struct mwl8k_priv
*priv
;
4837 struct mwl8k_device_info
*di
;
4840 if (!printed_version
) {
4841 printk(KERN_INFO
"%s version %s\n", MWL8K_DESC
, MWL8K_VERSION
);
4842 printed_version
= 1;
4846 rc
= pci_enable_device(pdev
);
4848 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
4853 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
4855 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
4857 goto err_disable_device
;
4860 pci_set_master(pdev
);
4863 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
4865 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
4870 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
4871 pci_set_drvdata(pdev
, hw
);
4876 priv
->device_info
= &mwl8k_info_tbl
[id
->driver_data
];
4879 priv
->sram
= pci_iomap(pdev
, 0, 0x10000);
4880 if (priv
->sram
== NULL
) {
4881 wiphy_err(hw
->wiphy
, "Cannot map device SRAM\n");
4886 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
4887 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
4889 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
4890 if (priv
->regs
== NULL
) {
4891 priv
->regs
= pci_iomap(pdev
, 2, 0x10000);
4892 if (priv
->regs
== NULL
) {
4893 wiphy_err(hw
->wiphy
, "Cannot map device registers\n");
4899 * Choose the initial fw image depending on user input. If a second
4900 * image is available, make it the alternative image that will be
4901 * loaded if the first one fails.
4903 init_completion(&priv
->firmware_loading_complete
);
4904 di
= priv
->device_info
;
4905 if (ap_mode_default
&& di
->fw_image_ap
) {
4906 priv
->fw_pref
= di
->fw_image_ap
;
4907 priv
->fw_alt
= di
->fw_image_sta
;
4908 } else if (!ap_mode_default
&& di
->fw_image_sta
) {
4909 priv
->fw_pref
= di
->fw_image_sta
;
4910 priv
->fw_alt
= di
->fw_image_ap
;
4911 } else if (ap_mode_default
&& !di
->fw_image_ap
&& di
->fw_image_sta
) {
4912 printk(KERN_WARNING
"AP fw is unavailable. Using STA fw.");
4913 priv
->fw_pref
= di
->fw_image_sta
;
4914 } else if (!ap_mode_default
&& !di
->fw_image_sta
&& di
->fw_image_ap
) {
4915 printk(KERN_WARNING
"STA fw is unavailable. Using AP fw.");
4916 priv
->fw_pref
= di
->fw_image_ap
;
4918 rc
= mwl8k_init_firmware(hw
, priv
->fw_pref
, true);
4920 goto err_stop_firmware
;
4924 mwl8k_hw_reset(priv
);
4927 if (priv
->regs
!= NULL
)
4928 pci_iounmap(pdev
, priv
->regs
);
4930 if (priv
->sram
!= NULL
)
4931 pci_iounmap(pdev
, priv
->sram
);
4933 pci_set_drvdata(pdev
, NULL
);
4934 ieee80211_free_hw(hw
);
4937 pci_release_regions(pdev
);
4940 pci_disable_device(pdev
);
4945 static void __devexit
mwl8k_shutdown(struct pci_dev
*pdev
)
4947 printk(KERN_ERR
"===>%s(%u)\n", __func__
, __LINE__
);
4950 static void __devexit
mwl8k_remove(struct pci_dev
*pdev
)
4952 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
4953 struct mwl8k_priv
*priv
;
4960 wait_for_completion(&priv
->firmware_loading_complete
);
4962 if (priv
->fw_state
== FW_STATE_ERROR
) {
4963 mwl8k_hw_reset(priv
);
4967 ieee80211_stop_queues(hw
);
4969 ieee80211_unregister_hw(hw
);
4971 /* Remove TX reclaim and RX tasklets. */
4972 tasklet_kill(&priv
->poll_tx_task
);
4973 tasklet_kill(&priv
->poll_rx_task
);
4976 mwl8k_hw_reset(priv
);
4978 /* Return all skbs to mac80211 */
4979 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4980 mwl8k_txq_reclaim(hw
, i
, INT_MAX
, 1);
4982 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4983 mwl8k_txq_deinit(hw
, i
);
4985 mwl8k_rxq_deinit(hw
, 0);
4987 pci_free_consistent(priv
->pdev
, 4, priv
->cookie
, priv
->cookie_dma
);
4990 pci_iounmap(pdev
, priv
->regs
);
4991 pci_iounmap(pdev
, priv
->sram
);
4992 pci_set_drvdata(pdev
, NULL
);
4993 ieee80211_free_hw(hw
);
4994 pci_release_regions(pdev
);
4995 pci_disable_device(pdev
);
4998 static struct pci_driver mwl8k_driver
= {
5000 .id_table
= mwl8k_pci_id_table
,
5001 .probe
= mwl8k_probe
,
5002 .remove
= __devexit_p(mwl8k_remove
),
5003 .shutdown
= __devexit_p(mwl8k_shutdown
),
5006 static int __init
mwl8k_init(void)
5008 return pci_register_driver(&mwl8k_driver
);
5011 static void __exit
mwl8k_exit(void)
5013 pci_unregister_driver(&mwl8k_driver
);
5016 module_init(mwl8k_init
);
5017 module_exit(mwl8k_exit
);
5019 MODULE_DESCRIPTION(MWL8K_DESC
);
5020 MODULE_VERSION(MWL8K_VERSION
);
5021 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
5022 MODULE_LICENSE("GPL");