2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc.
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/spinlock.h>
18 #include <linux/list.h>
19 #include <linux/pci.h>
20 #include <linux/delay.h>
21 #include <linux/completion.h>
22 #include <linux/etherdevice.h>
23 #include <linux/slab.h>
24 #include <net/mac80211.h>
25 #include <linux/moduleparam.h>
26 #include <linux/firmware.h>
27 #include <linux/workqueue.h>
29 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
30 #define MWL8K_NAME KBUILD_MODNAME
31 #define MWL8K_VERSION "0.13"
33 /* Module parameters */
34 static bool ap_mode_default;
35 module_param(ap_mode_default, bool, 0);
36 MODULE_PARM_DESC(ap_mode_default,
37 "Set to 1 to make ap mode the default instead of sta mode");
39 /* Register definitions */
40 #define MWL8K_HIU_GEN_PTR 0x00000c10
41 #define MWL8K_MODE_STA 0x0000005a
42 #define MWL8K_MODE_AP 0x000000a5
43 #define MWL8K_HIU_INT_CODE 0x00000c14
44 #define MWL8K_FWSTA_READY 0xf0f1f2f4
45 #define MWL8K_FWAP_READY 0xf1f2f4a5
46 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
47 #define MWL8K_HIU_SCRATCH 0x00000c40
49 /* Host->device communications */
50 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
51 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
52 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
53 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
54 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
55 #define MWL8K_H2A_INT_DUMMY (1 << 20)
56 #define MWL8K_H2A_INT_RESET (1 << 15)
57 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
58 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
60 /* Device->host communications */
61 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
62 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
63 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
64 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
65 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
66 #define MWL8K_A2H_INT_DUMMY (1 << 20)
67 #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
68 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
69 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
70 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
71 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
72 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
73 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
74 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
75 #define MWL8K_A2H_INT_RX_READY (1 << 1)
76 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
78 /* HW micro second timer register
79 * located at offset 0xA600. This
80 * will be used to timestamp tx
84 #define MWL8K_HW_TIMER_REGISTER 0x0000a600
86 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
87 MWL8K_A2H_INT_CHNL_SWITCHED | \
88 MWL8K_A2H_INT_QUEUE_EMPTY | \
89 MWL8K_A2H_INT_RADAR_DETECT | \
90 MWL8K_A2H_INT_RADIO_ON | \
91 MWL8K_A2H_INT_RADIO_OFF | \
92 MWL8K_A2H_INT_MAC_EVENT | \
93 MWL8K_A2H_INT_OPC_DONE | \
94 MWL8K_A2H_INT_RX_READY | \
95 MWL8K_A2H_INT_TX_DONE | \
96 MWL8K_A2H_INT_BA_WATCHDOG)
98 #define MWL8K_RX_QUEUES 1
99 #define MWL8K_TX_WMM_QUEUES 4
100 #define MWL8K_MAX_AMPDU_QUEUES 8
101 #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
102 #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
104 /* txpriorities are mapped with hw queues.
105 * Each hw queue has a txpriority.
107 #define TOTAL_HW_TX_QUEUES 8
109 /* Each HW queue can have one AMPDU stream.
110 * But, because one of the hw queue is reserved,
111 * maximum AMPDU queues that can be created are
112 * one short of total tx queues.
114 #define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1)
118 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
119 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
120 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
121 __le16 *qos, s8 *noise);
124 struct mwl8k_device_info {
129 struct rxd_ops *ap_rxd_ops;
133 struct mwl8k_rx_queue {
136 /* hw receives here */
139 /* refill descs here */
146 DEFINE_DMA_UNMAP_ADDR(dma);
150 struct mwl8k_tx_queue {
151 /* hw transmits here */
154 /* sw appends here */
158 struct mwl8k_tx_desc *txd;
160 struct sk_buff **skb;
166 AMPDU_STREAM_IN_PROGRESS,
170 struct mwl8k_ampdu_stream {
171 struct ieee80211_sta *sta;
178 struct ieee80211_hw *hw;
179 struct pci_dev *pdev;
182 struct mwl8k_device_info *device_info;
188 const struct firmware *fw_helper;
189 const struct firmware *fw_ucode;
191 /* hardware/firmware parameters */
193 struct rxd_ops *rxd_ops;
194 struct ieee80211_supported_band band_24;
195 struct ieee80211_channel channels_24[14];
196 struct ieee80211_rate rates_24[14];
197 struct ieee80211_supported_band band_50;
198 struct ieee80211_channel channels_50[4];
199 struct ieee80211_rate rates_50[9];
200 u32 ap_macids_supported;
201 u32 sta_macids_supported;
203 /* Ampdu stream information */
205 spinlock_t stream_lock;
206 struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
207 struct work_struct watchdog_ba_handle;
209 /* firmware access */
210 struct mutex fw_mutex;
211 struct task_struct *fw_mutex_owner;
212 struct task_struct *hw_restart_owner;
214 struct completion *hostcmd_wait;
216 /* lock held over TX and TX reap */
219 /* TX quiesce completion, protected by fw_mutex and tx_lock */
220 struct completion *tx_wait;
222 /* List of interfaces. */
224 struct list_head vif_list;
226 /* power management status cookie from firmware */
228 dma_addr_t cookie_dma;
235 * Running count of TX packets in flight, to avoid
236 * iterating over the transmit rings each time.
240 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
241 struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
242 u32 txq_offset[MWL8K_MAX_TX_QUEUES];
245 bool radio_short_preamble;
246 bool sniffer_enabled;
249 /* XXX need to convert this to handle multiple interfaces */
251 u8 capture_bssid[ETH_ALEN];
252 struct sk_buff *beacon_skb;
255 * This FJ worker has to be global as it is scheduled from the
256 * RX handler. At this point we don't know which interface it
257 * belongs to until the list of bssids waiting to complete join
260 struct work_struct finalize_join_worker;
262 /* Tasklet to perform TX reclaim. */
263 struct tasklet_struct poll_tx_task;
265 /* Tasklet to perform RX. */
266 struct tasklet_struct poll_rx_task;
268 /* Most recently reported noise in dBm */
272 * preserve the queue configurations so they can be restored if/when
273 * the firmware image is swapped.
275 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
277 /* To perform the task of reloading the firmware */
278 struct work_struct fw_reload;
279 bool hw_restart_in_progress;
281 /* async firmware loading state */
285 struct completion firmware_loading_complete;
288 #define MAX_WEP_KEY_LEN 13
289 #define NUM_WEP_KEYS 4
291 /* Per interface specific private data */
293 struct list_head list;
294 struct ieee80211_vif *vif;
296 /* Firmware macid for this vif. */
299 /* Non AMPDU sequence number assigned by driver. */
305 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
306 } wep_key_conf[NUM_WEP_KEYS];
311 /* A flag to indicate is HW crypto is enabled for this bssid */
312 bool is_hw_crypto_enabled;
314 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
315 #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
317 struct tx_traffic_info {
322 #define MWL8K_MAX_TID 8
324 /* Index into station database. Returned by UPDATE_STADB. */
327 struct tx_traffic_info tx_stats[MWL8K_MAX_TID];
329 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
331 static const struct ieee80211_channel mwl8k_channels_24[] = {
332 { .center_freq = 2412, .hw_value = 1, },
333 { .center_freq = 2417, .hw_value = 2, },
334 { .center_freq = 2422, .hw_value = 3, },
335 { .center_freq = 2427, .hw_value = 4, },
336 { .center_freq = 2432, .hw_value = 5, },
337 { .center_freq = 2437, .hw_value = 6, },
338 { .center_freq = 2442, .hw_value = 7, },
339 { .center_freq = 2447, .hw_value = 8, },
340 { .center_freq = 2452, .hw_value = 9, },
341 { .center_freq = 2457, .hw_value = 10, },
342 { .center_freq = 2462, .hw_value = 11, },
343 { .center_freq = 2467, .hw_value = 12, },
344 { .center_freq = 2472, .hw_value = 13, },
345 { .center_freq = 2484, .hw_value = 14, },
348 static const struct ieee80211_rate mwl8k_rates_24[] = {
349 { .bitrate = 10, .hw_value = 2, },
350 { .bitrate = 20, .hw_value = 4, },
351 { .bitrate = 55, .hw_value = 11, },
352 { .bitrate = 110, .hw_value = 22, },
353 { .bitrate = 220, .hw_value = 44, },
354 { .bitrate = 60, .hw_value = 12, },
355 { .bitrate = 90, .hw_value = 18, },
356 { .bitrate = 120, .hw_value = 24, },
357 { .bitrate = 180, .hw_value = 36, },
358 { .bitrate = 240, .hw_value = 48, },
359 { .bitrate = 360, .hw_value = 72, },
360 { .bitrate = 480, .hw_value = 96, },
361 { .bitrate = 540, .hw_value = 108, },
362 { .bitrate = 720, .hw_value = 144, },
365 static const struct ieee80211_channel mwl8k_channels_50[] = {
366 { .center_freq = 5180, .hw_value = 36, },
367 { .center_freq = 5200, .hw_value = 40, },
368 { .center_freq = 5220, .hw_value = 44, },
369 { .center_freq = 5240, .hw_value = 48, },
372 static const struct ieee80211_rate mwl8k_rates_50[] = {
373 { .bitrate = 60, .hw_value = 12, },
374 { .bitrate = 90, .hw_value = 18, },
375 { .bitrate = 120, .hw_value = 24, },
376 { .bitrate = 180, .hw_value = 36, },
377 { .bitrate = 240, .hw_value = 48, },
378 { .bitrate = 360, .hw_value = 72, },
379 { .bitrate = 480, .hw_value = 96, },
380 { .bitrate = 540, .hw_value = 108, },
381 { .bitrate = 720, .hw_value = 144, },
384 /* Set or get info from Firmware */
385 #define MWL8K_CMD_GET 0x0000
386 #define MWL8K_CMD_SET 0x0001
387 #define MWL8K_CMD_SET_LIST 0x0002
389 /* Firmware command codes */
390 #define MWL8K_CMD_CODE_DNLD 0x0001
391 #define MWL8K_CMD_GET_HW_SPEC 0x0003
392 #define MWL8K_CMD_SET_HW_SPEC 0x0004
393 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
394 #define MWL8K_CMD_GET_STAT 0x0014
395 #define MWL8K_CMD_RADIO_CONTROL 0x001c
396 #define MWL8K_CMD_RF_TX_POWER 0x001e
397 #define MWL8K_CMD_TX_POWER 0x001f
398 #define MWL8K_CMD_RF_ANTENNA 0x0020
399 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
400 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
401 #define MWL8K_CMD_SET_POST_SCAN 0x0108
402 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
403 #define MWL8K_CMD_SET_AID 0x010d
404 #define MWL8K_CMD_SET_RATE 0x0110
405 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
406 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
407 #define MWL8K_CMD_SET_SLOT 0x0114
408 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
409 #define MWL8K_CMD_SET_WMM_MODE 0x0123
410 #define MWL8K_CMD_MIMO_CONFIG 0x0125
411 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
412 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
413 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
414 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
415 #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
416 #define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
417 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
418 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
419 #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
420 #define MWL8K_CMD_UPDATE_STADB 0x1123
421 #define MWL8K_CMD_BASTREAM 0x1125
423 static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
425 u16 command = le16_to_cpu(cmd);
427 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
428 snprintf(buf, bufsize, "%s", #x);\
431 switch (command & ~0x8000) {
432 MWL8K_CMDNAME(CODE_DNLD);
433 MWL8K_CMDNAME(GET_HW_SPEC);
434 MWL8K_CMDNAME(SET_HW_SPEC);
435 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
436 MWL8K_CMDNAME(GET_STAT);
437 MWL8K_CMDNAME(RADIO_CONTROL);
438 MWL8K_CMDNAME(RF_TX_POWER);
439 MWL8K_CMDNAME(TX_POWER);
440 MWL8K_CMDNAME(RF_ANTENNA);
441 MWL8K_CMDNAME(SET_BEACON);
442 MWL8K_CMDNAME(SET_PRE_SCAN);
443 MWL8K_CMDNAME(SET_POST_SCAN);
444 MWL8K_CMDNAME(SET_RF_CHANNEL);
445 MWL8K_CMDNAME(SET_AID);
446 MWL8K_CMDNAME(SET_RATE);
447 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
448 MWL8K_CMDNAME(RTS_THRESHOLD);
449 MWL8K_CMDNAME(SET_SLOT);
450 MWL8K_CMDNAME(SET_EDCA_PARAMS);
451 MWL8K_CMDNAME(SET_WMM_MODE);
452 MWL8K_CMDNAME(MIMO_CONFIG);
453 MWL8K_CMDNAME(USE_FIXED_RATE);
454 MWL8K_CMDNAME(ENABLE_SNIFFER);
455 MWL8K_CMDNAME(SET_MAC_ADDR);
456 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
457 MWL8K_CMDNAME(BSS_START);
458 MWL8K_CMDNAME(SET_NEW_STN);
459 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
460 MWL8K_CMDNAME(UPDATE_STADB);
461 MWL8K_CMDNAME(BASTREAM);
462 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
464 snprintf(buf, bufsize, "0x%x", cmd);
471 /* Hardware and firmware reset */
472 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
474 iowrite32(MWL8K_H2A_INT_RESET,
475 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
476 iowrite32(MWL8K_H2A_INT_RESET,
477 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
481 /* Release fw image */
482 static void mwl8k_release_fw(const struct firmware **fw)
486 release_firmware(*fw);
490 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
492 mwl8k_release_fw(&priv->fw_ucode);
493 mwl8k_release_fw(&priv->fw_helper);
496 /* states for asynchronous f/w loading */
497 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
500 FW_STATE_LOADING_PREF,
501 FW_STATE_LOADING_ALT,
505 /* Request fw image */
506 static int mwl8k_request_fw(struct mwl8k_priv *priv,
507 const char *fname, const struct firmware **fw,
510 /* release current image */
512 mwl8k_release_fw(fw);
515 return request_firmware_nowait(THIS_MODULE, 1, fname,
516 &priv->pdev->dev, GFP_KERNEL,
517 priv, mwl8k_fw_state_machine);
519 return request_firmware(fw, fname, &priv->pdev->dev);
522 static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
525 struct mwl8k_device_info *di = priv->device_info;
528 if (di->helper_image != NULL) {
530 rc = mwl8k_request_fw(priv, di->helper_image,
531 &priv->fw_helper, true);
533 rc = mwl8k_request_fw(priv, di->helper_image,
534 &priv->fw_helper, false);
536 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
537 pci_name(priv->pdev), di->helper_image);
545 * if we get here, no helper image is needed. Skip the
546 * FW_STATE_INIT state.
548 priv->fw_state = FW_STATE_LOADING_PREF;
549 rc = mwl8k_request_fw(priv, fw_image,
553 rc = mwl8k_request_fw(priv, fw_image,
554 &priv->fw_ucode, false);
556 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
557 pci_name(priv->pdev), fw_image);
558 mwl8k_release_fw(&priv->fw_helper);
565 struct mwl8k_cmd_pkt {
578 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
580 void __iomem *regs = priv->regs;
584 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
585 if (pci_dma_mapping_error(priv->pdev, dma_addr))
588 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
589 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
590 iowrite32(MWL8K_H2A_INT_DOORBELL,
591 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
592 iowrite32(MWL8K_H2A_INT_DUMMY,
593 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
599 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
600 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
601 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
609 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
611 return loops ? 0 : -ETIMEDOUT;
614 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
615 const u8 *data, size_t length)
617 struct mwl8k_cmd_pkt *cmd;
621 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
625 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
632 int block_size = length > 256 ? 256 : length;
634 memcpy(cmd->payload, data + done, block_size);
635 cmd->length = cpu_to_le16(block_size);
637 rc = mwl8k_send_fw_load_cmd(priv, cmd,
638 sizeof(*cmd) + block_size);
643 length -= block_size;
648 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
656 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
657 const u8 *data, size_t length)
659 unsigned char *buffer;
660 int may_continue, rc = 0;
661 u32 done, prev_block_size;
663 buffer = kmalloc(1024, GFP_KERNEL);
670 while (may_continue > 0) {
673 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
674 if (block_size & 1) {
678 done += prev_block_size;
679 length -= prev_block_size;
682 if (block_size > 1024 || block_size > length) {
692 if (block_size == 0) {
699 prev_block_size = block_size;
700 memcpy(buffer, data + done, block_size);
702 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
707 if (!rc && length != 0)
715 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
717 struct mwl8k_priv *priv = hw->priv;
718 const struct firmware *fw = priv->fw_ucode;
722 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
723 const struct firmware *helper = priv->fw_helper;
725 if (helper == NULL) {
726 printk(KERN_ERR "%s: helper image needed but none "
727 "given\n", pci_name(priv->pdev));
731 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
733 printk(KERN_ERR "%s: unable to load firmware "
734 "helper image\n", pci_name(priv->pdev));
739 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
741 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
745 printk(KERN_ERR "%s: unable to load firmware image\n",
746 pci_name(priv->pdev));
750 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
756 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
757 if (ready_code == MWL8K_FWAP_READY) {
760 } else if (ready_code == MWL8K_FWSTA_READY) {
769 return loops ? 0 : -ETIMEDOUT;
773 /* DMA header used by firmware and hardware. */
774 struct mwl8k_dma_data {
776 struct ieee80211_hdr wh;
780 /* Routines to add/remove DMA header from skb. */
781 static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
783 struct mwl8k_dma_data *tr;
786 tr = (struct mwl8k_dma_data *)skb->data;
787 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
789 if (hdrlen != sizeof(tr->wh)) {
790 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
791 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
792 *((__le16 *)(tr->data - 2)) = qos;
794 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
798 if (hdrlen != sizeof(*tr))
799 skb_pull(skb, sizeof(*tr) - hdrlen);
802 #define REDUCED_TX_HEADROOM 8
805 mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb,
806 int head_pad, int tail_pad)
808 struct ieee80211_hdr *wh;
811 struct mwl8k_dma_data *tr;
814 * Add a firmware DMA header; the firmware requires that we
815 * present a 2-byte payload length followed by a 4-address
816 * header (without QoS field), followed (optionally) by any
817 * WEP/ExtIV header (but only filled in for CCMP).
819 wh = (struct ieee80211_hdr *)skb->data;
821 hdrlen = ieee80211_hdrlen(wh->frame_control);
824 * Check if skb_resize is required because of
825 * tx_headroom adjustment.
827 if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts)
828 + REDUCED_TX_HEADROOM))) {
829 if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) {
831 wiphy_err(priv->hw->wiphy,
832 "Failed to reallocate TX buffer\n");
835 skb->truesize += REDUCED_TX_HEADROOM;
838 reqd_hdrlen = sizeof(*tr) + head_pad;
840 if (hdrlen != reqd_hdrlen)
841 skb_push(skb, reqd_hdrlen - hdrlen);
843 if (ieee80211_is_data_qos(wh->frame_control))
844 hdrlen -= IEEE80211_QOS_CTL_LEN;
846 tr = (struct mwl8k_dma_data *)skb->data;
848 memmove(&tr->wh, wh, hdrlen);
849 if (hdrlen != sizeof(tr->wh))
850 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
853 * Firmware length is the length of the fully formed "802.11
854 * payload". That is, everything except for the 802.11 header.
855 * This includes all crypto material including the MIC.
857 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
860 static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv,
863 struct ieee80211_hdr *wh;
864 struct ieee80211_tx_info *tx_info;
865 struct ieee80211_key_conf *key_conf;
869 wh = (struct ieee80211_hdr *)skb->data;
871 tx_info = IEEE80211_SKB_CB(skb);
874 if (ieee80211_is_data(wh->frame_control))
875 key_conf = tx_info->control.hw_key;
878 * Make sure the packet header is in the DMA header format (4-address
879 * without QoS), and add head & tail padding when HW crypto is enabled.
881 * We have the following trailer padding requirements:
882 * - WEP: 4 trailer bytes (ICV)
883 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
884 * - CCMP: 8 trailer bytes (MIC)
887 if (key_conf != NULL) {
888 head_pad = key_conf->iv_len;
889 switch (key_conf->cipher) {
890 case WLAN_CIPHER_SUITE_WEP40:
891 case WLAN_CIPHER_SUITE_WEP104:
894 case WLAN_CIPHER_SUITE_TKIP:
897 case WLAN_CIPHER_SUITE_CCMP:
902 mwl8k_add_dma_header(priv, skb, head_pad, data_pad);
906 * Packet reception for 88w8366 AP firmware.
908 struct mwl8k_rxd_8366_ap {
912 __le32 pkt_phys_addr;
913 __le32 next_rxd_phys_addr;
917 __le32 hw_noise_floor_info;
926 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
927 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
928 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
930 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
932 /* 8366 AP rx_status bits */
933 #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
934 #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
935 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
936 #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
937 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
939 static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
941 struct mwl8k_rxd_8366_ap *rxd = _rxd;
943 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
944 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
947 static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
949 struct mwl8k_rxd_8366_ap *rxd = _rxd;
951 rxd->pkt_len = cpu_to_le16(len);
952 rxd->pkt_phys_addr = cpu_to_le32(addr);
958 mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
959 __le16 *qos, s8 *noise)
961 struct mwl8k_rxd_8366_ap *rxd = _rxd;
963 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
967 memset(status, 0, sizeof(*status));
969 status->signal = -rxd->rssi;
970 *noise = -rxd->noise_floor;
972 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
973 status->flag |= RX_FLAG_HT;
974 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
975 status->flag |= RX_FLAG_40MHZ;
976 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
980 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
981 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
982 status->rate_idx = i;
988 if (rxd->channel > 14) {
989 status->band = IEEE80211_BAND_5GHZ;
990 if (!(status->flag & RX_FLAG_HT))
991 status->rate_idx -= 5;
993 status->band = IEEE80211_BAND_2GHZ;
995 status->freq = ieee80211_channel_to_frequency(rxd->channel,
998 *qos = rxd->qos_control;
1000 if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
1001 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) &&
1002 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
1003 status->flag |= RX_FLAG_MMIC_ERROR;
1005 return le16_to_cpu(rxd->pkt_len);
1008 static struct rxd_ops rxd_8366_ap_ops = {
1009 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
1010 .rxd_init = mwl8k_rxd_8366_ap_init,
1011 .rxd_refill = mwl8k_rxd_8366_ap_refill,
1012 .rxd_process = mwl8k_rxd_8366_ap_process,
1016 * Packet reception for STA firmware.
1018 struct mwl8k_rxd_sta {
1022 __le32 pkt_phys_addr;
1023 __le32 next_rxd_phys_addr;
1035 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
1036 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
1037 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
1038 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
1039 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
1040 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
1042 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
1043 #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
1044 /* ICV=0 or MIC=1 */
1045 #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
1046 /* Key is uploaded only in failure case */
1047 #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
1049 static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
1051 struct mwl8k_rxd_sta *rxd = _rxd;
1053 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
1054 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
1057 static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
1059 struct mwl8k_rxd_sta *rxd = _rxd;
1061 rxd->pkt_len = cpu_to_le16(len);
1062 rxd->pkt_phys_addr = cpu_to_le32(addr);
1068 mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
1069 __le16 *qos, s8 *noise)
1071 struct mwl8k_rxd_sta *rxd = _rxd;
1074 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
1078 rate_info = le16_to_cpu(rxd->rate_info);
1080 memset(status, 0, sizeof(*status));
1082 status->signal = -rxd->rssi;
1083 *noise = -rxd->noise_level;
1084 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
1085 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
1087 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
1088 status->flag |= RX_FLAG_SHORTPRE;
1089 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
1090 status->flag |= RX_FLAG_40MHZ;
1091 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
1092 status->flag |= RX_FLAG_SHORT_GI;
1093 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
1094 status->flag |= RX_FLAG_HT;
1096 if (rxd->channel > 14) {
1097 status->band = IEEE80211_BAND_5GHZ;
1098 if (!(status->flag & RX_FLAG_HT))
1099 status->rate_idx -= 5;
1101 status->band = IEEE80211_BAND_2GHZ;
1103 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1106 *qos = rxd->qos_control;
1107 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1108 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1109 status->flag |= RX_FLAG_MMIC_ERROR;
1111 return le16_to_cpu(rxd->pkt_len);
1114 static struct rxd_ops rxd_sta_ops = {
1115 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1116 .rxd_init = mwl8k_rxd_sta_init,
1117 .rxd_refill = mwl8k_rxd_sta_refill,
1118 .rxd_process = mwl8k_rxd_sta_process,
1122 #define MWL8K_RX_DESCS 256
1123 #define MWL8K_RX_MAXSZ 3800
1125 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1127 struct mwl8k_priv *priv = hw->priv;
1128 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1136 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
1138 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1139 if (rxq->rxd == NULL) {
1140 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
1143 memset(rxq->rxd, 0, size);
1145 rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
1146 if (rxq->buf == NULL) {
1147 wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
1148 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
1152 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1156 dma_addr_t next_dma_addr;
1158 desc_size = priv->rxd_ops->rxd_size;
1159 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
1162 if (nexti == MWL8K_RX_DESCS)
1164 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1166 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
1172 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1174 struct mwl8k_priv *priv = hw->priv;
1175 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1179 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
1180 struct sk_buff *skb;
1185 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1189 addr = pci_map_single(priv->pdev, skb->data,
1190 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
1194 if (rxq->tail == MWL8K_RX_DESCS)
1196 rxq->buf[rx].skb = skb;
1197 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
1199 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1200 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
1208 /* Must be called only when the card's reception is completely halted */
1209 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1211 struct mwl8k_priv *priv = hw->priv;
1212 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1215 if (rxq->rxd == NULL)
1218 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1219 if (rxq->buf[i].skb != NULL) {
1220 pci_unmap_single(priv->pdev,
1221 dma_unmap_addr(&rxq->buf[i], dma),
1222 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1223 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
1225 kfree_skb(rxq->buf[i].skb);
1226 rxq->buf[i].skb = NULL;
1233 pci_free_consistent(priv->pdev,
1234 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
1235 rxq->rxd, rxq->rxd_dma);
1241 * Scan a list of BSSIDs to process for finalize join.
1242 * Allows for extension to process multiple BSSIDs.
1245 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1247 return priv->capture_beacon &&
1248 ieee80211_is_beacon(wh->frame_control) &&
1249 ether_addr_equal(wh->addr3, priv->capture_bssid);
1252 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1253 struct sk_buff *skb)
1255 struct mwl8k_priv *priv = hw->priv;
1257 priv->capture_beacon = false;
1258 memset(priv->capture_bssid, 0, ETH_ALEN);
1261 * Use GFP_ATOMIC as rxq_process is called from
1262 * the primary interrupt handler, memory allocation call
1265 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1266 if (priv->beacon_skb != NULL)
1267 ieee80211_queue_work(hw, &priv->finalize_join_worker);
1270 static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1273 struct mwl8k_vif *mwl8k_vif;
1275 list_for_each_entry(mwl8k_vif,
1277 if (memcmp(bssid, mwl8k_vif->bssid,
1285 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1287 struct mwl8k_priv *priv = hw->priv;
1288 struct mwl8k_vif *mwl8k_vif = NULL;
1289 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1293 while (rxq->rxd_count && limit--) {
1294 struct sk_buff *skb;
1297 struct ieee80211_rx_status status;
1298 struct ieee80211_hdr *wh;
1301 skb = rxq->buf[rxq->head].skb;
1305 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1307 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1312 rxq->buf[rxq->head].skb = NULL;
1314 pci_unmap_single(priv->pdev,
1315 dma_unmap_addr(&rxq->buf[rxq->head], dma),
1316 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1317 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1320 if (rxq->head == MWL8K_RX_DESCS)
1325 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1328 * Check for a pending join operation. Save a
1329 * copy of the beacon and schedule a tasklet to
1330 * send a FINALIZE_JOIN command to the firmware.
1332 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1333 mwl8k_save_beacon(hw, skb);
1335 if (ieee80211_has_protected(wh->frame_control)) {
1337 /* Check if hw crypto has been enabled for
1338 * this bss. If yes, set the status flags
1341 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1344 if (mwl8k_vif != NULL &&
1345 mwl8k_vif->is_hw_crypto_enabled) {
1347 * When MMIC ERROR is encountered
1348 * by the firmware, payload is
1349 * dropped and only 32 bytes of
1350 * mwl8k Firmware header is sent
1353 * We need to add four bytes of
1354 * key information. In it
1355 * MAC80211 expects keyidx set to
1356 * 0 for triggering Counter
1357 * Measure of MMIC failure.
1359 if (status.flag & RX_FLAG_MMIC_ERROR) {
1360 struct mwl8k_dma_data *tr;
1361 tr = (struct mwl8k_dma_data *)skb->data;
1362 memset((void *)&(tr->data), 0, 4);
1366 if (!ieee80211_is_auth(wh->frame_control))
1367 status.flag |= RX_FLAG_IV_STRIPPED |
1369 RX_FLAG_MMIC_STRIPPED;
1373 skb_put(skb, pkt_len);
1374 mwl8k_remove_dma_header(skb, qos);
1375 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1376 ieee80211_rx_irqsafe(hw, skb);
1386 * Packet transmission.
1389 #define MWL8K_TXD_STATUS_OK 0x00000001
1390 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1391 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1392 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1393 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1395 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1396 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1397 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1398 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1399 #define MWL8K_QOS_EOSP 0x0010
1401 struct mwl8k_tx_desc {
1406 __le32 pkt_phys_addr;
1408 __u8 dest_MAC_addr[ETH_ALEN];
1409 __le32 next_txd_phys_addr;
1416 #define MWL8K_TX_DESCS 128
1418 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1420 struct mwl8k_priv *priv = hw->priv;
1421 struct mwl8k_tx_queue *txq = priv->txq + index;
1429 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1431 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1432 if (txq->txd == NULL) {
1433 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
1436 memset(txq->txd, 0, size);
1438 txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
1439 if (txq->skb == NULL) {
1440 wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
1441 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1445 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1446 struct mwl8k_tx_desc *tx_desc;
1449 tx_desc = txq->txd + i;
1450 nexti = (i + 1) % MWL8K_TX_DESCS;
1452 tx_desc->status = 0;
1453 tx_desc->next_txd_phys_addr =
1454 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1460 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1462 iowrite32(MWL8K_H2A_INT_PPA_READY,
1463 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1464 iowrite32(MWL8K_H2A_INT_DUMMY,
1465 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1466 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1469 static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1471 struct mwl8k_priv *priv = hw->priv;
1474 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
1475 struct mwl8k_tx_queue *txq = priv->txq + i;
1481 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1482 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1485 status = le32_to_cpu(tx_desc->status);
1486 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1491 if (tx_desc->pkt_len == 0)
1495 wiphy_err(hw->wiphy,
1496 "txq[%d] len=%d head=%d tail=%d "
1497 "fw_owned=%d drv_owned=%d unused=%d\n",
1499 txq->len, txq->head, txq->tail,
1500 fw_owned, drv_owned, unused);
1505 * Must be called with priv->fw_mutex held and tx queues stopped.
1507 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1509 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1511 struct mwl8k_priv *priv = hw->priv;
1512 DECLARE_COMPLETION_ONSTACK(tx_wait);
1518 /* Since fw restart is in progress, allow only the firmware
1519 * commands from the restart code and block the other
1520 * commands since they are going to fail in any case since
1521 * the firmware has crashed
1523 if (priv->hw_restart_in_progress) {
1524 if (priv->hw_restart_owner == current)
1531 * The TX queues are stopped at this point, so this test
1532 * doesn't need to take ->tx_lock.
1534 if (!priv->pending_tx_pkts)
1540 spin_lock_bh(&priv->tx_lock);
1541 priv->tx_wait = &tx_wait;
1544 unsigned long timeout;
1546 oldcount = priv->pending_tx_pkts;
1548 spin_unlock_bh(&priv->tx_lock);
1549 timeout = wait_for_completion_timeout(&tx_wait,
1550 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1551 spin_lock_bh(&priv->tx_lock);
1554 WARN_ON(priv->pending_tx_pkts);
1556 wiphy_notice(hw->wiphy, "tx rings drained\n");
1560 if (priv->pending_tx_pkts < oldcount) {
1561 wiphy_notice(hw->wiphy,
1562 "waiting for tx rings to drain (%d -> %d pkts)\n",
1563 oldcount, priv->pending_tx_pkts);
1568 priv->tx_wait = NULL;
1570 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1571 MWL8K_TX_WAIT_TIMEOUT_MS);
1572 mwl8k_dump_tx_rings(hw);
1573 priv->hw_restart_in_progress = true;
1574 ieee80211_queue_work(hw, &priv->fw_reload);
1578 spin_unlock_bh(&priv->tx_lock);
1583 #define MWL8K_TXD_SUCCESS(status) \
1584 ((status) & (MWL8K_TXD_STATUS_OK | \
1585 MWL8K_TXD_STATUS_OK_RETRY | \
1586 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1588 static int mwl8k_tid_queue_mapping(u8 tid)
1595 return IEEE80211_AC_BE;
1599 return IEEE80211_AC_BK;
1603 return IEEE80211_AC_VI;
1607 return IEEE80211_AC_VO;
1615 /* The firmware will fill in the rate information
1616 * for each packet that gets queued in the hardware
1617 * and these macros will interpret that info.
1620 #define RI_FORMAT(a) (a & 0x0001)
1621 #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
1624 mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1626 struct mwl8k_priv *priv = hw->priv;
1627 struct mwl8k_tx_queue *txq = priv->txq + index;
1631 while (txq->len > 0 && limit--) {
1633 struct mwl8k_tx_desc *tx_desc;
1636 struct sk_buff *skb;
1637 struct ieee80211_tx_info *info;
1639 struct ieee80211_sta *sta;
1640 struct mwl8k_sta *sta_info = NULL;
1642 struct ieee80211_hdr *wh;
1645 tx_desc = txq->txd + tx;
1647 status = le32_to_cpu(tx_desc->status);
1649 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1653 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1656 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1657 BUG_ON(txq->len == 0);
1659 priv->pending_tx_pkts--;
1661 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1662 size = le16_to_cpu(tx_desc->pkt_len);
1664 txq->skb[tx] = NULL;
1666 BUG_ON(skb == NULL);
1667 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1669 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
1671 wh = (struct ieee80211_hdr *) skb->data;
1673 /* Mark descriptor as unused */
1674 tx_desc->pkt_phys_addr = 0;
1675 tx_desc->pkt_len = 0;
1677 info = IEEE80211_SKB_CB(skb);
1678 if (ieee80211_is_data(wh->frame_control)) {
1680 sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
1683 sta_info = MWL8K_STA(sta);
1684 BUG_ON(sta_info == NULL);
1685 rate_info = le16_to_cpu(tx_desc->rate_info);
1686 /* If rate is < 6.5 Mpbs for an ht station
1687 * do not form an ampdu. If the station is a
1688 * legacy station (format = 0), do not form an
1691 if (RI_RATE_ID_MCS(rate_info) < 1 ||
1692 RI_FORMAT(rate_info) == 0) {
1693 sta_info->is_ampdu_allowed = false;
1695 sta_info->is_ampdu_allowed = true;
1701 ieee80211_tx_info_clear_status(info);
1703 /* Rate control is happening in the firmware.
1704 * Ensure no tx rate is being reported.
1706 info->status.rates[0].idx = -1;
1707 info->status.rates[0].count = 1;
1709 if (MWL8K_TXD_SUCCESS(status))
1710 info->flags |= IEEE80211_TX_STAT_ACK;
1712 ieee80211_tx_status_irqsafe(hw, skb);
1720 /* must be called only when the card's transmit is completely halted */
1721 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1723 struct mwl8k_priv *priv = hw->priv;
1724 struct mwl8k_tx_queue *txq = priv->txq + index;
1726 if (txq->txd == NULL)
1729 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1734 pci_free_consistent(priv->pdev,
1735 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1736 txq->txd, txq->txd_dma);
1740 /* caller must hold priv->stream_lock when calling the stream functions */
1741 static struct mwl8k_ampdu_stream *
1742 mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
1744 struct mwl8k_ampdu_stream *stream;
1745 struct mwl8k_priv *priv = hw->priv;
1748 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
1749 stream = &priv->ampdu[i];
1750 if (stream->state == AMPDU_NO_STREAM) {
1752 stream->state = AMPDU_STREAM_NEW;
1755 wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
1764 mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1768 /* if the stream has already been started, don't start it again */
1769 if (stream->state != AMPDU_STREAM_NEW)
1771 ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
1773 wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
1774 "%d\n", stream->sta->addr, stream->tid, ret);
1776 wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
1777 stream->sta->addr, stream->tid);
1782 mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1784 wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
1786 memset(stream, 0, sizeof(*stream));
1789 static struct mwl8k_ampdu_stream *
1790 mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
1792 struct mwl8k_priv *priv = hw->priv;
1795 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
1796 struct mwl8k_ampdu_stream *stream;
1797 stream = &priv->ampdu[i];
1798 if (stream->state == AMPDU_NO_STREAM)
1800 if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
1807 #define MWL8K_AMPDU_PACKET_THRESHOLD 64
1808 static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
1810 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1811 struct tx_traffic_info *tx_stats;
1813 BUG_ON(tid >= MWL8K_MAX_TID);
1814 tx_stats = &sta_info->tx_stats[tid];
1816 return sta_info->is_ampdu_allowed &&
1817 tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
1820 static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
1822 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1823 struct tx_traffic_info *tx_stats;
1825 BUG_ON(tid >= MWL8K_MAX_TID);
1826 tx_stats = &sta_info->tx_stats[tid];
1828 if (tx_stats->start_time == 0)
1829 tx_stats->start_time = jiffies;
1831 /* reset the packet count after each second elapses. If the number of
1832 * packets ever exceeds the ampdu_min_traffic threshold, we will allow
1833 * an ampdu stream to be started.
1835 if (jiffies - tx_stats->start_time > HZ) {
1837 tx_stats->start_time = 0;
1842 /* The hardware ampdu queues start from 5.
1843 * txpriorities for ampdu queues are
1844 * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
1845 * and queue 3 is lowest (queue 4 is reserved)
1850 mwl8k_txq_xmit(struct ieee80211_hw *hw,
1852 struct ieee80211_sta *sta,
1853 struct sk_buff *skb)
1855 struct mwl8k_priv *priv = hw->priv;
1856 struct ieee80211_tx_info *tx_info;
1857 struct mwl8k_vif *mwl8k_vif;
1858 struct ieee80211_hdr *wh;
1859 struct mwl8k_tx_queue *txq;
1860 struct mwl8k_tx_desc *tx;
1867 struct mwl8k_ampdu_stream *stream = NULL;
1868 bool start_ba_session = false;
1869 bool mgmtframe = false;
1870 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
1871 bool eapol_frame = false;
1873 wh = (struct ieee80211_hdr *)skb->data;
1874 if (ieee80211_is_data_qos(wh->frame_control))
1875 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1879 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
1882 if (ieee80211_is_mgmt(wh->frame_control))
1886 mwl8k_encapsulate_tx_frame(priv, skb);
1888 mwl8k_add_dma_header(priv, skb, 0, 0);
1890 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1892 tx_info = IEEE80211_SKB_CB(skb);
1893 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1895 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1896 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1897 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1898 mwl8k_vif->seqno += 0x10;
1901 /* Setup firmware control bit fields for each frame type. */
1904 if (ieee80211_is_mgmt(wh->frame_control) ||
1905 ieee80211_is_ctl(wh->frame_control)) {
1907 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1908 } else if (ieee80211_is_data(wh->frame_control)) {
1910 if (is_multicast_ether_addr(wh->addr1))
1911 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1913 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1914 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1915 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1917 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1920 /* Queue ADDBA request in the respective data queue. While setting up
1921 * the ampdu stream, mac80211 queues further packets for that
1922 * particular ra/tid pair. However, packets piled up in the hardware
1923 * for that ra/tid pair will still go out. ADDBA request and the
1924 * related data packets going out from different queues asynchronously
1925 * will cause a shift in the receiver window which might result in
1926 * ampdu packets getting dropped at the receiver after the stream has
1929 if (unlikely(ieee80211_is_action(wh->frame_control) &&
1930 mgmt->u.action.category == WLAN_CATEGORY_BACK &&
1931 mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
1933 u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1934 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1935 index = mwl8k_tid_queue_mapping(tid);
1940 if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame &&
1941 ieee80211_is_data_qos(wh->frame_control)) {
1943 mwl8k_tx_count_packet(sta, tid);
1944 spin_lock(&priv->stream_lock);
1945 stream = mwl8k_lookup_stream(hw, sta->addr, tid);
1946 if (stream != NULL) {
1947 if (stream->state == AMPDU_STREAM_ACTIVE) {
1948 WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK));
1949 txpriority = (BA_QUEUE + stream->idx) %
1951 if (stream->idx <= 1)
1952 index = stream->idx +
1953 MWL8K_TX_WMM_QUEUES;
1955 } else if (stream->state == AMPDU_STREAM_NEW) {
1956 /* We get here if the driver sends us packets
1957 * after we've initiated a stream, but before
1958 * our ampdu_action routine has been called
1959 * with IEEE80211_AMPDU_TX_START to get the SSN
1960 * for the ADDBA request. So this packet can
1961 * go out with no risk of sequence number
1962 * mismatch. No special handling is required.
1965 /* Drop packets that would go out after the
1966 * ADDBA request was sent but before the ADDBA
1967 * response is received. If we don't do this,
1968 * the recipient would probably receive it
1969 * after the ADDBA request with SSN 0. This
1970 * will cause the recipient's BA receive window
1971 * to shift, which would cause the subsequent
1972 * packets in the BA stream to be discarded.
1973 * mac80211 queues our packets for us in this
1974 * case, so this is really just a safety check.
1976 wiphy_warn(hw->wiphy,
1977 "Cannot send packet while ADDBA "
1978 "dialog is underway.\n");
1979 spin_unlock(&priv->stream_lock);
1984 /* Defer calling mwl8k_start_stream so that the current
1985 * skb can go out before the ADDBA request. This
1986 * prevents sequence number mismatch at the recepient
1987 * as described above.
1989 if (mwl8k_ampdu_allowed(sta, tid)) {
1990 stream = mwl8k_add_stream(hw, sta, tid);
1992 start_ba_session = true;
1995 spin_unlock(&priv->stream_lock);
1997 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1998 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
2001 dma = pci_map_single(priv->pdev, skb->data,
2002 skb->len, PCI_DMA_TODEVICE);
2004 if (pci_dma_mapping_error(priv->pdev, dma)) {
2005 wiphy_debug(hw->wiphy,
2006 "failed to dma map skb, dropping TX frame.\n");
2007 if (start_ba_session) {
2008 spin_lock(&priv->stream_lock);
2009 mwl8k_remove_stream(hw, stream);
2010 spin_unlock(&priv->stream_lock);
2016 spin_lock_bh(&priv->tx_lock);
2018 txq = priv->txq + index;
2020 /* Mgmt frames that go out frequently are probe
2021 * responses. Other mgmt frames got out relatively
2022 * infrequently. Hence reserve 2 buffers so that
2023 * other mgmt frames do not get dropped due to an
2024 * already queued probe response in one of the
2028 if (txq->len >= MWL8K_TX_DESCS - 2) {
2029 if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
2030 if (start_ba_session) {
2031 spin_lock(&priv->stream_lock);
2032 mwl8k_remove_stream(hw, stream);
2033 spin_unlock(&priv->stream_lock);
2035 spin_unlock_bh(&priv->tx_lock);
2036 pci_unmap_single(priv->pdev, dma, skb->len,
2043 BUG_ON(txq->skb[txq->tail] != NULL);
2044 txq->skb[txq->tail] = skb;
2046 tx = txq->txd + txq->tail;
2047 tx->data_rate = txdatarate;
2048 tx->tx_priority = txpriority;
2049 tx->qos_control = cpu_to_le16(qos);
2050 tx->pkt_phys_addr = cpu_to_le32(dma);
2051 tx->pkt_len = cpu_to_le16(skb->len);
2053 if (!priv->ap_fw && sta != NULL)
2054 tx->peer_id = MWL8K_STA(sta)->peer_id;
2058 if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame)
2059 tx->timestamp = cpu_to_le32(ioread32(priv->regs +
2060 MWL8K_HW_TIMER_REGISTER));
2065 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
2068 priv->pending_tx_pkts++;
2071 if (txq->tail == MWL8K_TX_DESCS)
2074 mwl8k_tx_start(priv);
2076 spin_unlock_bh(&priv->tx_lock);
2078 /* Initiate the ampdu session here */
2079 if (start_ba_session) {
2080 spin_lock(&priv->stream_lock);
2081 if (mwl8k_start_stream(hw, stream))
2082 mwl8k_remove_stream(hw, stream);
2083 spin_unlock(&priv->stream_lock);
2091 * We have the following requirements for issuing firmware commands:
2092 * - Some commands require that the packet transmit path is idle when
2093 * the command is issued. (For simplicity, we'll just quiesce the
2094 * transmit path for every command.)
2095 * - There are certain sequences of commands that need to be issued to
2096 * the hardware sequentially, with no other intervening commands.
2098 * This leads to an implementation of a "firmware lock" as a mutex that
2099 * can be taken recursively, and which is taken by both the low-level
2100 * command submission function (mwl8k_post_cmd) as well as any users of
2101 * that function that require issuing of an atomic sequence of commands,
2102 * and quiesces the transmit path whenever it's taken.
2104 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
2106 struct mwl8k_priv *priv = hw->priv;
2108 if (priv->fw_mutex_owner != current) {
2111 mutex_lock(&priv->fw_mutex);
2112 ieee80211_stop_queues(hw);
2114 rc = mwl8k_tx_wait_empty(hw);
2116 if (!priv->hw_restart_in_progress)
2117 ieee80211_wake_queues(hw);
2119 mutex_unlock(&priv->fw_mutex);
2124 priv->fw_mutex_owner = current;
2127 priv->fw_mutex_depth++;
2132 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
2134 struct mwl8k_priv *priv = hw->priv;
2136 if (!--priv->fw_mutex_depth) {
2137 if (!priv->hw_restart_in_progress)
2138 ieee80211_wake_queues(hw);
2140 priv->fw_mutex_owner = NULL;
2141 mutex_unlock(&priv->fw_mutex);
2147 * Command processing.
2150 /* Timeout firmware commands after 10s */
2151 #define MWL8K_CMD_TIMEOUT_MS 10000
2153 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
2155 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2156 struct mwl8k_priv *priv = hw->priv;
2157 void __iomem *regs = priv->regs;
2158 dma_addr_t dma_addr;
2159 unsigned int dma_size;
2161 unsigned long timeout = 0;
2164 cmd->result = (__force __le16) 0xffff;
2165 dma_size = le16_to_cpu(cmd->length);
2166 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
2167 PCI_DMA_BIDIRECTIONAL);
2168 if (pci_dma_mapping_error(priv->pdev, dma_addr))
2171 rc = mwl8k_fw_lock(hw);
2173 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2174 PCI_DMA_BIDIRECTIONAL);
2178 priv->hostcmd_wait = &cmd_wait;
2179 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
2180 iowrite32(MWL8K_H2A_INT_DOORBELL,
2181 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2182 iowrite32(MWL8K_H2A_INT_DUMMY,
2183 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2185 timeout = wait_for_completion_timeout(&cmd_wait,
2186 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
2188 priv->hostcmd_wait = NULL;
2190 mwl8k_fw_unlock(hw);
2192 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2193 PCI_DMA_BIDIRECTIONAL);
2196 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
2197 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2198 MWL8K_CMD_TIMEOUT_MS);
2203 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
2205 rc = cmd->result ? -EINVAL : 0;
2207 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
2208 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2209 le16_to_cpu(cmd->result));
2211 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
2212 mwl8k_cmd_name(cmd->code,
2220 static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
2221 struct ieee80211_vif *vif,
2222 struct mwl8k_cmd_pkt *cmd)
2225 cmd->macid = MWL8K_VIF(vif)->macid;
2226 return mwl8k_post_cmd(hw, cmd);
2230 * Setup code shared between STA and AP firmware images.
2232 static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
2234 struct mwl8k_priv *priv = hw->priv;
2236 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
2237 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
2239 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
2240 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
2242 priv->band_24.band = IEEE80211_BAND_2GHZ;
2243 priv->band_24.channels = priv->channels_24;
2244 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
2245 priv->band_24.bitrates = priv->rates_24;
2246 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
2248 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
2251 static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
2253 struct mwl8k_priv *priv = hw->priv;
2255 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
2256 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
2258 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
2259 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
2261 priv->band_50.band = IEEE80211_BAND_5GHZ;
2262 priv->band_50.channels = priv->channels_50;
2263 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
2264 priv->band_50.bitrates = priv->rates_50;
2265 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
2267 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
2271 * CMD_GET_HW_SPEC (STA version).
2273 struct mwl8k_cmd_get_hw_spec_sta {
2274 struct mwl8k_cmd_pkt header;
2276 __u8 host_interface;
2278 __u8 perm_addr[ETH_ALEN];
2283 __u8 mcs_bitmap[16];
2284 __le32 rx_queue_ptr;
2285 __le32 num_tx_queues;
2286 __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
2288 __le32 num_tx_desc_per_queue;
2292 #define MWL8K_CAP_MAX_AMSDU 0x20000000
2293 #define MWL8K_CAP_GREENFIELD 0x08000000
2294 #define MWL8K_CAP_AMPDU 0x04000000
2295 #define MWL8K_CAP_RX_STBC 0x01000000
2296 #define MWL8K_CAP_TX_STBC 0x00800000
2297 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2298 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2299 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2300 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2301 #define MWL8K_CAP_DELAY_BA 0x00003000
2302 #define MWL8K_CAP_MIMO 0x00000200
2303 #define MWL8K_CAP_40MHZ 0x00000100
2304 #define MWL8K_CAP_BAND_MASK 0x00000007
2305 #define MWL8K_CAP_5GHZ 0x00000004
2306 #define MWL8K_CAP_2GHZ4 0x00000001
2309 mwl8k_set_ht_caps(struct ieee80211_hw *hw,
2310 struct ieee80211_supported_band *band, u32 cap)
2315 band->ht_cap.ht_supported = 1;
2317 if (cap & MWL8K_CAP_MAX_AMSDU)
2318 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
2319 if (cap & MWL8K_CAP_GREENFIELD)
2320 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
2321 if (cap & MWL8K_CAP_AMPDU) {
2322 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
2323 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2324 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2326 if (cap & MWL8K_CAP_RX_STBC)
2327 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
2328 if (cap & MWL8K_CAP_TX_STBC)
2329 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
2330 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
2331 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
2332 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
2333 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
2334 if (cap & MWL8K_CAP_DELAY_BA)
2335 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
2336 if (cap & MWL8K_CAP_40MHZ)
2337 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2339 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
2340 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
2342 band->ht_cap.mcs.rx_mask[0] = 0xff;
2343 if (rx_streams >= 2)
2344 band->ht_cap.mcs.rx_mask[1] = 0xff;
2345 if (rx_streams >= 3)
2346 band->ht_cap.mcs.rx_mask[2] = 0xff;
2347 band->ht_cap.mcs.rx_mask[4] = 0x01;
2348 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2350 if (rx_streams != tx_streams) {
2351 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
2352 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
2353 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2358 mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
2360 struct mwl8k_priv *priv = hw->priv;
2362 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
2363 mwl8k_setup_2ghz_band(hw);
2364 if (caps & MWL8K_CAP_MIMO)
2365 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
2368 if (caps & MWL8K_CAP_5GHZ) {
2369 mwl8k_setup_5ghz_band(hw);
2370 if (caps & MWL8K_CAP_MIMO)
2371 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
2375 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
2377 struct mwl8k_priv *priv = hw->priv;
2378 struct mwl8k_cmd_get_hw_spec_sta *cmd;
2382 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2386 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2387 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2389 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2390 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2391 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2392 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2393 for (i = 0; i < mwl8k_tx_queues(priv); i++)
2394 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
2395 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2396 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2398 rc = mwl8k_post_cmd(hw, &cmd->header);
2401 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2402 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2403 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2404 priv->hw_rev = cmd->hw_rev;
2405 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2406 priv->ap_macids_supported = 0x00000000;
2407 priv->sta_macids_supported = 0x00000001;
2415 * CMD_GET_HW_SPEC (AP version).
2417 struct mwl8k_cmd_get_hw_spec_ap {
2418 struct mwl8k_cmd_pkt header;
2420 __u8 host_interface;
2423 __u8 perm_addr[ETH_ALEN];
2434 __le32 fw_api_version;
2436 __le32 num_of_ampdu_queues;
2437 __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
2440 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2442 struct mwl8k_priv *priv = hw->priv;
2443 struct mwl8k_cmd_get_hw_spec_ap *cmd;
2447 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2451 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2452 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2454 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2455 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2457 rc = mwl8k_post_cmd(hw, &cmd->header);
2462 api_version = le32_to_cpu(cmd->fw_api_version);
2463 if (priv->device_info->fw_api_ap != api_version) {
2464 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2465 " Expected %d got %d.\n", MWL8K_NAME,
2466 priv->device_info->part_name,
2467 priv->device_info->fw_api_ap,
2472 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2473 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2474 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2475 priv->hw_rev = cmd->hw_rev;
2476 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2477 priv->ap_macids_supported = 0x000000ff;
2478 priv->sta_macids_supported = 0x00000000;
2479 priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
2480 if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
2481 wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
2482 " but we only support %d.\n",
2483 priv->num_ampdu_queues,
2484 MWL8K_MAX_AMPDU_QUEUES);
2485 priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
2487 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
2488 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2490 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
2491 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2493 priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
2494 priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
2495 priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
2496 priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
2498 for (i = 0; i < priv->num_ampdu_queues; i++)
2499 priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
2500 le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
2511 struct mwl8k_cmd_set_hw_spec {
2512 struct mwl8k_cmd_pkt header;
2514 __u8 host_interface;
2516 __u8 perm_addr[ETH_ALEN];
2521 __le32 rx_queue_ptr;
2522 __le32 num_tx_queues;
2523 __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
2525 __le32 num_tx_desc_per_queue;
2529 /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2530 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2531 * the packets that are queued for more than 500ms, will be dropped in the
2532 * hardware. This helps minimizing the issues caused due to head-of-line
2533 * blocking where a slow client can hog the bandwidth and affect traffic to a
2536 #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
2537 #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
2538 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2539 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2540 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
2542 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2544 struct mwl8k_priv *priv = hw->priv;
2545 struct mwl8k_cmd_set_hw_spec *cmd;
2549 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2553 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2554 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2556 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2557 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2558 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2561 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2562 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2563 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2564 * priority is interpreted the right way in firmware.
2566 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
2567 int j = mwl8k_tx_queues(priv) - 1 - i;
2568 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
2571 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2572 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
2573 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
2574 MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
2575 MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
2576 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2577 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2579 rc = mwl8k_post_cmd(hw, &cmd->header);
2586 * CMD_MAC_MULTICAST_ADR.
2588 struct mwl8k_cmd_mac_multicast_adr {
2589 struct mwl8k_cmd_pkt header;
2592 __u8 addr[0][ETH_ALEN];
2595 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
2596 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
2597 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2598 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
2600 static struct mwl8k_cmd_pkt *
2601 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
2602 struct netdev_hw_addr_list *mc_list)
2604 struct mwl8k_priv *priv = hw->priv;
2605 struct mwl8k_cmd_mac_multicast_adr *cmd;
2610 mc_count = netdev_hw_addr_list_count(mc_list);
2612 if (allmulti || mc_count > priv->num_mcaddrs) {
2617 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2619 cmd = kzalloc(size, GFP_ATOMIC);
2623 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2624 cmd->header.length = cpu_to_le16(size);
2625 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2626 MWL8K_ENABLE_RX_BROADCAST);
2629 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2630 } else if (mc_count) {
2631 struct netdev_hw_addr *ha;
2634 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2635 cmd->numaddr = cpu_to_le16(mc_count);
2636 netdev_hw_addr_list_for_each(ha, mc_list) {
2637 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
2641 return &cmd->header;
2647 struct mwl8k_cmd_get_stat {
2648 struct mwl8k_cmd_pkt header;
2652 #define MWL8K_STAT_ACK_FAILURE 9
2653 #define MWL8K_STAT_RTS_FAILURE 12
2654 #define MWL8K_STAT_FCS_ERROR 24
2655 #define MWL8K_STAT_RTS_SUCCESS 11
2657 static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2658 struct ieee80211_low_level_stats *stats)
2660 struct mwl8k_cmd_get_stat *cmd;
2663 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2667 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2668 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2670 rc = mwl8k_post_cmd(hw, &cmd->header);
2672 stats->dot11ACKFailureCount =
2673 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2674 stats->dot11RTSFailureCount =
2675 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2676 stats->dot11FCSErrorCount =
2677 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2678 stats->dot11RTSSuccessCount =
2679 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2687 * CMD_RADIO_CONTROL.
2689 struct mwl8k_cmd_radio_control {
2690 struct mwl8k_cmd_pkt header;
2697 mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
2699 struct mwl8k_priv *priv = hw->priv;
2700 struct mwl8k_cmd_radio_control *cmd;
2703 if (enable == priv->radio_on && !force)
2706 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2710 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2711 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2712 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2713 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
2714 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2716 rc = mwl8k_post_cmd(hw, &cmd->header);
2720 priv->radio_on = enable;
2725 static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
2727 return mwl8k_cmd_radio_control(hw, 0, 0);
2730 static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
2732 return mwl8k_cmd_radio_control(hw, 1, 0);
2736 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2738 struct mwl8k_priv *priv = hw->priv;
2740 priv->radio_short_preamble = short_preamble;
2742 return mwl8k_cmd_radio_control(hw, 1, 1);
2748 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2750 struct mwl8k_cmd_rf_tx_power {
2751 struct mwl8k_cmd_pkt header;
2753 __le16 support_level;
2754 __le16 current_level;
2756 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
2759 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
2761 struct mwl8k_cmd_rf_tx_power *cmd;
2764 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2768 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2769 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2770 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2771 cmd->support_level = cpu_to_le16(dBm);
2773 rc = mwl8k_post_cmd(hw, &cmd->header);
2782 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2784 struct mwl8k_cmd_tx_power {
2785 struct mwl8k_cmd_pkt header;
2791 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2794 static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2795 struct ieee80211_conf *conf,
2798 struct ieee80211_channel *channel = conf->channel;
2799 struct mwl8k_cmd_tx_power *cmd;
2803 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2807 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2808 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2809 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2811 if (channel->band == IEEE80211_BAND_2GHZ)
2812 cmd->band = cpu_to_le16(0x1);
2813 else if (channel->band == IEEE80211_BAND_5GHZ)
2814 cmd->band = cpu_to_le16(0x4);
2816 cmd->channel = cpu_to_le16(channel->hw_value);
2818 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2819 conf->channel_type == NL80211_CHAN_HT20) {
2820 cmd->bw = cpu_to_le16(0x2);
2822 cmd->bw = cpu_to_le16(0x4);
2823 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2824 cmd->sub_ch = cpu_to_le16(0x3);
2825 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2826 cmd->sub_ch = cpu_to_le16(0x1);
2829 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2830 cmd->power_level_list[i] = cpu_to_le16(pwr);
2832 rc = mwl8k_post_cmd(hw, &cmd->header);
2841 struct mwl8k_cmd_rf_antenna {
2842 struct mwl8k_cmd_pkt header;
2847 #define MWL8K_RF_ANTENNA_RX 1
2848 #define MWL8K_RF_ANTENNA_TX 2
2851 mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2853 struct mwl8k_cmd_rf_antenna *cmd;
2856 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2860 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2861 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2862 cmd->antenna = cpu_to_le16(antenna);
2863 cmd->mode = cpu_to_le16(mask);
2865 rc = mwl8k_post_cmd(hw, &cmd->header);
2874 struct mwl8k_cmd_set_beacon {
2875 struct mwl8k_cmd_pkt header;
2880 static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2881 struct ieee80211_vif *vif, u8 *beacon, int len)
2883 struct mwl8k_cmd_set_beacon *cmd;
2886 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2890 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2891 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2892 cmd->beacon_len = cpu_to_le16(len);
2893 memcpy(cmd->beacon, beacon, len);
2895 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2904 struct mwl8k_cmd_set_pre_scan {
2905 struct mwl8k_cmd_pkt header;
2908 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2910 struct mwl8k_cmd_set_pre_scan *cmd;
2913 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2917 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2918 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2920 rc = mwl8k_post_cmd(hw, &cmd->header);
2927 * CMD_SET_POST_SCAN.
2929 struct mwl8k_cmd_set_post_scan {
2930 struct mwl8k_cmd_pkt header;
2932 __u8 bssid[ETH_ALEN];
2936 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2938 struct mwl8k_cmd_set_post_scan *cmd;
2941 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2945 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2946 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2948 memcpy(cmd->bssid, mac, ETH_ALEN);
2950 rc = mwl8k_post_cmd(hw, &cmd->header);
2957 * CMD_SET_RF_CHANNEL.
2959 struct mwl8k_cmd_set_rf_channel {
2960 struct mwl8k_cmd_pkt header;
2962 __u8 current_channel;
2963 __le32 channel_flags;
2966 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2967 struct ieee80211_conf *conf)
2969 struct ieee80211_channel *channel = conf->channel;
2970 struct mwl8k_cmd_set_rf_channel *cmd;
2973 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2977 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2978 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2979 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2980 cmd->current_channel = channel->hw_value;
2982 if (channel->band == IEEE80211_BAND_2GHZ)
2983 cmd->channel_flags |= cpu_to_le32(0x00000001);
2984 else if (channel->band == IEEE80211_BAND_5GHZ)
2985 cmd->channel_flags |= cpu_to_le32(0x00000004);
2987 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2988 conf->channel_type == NL80211_CHAN_HT20)
2989 cmd->channel_flags |= cpu_to_le32(0x00000080);
2990 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2991 cmd->channel_flags |= cpu_to_le32(0x000001900);
2992 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2993 cmd->channel_flags |= cpu_to_le32(0x000000900);
2995 rc = mwl8k_post_cmd(hw, &cmd->header);
3004 #define MWL8K_FRAME_PROT_DISABLED 0x00
3005 #define MWL8K_FRAME_PROT_11G 0x07
3006 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
3007 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
3009 struct mwl8k_cmd_update_set_aid {
3010 struct mwl8k_cmd_pkt header;
3013 /* AP's MAC address (BSSID) */
3014 __u8 bssid[ETH_ALEN];
3015 __le16 protection_mode;
3016 __u8 supp_rates[14];
3019 static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
3025 * Clear nonstandard rates 4 and 13.
3029 for (i = 0, j = 0; i < 14; i++) {
3030 if (mask & (1 << i))
3031 rates[j++] = mwl8k_rates_24[i].hw_value;
3036 mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
3037 struct ieee80211_vif *vif, u32 legacy_rate_mask)
3039 struct mwl8k_cmd_update_set_aid *cmd;
3043 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3047 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
3048 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3049 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
3050 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
3052 if (vif->bss_conf.use_cts_prot) {
3053 prot_mode = MWL8K_FRAME_PROT_11G;
3055 switch (vif->bss_conf.ht_operation_mode &
3056 IEEE80211_HT_OP_MODE_PROTECTION) {
3057 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
3058 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
3060 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
3061 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
3064 prot_mode = MWL8K_FRAME_PROT_DISABLED;
3068 cmd->protection_mode = cpu_to_le16(prot_mode);
3070 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
3072 rc = mwl8k_post_cmd(hw, &cmd->header);
3081 struct mwl8k_cmd_set_rate {
3082 struct mwl8k_cmd_pkt header;
3083 __u8 legacy_rates[14];
3085 /* Bitmap for supported MCS codes. */
3091 mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3092 u32 legacy_rate_mask, u8 *mcs_rates)
3094 struct mwl8k_cmd_set_rate *cmd;
3097 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3101 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
3102 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3103 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
3104 memcpy(cmd->mcs_set, mcs_rates, 16);
3106 rc = mwl8k_post_cmd(hw, &cmd->header);
3113 * CMD_FINALIZE_JOIN.
3115 #define MWL8K_FJ_BEACON_MAXLEN 128
3117 struct mwl8k_cmd_finalize_join {
3118 struct mwl8k_cmd_pkt header;
3119 __le32 sleep_interval; /* Number of beacon periods to sleep */
3120 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
3123 static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
3124 int framelen, int dtim)
3126 struct mwl8k_cmd_finalize_join *cmd;
3127 struct ieee80211_mgmt *payload = frame;
3131 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3135 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
3136 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3137 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
3139 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
3140 if (payload_len < 0)
3142 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
3143 payload_len = MWL8K_FJ_BEACON_MAXLEN;
3145 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
3147 rc = mwl8k_post_cmd(hw, &cmd->header);
3154 * CMD_SET_RTS_THRESHOLD.
3156 struct mwl8k_cmd_set_rts_threshold {
3157 struct mwl8k_cmd_pkt header;
3163 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
3165 struct mwl8k_cmd_set_rts_threshold *cmd;
3168 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3172 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
3173 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3174 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3175 cmd->threshold = cpu_to_le16(rts_thresh);
3177 rc = mwl8k_post_cmd(hw, &cmd->header);
3186 struct mwl8k_cmd_set_slot {
3187 struct mwl8k_cmd_pkt header;
3192 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
3194 struct mwl8k_cmd_set_slot *cmd;
3197 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3201 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
3202 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3203 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3204 cmd->short_slot = short_slot_time;
3206 rc = mwl8k_post_cmd(hw, &cmd->header);
3213 * CMD_SET_EDCA_PARAMS.
3215 struct mwl8k_cmd_set_edca_params {
3216 struct mwl8k_cmd_pkt header;
3218 /* See MWL8K_SET_EDCA_XXX below */
3221 /* TX opportunity in units of 32 us */
3226 /* Log exponent of max contention period: 0...15 */
3229 /* Log exponent of min contention period: 0...15 */
3232 /* Adaptive interframe spacing in units of 32us */
3235 /* TX queue to configure */
3239 /* Log exponent of max contention period: 0...15 */
3242 /* Log exponent of min contention period: 0...15 */
3245 /* Adaptive interframe spacing in units of 32us */
3248 /* TX queue to configure */
3254 #define MWL8K_SET_EDCA_CW 0x01
3255 #define MWL8K_SET_EDCA_TXOP 0x02
3256 #define MWL8K_SET_EDCA_AIFS 0x04
3258 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3259 MWL8K_SET_EDCA_TXOP | \
3260 MWL8K_SET_EDCA_AIFS)
3263 mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
3264 __u16 cw_min, __u16 cw_max,
3265 __u8 aifs, __u16 txop)
3267 struct mwl8k_priv *priv = hw->priv;
3268 struct mwl8k_cmd_set_edca_params *cmd;
3271 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3275 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
3276 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3277 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
3278 cmd->txop = cpu_to_le16(txop);
3280 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
3281 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
3282 cmd->ap.aifs = aifs;
3285 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
3286 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
3287 cmd->sta.aifs = aifs;
3288 cmd->sta.txq = qnum;
3291 rc = mwl8k_post_cmd(hw, &cmd->header);
3300 struct mwl8k_cmd_set_wmm_mode {
3301 struct mwl8k_cmd_pkt header;
3305 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
3307 struct mwl8k_priv *priv = hw->priv;
3308 struct mwl8k_cmd_set_wmm_mode *cmd;
3311 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3315 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
3316 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3317 cmd->action = cpu_to_le16(!!enable);
3319 rc = mwl8k_post_cmd(hw, &cmd->header);
3323 priv->wmm_enabled = enable;
3331 struct mwl8k_cmd_mimo_config {
3332 struct mwl8k_cmd_pkt header;
3334 __u8 rx_antenna_map;
3335 __u8 tx_antenna_map;
3338 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
3340 struct mwl8k_cmd_mimo_config *cmd;
3343 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3347 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
3348 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3349 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
3350 cmd->rx_antenna_map = rx;
3351 cmd->tx_antenna_map = tx;
3353 rc = mwl8k_post_cmd(hw, &cmd->header);
3360 * CMD_USE_FIXED_RATE (STA version).
3362 struct mwl8k_cmd_use_fixed_rate_sta {
3363 struct mwl8k_cmd_pkt header;
3365 __le32 allow_rate_drop;
3369 __le32 enable_retry;
3378 #define MWL8K_USE_AUTO_RATE 0x0002
3379 #define MWL8K_UCAST_RATE 0
3381 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
3383 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
3386 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3390 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3391 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3392 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3393 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
3395 rc = mwl8k_post_cmd(hw, &cmd->header);
3402 * CMD_USE_FIXED_RATE (AP version).
3404 struct mwl8k_cmd_use_fixed_rate_ap {
3405 struct mwl8k_cmd_pkt header;
3407 __le32 allow_rate_drop;
3409 struct mwl8k_rate_entry_ap {
3411 __le32 enable_retry;
3416 u8 multicast_rate_type;
3421 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
3423 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
3426 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3430 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3431 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3432 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3433 cmd->multicast_rate = mcast;
3434 cmd->management_rate = mgmt;
3436 rc = mwl8k_post_cmd(hw, &cmd->header);
3443 * CMD_ENABLE_SNIFFER.
3445 struct mwl8k_cmd_enable_sniffer {
3446 struct mwl8k_cmd_pkt header;
3450 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3452 struct mwl8k_cmd_enable_sniffer *cmd;
3455 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3459 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3460 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3461 cmd->action = cpu_to_le32(!!enable);
3463 rc = mwl8k_post_cmd(hw, &cmd->header);
3469 struct mwl8k_cmd_update_mac_addr {
3470 struct mwl8k_cmd_pkt header;
3474 __u8 mac_addr[ETH_ALEN];
3476 __u8 mac_addr[ETH_ALEN];
3480 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3481 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3482 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
3483 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
3485 static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
3486 struct ieee80211_vif *vif, u8 *mac, bool set)
3488 struct mwl8k_priv *priv = hw->priv;
3489 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3490 struct mwl8k_cmd_update_mac_addr *cmd;
3494 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3495 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3496 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
3497 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
3499 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3500 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3501 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3502 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3504 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3507 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3512 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3514 cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
3516 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3518 cmd->mbss.mac_type = cpu_to_le16(mac_type);
3519 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3521 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3524 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3531 * MWL8K_CMD_SET_MAC_ADDR.
3533 static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3534 struct ieee80211_vif *vif, u8 *mac)
3536 return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
3540 * MWL8K_CMD_DEL_MAC_ADDR.
3542 static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
3543 struct ieee80211_vif *vif, u8 *mac)
3545 return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
3549 * CMD_SET_RATEADAPT_MODE.
3551 struct mwl8k_cmd_set_rate_adapt_mode {
3552 struct mwl8k_cmd_pkt header;
3557 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3559 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
3562 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3566 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
3567 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3568 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3569 cmd->mode = cpu_to_le16(mode);
3571 rc = mwl8k_post_cmd(hw, &cmd->header);
3578 * CMD_GET_WATCHDOG_BITMAP.
3580 struct mwl8k_cmd_get_watchdog_bitmap {
3581 struct mwl8k_cmd_pkt header;
3585 static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
3587 struct mwl8k_cmd_get_watchdog_bitmap *cmd;
3590 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3594 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
3595 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3597 rc = mwl8k_post_cmd(hw, &cmd->header);
3599 *bitmap = cmd->bitmap;
3606 #define INVALID_BA 0xAA
3607 static void mwl8k_watchdog_ba_events(struct work_struct *work)
3610 u8 bitmap = 0, stream_index;
3611 struct mwl8k_ampdu_stream *streams;
3612 struct mwl8k_priv *priv =
3613 container_of(work, struct mwl8k_priv, watchdog_ba_handle);
3615 rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
3619 if (bitmap == INVALID_BA)
3622 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
3623 stream_index = bitmap - MWL8K_TX_WMM_QUEUES;
3625 BUG_ON(stream_index >= priv->num_ampdu_queues);
3627 streams = &priv->ampdu[stream_index];
3629 if (streams->state == AMPDU_STREAM_ACTIVE)
3630 ieee80211_stop_tx_ba_session(streams->sta, streams->tid);
3639 struct mwl8k_cmd_bss_start {
3640 struct mwl8k_cmd_pkt header;
3644 static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3645 struct ieee80211_vif *vif, int enable)
3647 struct mwl8k_cmd_bss_start *cmd;
3650 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3654 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3655 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3656 cmd->enable = cpu_to_le32(enable);
3658 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3669 * UPSTREAM is tx direction
3671 #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3672 #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3674 enum ba_stream_action_type {
3683 struct mwl8k_create_ba_stream {
3688 u8 peer_mac_addr[6];
3694 u8 reset_seq_no_flag;
3696 u8 sta_src_mac_addr[6];
3699 struct mwl8k_destroy_ba_stream {
3704 struct mwl8k_cmd_bastream {
3705 struct mwl8k_cmd_pkt header;
3708 struct mwl8k_create_ba_stream create_params;
3709 struct mwl8k_destroy_ba_stream destroy_params;
3714 mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3715 struct ieee80211_vif *vif)
3717 struct mwl8k_cmd_bastream *cmd;
3720 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3724 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3725 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3727 cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
3729 cmd->create_params.queue_id = stream->idx;
3730 memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
3732 cmd->create_params.tid = stream->tid;
3734 cmd->create_params.flags =
3735 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
3736 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
3738 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3746 mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3747 u8 buf_size, struct ieee80211_vif *vif)
3749 struct mwl8k_cmd_bastream *cmd;
3752 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3757 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3758 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3760 cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
3762 cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
3763 cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
3764 cmd->create_params.queue_id = stream->idx;
3766 memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
3767 cmd->create_params.tid = stream->tid;
3768 cmd->create_params.curr_seq_no = cpu_to_le16(0);
3769 cmd->create_params.reset_seq_no_flag = 1;
3771 cmd->create_params.param_info =
3772 (stream->sta->ht_cap.ampdu_factor &
3773 IEEE80211_HT_AMPDU_PARM_FACTOR) |
3774 ((stream->sta->ht_cap.ampdu_density << 2) &
3775 IEEE80211_HT_AMPDU_PARM_DENSITY);
3777 cmd->create_params.flags =
3778 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
3779 BASTREAM_FLAG_DIRECTION_UPSTREAM);
3781 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3783 wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
3784 stream->sta->addr, stream->tid);
3790 static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3791 struct mwl8k_ampdu_stream *stream)
3793 struct mwl8k_cmd_bastream *cmd;
3795 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3799 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3800 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3801 cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
3803 cmd->destroy_params.ba_context = cpu_to_le32(stream->idx);
3804 mwl8k_post_cmd(hw, &cmd->header);
3806 wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", stream->idx);
3814 struct mwl8k_cmd_set_new_stn {
3815 struct mwl8k_cmd_pkt header;
3821 __le32 legacy_rates;
3824 __le16 ht_capabilities_info;
3825 __u8 mac_ht_param_info;
3827 __u8 control_channel;
3836 #define MWL8K_STA_ACTION_ADD 0
3837 #define MWL8K_STA_ACTION_REMOVE 2
3839 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3840 struct ieee80211_vif *vif,
3841 struct ieee80211_sta *sta)
3843 struct mwl8k_cmd_set_new_stn *cmd;
3847 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3851 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3852 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3853 cmd->aid = cpu_to_le16(sta->aid);
3854 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3855 cmd->stn_id = cpu_to_le16(sta->aid);
3856 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
3857 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3858 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3860 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3861 cmd->legacy_rates = cpu_to_le32(rates);
3862 if (sta->ht_cap.ht_supported) {
3863 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3864 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3865 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3866 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3867 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3868 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3869 ((sta->ht_cap.ampdu_density & 7) << 2);
3870 cmd->is_qos_sta = 1;
3873 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3879 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3880 struct ieee80211_vif *vif)
3882 struct mwl8k_cmd_set_new_stn *cmd;
3885 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3889 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3890 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3891 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3893 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3899 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
3900 struct ieee80211_vif *vif, u8 *addr)
3902 struct mwl8k_cmd_set_new_stn *cmd;
3905 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3909 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3910 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3911 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3912 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
3914 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3921 * CMD_UPDATE_ENCRYPTION.
3924 #define MAX_ENCR_KEY_LENGTH 16
3925 #define MIC_KEY_LENGTH 8
3927 struct mwl8k_cmd_update_encryption {
3928 struct mwl8k_cmd_pkt header;
3937 struct mwl8k_cmd_set_key {
3938 struct mwl8k_cmd_pkt header;
3947 __u8 key_material[MAX_ENCR_KEY_LENGTH];
3948 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
3949 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
3950 __le16 tkip_rsc_low;
3951 __le32 tkip_rsc_high;
3952 __le16 tkip_tsc_low;
3953 __le32 tkip_tsc_high;
3960 MWL8K_ENCR_REMOVE_KEY,
3961 MWL8K_ENCR_SET_GROUP_KEY,
3964 #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
3965 #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
3966 #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
3967 #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
3968 #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
3976 #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
3977 #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
3978 #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
3979 #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
3980 #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
3982 static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
3983 struct ieee80211_vif *vif,
3987 struct mwl8k_cmd_update_encryption *cmd;
3990 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3994 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3995 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3996 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
3997 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3998 cmd->encr_type = encr_type;
4000 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4006 static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
4008 struct ieee80211_key_conf *key)
4010 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4011 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4012 cmd->length = cpu_to_le16(sizeof(*cmd) -
4013 offsetof(struct mwl8k_cmd_set_key, length));
4014 cmd->key_id = cpu_to_le32(key->keyidx);
4015 cmd->key_len = cpu_to_le16(key->keylen);
4016 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4018 switch (key->cipher) {
4019 case WLAN_CIPHER_SUITE_WEP40:
4020 case WLAN_CIPHER_SUITE_WEP104:
4021 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
4022 if (key->keyidx == 0)
4023 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
4026 case WLAN_CIPHER_SUITE_TKIP:
4027 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
4028 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4029 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4030 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4031 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
4032 | MWL8K_KEY_FLAG_TSC_VALID);
4034 case WLAN_CIPHER_SUITE_CCMP:
4035 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
4036 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4037 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4038 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4047 static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
4048 struct ieee80211_vif *vif,
4050 struct ieee80211_key_conf *key)
4052 struct mwl8k_cmd_set_key *cmd;
4057 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4059 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4063 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4069 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4070 action = MWL8K_ENCR_SET_KEY;
4072 action = MWL8K_ENCR_SET_GROUP_KEY;
4074 switch (key->cipher) {
4075 case WLAN_CIPHER_SUITE_WEP40:
4076 case WLAN_CIPHER_SUITE_WEP104:
4077 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
4078 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
4079 sizeof(*key) + key->keylen);
4080 mwl8k_vif->wep_key_conf[idx].enabled = 1;
4083 keymlen = key->keylen;
4084 action = MWL8K_ENCR_SET_KEY;
4086 case WLAN_CIPHER_SUITE_TKIP:
4087 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
4089 case WLAN_CIPHER_SUITE_CCMP:
4090 keymlen = key->keylen;
4097 memcpy(cmd->key_material, key->key, keymlen);
4098 cmd->action = cpu_to_le32(action);
4100 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4107 static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
4108 struct ieee80211_vif *vif,
4110 struct ieee80211_key_conf *key)
4112 struct mwl8k_cmd_set_key *cmd;
4114 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4116 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4120 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4124 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4125 key->cipher == WLAN_CIPHER_SUITE_WEP104)
4126 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
4128 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
4130 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4137 static int mwl8k_set_key(struct ieee80211_hw *hw,
4138 enum set_key_cmd cmd_param,
4139 struct ieee80211_vif *vif,
4140 struct ieee80211_sta *sta,
4141 struct ieee80211_key_conf *key)
4146 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4148 if (vif->type == NL80211_IFTYPE_STATION)
4156 if (cmd_param == SET_KEY) {
4157 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
4161 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
4162 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
4163 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
4165 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
4167 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
4172 mwl8k_vif->is_hw_crypto_enabled = true;
4175 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
4187 struct ewc_ht_info {
4193 struct peer_capability_info {
4194 /* Peer type - AP vs. STA. */
4197 /* Basic 802.11 capabilities from assoc resp. */
4200 /* Set if peer supports 802.11n high throughput (HT). */
4203 /* Valid if HT is supported. */
4205 __u8 extended_ht_caps;
4206 struct ewc_ht_info ewc_info;
4208 /* Legacy rate table. Intersection of our rates and peer rates. */
4209 __u8 legacy_rates[12];
4211 /* HT rate table. Intersection of our rates and peer rates. */
4215 /* If set, interoperability mode, no proprietary extensions. */
4219 __le16 amsdu_enabled;
4222 struct mwl8k_cmd_update_stadb {
4223 struct mwl8k_cmd_pkt header;
4225 /* See STADB_ACTION_TYPE */
4228 /* Peer MAC address */
4229 __u8 peer_addr[ETH_ALEN];
4233 /* Peer info - valid during add/update. */
4234 struct peer_capability_info peer_info;
4237 #define MWL8K_STA_DB_MODIFY_ENTRY 1
4238 #define MWL8K_STA_DB_DEL_ENTRY 2
4240 /* Peer Entry flags - used to define the type of the peer node */
4241 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
4243 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
4244 struct ieee80211_vif *vif,
4245 struct ieee80211_sta *sta)
4247 struct mwl8k_cmd_update_stadb *cmd;
4248 struct peer_capability_info *p;
4252 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4256 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4257 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4258 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
4259 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
4261 p = &cmd->peer_info;
4262 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
4263 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
4264 p->ht_support = sta->ht_cap.ht_supported;
4265 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
4266 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
4267 ((sta->ht_cap.ampdu_density & 7) << 2);
4268 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4269 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
4271 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4272 legacy_rate_mask_to_array(p->legacy_rates, rates);
4273 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
4275 p->amsdu_enabled = 0;
4277 rc = mwl8k_post_cmd(hw, &cmd->header);
4280 return rc ? rc : p->station_id;
4283 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
4284 struct ieee80211_vif *vif, u8 *addr)
4286 struct mwl8k_cmd_update_stadb *cmd;
4289 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4293 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4294 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4295 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
4296 memcpy(cmd->peer_addr, addr, ETH_ALEN);
4298 rc = mwl8k_post_cmd(hw, &cmd->header);
4306 * Interrupt handling.
4308 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
4310 struct ieee80211_hw *hw = dev_id;
4311 struct mwl8k_priv *priv = hw->priv;
4314 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4318 if (status & MWL8K_A2H_INT_TX_DONE) {
4319 status &= ~MWL8K_A2H_INT_TX_DONE;
4320 tasklet_schedule(&priv->poll_tx_task);
4323 if (status & MWL8K_A2H_INT_RX_READY) {
4324 status &= ~MWL8K_A2H_INT_RX_READY;
4325 tasklet_schedule(&priv->poll_rx_task);
4328 if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
4329 status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
4330 ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
4334 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4336 if (status & MWL8K_A2H_INT_OPC_DONE) {
4337 if (priv->hostcmd_wait != NULL)
4338 complete(priv->hostcmd_wait);
4341 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
4342 if (!mutex_is_locked(&priv->fw_mutex) &&
4343 priv->radio_on && priv->pending_tx_pkts)
4344 mwl8k_tx_start(priv);
4350 static void mwl8k_tx_poll(unsigned long data)
4352 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4353 struct mwl8k_priv *priv = hw->priv;
4359 spin_lock_bh(&priv->tx_lock);
4361 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4362 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
4364 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
4365 complete(priv->tx_wait);
4366 priv->tx_wait = NULL;
4369 spin_unlock_bh(&priv->tx_lock);
4372 writel(~MWL8K_A2H_INT_TX_DONE,
4373 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4375 tasklet_schedule(&priv->poll_tx_task);
4379 static void mwl8k_rx_poll(unsigned long data)
4381 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4382 struct mwl8k_priv *priv = hw->priv;
4386 limit -= rxq_process(hw, 0, limit);
4387 limit -= rxq_refill(hw, 0, limit);
4390 writel(~MWL8K_A2H_INT_RX_READY,
4391 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4393 tasklet_schedule(&priv->poll_rx_task);
4399 * Core driver operations.
4401 static void mwl8k_tx(struct ieee80211_hw *hw,
4402 struct ieee80211_tx_control *control,
4403 struct sk_buff *skb)
4405 struct mwl8k_priv *priv = hw->priv;
4406 int index = skb_get_queue_mapping(skb);
4408 if (!priv->radio_on) {
4409 wiphy_debug(hw->wiphy,
4410 "dropped TX frame since radio disabled\n");
4415 mwl8k_txq_xmit(hw, index, control->sta, skb);
4418 static int mwl8k_start(struct ieee80211_hw *hw)
4420 struct mwl8k_priv *priv = hw->priv;
4423 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
4424 IRQF_SHARED, MWL8K_NAME, hw);
4427 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
4430 priv->irq = priv->pdev->irq;
4432 /* Enable TX reclaim and RX tasklets. */
4433 tasklet_enable(&priv->poll_tx_task);
4434 tasklet_enable(&priv->poll_rx_task);
4436 /* Enable interrupts */
4437 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4438 iowrite32(MWL8K_A2H_EVENTS,
4439 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4441 rc = mwl8k_fw_lock(hw);
4443 rc = mwl8k_cmd_radio_enable(hw);
4447 rc = mwl8k_cmd_enable_sniffer(hw, 0);
4450 rc = mwl8k_cmd_set_pre_scan(hw);
4453 rc = mwl8k_cmd_set_post_scan(hw,
4454 "\x00\x00\x00\x00\x00\x00");
4458 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
4461 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
4463 mwl8k_fw_unlock(hw);
4467 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4468 free_irq(priv->pdev->irq, hw);
4470 tasklet_disable(&priv->poll_tx_task);
4471 tasklet_disable(&priv->poll_rx_task);
4477 static void mwl8k_stop(struct ieee80211_hw *hw)
4479 struct mwl8k_priv *priv = hw->priv;
4482 if (!priv->hw_restart_in_progress)
4483 mwl8k_cmd_radio_disable(hw);
4485 ieee80211_stop_queues(hw);
4487 /* Disable interrupts */
4488 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4489 if (priv->irq != -1) {
4490 free_irq(priv->pdev->irq, hw);
4494 /* Stop finalize join worker */
4495 cancel_work_sync(&priv->finalize_join_worker);
4496 cancel_work_sync(&priv->watchdog_ba_handle);
4497 if (priv->beacon_skb != NULL)
4498 dev_kfree_skb(priv->beacon_skb);
4500 /* Stop TX reclaim and RX tasklets. */
4501 tasklet_disable(&priv->poll_tx_task);
4502 tasklet_disable(&priv->poll_rx_task);
4504 /* Return all skbs to mac80211 */
4505 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4506 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
4509 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
4511 static int mwl8k_add_interface(struct ieee80211_hw *hw,
4512 struct ieee80211_vif *vif)
4514 struct mwl8k_priv *priv = hw->priv;
4515 struct mwl8k_vif *mwl8k_vif;
4516 u32 macids_supported;
4518 struct mwl8k_device_info *di;
4521 * Reject interface creation if sniffer mode is active, as
4522 * STA operation is mutually exclusive with hardware sniffer
4523 * mode. (Sniffer mode is only used on STA firmware.)
4525 if (priv->sniffer_enabled) {
4526 wiphy_info(hw->wiphy,
4527 "unable to create STA interface because sniffer mode is enabled\n");
4531 di = priv->device_info;
4532 switch (vif->type) {
4533 case NL80211_IFTYPE_AP:
4534 if (!priv->ap_fw && di->fw_image_ap) {
4535 /* we must load the ap fw to meet this request */
4536 if (!list_empty(&priv->vif_list))
4538 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4542 macids_supported = priv->ap_macids_supported;
4544 case NL80211_IFTYPE_STATION:
4545 if (priv->ap_fw && di->fw_image_sta) {
4546 /* we must load the sta fw to meet this request */
4547 if (!list_empty(&priv->vif_list))
4549 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4553 macids_supported = priv->sta_macids_supported;
4559 macid = ffs(macids_supported & ~priv->macids_used);
4563 /* Setup driver private area. */
4564 mwl8k_vif = MWL8K_VIF(vif);
4565 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
4566 mwl8k_vif->vif = vif;
4567 mwl8k_vif->macid = macid;
4568 mwl8k_vif->seqno = 0;
4569 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
4570 mwl8k_vif->is_hw_crypto_enabled = false;
4572 /* Set the mac address. */
4573 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
4576 mwl8k_cmd_set_new_stn_add_self(hw, vif);
4578 priv->macids_used |= 1 << mwl8k_vif->macid;
4579 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
4584 static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
4586 /* Has ieee80211_restart_hw re-added the removed interfaces? */
4587 if (!priv->macids_used)
4590 priv->macids_used &= ~(1 << vif->macid);
4591 list_del(&vif->list);
4594 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
4595 struct ieee80211_vif *vif)
4597 struct mwl8k_priv *priv = hw->priv;
4598 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4601 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
4603 mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
4605 mwl8k_remove_vif(priv, mwl8k_vif);
4608 static void mwl8k_hw_restart_work(struct work_struct *work)
4610 struct mwl8k_priv *priv =
4611 container_of(work, struct mwl8k_priv, fw_reload);
4612 struct ieee80211_hw *hw = priv->hw;
4613 struct mwl8k_device_info *di;
4616 /* If some command is waiting for a response, clear it */
4617 if (priv->hostcmd_wait != NULL) {
4618 complete(priv->hostcmd_wait);
4619 priv->hostcmd_wait = NULL;
4622 priv->hw_restart_owner = current;
4623 di = priv->device_info;
4627 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4629 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4634 priv->hw_restart_owner = NULL;
4635 priv->hw_restart_in_progress = false;
4638 * This unlock will wake up the queues and
4639 * also opens the command path for other
4642 mwl8k_fw_unlock(hw);
4644 ieee80211_restart_hw(hw);
4646 wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
4650 mwl8k_fw_unlock(hw);
4652 wiphy_err(hw->wiphy, "Firmware restart failed\n");
4655 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
4657 struct ieee80211_conf *conf = &hw->conf;
4658 struct mwl8k_priv *priv = hw->priv;
4661 if (conf->flags & IEEE80211_CONF_IDLE) {
4662 mwl8k_cmd_radio_disable(hw);
4666 rc = mwl8k_fw_lock(hw);
4670 rc = mwl8k_cmd_radio_enable(hw);
4674 rc = mwl8k_cmd_set_rf_channel(hw, conf);
4678 if (conf->power_level > 18)
4679 conf->power_level = 18;
4683 if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
4684 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
4689 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
4691 wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
4692 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
4694 wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
4697 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
4700 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
4704 mwl8k_fw_unlock(hw);
4710 mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4711 struct ieee80211_bss_conf *info, u32 changed)
4713 struct mwl8k_priv *priv = hw->priv;
4714 u32 ap_legacy_rates = 0;
4715 u8 ap_mcs_rates[16];
4718 if (mwl8k_fw_lock(hw))
4722 * No need to capture a beacon if we're no longer associated.
4724 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
4725 priv->capture_beacon = false;
4728 * Get the AP's legacy and MCS rates.
4730 if (vif->bss_conf.assoc) {
4731 struct ieee80211_sta *ap;
4735 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
4741 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
4742 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
4745 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4747 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
4752 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
4753 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
4757 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
4762 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4763 rc = mwl8k_set_radio_preamble(hw,
4764 vif->bss_conf.use_short_preamble);
4769 if (changed & BSS_CHANGED_ERP_SLOT) {
4770 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
4775 if (vif->bss_conf.assoc &&
4776 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4778 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
4783 if (vif->bss_conf.assoc &&
4784 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
4786 * Finalize the join. Tell rx handler to process
4787 * next beacon from our BSSID.
4789 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
4790 priv->capture_beacon = true;
4794 mwl8k_fw_unlock(hw);
4798 mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4799 struct ieee80211_bss_conf *info, u32 changed)
4803 if (mwl8k_fw_lock(hw))
4806 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4807 rc = mwl8k_set_radio_preamble(hw,
4808 vif->bss_conf.use_short_preamble);
4813 if (changed & BSS_CHANGED_BASIC_RATES) {
4818 * Use lowest supported basic rate for multicasts
4819 * and management frames (such as probe responses --
4820 * beacons will always go out at 1 Mb/s).
4822 idx = ffs(vif->bss_conf.basic_rates);
4826 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4827 rate = mwl8k_rates_24[idx].hw_value;
4829 rate = mwl8k_rates_50[idx].hw_value;
4831 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4834 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
4835 struct sk_buff *skb;
4837 skb = ieee80211_beacon_get(hw, vif);
4839 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
4844 if (changed & BSS_CHANGED_BEACON_ENABLED)
4845 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
4848 mwl8k_fw_unlock(hw);
4852 mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4853 struct ieee80211_bss_conf *info, u32 changed)
4855 struct mwl8k_priv *priv = hw->priv;
4858 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
4860 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
4863 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
4864 struct netdev_hw_addr_list *mc_list)
4866 struct mwl8k_cmd_pkt *cmd;
4869 * Synthesize and return a command packet that programs the
4870 * hardware multicast address filter. At this point we don't
4871 * know whether FIF_ALLMULTI is being requested, but if it is,
4872 * we'll end up throwing this packet away and creating a new
4873 * one in mwl8k_configure_filter().
4875 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
4877 return (unsigned long)cmd;
4881 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
4882 unsigned int changed_flags,
4883 unsigned int *total_flags)
4885 struct mwl8k_priv *priv = hw->priv;
4888 * Hardware sniffer mode is mutually exclusive with STA
4889 * operation, so refuse to enable sniffer mode if a STA
4890 * interface is active.
4892 if (!list_empty(&priv->vif_list)) {
4893 if (net_ratelimit())
4894 wiphy_info(hw->wiphy,
4895 "not enabling sniffer mode because STA interface is active\n");
4899 if (!priv->sniffer_enabled) {
4900 if (mwl8k_cmd_enable_sniffer(hw, 1))
4902 priv->sniffer_enabled = true;
4905 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
4906 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
4912 static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
4914 if (!list_empty(&priv->vif_list))
4915 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
4920 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
4921 unsigned int changed_flags,
4922 unsigned int *total_flags,
4925 struct mwl8k_priv *priv = hw->priv;
4926 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
4929 * AP firmware doesn't allow fine-grained control over
4930 * the receive filter.
4933 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4939 * Enable hardware sniffer mode if FIF_CONTROL or
4940 * FIF_OTHER_BSS is requested.
4942 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
4943 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
4948 /* Clear unsupported feature flags */
4949 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4951 if (mwl8k_fw_lock(hw)) {
4956 if (priv->sniffer_enabled) {
4957 mwl8k_cmd_enable_sniffer(hw, 0);
4958 priv->sniffer_enabled = false;
4961 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
4962 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
4964 * Disable the BSS filter.
4966 mwl8k_cmd_set_pre_scan(hw);
4968 struct mwl8k_vif *mwl8k_vif;
4972 * Enable the BSS filter.
4974 * If there is an active STA interface, use that
4975 * interface's BSSID, otherwise use a dummy one
4976 * (where the OUI part needs to be nonzero for
4977 * the BSSID to be accepted by POST_SCAN).
4979 mwl8k_vif = mwl8k_first_vif(priv);
4980 if (mwl8k_vif != NULL)
4981 bssid = mwl8k_vif->vif->bss_conf.bssid;
4983 bssid = "\x01\x00\x00\x00\x00\x00";
4985 mwl8k_cmd_set_post_scan(hw, bssid);
4990 * If FIF_ALLMULTI is being requested, throw away the command
4991 * packet that ->prepare_multicast() built and replace it with
4992 * a command packet that enables reception of all multicast
4995 if (*total_flags & FIF_ALLMULTI) {
4997 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
5001 mwl8k_post_cmd(hw, cmd);
5005 mwl8k_fw_unlock(hw);
5008 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5010 return mwl8k_cmd_set_rts_threshold(hw, value);
5013 static int mwl8k_sta_remove(struct ieee80211_hw *hw,
5014 struct ieee80211_vif *vif,
5015 struct ieee80211_sta *sta)
5017 struct mwl8k_priv *priv = hw->priv;
5020 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
5022 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
5025 static int mwl8k_sta_add(struct ieee80211_hw *hw,
5026 struct ieee80211_vif *vif,
5027 struct ieee80211_sta *sta)
5029 struct mwl8k_priv *priv = hw->priv;
5032 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
5033 struct ieee80211_key_conf *key;
5036 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
5038 MWL8K_STA(sta)->peer_id = ret;
5039 if (sta->ht_cap.ht_supported)
5040 MWL8K_STA(sta)->is_ampdu_allowed = true;
5045 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
5048 for (i = 0; i < NUM_WEP_KEYS; i++) {
5049 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
5050 if (mwl8k_vif->wep_key_conf[i].enabled)
5051 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
5056 static int mwl8k_conf_tx(struct ieee80211_hw *hw,
5057 struct ieee80211_vif *vif, u16 queue,
5058 const struct ieee80211_tx_queue_params *params)
5060 struct mwl8k_priv *priv = hw->priv;
5063 rc = mwl8k_fw_lock(hw);
5065 BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
5066 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
5068 if (!priv->wmm_enabled)
5069 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
5072 int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
5073 rc = mwl8k_cmd_set_edca_params(hw, q,
5080 mwl8k_fw_unlock(hw);
5086 static int mwl8k_get_stats(struct ieee80211_hw *hw,
5087 struct ieee80211_low_level_stats *stats)
5089 return mwl8k_cmd_get_stat(hw, stats);
5092 static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
5093 struct survey_info *survey)
5095 struct mwl8k_priv *priv = hw->priv;
5096 struct ieee80211_conf *conf = &hw->conf;
5101 survey->channel = conf->channel;
5102 survey->filled = SURVEY_INFO_NOISE_DBM;
5103 survey->noise = priv->noise;
5108 #define MAX_AMPDU_ATTEMPTS 5
5111 mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5112 enum ieee80211_ampdu_mlme_action action,
5113 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5118 struct mwl8k_priv *priv = hw->priv;
5119 struct mwl8k_ampdu_stream *stream;
5120 u8 *addr = sta->addr;
5121 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
5123 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
5126 spin_lock(&priv->stream_lock);
5127 stream = mwl8k_lookup_stream(hw, addr, tid);
5130 case IEEE80211_AMPDU_RX_START:
5131 case IEEE80211_AMPDU_RX_STOP:
5133 case IEEE80211_AMPDU_TX_START:
5134 /* By the time we get here the hw queues may contain outgoing
5135 * packets for this RA/TID that are not part of this BA
5136 * session. The hw will assign sequence numbers to these
5137 * packets as they go out. So if we query the hw for its next
5138 * sequence number and use that for the SSN here, it may end up
5139 * being wrong, which will lead to sequence number mismatch at
5140 * the recipient. To avoid this, we reset the sequence number
5141 * to O for the first MPDU in this BA stream.
5144 if (stream == NULL) {
5145 /* This means that somebody outside this driver called
5146 * ieee80211_start_tx_ba_session. This is unexpected
5147 * because we do our own rate control. Just warn and
5150 wiphy_warn(hw->wiphy, "Unexpected call to %s. "
5151 "Proceeding anyway.\n", __func__);
5152 stream = mwl8k_add_stream(hw, sta, tid);
5154 if (stream == NULL) {
5155 wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
5159 stream->state = AMPDU_STREAM_IN_PROGRESS;
5161 /* Release the lock before we do the time consuming stuff */
5162 spin_unlock(&priv->stream_lock);
5163 for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
5165 /* Check if link is still valid */
5166 if (!sta_info->is_ampdu_allowed) {
5167 spin_lock(&priv->stream_lock);
5168 mwl8k_remove_stream(hw, stream);
5169 spin_unlock(&priv->stream_lock);
5173 rc = mwl8k_check_ba(hw, stream, vif);
5175 /* If HW restart is in progress mwl8k_post_cmd will
5176 * return -EBUSY. Avoid retrying mwl8k_check_ba in
5179 if (!rc || rc == -EBUSY)
5182 * HW queues take time to be flushed, give them
5188 spin_lock(&priv->stream_lock);
5190 wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
5191 " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
5192 mwl8k_remove_stream(hw, stream);
5196 ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
5198 case IEEE80211_AMPDU_TX_STOP_CONT:
5199 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5200 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5202 if (stream->state == AMPDU_STREAM_ACTIVE) {
5203 spin_unlock(&priv->stream_lock);
5204 mwl8k_destroy_ba(hw, stream);
5205 spin_lock(&priv->stream_lock);
5207 mwl8k_remove_stream(hw, stream);
5209 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
5211 case IEEE80211_AMPDU_TX_OPERATIONAL:
5212 BUG_ON(stream == NULL);
5213 BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
5214 spin_unlock(&priv->stream_lock);
5215 rc = mwl8k_create_ba(hw, stream, buf_size, vif);
5216 spin_lock(&priv->stream_lock);
5218 stream->state = AMPDU_STREAM_ACTIVE;
5220 spin_unlock(&priv->stream_lock);
5221 mwl8k_destroy_ba(hw, stream);
5222 spin_lock(&priv->stream_lock);
5223 wiphy_debug(hw->wiphy,
5224 "Failed adding stream for sta %pM tid %d\n",
5226 mwl8k_remove_stream(hw, stream);
5234 spin_unlock(&priv->stream_lock);
5238 static const struct ieee80211_ops mwl8k_ops = {
5240 .start = mwl8k_start,
5242 .add_interface = mwl8k_add_interface,
5243 .remove_interface = mwl8k_remove_interface,
5244 .config = mwl8k_config,
5245 .bss_info_changed = mwl8k_bss_info_changed,
5246 .prepare_multicast = mwl8k_prepare_multicast,
5247 .configure_filter = mwl8k_configure_filter,
5248 .set_key = mwl8k_set_key,
5249 .set_rts_threshold = mwl8k_set_rts_threshold,
5250 .sta_add = mwl8k_sta_add,
5251 .sta_remove = mwl8k_sta_remove,
5252 .conf_tx = mwl8k_conf_tx,
5253 .get_stats = mwl8k_get_stats,
5254 .get_survey = mwl8k_get_survey,
5255 .ampdu_action = mwl8k_ampdu_action,
5258 static void mwl8k_finalize_join_worker(struct work_struct *work)
5260 struct mwl8k_priv *priv =
5261 container_of(work, struct mwl8k_priv, finalize_join_worker);
5262 struct sk_buff *skb = priv->beacon_skb;
5263 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5264 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
5265 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
5266 mgmt->u.beacon.variable, len);
5267 int dtim_period = 1;
5269 if (tim && tim[1] >= 2)
5270 dtim_period = tim[3];
5272 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
5275 priv->beacon_skb = NULL;
5284 #define MWL8K_8366_AP_FW_API 2
5285 #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5286 #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5288 static struct mwl8k_device_info mwl8k_info_tbl[] = {
5290 .part_name = "88w8363",
5291 .helper_image = "mwl8k/helper_8363.fw",
5292 .fw_image_sta = "mwl8k/fmimage_8363.fw",
5295 .part_name = "88w8687",
5296 .helper_image = "mwl8k/helper_8687.fw",
5297 .fw_image_sta = "mwl8k/fmimage_8687.fw",
5300 .part_name = "88w8366",
5301 .helper_image = "mwl8k/helper_8366.fw",
5302 .fw_image_sta = "mwl8k/fmimage_8366.fw",
5303 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
5304 .fw_api_ap = MWL8K_8366_AP_FW_API,
5305 .ap_rxd_ops = &rxd_8366_ap_ops,
5309 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5310 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5311 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5312 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5313 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5314 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
5315 MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
5317 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
5318 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
5319 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
5320 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
5321 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
5322 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
5323 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
5324 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
5327 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
5329 static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
5332 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
5333 "Trying alternative firmware %s\n", pci_name(priv->pdev),
5334 priv->fw_pref, priv->fw_alt);
5335 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
5337 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5338 pci_name(priv->pdev), priv->fw_alt);
5344 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
5345 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
5347 struct mwl8k_priv *priv = context;
5348 struct mwl8k_device_info *di = priv->device_info;
5351 switch (priv->fw_state) {
5354 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
5355 pci_name(priv->pdev), di->helper_image);
5358 priv->fw_helper = fw;
5359 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
5361 if (rc && priv->fw_alt) {
5362 rc = mwl8k_request_alt_fw(priv);
5365 priv->fw_state = FW_STATE_LOADING_ALT;
5369 priv->fw_state = FW_STATE_LOADING_PREF;
5372 case FW_STATE_LOADING_PREF:
5375 rc = mwl8k_request_alt_fw(priv);
5378 priv->fw_state = FW_STATE_LOADING_ALT;
5382 priv->fw_ucode = fw;
5383 rc = mwl8k_firmware_load_success(priv);
5387 complete(&priv->firmware_loading_complete);
5391 case FW_STATE_LOADING_ALT:
5393 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5394 pci_name(priv->pdev), di->helper_image);
5397 priv->fw_ucode = fw;
5398 rc = mwl8k_firmware_load_success(priv);
5402 complete(&priv->firmware_loading_complete);
5406 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
5407 MWL8K_NAME, priv->fw_state);
5414 priv->fw_state = FW_STATE_ERROR;
5415 complete(&priv->firmware_loading_complete);
5416 device_release_driver(&priv->pdev->dev);
5417 mwl8k_release_firmware(priv);
5420 #define MAX_RESTART_ATTEMPTS 1
5421 static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
5424 struct mwl8k_priv *priv = hw->priv;
5426 int count = MAX_RESTART_ATTEMPTS;
5429 /* Reset firmware and hardware */
5430 mwl8k_hw_reset(priv);
5432 /* Ask userland hotplug daemon for the device firmware */
5433 rc = mwl8k_request_firmware(priv, fw_image, nowait);
5435 wiphy_err(hw->wiphy, "Firmware files not found\n");
5442 /* Load firmware into hardware */
5443 rc = mwl8k_load_firmware(hw);
5445 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5447 /* Reclaim memory once firmware is successfully loaded */
5448 mwl8k_release_firmware(priv);
5451 /* FW did not start successfully;
5452 * lets try one more time
5455 wiphy_err(hw->wiphy, "Trying to reload the firmware again\n");
5463 static int mwl8k_init_txqs(struct ieee80211_hw *hw)
5465 struct mwl8k_priv *priv = hw->priv;
5469 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
5470 rc = mwl8k_txq_init(hw, i);
5474 iowrite32(priv->txq[i].txd_dma,
5475 priv->sram + priv->txq_offset[i]);
5480 /* initialize hw after successfully loading a firmware image */
5481 static int mwl8k_probe_hw(struct ieee80211_hw *hw)
5483 struct mwl8k_priv *priv = hw->priv;
5488 priv->rxd_ops = priv->device_info->ap_rxd_ops;
5489 if (priv->rxd_ops == NULL) {
5490 wiphy_err(hw->wiphy,
5491 "Driver does not have AP firmware image support for this hardware\n");
5492 goto err_stop_firmware;
5495 priv->rxd_ops = &rxd_sta_ops;
5498 priv->sniffer_enabled = false;
5499 priv->wmm_enabled = false;
5500 priv->pending_tx_pkts = 0;
5502 rc = mwl8k_rxq_init(hw, 0);
5504 goto err_stop_firmware;
5505 rxq_refill(hw, 0, INT_MAX);
5507 /* For the sta firmware, we need to know the dma addresses of tx queues
5508 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5509 * prior to issuing this command. But for the AP case, we learn the
5510 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5511 * case we must initialize the tx queues after.
5513 priv->num_ampdu_queues = 0;
5515 rc = mwl8k_init_txqs(hw);
5517 goto err_free_queues;
5520 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
5521 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5522 iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
5523 MWL8K_A2H_INT_BA_WATCHDOG,
5524 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
5525 iowrite32(MWL8K_A2H_INT_OPC_DONE,
5526 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
5528 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
5529 IRQF_SHARED, MWL8K_NAME, hw);
5531 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
5532 goto err_free_queues;
5536 * When hw restart is requested,
5537 * mac80211 will take care of clearing
5538 * the ampdu streams, so do not clear
5539 * the ampdu state here
5541 if (!priv->hw_restart_in_progress)
5542 memset(priv->ampdu, 0, sizeof(priv->ampdu));
5545 * Temporarily enable interrupts. Initial firmware host
5546 * commands use interrupts and avoid polling. Disable
5547 * interrupts when done.
5549 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5551 /* Get config data, mac addrs etc */
5553 rc = mwl8k_cmd_get_hw_spec_ap(hw);
5555 rc = mwl8k_init_txqs(hw);
5557 rc = mwl8k_cmd_set_hw_spec(hw);
5559 rc = mwl8k_cmd_get_hw_spec_sta(hw);
5562 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
5566 /* Turn radio off */
5567 rc = mwl8k_cmd_radio_disable(hw);
5569 wiphy_err(hw->wiphy, "Cannot disable\n");
5573 /* Clear MAC address */
5574 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
5576 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
5580 /* Disable interrupts */
5581 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5582 free_irq(priv->pdev->irq, hw);
5584 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5585 priv->device_info->part_name,
5586 priv->hw_rev, hw->wiphy->perm_addr,
5587 priv->ap_fw ? "AP" : "STA",
5588 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
5589 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
5594 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5595 free_irq(priv->pdev->irq, hw);
5598 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5599 mwl8k_txq_deinit(hw, i);
5600 mwl8k_rxq_deinit(hw, 0);
5603 mwl8k_hw_reset(priv);
5609 * invoke mwl8k_reload_firmware to change the firmware image after the device
5610 * has already been registered
5612 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
5615 struct mwl8k_priv *priv = hw->priv;
5616 struct mwl8k_vif *vif, *tmp_vif;
5619 mwl8k_rxq_deinit(hw, 0);
5622 * All the existing interfaces are re-added by the ieee80211_reconfig;
5623 * which means driver should remove existing interfaces before calling
5624 * ieee80211_restart_hw
5626 if (priv->hw_restart_in_progress)
5627 list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list)
5628 mwl8k_remove_vif(priv, vif);
5630 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5631 mwl8k_txq_deinit(hw, i);
5633 rc = mwl8k_init_firmware(hw, fw_image, false);
5637 rc = mwl8k_probe_hw(hw);
5641 if (priv->hw_restart_in_progress)
5644 rc = mwl8k_start(hw);
5648 rc = mwl8k_config(hw, ~0);
5652 for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
5653 rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]);
5661 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
5665 static const struct ieee80211_iface_limit ap_if_limits[] = {
5666 { .max = 8, .types = BIT(NL80211_IFTYPE_AP) },
5669 static const struct ieee80211_iface_combination ap_if_comb = {
5670 .limits = ap_if_limits,
5671 .n_limits = ARRAY_SIZE(ap_if_limits),
5672 .max_interfaces = 8,
5673 .num_different_channels = 1,
5677 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
5679 struct ieee80211_hw *hw = priv->hw;
5682 rc = mwl8k_load_firmware(hw);
5683 mwl8k_release_firmware(priv);
5685 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5690 * Extra headroom is the size of the required DMA header
5691 * minus the size of the smallest 802.11 frame (CTS frame).
5693 hw->extra_tx_headroom =
5694 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
5696 hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0;
5698 hw->channel_change_time = 10;
5700 hw->queues = MWL8K_TX_WMM_QUEUES;
5702 /* Set rssi values to dBm */
5703 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
5706 * Ask mac80211 to not to trigger PS mode
5707 * based on PM bit of incoming frames.
5710 hw->flags |= IEEE80211_HW_AP_LINK_PS;
5712 hw->vif_data_size = sizeof(struct mwl8k_vif);
5713 hw->sta_data_size = sizeof(struct mwl8k_sta);
5715 priv->macids_used = 0;
5716 INIT_LIST_HEAD(&priv->vif_list);
5718 /* Set default radio state and preamble */
5719 priv->radio_on = false;
5720 priv->radio_short_preamble = false;
5722 /* Finalize join worker */
5723 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
5724 /* Handle watchdog ba events */
5725 INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
5726 /* To reload the firmware if it crashes */
5727 INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
5729 /* TX reclaim and RX tasklets. */
5730 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
5731 tasklet_disable(&priv->poll_tx_task);
5732 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
5733 tasklet_disable(&priv->poll_rx_task);
5735 /* Power management cookie */
5736 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
5737 if (priv->cookie == NULL)
5740 mutex_init(&priv->fw_mutex);
5741 priv->fw_mutex_owner = NULL;
5742 priv->fw_mutex_depth = 0;
5743 priv->hostcmd_wait = NULL;
5745 spin_lock_init(&priv->tx_lock);
5747 spin_lock_init(&priv->stream_lock);
5749 priv->tx_wait = NULL;
5751 rc = mwl8k_probe_hw(hw);
5753 goto err_free_cookie;
5755 hw->wiphy->interface_modes = 0;
5757 if (priv->ap_macids_supported || priv->device_info->fw_image_ap) {
5758 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
5759 hw->wiphy->iface_combinations = &ap_if_comb;
5760 hw->wiphy->n_iface_combinations = 1;
5763 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
5764 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
5766 rc = ieee80211_register_hw(hw);
5768 wiphy_err(hw->wiphy, "Cannot register device\n");
5769 goto err_unprobe_hw;
5775 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5776 mwl8k_txq_deinit(hw, i);
5777 mwl8k_rxq_deinit(hw, 0);
5780 if (priv->cookie != NULL)
5781 pci_free_consistent(priv->pdev, 4,
5782 priv->cookie, priv->cookie_dma);
5786 static int mwl8k_probe(struct pci_dev *pdev,
5787 const struct pci_device_id *id)
5789 static int printed_version;
5790 struct ieee80211_hw *hw;
5791 struct mwl8k_priv *priv;
5792 struct mwl8k_device_info *di;
5795 if (!printed_version) {
5796 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
5797 printed_version = 1;
5801 rc = pci_enable_device(pdev);
5803 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
5808 rc = pci_request_regions(pdev, MWL8K_NAME);
5810 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
5812 goto err_disable_device;
5815 pci_set_master(pdev);
5818 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
5820 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
5825 SET_IEEE80211_DEV(hw, &pdev->dev);
5826 pci_set_drvdata(pdev, hw);
5831 priv->device_info = &mwl8k_info_tbl[id->driver_data];
5834 priv->sram = pci_iomap(pdev, 0, 0x10000);
5835 if (priv->sram == NULL) {
5836 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
5841 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
5842 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
5844 priv->regs = pci_iomap(pdev, 1, 0x10000);
5845 if (priv->regs == NULL) {
5846 priv->regs = pci_iomap(pdev, 2, 0x10000);
5847 if (priv->regs == NULL) {
5848 wiphy_err(hw->wiphy, "Cannot map device registers\n");
5854 * Choose the initial fw image depending on user input. If a second
5855 * image is available, make it the alternative image that will be
5856 * loaded if the first one fails.
5858 init_completion(&priv->firmware_loading_complete);
5859 di = priv->device_info;
5860 if (ap_mode_default && di->fw_image_ap) {
5861 priv->fw_pref = di->fw_image_ap;
5862 priv->fw_alt = di->fw_image_sta;
5863 } else if (!ap_mode_default && di->fw_image_sta) {
5864 priv->fw_pref = di->fw_image_sta;
5865 priv->fw_alt = di->fw_image_ap;
5866 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
5867 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
5868 priv->fw_pref = di->fw_image_sta;
5869 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
5870 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
5871 priv->fw_pref = di->fw_image_ap;
5873 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
5875 goto err_stop_firmware;
5877 priv->hw_restart_in_progress = false;
5882 mwl8k_hw_reset(priv);
5885 if (priv->regs != NULL)
5886 pci_iounmap(pdev, priv->regs);
5888 if (priv->sram != NULL)
5889 pci_iounmap(pdev, priv->sram);
5891 pci_set_drvdata(pdev, NULL);
5892 ieee80211_free_hw(hw);
5895 pci_release_regions(pdev);
5898 pci_disable_device(pdev);
5903 static void mwl8k_remove(struct pci_dev *pdev)
5905 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
5906 struct mwl8k_priv *priv;
5913 wait_for_completion(&priv->firmware_loading_complete);
5915 if (priv->fw_state == FW_STATE_ERROR) {
5916 mwl8k_hw_reset(priv);
5920 ieee80211_stop_queues(hw);
5922 ieee80211_unregister_hw(hw);
5924 /* Remove TX reclaim and RX tasklets. */
5925 tasklet_kill(&priv->poll_tx_task);
5926 tasklet_kill(&priv->poll_rx_task);
5929 mwl8k_hw_reset(priv);
5931 /* Return all skbs to mac80211 */
5932 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5933 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
5935 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5936 mwl8k_txq_deinit(hw, i);
5938 mwl8k_rxq_deinit(hw, 0);
5940 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
5943 pci_iounmap(pdev, priv->regs);
5944 pci_iounmap(pdev, priv->sram);
5945 pci_set_drvdata(pdev, NULL);
5946 ieee80211_free_hw(hw);
5947 pci_release_regions(pdev);
5948 pci_disable_device(pdev);
5951 static struct pci_driver mwl8k_driver = {
5953 .id_table = mwl8k_pci_id_table,
5954 .probe = mwl8k_probe,
5955 .remove = mwl8k_remove,
5958 module_pci_driver(mwl8k_driver);
5960 MODULE_DESCRIPTION(MWL8K_DESC);
5961 MODULE_VERSION(MWL8K_VERSION);
5962 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
5963 MODULE_LICENSE("GPL");