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/interrupt.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/spinlock.h>
18 #include <linux/list.h>
19 #include <linux/pci.h>
20 #include <linux/delay.h>
21 #include <linux/completion.h>
22 #include <linux/etherdevice.h>
23 #include <linux/slab.h>
24 #include <net/mac80211.h>
25 #include <linux/moduleparam.h>
26 #include <linux/firmware.h>
27 #include <linux/workqueue.h>
29 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
30 #define MWL8K_NAME KBUILD_MODNAME
31 #define MWL8K_VERSION "0.13"
33 /* Module parameters */
34 static bool ap_mode_default;
35 module_param(ap_mode_default, bool, 0);
36 MODULE_PARM_DESC(ap_mode_default,
37 "Set to 1 to make ap mode the default instead of sta mode");
39 /* Register definitions */
40 #define MWL8K_HIU_GEN_PTR 0x00000c10
41 #define MWL8K_MODE_STA 0x0000005a
42 #define MWL8K_MODE_AP 0x000000a5
43 #define MWL8K_HIU_INT_CODE 0x00000c14
44 #define MWL8K_FWSTA_READY 0xf0f1f2f4
45 #define MWL8K_FWAP_READY 0xf1f2f4a5
46 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
47 #define MWL8K_HIU_SCRATCH 0x00000c40
49 /* Host->device communications */
50 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
51 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
52 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
53 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
54 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
55 #define MWL8K_H2A_INT_DUMMY (1 << 20)
56 #define MWL8K_H2A_INT_RESET (1 << 15)
57 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
58 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
60 /* Device->host communications */
61 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
62 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
63 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
64 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
65 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
66 #define MWL8K_A2H_INT_DUMMY (1 << 20)
67 #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
68 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
69 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
70 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
71 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
72 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
73 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
74 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
75 #define MWL8K_A2H_INT_RX_READY (1 << 1)
76 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
78 /* HW micro second timer register
79 * located at offset 0xA600. This
80 * will be used to timestamp tx
84 #define MWL8K_HW_TIMER_REGISTER 0x0000a600
86 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
87 MWL8K_A2H_INT_CHNL_SWITCHED | \
88 MWL8K_A2H_INT_QUEUE_EMPTY | \
89 MWL8K_A2H_INT_RADAR_DETECT | \
90 MWL8K_A2H_INT_RADIO_ON | \
91 MWL8K_A2H_INT_RADIO_OFF | \
92 MWL8K_A2H_INT_MAC_EVENT | \
93 MWL8K_A2H_INT_OPC_DONE | \
94 MWL8K_A2H_INT_RX_READY | \
95 MWL8K_A2H_INT_TX_DONE | \
96 MWL8K_A2H_INT_BA_WATCHDOG)
98 #define MWL8K_RX_QUEUES 1
99 #define MWL8K_TX_WMM_QUEUES 4
100 #define MWL8K_MAX_AMPDU_QUEUES 8
101 #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
102 #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
104 /* txpriorities are mapped with hw queues.
105 * Each hw queue has a txpriority.
107 #define TOTAL_HW_TX_QUEUES 8
109 /* Each HW queue can have one AMPDU stream.
110 * But, because one of the hw queue is reserved,
111 * maximum AMPDU queues that can be created are
112 * one short of total tx queues.
114 #define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1)
118 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
119 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
120 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
121 __le16 *qos, s8 *noise);
124 struct mwl8k_device_info {
129 struct rxd_ops *ap_rxd_ops;
133 struct mwl8k_rx_queue {
136 /* hw receives here */
139 /* refill descs here */
146 DEFINE_DMA_UNMAP_ADDR(dma);
150 struct mwl8k_tx_queue {
151 /* hw transmits here */
154 /* sw appends here */
158 struct mwl8k_tx_desc *txd;
160 struct sk_buff **skb;
166 AMPDU_STREAM_IN_PROGRESS,
170 struct mwl8k_ampdu_stream {
171 struct ieee80211_sta *sta;
178 struct ieee80211_hw *hw;
179 struct pci_dev *pdev;
182 struct mwl8k_device_info *device_info;
188 const struct firmware *fw_helper;
189 const struct firmware *fw_ucode;
191 /* hardware/firmware parameters */
193 struct rxd_ops *rxd_ops;
194 struct ieee80211_supported_band band_24;
195 struct ieee80211_channel channels_24[14];
196 struct ieee80211_rate rates_24[14];
197 struct ieee80211_supported_band band_50;
198 struct ieee80211_channel channels_50[4];
199 struct ieee80211_rate rates_50[9];
200 u32 ap_macids_supported;
201 u32 sta_macids_supported;
203 /* Ampdu stream information */
205 spinlock_t stream_lock;
206 struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
207 struct work_struct watchdog_ba_handle;
209 /* firmware access */
210 struct mutex fw_mutex;
211 struct task_struct *fw_mutex_owner;
212 struct task_struct *hw_restart_owner;
214 struct completion *hostcmd_wait;
216 atomic_t watchdog_event_pending;
218 /* lock held over TX and TX reap */
221 /* TX quiesce completion, protected by fw_mutex and tx_lock */
222 struct completion *tx_wait;
224 /* List of interfaces. */
226 struct list_head vif_list;
228 /* power management status cookie from firmware */
230 dma_addr_t cookie_dma;
237 * Running count of TX packets in flight, to avoid
238 * iterating over the transmit rings each time.
242 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
243 struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
244 u32 txq_offset[MWL8K_MAX_TX_QUEUES];
247 bool radio_short_preamble;
248 bool sniffer_enabled;
251 /* XXX need to convert this to handle multiple interfaces */
253 u8 capture_bssid[ETH_ALEN];
254 struct sk_buff *beacon_skb;
257 * This FJ worker has to be global as it is scheduled from the
258 * RX handler. At this point we don't know which interface it
259 * belongs to until the list of bssids waiting to complete join
262 struct work_struct finalize_join_worker;
264 /* Tasklet to perform TX reclaim. */
265 struct tasklet_struct poll_tx_task;
267 /* Tasklet to perform RX. */
268 struct tasklet_struct poll_rx_task;
270 /* Most recently reported noise in dBm */
274 * preserve the queue configurations so they can be restored if/when
275 * the firmware image is swapped.
277 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
279 /* To perform the task of reloading the firmware */
280 struct work_struct fw_reload;
281 bool hw_restart_in_progress;
283 /* async firmware loading state */
288 struct completion firmware_loading_complete;
290 /* bitmap of running BSSes */
294 #define MAX_WEP_KEY_LEN 13
295 #define NUM_WEP_KEYS 4
297 /* Per interface specific private data */
299 struct list_head list;
300 struct ieee80211_vif *vif;
302 /* Firmware macid for this vif. */
305 /* Non AMPDU sequence number assigned by driver. */
311 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
312 } wep_key_conf[NUM_WEP_KEYS];
317 /* A flag to indicate is HW crypto is enabled for this bssid */
318 bool is_hw_crypto_enabled;
320 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
321 #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
323 struct tx_traffic_info {
328 #define MWL8K_MAX_TID 8
330 /* Index into station database. Returned by UPDATE_STADB. */
333 struct tx_traffic_info tx_stats[MWL8K_MAX_TID];
335 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
337 static const struct ieee80211_channel mwl8k_channels_24[] = {
338 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2412, .hw_value = 1, },
339 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2417, .hw_value = 2, },
340 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2422, .hw_value = 3, },
341 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2427, .hw_value = 4, },
342 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2432, .hw_value = 5, },
343 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2437, .hw_value = 6, },
344 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2442, .hw_value = 7, },
345 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2447, .hw_value = 8, },
346 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2452, .hw_value = 9, },
347 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2457, .hw_value = 10, },
348 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2462, .hw_value = 11, },
349 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2467, .hw_value = 12, },
350 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2472, .hw_value = 13, },
351 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2484, .hw_value = 14, },
354 static const struct ieee80211_rate mwl8k_rates_24[] = {
355 { .bitrate = 10, .hw_value = 2, },
356 { .bitrate = 20, .hw_value = 4, },
357 { .bitrate = 55, .hw_value = 11, },
358 { .bitrate = 110, .hw_value = 22, },
359 { .bitrate = 220, .hw_value = 44, },
360 { .bitrate = 60, .hw_value = 12, },
361 { .bitrate = 90, .hw_value = 18, },
362 { .bitrate = 120, .hw_value = 24, },
363 { .bitrate = 180, .hw_value = 36, },
364 { .bitrate = 240, .hw_value = 48, },
365 { .bitrate = 360, .hw_value = 72, },
366 { .bitrate = 480, .hw_value = 96, },
367 { .bitrate = 540, .hw_value = 108, },
368 { .bitrate = 720, .hw_value = 144, },
371 static const struct ieee80211_channel mwl8k_channels_50[] = {
372 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5180, .hw_value = 36, },
373 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5200, .hw_value = 40, },
374 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5220, .hw_value = 44, },
375 { .band = IEEE80211_BAND_5GHZ, .center_freq = 5240, .hw_value = 48, },
378 static const struct ieee80211_rate mwl8k_rates_50[] = {
379 { .bitrate = 60, .hw_value = 12, },
380 { .bitrate = 90, .hw_value = 18, },
381 { .bitrate = 120, .hw_value = 24, },
382 { .bitrate = 180, .hw_value = 36, },
383 { .bitrate = 240, .hw_value = 48, },
384 { .bitrate = 360, .hw_value = 72, },
385 { .bitrate = 480, .hw_value = 96, },
386 { .bitrate = 540, .hw_value = 108, },
387 { .bitrate = 720, .hw_value = 144, },
390 /* Set or get info from Firmware */
391 #define MWL8K_CMD_GET 0x0000
392 #define MWL8K_CMD_SET 0x0001
393 #define MWL8K_CMD_SET_LIST 0x0002
395 /* Firmware command codes */
396 #define MWL8K_CMD_CODE_DNLD 0x0001
397 #define MWL8K_CMD_GET_HW_SPEC 0x0003
398 #define MWL8K_CMD_SET_HW_SPEC 0x0004
399 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
400 #define MWL8K_CMD_GET_STAT 0x0014
401 #define MWL8K_CMD_RADIO_CONTROL 0x001c
402 #define MWL8K_CMD_RF_TX_POWER 0x001e
403 #define MWL8K_CMD_TX_POWER 0x001f
404 #define MWL8K_CMD_RF_ANTENNA 0x0020
405 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
406 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
407 #define MWL8K_CMD_SET_POST_SCAN 0x0108
408 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
409 #define MWL8K_CMD_SET_AID 0x010d
410 #define MWL8K_CMD_SET_RATE 0x0110
411 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
412 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
413 #define MWL8K_CMD_SET_SLOT 0x0114
414 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
415 #define MWL8K_CMD_SET_WMM_MODE 0x0123
416 #define MWL8K_CMD_MIMO_CONFIG 0x0125
417 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
418 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
419 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
420 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
421 #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
422 #define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
423 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
424 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
425 #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
426 #define MWL8K_CMD_UPDATE_STADB 0x1123
427 #define MWL8K_CMD_BASTREAM 0x1125
429 static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
431 u16 command = le16_to_cpu(cmd);
433 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
434 snprintf(buf, bufsize, "%s", #x);\
437 switch (command & ~0x8000) {
438 MWL8K_CMDNAME(CODE_DNLD);
439 MWL8K_CMDNAME(GET_HW_SPEC);
440 MWL8K_CMDNAME(SET_HW_SPEC);
441 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
442 MWL8K_CMDNAME(GET_STAT);
443 MWL8K_CMDNAME(RADIO_CONTROL);
444 MWL8K_CMDNAME(RF_TX_POWER);
445 MWL8K_CMDNAME(TX_POWER);
446 MWL8K_CMDNAME(RF_ANTENNA);
447 MWL8K_CMDNAME(SET_BEACON);
448 MWL8K_CMDNAME(SET_PRE_SCAN);
449 MWL8K_CMDNAME(SET_POST_SCAN);
450 MWL8K_CMDNAME(SET_RF_CHANNEL);
451 MWL8K_CMDNAME(SET_AID);
452 MWL8K_CMDNAME(SET_RATE);
453 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
454 MWL8K_CMDNAME(RTS_THRESHOLD);
455 MWL8K_CMDNAME(SET_SLOT);
456 MWL8K_CMDNAME(SET_EDCA_PARAMS);
457 MWL8K_CMDNAME(SET_WMM_MODE);
458 MWL8K_CMDNAME(MIMO_CONFIG);
459 MWL8K_CMDNAME(USE_FIXED_RATE);
460 MWL8K_CMDNAME(ENABLE_SNIFFER);
461 MWL8K_CMDNAME(SET_MAC_ADDR);
462 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
463 MWL8K_CMDNAME(BSS_START);
464 MWL8K_CMDNAME(SET_NEW_STN);
465 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
466 MWL8K_CMDNAME(UPDATE_STADB);
467 MWL8K_CMDNAME(BASTREAM);
468 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
470 snprintf(buf, bufsize, "0x%x", cmd);
477 /* Hardware and firmware reset */
478 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
480 iowrite32(MWL8K_H2A_INT_RESET,
481 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
482 iowrite32(MWL8K_H2A_INT_RESET,
483 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
487 /* Release fw image */
488 static void mwl8k_release_fw(const struct firmware **fw)
492 release_firmware(*fw);
496 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
498 mwl8k_release_fw(&priv->fw_ucode);
499 mwl8k_release_fw(&priv->fw_helper);
502 /* states for asynchronous f/w loading */
503 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
506 FW_STATE_LOADING_PREF,
507 FW_STATE_LOADING_ALT,
511 /* Request fw image */
512 static int mwl8k_request_fw(struct mwl8k_priv *priv,
513 const char *fname, const struct firmware **fw,
516 /* release current image */
518 mwl8k_release_fw(fw);
521 return request_firmware_nowait(THIS_MODULE, 1, fname,
522 &priv->pdev->dev, GFP_KERNEL,
523 priv, mwl8k_fw_state_machine);
525 return request_firmware(fw, fname, &priv->pdev->dev);
528 static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
531 struct mwl8k_device_info *di = priv->device_info;
534 if (di->helper_image != NULL) {
536 rc = mwl8k_request_fw(priv, di->helper_image,
537 &priv->fw_helper, true);
539 rc = mwl8k_request_fw(priv, di->helper_image,
540 &priv->fw_helper, false);
542 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
543 pci_name(priv->pdev), di->helper_image);
551 * if we get here, no helper image is needed. Skip the
552 * FW_STATE_INIT state.
554 priv->fw_state = FW_STATE_LOADING_PREF;
555 rc = mwl8k_request_fw(priv, fw_image,
559 rc = mwl8k_request_fw(priv, fw_image,
560 &priv->fw_ucode, false);
562 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
563 pci_name(priv->pdev), fw_image);
564 mwl8k_release_fw(&priv->fw_helper);
571 struct mwl8k_cmd_pkt {
584 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
586 void __iomem *regs = priv->regs;
590 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
591 if (pci_dma_mapping_error(priv->pdev, dma_addr))
594 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
595 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
596 iowrite32(MWL8K_H2A_INT_DOORBELL,
597 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
598 iowrite32(MWL8K_H2A_INT_DUMMY,
599 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
605 int_code = ioread32(regs +
606 MWL8K_HIU_H2A_INTERRUPT_STATUS);
610 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
611 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
612 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
620 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
622 return loops ? 0 : -ETIMEDOUT;
625 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
626 const u8 *data, size_t length)
628 struct mwl8k_cmd_pkt *cmd;
632 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
636 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
643 int block_size = length > 256 ? 256 : length;
645 memcpy(cmd->payload, data + done, block_size);
646 cmd->length = cpu_to_le16(block_size);
648 rc = mwl8k_send_fw_load_cmd(priv, cmd,
649 sizeof(*cmd) + block_size);
654 length -= block_size;
659 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
667 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
668 const u8 *data, size_t length)
670 unsigned char *buffer;
671 int may_continue, rc = 0;
672 u32 done, prev_block_size;
674 buffer = kmalloc(1024, GFP_KERNEL);
681 while (may_continue > 0) {
684 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
685 if (block_size & 1) {
689 done += prev_block_size;
690 length -= prev_block_size;
693 if (block_size > 1024 || block_size > length) {
703 if (block_size == 0) {
710 prev_block_size = block_size;
711 memcpy(buffer, data + done, block_size);
713 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
718 if (!rc && length != 0)
726 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
728 struct mwl8k_priv *priv = hw->priv;
729 const struct firmware *fw = priv->fw_ucode;
733 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4) && !priv->is_8764) {
734 const struct firmware *helper = priv->fw_helper;
736 if (helper == NULL) {
737 printk(KERN_ERR "%s: helper image needed but none "
738 "given\n", pci_name(priv->pdev));
742 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
744 printk(KERN_ERR "%s: unable to load firmware "
745 "helper image\n", pci_name(priv->pdev));
750 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
753 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
755 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
759 printk(KERN_ERR "%s: unable to load firmware image\n",
760 pci_name(priv->pdev));
764 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
770 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
771 if (ready_code == MWL8K_FWAP_READY) {
774 } else if (ready_code == MWL8K_FWSTA_READY) {
783 return loops ? 0 : -ETIMEDOUT;
787 /* DMA header used by firmware and hardware. */
788 struct mwl8k_dma_data {
790 struct ieee80211_hdr wh;
794 /* Routines to add/remove DMA header from skb. */
795 static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
797 struct mwl8k_dma_data *tr;
800 tr = (struct mwl8k_dma_data *)skb->data;
801 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
803 if (hdrlen != sizeof(tr->wh)) {
804 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
805 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
806 *((__le16 *)(tr->data - 2)) = qos;
808 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
812 if (hdrlen != sizeof(*tr))
813 skb_pull(skb, sizeof(*tr) - hdrlen);
816 #define REDUCED_TX_HEADROOM 8
819 mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb,
820 int head_pad, int tail_pad)
822 struct ieee80211_hdr *wh;
825 struct mwl8k_dma_data *tr;
828 * Add a firmware DMA header; the firmware requires that we
829 * present a 2-byte payload length followed by a 4-address
830 * header (without QoS field), followed (optionally) by any
831 * WEP/ExtIV header (but only filled in for CCMP).
833 wh = (struct ieee80211_hdr *)skb->data;
835 hdrlen = ieee80211_hdrlen(wh->frame_control);
838 * Check if skb_resize is required because of
839 * tx_headroom adjustment.
841 if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts)
842 + REDUCED_TX_HEADROOM))) {
843 if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) {
845 wiphy_err(priv->hw->wiphy,
846 "Failed to reallocate TX buffer\n");
849 skb->truesize += REDUCED_TX_HEADROOM;
852 reqd_hdrlen = sizeof(*tr) + head_pad;
854 if (hdrlen != reqd_hdrlen)
855 skb_push(skb, reqd_hdrlen - hdrlen);
857 if (ieee80211_is_data_qos(wh->frame_control))
858 hdrlen -= IEEE80211_QOS_CTL_LEN;
860 tr = (struct mwl8k_dma_data *)skb->data;
862 memmove(&tr->wh, wh, hdrlen);
863 if (hdrlen != sizeof(tr->wh))
864 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
867 * Firmware length is the length of the fully formed "802.11
868 * payload". That is, everything except for the 802.11 header.
869 * This includes all crypto material including the MIC.
871 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
874 static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv,
877 struct ieee80211_hdr *wh;
878 struct ieee80211_tx_info *tx_info;
879 struct ieee80211_key_conf *key_conf;
883 wh = (struct ieee80211_hdr *)skb->data;
885 tx_info = IEEE80211_SKB_CB(skb);
888 if (ieee80211_is_data(wh->frame_control))
889 key_conf = tx_info->control.hw_key;
892 * Make sure the packet header is in the DMA header format (4-address
893 * without QoS), and add head & tail padding when HW crypto is enabled.
895 * We have the following trailer padding requirements:
896 * - WEP: 4 trailer bytes (ICV)
897 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
898 * - CCMP: 8 trailer bytes (MIC)
901 if (key_conf != NULL) {
902 head_pad = key_conf->iv_len;
903 switch (key_conf->cipher) {
904 case WLAN_CIPHER_SUITE_WEP40:
905 case WLAN_CIPHER_SUITE_WEP104:
908 case WLAN_CIPHER_SUITE_TKIP:
911 case WLAN_CIPHER_SUITE_CCMP:
916 mwl8k_add_dma_header(priv, skb, head_pad, data_pad);
920 * Packet reception for 88w8366/88w8764 AP firmware.
922 struct mwl8k_rxd_ap {
926 __le32 pkt_phys_addr;
927 __le32 next_rxd_phys_addr;
931 __le32 hw_noise_floor_info;
940 #define MWL8K_AP_RATE_INFO_MCS_FORMAT 0x80
941 #define MWL8K_AP_RATE_INFO_40MHZ 0x40
942 #define MWL8K_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
944 #define MWL8K_AP_RX_CTRL_OWNED_BY_HOST 0x80
946 /* 8366/8764 AP rx_status bits */
947 #define MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
948 #define MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
949 #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
950 #define MWL8K_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
951 #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
953 static void mwl8k_rxd_ap_init(void *_rxd, dma_addr_t next_dma_addr)
955 struct mwl8k_rxd_ap *rxd = _rxd;
957 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
958 rxd->rx_ctrl = MWL8K_AP_RX_CTRL_OWNED_BY_HOST;
961 static void mwl8k_rxd_ap_refill(void *_rxd, dma_addr_t addr, int len)
963 struct mwl8k_rxd_ap *rxd = _rxd;
965 rxd->pkt_len = cpu_to_le16(len);
966 rxd->pkt_phys_addr = cpu_to_le32(addr);
972 mwl8k_rxd_ap_process(void *_rxd, struct ieee80211_rx_status *status,
973 __le16 *qos, s8 *noise)
975 struct mwl8k_rxd_ap *rxd = _rxd;
977 if (!(rxd->rx_ctrl & MWL8K_AP_RX_CTRL_OWNED_BY_HOST))
981 memset(status, 0, sizeof(*status));
983 status->signal = -rxd->rssi;
984 *noise = -rxd->noise_floor;
986 if (rxd->rate & MWL8K_AP_RATE_INFO_MCS_FORMAT) {
987 status->flag |= RX_FLAG_HT;
988 if (rxd->rate & MWL8K_AP_RATE_INFO_40MHZ)
989 status->flag |= RX_FLAG_40MHZ;
990 status->rate_idx = MWL8K_AP_RATE_INFO_RATEID(rxd->rate);
994 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
995 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
996 status->rate_idx = i;
1002 if (rxd->channel > 14) {
1003 status->band = IEEE80211_BAND_5GHZ;
1004 if (!(status->flag & RX_FLAG_HT))
1005 status->rate_idx -= 5;
1007 status->band = IEEE80211_BAND_2GHZ;
1009 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1012 *qos = rxd->qos_control;
1014 if ((rxd->rx_status != MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
1015 (rxd->rx_status & MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK) &&
1016 (rxd->rx_status & MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
1017 status->flag |= RX_FLAG_MMIC_ERROR;
1019 return le16_to_cpu(rxd->pkt_len);
1022 static struct rxd_ops rxd_ap_ops = {
1023 .rxd_size = sizeof(struct mwl8k_rxd_ap),
1024 .rxd_init = mwl8k_rxd_ap_init,
1025 .rxd_refill = mwl8k_rxd_ap_refill,
1026 .rxd_process = mwl8k_rxd_ap_process,
1030 * Packet reception for STA firmware.
1032 struct mwl8k_rxd_sta {
1036 __le32 pkt_phys_addr;
1037 __le32 next_rxd_phys_addr;
1049 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
1050 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
1051 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
1052 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
1053 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
1054 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
1056 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
1057 #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
1058 /* ICV=0 or MIC=1 */
1059 #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
1060 /* Key is uploaded only in failure case */
1061 #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
1063 static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
1065 struct mwl8k_rxd_sta *rxd = _rxd;
1067 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
1068 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
1071 static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
1073 struct mwl8k_rxd_sta *rxd = _rxd;
1075 rxd->pkt_len = cpu_to_le16(len);
1076 rxd->pkt_phys_addr = cpu_to_le32(addr);
1082 mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
1083 __le16 *qos, s8 *noise)
1085 struct mwl8k_rxd_sta *rxd = _rxd;
1088 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
1092 rate_info = le16_to_cpu(rxd->rate_info);
1094 memset(status, 0, sizeof(*status));
1096 status->signal = -rxd->rssi;
1097 *noise = -rxd->noise_level;
1098 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
1099 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
1101 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
1102 status->flag |= RX_FLAG_SHORTPRE;
1103 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
1104 status->flag |= RX_FLAG_40MHZ;
1105 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
1106 status->flag |= RX_FLAG_SHORT_GI;
1107 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
1108 status->flag |= RX_FLAG_HT;
1110 if (rxd->channel > 14) {
1111 status->band = IEEE80211_BAND_5GHZ;
1112 if (!(status->flag & RX_FLAG_HT))
1113 status->rate_idx -= 5;
1115 status->band = IEEE80211_BAND_2GHZ;
1117 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1120 *qos = rxd->qos_control;
1121 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1122 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1123 status->flag |= RX_FLAG_MMIC_ERROR;
1125 return le16_to_cpu(rxd->pkt_len);
1128 static struct rxd_ops rxd_sta_ops = {
1129 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1130 .rxd_init = mwl8k_rxd_sta_init,
1131 .rxd_refill = mwl8k_rxd_sta_refill,
1132 .rxd_process = mwl8k_rxd_sta_process,
1136 #define MWL8K_RX_DESCS 256
1137 #define MWL8K_RX_MAXSZ 3800
1139 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1141 struct mwl8k_priv *priv = hw->priv;
1142 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1150 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
1152 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1153 if (rxq->rxd == NULL) {
1154 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
1157 memset(rxq->rxd, 0, size);
1159 rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
1160 if (rxq->buf == NULL) {
1161 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
1165 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1169 dma_addr_t next_dma_addr;
1171 desc_size = priv->rxd_ops->rxd_size;
1172 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
1175 if (nexti == MWL8K_RX_DESCS)
1177 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1179 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
1185 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1187 struct mwl8k_priv *priv = hw->priv;
1188 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1192 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
1193 struct sk_buff *skb;
1198 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1202 addr = pci_map_single(priv->pdev, skb->data,
1203 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
1207 if (rxq->tail == MWL8K_RX_DESCS)
1209 rxq->buf[rx].skb = skb;
1210 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
1212 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1213 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
1221 /* Must be called only when the card's reception is completely halted */
1222 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1224 struct mwl8k_priv *priv = hw->priv;
1225 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1228 if (rxq->rxd == NULL)
1231 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1232 if (rxq->buf[i].skb != NULL) {
1233 pci_unmap_single(priv->pdev,
1234 dma_unmap_addr(&rxq->buf[i], dma),
1235 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1236 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
1238 kfree_skb(rxq->buf[i].skb);
1239 rxq->buf[i].skb = NULL;
1246 pci_free_consistent(priv->pdev,
1247 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
1248 rxq->rxd, rxq->rxd_dma);
1254 * Scan a list of BSSIDs to process for finalize join.
1255 * Allows for extension to process multiple BSSIDs.
1258 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1260 return priv->capture_beacon &&
1261 ieee80211_is_beacon(wh->frame_control) &&
1262 ether_addr_equal(wh->addr3, priv->capture_bssid);
1265 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1266 struct sk_buff *skb)
1268 struct mwl8k_priv *priv = hw->priv;
1270 priv->capture_beacon = false;
1271 memset(priv->capture_bssid, 0, ETH_ALEN);
1274 * Use GFP_ATOMIC as rxq_process is called from
1275 * the primary interrupt handler, memory allocation call
1278 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1279 if (priv->beacon_skb != NULL)
1280 ieee80211_queue_work(hw, &priv->finalize_join_worker);
1283 static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1286 struct mwl8k_vif *mwl8k_vif;
1288 list_for_each_entry(mwl8k_vif,
1290 if (memcmp(bssid, mwl8k_vif->bssid,
1298 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1300 struct mwl8k_priv *priv = hw->priv;
1301 struct mwl8k_vif *mwl8k_vif = NULL;
1302 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1306 while (rxq->rxd_count && limit--) {
1307 struct sk_buff *skb;
1310 struct ieee80211_rx_status status;
1311 struct ieee80211_hdr *wh;
1314 skb = rxq->buf[rxq->head].skb;
1318 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1320 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1325 rxq->buf[rxq->head].skb = NULL;
1327 pci_unmap_single(priv->pdev,
1328 dma_unmap_addr(&rxq->buf[rxq->head], dma),
1329 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1330 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1333 if (rxq->head == MWL8K_RX_DESCS)
1338 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1341 * Check for a pending join operation. Save a
1342 * copy of the beacon and schedule a tasklet to
1343 * send a FINALIZE_JOIN command to the firmware.
1345 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1346 mwl8k_save_beacon(hw, skb);
1348 if (ieee80211_has_protected(wh->frame_control)) {
1350 /* Check if hw crypto has been enabled for
1351 * this bss. If yes, set the status flags
1354 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1357 if (mwl8k_vif != NULL &&
1358 mwl8k_vif->is_hw_crypto_enabled) {
1360 * When MMIC ERROR is encountered
1361 * by the firmware, payload is
1362 * dropped and only 32 bytes of
1363 * mwl8k Firmware header is sent
1366 * We need to add four bytes of
1367 * key information. In it
1368 * MAC80211 expects keyidx set to
1369 * 0 for triggering Counter
1370 * Measure of MMIC failure.
1372 if (status.flag & RX_FLAG_MMIC_ERROR) {
1373 struct mwl8k_dma_data *tr;
1374 tr = (struct mwl8k_dma_data *)skb->data;
1375 memset((void *)&(tr->data), 0, 4);
1379 if (!ieee80211_is_auth(wh->frame_control))
1380 status.flag |= RX_FLAG_IV_STRIPPED |
1382 RX_FLAG_MMIC_STRIPPED;
1386 skb_put(skb, pkt_len);
1387 mwl8k_remove_dma_header(skb, qos);
1388 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1389 ieee80211_rx_irqsafe(hw, skb);
1399 * Packet transmission.
1402 #define MWL8K_TXD_STATUS_OK 0x00000001
1403 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1404 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1405 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1406 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1408 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1409 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1410 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1411 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1412 #define MWL8K_QOS_EOSP 0x0010
1414 struct mwl8k_tx_desc {
1419 __le32 pkt_phys_addr;
1421 __u8 dest_MAC_addr[ETH_ALEN];
1422 __le32 next_txd_phys_addr;
1429 #define MWL8K_TX_DESCS 128
1431 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1433 struct mwl8k_priv *priv = hw->priv;
1434 struct mwl8k_tx_queue *txq = priv->txq + index;
1442 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1444 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1445 if (txq->txd == NULL) {
1446 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
1449 memset(txq->txd, 0, size);
1451 txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
1452 if (txq->skb == NULL) {
1453 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1457 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1458 struct mwl8k_tx_desc *tx_desc;
1461 tx_desc = txq->txd + i;
1462 nexti = (i + 1) % MWL8K_TX_DESCS;
1464 tx_desc->status = 0;
1465 tx_desc->next_txd_phys_addr =
1466 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1472 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1474 iowrite32(MWL8K_H2A_INT_PPA_READY,
1475 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1476 iowrite32(MWL8K_H2A_INT_DUMMY,
1477 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1478 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1481 static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1483 struct mwl8k_priv *priv = hw->priv;
1486 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
1487 struct mwl8k_tx_queue *txq = priv->txq + i;
1493 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1494 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1497 status = le32_to_cpu(tx_desc->status);
1498 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1503 if (tx_desc->pkt_len == 0)
1507 wiphy_err(hw->wiphy,
1508 "txq[%d] len=%d head=%d tail=%d "
1509 "fw_owned=%d drv_owned=%d unused=%d\n",
1511 txq->len, txq->head, txq->tail,
1512 fw_owned, drv_owned, unused);
1517 * Must be called with priv->fw_mutex held and tx queues stopped.
1519 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1521 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1523 struct mwl8k_priv *priv = hw->priv;
1524 DECLARE_COMPLETION_ONSTACK(tx_wait);
1530 /* Since fw restart is in progress, allow only the firmware
1531 * commands from the restart code and block the other
1532 * commands since they are going to fail in any case since
1533 * the firmware has crashed
1535 if (priv->hw_restart_in_progress) {
1536 if (priv->hw_restart_owner == current)
1542 if (atomic_read(&priv->watchdog_event_pending))
1546 * The TX queues are stopped at this point, so this test
1547 * doesn't need to take ->tx_lock.
1549 if (!priv->pending_tx_pkts)
1555 spin_lock_bh(&priv->tx_lock);
1556 priv->tx_wait = &tx_wait;
1559 unsigned long timeout;
1561 oldcount = priv->pending_tx_pkts;
1563 spin_unlock_bh(&priv->tx_lock);
1564 timeout = wait_for_completion_timeout(&tx_wait,
1565 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1567 if (atomic_read(&priv->watchdog_event_pending)) {
1568 spin_lock_bh(&priv->tx_lock);
1569 priv->tx_wait = NULL;
1570 spin_unlock_bh(&priv->tx_lock);
1574 spin_lock_bh(&priv->tx_lock);
1577 WARN_ON(priv->pending_tx_pkts);
1579 wiphy_notice(hw->wiphy, "tx rings drained\n");
1583 if (priv->pending_tx_pkts < oldcount) {
1584 wiphy_notice(hw->wiphy,
1585 "waiting for tx rings to drain (%d -> %d pkts)\n",
1586 oldcount, priv->pending_tx_pkts);
1591 priv->tx_wait = NULL;
1593 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1594 MWL8K_TX_WAIT_TIMEOUT_MS);
1595 mwl8k_dump_tx_rings(hw);
1596 priv->hw_restart_in_progress = true;
1597 ieee80211_queue_work(hw, &priv->fw_reload);
1601 priv->tx_wait = NULL;
1602 spin_unlock_bh(&priv->tx_lock);
1607 #define MWL8K_TXD_SUCCESS(status) \
1608 ((status) & (MWL8K_TXD_STATUS_OK | \
1609 MWL8K_TXD_STATUS_OK_RETRY | \
1610 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1612 static int mwl8k_tid_queue_mapping(u8 tid)
1619 return IEEE80211_AC_BE;
1623 return IEEE80211_AC_BK;
1627 return IEEE80211_AC_VI;
1631 return IEEE80211_AC_VO;
1639 /* The firmware will fill in the rate information
1640 * for each packet that gets queued in the hardware
1641 * and these macros will interpret that info.
1644 #define RI_FORMAT(a) (a & 0x0001)
1645 #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
1648 mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1650 struct mwl8k_priv *priv = hw->priv;
1651 struct mwl8k_tx_queue *txq = priv->txq + index;
1655 while (txq->len > 0 && limit--) {
1657 struct mwl8k_tx_desc *tx_desc;
1660 struct sk_buff *skb;
1661 struct ieee80211_tx_info *info;
1663 struct ieee80211_sta *sta;
1664 struct mwl8k_sta *sta_info = NULL;
1666 struct ieee80211_hdr *wh;
1669 tx_desc = txq->txd + tx;
1671 status = le32_to_cpu(tx_desc->status);
1673 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1677 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1680 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1681 BUG_ON(txq->len == 0);
1683 priv->pending_tx_pkts--;
1685 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1686 size = le16_to_cpu(tx_desc->pkt_len);
1688 txq->skb[tx] = NULL;
1690 BUG_ON(skb == NULL);
1691 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1693 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
1695 wh = (struct ieee80211_hdr *) skb->data;
1697 /* Mark descriptor as unused */
1698 tx_desc->pkt_phys_addr = 0;
1699 tx_desc->pkt_len = 0;
1701 info = IEEE80211_SKB_CB(skb);
1702 if (ieee80211_is_data(wh->frame_control)) {
1704 sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
1707 sta_info = MWL8K_STA(sta);
1708 BUG_ON(sta_info == NULL);
1709 rate_info = le16_to_cpu(tx_desc->rate_info);
1710 /* If rate is < 6.5 Mpbs for an ht station
1711 * do not form an ampdu. If the station is a
1712 * legacy station (format = 0), do not form an
1715 if (RI_RATE_ID_MCS(rate_info) < 1 ||
1716 RI_FORMAT(rate_info) == 0) {
1717 sta_info->is_ampdu_allowed = false;
1719 sta_info->is_ampdu_allowed = true;
1725 ieee80211_tx_info_clear_status(info);
1727 /* Rate control is happening in the firmware.
1728 * Ensure no tx rate is being reported.
1730 info->status.rates[0].idx = -1;
1731 info->status.rates[0].count = 1;
1733 if (MWL8K_TXD_SUCCESS(status))
1734 info->flags |= IEEE80211_TX_STAT_ACK;
1736 ieee80211_tx_status_irqsafe(hw, skb);
1744 /* must be called only when the card's transmit is completely halted */
1745 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1747 struct mwl8k_priv *priv = hw->priv;
1748 struct mwl8k_tx_queue *txq = priv->txq + index;
1750 if (txq->txd == NULL)
1753 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1758 pci_free_consistent(priv->pdev,
1759 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1760 txq->txd, txq->txd_dma);
1764 /* caller must hold priv->stream_lock when calling the stream functions */
1765 static struct mwl8k_ampdu_stream *
1766 mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
1768 struct mwl8k_ampdu_stream *stream;
1769 struct mwl8k_priv *priv = hw->priv;
1772 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
1773 stream = &priv->ampdu[i];
1774 if (stream->state == AMPDU_NO_STREAM) {
1776 stream->state = AMPDU_STREAM_NEW;
1779 wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
1788 mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1792 /* if the stream has already been started, don't start it again */
1793 if (stream->state != AMPDU_STREAM_NEW)
1795 ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
1797 wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
1798 "%d\n", stream->sta->addr, stream->tid, ret);
1800 wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
1801 stream->sta->addr, stream->tid);
1806 mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1808 wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
1810 memset(stream, 0, sizeof(*stream));
1813 static struct mwl8k_ampdu_stream *
1814 mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
1816 struct mwl8k_priv *priv = hw->priv;
1819 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
1820 struct mwl8k_ampdu_stream *stream;
1821 stream = &priv->ampdu[i];
1822 if (stream->state == AMPDU_NO_STREAM)
1824 if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
1831 #define MWL8K_AMPDU_PACKET_THRESHOLD 64
1832 static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
1834 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1835 struct tx_traffic_info *tx_stats;
1837 BUG_ON(tid >= MWL8K_MAX_TID);
1838 tx_stats = &sta_info->tx_stats[tid];
1840 return sta_info->is_ampdu_allowed &&
1841 tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
1844 static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
1846 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1847 struct tx_traffic_info *tx_stats;
1849 BUG_ON(tid >= MWL8K_MAX_TID);
1850 tx_stats = &sta_info->tx_stats[tid];
1852 if (tx_stats->start_time == 0)
1853 tx_stats->start_time = jiffies;
1855 /* reset the packet count after each second elapses. If the number of
1856 * packets ever exceeds the ampdu_min_traffic threshold, we will allow
1857 * an ampdu stream to be started.
1859 if (jiffies - tx_stats->start_time > HZ) {
1861 tx_stats->start_time = 0;
1866 /* The hardware ampdu queues start from 5.
1867 * txpriorities for ampdu queues are
1868 * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
1869 * and queue 3 is lowest (queue 4 is reserved)
1874 mwl8k_txq_xmit(struct ieee80211_hw *hw,
1876 struct ieee80211_sta *sta,
1877 struct sk_buff *skb)
1879 struct mwl8k_priv *priv = hw->priv;
1880 struct ieee80211_tx_info *tx_info;
1881 struct mwl8k_vif *mwl8k_vif;
1882 struct ieee80211_hdr *wh;
1883 struct mwl8k_tx_queue *txq;
1884 struct mwl8k_tx_desc *tx;
1891 struct mwl8k_ampdu_stream *stream = NULL;
1892 bool start_ba_session = false;
1893 bool mgmtframe = false;
1894 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
1895 bool eapol_frame = false;
1897 wh = (struct ieee80211_hdr *)skb->data;
1898 if (ieee80211_is_data_qos(wh->frame_control))
1899 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1903 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
1906 if (ieee80211_is_mgmt(wh->frame_control))
1910 mwl8k_encapsulate_tx_frame(priv, skb);
1912 mwl8k_add_dma_header(priv, skb, 0, 0);
1914 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1916 tx_info = IEEE80211_SKB_CB(skb);
1917 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1919 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1920 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1921 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1922 mwl8k_vif->seqno += 0x10;
1925 /* Setup firmware control bit fields for each frame type. */
1928 if (ieee80211_is_mgmt(wh->frame_control) ||
1929 ieee80211_is_ctl(wh->frame_control)) {
1931 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1932 } else if (ieee80211_is_data(wh->frame_control)) {
1934 if (is_multicast_ether_addr(wh->addr1))
1935 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1937 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1938 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1939 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1941 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1944 /* Queue ADDBA request in the respective data queue. While setting up
1945 * the ampdu stream, mac80211 queues further packets for that
1946 * particular ra/tid pair. However, packets piled up in the hardware
1947 * for that ra/tid pair will still go out. ADDBA request and the
1948 * related data packets going out from different queues asynchronously
1949 * will cause a shift in the receiver window which might result in
1950 * ampdu packets getting dropped at the receiver after the stream has
1953 if (unlikely(ieee80211_is_action(wh->frame_control) &&
1954 mgmt->u.action.category == WLAN_CATEGORY_BACK &&
1955 mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
1957 u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1958 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1959 index = mwl8k_tid_queue_mapping(tid);
1964 if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame &&
1965 ieee80211_is_data_qos(wh->frame_control)) {
1967 mwl8k_tx_count_packet(sta, tid);
1968 spin_lock(&priv->stream_lock);
1969 stream = mwl8k_lookup_stream(hw, sta->addr, tid);
1970 if (stream != NULL) {
1971 if (stream->state == AMPDU_STREAM_ACTIVE) {
1972 WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK));
1973 txpriority = (BA_QUEUE + stream->idx) %
1975 if (stream->idx <= 1)
1976 index = stream->idx +
1977 MWL8K_TX_WMM_QUEUES;
1979 } else if (stream->state == AMPDU_STREAM_NEW) {
1980 /* We get here if the driver sends us packets
1981 * after we've initiated a stream, but before
1982 * our ampdu_action routine has been called
1983 * with IEEE80211_AMPDU_TX_START to get the SSN
1984 * for the ADDBA request. So this packet can
1985 * go out with no risk of sequence number
1986 * mismatch. No special handling is required.
1989 /* Drop packets that would go out after the
1990 * ADDBA request was sent but before the ADDBA
1991 * response is received. If we don't do this,
1992 * the recipient would probably receive it
1993 * after the ADDBA request with SSN 0. This
1994 * will cause the recipient's BA receive window
1995 * to shift, which would cause the subsequent
1996 * packets in the BA stream to be discarded.
1997 * mac80211 queues our packets for us in this
1998 * case, so this is really just a safety check.
2000 wiphy_warn(hw->wiphy,
2001 "Cannot send packet while ADDBA "
2002 "dialog is underway.\n");
2003 spin_unlock(&priv->stream_lock);
2008 /* Defer calling mwl8k_start_stream so that the current
2009 * skb can go out before the ADDBA request. This
2010 * prevents sequence number mismatch at the recepient
2011 * as described above.
2013 if (mwl8k_ampdu_allowed(sta, tid)) {
2014 stream = mwl8k_add_stream(hw, sta, tid);
2016 start_ba_session = true;
2019 spin_unlock(&priv->stream_lock);
2021 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
2022 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
2025 dma = pci_map_single(priv->pdev, skb->data,
2026 skb->len, PCI_DMA_TODEVICE);
2028 if (pci_dma_mapping_error(priv->pdev, dma)) {
2029 wiphy_debug(hw->wiphy,
2030 "failed to dma map skb, dropping TX frame.\n");
2031 if (start_ba_session) {
2032 spin_lock(&priv->stream_lock);
2033 mwl8k_remove_stream(hw, stream);
2034 spin_unlock(&priv->stream_lock);
2040 spin_lock_bh(&priv->tx_lock);
2042 txq = priv->txq + index;
2044 /* Mgmt frames that go out frequently are probe
2045 * responses. Other mgmt frames got out relatively
2046 * infrequently. Hence reserve 2 buffers so that
2047 * other mgmt frames do not get dropped due to an
2048 * already queued probe response in one of the
2052 if (txq->len >= MWL8K_TX_DESCS - 2) {
2053 if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
2054 if (start_ba_session) {
2055 spin_lock(&priv->stream_lock);
2056 mwl8k_remove_stream(hw, stream);
2057 spin_unlock(&priv->stream_lock);
2059 spin_unlock_bh(&priv->tx_lock);
2060 pci_unmap_single(priv->pdev, dma, skb->len,
2067 BUG_ON(txq->skb[txq->tail] != NULL);
2068 txq->skb[txq->tail] = skb;
2070 tx = txq->txd + txq->tail;
2071 tx->data_rate = txdatarate;
2072 tx->tx_priority = txpriority;
2073 tx->qos_control = cpu_to_le16(qos);
2074 tx->pkt_phys_addr = cpu_to_le32(dma);
2075 tx->pkt_len = cpu_to_le16(skb->len);
2077 if (!priv->ap_fw && sta != NULL)
2078 tx->peer_id = MWL8K_STA(sta)->peer_id;
2082 if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame)
2083 tx->timestamp = cpu_to_le32(ioread32(priv->regs +
2084 MWL8K_HW_TIMER_REGISTER));
2089 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
2092 priv->pending_tx_pkts++;
2095 if (txq->tail == MWL8K_TX_DESCS)
2098 mwl8k_tx_start(priv);
2100 spin_unlock_bh(&priv->tx_lock);
2102 /* Initiate the ampdu session here */
2103 if (start_ba_session) {
2104 spin_lock(&priv->stream_lock);
2105 if (mwl8k_start_stream(hw, stream))
2106 mwl8k_remove_stream(hw, stream);
2107 spin_unlock(&priv->stream_lock);
2115 * We have the following requirements for issuing firmware commands:
2116 * - Some commands require that the packet transmit path is idle when
2117 * the command is issued. (For simplicity, we'll just quiesce the
2118 * transmit path for every command.)
2119 * - There are certain sequences of commands that need to be issued to
2120 * the hardware sequentially, with no other intervening commands.
2122 * This leads to an implementation of a "firmware lock" as a mutex that
2123 * can be taken recursively, and which is taken by both the low-level
2124 * command submission function (mwl8k_post_cmd) as well as any users of
2125 * that function that require issuing of an atomic sequence of commands,
2126 * and quiesces the transmit path whenever it's taken.
2128 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
2130 struct mwl8k_priv *priv = hw->priv;
2132 if (priv->fw_mutex_owner != current) {
2135 mutex_lock(&priv->fw_mutex);
2136 ieee80211_stop_queues(hw);
2138 rc = mwl8k_tx_wait_empty(hw);
2140 if (!priv->hw_restart_in_progress)
2141 ieee80211_wake_queues(hw);
2143 mutex_unlock(&priv->fw_mutex);
2148 priv->fw_mutex_owner = current;
2151 priv->fw_mutex_depth++;
2156 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
2158 struct mwl8k_priv *priv = hw->priv;
2160 if (!--priv->fw_mutex_depth) {
2161 if (!priv->hw_restart_in_progress)
2162 ieee80211_wake_queues(hw);
2164 priv->fw_mutex_owner = NULL;
2165 mutex_unlock(&priv->fw_mutex);
2169 static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable,
2173 * Command processing.
2176 /* Timeout firmware commands after 10s */
2177 #define MWL8K_CMD_TIMEOUT_MS 10000
2179 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
2181 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2182 struct mwl8k_priv *priv = hw->priv;
2183 void __iomem *regs = priv->regs;
2184 dma_addr_t dma_addr;
2185 unsigned int dma_size;
2187 unsigned long timeout = 0;
2191 wiphy_dbg(hw->wiphy, "Posting %s [%d]\n",
2192 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), cmd->macid);
2194 /* Before posting firmware commands that could change the hardware
2195 * characteristics, make sure that all BSSes are stopped temporary.
2196 * Enable these stopped BSSes after completion of the commands
2199 rc = mwl8k_fw_lock(hw);
2203 if (priv->ap_fw && priv->running_bsses) {
2204 switch (le16_to_cpu(cmd->code)) {
2205 case MWL8K_CMD_SET_RF_CHANNEL:
2206 case MWL8K_CMD_RADIO_CONTROL:
2207 case MWL8K_CMD_RF_TX_POWER:
2208 case MWL8K_CMD_TX_POWER:
2209 case MWL8K_CMD_RF_ANTENNA:
2210 case MWL8K_CMD_RTS_THRESHOLD:
2211 case MWL8K_CMD_MIMO_CONFIG:
2212 bitmap = priv->running_bsses;
2213 mwl8k_enable_bsses(hw, false, bitmap);
2218 cmd->result = (__force __le16) 0xffff;
2219 dma_size = le16_to_cpu(cmd->length);
2220 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
2221 PCI_DMA_BIDIRECTIONAL);
2222 if (pci_dma_mapping_error(priv->pdev, dma_addr))
2225 priv->hostcmd_wait = &cmd_wait;
2226 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
2227 iowrite32(MWL8K_H2A_INT_DOORBELL,
2228 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2229 iowrite32(MWL8K_H2A_INT_DUMMY,
2230 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2232 timeout = wait_for_completion_timeout(&cmd_wait,
2233 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
2235 priv->hostcmd_wait = NULL;
2238 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2239 PCI_DMA_BIDIRECTIONAL);
2242 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
2243 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2244 MWL8K_CMD_TIMEOUT_MS);
2249 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
2251 rc = cmd->result ? -EINVAL : 0;
2253 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
2254 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2255 le16_to_cpu(cmd->result));
2257 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
2258 mwl8k_cmd_name(cmd->code,
2264 mwl8k_enable_bsses(hw, true, bitmap);
2266 mwl8k_fw_unlock(hw);
2271 static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
2272 struct ieee80211_vif *vif,
2273 struct mwl8k_cmd_pkt *cmd)
2276 cmd->macid = MWL8K_VIF(vif)->macid;
2277 return mwl8k_post_cmd(hw, cmd);
2281 * Setup code shared between STA and AP firmware images.
2283 static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
2285 struct mwl8k_priv *priv = hw->priv;
2287 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
2288 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
2290 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
2291 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
2293 priv->band_24.band = IEEE80211_BAND_2GHZ;
2294 priv->band_24.channels = priv->channels_24;
2295 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
2296 priv->band_24.bitrates = priv->rates_24;
2297 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
2299 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
2302 static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
2304 struct mwl8k_priv *priv = hw->priv;
2306 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
2307 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
2309 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
2310 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
2312 priv->band_50.band = IEEE80211_BAND_5GHZ;
2313 priv->band_50.channels = priv->channels_50;
2314 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
2315 priv->band_50.bitrates = priv->rates_50;
2316 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
2318 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
2322 * CMD_GET_HW_SPEC (STA version).
2324 struct mwl8k_cmd_get_hw_spec_sta {
2325 struct mwl8k_cmd_pkt header;
2327 __u8 host_interface;
2329 __u8 perm_addr[ETH_ALEN];
2334 __u8 mcs_bitmap[16];
2335 __le32 rx_queue_ptr;
2336 __le32 num_tx_queues;
2337 __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
2339 __le32 num_tx_desc_per_queue;
2343 #define MWL8K_CAP_MAX_AMSDU 0x20000000
2344 #define MWL8K_CAP_GREENFIELD 0x08000000
2345 #define MWL8K_CAP_AMPDU 0x04000000
2346 #define MWL8K_CAP_RX_STBC 0x01000000
2347 #define MWL8K_CAP_TX_STBC 0x00800000
2348 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2349 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2350 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2351 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2352 #define MWL8K_CAP_DELAY_BA 0x00003000
2353 #define MWL8K_CAP_MIMO 0x00000200
2354 #define MWL8K_CAP_40MHZ 0x00000100
2355 #define MWL8K_CAP_BAND_MASK 0x00000007
2356 #define MWL8K_CAP_5GHZ 0x00000004
2357 #define MWL8K_CAP_2GHZ4 0x00000001
2360 mwl8k_set_ht_caps(struct ieee80211_hw *hw,
2361 struct ieee80211_supported_band *band, u32 cap)
2366 band->ht_cap.ht_supported = 1;
2368 if (cap & MWL8K_CAP_MAX_AMSDU)
2369 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
2370 if (cap & MWL8K_CAP_GREENFIELD)
2371 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
2372 if (cap & MWL8K_CAP_AMPDU) {
2373 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
2374 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2375 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2377 if (cap & MWL8K_CAP_RX_STBC)
2378 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
2379 if (cap & MWL8K_CAP_TX_STBC)
2380 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
2381 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
2382 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
2383 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
2384 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
2385 if (cap & MWL8K_CAP_DELAY_BA)
2386 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
2387 if (cap & MWL8K_CAP_40MHZ)
2388 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2390 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
2391 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
2393 band->ht_cap.mcs.rx_mask[0] = 0xff;
2394 if (rx_streams >= 2)
2395 band->ht_cap.mcs.rx_mask[1] = 0xff;
2396 if (rx_streams >= 3)
2397 band->ht_cap.mcs.rx_mask[2] = 0xff;
2398 band->ht_cap.mcs.rx_mask[4] = 0x01;
2399 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2401 if (rx_streams != tx_streams) {
2402 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
2403 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
2404 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2409 mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
2411 struct mwl8k_priv *priv = hw->priv;
2413 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
2414 mwl8k_setup_2ghz_band(hw);
2415 if (caps & MWL8K_CAP_MIMO)
2416 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
2419 if (caps & MWL8K_CAP_5GHZ) {
2420 mwl8k_setup_5ghz_band(hw);
2421 if (caps & MWL8K_CAP_MIMO)
2422 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
2426 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
2428 struct mwl8k_priv *priv = hw->priv;
2429 struct mwl8k_cmd_get_hw_spec_sta *cmd;
2433 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2437 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2438 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2440 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2441 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2442 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2443 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2444 for (i = 0; i < mwl8k_tx_queues(priv); i++)
2445 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
2446 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2447 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2449 rc = mwl8k_post_cmd(hw, &cmd->header);
2452 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2453 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2454 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2455 priv->hw_rev = cmd->hw_rev;
2456 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2457 priv->ap_macids_supported = 0x00000000;
2458 priv->sta_macids_supported = 0x00000001;
2466 * CMD_GET_HW_SPEC (AP version).
2468 struct mwl8k_cmd_get_hw_spec_ap {
2469 struct mwl8k_cmd_pkt header;
2471 __u8 host_interface;
2474 __u8 perm_addr[ETH_ALEN];
2485 __le32 fw_api_version;
2487 __le32 num_of_ampdu_queues;
2488 __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
2491 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2493 struct mwl8k_priv *priv = hw->priv;
2494 struct mwl8k_cmd_get_hw_spec_ap *cmd;
2498 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2502 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2503 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2505 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2506 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2508 rc = mwl8k_post_cmd(hw, &cmd->header);
2513 api_version = le32_to_cpu(cmd->fw_api_version);
2514 if (priv->device_info->fw_api_ap != api_version) {
2515 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2516 " Expected %d got %d.\n", MWL8K_NAME,
2517 priv->device_info->part_name,
2518 priv->device_info->fw_api_ap,
2523 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2524 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2525 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2526 priv->hw_rev = cmd->hw_rev;
2527 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2528 priv->ap_macids_supported = 0x000000ff;
2529 priv->sta_macids_supported = 0x00000100;
2530 priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
2531 if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
2532 wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
2533 " but we only support %d.\n",
2534 priv->num_ampdu_queues,
2535 MWL8K_MAX_AMPDU_QUEUES);
2536 priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
2538 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
2539 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2541 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
2542 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2544 priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
2545 priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
2546 priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
2547 priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
2549 for (i = 0; i < priv->num_ampdu_queues; i++)
2550 priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
2551 le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
2562 struct mwl8k_cmd_set_hw_spec {
2563 struct mwl8k_cmd_pkt header;
2565 __u8 host_interface;
2567 __u8 perm_addr[ETH_ALEN];
2572 __le32 rx_queue_ptr;
2573 __le32 num_tx_queues;
2574 __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
2576 __le32 num_tx_desc_per_queue;
2580 /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2581 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2582 * the packets that are queued for more than 500ms, will be dropped in the
2583 * hardware. This helps minimizing the issues caused due to head-of-line
2584 * blocking where a slow client can hog the bandwidth and affect traffic to a
2587 #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
2588 #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
2589 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2590 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2591 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
2593 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2595 struct mwl8k_priv *priv = hw->priv;
2596 struct mwl8k_cmd_set_hw_spec *cmd;
2600 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2604 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2605 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2607 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2608 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2609 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2612 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2613 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2614 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2615 * priority is interpreted the right way in firmware.
2617 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
2618 int j = mwl8k_tx_queues(priv) - 1 - i;
2619 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
2622 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2623 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
2624 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
2625 MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
2626 MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
2627 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2628 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2630 rc = mwl8k_post_cmd(hw, &cmd->header);
2637 * CMD_MAC_MULTICAST_ADR.
2639 struct mwl8k_cmd_mac_multicast_adr {
2640 struct mwl8k_cmd_pkt header;
2643 __u8 addr[0][ETH_ALEN];
2646 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
2647 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
2648 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2649 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
2651 static struct mwl8k_cmd_pkt *
2652 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
2653 struct netdev_hw_addr_list *mc_list)
2655 struct mwl8k_priv *priv = hw->priv;
2656 struct mwl8k_cmd_mac_multicast_adr *cmd;
2661 mc_count = netdev_hw_addr_list_count(mc_list);
2663 if (allmulti || mc_count > priv->num_mcaddrs) {
2668 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2670 cmd = kzalloc(size, GFP_ATOMIC);
2674 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2675 cmd->header.length = cpu_to_le16(size);
2676 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2677 MWL8K_ENABLE_RX_BROADCAST);
2680 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2681 } else if (mc_count) {
2682 struct netdev_hw_addr *ha;
2685 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2686 cmd->numaddr = cpu_to_le16(mc_count);
2687 netdev_hw_addr_list_for_each(ha, mc_list) {
2688 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
2692 return &cmd->header;
2698 struct mwl8k_cmd_get_stat {
2699 struct mwl8k_cmd_pkt header;
2703 #define MWL8K_STAT_ACK_FAILURE 9
2704 #define MWL8K_STAT_RTS_FAILURE 12
2705 #define MWL8K_STAT_FCS_ERROR 24
2706 #define MWL8K_STAT_RTS_SUCCESS 11
2708 static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2709 struct ieee80211_low_level_stats *stats)
2711 struct mwl8k_cmd_get_stat *cmd;
2714 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2718 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2719 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2721 rc = mwl8k_post_cmd(hw, &cmd->header);
2723 stats->dot11ACKFailureCount =
2724 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2725 stats->dot11RTSFailureCount =
2726 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2727 stats->dot11FCSErrorCount =
2728 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2729 stats->dot11RTSSuccessCount =
2730 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2738 * CMD_RADIO_CONTROL.
2740 struct mwl8k_cmd_radio_control {
2741 struct mwl8k_cmd_pkt header;
2748 mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
2750 struct mwl8k_priv *priv = hw->priv;
2751 struct mwl8k_cmd_radio_control *cmd;
2754 if (enable == priv->radio_on && !force)
2757 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2761 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2762 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2763 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2764 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
2765 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2767 rc = mwl8k_post_cmd(hw, &cmd->header);
2771 priv->radio_on = enable;
2776 static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
2778 return mwl8k_cmd_radio_control(hw, 0, 0);
2781 static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
2783 return mwl8k_cmd_radio_control(hw, 1, 0);
2787 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2789 struct mwl8k_priv *priv = hw->priv;
2791 priv->radio_short_preamble = short_preamble;
2793 return mwl8k_cmd_radio_control(hw, 1, 1);
2799 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2801 struct mwl8k_cmd_rf_tx_power {
2802 struct mwl8k_cmd_pkt header;
2804 __le16 support_level;
2805 __le16 current_level;
2807 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
2810 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
2812 struct mwl8k_cmd_rf_tx_power *cmd;
2815 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2819 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2820 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2821 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2822 cmd->support_level = cpu_to_le16(dBm);
2824 rc = mwl8k_post_cmd(hw, &cmd->header);
2833 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2835 struct mwl8k_cmd_tx_power {
2836 struct mwl8k_cmd_pkt header;
2842 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2845 static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2846 struct ieee80211_conf *conf,
2849 struct ieee80211_channel *channel = conf->channel;
2850 struct mwl8k_cmd_tx_power *cmd;
2854 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2858 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2859 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2860 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2862 if (channel->band == IEEE80211_BAND_2GHZ)
2863 cmd->band = cpu_to_le16(0x1);
2864 else if (channel->band == IEEE80211_BAND_5GHZ)
2865 cmd->band = cpu_to_le16(0x4);
2867 cmd->channel = cpu_to_le16(channel->hw_value);
2869 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2870 conf->channel_type == NL80211_CHAN_HT20) {
2871 cmd->bw = cpu_to_le16(0x2);
2873 cmd->bw = cpu_to_le16(0x4);
2874 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2875 cmd->sub_ch = cpu_to_le16(0x3);
2876 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2877 cmd->sub_ch = cpu_to_le16(0x1);
2880 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2881 cmd->power_level_list[i] = cpu_to_le16(pwr);
2883 rc = mwl8k_post_cmd(hw, &cmd->header);
2892 struct mwl8k_cmd_rf_antenna {
2893 struct mwl8k_cmd_pkt header;
2898 #define MWL8K_RF_ANTENNA_RX 1
2899 #define MWL8K_RF_ANTENNA_TX 2
2902 mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2904 struct mwl8k_cmd_rf_antenna *cmd;
2907 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2911 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2912 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2913 cmd->antenna = cpu_to_le16(antenna);
2914 cmd->mode = cpu_to_le16(mask);
2916 rc = mwl8k_post_cmd(hw, &cmd->header);
2925 struct mwl8k_cmd_set_beacon {
2926 struct mwl8k_cmd_pkt header;
2931 static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2932 struct ieee80211_vif *vif, u8 *beacon, int len)
2934 struct mwl8k_cmd_set_beacon *cmd;
2937 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2941 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2942 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2943 cmd->beacon_len = cpu_to_le16(len);
2944 memcpy(cmd->beacon, beacon, len);
2946 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2955 struct mwl8k_cmd_set_pre_scan {
2956 struct mwl8k_cmd_pkt header;
2959 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2961 struct mwl8k_cmd_set_pre_scan *cmd;
2964 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2968 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2969 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2971 rc = mwl8k_post_cmd(hw, &cmd->header);
2978 * CMD_SET_POST_SCAN.
2980 struct mwl8k_cmd_set_post_scan {
2981 struct mwl8k_cmd_pkt header;
2983 __u8 bssid[ETH_ALEN];
2987 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2989 struct mwl8k_cmd_set_post_scan *cmd;
2992 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2996 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2997 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2999 memcpy(cmd->bssid, mac, ETH_ALEN);
3001 rc = mwl8k_post_cmd(hw, &cmd->header);
3008 * CMD_SET_RF_CHANNEL.
3010 struct mwl8k_cmd_set_rf_channel {
3011 struct mwl8k_cmd_pkt header;
3013 __u8 current_channel;
3014 __le32 channel_flags;
3017 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
3018 struct ieee80211_conf *conf)
3020 struct ieee80211_channel *channel = conf->channel;
3021 struct mwl8k_cmd_set_rf_channel *cmd;
3024 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3028 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
3029 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3030 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3031 cmd->current_channel = channel->hw_value;
3033 if (channel->band == IEEE80211_BAND_2GHZ)
3034 cmd->channel_flags |= cpu_to_le32(0x00000001);
3035 else if (channel->band == IEEE80211_BAND_5GHZ)
3036 cmd->channel_flags |= cpu_to_le32(0x00000004);
3038 if (conf->channel_type == NL80211_CHAN_NO_HT ||
3039 conf->channel_type == NL80211_CHAN_HT20)
3040 cmd->channel_flags |= cpu_to_le32(0x00000080);
3041 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
3042 cmd->channel_flags |= cpu_to_le32(0x000001900);
3043 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
3044 cmd->channel_flags |= cpu_to_le32(0x000000900);
3046 rc = mwl8k_post_cmd(hw, &cmd->header);
3055 #define MWL8K_FRAME_PROT_DISABLED 0x00
3056 #define MWL8K_FRAME_PROT_11G 0x07
3057 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
3058 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
3060 struct mwl8k_cmd_update_set_aid {
3061 struct mwl8k_cmd_pkt header;
3064 /* AP's MAC address (BSSID) */
3065 __u8 bssid[ETH_ALEN];
3066 __le16 protection_mode;
3067 __u8 supp_rates[14];
3070 static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
3076 * Clear nonstandard rates 4 and 13.
3080 for (i = 0, j = 0; i < 14; i++) {
3081 if (mask & (1 << i))
3082 rates[j++] = mwl8k_rates_24[i].hw_value;
3087 mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
3088 struct ieee80211_vif *vif, u32 legacy_rate_mask)
3090 struct mwl8k_cmd_update_set_aid *cmd;
3094 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3098 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
3099 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3100 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
3101 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
3103 if (vif->bss_conf.use_cts_prot) {
3104 prot_mode = MWL8K_FRAME_PROT_11G;
3106 switch (vif->bss_conf.ht_operation_mode &
3107 IEEE80211_HT_OP_MODE_PROTECTION) {
3108 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
3109 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
3111 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
3112 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
3115 prot_mode = MWL8K_FRAME_PROT_DISABLED;
3119 cmd->protection_mode = cpu_to_le16(prot_mode);
3121 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
3123 rc = mwl8k_post_cmd(hw, &cmd->header);
3132 struct mwl8k_cmd_set_rate {
3133 struct mwl8k_cmd_pkt header;
3134 __u8 legacy_rates[14];
3136 /* Bitmap for supported MCS codes. */
3142 mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3143 u32 legacy_rate_mask, u8 *mcs_rates)
3145 struct mwl8k_cmd_set_rate *cmd;
3148 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3152 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
3153 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3154 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
3155 memcpy(cmd->mcs_set, mcs_rates, 16);
3157 rc = mwl8k_post_cmd(hw, &cmd->header);
3164 * CMD_FINALIZE_JOIN.
3166 #define MWL8K_FJ_BEACON_MAXLEN 128
3168 struct mwl8k_cmd_finalize_join {
3169 struct mwl8k_cmd_pkt header;
3170 __le32 sleep_interval; /* Number of beacon periods to sleep */
3171 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
3174 static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
3175 int framelen, int dtim)
3177 struct mwl8k_cmd_finalize_join *cmd;
3178 struct ieee80211_mgmt *payload = frame;
3182 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3186 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
3187 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3188 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
3190 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
3191 if (payload_len < 0)
3193 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
3194 payload_len = MWL8K_FJ_BEACON_MAXLEN;
3196 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
3198 rc = mwl8k_post_cmd(hw, &cmd->header);
3205 * CMD_SET_RTS_THRESHOLD.
3207 struct mwl8k_cmd_set_rts_threshold {
3208 struct mwl8k_cmd_pkt header;
3214 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
3216 struct mwl8k_cmd_set_rts_threshold *cmd;
3219 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3223 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
3224 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3225 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3226 cmd->threshold = cpu_to_le16(rts_thresh);
3228 rc = mwl8k_post_cmd(hw, &cmd->header);
3237 struct mwl8k_cmd_set_slot {
3238 struct mwl8k_cmd_pkt header;
3243 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
3245 struct mwl8k_cmd_set_slot *cmd;
3248 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3252 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
3253 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3254 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3255 cmd->short_slot = short_slot_time;
3257 rc = mwl8k_post_cmd(hw, &cmd->header);
3264 * CMD_SET_EDCA_PARAMS.
3266 struct mwl8k_cmd_set_edca_params {
3267 struct mwl8k_cmd_pkt header;
3269 /* See MWL8K_SET_EDCA_XXX below */
3272 /* TX opportunity in units of 32 us */
3277 /* Log exponent of max contention period: 0...15 */
3280 /* Log exponent of min contention period: 0...15 */
3283 /* Adaptive interframe spacing in units of 32us */
3286 /* TX queue to configure */
3290 /* Log exponent of max contention period: 0...15 */
3293 /* Log exponent of min contention period: 0...15 */
3296 /* Adaptive interframe spacing in units of 32us */
3299 /* TX queue to configure */
3305 #define MWL8K_SET_EDCA_CW 0x01
3306 #define MWL8K_SET_EDCA_TXOP 0x02
3307 #define MWL8K_SET_EDCA_AIFS 0x04
3309 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3310 MWL8K_SET_EDCA_TXOP | \
3311 MWL8K_SET_EDCA_AIFS)
3314 mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
3315 __u16 cw_min, __u16 cw_max,
3316 __u8 aifs, __u16 txop)
3318 struct mwl8k_priv *priv = hw->priv;
3319 struct mwl8k_cmd_set_edca_params *cmd;
3322 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3326 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
3327 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3328 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
3329 cmd->txop = cpu_to_le16(txop);
3331 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
3332 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
3333 cmd->ap.aifs = aifs;
3336 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
3337 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
3338 cmd->sta.aifs = aifs;
3339 cmd->sta.txq = qnum;
3342 rc = mwl8k_post_cmd(hw, &cmd->header);
3351 struct mwl8k_cmd_set_wmm_mode {
3352 struct mwl8k_cmd_pkt header;
3356 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
3358 struct mwl8k_priv *priv = hw->priv;
3359 struct mwl8k_cmd_set_wmm_mode *cmd;
3362 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3366 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
3367 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3368 cmd->action = cpu_to_le16(!!enable);
3370 rc = mwl8k_post_cmd(hw, &cmd->header);
3374 priv->wmm_enabled = enable;
3382 struct mwl8k_cmd_mimo_config {
3383 struct mwl8k_cmd_pkt header;
3385 __u8 rx_antenna_map;
3386 __u8 tx_antenna_map;
3389 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
3391 struct mwl8k_cmd_mimo_config *cmd;
3394 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3398 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
3399 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3400 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
3401 cmd->rx_antenna_map = rx;
3402 cmd->tx_antenna_map = tx;
3404 rc = mwl8k_post_cmd(hw, &cmd->header);
3411 * CMD_USE_FIXED_RATE (STA version).
3413 struct mwl8k_cmd_use_fixed_rate_sta {
3414 struct mwl8k_cmd_pkt header;
3416 __le32 allow_rate_drop;
3420 __le32 enable_retry;
3429 #define MWL8K_USE_AUTO_RATE 0x0002
3430 #define MWL8K_UCAST_RATE 0
3432 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
3434 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
3437 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3441 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3442 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3443 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3444 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
3446 rc = mwl8k_post_cmd(hw, &cmd->header);
3453 * CMD_USE_FIXED_RATE (AP version).
3455 struct mwl8k_cmd_use_fixed_rate_ap {
3456 struct mwl8k_cmd_pkt header;
3458 __le32 allow_rate_drop;
3460 struct mwl8k_rate_entry_ap {
3462 __le32 enable_retry;
3467 u8 multicast_rate_type;
3472 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
3474 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
3477 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3481 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3482 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3483 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3484 cmd->multicast_rate = mcast;
3485 cmd->management_rate = mgmt;
3487 rc = mwl8k_post_cmd(hw, &cmd->header);
3494 * CMD_ENABLE_SNIFFER.
3496 struct mwl8k_cmd_enable_sniffer {
3497 struct mwl8k_cmd_pkt header;
3501 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3503 struct mwl8k_cmd_enable_sniffer *cmd;
3506 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3510 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3511 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3512 cmd->action = cpu_to_le32(!!enable);
3514 rc = mwl8k_post_cmd(hw, &cmd->header);
3520 struct mwl8k_cmd_update_mac_addr {
3521 struct mwl8k_cmd_pkt header;
3525 __u8 mac_addr[ETH_ALEN];
3527 __u8 mac_addr[ETH_ALEN];
3531 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3532 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3533 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
3534 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
3536 static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
3537 struct ieee80211_vif *vif, u8 *mac, bool set)
3539 struct mwl8k_priv *priv = hw->priv;
3540 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3541 struct mwl8k_cmd_update_mac_addr *cmd;
3545 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3546 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3547 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
3549 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3551 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
3553 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3554 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3555 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3556 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3558 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3561 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3566 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3568 cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
3570 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3572 cmd->mbss.mac_type = cpu_to_le16(mac_type);
3573 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3575 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3578 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3585 * MWL8K_CMD_SET_MAC_ADDR.
3587 static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3588 struct ieee80211_vif *vif, u8 *mac)
3590 return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
3594 * MWL8K_CMD_DEL_MAC_ADDR.
3596 static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
3597 struct ieee80211_vif *vif, u8 *mac)
3599 return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
3603 * CMD_SET_RATEADAPT_MODE.
3605 struct mwl8k_cmd_set_rate_adapt_mode {
3606 struct mwl8k_cmd_pkt header;
3611 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3613 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
3616 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3620 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
3621 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3622 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3623 cmd->mode = cpu_to_le16(mode);
3625 rc = mwl8k_post_cmd(hw, &cmd->header);
3632 * CMD_GET_WATCHDOG_BITMAP.
3634 struct mwl8k_cmd_get_watchdog_bitmap {
3635 struct mwl8k_cmd_pkt header;
3639 static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
3641 struct mwl8k_cmd_get_watchdog_bitmap *cmd;
3644 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3648 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
3649 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3651 rc = mwl8k_post_cmd(hw, &cmd->header);
3653 *bitmap = cmd->bitmap;
3660 #define MWL8K_WMM_QUEUE_NUMBER 3
3662 static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3665 static void mwl8k_watchdog_ba_events(struct work_struct *work)
3668 u8 bitmap = 0, stream_index;
3669 struct mwl8k_ampdu_stream *streams;
3670 struct mwl8k_priv *priv =
3671 container_of(work, struct mwl8k_priv, watchdog_ba_handle);
3672 struct ieee80211_hw *hw = priv->hw;
3678 rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
3682 spin_lock(&priv->stream_lock);
3684 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
3685 for (i = 0; i < TOTAL_HW_TX_QUEUES; i++) {
3686 if (bitmap & (1 << i)) {
3687 stream_index = (i + MWL8K_WMM_QUEUE_NUMBER) %
3689 streams = &priv->ampdu[stream_index];
3690 if (streams->state == AMPDU_STREAM_ACTIVE) {
3691 ieee80211_stop_tx_ba_session(streams->sta,
3693 spin_unlock(&priv->stream_lock);
3694 mwl8k_destroy_ba(hw, stream_index);
3695 spin_lock(&priv->stream_lock);
3700 spin_unlock(&priv->stream_lock);
3702 atomic_dec(&priv->watchdog_event_pending);
3703 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3704 iowrite32((status | MWL8K_A2H_INT_BA_WATCHDOG),
3705 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3706 mwl8k_fw_unlock(hw);
3714 struct mwl8k_cmd_bss_start {
3715 struct mwl8k_cmd_pkt header;
3719 static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3720 struct ieee80211_vif *vif, int enable)
3722 struct mwl8k_cmd_bss_start *cmd;
3723 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3724 struct mwl8k_priv *priv = hw->priv;
3727 if (enable && (priv->running_bsses & (1 << mwl8k_vif->macid)))
3730 if (!enable && !(priv->running_bsses & (1 << mwl8k_vif->macid)))
3733 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3737 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3738 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3739 cmd->enable = cpu_to_le32(enable);
3741 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3746 priv->running_bsses |= (1 << mwl8k_vif->macid);
3748 priv->running_bsses &= ~(1 << mwl8k_vif->macid);
3753 static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable, u32 bitmap)
3755 struct mwl8k_priv *priv = hw->priv;
3756 struct mwl8k_vif *mwl8k_vif, *tmp_vif;
3757 struct ieee80211_vif *vif;
3759 list_for_each_entry_safe(mwl8k_vif, tmp_vif, &priv->vif_list, list) {
3760 vif = mwl8k_vif->vif;
3762 if (!(bitmap & (1 << mwl8k_vif->macid)))
3765 if (vif->type == NL80211_IFTYPE_AP)
3766 mwl8k_cmd_bss_start(hw, vif, enable);
3774 * UPSTREAM is tx direction
3776 #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3777 #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3779 enum ba_stream_action_type {
3788 struct mwl8k_create_ba_stream {
3793 u8 peer_mac_addr[6];
3799 u8 reset_seq_no_flag;
3801 u8 sta_src_mac_addr[6];
3804 struct mwl8k_destroy_ba_stream {
3809 struct mwl8k_cmd_bastream {
3810 struct mwl8k_cmd_pkt header;
3813 struct mwl8k_create_ba_stream create_params;
3814 struct mwl8k_destroy_ba_stream destroy_params;
3819 mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3820 struct ieee80211_vif *vif)
3822 struct mwl8k_cmd_bastream *cmd;
3825 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3829 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3830 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3832 cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
3834 cmd->create_params.queue_id = stream->idx;
3835 memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
3837 cmd->create_params.tid = stream->tid;
3839 cmd->create_params.flags =
3840 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
3841 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
3843 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3851 mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3852 u8 buf_size, struct ieee80211_vif *vif)
3854 struct mwl8k_cmd_bastream *cmd;
3857 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3862 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3863 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3865 cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
3867 cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
3868 cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
3869 cmd->create_params.queue_id = stream->idx;
3871 memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
3872 cmd->create_params.tid = stream->tid;
3873 cmd->create_params.curr_seq_no = cpu_to_le16(0);
3874 cmd->create_params.reset_seq_no_flag = 1;
3876 cmd->create_params.param_info =
3877 (stream->sta->ht_cap.ampdu_factor &
3878 IEEE80211_HT_AMPDU_PARM_FACTOR) |
3879 ((stream->sta->ht_cap.ampdu_density << 2) &
3880 IEEE80211_HT_AMPDU_PARM_DENSITY);
3882 cmd->create_params.flags =
3883 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
3884 BASTREAM_FLAG_DIRECTION_UPSTREAM);
3886 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3888 wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
3889 stream->sta->addr, stream->tid);
3895 static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3898 struct mwl8k_cmd_bastream *cmd;
3900 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3904 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3905 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3906 cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
3908 cmd->destroy_params.ba_context = cpu_to_le32(idx);
3909 mwl8k_post_cmd(hw, &cmd->header);
3911 wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", idx);
3919 struct mwl8k_cmd_set_new_stn {
3920 struct mwl8k_cmd_pkt header;
3926 __le32 legacy_rates;
3929 __le16 ht_capabilities_info;
3930 __u8 mac_ht_param_info;
3932 __u8 control_channel;
3941 #define MWL8K_STA_ACTION_ADD 0
3942 #define MWL8K_STA_ACTION_REMOVE 2
3944 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3945 struct ieee80211_vif *vif,
3946 struct ieee80211_sta *sta)
3948 struct mwl8k_cmd_set_new_stn *cmd;
3952 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3956 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3957 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3958 cmd->aid = cpu_to_le16(sta->aid);
3959 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3960 cmd->stn_id = cpu_to_le16(sta->aid);
3961 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
3962 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3963 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3965 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3966 cmd->legacy_rates = cpu_to_le32(rates);
3967 if (sta->ht_cap.ht_supported) {
3968 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3969 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3970 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3971 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3972 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3973 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3974 ((sta->ht_cap.ampdu_density & 7) << 2);
3975 cmd->is_qos_sta = 1;
3978 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3984 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3985 struct ieee80211_vif *vif)
3987 struct mwl8k_cmd_set_new_stn *cmd;
3990 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3994 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3995 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3996 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3998 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4004 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
4005 struct ieee80211_vif *vif, u8 *addr)
4007 struct mwl8k_cmd_set_new_stn *cmd;
4008 struct mwl8k_priv *priv = hw->priv;
4012 spin_lock(&priv->stream_lock);
4013 /* Destroy any active ampdu streams for this sta */
4014 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
4015 struct mwl8k_ampdu_stream *s;
4016 s = &priv->ampdu[i];
4017 if (s->state != AMPDU_NO_STREAM) {
4018 if (memcmp(s->sta->addr, addr, ETH_ALEN) == 0) {
4019 if (s->state == AMPDU_STREAM_ACTIVE) {
4021 spin_unlock(&priv->stream_lock);
4022 mwl8k_destroy_ba(hw, idx);
4023 spin_lock(&priv->stream_lock);
4024 } else if (s->state == AMPDU_STREAM_NEW) {
4025 mwl8k_remove_stream(hw, s);
4031 spin_unlock(&priv->stream_lock);
4033 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4037 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
4038 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4039 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4040 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
4042 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4049 * CMD_UPDATE_ENCRYPTION.
4052 #define MAX_ENCR_KEY_LENGTH 16
4053 #define MIC_KEY_LENGTH 8
4055 struct mwl8k_cmd_update_encryption {
4056 struct mwl8k_cmd_pkt header;
4065 struct mwl8k_cmd_set_key {
4066 struct mwl8k_cmd_pkt header;
4075 __u8 key_material[MAX_ENCR_KEY_LENGTH];
4076 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
4077 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
4078 __le16 tkip_rsc_low;
4079 __le32 tkip_rsc_high;
4080 __le16 tkip_tsc_low;
4081 __le32 tkip_tsc_high;
4088 MWL8K_ENCR_REMOVE_KEY,
4089 MWL8K_ENCR_SET_GROUP_KEY,
4092 #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
4093 #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
4094 #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
4095 #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
4096 #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
4104 #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
4105 #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
4106 #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
4107 #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
4108 #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
4110 static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
4111 struct ieee80211_vif *vif,
4115 struct mwl8k_cmd_update_encryption *cmd;
4118 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4122 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4123 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4124 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
4125 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4126 cmd->encr_type = encr_type;
4128 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4134 static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
4136 struct ieee80211_key_conf *key)
4138 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4139 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4140 cmd->length = cpu_to_le16(sizeof(*cmd) -
4141 offsetof(struct mwl8k_cmd_set_key, length));
4142 cmd->key_id = cpu_to_le32(key->keyidx);
4143 cmd->key_len = cpu_to_le16(key->keylen);
4144 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4146 switch (key->cipher) {
4147 case WLAN_CIPHER_SUITE_WEP40:
4148 case WLAN_CIPHER_SUITE_WEP104:
4149 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
4150 if (key->keyidx == 0)
4151 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
4154 case WLAN_CIPHER_SUITE_TKIP:
4155 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
4156 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4157 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4158 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4159 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
4160 | MWL8K_KEY_FLAG_TSC_VALID);
4162 case WLAN_CIPHER_SUITE_CCMP:
4163 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
4164 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4165 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4166 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4175 static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
4176 struct ieee80211_vif *vif,
4178 struct ieee80211_key_conf *key)
4180 struct mwl8k_cmd_set_key *cmd;
4185 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4187 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4191 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4197 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4198 action = MWL8K_ENCR_SET_KEY;
4200 action = MWL8K_ENCR_SET_GROUP_KEY;
4202 switch (key->cipher) {
4203 case WLAN_CIPHER_SUITE_WEP40:
4204 case WLAN_CIPHER_SUITE_WEP104:
4205 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
4206 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
4207 sizeof(*key) + key->keylen);
4208 mwl8k_vif->wep_key_conf[idx].enabled = 1;
4211 keymlen = key->keylen;
4212 action = MWL8K_ENCR_SET_KEY;
4214 case WLAN_CIPHER_SUITE_TKIP:
4215 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
4217 case WLAN_CIPHER_SUITE_CCMP:
4218 keymlen = key->keylen;
4225 memcpy(cmd->key_material, key->key, keymlen);
4226 cmd->action = cpu_to_le32(action);
4228 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4235 static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
4236 struct ieee80211_vif *vif,
4238 struct ieee80211_key_conf *key)
4240 struct mwl8k_cmd_set_key *cmd;
4242 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4244 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4248 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4252 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4253 key->cipher == WLAN_CIPHER_SUITE_WEP104)
4254 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
4256 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
4258 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4265 static int mwl8k_set_key(struct ieee80211_hw *hw,
4266 enum set_key_cmd cmd_param,
4267 struct ieee80211_vif *vif,
4268 struct ieee80211_sta *sta,
4269 struct ieee80211_key_conf *key)
4274 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4275 struct mwl8k_priv *priv = hw->priv;
4277 if (vif->type == NL80211_IFTYPE_STATION && !priv->ap_fw)
4285 if (cmd_param == SET_KEY) {
4286 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
4290 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
4291 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
4292 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
4294 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
4296 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
4301 mwl8k_vif->is_hw_crypto_enabled = true;
4304 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
4316 struct ewc_ht_info {
4322 struct peer_capability_info {
4323 /* Peer type - AP vs. STA. */
4326 /* Basic 802.11 capabilities from assoc resp. */
4329 /* Set if peer supports 802.11n high throughput (HT). */
4332 /* Valid if HT is supported. */
4334 __u8 extended_ht_caps;
4335 struct ewc_ht_info ewc_info;
4337 /* Legacy rate table. Intersection of our rates and peer rates. */
4338 __u8 legacy_rates[12];
4340 /* HT rate table. Intersection of our rates and peer rates. */
4344 /* If set, interoperability mode, no proprietary extensions. */
4348 __le16 amsdu_enabled;
4351 struct mwl8k_cmd_update_stadb {
4352 struct mwl8k_cmd_pkt header;
4354 /* See STADB_ACTION_TYPE */
4357 /* Peer MAC address */
4358 __u8 peer_addr[ETH_ALEN];
4362 /* Peer info - valid during add/update. */
4363 struct peer_capability_info peer_info;
4366 #define MWL8K_STA_DB_MODIFY_ENTRY 1
4367 #define MWL8K_STA_DB_DEL_ENTRY 2
4369 /* Peer Entry flags - used to define the type of the peer node */
4370 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
4372 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
4373 struct ieee80211_vif *vif,
4374 struct ieee80211_sta *sta)
4376 struct mwl8k_cmd_update_stadb *cmd;
4377 struct peer_capability_info *p;
4381 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4385 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4386 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4387 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
4388 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
4390 p = &cmd->peer_info;
4391 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
4392 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
4393 p->ht_support = sta->ht_cap.ht_supported;
4394 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
4395 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
4396 ((sta->ht_cap.ampdu_density & 7) << 2);
4397 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4398 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
4400 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4401 legacy_rate_mask_to_array(p->legacy_rates, rates);
4402 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
4404 p->amsdu_enabled = 0;
4406 rc = mwl8k_post_cmd(hw, &cmd->header);
4414 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
4415 struct ieee80211_vif *vif, u8 *addr)
4417 struct mwl8k_cmd_update_stadb *cmd;
4420 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4424 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4425 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4426 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
4427 memcpy(cmd->peer_addr, addr, ETH_ALEN);
4429 rc = mwl8k_post_cmd(hw, &cmd->header);
4437 * Interrupt handling.
4439 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
4441 struct ieee80211_hw *hw = dev_id;
4442 struct mwl8k_priv *priv = hw->priv;
4445 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4449 if (status & MWL8K_A2H_INT_TX_DONE) {
4450 status &= ~MWL8K_A2H_INT_TX_DONE;
4451 tasklet_schedule(&priv->poll_tx_task);
4454 if (status & MWL8K_A2H_INT_RX_READY) {
4455 status &= ~MWL8K_A2H_INT_RX_READY;
4456 tasklet_schedule(&priv->poll_rx_task);
4459 if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
4460 iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG,
4461 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4463 atomic_inc(&priv->watchdog_event_pending);
4464 status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
4465 ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
4469 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4471 if (status & MWL8K_A2H_INT_OPC_DONE) {
4472 if (priv->hostcmd_wait != NULL)
4473 complete(priv->hostcmd_wait);
4476 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
4477 if (!mutex_is_locked(&priv->fw_mutex) &&
4478 priv->radio_on && priv->pending_tx_pkts)
4479 mwl8k_tx_start(priv);
4485 static void mwl8k_tx_poll(unsigned long data)
4487 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4488 struct mwl8k_priv *priv = hw->priv;
4494 spin_lock_bh(&priv->tx_lock);
4496 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4497 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
4499 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
4500 complete(priv->tx_wait);
4501 priv->tx_wait = NULL;
4504 spin_unlock_bh(&priv->tx_lock);
4507 writel(~MWL8K_A2H_INT_TX_DONE,
4508 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4510 tasklet_schedule(&priv->poll_tx_task);
4514 static void mwl8k_rx_poll(unsigned long data)
4516 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4517 struct mwl8k_priv *priv = hw->priv;
4521 limit -= rxq_process(hw, 0, limit);
4522 limit -= rxq_refill(hw, 0, limit);
4525 writel(~MWL8K_A2H_INT_RX_READY,
4526 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4528 tasklet_schedule(&priv->poll_rx_task);
4534 * Core driver operations.
4536 static void mwl8k_tx(struct ieee80211_hw *hw,
4537 struct ieee80211_tx_control *control,
4538 struct sk_buff *skb)
4540 struct mwl8k_priv *priv = hw->priv;
4541 int index = skb_get_queue_mapping(skb);
4543 if (!priv->radio_on) {
4544 wiphy_debug(hw->wiphy,
4545 "dropped TX frame since radio disabled\n");
4550 mwl8k_txq_xmit(hw, index, control->sta, skb);
4553 static int mwl8k_start(struct ieee80211_hw *hw)
4555 struct mwl8k_priv *priv = hw->priv;
4558 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
4559 IRQF_SHARED, MWL8K_NAME, hw);
4562 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
4565 priv->irq = priv->pdev->irq;
4567 /* Enable TX reclaim and RX tasklets. */
4568 tasklet_enable(&priv->poll_tx_task);
4569 tasklet_enable(&priv->poll_rx_task);
4571 /* Enable interrupts */
4572 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4573 iowrite32(MWL8K_A2H_EVENTS,
4574 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4576 rc = mwl8k_fw_lock(hw);
4578 rc = mwl8k_cmd_radio_enable(hw);
4582 rc = mwl8k_cmd_enable_sniffer(hw, 0);
4585 rc = mwl8k_cmd_set_pre_scan(hw);
4588 rc = mwl8k_cmd_set_post_scan(hw,
4589 "\x00\x00\x00\x00\x00\x00");
4593 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
4596 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
4598 mwl8k_fw_unlock(hw);
4602 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4603 free_irq(priv->pdev->irq, hw);
4605 tasklet_disable(&priv->poll_tx_task);
4606 tasklet_disable(&priv->poll_rx_task);
4608 ieee80211_wake_queues(hw);
4614 static void mwl8k_stop(struct ieee80211_hw *hw)
4616 struct mwl8k_priv *priv = hw->priv;
4619 if (!priv->hw_restart_in_progress)
4620 mwl8k_cmd_radio_disable(hw);
4622 ieee80211_stop_queues(hw);
4624 /* Disable interrupts */
4625 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4626 if (priv->irq != -1) {
4627 free_irq(priv->pdev->irq, hw);
4631 /* Stop finalize join worker */
4632 cancel_work_sync(&priv->finalize_join_worker);
4633 cancel_work_sync(&priv->watchdog_ba_handle);
4634 if (priv->beacon_skb != NULL)
4635 dev_kfree_skb(priv->beacon_skb);
4637 /* Stop TX reclaim and RX tasklets. */
4638 tasklet_disable(&priv->poll_tx_task);
4639 tasklet_disable(&priv->poll_rx_task);
4641 /* Return all skbs to mac80211 */
4642 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4643 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
4646 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
4648 static int mwl8k_add_interface(struct ieee80211_hw *hw,
4649 struct ieee80211_vif *vif)
4651 struct mwl8k_priv *priv = hw->priv;
4652 struct mwl8k_vif *mwl8k_vif;
4653 u32 macids_supported;
4655 struct mwl8k_device_info *di;
4658 * Reject interface creation if sniffer mode is active, as
4659 * STA operation is mutually exclusive with hardware sniffer
4660 * mode. (Sniffer mode is only used on STA firmware.)
4662 if (priv->sniffer_enabled) {
4663 wiphy_info(hw->wiphy,
4664 "unable to create STA interface because sniffer mode is enabled\n");
4668 di = priv->device_info;
4669 switch (vif->type) {
4670 case NL80211_IFTYPE_AP:
4671 if (!priv->ap_fw && di->fw_image_ap) {
4672 /* we must load the ap fw to meet this request */
4673 if (!list_empty(&priv->vif_list))
4675 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4679 macids_supported = priv->ap_macids_supported;
4681 case NL80211_IFTYPE_STATION:
4682 if (priv->ap_fw && di->fw_image_sta) {
4683 if (!list_empty(&priv->vif_list)) {
4684 wiphy_warn(hw->wiphy, "AP interface is running.\n"
4685 "Adding STA interface for WDS");
4687 /* we must load the sta fw to
4688 * meet this request.
4690 rc = mwl8k_reload_firmware(hw,
4696 macids_supported = priv->sta_macids_supported;
4702 macid = ffs(macids_supported & ~priv->macids_used);
4706 /* Setup driver private area. */
4707 mwl8k_vif = MWL8K_VIF(vif);
4708 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
4709 mwl8k_vif->vif = vif;
4710 mwl8k_vif->macid = macid;
4711 mwl8k_vif->seqno = 0;
4712 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
4713 mwl8k_vif->is_hw_crypto_enabled = false;
4715 /* Set the mac address. */
4716 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
4718 if (vif->type == NL80211_IFTYPE_AP)
4719 mwl8k_cmd_set_new_stn_add_self(hw, vif);
4721 priv->macids_used |= 1 << mwl8k_vif->macid;
4722 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
4727 static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
4729 /* Has ieee80211_restart_hw re-added the removed interfaces? */
4730 if (!priv->macids_used)
4733 priv->macids_used &= ~(1 << vif->macid);
4734 list_del(&vif->list);
4737 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
4738 struct ieee80211_vif *vif)
4740 struct mwl8k_priv *priv = hw->priv;
4741 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4743 if (vif->type == NL80211_IFTYPE_AP)
4744 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
4746 mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
4748 mwl8k_remove_vif(priv, mwl8k_vif);
4751 static void mwl8k_hw_restart_work(struct work_struct *work)
4753 struct mwl8k_priv *priv =
4754 container_of(work, struct mwl8k_priv, fw_reload);
4755 struct ieee80211_hw *hw = priv->hw;
4756 struct mwl8k_device_info *di;
4759 /* If some command is waiting for a response, clear it */
4760 if (priv->hostcmd_wait != NULL) {
4761 complete(priv->hostcmd_wait);
4762 priv->hostcmd_wait = NULL;
4765 priv->hw_restart_owner = current;
4766 di = priv->device_info;
4770 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4772 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4777 priv->hw_restart_owner = NULL;
4778 priv->hw_restart_in_progress = false;
4781 * This unlock will wake up the queues and
4782 * also opens the command path for other
4785 mwl8k_fw_unlock(hw);
4787 ieee80211_restart_hw(hw);
4789 wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
4793 mwl8k_fw_unlock(hw);
4795 wiphy_err(hw->wiphy, "Firmware restart failed\n");
4798 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
4800 struct ieee80211_conf *conf = &hw->conf;
4801 struct mwl8k_priv *priv = hw->priv;
4804 if (conf->flags & IEEE80211_CONF_IDLE) {
4805 mwl8k_cmd_radio_disable(hw);
4809 rc = mwl8k_fw_lock(hw);
4813 rc = mwl8k_cmd_radio_enable(hw);
4817 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
4818 rc = mwl8k_cmd_set_rf_channel(hw, conf);
4823 if (conf->power_level > 18)
4824 conf->power_level = 18;
4828 if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
4829 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
4836 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
4839 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
4843 mwl8k_fw_unlock(hw);
4849 mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4850 struct ieee80211_bss_conf *info, u32 changed)
4852 struct mwl8k_priv *priv = hw->priv;
4853 u32 ap_legacy_rates = 0;
4854 u8 ap_mcs_rates[16];
4857 if (mwl8k_fw_lock(hw))
4861 * No need to capture a beacon if we're no longer associated.
4863 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
4864 priv->capture_beacon = false;
4867 * Get the AP's legacy and MCS rates.
4869 if (vif->bss_conf.assoc) {
4870 struct ieee80211_sta *ap;
4874 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
4880 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
4881 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
4884 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4886 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
4891 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
4893 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
4897 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
4901 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
4906 /* Use AP firmware specific rate command.
4908 idx = ffs(vif->bss_conf.basic_rates);
4912 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4913 rate = mwl8k_rates_24[idx].hw_value;
4915 rate = mwl8k_rates_50[idx].hw_value;
4917 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4921 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4922 rc = mwl8k_set_radio_preamble(hw,
4923 vif->bss_conf.use_short_preamble);
4928 if ((changed & BSS_CHANGED_ERP_SLOT) && !priv->ap_fw) {
4929 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
4934 if (vif->bss_conf.assoc && !priv->ap_fw &&
4935 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4937 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
4942 if (vif->bss_conf.assoc &&
4943 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
4945 * Finalize the join. Tell rx handler to process
4946 * next beacon from our BSSID.
4948 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
4949 priv->capture_beacon = true;
4953 mwl8k_fw_unlock(hw);
4957 mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4958 struct ieee80211_bss_conf *info, u32 changed)
4962 if (mwl8k_fw_lock(hw))
4965 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4966 rc = mwl8k_set_radio_preamble(hw,
4967 vif->bss_conf.use_short_preamble);
4972 if (changed & BSS_CHANGED_BASIC_RATES) {
4977 * Use lowest supported basic rate for multicasts
4978 * and management frames (such as probe responses --
4979 * beacons will always go out at 1 Mb/s).
4981 idx = ffs(vif->bss_conf.basic_rates);
4985 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4986 rate = mwl8k_rates_24[idx].hw_value;
4988 rate = mwl8k_rates_50[idx].hw_value;
4990 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4993 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
4994 struct sk_buff *skb;
4996 skb = ieee80211_beacon_get(hw, vif);
4998 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
5003 if (changed & BSS_CHANGED_BEACON_ENABLED)
5004 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
5007 mwl8k_fw_unlock(hw);
5011 mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5012 struct ieee80211_bss_conf *info, u32 changed)
5014 if (vif->type == NL80211_IFTYPE_STATION)
5015 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
5016 if (vif->type == NL80211_IFTYPE_AP)
5017 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
5020 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
5021 struct netdev_hw_addr_list *mc_list)
5023 struct mwl8k_cmd_pkt *cmd;
5026 * Synthesize and return a command packet that programs the
5027 * hardware multicast address filter. At this point we don't
5028 * know whether FIF_ALLMULTI is being requested, but if it is,
5029 * we'll end up throwing this packet away and creating a new
5030 * one in mwl8k_configure_filter().
5032 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
5034 return (unsigned long)cmd;
5038 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
5039 unsigned int changed_flags,
5040 unsigned int *total_flags)
5042 struct mwl8k_priv *priv = hw->priv;
5045 * Hardware sniffer mode is mutually exclusive with STA
5046 * operation, so refuse to enable sniffer mode if a STA
5047 * interface is active.
5049 if (!list_empty(&priv->vif_list)) {
5050 if (net_ratelimit())
5051 wiphy_info(hw->wiphy,
5052 "not enabling sniffer mode because STA interface is active\n");
5056 if (!priv->sniffer_enabled) {
5057 if (mwl8k_cmd_enable_sniffer(hw, 1))
5059 priv->sniffer_enabled = true;
5062 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
5063 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
5069 static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
5071 if (!list_empty(&priv->vif_list))
5072 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
5077 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
5078 unsigned int changed_flags,
5079 unsigned int *total_flags,
5082 struct mwl8k_priv *priv = hw->priv;
5083 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
5086 * AP firmware doesn't allow fine-grained control over
5087 * the receive filter.
5090 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
5096 * Enable hardware sniffer mode if FIF_CONTROL or
5097 * FIF_OTHER_BSS is requested.
5099 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
5100 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
5105 /* Clear unsupported feature flags */
5106 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
5108 if (mwl8k_fw_lock(hw)) {
5113 if (priv->sniffer_enabled) {
5114 mwl8k_cmd_enable_sniffer(hw, 0);
5115 priv->sniffer_enabled = false;
5118 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
5119 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
5121 * Disable the BSS filter.
5123 mwl8k_cmd_set_pre_scan(hw);
5125 struct mwl8k_vif *mwl8k_vif;
5129 * Enable the BSS filter.
5131 * If there is an active STA interface, use that
5132 * interface's BSSID, otherwise use a dummy one
5133 * (where the OUI part needs to be nonzero for
5134 * the BSSID to be accepted by POST_SCAN).
5136 mwl8k_vif = mwl8k_first_vif(priv);
5137 if (mwl8k_vif != NULL)
5138 bssid = mwl8k_vif->vif->bss_conf.bssid;
5140 bssid = "\x01\x00\x00\x00\x00\x00";
5142 mwl8k_cmd_set_post_scan(hw, bssid);
5147 * If FIF_ALLMULTI is being requested, throw away the command
5148 * packet that ->prepare_multicast() built and replace it with
5149 * a command packet that enables reception of all multicast
5152 if (*total_flags & FIF_ALLMULTI) {
5154 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
5158 mwl8k_post_cmd(hw, cmd);
5162 mwl8k_fw_unlock(hw);
5165 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5167 return mwl8k_cmd_set_rts_threshold(hw, value);
5170 static int mwl8k_sta_remove(struct ieee80211_hw *hw,
5171 struct ieee80211_vif *vif,
5172 struct ieee80211_sta *sta)
5174 struct mwl8k_priv *priv = hw->priv;
5177 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
5179 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
5182 static int mwl8k_sta_add(struct ieee80211_hw *hw,
5183 struct ieee80211_vif *vif,
5184 struct ieee80211_sta *sta)
5186 struct mwl8k_priv *priv = hw->priv;
5189 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
5190 struct ieee80211_key_conf *key;
5193 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
5195 MWL8K_STA(sta)->peer_id = ret;
5196 if (sta->ht_cap.ht_supported)
5197 MWL8K_STA(sta)->is_ampdu_allowed = true;
5202 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
5205 for (i = 0; i < NUM_WEP_KEYS; i++) {
5206 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
5207 if (mwl8k_vif->wep_key_conf[i].enabled)
5208 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
5213 static int mwl8k_conf_tx(struct ieee80211_hw *hw,
5214 struct ieee80211_vif *vif, u16 queue,
5215 const struct ieee80211_tx_queue_params *params)
5217 struct mwl8k_priv *priv = hw->priv;
5220 rc = mwl8k_fw_lock(hw);
5222 BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
5223 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
5225 if (!priv->wmm_enabled)
5226 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
5229 int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
5230 rc = mwl8k_cmd_set_edca_params(hw, q,
5237 mwl8k_fw_unlock(hw);
5243 static int mwl8k_get_stats(struct ieee80211_hw *hw,
5244 struct ieee80211_low_level_stats *stats)
5246 return mwl8k_cmd_get_stat(hw, stats);
5249 static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
5250 struct survey_info *survey)
5252 struct mwl8k_priv *priv = hw->priv;
5253 struct ieee80211_conf *conf = &hw->conf;
5258 survey->channel = conf->channel;
5259 survey->filled = SURVEY_INFO_NOISE_DBM;
5260 survey->noise = priv->noise;
5265 #define MAX_AMPDU_ATTEMPTS 5
5268 mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5269 enum ieee80211_ampdu_mlme_action action,
5270 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5275 struct mwl8k_priv *priv = hw->priv;
5276 struct mwl8k_ampdu_stream *stream;
5277 u8 *addr = sta->addr, idx;
5278 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
5280 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
5283 spin_lock(&priv->stream_lock);
5284 stream = mwl8k_lookup_stream(hw, addr, tid);
5287 case IEEE80211_AMPDU_RX_START:
5288 case IEEE80211_AMPDU_RX_STOP:
5290 case IEEE80211_AMPDU_TX_START:
5291 /* By the time we get here the hw queues may contain outgoing
5292 * packets for this RA/TID that are not part of this BA
5293 * session. The hw will assign sequence numbers to these
5294 * packets as they go out. So if we query the hw for its next
5295 * sequence number and use that for the SSN here, it may end up
5296 * being wrong, which will lead to sequence number mismatch at
5297 * the recipient. To avoid this, we reset the sequence number
5298 * to O for the first MPDU in this BA stream.
5301 if (stream == NULL) {
5302 /* This means that somebody outside this driver called
5303 * ieee80211_start_tx_ba_session. This is unexpected
5304 * because we do our own rate control. Just warn and
5307 wiphy_warn(hw->wiphy, "Unexpected call to %s. "
5308 "Proceeding anyway.\n", __func__);
5309 stream = mwl8k_add_stream(hw, sta, tid);
5311 if (stream == NULL) {
5312 wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
5316 stream->state = AMPDU_STREAM_IN_PROGRESS;
5318 /* Release the lock before we do the time consuming stuff */
5319 spin_unlock(&priv->stream_lock);
5320 for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
5322 /* Check if link is still valid */
5323 if (!sta_info->is_ampdu_allowed) {
5324 spin_lock(&priv->stream_lock);
5325 mwl8k_remove_stream(hw, stream);
5326 spin_unlock(&priv->stream_lock);
5330 rc = mwl8k_check_ba(hw, stream, vif);
5332 /* If HW restart is in progress mwl8k_post_cmd will
5333 * return -EBUSY. Avoid retrying mwl8k_check_ba in
5336 if (!rc || rc == -EBUSY)
5339 * HW queues take time to be flushed, give them
5345 spin_lock(&priv->stream_lock);
5347 wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
5348 " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
5349 mwl8k_remove_stream(hw, stream);
5353 ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
5355 case IEEE80211_AMPDU_TX_STOP_CONT:
5356 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5357 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5359 if (stream->state == AMPDU_STREAM_ACTIVE) {
5361 spin_unlock(&priv->stream_lock);
5362 mwl8k_destroy_ba(hw, idx);
5363 spin_lock(&priv->stream_lock);
5365 mwl8k_remove_stream(hw, stream);
5367 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
5369 case IEEE80211_AMPDU_TX_OPERATIONAL:
5370 BUG_ON(stream == NULL);
5371 BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
5372 spin_unlock(&priv->stream_lock);
5373 rc = mwl8k_create_ba(hw, stream, buf_size, vif);
5374 spin_lock(&priv->stream_lock);
5376 stream->state = AMPDU_STREAM_ACTIVE;
5379 spin_unlock(&priv->stream_lock);
5380 mwl8k_destroy_ba(hw, idx);
5381 spin_lock(&priv->stream_lock);
5382 wiphy_debug(hw->wiphy,
5383 "Failed adding stream for sta %pM tid %d\n",
5385 mwl8k_remove_stream(hw, stream);
5393 spin_unlock(&priv->stream_lock);
5397 static const struct ieee80211_ops mwl8k_ops = {
5399 .start = mwl8k_start,
5401 .add_interface = mwl8k_add_interface,
5402 .remove_interface = mwl8k_remove_interface,
5403 .config = mwl8k_config,
5404 .bss_info_changed = mwl8k_bss_info_changed,
5405 .prepare_multicast = mwl8k_prepare_multicast,
5406 .configure_filter = mwl8k_configure_filter,
5407 .set_key = mwl8k_set_key,
5408 .set_rts_threshold = mwl8k_set_rts_threshold,
5409 .sta_add = mwl8k_sta_add,
5410 .sta_remove = mwl8k_sta_remove,
5411 .conf_tx = mwl8k_conf_tx,
5412 .get_stats = mwl8k_get_stats,
5413 .get_survey = mwl8k_get_survey,
5414 .ampdu_action = mwl8k_ampdu_action,
5417 static void mwl8k_finalize_join_worker(struct work_struct *work)
5419 struct mwl8k_priv *priv =
5420 container_of(work, struct mwl8k_priv, finalize_join_worker);
5421 struct sk_buff *skb = priv->beacon_skb;
5422 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5423 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
5424 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
5425 mgmt->u.beacon.variable, len);
5426 int dtim_period = 1;
5428 if (tim && tim[1] >= 2)
5429 dtim_period = tim[3];
5431 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
5434 priv->beacon_skb = NULL;
5444 #define MWL8K_8366_AP_FW_API 3
5445 #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5446 #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5448 #define MWL8K_8764_AP_FW_API 1
5449 #define _MWL8K_8764_AP_FW(api) "mwl8k/fmimage_8764_ap-" #api ".fw"
5450 #define MWL8K_8764_AP_FW(api) _MWL8K_8764_AP_FW(api)
5452 static struct mwl8k_device_info mwl8k_info_tbl[] = {
5454 .part_name = "88w8363",
5455 .helper_image = "mwl8k/helper_8363.fw",
5456 .fw_image_sta = "mwl8k/fmimage_8363.fw",
5459 .part_name = "88w8687",
5460 .helper_image = "mwl8k/helper_8687.fw",
5461 .fw_image_sta = "mwl8k/fmimage_8687.fw",
5464 .part_name = "88w8366",
5465 .helper_image = "mwl8k/helper_8366.fw",
5466 .fw_image_sta = "mwl8k/fmimage_8366.fw",
5467 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
5468 .fw_api_ap = MWL8K_8366_AP_FW_API,
5469 .ap_rxd_ops = &rxd_ap_ops,
5472 .part_name = "88w8764",
5473 .fw_image_ap = MWL8K_8764_AP_FW(MWL8K_8764_AP_FW_API),
5474 .fw_api_ap = MWL8K_8764_AP_FW_API,
5475 .ap_rxd_ops = &rxd_ap_ops,
5479 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5480 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5481 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5482 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5483 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5484 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
5485 MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
5487 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
5488 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
5489 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
5490 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
5491 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
5492 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
5493 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
5494 { PCI_VDEVICE(MARVELL, 0x2a41), .driver_data = MWL8366, },
5495 { PCI_VDEVICE(MARVELL, 0x2a42), .driver_data = MWL8366, },
5496 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
5497 { PCI_VDEVICE(MARVELL, 0x2b36), .driver_data = MWL8764, },
5500 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
5502 static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
5505 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
5506 "Trying alternative firmware %s\n", pci_name(priv->pdev),
5507 priv->fw_pref, priv->fw_alt);
5508 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
5510 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5511 pci_name(priv->pdev), priv->fw_alt);
5517 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
5518 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
5520 struct mwl8k_priv *priv = context;
5521 struct mwl8k_device_info *di = priv->device_info;
5524 switch (priv->fw_state) {
5527 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
5528 pci_name(priv->pdev), di->helper_image);
5531 priv->fw_helper = fw;
5532 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
5534 if (rc && priv->fw_alt) {
5535 rc = mwl8k_request_alt_fw(priv);
5538 priv->fw_state = FW_STATE_LOADING_ALT;
5542 priv->fw_state = FW_STATE_LOADING_PREF;
5545 case FW_STATE_LOADING_PREF:
5548 rc = mwl8k_request_alt_fw(priv);
5551 priv->fw_state = FW_STATE_LOADING_ALT;
5555 priv->fw_ucode = fw;
5556 rc = mwl8k_firmware_load_success(priv);
5560 complete(&priv->firmware_loading_complete);
5564 case FW_STATE_LOADING_ALT:
5566 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5567 pci_name(priv->pdev), di->helper_image);
5570 priv->fw_ucode = fw;
5571 rc = mwl8k_firmware_load_success(priv);
5575 complete(&priv->firmware_loading_complete);
5579 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
5580 MWL8K_NAME, priv->fw_state);
5587 priv->fw_state = FW_STATE_ERROR;
5588 complete(&priv->firmware_loading_complete);
5589 device_release_driver(&priv->pdev->dev);
5590 mwl8k_release_firmware(priv);
5593 #define MAX_RESTART_ATTEMPTS 1
5594 static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
5597 struct mwl8k_priv *priv = hw->priv;
5599 int count = MAX_RESTART_ATTEMPTS;
5602 /* Reset firmware and hardware */
5603 mwl8k_hw_reset(priv);
5605 /* Ask userland hotplug daemon for the device firmware */
5606 rc = mwl8k_request_firmware(priv, fw_image, nowait);
5608 wiphy_err(hw->wiphy, "Firmware files not found\n");
5615 /* Load firmware into hardware */
5616 rc = mwl8k_load_firmware(hw);
5618 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5620 /* Reclaim memory once firmware is successfully loaded */
5621 mwl8k_release_firmware(priv);
5624 /* FW did not start successfully;
5625 * lets try one more time
5628 wiphy_err(hw->wiphy, "Trying to reload the firmware again\n");
5636 static int mwl8k_init_txqs(struct ieee80211_hw *hw)
5638 struct mwl8k_priv *priv = hw->priv;
5642 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
5643 rc = mwl8k_txq_init(hw, i);
5647 iowrite32(priv->txq[i].txd_dma,
5648 priv->sram + priv->txq_offset[i]);
5653 /* initialize hw after successfully loading a firmware image */
5654 static int mwl8k_probe_hw(struct ieee80211_hw *hw)
5656 struct mwl8k_priv *priv = hw->priv;
5661 priv->rxd_ops = priv->device_info->ap_rxd_ops;
5662 if (priv->rxd_ops == NULL) {
5663 wiphy_err(hw->wiphy,
5664 "Driver does not have AP firmware image support for this hardware\n");
5666 goto err_stop_firmware;
5669 priv->rxd_ops = &rxd_sta_ops;
5672 priv->sniffer_enabled = false;
5673 priv->wmm_enabled = false;
5674 priv->pending_tx_pkts = 0;
5675 atomic_set(&priv->watchdog_event_pending, 0);
5677 rc = mwl8k_rxq_init(hw, 0);
5679 goto err_stop_firmware;
5680 rxq_refill(hw, 0, INT_MAX);
5682 /* For the sta firmware, we need to know the dma addresses of tx queues
5683 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5684 * prior to issuing this command. But for the AP case, we learn the
5685 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5686 * case we must initialize the tx queues after.
5688 priv->num_ampdu_queues = 0;
5690 rc = mwl8k_init_txqs(hw);
5692 goto err_free_queues;
5695 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
5696 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5697 iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
5698 MWL8K_A2H_INT_BA_WATCHDOG,
5699 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
5700 iowrite32(MWL8K_A2H_INT_OPC_DONE,
5701 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
5703 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
5704 IRQF_SHARED, MWL8K_NAME, hw);
5706 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
5707 goto err_free_queues;
5711 * When hw restart is requested,
5712 * mac80211 will take care of clearing
5713 * the ampdu streams, so do not clear
5714 * the ampdu state here
5716 if (!priv->hw_restart_in_progress)
5717 memset(priv->ampdu, 0, sizeof(priv->ampdu));
5720 * Temporarily enable interrupts. Initial firmware host
5721 * commands use interrupts and avoid polling. Disable
5722 * interrupts when done.
5724 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5726 /* Get config data, mac addrs etc */
5728 rc = mwl8k_cmd_get_hw_spec_ap(hw);
5730 rc = mwl8k_init_txqs(hw);
5732 rc = mwl8k_cmd_set_hw_spec(hw);
5734 rc = mwl8k_cmd_get_hw_spec_sta(hw);
5737 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
5741 /* Turn radio off */
5742 rc = mwl8k_cmd_radio_disable(hw);
5744 wiphy_err(hw->wiphy, "Cannot disable\n");
5748 /* Clear MAC address */
5749 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
5751 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
5755 /* Configure Antennas */
5756 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
5758 wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
5759 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
5761 wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
5764 /* Disable interrupts */
5765 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5766 free_irq(priv->pdev->irq, hw);
5768 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5769 priv->device_info->part_name,
5770 priv->hw_rev, hw->wiphy->perm_addr,
5771 priv->ap_fw ? "AP" : "STA",
5772 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
5773 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
5778 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5779 free_irq(priv->pdev->irq, hw);
5782 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5783 mwl8k_txq_deinit(hw, i);
5784 mwl8k_rxq_deinit(hw, 0);
5787 mwl8k_hw_reset(priv);
5793 * invoke mwl8k_reload_firmware to change the firmware image after the device
5794 * has already been registered
5796 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
5799 struct mwl8k_priv *priv = hw->priv;
5800 struct mwl8k_vif *vif, *tmp_vif;
5803 mwl8k_rxq_deinit(hw, 0);
5806 * All the existing interfaces are re-added by the ieee80211_reconfig;
5807 * which means driver should remove existing interfaces before calling
5808 * ieee80211_restart_hw
5810 if (priv->hw_restart_in_progress)
5811 list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list)
5812 mwl8k_remove_vif(priv, vif);
5814 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5815 mwl8k_txq_deinit(hw, i);
5817 rc = mwl8k_init_firmware(hw, fw_image, false);
5821 rc = mwl8k_probe_hw(hw);
5825 if (priv->hw_restart_in_progress)
5828 rc = mwl8k_start(hw);
5832 rc = mwl8k_config(hw, ~0);
5836 for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
5837 rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]);
5845 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
5849 static const struct ieee80211_iface_limit ap_if_limits[] = {
5850 { .max = 8, .types = BIT(NL80211_IFTYPE_AP) },
5851 { .max = 1, .types = BIT(NL80211_IFTYPE_STATION) },
5854 static const struct ieee80211_iface_combination ap_if_comb = {
5855 .limits = ap_if_limits,
5856 .n_limits = ARRAY_SIZE(ap_if_limits),
5857 .max_interfaces = 8,
5858 .num_different_channels = 1,
5862 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
5864 struct ieee80211_hw *hw = priv->hw;
5867 rc = mwl8k_load_firmware(hw);
5868 mwl8k_release_firmware(priv);
5870 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5875 * Extra headroom is the size of the required DMA header
5876 * minus the size of the smallest 802.11 frame (CTS frame).
5878 hw->extra_tx_headroom =
5879 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
5881 hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0;
5883 hw->channel_change_time = 10;
5885 hw->queues = MWL8K_TX_WMM_QUEUES;
5887 /* Set rssi values to dBm */
5888 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
5891 * Ask mac80211 to not to trigger PS mode
5892 * based on PM bit of incoming frames.
5895 hw->flags |= IEEE80211_HW_AP_LINK_PS;
5897 hw->vif_data_size = sizeof(struct mwl8k_vif);
5898 hw->sta_data_size = sizeof(struct mwl8k_sta);
5900 priv->macids_used = 0;
5901 INIT_LIST_HEAD(&priv->vif_list);
5903 /* Set default radio state and preamble */
5904 priv->radio_on = false;
5905 priv->radio_short_preamble = false;
5907 /* Finalize join worker */
5908 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
5909 /* Handle watchdog ba events */
5910 INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
5911 /* To reload the firmware if it crashes */
5912 INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
5914 /* TX reclaim and RX tasklets. */
5915 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
5916 tasklet_disable(&priv->poll_tx_task);
5917 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
5918 tasklet_disable(&priv->poll_rx_task);
5920 /* Power management cookie */
5921 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
5922 if (priv->cookie == NULL)
5925 mutex_init(&priv->fw_mutex);
5926 priv->fw_mutex_owner = NULL;
5927 priv->fw_mutex_depth = 0;
5928 priv->hostcmd_wait = NULL;
5930 spin_lock_init(&priv->tx_lock);
5932 spin_lock_init(&priv->stream_lock);
5934 priv->tx_wait = NULL;
5936 rc = mwl8k_probe_hw(hw);
5938 goto err_free_cookie;
5940 hw->wiphy->interface_modes = 0;
5942 if (priv->ap_macids_supported || priv->device_info->fw_image_ap) {
5943 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
5944 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
5945 hw->wiphy->iface_combinations = &ap_if_comb;
5946 hw->wiphy->n_iface_combinations = 1;
5949 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
5950 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
5952 rc = ieee80211_register_hw(hw);
5954 wiphy_err(hw->wiphy, "Cannot register device\n");
5955 goto err_unprobe_hw;
5961 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5962 mwl8k_txq_deinit(hw, i);
5963 mwl8k_rxq_deinit(hw, 0);
5966 if (priv->cookie != NULL)
5967 pci_free_consistent(priv->pdev, 4,
5968 priv->cookie, priv->cookie_dma);
5972 static int mwl8k_probe(struct pci_dev *pdev,
5973 const struct pci_device_id *id)
5975 static int printed_version;
5976 struct ieee80211_hw *hw;
5977 struct mwl8k_priv *priv;
5978 struct mwl8k_device_info *di;
5981 if (!printed_version) {
5982 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
5983 printed_version = 1;
5987 rc = pci_enable_device(pdev);
5989 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
5994 rc = pci_request_regions(pdev, MWL8K_NAME);
5996 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
5998 goto err_disable_device;
6001 pci_set_master(pdev);
6004 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
6006 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
6011 SET_IEEE80211_DEV(hw, &pdev->dev);
6012 pci_set_drvdata(pdev, hw);
6017 priv->device_info = &mwl8k_info_tbl[id->driver_data];
6019 if (id->driver_data == MWL8764)
6020 priv->is_8764 = true;
6022 priv->sram = pci_iomap(pdev, 0, 0x10000);
6023 if (priv->sram == NULL) {
6024 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
6030 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
6031 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
6033 priv->regs = pci_iomap(pdev, 1, 0x10000);
6034 if (priv->regs == NULL) {
6035 priv->regs = pci_iomap(pdev, 2, 0x10000);
6036 if (priv->regs == NULL) {
6037 wiphy_err(hw->wiphy, "Cannot map device registers\n");
6044 * Choose the initial fw image depending on user input. If a second
6045 * image is available, make it the alternative image that will be
6046 * loaded if the first one fails.
6048 init_completion(&priv->firmware_loading_complete);
6049 di = priv->device_info;
6050 if (ap_mode_default && di->fw_image_ap) {
6051 priv->fw_pref = di->fw_image_ap;
6052 priv->fw_alt = di->fw_image_sta;
6053 } else if (!ap_mode_default && di->fw_image_sta) {
6054 priv->fw_pref = di->fw_image_sta;
6055 priv->fw_alt = di->fw_image_ap;
6056 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
6057 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
6058 priv->fw_pref = di->fw_image_sta;
6059 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
6060 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
6061 priv->fw_pref = di->fw_image_ap;
6063 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
6065 goto err_stop_firmware;
6067 priv->hw_restart_in_progress = false;
6069 priv->running_bsses = 0;
6074 mwl8k_hw_reset(priv);
6077 if (priv->regs != NULL)
6078 pci_iounmap(pdev, priv->regs);
6080 if (priv->sram != NULL)
6081 pci_iounmap(pdev, priv->sram);
6083 pci_set_drvdata(pdev, NULL);
6084 ieee80211_free_hw(hw);
6087 pci_release_regions(pdev);
6090 pci_disable_device(pdev);
6095 static void mwl8k_remove(struct pci_dev *pdev)
6097 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
6098 struct mwl8k_priv *priv;
6105 wait_for_completion(&priv->firmware_loading_complete);
6107 if (priv->fw_state == FW_STATE_ERROR) {
6108 mwl8k_hw_reset(priv);
6112 ieee80211_stop_queues(hw);
6114 ieee80211_unregister_hw(hw);
6116 /* Remove TX reclaim and RX tasklets. */
6117 tasklet_kill(&priv->poll_tx_task);
6118 tasklet_kill(&priv->poll_rx_task);
6121 mwl8k_hw_reset(priv);
6123 /* Return all skbs to mac80211 */
6124 for (i = 0; i < mwl8k_tx_queues(priv); i++)
6125 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
6127 for (i = 0; i < mwl8k_tx_queues(priv); i++)
6128 mwl8k_txq_deinit(hw, i);
6130 mwl8k_rxq_deinit(hw, 0);
6132 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
6135 pci_iounmap(pdev, priv->regs);
6136 pci_iounmap(pdev, priv->sram);
6137 pci_set_drvdata(pdev, NULL);
6138 ieee80211_free_hw(hw);
6139 pci_release_regions(pdev);
6140 pci_disable_device(pdev);
6143 static struct pci_driver mwl8k_driver = {
6145 .id_table = mwl8k_pci_id_table,
6146 .probe = mwl8k_probe,
6147 .remove = mwl8k_remove,
6150 module_pci_driver(mwl8k_driver);
6152 MODULE_DESCRIPTION(MWL8K_DESC);
6153 MODULE_VERSION(MWL8K_VERSION);
6154 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
6155 MODULE_LICENSE("GPL");