2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc.
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/spinlock.h>
17 #include <linux/list.h>
18 #include <linux/pci.h>
19 #include <linux/delay.h>
20 #include <linux/completion.h>
21 #include <linux/etherdevice.h>
22 #include <linux/slab.h>
23 #include <net/mac80211.h>
24 #include <linux/moduleparam.h>
25 #include <linux/firmware.h>
26 #include <linux/workqueue.h>
28 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
29 #define MWL8K_NAME KBUILD_MODNAME
30 #define MWL8K_VERSION "0.12"
32 /* Module parameters */
33 static unsigned ap_mode_default;
34 module_param(ap_mode_default, bool, 0);
35 MODULE_PARM_DESC(ap_mode_default,
36 "Set to 1 to make ap mode the default instead of sta mode");
38 /* Register definitions */
39 #define MWL8K_HIU_GEN_PTR 0x00000c10
40 #define MWL8K_MODE_STA 0x0000005a
41 #define MWL8K_MODE_AP 0x000000a5
42 #define MWL8K_HIU_INT_CODE 0x00000c14
43 #define MWL8K_FWSTA_READY 0xf0f1f2f4
44 #define MWL8K_FWAP_READY 0xf1f2f4a5
45 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
46 #define MWL8K_HIU_SCRATCH 0x00000c40
48 /* Host->device communications */
49 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
50 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
51 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
52 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
53 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
54 #define MWL8K_H2A_INT_DUMMY (1 << 20)
55 #define MWL8K_H2A_INT_RESET (1 << 15)
56 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
57 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
59 /* Device->host communications */
60 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
61 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
62 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
63 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
64 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
65 #define MWL8K_A2H_INT_DUMMY (1 << 20)
66 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
67 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
68 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
69 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
70 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
71 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
72 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
73 #define MWL8K_A2H_INT_RX_READY (1 << 1)
74 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
76 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
77 MWL8K_A2H_INT_CHNL_SWITCHED | \
78 MWL8K_A2H_INT_QUEUE_EMPTY | \
79 MWL8K_A2H_INT_RADAR_DETECT | \
80 MWL8K_A2H_INT_RADIO_ON | \
81 MWL8K_A2H_INT_RADIO_OFF | \
82 MWL8K_A2H_INT_MAC_EVENT | \
83 MWL8K_A2H_INT_OPC_DONE | \
84 MWL8K_A2H_INT_RX_READY | \
85 MWL8K_A2H_INT_TX_DONE)
87 #define MWL8K_RX_QUEUES 1
88 #define MWL8K_TX_WMM_QUEUES 4
89 #define MWL8K_MAX_AMPDU_QUEUES 8
90 #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
91 #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
95 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
96 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
97 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
98 __le16 *qos, s8 *noise);
101 struct mwl8k_device_info {
106 struct rxd_ops *ap_rxd_ops;
110 struct mwl8k_rx_queue {
113 /* hw receives here */
116 /* refill descs here */
123 DEFINE_DMA_UNMAP_ADDR(dma);
127 struct mwl8k_tx_queue {
128 /* hw transmits here */
131 /* sw appends here */
135 struct mwl8k_tx_desc *txd;
137 struct sk_buff **skb;
143 AMPDU_STREAM_IN_PROGRESS,
147 struct mwl8k_ampdu_stream {
148 struct ieee80211_sta *sta;
152 u8 txq_idx; /* index of this stream in priv->txq */
156 struct ieee80211_hw *hw;
157 struct pci_dev *pdev;
159 struct mwl8k_device_info *device_info;
165 const struct firmware *fw_helper;
166 const struct firmware *fw_ucode;
168 /* hardware/firmware parameters */
170 struct rxd_ops *rxd_ops;
171 struct ieee80211_supported_band band_24;
172 struct ieee80211_channel channels_24[14];
173 struct ieee80211_rate rates_24[14];
174 struct ieee80211_supported_band band_50;
175 struct ieee80211_channel channels_50[4];
176 struct ieee80211_rate rates_50[9];
177 u32 ap_macids_supported;
178 u32 sta_macids_supported;
180 /* Ampdu stream information */
182 spinlock_t stream_lock;
183 struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
185 /* firmware access */
186 struct mutex fw_mutex;
187 struct task_struct *fw_mutex_owner;
189 struct completion *hostcmd_wait;
191 /* lock held over TX and TX reap */
194 /* TX quiesce completion, protected by fw_mutex and tx_lock */
195 struct completion *tx_wait;
197 /* List of interfaces. */
199 struct list_head vif_list;
201 /* power management status cookie from firmware */
203 dma_addr_t cookie_dma;
210 * Running count of TX packets in flight, to avoid
211 * iterating over the transmit rings each time.
215 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
216 struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
217 u32 txq_offset[MWL8K_MAX_TX_QUEUES];
220 bool radio_short_preamble;
221 bool sniffer_enabled;
224 /* XXX need to convert this to handle multiple interfaces */
226 u8 capture_bssid[ETH_ALEN];
227 struct sk_buff *beacon_skb;
230 * This FJ worker has to be global as it is scheduled from the
231 * RX handler. At this point we don't know which interface it
232 * belongs to until the list of bssids waiting to complete join
235 struct work_struct finalize_join_worker;
237 /* Tasklet to perform TX reclaim. */
238 struct tasklet_struct poll_tx_task;
240 /* Tasklet to perform RX. */
241 struct tasklet_struct poll_rx_task;
243 /* Most recently reported noise in dBm */
247 * preserve the queue configurations so they can be restored if/when
248 * the firmware image is swapped.
250 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
252 /* async firmware loading state */
256 struct completion firmware_loading_complete;
259 #define MAX_WEP_KEY_LEN 13
260 #define NUM_WEP_KEYS 4
262 /* Per interface specific private data */
264 struct list_head list;
265 struct ieee80211_vif *vif;
267 /* Firmware macid for this vif. */
270 /* Non AMPDU sequence number assigned by driver. */
276 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
277 } wep_key_conf[NUM_WEP_KEYS];
282 /* A flag to indicate is HW crypto is enabled for this bssid */
283 bool is_hw_crypto_enabled;
285 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
286 #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
289 /* Index into station database. Returned by UPDATE_STADB. */
292 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
294 static const struct ieee80211_channel mwl8k_channels_24[] = {
295 { .center_freq = 2412, .hw_value = 1, },
296 { .center_freq = 2417, .hw_value = 2, },
297 { .center_freq = 2422, .hw_value = 3, },
298 { .center_freq = 2427, .hw_value = 4, },
299 { .center_freq = 2432, .hw_value = 5, },
300 { .center_freq = 2437, .hw_value = 6, },
301 { .center_freq = 2442, .hw_value = 7, },
302 { .center_freq = 2447, .hw_value = 8, },
303 { .center_freq = 2452, .hw_value = 9, },
304 { .center_freq = 2457, .hw_value = 10, },
305 { .center_freq = 2462, .hw_value = 11, },
306 { .center_freq = 2467, .hw_value = 12, },
307 { .center_freq = 2472, .hw_value = 13, },
308 { .center_freq = 2484, .hw_value = 14, },
311 static const struct ieee80211_rate mwl8k_rates_24[] = {
312 { .bitrate = 10, .hw_value = 2, },
313 { .bitrate = 20, .hw_value = 4, },
314 { .bitrate = 55, .hw_value = 11, },
315 { .bitrate = 110, .hw_value = 22, },
316 { .bitrate = 220, .hw_value = 44, },
317 { .bitrate = 60, .hw_value = 12, },
318 { .bitrate = 90, .hw_value = 18, },
319 { .bitrate = 120, .hw_value = 24, },
320 { .bitrate = 180, .hw_value = 36, },
321 { .bitrate = 240, .hw_value = 48, },
322 { .bitrate = 360, .hw_value = 72, },
323 { .bitrate = 480, .hw_value = 96, },
324 { .bitrate = 540, .hw_value = 108, },
325 { .bitrate = 720, .hw_value = 144, },
328 static const struct ieee80211_channel mwl8k_channels_50[] = {
329 { .center_freq = 5180, .hw_value = 36, },
330 { .center_freq = 5200, .hw_value = 40, },
331 { .center_freq = 5220, .hw_value = 44, },
332 { .center_freq = 5240, .hw_value = 48, },
335 static const struct ieee80211_rate mwl8k_rates_50[] = {
336 { .bitrate = 60, .hw_value = 12, },
337 { .bitrate = 90, .hw_value = 18, },
338 { .bitrate = 120, .hw_value = 24, },
339 { .bitrate = 180, .hw_value = 36, },
340 { .bitrate = 240, .hw_value = 48, },
341 { .bitrate = 360, .hw_value = 72, },
342 { .bitrate = 480, .hw_value = 96, },
343 { .bitrate = 540, .hw_value = 108, },
344 { .bitrate = 720, .hw_value = 144, },
347 /* Set or get info from Firmware */
348 #define MWL8K_CMD_GET 0x0000
349 #define MWL8K_CMD_SET 0x0001
350 #define MWL8K_CMD_SET_LIST 0x0002
352 /* Firmware command codes */
353 #define MWL8K_CMD_CODE_DNLD 0x0001
354 #define MWL8K_CMD_GET_HW_SPEC 0x0003
355 #define MWL8K_CMD_SET_HW_SPEC 0x0004
356 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
357 #define MWL8K_CMD_GET_STAT 0x0014
358 #define MWL8K_CMD_RADIO_CONTROL 0x001c
359 #define MWL8K_CMD_RF_TX_POWER 0x001e
360 #define MWL8K_CMD_TX_POWER 0x001f
361 #define MWL8K_CMD_RF_ANTENNA 0x0020
362 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
363 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
364 #define MWL8K_CMD_SET_POST_SCAN 0x0108
365 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
366 #define MWL8K_CMD_SET_AID 0x010d
367 #define MWL8K_CMD_SET_RATE 0x0110
368 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
369 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
370 #define MWL8K_CMD_SET_SLOT 0x0114
371 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
372 #define MWL8K_CMD_SET_WMM_MODE 0x0123
373 #define MWL8K_CMD_MIMO_CONFIG 0x0125
374 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
375 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
376 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
377 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
378 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
379 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
380 #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
381 #define MWL8K_CMD_UPDATE_STADB 0x1123
382 #define MWL8K_CMD_BASTREAM 0x1125
384 static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
386 u16 command = le16_to_cpu(cmd);
388 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
389 snprintf(buf, bufsize, "%s", #x);\
392 switch (command & ~0x8000) {
393 MWL8K_CMDNAME(CODE_DNLD);
394 MWL8K_CMDNAME(GET_HW_SPEC);
395 MWL8K_CMDNAME(SET_HW_SPEC);
396 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
397 MWL8K_CMDNAME(GET_STAT);
398 MWL8K_CMDNAME(RADIO_CONTROL);
399 MWL8K_CMDNAME(RF_TX_POWER);
400 MWL8K_CMDNAME(TX_POWER);
401 MWL8K_CMDNAME(RF_ANTENNA);
402 MWL8K_CMDNAME(SET_BEACON);
403 MWL8K_CMDNAME(SET_PRE_SCAN);
404 MWL8K_CMDNAME(SET_POST_SCAN);
405 MWL8K_CMDNAME(SET_RF_CHANNEL);
406 MWL8K_CMDNAME(SET_AID);
407 MWL8K_CMDNAME(SET_RATE);
408 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
409 MWL8K_CMDNAME(RTS_THRESHOLD);
410 MWL8K_CMDNAME(SET_SLOT);
411 MWL8K_CMDNAME(SET_EDCA_PARAMS);
412 MWL8K_CMDNAME(SET_WMM_MODE);
413 MWL8K_CMDNAME(MIMO_CONFIG);
414 MWL8K_CMDNAME(USE_FIXED_RATE);
415 MWL8K_CMDNAME(ENABLE_SNIFFER);
416 MWL8K_CMDNAME(SET_MAC_ADDR);
417 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
418 MWL8K_CMDNAME(BSS_START);
419 MWL8K_CMDNAME(SET_NEW_STN);
420 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
421 MWL8K_CMDNAME(UPDATE_STADB);
422 MWL8K_CMDNAME(BASTREAM);
424 snprintf(buf, bufsize, "0x%x", cmd);
431 /* Hardware and firmware reset */
432 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
434 iowrite32(MWL8K_H2A_INT_RESET,
435 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
436 iowrite32(MWL8K_H2A_INT_RESET,
437 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
441 /* Release fw image */
442 static void mwl8k_release_fw(const struct firmware **fw)
446 release_firmware(*fw);
450 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
452 mwl8k_release_fw(&priv->fw_ucode);
453 mwl8k_release_fw(&priv->fw_helper);
456 /* states for asynchronous f/w loading */
457 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
460 FW_STATE_LOADING_PREF,
461 FW_STATE_LOADING_ALT,
465 /* Request fw image */
466 static int mwl8k_request_fw(struct mwl8k_priv *priv,
467 const char *fname, const struct firmware **fw,
470 /* release current image */
472 mwl8k_release_fw(fw);
475 return request_firmware_nowait(THIS_MODULE, 1, fname,
476 &priv->pdev->dev, GFP_KERNEL,
477 priv, mwl8k_fw_state_machine);
479 return request_firmware(fw, fname, &priv->pdev->dev);
482 static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
485 struct mwl8k_device_info *di = priv->device_info;
488 if (di->helper_image != NULL) {
490 rc = mwl8k_request_fw(priv, di->helper_image,
491 &priv->fw_helper, true);
493 rc = mwl8k_request_fw(priv, di->helper_image,
494 &priv->fw_helper, false);
496 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
497 pci_name(priv->pdev), di->helper_image);
505 * if we get here, no helper image is needed. Skip the
506 * FW_STATE_INIT state.
508 priv->fw_state = FW_STATE_LOADING_PREF;
509 rc = mwl8k_request_fw(priv, fw_image,
513 rc = mwl8k_request_fw(priv, fw_image,
514 &priv->fw_ucode, false);
516 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
517 pci_name(priv->pdev), fw_image);
518 mwl8k_release_fw(&priv->fw_helper);
525 struct mwl8k_cmd_pkt {
538 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
540 void __iomem *regs = priv->regs;
544 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
545 if (pci_dma_mapping_error(priv->pdev, dma_addr))
548 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
549 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
550 iowrite32(MWL8K_H2A_INT_DOORBELL,
551 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
552 iowrite32(MWL8K_H2A_INT_DUMMY,
553 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
559 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
560 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
561 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
569 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
571 return loops ? 0 : -ETIMEDOUT;
574 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
575 const u8 *data, size_t length)
577 struct mwl8k_cmd_pkt *cmd;
581 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
585 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
592 int block_size = length > 256 ? 256 : length;
594 memcpy(cmd->payload, data + done, block_size);
595 cmd->length = cpu_to_le16(block_size);
597 rc = mwl8k_send_fw_load_cmd(priv, cmd,
598 sizeof(*cmd) + block_size);
603 length -= block_size;
608 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
616 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
617 const u8 *data, size_t length)
619 unsigned char *buffer;
620 int may_continue, rc = 0;
621 u32 done, prev_block_size;
623 buffer = kmalloc(1024, GFP_KERNEL);
630 while (may_continue > 0) {
633 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
634 if (block_size & 1) {
638 done += prev_block_size;
639 length -= prev_block_size;
642 if (block_size > 1024 || block_size > length) {
652 if (block_size == 0) {
659 prev_block_size = block_size;
660 memcpy(buffer, data + done, block_size);
662 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
667 if (!rc && length != 0)
675 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
677 struct mwl8k_priv *priv = hw->priv;
678 const struct firmware *fw = priv->fw_ucode;
682 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
683 const struct firmware *helper = priv->fw_helper;
685 if (helper == NULL) {
686 printk(KERN_ERR "%s: helper image needed but none "
687 "given\n", pci_name(priv->pdev));
691 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
693 printk(KERN_ERR "%s: unable to load firmware "
694 "helper image\n", pci_name(priv->pdev));
699 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
701 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
705 printk(KERN_ERR "%s: unable to load firmware image\n",
706 pci_name(priv->pdev));
710 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
716 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
717 if (ready_code == MWL8K_FWAP_READY) {
720 } else if (ready_code == MWL8K_FWSTA_READY) {
729 return loops ? 0 : -ETIMEDOUT;
733 /* DMA header used by firmware and hardware. */
734 struct mwl8k_dma_data {
736 struct ieee80211_hdr wh;
740 /* Routines to add/remove DMA header from skb. */
741 static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
743 struct mwl8k_dma_data *tr;
746 tr = (struct mwl8k_dma_data *)skb->data;
747 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
749 if (hdrlen != sizeof(tr->wh)) {
750 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
751 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
752 *((__le16 *)(tr->data - 2)) = qos;
754 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
758 if (hdrlen != sizeof(*tr))
759 skb_pull(skb, sizeof(*tr) - hdrlen);
763 mwl8k_add_dma_header(struct sk_buff *skb, int tail_pad)
765 struct ieee80211_hdr *wh;
768 struct mwl8k_dma_data *tr;
771 * Add a firmware DMA header; the firmware requires that we
772 * present a 2-byte payload length followed by a 4-address
773 * header (without QoS field), followed (optionally) by any
774 * WEP/ExtIV header (but only filled in for CCMP).
776 wh = (struct ieee80211_hdr *)skb->data;
778 hdrlen = ieee80211_hdrlen(wh->frame_control);
779 reqd_hdrlen = sizeof(*tr);
781 if (hdrlen != reqd_hdrlen)
782 skb_push(skb, reqd_hdrlen - hdrlen);
784 if (ieee80211_is_data_qos(wh->frame_control))
785 hdrlen -= IEEE80211_QOS_CTL_LEN;
787 tr = (struct mwl8k_dma_data *)skb->data;
789 memmove(&tr->wh, wh, hdrlen);
790 if (hdrlen != sizeof(tr->wh))
791 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
794 * Firmware length is the length of the fully formed "802.11
795 * payload". That is, everything except for the 802.11 header.
796 * This includes all crypto material including the MIC.
798 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
801 static void mwl8k_encapsulate_tx_frame(struct sk_buff *skb)
803 struct ieee80211_hdr *wh;
804 struct ieee80211_tx_info *tx_info;
805 struct ieee80211_key_conf *key_conf;
808 wh = (struct ieee80211_hdr *)skb->data;
810 tx_info = IEEE80211_SKB_CB(skb);
813 if (ieee80211_is_data(wh->frame_control))
814 key_conf = tx_info->control.hw_key;
817 * Make sure the packet header is in the DMA header format (4-address
818 * without QoS), the necessary crypto padding between the header and the
819 * payload has already been provided by mac80211, but it doesn't add tail
820 * padding when HW crypto is enabled.
822 * We have the following trailer padding requirements:
823 * - WEP: 4 trailer bytes (ICV)
824 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
825 * - CCMP: 8 trailer bytes (MIC)
828 if (key_conf != NULL) {
829 switch (key_conf->cipher) {
830 case WLAN_CIPHER_SUITE_WEP40:
831 case WLAN_CIPHER_SUITE_WEP104:
834 case WLAN_CIPHER_SUITE_TKIP:
837 case WLAN_CIPHER_SUITE_CCMP:
842 mwl8k_add_dma_header(skb, data_pad);
846 * Packet reception for 88w8366 AP firmware.
848 struct mwl8k_rxd_8366_ap {
852 __le32 pkt_phys_addr;
853 __le32 next_rxd_phys_addr;
857 __le32 hw_noise_floor_info;
866 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
867 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
868 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
870 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
872 /* 8366 AP rx_status bits */
873 #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
874 #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
875 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
876 #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
877 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
879 static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
881 struct mwl8k_rxd_8366_ap *rxd = _rxd;
883 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
884 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
887 static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
889 struct mwl8k_rxd_8366_ap *rxd = _rxd;
891 rxd->pkt_len = cpu_to_le16(len);
892 rxd->pkt_phys_addr = cpu_to_le32(addr);
898 mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
899 __le16 *qos, s8 *noise)
901 struct mwl8k_rxd_8366_ap *rxd = _rxd;
903 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
907 memset(status, 0, sizeof(*status));
909 status->signal = -rxd->rssi;
910 *noise = -rxd->noise_floor;
912 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
913 status->flag |= RX_FLAG_HT;
914 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
915 status->flag |= RX_FLAG_40MHZ;
916 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
920 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
921 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
922 status->rate_idx = i;
928 if (rxd->channel > 14) {
929 status->band = IEEE80211_BAND_5GHZ;
930 if (!(status->flag & RX_FLAG_HT))
931 status->rate_idx -= 5;
933 status->band = IEEE80211_BAND_2GHZ;
935 status->freq = ieee80211_channel_to_frequency(rxd->channel,
938 *qos = rxd->qos_control;
940 if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
941 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) &&
942 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
943 status->flag |= RX_FLAG_MMIC_ERROR;
945 return le16_to_cpu(rxd->pkt_len);
948 static struct rxd_ops rxd_8366_ap_ops = {
949 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
950 .rxd_init = mwl8k_rxd_8366_ap_init,
951 .rxd_refill = mwl8k_rxd_8366_ap_refill,
952 .rxd_process = mwl8k_rxd_8366_ap_process,
956 * Packet reception for STA firmware.
958 struct mwl8k_rxd_sta {
962 __le32 pkt_phys_addr;
963 __le32 next_rxd_phys_addr;
975 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
976 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
977 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
978 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
979 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
980 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
982 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
983 #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
985 #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
986 /* Key is uploaded only in failure case */
987 #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
989 static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
991 struct mwl8k_rxd_sta *rxd = _rxd;
993 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
994 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
997 static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
999 struct mwl8k_rxd_sta *rxd = _rxd;
1001 rxd->pkt_len = cpu_to_le16(len);
1002 rxd->pkt_phys_addr = cpu_to_le32(addr);
1008 mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
1009 __le16 *qos, s8 *noise)
1011 struct mwl8k_rxd_sta *rxd = _rxd;
1014 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
1018 rate_info = le16_to_cpu(rxd->rate_info);
1020 memset(status, 0, sizeof(*status));
1022 status->signal = -rxd->rssi;
1023 *noise = -rxd->noise_level;
1024 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
1025 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
1027 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
1028 status->flag |= RX_FLAG_SHORTPRE;
1029 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
1030 status->flag |= RX_FLAG_40MHZ;
1031 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
1032 status->flag |= RX_FLAG_SHORT_GI;
1033 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
1034 status->flag |= RX_FLAG_HT;
1036 if (rxd->channel > 14) {
1037 status->band = IEEE80211_BAND_5GHZ;
1038 if (!(status->flag & RX_FLAG_HT))
1039 status->rate_idx -= 5;
1041 status->band = IEEE80211_BAND_2GHZ;
1043 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1046 *qos = rxd->qos_control;
1047 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1048 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1049 status->flag |= RX_FLAG_MMIC_ERROR;
1051 return le16_to_cpu(rxd->pkt_len);
1054 static struct rxd_ops rxd_sta_ops = {
1055 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1056 .rxd_init = mwl8k_rxd_sta_init,
1057 .rxd_refill = mwl8k_rxd_sta_refill,
1058 .rxd_process = mwl8k_rxd_sta_process,
1062 #define MWL8K_RX_DESCS 256
1063 #define MWL8K_RX_MAXSZ 3800
1065 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1067 struct mwl8k_priv *priv = hw->priv;
1068 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1076 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
1078 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1079 if (rxq->rxd == NULL) {
1080 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
1083 memset(rxq->rxd, 0, size);
1085 rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
1086 if (rxq->buf == NULL) {
1087 wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
1088 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
1092 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1096 dma_addr_t next_dma_addr;
1098 desc_size = priv->rxd_ops->rxd_size;
1099 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
1102 if (nexti == MWL8K_RX_DESCS)
1104 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1106 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
1112 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1114 struct mwl8k_priv *priv = hw->priv;
1115 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1119 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
1120 struct sk_buff *skb;
1125 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1129 addr = pci_map_single(priv->pdev, skb->data,
1130 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
1134 if (rxq->tail == MWL8K_RX_DESCS)
1136 rxq->buf[rx].skb = skb;
1137 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
1139 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1140 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
1148 /* Must be called only when the card's reception is completely halted */
1149 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1151 struct mwl8k_priv *priv = hw->priv;
1152 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1155 if (rxq->rxd == NULL)
1158 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1159 if (rxq->buf[i].skb != NULL) {
1160 pci_unmap_single(priv->pdev,
1161 dma_unmap_addr(&rxq->buf[i], dma),
1162 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1163 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
1165 kfree_skb(rxq->buf[i].skb);
1166 rxq->buf[i].skb = NULL;
1173 pci_free_consistent(priv->pdev,
1174 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
1175 rxq->rxd, rxq->rxd_dma);
1181 * Scan a list of BSSIDs to process for finalize join.
1182 * Allows for extension to process multiple BSSIDs.
1185 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1187 return priv->capture_beacon &&
1188 ieee80211_is_beacon(wh->frame_control) &&
1189 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1192 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1193 struct sk_buff *skb)
1195 struct mwl8k_priv *priv = hw->priv;
1197 priv->capture_beacon = false;
1198 memset(priv->capture_bssid, 0, ETH_ALEN);
1201 * Use GFP_ATOMIC as rxq_process is called from
1202 * the primary interrupt handler, memory allocation call
1205 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1206 if (priv->beacon_skb != NULL)
1207 ieee80211_queue_work(hw, &priv->finalize_join_worker);
1210 static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1213 struct mwl8k_vif *mwl8k_vif;
1215 list_for_each_entry(mwl8k_vif,
1217 if (memcmp(bssid, mwl8k_vif->bssid,
1225 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1227 struct mwl8k_priv *priv = hw->priv;
1228 struct mwl8k_vif *mwl8k_vif = NULL;
1229 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1233 while (rxq->rxd_count && limit--) {
1234 struct sk_buff *skb;
1237 struct ieee80211_rx_status status;
1238 struct ieee80211_hdr *wh;
1241 skb = rxq->buf[rxq->head].skb;
1245 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1247 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1252 rxq->buf[rxq->head].skb = NULL;
1254 pci_unmap_single(priv->pdev,
1255 dma_unmap_addr(&rxq->buf[rxq->head], dma),
1256 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1257 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1260 if (rxq->head == MWL8K_RX_DESCS)
1265 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1268 * Check for a pending join operation. Save a
1269 * copy of the beacon and schedule a tasklet to
1270 * send a FINALIZE_JOIN command to the firmware.
1272 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1273 mwl8k_save_beacon(hw, skb);
1275 if (ieee80211_has_protected(wh->frame_control)) {
1277 /* Check if hw crypto has been enabled for
1278 * this bss. If yes, set the status flags
1281 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1284 if (mwl8k_vif != NULL &&
1285 mwl8k_vif->is_hw_crypto_enabled == true) {
1287 * When MMIC ERROR is encountered
1288 * by the firmware, payload is
1289 * dropped and only 32 bytes of
1290 * mwl8k Firmware header is sent
1293 * We need to add four bytes of
1294 * key information. In it
1295 * MAC80211 expects keyidx set to
1296 * 0 for triggering Counter
1297 * Measure of MMIC failure.
1299 if (status.flag & RX_FLAG_MMIC_ERROR) {
1300 struct mwl8k_dma_data *tr;
1301 tr = (struct mwl8k_dma_data *)skb->data;
1302 memset((void *)&(tr->data), 0, 4);
1306 if (!ieee80211_is_auth(wh->frame_control))
1307 status.flag |= RX_FLAG_IV_STRIPPED |
1309 RX_FLAG_MMIC_STRIPPED;
1313 skb_put(skb, pkt_len);
1314 mwl8k_remove_dma_header(skb, qos);
1315 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1316 ieee80211_rx_irqsafe(hw, skb);
1326 * Packet transmission.
1329 #define MWL8K_TXD_STATUS_OK 0x00000001
1330 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1331 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1332 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1333 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1335 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1336 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1337 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1338 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1339 #define MWL8K_QOS_EOSP 0x0010
1341 struct mwl8k_tx_desc {
1346 __le32 pkt_phys_addr;
1348 __u8 dest_MAC_addr[ETH_ALEN];
1349 __le32 next_txd_phys_addr;
1356 #define MWL8K_TX_DESCS 128
1358 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1360 struct mwl8k_priv *priv = hw->priv;
1361 struct mwl8k_tx_queue *txq = priv->txq + index;
1369 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1371 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1372 if (txq->txd == NULL) {
1373 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
1376 memset(txq->txd, 0, size);
1378 txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
1379 if (txq->skb == NULL) {
1380 wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
1381 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1385 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1386 struct mwl8k_tx_desc *tx_desc;
1389 tx_desc = txq->txd + i;
1390 nexti = (i + 1) % MWL8K_TX_DESCS;
1392 tx_desc->status = 0;
1393 tx_desc->next_txd_phys_addr =
1394 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1400 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1402 iowrite32(MWL8K_H2A_INT_PPA_READY,
1403 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1404 iowrite32(MWL8K_H2A_INT_DUMMY,
1405 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1406 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1409 static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1411 struct mwl8k_priv *priv = hw->priv;
1414 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
1415 struct mwl8k_tx_queue *txq = priv->txq + i;
1421 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1422 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1425 status = le32_to_cpu(tx_desc->status);
1426 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1431 if (tx_desc->pkt_len == 0)
1435 wiphy_err(hw->wiphy,
1436 "txq[%d] len=%d head=%d tail=%d "
1437 "fw_owned=%d drv_owned=%d unused=%d\n",
1439 txq->len, txq->head, txq->tail,
1440 fw_owned, drv_owned, unused);
1445 * Must be called with priv->fw_mutex held and tx queues stopped.
1447 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1449 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1451 struct mwl8k_priv *priv = hw->priv;
1452 DECLARE_COMPLETION_ONSTACK(tx_wait);
1459 * The TX queues are stopped at this point, so this test
1460 * doesn't need to take ->tx_lock.
1462 if (!priv->pending_tx_pkts)
1468 spin_lock_bh(&priv->tx_lock);
1469 priv->tx_wait = &tx_wait;
1472 unsigned long timeout;
1474 oldcount = priv->pending_tx_pkts;
1476 spin_unlock_bh(&priv->tx_lock);
1477 timeout = wait_for_completion_timeout(&tx_wait,
1478 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1479 spin_lock_bh(&priv->tx_lock);
1482 WARN_ON(priv->pending_tx_pkts);
1484 wiphy_notice(hw->wiphy, "tx rings drained\n");
1489 if (priv->pending_tx_pkts < oldcount) {
1490 wiphy_notice(hw->wiphy,
1491 "waiting for tx rings to drain (%d -> %d pkts)\n",
1492 oldcount, priv->pending_tx_pkts);
1497 priv->tx_wait = NULL;
1499 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1500 MWL8K_TX_WAIT_TIMEOUT_MS);
1501 mwl8k_dump_tx_rings(hw);
1505 spin_unlock_bh(&priv->tx_lock);
1510 #define MWL8K_TXD_SUCCESS(status) \
1511 ((status) & (MWL8K_TXD_STATUS_OK | \
1512 MWL8K_TXD_STATUS_OK_RETRY | \
1513 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1516 mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1518 struct mwl8k_priv *priv = hw->priv;
1519 struct mwl8k_tx_queue *txq = priv->txq + index;
1523 while (txq->len > 0 && limit--) {
1525 struct mwl8k_tx_desc *tx_desc;
1528 struct sk_buff *skb;
1529 struct ieee80211_tx_info *info;
1533 tx_desc = txq->txd + tx;
1535 status = le32_to_cpu(tx_desc->status);
1537 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1541 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1544 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1545 BUG_ON(txq->len == 0);
1547 priv->pending_tx_pkts--;
1549 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1550 size = le16_to_cpu(tx_desc->pkt_len);
1552 txq->skb[tx] = NULL;
1554 BUG_ON(skb == NULL);
1555 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1557 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
1559 /* Mark descriptor as unused */
1560 tx_desc->pkt_phys_addr = 0;
1561 tx_desc->pkt_len = 0;
1563 info = IEEE80211_SKB_CB(skb);
1564 ieee80211_tx_info_clear_status(info);
1566 /* Rate control is happening in the firmware.
1567 * Ensure no tx rate is being reported.
1569 info->status.rates[0].idx = -1;
1570 info->status.rates[0].count = 1;
1572 if (MWL8K_TXD_SUCCESS(status))
1573 info->flags |= IEEE80211_TX_STAT_ACK;
1575 ieee80211_tx_status_irqsafe(hw, skb);
1580 if (index < MWL8K_TX_WMM_QUEUES && processed && priv->radio_on &&
1581 !mutex_is_locked(&priv->fw_mutex))
1582 ieee80211_wake_queue(hw, index);
1587 /* must be called only when the card's transmit is completely halted */
1588 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1590 struct mwl8k_priv *priv = hw->priv;
1591 struct mwl8k_tx_queue *txq = priv->txq + index;
1593 if (txq->txd == NULL)
1596 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1601 pci_free_consistent(priv->pdev,
1602 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1603 txq->txd, txq->txd_dma);
1607 /* caller must hold priv->stream_lock when calling the stream functions */
1608 struct mwl8k_ampdu_stream *
1609 mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
1611 struct mwl8k_ampdu_stream *stream;
1612 struct mwl8k_priv *priv = hw->priv;
1615 for (i = 0; i < priv->num_ampdu_queues; i++) {
1616 stream = &priv->ampdu[i];
1617 if (stream->state == AMPDU_NO_STREAM) {
1619 stream->state = AMPDU_STREAM_NEW;
1622 stream->txq_idx = MWL8K_TX_WMM_QUEUES + i;
1623 wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
1632 mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1636 /* if the stream has already been started, don't start it again */
1637 if (stream->state != AMPDU_STREAM_NEW)
1639 ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
1641 wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
1642 "%d\n", stream->sta->addr, stream->tid, ret);
1644 wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
1645 stream->sta->addr, stream->tid);
1650 mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1652 wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
1654 memset(stream, 0, sizeof(*stream));
1657 static struct mwl8k_ampdu_stream *
1658 mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
1660 struct mwl8k_priv *priv = hw->priv;
1663 for (i = 0 ; i < priv->num_ampdu_queues; i++) {
1664 struct mwl8k_ampdu_stream *stream;
1665 stream = &priv->ampdu[i];
1666 if (stream->state == AMPDU_NO_STREAM)
1668 if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
1676 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1678 struct mwl8k_priv *priv = hw->priv;
1679 struct ieee80211_tx_info *tx_info;
1680 struct mwl8k_vif *mwl8k_vif;
1681 struct ieee80211_sta *sta;
1682 struct ieee80211_hdr *wh;
1683 struct mwl8k_tx_queue *txq;
1684 struct mwl8k_tx_desc *tx;
1691 struct mwl8k_ampdu_stream *stream = NULL;
1692 bool start_ba_session = false;
1694 wh = (struct ieee80211_hdr *)skb->data;
1695 if (ieee80211_is_data_qos(wh->frame_control))
1696 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1701 mwl8k_encapsulate_tx_frame(skb);
1703 mwl8k_add_dma_header(skb, 0);
1705 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1707 tx_info = IEEE80211_SKB_CB(skb);
1708 sta = tx_info->control.sta;
1709 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1711 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1712 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1713 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1714 mwl8k_vif->seqno += 0x10;
1717 /* Setup firmware control bit fields for each frame type. */
1720 if (ieee80211_is_mgmt(wh->frame_control) ||
1721 ieee80211_is_ctl(wh->frame_control)) {
1723 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1724 } else if (ieee80211_is_data(wh->frame_control)) {
1726 if (is_multicast_ether_addr(wh->addr1))
1727 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1729 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1730 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1731 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1733 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1738 if (ieee80211_is_data_qos(wh->frame_control) &&
1739 skb->protocol != cpu_to_be16(ETH_P_PAE) &&
1740 sta->ht_cap.ht_supported && priv->ap_fw) {
1742 spin_lock(&priv->stream_lock);
1743 stream = mwl8k_lookup_stream(hw, sta->addr, tid);
1744 if (stream != NULL) {
1745 if (stream->state == AMPDU_STREAM_ACTIVE) {
1746 txpriority = stream->txq_idx;
1747 index = stream->txq_idx;
1748 } else if (stream->state == AMPDU_STREAM_NEW) {
1749 /* We get here if the driver sends us packets
1750 * after we've initiated a stream, but before
1751 * our ampdu_action routine has been called
1752 * with IEEE80211_AMPDU_TX_START to get the SSN
1753 * for the ADDBA request. So this packet can
1754 * go out with no risk of sequence number
1755 * mismatch. No special handling is required.
1758 /* Drop packets that would go out after the
1759 * ADDBA request was sent but before the ADDBA
1760 * response is received. If we don't do this,
1761 * the recipient would probably receive it
1762 * after the ADDBA request with SSN 0. This
1763 * will cause the recipient's BA receive window
1764 * to shift, which would cause the subsequent
1765 * packets in the BA stream to be discarded.
1766 * mac80211 queues our packets for us in this
1767 * case, so this is really just a safety check.
1769 wiphy_warn(hw->wiphy,
1770 "Cannot send packet while ADDBA "
1771 "dialog is underway.\n");
1772 spin_unlock(&priv->stream_lock);
1777 /* Defer calling mwl8k_start_stream so that the current
1778 * skb can go out before the ADDBA request. This
1779 * prevents sequence number mismatch at the recepient
1780 * as described above.
1782 stream = mwl8k_add_stream(hw, sta, tid);
1784 start_ba_session = true;
1786 spin_unlock(&priv->stream_lock);
1789 dma = pci_map_single(priv->pdev, skb->data,
1790 skb->len, PCI_DMA_TODEVICE);
1792 if (pci_dma_mapping_error(priv->pdev, dma)) {
1793 wiphy_debug(hw->wiphy,
1794 "failed to dma map skb, dropping TX frame.\n");
1795 if (start_ba_session) {
1796 spin_lock(&priv->stream_lock);
1797 mwl8k_remove_stream(hw, stream);
1798 spin_unlock(&priv->stream_lock);
1804 spin_lock_bh(&priv->tx_lock);
1806 txq = priv->txq + index;
1808 if (index >= MWL8K_TX_WMM_QUEUES && txq->len >= MWL8K_TX_DESCS) {
1809 /* This is the case in which the tx packet is destined for an
1810 * AMPDU queue and that AMPDU queue is full. Because we don't
1811 * start and stop the AMPDU queues, we must drop these packets.
1814 spin_unlock_bh(&priv->tx_lock);
1818 BUG_ON(txq->skb[txq->tail] != NULL);
1819 txq->skb[txq->tail] = skb;
1821 tx = txq->txd + txq->tail;
1822 tx->data_rate = txdatarate;
1823 tx->tx_priority = txpriority;
1824 tx->qos_control = cpu_to_le16(qos);
1825 tx->pkt_phys_addr = cpu_to_le32(dma);
1826 tx->pkt_len = cpu_to_le16(skb->len);
1828 if (!priv->ap_fw && tx_info->control.sta != NULL)
1829 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1833 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1836 priv->pending_tx_pkts++;
1839 if (txq->tail == MWL8K_TX_DESCS)
1842 if (txq->head == txq->tail && index < MWL8K_TX_WMM_QUEUES)
1843 ieee80211_stop_queue(hw, index);
1845 mwl8k_tx_start(priv);
1847 spin_unlock_bh(&priv->tx_lock);
1849 /* Initiate the ampdu session here */
1850 if (start_ba_session) {
1851 spin_lock(&priv->stream_lock);
1852 if (mwl8k_start_stream(hw, stream))
1853 mwl8k_remove_stream(hw, stream);
1854 spin_unlock(&priv->stream_lock);
1862 * We have the following requirements for issuing firmware commands:
1863 * - Some commands require that the packet transmit path is idle when
1864 * the command is issued. (For simplicity, we'll just quiesce the
1865 * transmit path for every command.)
1866 * - There are certain sequences of commands that need to be issued to
1867 * the hardware sequentially, with no other intervening commands.
1869 * This leads to an implementation of a "firmware lock" as a mutex that
1870 * can be taken recursively, and which is taken by both the low-level
1871 * command submission function (mwl8k_post_cmd) as well as any users of
1872 * that function that require issuing of an atomic sequence of commands,
1873 * and quiesces the transmit path whenever it's taken.
1875 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1877 struct mwl8k_priv *priv = hw->priv;
1879 if (priv->fw_mutex_owner != current) {
1882 mutex_lock(&priv->fw_mutex);
1883 ieee80211_stop_queues(hw);
1885 rc = mwl8k_tx_wait_empty(hw);
1887 ieee80211_wake_queues(hw);
1888 mutex_unlock(&priv->fw_mutex);
1893 priv->fw_mutex_owner = current;
1896 priv->fw_mutex_depth++;
1901 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1903 struct mwl8k_priv *priv = hw->priv;
1905 if (!--priv->fw_mutex_depth) {
1906 ieee80211_wake_queues(hw);
1907 priv->fw_mutex_owner = NULL;
1908 mutex_unlock(&priv->fw_mutex);
1914 * Command processing.
1917 /* Timeout firmware commands after 10s */
1918 #define MWL8K_CMD_TIMEOUT_MS 10000
1920 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1922 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1923 struct mwl8k_priv *priv = hw->priv;
1924 void __iomem *regs = priv->regs;
1925 dma_addr_t dma_addr;
1926 unsigned int dma_size;
1928 unsigned long timeout = 0;
1931 cmd->result = (__force __le16) 0xffff;
1932 dma_size = le16_to_cpu(cmd->length);
1933 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1934 PCI_DMA_BIDIRECTIONAL);
1935 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1938 rc = mwl8k_fw_lock(hw);
1940 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1941 PCI_DMA_BIDIRECTIONAL);
1945 priv->hostcmd_wait = &cmd_wait;
1946 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1947 iowrite32(MWL8K_H2A_INT_DOORBELL,
1948 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1949 iowrite32(MWL8K_H2A_INT_DUMMY,
1950 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1952 timeout = wait_for_completion_timeout(&cmd_wait,
1953 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1955 priv->hostcmd_wait = NULL;
1957 mwl8k_fw_unlock(hw);
1959 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1960 PCI_DMA_BIDIRECTIONAL);
1963 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
1964 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1965 MWL8K_CMD_TIMEOUT_MS);
1970 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1972 rc = cmd->result ? -EINVAL : 0;
1974 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
1975 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1976 le16_to_cpu(cmd->result));
1978 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
1979 mwl8k_cmd_name(cmd->code,
1987 static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
1988 struct ieee80211_vif *vif,
1989 struct mwl8k_cmd_pkt *cmd)
1992 cmd->macid = MWL8K_VIF(vif)->macid;
1993 return mwl8k_post_cmd(hw, cmd);
1997 * Setup code shared between STA and AP firmware images.
1999 static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
2001 struct mwl8k_priv *priv = hw->priv;
2003 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
2004 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
2006 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
2007 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
2009 priv->band_24.band = IEEE80211_BAND_2GHZ;
2010 priv->band_24.channels = priv->channels_24;
2011 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
2012 priv->band_24.bitrates = priv->rates_24;
2013 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
2015 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
2018 static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
2020 struct mwl8k_priv *priv = hw->priv;
2022 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
2023 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
2025 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
2026 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
2028 priv->band_50.band = IEEE80211_BAND_5GHZ;
2029 priv->band_50.channels = priv->channels_50;
2030 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
2031 priv->band_50.bitrates = priv->rates_50;
2032 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
2034 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
2038 * CMD_GET_HW_SPEC (STA version).
2040 struct mwl8k_cmd_get_hw_spec_sta {
2041 struct mwl8k_cmd_pkt header;
2043 __u8 host_interface;
2045 __u8 perm_addr[ETH_ALEN];
2050 __u8 mcs_bitmap[16];
2051 __le32 rx_queue_ptr;
2052 __le32 num_tx_queues;
2053 __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
2055 __le32 num_tx_desc_per_queue;
2059 #define MWL8K_CAP_MAX_AMSDU 0x20000000
2060 #define MWL8K_CAP_GREENFIELD 0x08000000
2061 #define MWL8K_CAP_AMPDU 0x04000000
2062 #define MWL8K_CAP_RX_STBC 0x01000000
2063 #define MWL8K_CAP_TX_STBC 0x00800000
2064 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2065 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2066 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2067 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2068 #define MWL8K_CAP_DELAY_BA 0x00003000
2069 #define MWL8K_CAP_MIMO 0x00000200
2070 #define MWL8K_CAP_40MHZ 0x00000100
2071 #define MWL8K_CAP_BAND_MASK 0x00000007
2072 #define MWL8K_CAP_5GHZ 0x00000004
2073 #define MWL8K_CAP_2GHZ4 0x00000001
2076 mwl8k_set_ht_caps(struct ieee80211_hw *hw,
2077 struct ieee80211_supported_band *band, u32 cap)
2082 band->ht_cap.ht_supported = 1;
2084 if (cap & MWL8K_CAP_MAX_AMSDU)
2085 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
2086 if (cap & MWL8K_CAP_GREENFIELD)
2087 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
2088 if (cap & MWL8K_CAP_AMPDU) {
2089 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
2090 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2091 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2093 if (cap & MWL8K_CAP_RX_STBC)
2094 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
2095 if (cap & MWL8K_CAP_TX_STBC)
2096 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
2097 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
2098 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
2099 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
2100 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
2101 if (cap & MWL8K_CAP_DELAY_BA)
2102 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
2103 if (cap & MWL8K_CAP_40MHZ)
2104 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2106 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
2107 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
2109 band->ht_cap.mcs.rx_mask[0] = 0xff;
2110 if (rx_streams >= 2)
2111 band->ht_cap.mcs.rx_mask[1] = 0xff;
2112 if (rx_streams >= 3)
2113 band->ht_cap.mcs.rx_mask[2] = 0xff;
2114 band->ht_cap.mcs.rx_mask[4] = 0x01;
2115 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2117 if (rx_streams != tx_streams) {
2118 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
2119 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
2120 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2125 mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
2127 struct mwl8k_priv *priv = hw->priv;
2129 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
2130 mwl8k_setup_2ghz_band(hw);
2131 if (caps & MWL8K_CAP_MIMO)
2132 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
2135 if (caps & MWL8K_CAP_5GHZ) {
2136 mwl8k_setup_5ghz_band(hw);
2137 if (caps & MWL8K_CAP_MIMO)
2138 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
2142 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
2144 struct mwl8k_priv *priv = hw->priv;
2145 struct mwl8k_cmd_get_hw_spec_sta *cmd;
2149 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2153 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2154 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2156 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2157 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2158 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2159 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2160 for (i = 0; i < mwl8k_tx_queues(priv); i++)
2161 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
2162 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2163 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2165 rc = mwl8k_post_cmd(hw, &cmd->header);
2168 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2169 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2170 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2171 priv->hw_rev = cmd->hw_rev;
2172 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2173 priv->ap_macids_supported = 0x00000000;
2174 priv->sta_macids_supported = 0x00000001;
2182 * CMD_GET_HW_SPEC (AP version).
2184 struct mwl8k_cmd_get_hw_spec_ap {
2185 struct mwl8k_cmd_pkt header;
2187 __u8 host_interface;
2190 __u8 perm_addr[ETH_ALEN];
2201 __le32 fw_api_version;
2203 __le32 num_of_ampdu_queues;
2204 __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
2207 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2209 struct mwl8k_priv *priv = hw->priv;
2210 struct mwl8k_cmd_get_hw_spec_ap *cmd;
2214 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2218 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2219 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2221 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2222 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2224 rc = mwl8k_post_cmd(hw, &cmd->header);
2229 api_version = le32_to_cpu(cmd->fw_api_version);
2230 if (priv->device_info->fw_api_ap != api_version) {
2231 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2232 " Expected %d got %d.\n", MWL8K_NAME,
2233 priv->device_info->part_name,
2234 priv->device_info->fw_api_ap,
2239 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2240 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2241 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2242 priv->hw_rev = cmd->hw_rev;
2243 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2244 priv->ap_macids_supported = 0x000000ff;
2245 priv->sta_macids_supported = 0x00000000;
2246 priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
2247 if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
2248 wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
2249 " but we only support %d.\n",
2250 priv->num_ampdu_queues,
2251 MWL8K_MAX_AMPDU_QUEUES);
2252 priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
2254 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
2255 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2257 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
2258 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2260 priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
2261 priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
2262 priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
2263 priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
2265 for (i = 0; i < priv->num_ampdu_queues; i++)
2266 priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
2267 le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
2278 struct mwl8k_cmd_set_hw_spec {
2279 struct mwl8k_cmd_pkt header;
2281 __u8 host_interface;
2283 __u8 perm_addr[ETH_ALEN];
2288 __le32 rx_queue_ptr;
2289 __le32 num_tx_queues;
2290 __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
2292 __le32 num_tx_desc_per_queue;
2296 /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2297 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2298 * the packets that are queued for more than 500ms, will be dropped in the
2299 * hardware. This helps minimizing the issues caused due to head-of-line
2300 * blocking where a slow client can hog the bandwidth and affect traffic to a
2303 #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
2304 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2305 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2306 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
2308 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2310 struct mwl8k_priv *priv = hw->priv;
2311 struct mwl8k_cmd_set_hw_spec *cmd;
2315 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2319 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2320 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2322 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2323 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2324 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2327 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2328 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2329 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2330 * priority is interpreted the right way in firmware.
2332 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
2333 int j = mwl8k_tx_queues(priv) - 1 - i;
2334 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
2337 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2338 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
2339 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
2340 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2341 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2343 rc = mwl8k_post_cmd(hw, &cmd->header);
2350 * CMD_MAC_MULTICAST_ADR.
2352 struct mwl8k_cmd_mac_multicast_adr {
2353 struct mwl8k_cmd_pkt header;
2356 __u8 addr[0][ETH_ALEN];
2359 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
2360 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
2361 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2362 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
2364 static struct mwl8k_cmd_pkt *
2365 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
2366 struct netdev_hw_addr_list *mc_list)
2368 struct mwl8k_priv *priv = hw->priv;
2369 struct mwl8k_cmd_mac_multicast_adr *cmd;
2374 mc_count = netdev_hw_addr_list_count(mc_list);
2376 if (allmulti || mc_count > priv->num_mcaddrs) {
2381 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2383 cmd = kzalloc(size, GFP_ATOMIC);
2387 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2388 cmd->header.length = cpu_to_le16(size);
2389 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2390 MWL8K_ENABLE_RX_BROADCAST);
2393 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2394 } else if (mc_count) {
2395 struct netdev_hw_addr *ha;
2398 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2399 cmd->numaddr = cpu_to_le16(mc_count);
2400 netdev_hw_addr_list_for_each(ha, mc_list) {
2401 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
2405 return &cmd->header;
2411 struct mwl8k_cmd_get_stat {
2412 struct mwl8k_cmd_pkt header;
2416 #define MWL8K_STAT_ACK_FAILURE 9
2417 #define MWL8K_STAT_RTS_FAILURE 12
2418 #define MWL8K_STAT_FCS_ERROR 24
2419 #define MWL8K_STAT_RTS_SUCCESS 11
2421 static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2422 struct ieee80211_low_level_stats *stats)
2424 struct mwl8k_cmd_get_stat *cmd;
2427 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2431 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2432 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2434 rc = mwl8k_post_cmd(hw, &cmd->header);
2436 stats->dot11ACKFailureCount =
2437 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2438 stats->dot11RTSFailureCount =
2439 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2440 stats->dot11FCSErrorCount =
2441 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2442 stats->dot11RTSSuccessCount =
2443 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2451 * CMD_RADIO_CONTROL.
2453 struct mwl8k_cmd_radio_control {
2454 struct mwl8k_cmd_pkt header;
2461 mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
2463 struct mwl8k_priv *priv = hw->priv;
2464 struct mwl8k_cmd_radio_control *cmd;
2467 if (enable == priv->radio_on && !force)
2470 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2474 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2475 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2476 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2477 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
2478 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2480 rc = mwl8k_post_cmd(hw, &cmd->header);
2484 priv->radio_on = enable;
2489 static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
2491 return mwl8k_cmd_radio_control(hw, 0, 0);
2494 static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
2496 return mwl8k_cmd_radio_control(hw, 1, 0);
2500 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2502 struct mwl8k_priv *priv = hw->priv;
2504 priv->radio_short_preamble = short_preamble;
2506 return mwl8k_cmd_radio_control(hw, 1, 1);
2512 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2514 struct mwl8k_cmd_rf_tx_power {
2515 struct mwl8k_cmd_pkt header;
2517 __le16 support_level;
2518 __le16 current_level;
2520 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
2523 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
2525 struct mwl8k_cmd_rf_tx_power *cmd;
2528 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2532 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2533 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2534 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2535 cmd->support_level = cpu_to_le16(dBm);
2537 rc = mwl8k_post_cmd(hw, &cmd->header);
2546 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2548 struct mwl8k_cmd_tx_power {
2549 struct mwl8k_cmd_pkt header;
2555 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2556 } __attribute__((packed));
2558 static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2559 struct ieee80211_conf *conf,
2562 struct ieee80211_channel *channel = conf->channel;
2563 struct mwl8k_cmd_tx_power *cmd;
2567 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2571 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2572 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2573 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2575 if (channel->band == IEEE80211_BAND_2GHZ)
2576 cmd->band = cpu_to_le16(0x1);
2577 else if (channel->band == IEEE80211_BAND_5GHZ)
2578 cmd->band = cpu_to_le16(0x4);
2580 cmd->channel = channel->hw_value;
2582 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2583 conf->channel_type == NL80211_CHAN_HT20) {
2584 cmd->bw = cpu_to_le16(0x2);
2586 cmd->bw = cpu_to_le16(0x4);
2587 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2588 cmd->sub_ch = cpu_to_le16(0x3);
2589 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2590 cmd->sub_ch = cpu_to_le16(0x1);
2593 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2594 cmd->power_level_list[i] = cpu_to_le16(pwr);
2596 rc = mwl8k_post_cmd(hw, &cmd->header);
2605 struct mwl8k_cmd_rf_antenna {
2606 struct mwl8k_cmd_pkt header;
2611 #define MWL8K_RF_ANTENNA_RX 1
2612 #define MWL8K_RF_ANTENNA_TX 2
2615 mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2617 struct mwl8k_cmd_rf_antenna *cmd;
2620 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2624 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2625 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2626 cmd->antenna = cpu_to_le16(antenna);
2627 cmd->mode = cpu_to_le16(mask);
2629 rc = mwl8k_post_cmd(hw, &cmd->header);
2638 struct mwl8k_cmd_set_beacon {
2639 struct mwl8k_cmd_pkt header;
2644 static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2645 struct ieee80211_vif *vif, u8 *beacon, int len)
2647 struct mwl8k_cmd_set_beacon *cmd;
2650 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2654 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2655 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2656 cmd->beacon_len = cpu_to_le16(len);
2657 memcpy(cmd->beacon, beacon, len);
2659 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2668 struct mwl8k_cmd_set_pre_scan {
2669 struct mwl8k_cmd_pkt header;
2672 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2674 struct mwl8k_cmd_set_pre_scan *cmd;
2677 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2681 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2682 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2684 rc = mwl8k_post_cmd(hw, &cmd->header);
2691 * CMD_SET_POST_SCAN.
2693 struct mwl8k_cmd_set_post_scan {
2694 struct mwl8k_cmd_pkt header;
2696 __u8 bssid[ETH_ALEN];
2700 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2702 struct mwl8k_cmd_set_post_scan *cmd;
2705 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2709 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2710 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2712 memcpy(cmd->bssid, mac, ETH_ALEN);
2714 rc = mwl8k_post_cmd(hw, &cmd->header);
2721 * CMD_SET_RF_CHANNEL.
2723 struct mwl8k_cmd_set_rf_channel {
2724 struct mwl8k_cmd_pkt header;
2726 __u8 current_channel;
2727 __le32 channel_flags;
2730 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2731 struct ieee80211_conf *conf)
2733 struct ieee80211_channel *channel = conf->channel;
2734 struct mwl8k_cmd_set_rf_channel *cmd;
2737 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2741 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2742 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2743 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2744 cmd->current_channel = channel->hw_value;
2746 if (channel->band == IEEE80211_BAND_2GHZ)
2747 cmd->channel_flags |= cpu_to_le32(0x00000001);
2748 else if (channel->band == IEEE80211_BAND_5GHZ)
2749 cmd->channel_flags |= cpu_to_le32(0x00000004);
2751 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2752 conf->channel_type == NL80211_CHAN_HT20)
2753 cmd->channel_flags |= cpu_to_le32(0x00000080);
2754 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2755 cmd->channel_flags |= cpu_to_le32(0x000001900);
2756 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2757 cmd->channel_flags |= cpu_to_le32(0x000000900);
2759 rc = mwl8k_post_cmd(hw, &cmd->header);
2768 #define MWL8K_FRAME_PROT_DISABLED 0x00
2769 #define MWL8K_FRAME_PROT_11G 0x07
2770 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2771 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2773 struct mwl8k_cmd_update_set_aid {
2774 struct mwl8k_cmd_pkt header;
2777 /* AP's MAC address (BSSID) */
2778 __u8 bssid[ETH_ALEN];
2779 __le16 protection_mode;
2780 __u8 supp_rates[14];
2783 static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2789 * Clear nonstandard rates 4 and 13.
2793 for (i = 0, j = 0; i < 14; i++) {
2794 if (mask & (1 << i))
2795 rates[j++] = mwl8k_rates_24[i].hw_value;
2800 mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2801 struct ieee80211_vif *vif, u32 legacy_rate_mask)
2803 struct mwl8k_cmd_update_set_aid *cmd;
2807 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2811 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2812 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2813 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
2814 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
2816 if (vif->bss_conf.use_cts_prot) {
2817 prot_mode = MWL8K_FRAME_PROT_11G;
2819 switch (vif->bss_conf.ht_operation_mode &
2820 IEEE80211_HT_OP_MODE_PROTECTION) {
2821 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2822 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2824 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2825 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2828 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2832 cmd->protection_mode = cpu_to_le16(prot_mode);
2834 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
2836 rc = mwl8k_post_cmd(hw, &cmd->header);
2845 struct mwl8k_cmd_set_rate {
2846 struct mwl8k_cmd_pkt header;
2847 __u8 legacy_rates[14];
2849 /* Bitmap for supported MCS codes. */
2855 mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2856 u32 legacy_rate_mask, u8 *mcs_rates)
2858 struct mwl8k_cmd_set_rate *cmd;
2861 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2865 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2866 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2867 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
2868 memcpy(cmd->mcs_set, mcs_rates, 16);
2870 rc = mwl8k_post_cmd(hw, &cmd->header);
2877 * CMD_FINALIZE_JOIN.
2879 #define MWL8K_FJ_BEACON_MAXLEN 128
2881 struct mwl8k_cmd_finalize_join {
2882 struct mwl8k_cmd_pkt header;
2883 __le32 sleep_interval; /* Number of beacon periods to sleep */
2884 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2887 static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2888 int framelen, int dtim)
2890 struct mwl8k_cmd_finalize_join *cmd;
2891 struct ieee80211_mgmt *payload = frame;
2895 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2899 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2900 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2901 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2903 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2904 if (payload_len < 0)
2906 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2907 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2909 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2911 rc = mwl8k_post_cmd(hw, &cmd->header);
2918 * CMD_SET_RTS_THRESHOLD.
2920 struct mwl8k_cmd_set_rts_threshold {
2921 struct mwl8k_cmd_pkt header;
2927 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
2929 struct mwl8k_cmd_set_rts_threshold *cmd;
2932 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2936 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2937 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2938 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2939 cmd->threshold = cpu_to_le16(rts_thresh);
2941 rc = mwl8k_post_cmd(hw, &cmd->header);
2950 struct mwl8k_cmd_set_slot {
2951 struct mwl8k_cmd_pkt header;
2956 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
2958 struct mwl8k_cmd_set_slot *cmd;
2961 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2965 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2966 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2967 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2968 cmd->short_slot = short_slot_time;
2970 rc = mwl8k_post_cmd(hw, &cmd->header);
2977 * CMD_SET_EDCA_PARAMS.
2979 struct mwl8k_cmd_set_edca_params {
2980 struct mwl8k_cmd_pkt header;
2982 /* See MWL8K_SET_EDCA_XXX below */
2985 /* TX opportunity in units of 32 us */
2990 /* Log exponent of max contention period: 0...15 */
2993 /* Log exponent of min contention period: 0...15 */
2996 /* Adaptive interframe spacing in units of 32us */
2999 /* TX queue to configure */
3003 /* Log exponent of max contention period: 0...15 */
3006 /* Log exponent of min contention period: 0...15 */
3009 /* Adaptive interframe spacing in units of 32us */
3012 /* TX queue to configure */
3018 #define MWL8K_SET_EDCA_CW 0x01
3019 #define MWL8K_SET_EDCA_TXOP 0x02
3020 #define MWL8K_SET_EDCA_AIFS 0x04
3022 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3023 MWL8K_SET_EDCA_TXOP | \
3024 MWL8K_SET_EDCA_AIFS)
3027 mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
3028 __u16 cw_min, __u16 cw_max,
3029 __u8 aifs, __u16 txop)
3031 struct mwl8k_priv *priv = hw->priv;
3032 struct mwl8k_cmd_set_edca_params *cmd;
3035 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3039 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
3040 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3041 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
3042 cmd->txop = cpu_to_le16(txop);
3044 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
3045 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
3046 cmd->ap.aifs = aifs;
3049 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
3050 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
3051 cmd->sta.aifs = aifs;
3052 cmd->sta.txq = qnum;
3055 rc = mwl8k_post_cmd(hw, &cmd->header);
3064 struct mwl8k_cmd_set_wmm_mode {
3065 struct mwl8k_cmd_pkt header;
3069 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
3071 struct mwl8k_priv *priv = hw->priv;
3072 struct mwl8k_cmd_set_wmm_mode *cmd;
3075 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3079 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
3080 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3081 cmd->action = cpu_to_le16(!!enable);
3083 rc = mwl8k_post_cmd(hw, &cmd->header);
3087 priv->wmm_enabled = enable;
3095 struct mwl8k_cmd_mimo_config {
3096 struct mwl8k_cmd_pkt header;
3098 __u8 rx_antenna_map;
3099 __u8 tx_antenna_map;
3102 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
3104 struct mwl8k_cmd_mimo_config *cmd;
3107 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3111 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
3112 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3113 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
3114 cmd->rx_antenna_map = rx;
3115 cmd->tx_antenna_map = tx;
3117 rc = mwl8k_post_cmd(hw, &cmd->header);
3124 * CMD_USE_FIXED_RATE (STA version).
3126 struct mwl8k_cmd_use_fixed_rate_sta {
3127 struct mwl8k_cmd_pkt header;
3129 __le32 allow_rate_drop;
3133 __le32 enable_retry;
3142 #define MWL8K_USE_AUTO_RATE 0x0002
3143 #define MWL8K_UCAST_RATE 0
3145 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
3147 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
3150 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3154 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3155 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3156 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3157 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
3159 rc = mwl8k_post_cmd(hw, &cmd->header);
3166 * CMD_USE_FIXED_RATE (AP version).
3168 struct mwl8k_cmd_use_fixed_rate_ap {
3169 struct mwl8k_cmd_pkt header;
3171 __le32 allow_rate_drop;
3173 struct mwl8k_rate_entry_ap {
3175 __le32 enable_retry;
3180 u8 multicast_rate_type;
3185 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
3187 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
3190 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3194 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3195 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3196 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3197 cmd->multicast_rate = mcast;
3198 cmd->management_rate = mgmt;
3200 rc = mwl8k_post_cmd(hw, &cmd->header);
3207 * CMD_ENABLE_SNIFFER.
3209 struct mwl8k_cmd_enable_sniffer {
3210 struct mwl8k_cmd_pkt header;
3214 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3216 struct mwl8k_cmd_enable_sniffer *cmd;
3219 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3223 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3224 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3225 cmd->action = cpu_to_le32(!!enable);
3227 rc = mwl8k_post_cmd(hw, &cmd->header);
3236 struct mwl8k_cmd_set_mac_addr {
3237 struct mwl8k_cmd_pkt header;
3241 __u8 mac_addr[ETH_ALEN];
3243 __u8 mac_addr[ETH_ALEN];
3247 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3248 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3249 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
3250 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
3252 static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3253 struct ieee80211_vif *vif, u8 *mac)
3255 struct mwl8k_priv *priv = hw->priv;
3256 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3257 struct mwl8k_cmd_set_mac_addr *cmd;
3261 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3262 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3263 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
3264 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
3266 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3267 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3268 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3269 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3271 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3274 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3278 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3279 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3281 cmd->mbss.mac_type = cpu_to_le16(mac_type);
3282 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3284 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3287 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3294 * CMD_SET_RATEADAPT_MODE.
3296 struct mwl8k_cmd_set_rate_adapt_mode {
3297 struct mwl8k_cmd_pkt header;
3302 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3304 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
3307 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3311 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
3312 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3313 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3314 cmd->mode = cpu_to_le16(mode);
3316 rc = mwl8k_post_cmd(hw, &cmd->header);
3325 struct mwl8k_cmd_bss_start {
3326 struct mwl8k_cmd_pkt header;
3330 static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3331 struct ieee80211_vif *vif, int enable)
3333 struct mwl8k_cmd_bss_start *cmd;
3336 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3340 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3341 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3342 cmd->enable = cpu_to_le32(enable);
3344 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3355 * UPSTREAM is tx direction
3357 #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3358 #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3366 } ba_stream_action_type;
3369 struct mwl8k_create_ba_stream {
3374 u8 peer_mac_addr[6];
3380 u8 reset_seq_no_flag;
3382 u8 sta_src_mac_addr[6];
3385 struct mwl8k_destroy_ba_stream {
3390 struct mwl8k_cmd_bastream {
3391 struct mwl8k_cmd_pkt header;
3394 struct mwl8k_create_ba_stream create_params;
3395 struct mwl8k_destroy_ba_stream destroy_params;
3400 mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
3402 struct mwl8k_cmd_bastream *cmd;
3405 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3409 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3410 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3412 cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
3414 cmd->create_params.queue_id = stream->idx;
3415 memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
3417 cmd->create_params.tid = stream->tid;
3419 cmd->create_params.flags =
3420 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
3421 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
3423 rc = mwl8k_post_cmd(hw, &cmd->header);
3431 mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3434 struct mwl8k_cmd_bastream *cmd;
3437 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3442 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3443 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3445 cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
3447 cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
3448 cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
3449 cmd->create_params.queue_id = stream->idx;
3451 memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
3452 cmd->create_params.tid = stream->tid;
3453 cmd->create_params.curr_seq_no = cpu_to_le16(0);
3454 cmd->create_params.reset_seq_no_flag = 1;
3456 cmd->create_params.param_info =
3457 (stream->sta->ht_cap.ampdu_factor &
3458 IEEE80211_HT_AMPDU_PARM_FACTOR) |
3459 ((stream->sta->ht_cap.ampdu_density << 2) &
3460 IEEE80211_HT_AMPDU_PARM_DENSITY);
3462 cmd->create_params.flags =
3463 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
3464 BASTREAM_FLAG_DIRECTION_UPSTREAM);
3466 rc = mwl8k_post_cmd(hw, &cmd->header);
3468 wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
3469 stream->sta->addr, stream->tid);
3475 static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3476 struct mwl8k_ampdu_stream *stream)
3478 struct mwl8k_cmd_bastream *cmd;
3480 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3484 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3485 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3486 cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
3488 cmd->destroy_params.ba_context = cpu_to_le32(stream->idx);
3489 mwl8k_post_cmd(hw, &cmd->header);
3491 wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", stream->idx);
3499 struct mwl8k_cmd_set_new_stn {
3500 struct mwl8k_cmd_pkt header;
3506 __le32 legacy_rates;
3509 __le16 ht_capabilities_info;
3510 __u8 mac_ht_param_info;
3512 __u8 control_channel;
3521 #define MWL8K_STA_ACTION_ADD 0
3522 #define MWL8K_STA_ACTION_REMOVE 2
3524 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3525 struct ieee80211_vif *vif,
3526 struct ieee80211_sta *sta)
3528 struct mwl8k_cmd_set_new_stn *cmd;
3532 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3536 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3537 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3538 cmd->aid = cpu_to_le16(sta->aid);
3539 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3540 cmd->stn_id = cpu_to_le16(sta->aid);
3541 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
3542 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3543 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3545 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3546 cmd->legacy_rates = cpu_to_le32(rates);
3547 if (sta->ht_cap.ht_supported) {
3548 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3549 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3550 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3551 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3552 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3553 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3554 ((sta->ht_cap.ampdu_density & 7) << 2);
3555 cmd->is_qos_sta = 1;
3558 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3564 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3565 struct ieee80211_vif *vif)
3567 struct mwl8k_cmd_set_new_stn *cmd;
3570 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3574 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3575 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3576 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3578 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3584 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
3585 struct ieee80211_vif *vif, u8 *addr)
3587 struct mwl8k_cmd_set_new_stn *cmd;
3590 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3594 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3595 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3596 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3597 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
3599 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3606 * CMD_UPDATE_ENCRYPTION.
3609 #define MAX_ENCR_KEY_LENGTH 16
3610 #define MIC_KEY_LENGTH 8
3612 struct mwl8k_cmd_update_encryption {
3613 struct mwl8k_cmd_pkt header;
3620 } __attribute__((packed));
3622 struct mwl8k_cmd_set_key {
3623 struct mwl8k_cmd_pkt header;
3632 __u8 key_material[MAX_ENCR_KEY_LENGTH];
3633 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
3634 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
3635 __le16 tkip_rsc_low;
3636 __le32 tkip_rsc_high;
3637 __le16 tkip_tsc_low;
3638 __le32 tkip_tsc_high;
3640 } __attribute__((packed));
3645 MWL8K_ENCR_REMOVE_KEY,
3646 MWL8K_ENCR_SET_GROUP_KEY,
3649 #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
3650 #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
3651 #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
3652 #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
3653 #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
3661 #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
3662 #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
3663 #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
3664 #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
3665 #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
3667 static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
3668 struct ieee80211_vif *vif,
3672 struct mwl8k_cmd_update_encryption *cmd;
3675 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3679 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3680 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3681 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
3682 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3683 cmd->encr_type = encr_type;
3685 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3691 static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
3693 struct ieee80211_key_conf *key)
3695 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3696 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3697 cmd->length = cpu_to_le16(sizeof(*cmd) -
3698 offsetof(struct mwl8k_cmd_set_key, length));
3699 cmd->key_id = cpu_to_le32(key->keyidx);
3700 cmd->key_len = cpu_to_le16(key->keylen);
3701 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3703 switch (key->cipher) {
3704 case WLAN_CIPHER_SUITE_WEP40:
3705 case WLAN_CIPHER_SUITE_WEP104:
3706 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
3707 if (key->keyidx == 0)
3708 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
3711 case WLAN_CIPHER_SUITE_TKIP:
3712 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
3713 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3714 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
3715 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
3716 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
3717 | MWL8K_KEY_FLAG_TSC_VALID);
3719 case WLAN_CIPHER_SUITE_CCMP:
3720 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
3721 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3722 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
3723 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
3732 static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
3733 struct ieee80211_vif *vif,
3735 struct ieee80211_key_conf *key)
3737 struct mwl8k_cmd_set_key *cmd;
3742 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3744 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3748 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
3754 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3755 action = MWL8K_ENCR_SET_KEY;
3757 action = MWL8K_ENCR_SET_GROUP_KEY;
3759 switch (key->cipher) {
3760 case WLAN_CIPHER_SUITE_WEP40:
3761 case WLAN_CIPHER_SUITE_WEP104:
3762 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
3763 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
3764 sizeof(*key) + key->keylen);
3765 mwl8k_vif->wep_key_conf[idx].enabled = 1;
3769 action = MWL8K_ENCR_SET_KEY;
3771 case WLAN_CIPHER_SUITE_TKIP:
3772 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
3774 case WLAN_CIPHER_SUITE_CCMP:
3775 keymlen = key->keylen;
3782 memcpy(cmd->key_material, key->key, keymlen);
3783 cmd->action = cpu_to_le32(action);
3785 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3792 static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
3793 struct ieee80211_vif *vif,
3795 struct ieee80211_key_conf *key)
3797 struct mwl8k_cmd_set_key *cmd;
3799 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3801 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3805 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
3809 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3810 WLAN_CIPHER_SUITE_WEP104)
3811 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
3813 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
3815 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3822 static int mwl8k_set_key(struct ieee80211_hw *hw,
3823 enum set_key_cmd cmd_param,
3824 struct ieee80211_vif *vif,
3825 struct ieee80211_sta *sta,
3826 struct ieee80211_key_conf *key)
3831 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3833 if (vif->type == NL80211_IFTYPE_STATION)
3837 addr = hw->wiphy->perm_addr;
3841 if (cmd_param == SET_KEY) {
3842 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
3843 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
3847 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
3848 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
3849 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
3851 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
3853 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
3858 mwl8k_vif->is_hw_crypto_enabled = true;
3861 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
3866 mwl8k_vif->is_hw_crypto_enabled = false;
3876 struct ewc_ht_info {
3882 struct peer_capability_info {
3883 /* Peer type - AP vs. STA. */
3886 /* Basic 802.11 capabilities from assoc resp. */
3889 /* Set if peer supports 802.11n high throughput (HT). */
3892 /* Valid if HT is supported. */
3894 __u8 extended_ht_caps;
3895 struct ewc_ht_info ewc_info;
3897 /* Legacy rate table. Intersection of our rates and peer rates. */
3898 __u8 legacy_rates[12];
3900 /* HT rate table. Intersection of our rates and peer rates. */
3904 /* If set, interoperability mode, no proprietary extensions. */
3908 __le16 amsdu_enabled;
3911 struct mwl8k_cmd_update_stadb {
3912 struct mwl8k_cmd_pkt header;
3914 /* See STADB_ACTION_TYPE */
3917 /* Peer MAC address */
3918 __u8 peer_addr[ETH_ALEN];
3922 /* Peer info - valid during add/update. */
3923 struct peer_capability_info peer_info;
3926 #define MWL8K_STA_DB_MODIFY_ENTRY 1
3927 #define MWL8K_STA_DB_DEL_ENTRY 2
3929 /* Peer Entry flags - used to define the type of the peer node */
3930 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
3932 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
3933 struct ieee80211_vif *vif,
3934 struct ieee80211_sta *sta)
3936 struct mwl8k_cmd_update_stadb *cmd;
3937 struct peer_capability_info *p;
3941 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3945 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3946 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3947 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
3948 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
3950 p = &cmd->peer_info;
3951 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
3952 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
3953 p->ht_support = sta->ht_cap.ht_supported;
3954 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
3955 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
3956 ((sta->ht_cap.ampdu_density & 7) << 2);
3957 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3958 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3960 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3961 legacy_rate_mask_to_array(p->legacy_rates, rates);
3962 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
3964 p->amsdu_enabled = 0;
3966 rc = mwl8k_post_cmd(hw, &cmd->header);
3969 return rc ? rc : p->station_id;
3972 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
3973 struct ieee80211_vif *vif, u8 *addr)
3975 struct mwl8k_cmd_update_stadb *cmd;
3978 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3982 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3983 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3984 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
3985 memcpy(cmd->peer_addr, addr, ETH_ALEN);
3987 rc = mwl8k_post_cmd(hw, &cmd->header);
3995 * Interrupt handling.
3997 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
3999 struct ieee80211_hw *hw = dev_id;
4000 struct mwl8k_priv *priv = hw->priv;
4003 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4007 if (status & MWL8K_A2H_INT_TX_DONE) {
4008 status &= ~MWL8K_A2H_INT_TX_DONE;
4009 tasklet_schedule(&priv->poll_tx_task);
4012 if (status & MWL8K_A2H_INT_RX_READY) {
4013 status &= ~MWL8K_A2H_INT_RX_READY;
4014 tasklet_schedule(&priv->poll_rx_task);
4018 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4020 if (status & MWL8K_A2H_INT_OPC_DONE) {
4021 if (priv->hostcmd_wait != NULL)
4022 complete(priv->hostcmd_wait);
4025 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
4026 if (!mutex_is_locked(&priv->fw_mutex) &&
4027 priv->radio_on && priv->pending_tx_pkts)
4028 mwl8k_tx_start(priv);
4034 static void mwl8k_tx_poll(unsigned long data)
4036 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4037 struct mwl8k_priv *priv = hw->priv;
4043 spin_lock_bh(&priv->tx_lock);
4045 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4046 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
4048 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
4049 complete(priv->tx_wait);
4050 priv->tx_wait = NULL;
4053 spin_unlock_bh(&priv->tx_lock);
4056 writel(~MWL8K_A2H_INT_TX_DONE,
4057 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4059 tasklet_schedule(&priv->poll_tx_task);
4063 static void mwl8k_rx_poll(unsigned long data)
4065 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4066 struct mwl8k_priv *priv = hw->priv;
4070 limit -= rxq_process(hw, 0, limit);
4071 limit -= rxq_refill(hw, 0, limit);
4074 writel(~MWL8K_A2H_INT_RX_READY,
4075 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4077 tasklet_schedule(&priv->poll_rx_task);
4083 * Core driver operations.
4085 static void mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
4087 struct mwl8k_priv *priv = hw->priv;
4088 int index = skb_get_queue_mapping(skb);
4090 if (!priv->radio_on) {
4091 wiphy_debug(hw->wiphy,
4092 "dropped TX frame since radio disabled\n");
4097 mwl8k_txq_xmit(hw, index, skb);
4100 static int mwl8k_start(struct ieee80211_hw *hw)
4102 struct mwl8k_priv *priv = hw->priv;
4105 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
4106 IRQF_SHARED, MWL8K_NAME, hw);
4108 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
4112 /* Enable TX reclaim and RX tasklets. */
4113 tasklet_enable(&priv->poll_tx_task);
4114 tasklet_enable(&priv->poll_rx_task);
4116 /* Enable interrupts */
4117 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4119 rc = mwl8k_fw_lock(hw);
4121 rc = mwl8k_cmd_radio_enable(hw);
4125 rc = mwl8k_cmd_enable_sniffer(hw, 0);
4128 rc = mwl8k_cmd_set_pre_scan(hw);
4131 rc = mwl8k_cmd_set_post_scan(hw,
4132 "\x00\x00\x00\x00\x00\x00");
4136 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
4139 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
4141 mwl8k_fw_unlock(hw);
4145 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4146 free_irq(priv->pdev->irq, hw);
4147 tasklet_disable(&priv->poll_tx_task);
4148 tasklet_disable(&priv->poll_rx_task);
4154 static void mwl8k_stop(struct ieee80211_hw *hw)
4156 struct mwl8k_priv *priv = hw->priv;
4159 mwl8k_cmd_radio_disable(hw);
4161 ieee80211_stop_queues(hw);
4163 /* Disable interrupts */
4164 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4165 free_irq(priv->pdev->irq, hw);
4167 /* Stop finalize join worker */
4168 cancel_work_sync(&priv->finalize_join_worker);
4169 if (priv->beacon_skb != NULL)
4170 dev_kfree_skb(priv->beacon_skb);
4172 /* Stop TX reclaim and RX tasklets. */
4173 tasklet_disable(&priv->poll_tx_task);
4174 tasklet_disable(&priv->poll_rx_task);
4176 /* Return all skbs to mac80211 */
4177 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4178 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
4181 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
4183 static int mwl8k_add_interface(struct ieee80211_hw *hw,
4184 struct ieee80211_vif *vif)
4186 struct mwl8k_priv *priv = hw->priv;
4187 struct mwl8k_vif *mwl8k_vif;
4188 u32 macids_supported;
4190 struct mwl8k_device_info *di;
4193 * Reject interface creation if sniffer mode is active, as
4194 * STA operation is mutually exclusive with hardware sniffer
4195 * mode. (Sniffer mode is only used on STA firmware.)
4197 if (priv->sniffer_enabled) {
4198 wiphy_info(hw->wiphy,
4199 "unable to create STA interface because sniffer mode is enabled\n");
4203 di = priv->device_info;
4204 switch (vif->type) {
4205 case NL80211_IFTYPE_AP:
4206 if (!priv->ap_fw && di->fw_image_ap) {
4207 /* we must load the ap fw to meet this request */
4208 if (!list_empty(&priv->vif_list))
4210 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4214 macids_supported = priv->ap_macids_supported;
4216 case NL80211_IFTYPE_STATION:
4217 if (priv->ap_fw && di->fw_image_sta) {
4218 /* we must load the sta fw to meet this request */
4219 if (!list_empty(&priv->vif_list))
4221 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4225 macids_supported = priv->sta_macids_supported;
4231 macid = ffs(macids_supported & ~priv->macids_used);
4235 /* Setup driver private area. */
4236 mwl8k_vif = MWL8K_VIF(vif);
4237 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
4238 mwl8k_vif->vif = vif;
4239 mwl8k_vif->macid = macid;
4240 mwl8k_vif->seqno = 0;
4241 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
4242 mwl8k_vif->is_hw_crypto_enabled = false;
4244 /* Set the mac address. */
4245 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
4248 mwl8k_cmd_set_new_stn_add_self(hw, vif);
4250 priv->macids_used |= 1 << mwl8k_vif->macid;
4251 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
4256 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
4257 struct ieee80211_vif *vif)
4259 struct mwl8k_priv *priv = hw->priv;
4260 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4263 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
4265 mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
4267 priv->macids_used &= ~(1 << mwl8k_vif->macid);
4268 list_del(&mwl8k_vif->list);
4271 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
4273 struct ieee80211_conf *conf = &hw->conf;
4274 struct mwl8k_priv *priv = hw->priv;
4277 if (conf->flags & IEEE80211_CONF_IDLE) {
4278 mwl8k_cmd_radio_disable(hw);
4282 rc = mwl8k_fw_lock(hw);
4286 rc = mwl8k_cmd_radio_enable(hw);
4290 rc = mwl8k_cmd_set_rf_channel(hw, conf);
4294 if (conf->power_level > 18)
4295 conf->power_level = 18;
4298 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
4302 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
4304 wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
4305 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
4307 wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
4310 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
4313 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
4317 mwl8k_fw_unlock(hw);
4323 mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4324 struct ieee80211_bss_conf *info, u32 changed)
4326 struct mwl8k_priv *priv = hw->priv;
4327 u32 ap_legacy_rates;
4328 u8 ap_mcs_rates[16];
4331 if (mwl8k_fw_lock(hw))
4335 * No need to capture a beacon if we're no longer associated.
4337 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
4338 priv->capture_beacon = false;
4341 * Get the AP's legacy and MCS rates.
4343 if (vif->bss_conf.assoc) {
4344 struct ieee80211_sta *ap;
4348 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
4354 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
4355 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
4358 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4360 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
4365 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
4366 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
4370 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
4375 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4376 rc = mwl8k_set_radio_preamble(hw,
4377 vif->bss_conf.use_short_preamble);
4382 if (changed & BSS_CHANGED_ERP_SLOT) {
4383 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
4388 if (vif->bss_conf.assoc &&
4389 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4391 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
4396 if (vif->bss_conf.assoc &&
4397 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
4399 * Finalize the join. Tell rx handler to process
4400 * next beacon from our BSSID.
4402 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
4403 priv->capture_beacon = true;
4407 mwl8k_fw_unlock(hw);
4411 mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4412 struct ieee80211_bss_conf *info, u32 changed)
4416 if (mwl8k_fw_lock(hw))
4419 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4420 rc = mwl8k_set_radio_preamble(hw,
4421 vif->bss_conf.use_short_preamble);
4426 if (changed & BSS_CHANGED_BASIC_RATES) {
4431 * Use lowest supported basic rate for multicasts
4432 * and management frames (such as probe responses --
4433 * beacons will always go out at 1 Mb/s).
4435 idx = ffs(vif->bss_conf.basic_rates);
4439 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4440 rate = mwl8k_rates_24[idx].hw_value;
4442 rate = mwl8k_rates_50[idx].hw_value;
4444 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4447 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
4448 struct sk_buff *skb;
4450 skb = ieee80211_beacon_get(hw, vif);
4452 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
4457 if (changed & BSS_CHANGED_BEACON_ENABLED)
4458 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
4461 mwl8k_fw_unlock(hw);
4465 mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4466 struct ieee80211_bss_conf *info, u32 changed)
4468 struct mwl8k_priv *priv = hw->priv;
4471 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
4473 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
4476 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
4477 struct netdev_hw_addr_list *mc_list)
4479 struct mwl8k_cmd_pkt *cmd;
4482 * Synthesize and return a command packet that programs the
4483 * hardware multicast address filter. At this point we don't
4484 * know whether FIF_ALLMULTI is being requested, but if it is,
4485 * we'll end up throwing this packet away and creating a new
4486 * one in mwl8k_configure_filter().
4488 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
4490 return (unsigned long)cmd;
4494 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
4495 unsigned int changed_flags,
4496 unsigned int *total_flags)
4498 struct mwl8k_priv *priv = hw->priv;
4501 * Hardware sniffer mode is mutually exclusive with STA
4502 * operation, so refuse to enable sniffer mode if a STA
4503 * interface is active.
4505 if (!list_empty(&priv->vif_list)) {
4506 if (net_ratelimit())
4507 wiphy_info(hw->wiphy,
4508 "not enabling sniffer mode because STA interface is active\n");
4512 if (!priv->sniffer_enabled) {
4513 if (mwl8k_cmd_enable_sniffer(hw, 1))
4515 priv->sniffer_enabled = true;
4518 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
4519 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
4525 static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
4527 if (!list_empty(&priv->vif_list))
4528 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
4533 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
4534 unsigned int changed_flags,
4535 unsigned int *total_flags,
4538 struct mwl8k_priv *priv = hw->priv;
4539 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
4542 * AP firmware doesn't allow fine-grained control over
4543 * the receive filter.
4546 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4552 * Enable hardware sniffer mode if FIF_CONTROL or
4553 * FIF_OTHER_BSS is requested.
4555 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
4556 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
4561 /* Clear unsupported feature flags */
4562 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4564 if (mwl8k_fw_lock(hw)) {
4569 if (priv->sniffer_enabled) {
4570 mwl8k_cmd_enable_sniffer(hw, 0);
4571 priv->sniffer_enabled = false;
4574 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
4575 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
4577 * Disable the BSS filter.
4579 mwl8k_cmd_set_pre_scan(hw);
4581 struct mwl8k_vif *mwl8k_vif;
4585 * Enable the BSS filter.
4587 * If there is an active STA interface, use that
4588 * interface's BSSID, otherwise use a dummy one
4589 * (where the OUI part needs to be nonzero for
4590 * the BSSID to be accepted by POST_SCAN).
4592 mwl8k_vif = mwl8k_first_vif(priv);
4593 if (mwl8k_vif != NULL)
4594 bssid = mwl8k_vif->vif->bss_conf.bssid;
4596 bssid = "\x01\x00\x00\x00\x00\x00";
4598 mwl8k_cmd_set_post_scan(hw, bssid);
4603 * If FIF_ALLMULTI is being requested, throw away the command
4604 * packet that ->prepare_multicast() built and replace it with
4605 * a command packet that enables reception of all multicast
4608 if (*total_flags & FIF_ALLMULTI) {
4610 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
4614 mwl8k_post_cmd(hw, cmd);
4618 mwl8k_fw_unlock(hw);
4621 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4623 return mwl8k_cmd_set_rts_threshold(hw, value);
4626 static int mwl8k_sta_remove(struct ieee80211_hw *hw,
4627 struct ieee80211_vif *vif,
4628 struct ieee80211_sta *sta)
4630 struct mwl8k_priv *priv = hw->priv;
4633 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
4635 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
4638 static int mwl8k_sta_add(struct ieee80211_hw *hw,
4639 struct ieee80211_vif *vif,
4640 struct ieee80211_sta *sta)
4642 struct mwl8k_priv *priv = hw->priv;
4645 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4646 struct ieee80211_key_conf *key;
4649 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
4651 MWL8K_STA(sta)->peer_id = ret;
4656 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
4659 for (i = 0; i < NUM_WEP_KEYS; i++) {
4660 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
4661 if (mwl8k_vif->wep_key_conf[i].enabled)
4662 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
4667 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
4668 const struct ieee80211_tx_queue_params *params)
4670 struct mwl8k_priv *priv = hw->priv;
4673 rc = mwl8k_fw_lock(hw);
4675 BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
4676 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
4678 if (!priv->wmm_enabled)
4679 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
4682 int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
4683 rc = mwl8k_cmd_set_edca_params(hw, q,
4690 mwl8k_fw_unlock(hw);
4696 static int mwl8k_get_stats(struct ieee80211_hw *hw,
4697 struct ieee80211_low_level_stats *stats)
4699 return mwl8k_cmd_get_stat(hw, stats);
4702 static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
4703 struct survey_info *survey)
4705 struct mwl8k_priv *priv = hw->priv;
4706 struct ieee80211_conf *conf = &hw->conf;
4711 survey->channel = conf->channel;
4712 survey->filled = SURVEY_INFO_NOISE_DBM;
4713 survey->noise = priv->noise;
4718 #define MAX_AMPDU_ATTEMPTS 5
4721 mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4722 enum ieee80211_ampdu_mlme_action action,
4723 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4728 struct mwl8k_priv *priv = hw->priv;
4729 struct mwl8k_ampdu_stream *stream;
4730 u8 *addr = sta->addr;
4732 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
4735 spin_lock(&priv->stream_lock);
4736 stream = mwl8k_lookup_stream(hw, addr, tid);
4739 case IEEE80211_AMPDU_RX_START:
4740 case IEEE80211_AMPDU_RX_STOP:
4742 case IEEE80211_AMPDU_TX_START:
4743 /* By the time we get here the hw queues may contain outgoing
4744 * packets for this RA/TID that are not part of this BA
4745 * session. The hw will assign sequence numbers to these
4746 * packets as they go out. So if we query the hw for its next
4747 * sequence number and use that for the SSN here, it may end up
4748 * being wrong, which will lead to sequence number mismatch at
4749 * the recipient. To avoid this, we reset the sequence number
4750 * to O for the first MPDU in this BA stream.
4753 if (stream == NULL) {
4754 /* This means that somebody outside this driver called
4755 * ieee80211_start_tx_ba_session. This is unexpected
4756 * because we do our own rate control. Just warn and
4759 wiphy_warn(hw->wiphy, "Unexpected call to %s. "
4760 "Proceeding anyway.\n", __func__);
4761 stream = mwl8k_add_stream(hw, sta, tid);
4763 if (stream == NULL) {
4764 wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
4768 stream->state = AMPDU_STREAM_IN_PROGRESS;
4770 /* Release the lock before we do the time consuming stuff */
4771 spin_unlock(&priv->stream_lock);
4772 for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
4773 rc = mwl8k_check_ba(hw, stream);
4778 * HW queues take time to be flushed, give them
4784 spin_lock(&priv->stream_lock);
4786 wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
4787 " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
4788 mwl8k_remove_stream(hw, stream);
4792 ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
4794 case IEEE80211_AMPDU_TX_STOP:
4797 if (stream->state == AMPDU_STREAM_ACTIVE) {
4798 spin_unlock(&priv->stream_lock);
4799 mwl8k_destroy_ba(hw, stream);
4800 spin_lock(&priv->stream_lock);
4802 mwl8k_remove_stream(hw, stream);
4803 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
4805 case IEEE80211_AMPDU_TX_OPERATIONAL:
4806 BUG_ON(stream == NULL);
4807 BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
4808 spin_unlock(&priv->stream_lock);
4809 rc = mwl8k_create_ba(hw, stream, buf_size);
4810 spin_lock(&priv->stream_lock);
4812 stream->state = AMPDU_STREAM_ACTIVE;
4814 spin_unlock(&priv->stream_lock);
4815 mwl8k_destroy_ba(hw, stream);
4816 spin_lock(&priv->stream_lock);
4817 wiphy_debug(hw->wiphy,
4818 "Failed adding stream for sta %pM tid %d\n",
4820 mwl8k_remove_stream(hw, stream);
4828 spin_unlock(&priv->stream_lock);
4832 static const struct ieee80211_ops mwl8k_ops = {
4834 .start = mwl8k_start,
4836 .add_interface = mwl8k_add_interface,
4837 .remove_interface = mwl8k_remove_interface,
4838 .config = mwl8k_config,
4839 .bss_info_changed = mwl8k_bss_info_changed,
4840 .prepare_multicast = mwl8k_prepare_multicast,
4841 .configure_filter = mwl8k_configure_filter,
4842 .set_key = mwl8k_set_key,
4843 .set_rts_threshold = mwl8k_set_rts_threshold,
4844 .sta_add = mwl8k_sta_add,
4845 .sta_remove = mwl8k_sta_remove,
4846 .conf_tx = mwl8k_conf_tx,
4847 .get_stats = mwl8k_get_stats,
4848 .get_survey = mwl8k_get_survey,
4849 .ampdu_action = mwl8k_ampdu_action,
4852 static void mwl8k_finalize_join_worker(struct work_struct *work)
4854 struct mwl8k_priv *priv =
4855 container_of(work, struct mwl8k_priv, finalize_join_worker);
4856 struct sk_buff *skb = priv->beacon_skb;
4857 struct ieee80211_mgmt *mgmt = (void *)skb->data;
4858 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
4859 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
4860 mgmt->u.beacon.variable, len);
4861 int dtim_period = 1;
4863 if (tim && tim[1] >= 2)
4864 dtim_period = tim[3];
4866 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
4869 priv->beacon_skb = NULL;
4878 #define MWL8K_8366_AP_FW_API 2
4879 #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
4880 #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
4882 static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
4884 .part_name = "88w8363",
4885 .helper_image = "mwl8k/helper_8363.fw",
4886 .fw_image_sta = "mwl8k/fmimage_8363.fw",
4889 .part_name = "88w8687",
4890 .helper_image = "mwl8k/helper_8687.fw",
4891 .fw_image_sta = "mwl8k/fmimage_8687.fw",
4894 .part_name = "88w8366",
4895 .helper_image = "mwl8k/helper_8366.fw",
4896 .fw_image_sta = "mwl8k/fmimage_8366.fw",
4897 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
4898 .fw_api_ap = MWL8K_8366_AP_FW_API,
4899 .ap_rxd_ops = &rxd_8366_ap_ops,
4903 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
4904 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
4905 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
4906 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
4907 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
4908 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
4909 MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
4911 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
4912 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
4913 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
4914 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
4915 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
4916 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
4917 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
4918 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
4921 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
4923 static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
4926 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
4927 "Trying alternative firmware %s\n", pci_name(priv->pdev),
4928 priv->fw_pref, priv->fw_alt);
4929 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
4931 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
4932 pci_name(priv->pdev), priv->fw_alt);
4938 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
4939 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
4941 struct mwl8k_priv *priv = context;
4942 struct mwl8k_device_info *di = priv->device_info;
4945 switch (priv->fw_state) {
4948 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
4949 pci_name(priv->pdev), di->helper_image);
4952 priv->fw_helper = fw;
4953 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
4955 if (rc && priv->fw_alt) {
4956 rc = mwl8k_request_alt_fw(priv);
4959 priv->fw_state = FW_STATE_LOADING_ALT;
4963 priv->fw_state = FW_STATE_LOADING_PREF;
4966 case FW_STATE_LOADING_PREF:
4969 rc = mwl8k_request_alt_fw(priv);
4972 priv->fw_state = FW_STATE_LOADING_ALT;
4976 priv->fw_ucode = fw;
4977 rc = mwl8k_firmware_load_success(priv);
4981 complete(&priv->firmware_loading_complete);
4985 case FW_STATE_LOADING_ALT:
4987 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
4988 pci_name(priv->pdev), di->helper_image);
4991 priv->fw_ucode = fw;
4992 rc = mwl8k_firmware_load_success(priv);
4996 complete(&priv->firmware_loading_complete);
5000 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
5001 MWL8K_NAME, priv->fw_state);
5008 priv->fw_state = FW_STATE_ERROR;
5009 complete(&priv->firmware_loading_complete);
5010 device_release_driver(&priv->pdev->dev);
5011 mwl8k_release_firmware(priv);
5014 static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
5017 struct mwl8k_priv *priv = hw->priv;
5020 /* Reset firmware and hardware */
5021 mwl8k_hw_reset(priv);
5023 /* Ask userland hotplug daemon for the device firmware */
5024 rc = mwl8k_request_firmware(priv, fw_image, nowait);
5026 wiphy_err(hw->wiphy, "Firmware files not found\n");
5033 /* Load firmware into hardware */
5034 rc = mwl8k_load_firmware(hw);
5036 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5038 /* Reclaim memory once firmware is successfully loaded */
5039 mwl8k_release_firmware(priv);
5044 static int mwl8k_init_txqs(struct ieee80211_hw *hw)
5046 struct mwl8k_priv *priv = hw->priv;
5050 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
5051 rc = mwl8k_txq_init(hw, i);
5055 iowrite32(priv->txq[i].txd_dma,
5056 priv->sram + priv->txq_offset[i]);
5061 /* initialize hw after successfully loading a firmware image */
5062 static int mwl8k_probe_hw(struct ieee80211_hw *hw)
5064 struct mwl8k_priv *priv = hw->priv;
5069 priv->rxd_ops = priv->device_info->ap_rxd_ops;
5070 if (priv->rxd_ops == NULL) {
5071 wiphy_err(hw->wiphy,
5072 "Driver does not have AP firmware image support for this hardware\n");
5073 goto err_stop_firmware;
5076 priv->rxd_ops = &rxd_sta_ops;
5079 priv->sniffer_enabled = false;
5080 priv->wmm_enabled = false;
5081 priv->pending_tx_pkts = 0;
5083 rc = mwl8k_rxq_init(hw, 0);
5085 goto err_stop_firmware;
5086 rxq_refill(hw, 0, INT_MAX);
5088 /* For the sta firmware, we need to know the dma addresses of tx queues
5089 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5090 * prior to issuing this command. But for the AP case, we learn the
5091 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5092 * case we must initialize the tx queues after.
5094 priv->num_ampdu_queues = 0;
5096 rc = mwl8k_init_txqs(hw);
5098 goto err_free_queues;
5101 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
5102 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5103 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
5104 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
5105 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
5107 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
5108 IRQF_SHARED, MWL8K_NAME, hw);
5110 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
5111 goto err_free_queues;
5114 memset(priv->ampdu, 0, sizeof(priv->ampdu));
5117 * Temporarily enable interrupts. Initial firmware host
5118 * commands use interrupts and avoid polling. Disable
5119 * interrupts when done.
5121 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5123 /* Get config data, mac addrs etc */
5125 rc = mwl8k_cmd_get_hw_spec_ap(hw);
5127 rc = mwl8k_init_txqs(hw);
5129 rc = mwl8k_cmd_set_hw_spec(hw);
5131 rc = mwl8k_cmd_get_hw_spec_sta(hw);
5134 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
5138 /* Turn radio off */
5139 rc = mwl8k_cmd_radio_disable(hw);
5141 wiphy_err(hw->wiphy, "Cannot disable\n");
5145 /* Clear MAC address */
5146 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
5148 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
5152 /* Disable interrupts */
5153 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5154 free_irq(priv->pdev->irq, hw);
5156 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5157 priv->device_info->part_name,
5158 priv->hw_rev, hw->wiphy->perm_addr,
5159 priv->ap_fw ? "AP" : "STA",
5160 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
5161 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
5166 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5167 free_irq(priv->pdev->irq, hw);
5170 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5171 mwl8k_txq_deinit(hw, i);
5172 mwl8k_rxq_deinit(hw, 0);
5175 mwl8k_hw_reset(priv);
5181 * invoke mwl8k_reload_firmware to change the firmware image after the device
5182 * has already been registered
5184 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
5187 struct mwl8k_priv *priv = hw->priv;
5190 mwl8k_rxq_deinit(hw, 0);
5192 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5193 mwl8k_txq_deinit(hw, i);
5195 rc = mwl8k_init_firmware(hw, fw_image, false);
5199 rc = mwl8k_probe_hw(hw);
5203 rc = mwl8k_start(hw);
5207 rc = mwl8k_config(hw, ~0);
5211 for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
5212 rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
5220 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
5224 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
5226 struct ieee80211_hw *hw = priv->hw;
5229 rc = mwl8k_load_firmware(hw);
5230 mwl8k_release_firmware(priv);
5232 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5237 * Extra headroom is the size of the required DMA header
5238 * minus the size of the smallest 802.11 frame (CTS frame).
5240 hw->extra_tx_headroom =
5241 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
5243 hw->channel_change_time = 10;
5245 hw->queues = MWL8K_TX_WMM_QUEUES;
5247 /* Set rssi values to dBm */
5248 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
5249 hw->vif_data_size = sizeof(struct mwl8k_vif);
5250 hw->sta_data_size = sizeof(struct mwl8k_sta);
5252 priv->macids_used = 0;
5253 INIT_LIST_HEAD(&priv->vif_list);
5255 /* Set default radio state and preamble */
5257 priv->radio_short_preamble = 0;
5259 /* Finalize join worker */
5260 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
5262 /* TX reclaim and RX tasklets. */
5263 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
5264 tasklet_disable(&priv->poll_tx_task);
5265 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
5266 tasklet_disable(&priv->poll_rx_task);
5268 /* Power management cookie */
5269 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
5270 if (priv->cookie == NULL)
5273 mutex_init(&priv->fw_mutex);
5274 priv->fw_mutex_owner = NULL;
5275 priv->fw_mutex_depth = 0;
5276 priv->hostcmd_wait = NULL;
5278 spin_lock_init(&priv->tx_lock);
5280 spin_lock_init(&priv->stream_lock);
5282 priv->tx_wait = NULL;
5284 rc = mwl8k_probe_hw(hw);
5286 goto err_free_cookie;
5288 hw->wiphy->interface_modes = 0;
5289 if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
5290 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
5291 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
5292 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
5294 rc = ieee80211_register_hw(hw);
5296 wiphy_err(hw->wiphy, "Cannot register device\n");
5297 goto err_unprobe_hw;
5303 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5304 mwl8k_txq_deinit(hw, i);
5305 mwl8k_rxq_deinit(hw, 0);
5308 if (priv->cookie != NULL)
5309 pci_free_consistent(priv->pdev, 4,
5310 priv->cookie, priv->cookie_dma);
5314 static int __devinit mwl8k_probe(struct pci_dev *pdev,
5315 const struct pci_device_id *id)
5317 static int printed_version;
5318 struct ieee80211_hw *hw;
5319 struct mwl8k_priv *priv;
5320 struct mwl8k_device_info *di;
5323 if (!printed_version) {
5324 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
5325 printed_version = 1;
5329 rc = pci_enable_device(pdev);
5331 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
5336 rc = pci_request_regions(pdev, MWL8K_NAME);
5338 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
5340 goto err_disable_device;
5343 pci_set_master(pdev);
5346 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
5348 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
5353 SET_IEEE80211_DEV(hw, &pdev->dev);
5354 pci_set_drvdata(pdev, hw);
5359 priv->device_info = &mwl8k_info_tbl[id->driver_data];
5362 priv->sram = pci_iomap(pdev, 0, 0x10000);
5363 if (priv->sram == NULL) {
5364 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
5369 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
5370 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
5372 priv->regs = pci_iomap(pdev, 1, 0x10000);
5373 if (priv->regs == NULL) {
5374 priv->regs = pci_iomap(pdev, 2, 0x10000);
5375 if (priv->regs == NULL) {
5376 wiphy_err(hw->wiphy, "Cannot map device registers\n");
5382 * Choose the initial fw image depending on user input. If a second
5383 * image is available, make it the alternative image that will be
5384 * loaded if the first one fails.
5386 init_completion(&priv->firmware_loading_complete);
5387 di = priv->device_info;
5388 if (ap_mode_default && di->fw_image_ap) {
5389 priv->fw_pref = di->fw_image_ap;
5390 priv->fw_alt = di->fw_image_sta;
5391 } else if (!ap_mode_default && di->fw_image_sta) {
5392 priv->fw_pref = di->fw_image_sta;
5393 priv->fw_alt = di->fw_image_ap;
5394 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
5395 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
5396 priv->fw_pref = di->fw_image_sta;
5397 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
5398 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
5399 priv->fw_pref = di->fw_image_ap;
5401 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
5403 goto err_stop_firmware;
5407 mwl8k_hw_reset(priv);
5410 if (priv->regs != NULL)
5411 pci_iounmap(pdev, priv->regs);
5413 if (priv->sram != NULL)
5414 pci_iounmap(pdev, priv->sram);
5416 pci_set_drvdata(pdev, NULL);
5417 ieee80211_free_hw(hw);
5420 pci_release_regions(pdev);
5423 pci_disable_device(pdev);
5428 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
5430 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
5433 static void __devexit mwl8k_remove(struct pci_dev *pdev)
5435 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
5436 struct mwl8k_priv *priv;
5443 wait_for_completion(&priv->firmware_loading_complete);
5445 if (priv->fw_state == FW_STATE_ERROR) {
5446 mwl8k_hw_reset(priv);
5450 ieee80211_stop_queues(hw);
5452 ieee80211_unregister_hw(hw);
5454 /* Remove TX reclaim and RX tasklets. */
5455 tasklet_kill(&priv->poll_tx_task);
5456 tasklet_kill(&priv->poll_rx_task);
5459 mwl8k_hw_reset(priv);
5461 /* Return all skbs to mac80211 */
5462 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5463 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
5465 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5466 mwl8k_txq_deinit(hw, i);
5468 mwl8k_rxq_deinit(hw, 0);
5470 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
5473 pci_iounmap(pdev, priv->regs);
5474 pci_iounmap(pdev, priv->sram);
5475 pci_set_drvdata(pdev, NULL);
5476 ieee80211_free_hw(hw);
5477 pci_release_regions(pdev);
5478 pci_disable_device(pdev);
5481 static struct pci_driver mwl8k_driver = {
5483 .id_table = mwl8k_pci_id_table,
5484 .probe = mwl8k_probe,
5485 .remove = __devexit_p(mwl8k_remove),
5486 .shutdown = __devexit_p(mwl8k_shutdown),
5489 static int __init mwl8k_init(void)
5491 return pci_register_driver(&mwl8k_driver);
5494 static void __exit mwl8k_exit(void)
5496 pci_unregister_driver(&mwl8k_driver);
5499 module_init(mwl8k_init);
5500 module_exit(mwl8k_exit);
5502 MODULE_DESCRIPTION(MWL8K_DESC);
5503 MODULE_VERSION(MWL8K_VERSION);
5504 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
5505 MODULE_LICENSE("GPL");