2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc.
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/spinlock.h>
17 #include <linux/list.h>
18 #include <linux/pci.h>
19 #include <linux/delay.h>
20 #include <linux/completion.h>
21 #include <linux/etherdevice.h>
22 #include <linux/slab.h>
23 #include <net/mac80211.h>
24 #include <linux/moduleparam.h>
25 #include <linux/firmware.h>
26 #include <linux/workqueue.h>
28 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
29 #define MWL8K_NAME KBUILD_MODNAME
30 #define MWL8K_VERSION "0.12"
32 /* Module parameters */
33 static unsigned ap_mode_default;
34 module_param(ap_mode_default, bool, 0);
35 MODULE_PARM_DESC(ap_mode_default,
36 "Set to 1 to make ap mode the default instead of sta mode");
38 /* Register definitions */
39 #define MWL8K_HIU_GEN_PTR 0x00000c10
40 #define MWL8K_MODE_STA 0x0000005a
41 #define MWL8K_MODE_AP 0x000000a5
42 #define MWL8K_HIU_INT_CODE 0x00000c14
43 #define MWL8K_FWSTA_READY 0xf0f1f2f4
44 #define MWL8K_FWAP_READY 0xf1f2f4a5
45 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
46 #define MWL8K_HIU_SCRATCH 0x00000c40
48 /* Host->device communications */
49 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
50 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
51 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
52 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
53 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
54 #define MWL8K_H2A_INT_DUMMY (1 << 20)
55 #define MWL8K_H2A_INT_RESET (1 << 15)
56 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
57 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
59 /* Device->host communications */
60 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
61 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
62 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
63 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
64 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
65 #define MWL8K_A2H_INT_DUMMY (1 << 20)
66 #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
67 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
68 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
69 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
70 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
71 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
72 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
73 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
74 #define MWL8K_A2H_INT_RX_READY (1 << 1)
75 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
77 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
78 MWL8K_A2H_INT_CHNL_SWITCHED | \
79 MWL8K_A2H_INT_QUEUE_EMPTY | \
80 MWL8K_A2H_INT_RADAR_DETECT | \
81 MWL8K_A2H_INT_RADIO_ON | \
82 MWL8K_A2H_INT_RADIO_OFF | \
83 MWL8K_A2H_INT_MAC_EVENT | \
84 MWL8K_A2H_INT_OPC_DONE | \
85 MWL8K_A2H_INT_RX_READY | \
86 MWL8K_A2H_INT_TX_DONE | \
87 MWL8K_A2H_INT_BA_WATCHDOG)
89 #define MWL8K_RX_QUEUES 1
90 #define MWL8K_TX_WMM_QUEUES 4
91 #define MWL8K_MAX_AMPDU_QUEUES 8
92 #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
93 #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
97 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
98 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
99 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
100 __le16 *qos, s8 *noise);
103 struct mwl8k_device_info {
108 struct rxd_ops *ap_rxd_ops;
112 struct mwl8k_rx_queue {
115 /* hw receives here */
118 /* refill descs here */
125 DEFINE_DMA_UNMAP_ADDR(dma);
129 struct mwl8k_tx_queue {
130 /* hw transmits here */
133 /* sw appends here */
137 struct mwl8k_tx_desc *txd;
139 struct sk_buff **skb;
145 AMPDU_STREAM_IN_PROGRESS,
149 struct mwl8k_ampdu_stream {
150 struct ieee80211_sta *sta;
154 u8 txq_idx; /* index of this stream in priv->txq */
158 struct ieee80211_hw *hw;
159 struct pci_dev *pdev;
162 struct mwl8k_device_info *device_info;
168 const struct firmware *fw_helper;
169 const struct firmware *fw_ucode;
171 /* hardware/firmware parameters */
173 struct rxd_ops *rxd_ops;
174 struct ieee80211_supported_band band_24;
175 struct ieee80211_channel channels_24[14];
176 struct ieee80211_rate rates_24[14];
177 struct ieee80211_supported_band band_50;
178 struct ieee80211_channel channels_50[4];
179 struct ieee80211_rate rates_50[9];
180 u32 ap_macids_supported;
181 u32 sta_macids_supported;
183 /* Ampdu stream information */
185 spinlock_t stream_lock;
186 struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
187 struct work_struct watchdog_ba_handle;
189 /* firmware access */
190 struct mutex fw_mutex;
191 struct task_struct *fw_mutex_owner;
193 struct completion *hostcmd_wait;
195 /* lock held over TX and TX reap */
198 /* TX quiesce completion, protected by fw_mutex and tx_lock */
199 struct completion *tx_wait;
201 /* List of interfaces. */
203 struct list_head vif_list;
205 /* power management status cookie from firmware */
207 dma_addr_t cookie_dma;
214 * Running count of TX packets in flight, to avoid
215 * iterating over the transmit rings each time.
219 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
220 struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
221 u32 txq_offset[MWL8K_MAX_TX_QUEUES];
224 bool radio_short_preamble;
225 bool sniffer_enabled;
228 /* XXX need to convert this to handle multiple interfaces */
230 u8 capture_bssid[ETH_ALEN];
231 struct sk_buff *beacon_skb;
234 * This FJ worker has to be global as it is scheduled from the
235 * RX handler. At this point we don't know which interface it
236 * belongs to until the list of bssids waiting to complete join
239 struct work_struct finalize_join_worker;
241 /* Tasklet to perform TX reclaim. */
242 struct tasklet_struct poll_tx_task;
244 /* Tasklet to perform RX. */
245 struct tasklet_struct poll_rx_task;
247 /* Most recently reported noise in dBm */
251 * preserve the queue configurations so they can be restored if/when
252 * the firmware image is swapped.
254 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
256 /* async firmware loading state */
260 struct completion firmware_loading_complete;
263 #define MAX_WEP_KEY_LEN 13
264 #define NUM_WEP_KEYS 4
266 /* Per interface specific private data */
268 struct list_head list;
269 struct ieee80211_vif *vif;
271 /* Firmware macid for this vif. */
274 /* Non AMPDU sequence number assigned by driver. */
280 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
281 } wep_key_conf[NUM_WEP_KEYS];
286 /* A flag to indicate is HW crypto is enabled for this bssid */
287 bool is_hw_crypto_enabled;
289 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
290 #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
292 struct tx_traffic_info {
297 #define MWL8K_MAX_TID 8
299 /* Index into station database. Returned by UPDATE_STADB. */
302 struct tx_traffic_info tx_stats[MWL8K_MAX_TID];
304 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
306 static const struct ieee80211_channel mwl8k_channels_24[] = {
307 { .center_freq = 2412, .hw_value = 1, },
308 { .center_freq = 2417, .hw_value = 2, },
309 { .center_freq = 2422, .hw_value = 3, },
310 { .center_freq = 2427, .hw_value = 4, },
311 { .center_freq = 2432, .hw_value = 5, },
312 { .center_freq = 2437, .hw_value = 6, },
313 { .center_freq = 2442, .hw_value = 7, },
314 { .center_freq = 2447, .hw_value = 8, },
315 { .center_freq = 2452, .hw_value = 9, },
316 { .center_freq = 2457, .hw_value = 10, },
317 { .center_freq = 2462, .hw_value = 11, },
318 { .center_freq = 2467, .hw_value = 12, },
319 { .center_freq = 2472, .hw_value = 13, },
320 { .center_freq = 2484, .hw_value = 14, },
323 static const struct ieee80211_rate mwl8k_rates_24[] = {
324 { .bitrate = 10, .hw_value = 2, },
325 { .bitrate = 20, .hw_value = 4, },
326 { .bitrate = 55, .hw_value = 11, },
327 { .bitrate = 110, .hw_value = 22, },
328 { .bitrate = 220, .hw_value = 44, },
329 { .bitrate = 60, .hw_value = 12, },
330 { .bitrate = 90, .hw_value = 18, },
331 { .bitrate = 120, .hw_value = 24, },
332 { .bitrate = 180, .hw_value = 36, },
333 { .bitrate = 240, .hw_value = 48, },
334 { .bitrate = 360, .hw_value = 72, },
335 { .bitrate = 480, .hw_value = 96, },
336 { .bitrate = 540, .hw_value = 108, },
337 { .bitrate = 720, .hw_value = 144, },
340 static const struct ieee80211_channel mwl8k_channels_50[] = {
341 { .center_freq = 5180, .hw_value = 36, },
342 { .center_freq = 5200, .hw_value = 40, },
343 { .center_freq = 5220, .hw_value = 44, },
344 { .center_freq = 5240, .hw_value = 48, },
347 static const struct ieee80211_rate mwl8k_rates_50[] = {
348 { .bitrate = 60, .hw_value = 12, },
349 { .bitrate = 90, .hw_value = 18, },
350 { .bitrate = 120, .hw_value = 24, },
351 { .bitrate = 180, .hw_value = 36, },
352 { .bitrate = 240, .hw_value = 48, },
353 { .bitrate = 360, .hw_value = 72, },
354 { .bitrate = 480, .hw_value = 96, },
355 { .bitrate = 540, .hw_value = 108, },
356 { .bitrate = 720, .hw_value = 144, },
359 /* Set or get info from Firmware */
360 #define MWL8K_CMD_GET 0x0000
361 #define MWL8K_CMD_SET 0x0001
362 #define MWL8K_CMD_SET_LIST 0x0002
364 /* Firmware command codes */
365 #define MWL8K_CMD_CODE_DNLD 0x0001
366 #define MWL8K_CMD_GET_HW_SPEC 0x0003
367 #define MWL8K_CMD_SET_HW_SPEC 0x0004
368 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
369 #define MWL8K_CMD_GET_STAT 0x0014
370 #define MWL8K_CMD_RADIO_CONTROL 0x001c
371 #define MWL8K_CMD_RF_TX_POWER 0x001e
372 #define MWL8K_CMD_TX_POWER 0x001f
373 #define MWL8K_CMD_RF_ANTENNA 0x0020
374 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
375 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
376 #define MWL8K_CMD_SET_POST_SCAN 0x0108
377 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
378 #define MWL8K_CMD_SET_AID 0x010d
379 #define MWL8K_CMD_SET_RATE 0x0110
380 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
381 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
382 #define MWL8K_CMD_SET_SLOT 0x0114
383 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
384 #define MWL8K_CMD_SET_WMM_MODE 0x0123
385 #define MWL8K_CMD_MIMO_CONFIG 0x0125
386 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
387 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
388 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
389 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
390 #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
391 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
392 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
393 #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
394 #define MWL8K_CMD_UPDATE_STADB 0x1123
395 #define MWL8K_CMD_BASTREAM 0x1125
397 static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
399 u16 command = le16_to_cpu(cmd);
401 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
402 snprintf(buf, bufsize, "%s", #x);\
405 switch (command & ~0x8000) {
406 MWL8K_CMDNAME(CODE_DNLD);
407 MWL8K_CMDNAME(GET_HW_SPEC);
408 MWL8K_CMDNAME(SET_HW_SPEC);
409 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
410 MWL8K_CMDNAME(GET_STAT);
411 MWL8K_CMDNAME(RADIO_CONTROL);
412 MWL8K_CMDNAME(RF_TX_POWER);
413 MWL8K_CMDNAME(TX_POWER);
414 MWL8K_CMDNAME(RF_ANTENNA);
415 MWL8K_CMDNAME(SET_BEACON);
416 MWL8K_CMDNAME(SET_PRE_SCAN);
417 MWL8K_CMDNAME(SET_POST_SCAN);
418 MWL8K_CMDNAME(SET_RF_CHANNEL);
419 MWL8K_CMDNAME(SET_AID);
420 MWL8K_CMDNAME(SET_RATE);
421 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
422 MWL8K_CMDNAME(RTS_THRESHOLD);
423 MWL8K_CMDNAME(SET_SLOT);
424 MWL8K_CMDNAME(SET_EDCA_PARAMS);
425 MWL8K_CMDNAME(SET_WMM_MODE);
426 MWL8K_CMDNAME(MIMO_CONFIG);
427 MWL8K_CMDNAME(USE_FIXED_RATE);
428 MWL8K_CMDNAME(ENABLE_SNIFFER);
429 MWL8K_CMDNAME(SET_MAC_ADDR);
430 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
431 MWL8K_CMDNAME(BSS_START);
432 MWL8K_CMDNAME(SET_NEW_STN);
433 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
434 MWL8K_CMDNAME(UPDATE_STADB);
435 MWL8K_CMDNAME(BASTREAM);
436 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
438 snprintf(buf, bufsize, "0x%x", cmd);
445 /* Hardware and firmware reset */
446 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
448 iowrite32(MWL8K_H2A_INT_RESET,
449 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
450 iowrite32(MWL8K_H2A_INT_RESET,
451 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
455 /* Release fw image */
456 static void mwl8k_release_fw(const struct firmware **fw)
460 release_firmware(*fw);
464 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
466 mwl8k_release_fw(&priv->fw_ucode);
467 mwl8k_release_fw(&priv->fw_helper);
470 /* states for asynchronous f/w loading */
471 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
474 FW_STATE_LOADING_PREF,
475 FW_STATE_LOADING_ALT,
479 /* Request fw image */
480 static int mwl8k_request_fw(struct mwl8k_priv *priv,
481 const char *fname, const struct firmware **fw,
484 /* release current image */
486 mwl8k_release_fw(fw);
489 return request_firmware_nowait(THIS_MODULE, 1, fname,
490 &priv->pdev->dev, GFP_KERNEL,
491 priv, mwl8k_fw_state_machine);
493 return request_firmware(fw, fname, &priv->pdev->dev);
496 static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
499 struct mwl8k_device_info *di = priv->device_info;
502 if (di->helper_image != NULL) {
504 rc = mwl8k_request_fw(priv, di->helper_image,
505 &priv->fw_helper, true);
507 rc = mwl8k_request_fw(priv, di->helper_image,
508 &priv->fw_helper, false);
510 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
511 pci_name(priv->pdev), di->helper_image);
519 * if we get here, no helper image is needed. Skip the
520 * FW_STATE_INIT state.
522 priv->fw_state = FW_STATE_LOADING_PREF;
523 rc = mwl8k_request_fw(priv, fw_image,
527 rc = mwl8k_request_fw(priv, fw_image,
528 &priv->fw_ucode, false);
530 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
531 pci_name(priv->pdev), fw_image);
532 mwl8k_release_fw(&priv->fw_helper);
539 struct mwl8k_cmd_pkt {
552 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
554 void __iomem *regs = priv->regs;
558 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
559 if (pci_dma_mapping_error(priv->pdev, dma_addr))
562 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
563 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
564 iowrite32(MWL8K_H2A_INT_DOORBELL,
565 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
566 iowrite32(MWL8K_H2A_INT_DUMMY,
567 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
573 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
574 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
575 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
583 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
585 return loops ? 0 : -ETIMEDOUT;
588 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
589 const u8 *data, size_t length)
591 struct mwl8k_cmd_pkt *cmd;
595 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
599 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
606 int block_size = length > 256 ? 256 : length;
608 memcpy(cmd->payload, data + done, block_size);
609 cmd->length = cpu_to_le16(block_size);
611 rc = mwl8k_send_fw_load_cmd(priv, cmd,
612 sizeof(*cmd) + block_size);
617 length -= block_size;
622 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
630 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
631 const u8 *data, size_t length)
633 unsigned char *buffer;
634 int may_continue, rc = 0;
635 u32 done, prev_block_size;
637 buffer = kmalloc(1024, GFP_KERNEL);
644 while (may_continue > 0) {
647 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
648 if (block_size & 1) {
652 done += prev_block_size;
653 length -= prev_block_size;
656 if (block_size > 1024 || block_size > length) {
666 if (block_size == 0) {
673 prev_block_size = block_size;
674 memcpy(buffer, data + done, block_size);
676 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
681 if (!rc && length != 0)
689 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
691 struct mwl8k_priv *priv = hw->priv;
692 const struct firmware *fw = priv->fw_ucode;
696 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
697 const struct firmware *helper = priv->fw_helper;
699 if (helper == NULL) {
700 printk(KERN_ERR "%s: helper image needed but none "
701 "given\n", pci_name(priv->pdev));
705 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
707 printk(KERN_ERR "%s: unable to load firmware "
708 "helper image\n", pci_name(priv->pdev));
713 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
715 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
719 printk(KERN_ERR "%s: unable to load firmware image\n",
720 pci_name(priv->pdev));
724 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
730 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
731 if (ready_code == MWL8K_FWAP_READY) {
734 } else if (ready_code == MWL8K_FWSTA_READY) {
743 return loops ? 0 : -ETIMEDOUT;
747 /* DMA header used by firmware and hardware. */
748 struct mwl8k_dma_data {
750 struct ieee80211_hdr wh;
754 /* Routines to add/remove DMA header from skb. */
755 static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
757 struct mwl8k_dma_data *tr;
760 tr = (struct mwl8k_dma_data *)skb->data;
761 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
763 if (hdrlen != sizeof(tr->wh)) {
764 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
765 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
766 *((__le16 *)(tr->data - 2)) = qos;
768 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
772 if (hdrlen != sizeof(*tr))
773 skb_pull(skb, sizeof(*tr) - hdrlen);
777 mwl8k_add_dma_header(struct sk_buff *skb, int tail_pad)
779 struct ieee80211_hdr *wh;
782 struct mwl8k_dma_data *tr;
785 * Add a firmware DMA header; the firmware requires that we
786 * present a 2-byte payload length followed by a 4-address
787 * header (without QoS field), followed (optionally) by any
788 * WEP/ExtIV header (but only filled in for CCMP).
790 wh = (struct ieee80211_hdr *)skb->data;
792 hdrlen = ieee80211_hdrlen(wh->frame_control);
793 reqd_hdrlen = sizeof(*tr);
795 if (hdrlen != reqd_hdrlen)
796 skb_push(skb, reqd_hdrlen - hdrlen);
798 if (ieee80211_is_data_qos(wh->frame_control))
799 hdrlen -= IEEE80211_QOS_CTL_LEN;
801 tr = (struct mwl8k_dma_data *)skb->data;
803 memmove(&tr->wh, wh, hdrlen);
804 if (hdrlen != sizeof(tr->wh))
805 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
808 * Firmware length is the length of the fully formed "802.11
809 * payload". That is, everything except for the 802.11 header.
810 * This includes all crypto material including the MIC.
812 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
815 static void mwl8k_encapsulate_tx_frame(struct sk_buff *skb)
817 struct ieee80211_hdr *wh;
818 struct ieee80211_tx_info *tx_info;
819 struct ieee80211_key_conf *key_conf;
822 wh = (struct ieee80211_hdr *)skb->data;
824 tx_info = IEEE80211_SKB_CB(skb);
827 if (ieee80211_is_data(wh->frame_control))
828 key_conf = tx_info->control.hw_key;
831 * Make sure the packet header is in the DMA header format (4-address
832 * without QoS), the necessary crypto padding between the header and the
833 * payload has already been provided by mac80211, but it doesn't add
834 * tail padding when HW crypto is enabled.
836 * We have the following trailer padding requirements:
837 * - WEP: 4 trailer bytes (ICV)
838 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
839 * - CCMP: 8 trailer bytes (MIC)
842 if (key_conf != NULL) {
843 switch (key_conf->cipher) {
844 case WLAN_CIPHER_SUITE_WEP40:
845 case WLAN_CIPHER_SUITE_WEP104:
848 case WLAN_CIPHER_SUITE_TKIP:
851 case WLAN_CIPHER_SUITE_CCMP:
856 mwl8k_add_dma_header(skb, data_pad);
860 * Packet reception for 88w8366 AP firmware.
862 struct mwl8k_rxd_8366_ap {
866 __le32 pkt_phys_addr;
867 __le32 next_rxd_phys_addr;
871 __le32 hw_noise_floor_info;
880 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
881 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
882 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
884 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
886 /* 8366 AP rx_status bits */
887 #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
888 #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
889 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
890 #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
891 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
893 static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
895 struct mwl8k_rxd_8366_ap *rxd = _rxd;
897 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
898 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
901 static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
903 struct mwl8k_rxd_8366_ap *rxd = _rxd;
905 rxd->pkt_len = cpu_to_le16(len);
906 rxd->pkt_phys_addr = cpu_to_le32(addr);
912 mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
913 __le16 *qos, s8 *noise)
915 struct mwl8k_rxd_8366_ap *rxd = _rxd;
917 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
921 memset(status, 0, sizeof(*status));
923 status->signal = -rxd->rssi;
924 *noise = -rxd->noise_floor;
926 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
927 status->flag |= RX_FLAG_HT;
928 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
929 status->flag |= RX_FLAG_40MHZ;
930 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
934 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
935 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
936 status->rate_idx = i;
942 if (rxd->channel > 14) {
943 status->band = IEEE80211_BAND_5GHZ;
944 if (!(status->flag & RX_FLAG_HT))
945 status->rate_idx -= 5;
947 status->band = IEEE80211_BAND_2GHZ;
949 status->freq = ieee80211_channel_to_frequency(rxd->channel,
952 *qos = rxd->qos_control;
954 if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
955 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) &&
956 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
957 status->flag |= RX_FLAG_MMIC_ERROR;
959 return le16_to_cpu(rxd->pkt_len);
962 static struct rxd_ops rxd_8366_ap_ops = {
963 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
964 .rxd_init = mwl8k_rxd_8366_ap_init,
965 .rxd_refill = mwl8k_rxd_8366_ap_refill,
966 .rxd_process = mwl8k_rxd_8366_ap_process,
970 * Packet reception for STA firmware.
972 struct mwl8k_rxd_sta {
976 __le32 pkt_phys_addr;
977 __le32 next_rxd_phys_addr;
989 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
990 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
991 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
992 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
993 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
994 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
996 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
997 #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
999 #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
1000 /* Key is uploaded only in failure case */
1001 #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
1003 static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
1005 struct mwl8k_rxd_sta *rxd = _rxd;
1007 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
1008 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
1011 static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
1013 struct mwl8k_rxd_sta *rxd = _rxd;
1015 rxd->pkt_len = cpu_to_le16(len);
1016 rxd->pkt_phys_addr = cpu_to_le32(addr);
1022 mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
1023 __le16 *qos, s8 *noise)
1025 struct mwl8k_rxd_sta *rxd = _rxd;
1028 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
1032 rate_info = le16_to_cpu(rxd->rate_info);
1034 memset(status, 0, sizeof(*status));
1036 status->signal = -rxd->rssi;
1037 *noise = -rxd->noise_level;
1038 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
1039 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
1041 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
1042 status->flag |= RX_FLAG_SHORTPRE;
1043 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
1044 status->flag |= RX_FLAG_40MHZ;
1045 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
1046 status->flag |= RX_FLAG_SHORT_GI;
1047 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
1048 status->flag |= RX_FLAG_HT;
1050 if (rxd->channel > 14) {
1051 status->band = IEEE80211_BAND_5GHZ;
1052 if (!(status->flag & RX_FLAG_HT))
1053 status->rate_idx -= 5;
1055 status->band = IEEE80211_BAND_2GHZ;
1057 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1060 *qos = rxd->qos_control;
1061 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1062 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1063 status->flag |= RX_FLAG_MMIC_ERROR;
1065 return le16_to_cpu(rxd->pkt_len);
1068 static struct rxd_ops rxd_sta_ops = {
1069 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1070 .rxd_init = mwl8k_rxd_sta_init,
1071 .rxd_refill = mwl8k_rxd_sta_refill,
1072 .rxd_process = mwl8k_rxd_sta_process,
1076 #define MWL8K_RX_DESCS 256
1077 #define MWL8K_RX_MAXSZ 3800
1079 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1081 struct mwl8k_priv *priv = hw->priv;
1082 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1090 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
1092 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1093 if (rxq->rxd == NULL) {
1094 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
1097 memset(rxq->rxd, 0, size);
1099 rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
1100 if (rxq->buf == NULL) {
1101 wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
1102 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
1106 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1110 dma_addr_t next_dma_addr;
1112 desc_size = priv->rxd_ops->rxd_size;
1113 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
1116 if (nexti == MWL8K_RX_DESCS)
1118 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1120 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
1126 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1128 struct mwl8k_priv *priv = hw->priv;
1129 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1133 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
1134 struct sk_buff *skb;
1139 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1143 addr = pci_map_single(priv->pdev, skb->data,
1144 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
1148 if (rxq->tail == MWL8K_RX_DESCS)
1150 rxq->buf[rx].skb = skb;
1151 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
1153 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1154 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
1162 /* Must be called only when the card's reception is completely halted */
1163 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1165 struct mwl8k_priv *priv = hw->priv;
1166 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1169 if (rxq->rxd == NULL)
1172 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1173 if (rxq->buf[i].skb != NULL) {
1174 pci_unmap_single(priv->pdev,
1175 dma_unmap_addr(&rxq->buf[i], dma),
1176 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1177 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
1179 kfree_skb(rxq->buf[i].skb);
1180 rxq->buf[i].skb = NULL;
1187 pci_free_consistent(priv->pdev,
1188 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
1189 rxq->rxd, rxq->rxd_dma);
1195 * Scan a list of BSSIDs to process for finalize join.
1196 * Allows for extension to process multiple BSSIDs.
1199 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1201 return priv->capture_beacon &&
1202 ieee80211_is_beacon(wh->frame_control) &&
1203 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1206 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1207 struct sk_buff *skb)
1209 struct mwl8k_priv *priv = hw->priv;
1211 priv->capture_beacon = false;
1212 memset(priv->capture_bssid, 0, ETH_ALEN);
1215 * Use GFP_ATOMIC as rxq_process is called from
1216 * the primary interrupt handler, memory allocation call
1219 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1220 if (priv->beacon_skb != NULL)
1221 ieee80211_queue_work(hw, &priv->finalize_join_worker);
1224 static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1227 struct mwl8k_vif *mwl8k_vif;
1229 list_for_each_entry(mwl8k_vif,
1231 if (memcmp(bssid, mwl8k_vif->bssid,
1239 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1241 struct mwl8k_priv *priv = hw->priv;
1242 struct mwl8k_vif *mwl8k_vif = NULL;
1243 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1247 while (rxq->rxd_count && limit--) {
1248 struct sk_buff *skb;
1251 struct ieee80211_rx_status status;
1252 struct ieee80211_hdr *wh;
1255 skb = rxq->buf[rxq->head].skb;
1259 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1261 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1266 rxq->buf[rxq->head].skb = NULL;
1268 pci_unmap_single(priv->pdev,
1269 dma_unmap_addr(&rxq->buf[rxq->head], dma),
1270 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1271 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1274 if (rxq->head == MWL8K_RX_DESCS)
1279 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1282 * Check for a pending join operation. Save a
1283 * copy of the beacon and schedule a tasklet to
1284 * send a FINALIZE_JOIN command to the firmware.
1286 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1287 mwl8k_save_beacon(hw, skb);
1289 if (ieee80211_has_protected(wh->frame_control)) {
1291 /* Check if hw crypto has been enabled for
1292 * this bss. If yes, set the status flags
1295 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1298 if (mwl8k_vif != NULL &&
1299 mwl8k_vif->is_hw_crypto_enabled == true) {
1301 * When MMIC ERROR is encountered
1302 * by the firmware, payload is
1303 * dropped and only 32 bytes of
1304 * mwl8k Firmware header is sent
1307 * We need to add four bytes of
1308 * key information. In it
1309 * MAC80211 expects keyidx set to
1310 * 0 for triggering Counter
1311 * Measure of MMIC failure.
1313 if (status.flag & RX_FLAG_MMIC_ERROR) {
1314 struct mwl8k_dma_data *tr;
1315 tr = (struct mwl8k_dma_data *)skb->data;
1316 memset((void *)&(tr->data), 0, 4);
1320 if (!ieee80211_is_auth(wh->frame_control))
1321 status.flag |= RX_FLAG_IV_STRIPPED |
1323 RX_FLAG_MMIC_STRIPPED;
1327 skb_put(skb, pkt_len);
1328 mwl8k_remove_dma_header(skb, qos);
1329 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1330 ieee80211_rx_irqsafe(hw, skb);
1340 * Packet transmission.
1343 #define MWL8K_TXD_STATUS_OK 0x00000001
1344 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1345 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1346 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1347 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1349 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1350 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1351 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1352 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1353 #define MWL8K_QOS_EOSP 0x0010
1355 struct mwl8k_tx_desc {
1360 __le32 pkt_phys_addr;
1362 __u8 dest_MAC_addr[ETH_ALEN];
1363 __le32 next_txd_phys_addr;
1370 #define MWL8K_TX_DESCS 128
1372 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1374 struct mwl8k_priv *priv = hw->priv;
1375 struct mwl8k_tx_queue *txq = priv->txq + index;
1383 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1385 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1386 if (txq->txd == NULL) {
1387 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
1390 memset(txq->txd, 0, size);
1392 txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
1393 if (txq->skb == NULL) {
1394 wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
1395 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1399 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1400 struct mwl8k_tx_desc *tx_desc;
1403 tx_desc = txq->txd + i;
1404 nexti = (i + 1) % MWL8K_TX_DESCS;
1406 tx_desc->status = 0;
1407 tx_desc->next_txd_phys_addr =
1408 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1414 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1416 iowrite32(MWL8K_H2A_INT_PPA_READY,
1417 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1418 iowrite32(MWL8K_H2A_INT_DUMMY,
1419 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1420 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1423 static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1425 struct mwl8k_priv *priv = hw->priv;
1428 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
1429 struct mwl8k_tx_queue *txq = priv->txq + i;
1435 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1436 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1439 status = le32_to_cpu(tx_desc->status);
1440 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1445 if (tx_desc->pkt_len == 0)
1449 wiphy_err(hw->wiphy,
1450 "txq[%d] len=%d head=%d tail=%d "
1451 "fw_owned=%d drv_owned=%d unused=%d\n",
1453 txq->len, txq->head, txq->tail,
1454 fw_owned, drv_owned, unused);
1459 * Must be called with priv->fw_mutex held and tx queues stopped.
1461 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1463 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1465 struct mwl8k_priv *priv = hw->priv;
1466 DECLARE_COMPLETION_ONSTACK(tx_wait);
1473 * The TX queues are stopped at this point, so this test
1474 * doesn't need to take ->tx_lock.
1476 if (!priv->pending_tx_pkts)
1482 spin_lock_bh(&priv->tx_lock);
1483 priv->tx_wait = &tx_wait;
1486 unsigned long timeout;
1488 oldcount = priv->pending_tx_pkts;
1490 spin_unlock_bh(&priv->tx_lock);
1491 timeout = wait_for_completion_timeout(&tx_wait,
1492 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1493 spin_lock_bh(&priv->tx_lock);
1496 WARN_ON(priv->pending_tx_pkts);
1498 wiphy_notice(hw->wiphy, "tx rings drained\n");
1502 if (priv->pending_tx_pkts < oldcount) {
1503 wiphy_notice(hw->wiphy,
1504 "waiting for tx rings to drain (%d -> %d pkts)\n",
1505 oldcount, priv->pending_tx_pkts);
1510 priv->tx_wait = NULL;
1512 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1513 MWL8K_TX_WAIT_TIMEOUT_MS);
1514 mwl8k_dump_tx_rings(hw);
1518 spin_unlock_bh(&priv->tx_lock);
1523 #define MWL8K_TXD_SUCCESS(status) \
1524 ((status) & (MWL8K_TXD_STATUS_OK | \
1525 MWL8K_TXD_STATUS_OK_RETRY | \
1526 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1528 static int mwl8k_tid_queue_mapping(u8 tid)
1535 return IEEE80211_AC_BE;
1539 return IEEE80211_AC_BK;
1543 return IEEE80211_AC_VI;
1547 return IEEE80211_AC_VO;
1555 /* The firmware will fill in the rate information
1556 * for each packet that gets queued in the hardware
1563 __le16 band_width:1;
1564 __le16 rate_id_mcs:6;
1565 __le16 adv_coding:2;
1567 __le16 act_sub_chan:2;
1568 __le16 preamble_type:1;
1572 __le16 tx_bf_frame:1;
1573 __le16 green_field:1;
1577 mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1579 struct mwl8k_priv *priv = hw->priv;
1580 struct mwl8k_tx_queue *txq = priv->txq + index;
1584 while (txq->len > 0 && limit--) {
1586 struct mwl8k_tx_desc *tx_desc;
1589 struct sk_buff *skb;
1590 struct ieee80211_tx_info *info;
1592 struct ieee80211_sta *sta;
1593 struct mwl8k_sta *sta_info = NULL;
1595 struct rateinfo *rate;
1596 struct ieee80211_hdr *wh;
1599 tx_desc = txq->txd + tx;
1601 status = le32_to_cpu(tx_desc->status);
1603 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1607 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1610 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1611 BUG_ON(txq->len == 0);
1613 priv->pending_tx_pkts--;
1615 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1616 size = le16_to_cpu(tx_desc->pkt_len);
1618 txq->skb[tx] = NULL;
1620 BUG_ON(skb == NULL);
1621 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1623 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
1625 wh = (struct ieee80211_hdr *) skb->data;
1627 /* Mark descriptor as unused */
1628 tx_desc->pkt_phys_addr = 0;
1629 tx_desc->pkt_len = 0;
1631 info = IEEE80211_SKB_CB(skb);
1632 if (ieee80211_is_data(wh->frame_control)) {
1633 sta = info->control.sta;
1635 sta_info = MWL8K_STA(sta);
1636 BUG_ON(sta_info == NULL);
1637 rate_info = le16_to_cpu(tx_desc->rate_info);
1638 rate = (struct rateinfo *)&rate_info;
1639 /* If rate is < 6.5 Mpbs for an ht station
1640 * do not form an ampdu. If the station is a
1641 * legacy station (format = 0), do not form an
1644 if (rate->rate_id_mcs < 1 ||
1645 rate->format == 0) {
1646 sta_info->is_ampdu_allowed = false;
1648 sta_info->is_ampdu_allowed = true;
1653 ieee80211_tx_info_clear_status(info);
1655 /* Rate control is happening in the firmware.
1656 * Ensure no tx rate is being reported.
1658 info->status.rates[0].idx = -1;
1659 info->status.rates[0].count = 1;
1661 if (MWL8K_TXD_SUCCESS(status))
1662 info->flags |= IEEE80211_TX_STAT_ACK;
1664 ieee80211_tx_status_irqsafe(hw, skb);
1669 if (index < MWL8K_TX_WMM_QUEUES && processed && priv->radio_on &&
1670 !mutex_is_locked(&priv->fw_mutex))
1671 ieee80211_wake_queue(hw, index);
1676 /* must be called only when the card's transmit is completely halted */
1677 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1679 struct mwl8k_priv *priv = hw->priv;
1680 struct mwl8k_tx_queue *txq = priv->txq + index;
1682 if (txq->txd == NULL)
1685 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1690 pci_free_consistent(priv->pdev,
1691 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1692 txq->txd, txq->txd_dma);
1696 /* caller must hold priv->stream_lock when calling the stream functions */
1697 static struct mwl8k_ampdu_stream *
1698 mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
1700 struct mwl8k_ampdu_stream *stream;
1701 struct mwl8k_priv *priv = hw->priv;
1704 for (i = 0; i < priv->num_ampdu_queues; i++) {
1705 stream = &priv->ampdu[i];
1706 if (stream->state == AMPDU_NO_STREAM) {
1708 stream->state = AMPDU_STREAM_NEW;
1711 stream->txq_idx = MWL8K_TX_WMM_QUEUES + i;
1712 wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
1721 mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1725 /* if the stream has already been started, don't start it again */
1726 if (stream->state != AMPDU_STREAM_NEW)
1728 ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
1730 wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
1731 "%d\n", stream->sta->addr, stream->tid, ret);
1733 wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
1734 stream->sta->addr, stream->tid);
1739 mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1741 wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
1743 memset(stream, 0, sizeof(*stream));
1746 static struct mwl8k_ampdu_stream *
1747 mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
1749 struct mwl8k_priv *priv = hw->priv;
1752 for (i = 0 ; i < priv->num_ampdu_queues; i++) {
1753 struct mwl8k_ampdu_stream *stream;
1754 stream = &priv->ampdu[i];
1755 if (stream->state == AMPDU_NO_STREAM)
1757 if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
1764 #define MWL8K_AMPDU_PACKET_THRESHOLD 64
1765 static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
1767 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1768 struct tx_traffic_info *tx_stats;
1770 BUG_ON(tid >= MWL8K_MAX_TID);
1771 tx_stats = &sta_info->tx_stats[tid];
1773 return sta_info->is_ampdu_allowed &&
1774 tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
1777 static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
1779 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1780 struct tx_traffic_info *tx_stats;
1782 BUG_ON(tid >= MWL8K_MAX_TID);
1783 tx_stats = &sta_info->tx_stats[tid];
1785 if (tx_stats->start_time == 0)
1786 tx_stats->start_time = jiffies;
1788 /* reset the packet count after each second elapses. If the number of
1789 * packets ever exceeds the ampdu_min_traffic threshold, we will allow
1790 * an ampdu stream to be started.
1792 if (jiffies - tx_stats->start_time > HZ) {
1794 tx_stats->start_time = 0;
1800 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1802 struct mwl8k_priv *priv = hw->priv;
1803 struct ieee80211_tx_info *tx_info;
1804 struct mwl8k_vif *mwl8k_vif;
1805 struct ieee80211_sta *sta;
1806 struct ieee80211_hdr *wh;
1807 struct mwl8k_tx_queue *txq;
1808 struct mwl8k_tx_desc *tx;
1815 struct mwl8k_ampdu_stream *stream = NULL;
1816 bool start_ba_session = false;
1817 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
1819 wh = (struct ieee80211_hdr *)skb->data;
1820 if (ieee80211_is_data_qos(wh->frame_control))
1821 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1826 mwl8k_encapsulate_tx_frame(skb);
1828 mwl8k_add_dma_header(skb, 0);
1830 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1832 tx_info = IEEE80211_SKB_CB(skb);
1833 sta = tx_info->control.sta;
1834 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1836 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1837 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1838 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1839 mwl8k_vif->seqno += 0x10;
1842 /* Setup firmware control bit fields for each frame type. */
1845 if (ieee80211_is_mgmt(wh->frame_control) ||
1846 ieee80211_is_ctl(wh->frame_control)) {
1848 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1849 } else if (ieee80211_is_data(wh->frame_control)) {
1851 if (is_multicast_ether_addr(wh->addr1))
1852 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1854 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1855 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1856 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1858 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1861 /* Queue ADDBA request in the respective data queue. While setting up
1862 * the ampdu stream, mac80211 queues further packets for that
1863 * particular ra/tid pair. However, packets piled up in the hardware
1864 * for that ra/tid pair will still go out. ADDBA request and the
1865 * related data packets going out from different queues asynchronously
1866 * will cause a shift in the receiver window which might result in
1867 * ampdu packets getting dropped at the receiver after the stream has
1870 if (unlikely(ieee80211_is_action(wh->frame_control) &&
1871 mgmt->u.action.category == WLAN_CATEGORY_BACK &&
1872 mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
1874 u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1875 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1876 index = mwl8k_tid_queue_mapping(tid);
1881 if (ieee80211_is_data_qos(wh->frame_control) &&
1882 skb->protocol != cpu_to_be16(ETH_P_PAE) &&
1883 sta->ht_cap.ht_supported && priv->ap_fw) {
1885 mwl8k_tx_count_packet(sta, tid);
1886 spin_lock(&priv->stream_lock);
1887 stream = mwl8k_lookup_stream(hw, sta->addr, tid);
1888 if (stream != NULL) {
1889 if (stream->state == AMPDU_STREAM_ACTIVE) {
1890 txpriority = stream->txq_idx;
1891 index = stream->txq_idx;
1892 } else if (stream->state == AMPDU_STREAM_NEW) {
1893 /* We get here if the driver sends us packets
1894 * after we've initiated a stream, but before
1895 * our ampdu_action routine has been called
1896 * with IEEE80211_AMPDU_TX_START to get the SSN
1897 * for the ADDBA request. So this packet can
1898 * go out with no risk of sequence number
1899 * mismatch. No special handling is required.
1902 /* Drop packets that would go out after the
1903 * ADDBA request was sent but before the ADDBA
1904 * response is received. If we don't do this,
1905 * the recipient would probably receive it
1906 * after the ADDBA request with SSN 0. This
1907 * will cause the recipient's BA receive window
1908 * to shift, which would cause the subsequent
1909 * packets in the BA stream to be discarded.
1910 * mac80211 queues our packets for us in this
1911 * case, so this is really just a safety check.
1913 wiphy_warn(hw->wiphy,
1914 "Cannot send packet while ADDBA "
1915 "dialog is underway.\n");
1916 spin_unlock(&priv->stream_lock);
1921 /* Defer calling mwl8k_start_stream so that the current
1922 * skb can go out before the ADDBA request. This
1923 * prevents sequence number mismatch at the recepient
1924 * as described above.
1926 if (mwl8k_ampdu_allowed(sta, tid)) {
1927 stream = mwl8k_add_stream(hw, sta, tid);
1929 start_ba_session = true;
1932 spin_unlock(&priv->stream_lock);
1935 dma = pci_map_single(priv->pdev, skb->data,
1936 skb->len, PCI_DMA_TODEVICE);
1938 if (pci_dma_mapping_error(priv->pdev, dma)) {
1939 wiphy_debug(hw->wiphy,
1940 "failed to dma map skb, dropping TX frame.\n");
1941 if (start_ba_session) {
1942 spin_lock(&priv->stream_lock);
1943 mwl8k_remove_stream(hw, stream);
1944 spin_unlock(&priv->stream_lock);
1950 spin_lock_bh(&priv->tx_lock);
1952 txq = priv->txq + index;
1954 if (index >= MWL8K_TX_WMM_QUEUES && txq->len >= MWL8K_TX_DESCS) {
1955 /* This is the case in which the tx packet is destined for an
1956 * AMPDU queue and that AMPDU queue is full. Because we don't
1957 * start and stop the AMPDU queues, we must drop these packets.
1960 spin_unlock_bh(&priv->tx_lock);
1964 BUG_ON(txq->skb[txq->tail] != NULL);
1965 txq->skb[txq->tail] = skb;
1967 tx = txq->txd + txq->tail;
1968 tx->data_rate = txdatarate;
1969 tx->tx_priority = txpriority;
1970 tx->qos_control = cpu_to_le16(qos);
1971 tx->pkt_phys_addr = cpu_to_le32(dma);
1972 tx->pkt_len = cpu_to_le16(skb->len);
1974 if (!priv->ap_fw && tx_info->control.sta != NULL)
1975 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1979 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1982 priv->pending_tx_pkts++;
1985 if (txq->tail == MWL8K_TX_DESCS)
1988 if (txq->head == txq->tail && index < MWL8K_TX_WMM_QUEUES)
1989 ieee80211_stop_queue(hw, index);
1991 mwl8k_tx_start(priv);
1993 spin_unlock_bh(&priv->tx_lock);
1995 /* Initiate the ampdu session here */
1996 if (start_ba_session) {
1997 spin_lock(&priv->stream_lock);
1998 if (mwl8k_start_stream(hw, stream))
1999 mwl8k_remove_stream(hw, stream);
2000 spin_unlock(&priv->stream_lock);
2008 * We have the following requirements for issuing firmware commands:
2009 * - Some commands require that the packet transmit path is idle when
2010 * the command is issued. (For simplicity, we'll just quiesce the
2011 * transmit path for every command.)
2012 * - There are certain sequences of commands that need to be issued to
2013 * the hardware sequentially, with no other intervening commands.
2015 * This leads to an implementation of a "firmware lock" as a mutex that
2016 * can be taken recursively, and which is taken by both the low-level
2017 * command submission function (mwl8k_post_cmd) as well as any users of
2018 * that function that require issuing of an atomic sequence of commands,
2019 * and quiesces the transmit path whenever it's taken.
2021 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
2023 struct mwl8k_priv *priv = hw->priv;
2025 if (priv->fw_mutex_owner != current) {
2028 mutex_lock(&priv->fw_mutex);
2029 ieee80211_stop_queues(hw);
2031 rc = mwl8k_tx_wait_empty(hw);
2033 ieee80211_wake_queues(hw);
2034 mutex_unlock(&priv->fw_mutex);
2039 priv->fw_mutex_owner = current;
2042 priv->fw_mutex_depth++;
2047 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
2049 struct mwl8k_priv *priv = hw->priv;
2051 if (!--priv->fw_mutex_depth) {
2052 ieee80211_wake_queues(hw);
2053 priv->fw_mutex_owner = NULL;
2054 mutex_unlock(&priv->fw_mutex);
2060 * Command processing.
2063 /* Timeout firmware commands after 10s */
2064 #define MWL8K_CMD_TIMEOUT_MS 10000
2066 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
2068 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2069 struct mwl8k_priv *priv = hw->priv;
2070 void __iomem *regs = priv->regs;
2071 dma_addr_t dma_addr;
2072 unsigned int dma_size;
2074 unsigned long timeout = 0;
2077 cmd->result = (__force __le16) 0xffff;
2078 dma_size = le16_to_cpu(cmd->length);
2079 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
2080 PCI_DMA_BIDIRECTIONAL);
2081 if (pci_dma_mapping_error(priv->pdev, dma_addr))
2084 rc = mwl8k_fw_lock(hw);
2086 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2087 PCI_DMA_BIDIRECTIONAL);
2091 priv->hostcmd_wait = &cmd_wait;
2092 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
2093 iowrite32(MWL8K_H2A_INT_DOORBELL,
2094 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2095 iowrite32(MWL8K_H2A_INT_DUMMY,
2096 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2098 timeout = wait_for_completion_timeout(&cmd_wait,
2099 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
2101 priv->hostcmd_wait = NULL;
2103 mwl8k_fw_unlock(hw);
2105 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2106 PCI_DMA_BIDIRECTIONAL);
2109 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
2110 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2111 MWL8K_CMD_TIMEOUT_MS);
2116 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
2118 rc = cmd->result ? -EINVAL : 0;
2120 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
2121 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2122 le16_to_cpu(cmd->result));
2124 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
2125 mwl8k_cmd_name(cmd->code,
2133 static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
2134 struct ieee80211_vif *vif,
2135 struct mwl8k_cmd_pkt *cmd)
2138 cmd->macid = MWL8K_VIF(vif)->macid;
2139 return mwl8k_post_cmd(hw, cmd);
2143 * Setup code shared between STA and AP firmware images.
2145 static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
2147 struct mwl8k_priv *priv = hw->priv;
2149 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
2150 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
2152 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
2153 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
2155 priv->band_24.band = IEEE80211_BAND_2GHZ;
2156 priv->band_24.channels = priv->channels_24;
2157 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
2158 priv->band_24.bitrates = priv->rates_24;
2159 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
2161 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
2164 static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
2166 struct mwl8k_priv *priv = hw->priv;
2168 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
2169 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
2171 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
2172 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
2174 priv->band_50.band = IEEE80211_BAND_5GHZ;
2175 priv->band_50.channels = priv->channels_50;
2176 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
2177 priv->band_50.bitrates = priv->rates_50;
2178 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
2180 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
2184 * CMD_GET_HW_SPEC (STA version).
2186 struct mwl8k_cmd_get_hw_spec_sta {
2187 struct mwl8k_cmd_pkt header;
2189 __u8 host_interface;
2191 __u8 perm_addr[ETH_ALEN];
2196 __u8 mcs_bitmap[16];
2197 __le32 rx_queue_ptr;
2198 __le32 num_tx_queues;
2199 __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
2201 __le32 num_tx_desc_per_queue;
2205 #define MWL8K_CAP_MAX_AMSDU 0x20000000
2206 #define MWL8K_CAP_GREENFIELD 0x08000000
2207 #define MWL8K_CAP_AMPDU 0x04000000
2208 #define MWL8K_CAP_RX_STBC 0x01000000
2209 #define MWL8K_CAP_TX_STBC 0x00800000
2210 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2211 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2212 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2213 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2214 #define MWL8K_CAP_DELAY_BA 0x00003000
2215 #define MWL8K_CAP_MIMO 0x00000200
2216 #define MWL8K_CAP_40MHZ 0x00000100
2217 #define MWL8K_CAP_BAND_MASK 0x00000007
2218 #define MWL8K_CAP_5GHZ 0x00000004
2219 #define MWL8K_CAP_2GHZ4 0x00000001
2222 mwl8k_set_ht_caps(struct ieee80211_hw *hw,
2223 struct ieee80211_supported_band *band, u32 cap)
2228 band->ht_cap.ht_supported = 1;
2230 if (cap & MWL8K_CAP_MAX_AMSDU)
2231 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
2232 if (cap & MWL8K_CAP_GREENFIELD)
2233 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
2234 if (cap & MWL8K_CAP_AMPDU) {
2235 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
2236 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2237 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2239 if (cap & MWL8K_CAP_RX_STBC)
2240 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
2241 if (cap & MWL8K_CAP_TX_STBC)
2242 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
2243 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
2244 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
2245 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
2246 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
2247 if (cap & MWL8K_CAP_DELAY_BA)
2248 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
2249 if (cap & MWL8K_CAP_40MHZ)
2250 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2252 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
2253 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
2255 band->ht_cap.mcs.rx_mask[0] = 0xff;
2256 if (rx_streams >= 2)
2257 band->ht_cap.mcs.rx_mask[1] = 0xff;
2258 if (rx_streams >= 3)
2259 band->ht_cap.mcs.rx_mask[2] = 0xff;
2260 band->ht_cap.mcs.rx_mask[4] = 0x01;
2261 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2263 if (rx_streams != tx_streams) {
2264 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
2265 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
2266 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2271 mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
2273 struct mwl8k_priv *priv = hw->priv;
2275 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
2276 mwl8k_setup_2ghz_band(hw);
2277 if (caps & MWL8K_CAP_MIMO)
2278 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
2281 if (caps & MWL8K_CAP_5GHZ) {
2282 mwl8k_setup_5ghz_band(hw);
2283 if (caps & MWL8K_CAP_MIMO)
2284 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
2288 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
2290 struct mwl8k_priv *priv = hw->priv;
2291 struct mwl8k_cmd_get_hw_spec_sta *cmd;
2295 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2299 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2300 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2302 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2303 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2304 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2305 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2306 for (i = 0; i < mwl8k_tx_queues(priv); i++)
2307 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
2308 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2309 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2311 rc = mwl8k_post_cmd(hw, &cmd->header);
2314 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2315 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2316 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2317 priv->hw_rev = cmd->hw_rev;
2318 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2319 priv->ap_macids_supported = 0x00000000;
2320 priv->sta_macids_supported = 0x00000001;
2328 * CMD_GET_HW_SPEC (AP version).
2330 struct mwl8k_cmd_get_hw_spec_ap {
2331 struct mwl8k_cmd_pkt header;
2333 __u8 host_interface;
2336 __u8 perm_addr[ETH_ALEN];
2347 __le32 fw_api_version;
2349 __le32 num_of_ampdu_queues;
2350 __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
2353 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2355 struct mwl8k_priv *priv = hw->priv;
2356 struct mwl8k_cmd_get_hw_spec_ap *cmd;
2360 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2364 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2365 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2367 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2368 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2370 rc = mwl8k_post_cmd(hw, &cmd->header);
2375 api_version = le32_to_cpu(cmd->fw_api_version);
2376 if (priv->device_info->fw_api_ap != api_version) {
2377 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2378 " Expected %d got %d.\n", MWL8K_NAME,
2379 priv->device_info->part_name,
2380 priv->device_info->fw_api_ap,
2385 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2386 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2387 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2388 priv->hw_rev = cmd->hw_rev;
2389 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2390 priv->ap_macids_supported = 0x000000ff;
2391 priv->sta_macids_supported = 0x00000000;
2392 priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
2393 if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
2394 wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
2395 " but we only support %d.\n",
2396 priv->num_ampdu_queues,
2397 MWL8K_MAX_AMPDU_QUEUES);
2398 priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
2400 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
2401 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2403 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
2404 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2406 priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
2407 priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
2408 priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
2409 priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
2411 for (i = 0; i < priv->num_ampdu_queues; i++)
2412 priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
2413 le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
2424 struct mwl8k_cmd_set_hw_spec {
2425 struct mwl8k_cmd_pkt header;
2427 __u8 host_interface;
2429 __u8 perm_addr[ETH_ALEN];
2434 __le32 rx_queue_ptr;
2435 __le32 num_tx_queues;
2436 __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
2438 __le32 num_tx_desc_per_queue;
2442 /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2443 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2444 * the packets that are queued for more than 500ms, will be dropped in the
2445 * hardware. This helps minimizing the issues caused due to head-of-line
2446 * blocking where a slow client can hog the bandwidth and affect traffic to a
2449 #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
2450 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2451 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2452 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
2454 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2456 struct mwl8k_priv *priv = hw->priv;
2457 struct mwl8k_cmd_set_hw_spec *cmd;
2461 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2465 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2466 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2468 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2469 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2470 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2473 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2474 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2475 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2476 * priority is interpreted the right way in firmware.
2478 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
2479 int j = mwl8k_tx_queues(priv) - 1 - i;
2480 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
2483 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2484 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
2485 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
2486 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2487 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2489 rc = mwl8k_post_cmd(hw, &cmd->header);
2496 * CMD_MAC_MULTICAST_ADR.
2498 struct mwl8k_cmd_mac_multicast_adr {
2499 struct mwl8k_cmd_pkt header;
2502 __u8 addr[0][ETH_ALEN];
2505 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
2506 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
2507 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2508 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
2510 static struct mwl8k_cmd_pkt *
2511 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
2512 struct netdev_hw_addr_list *mc_list)
2514 struct mwl8k_priv *priv = hw->priv;
2515 struct mwl8k_cmd_mac_multicast_adr *cmd;
2520 mc_count = netdev_hw_addr_list_count(mc_list);
2522 if (allmulti || mc_count > priv->num_mcaddrs) {
2527 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2529 cmd = kzalloc(size, GFP_ATOMIC);
2533 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2534 cmd->header.length = cpu_to_le16(size);
2535 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2536 MWL8K_ENABLE_RX_BROADCAST);
2539 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2540 } else if (mc_count) {
2541 struct netdev_hw_addr *ha;
2544 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2545 cmd->numaddr = cpu_to_le16(mc_count);
2546 netdev_hw_addr_list_for_each(ha, mc_list) {
2547 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
2551 return &cmd->header;
2557 struct mwl8k_cmd_get_stat {
2558 struct mwl8k_cmd_pkt header;
2562 #define MWL8K_STAT_ACK_FAILURE 9
2563 #define MWL8K_STAT_RTS_FAILURE 12
2564 #define MWL8K_STAT_FCS_ERROR 24
2565 #define MWL8K_STAT_RTS_SUCCESS 11
2567 static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2568 struct ieee80211_low_level_stats *stats)
2570 struct mwl8k_cmd_get_stat *cmd;
2573 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2577 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2578 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2580 rc = mwl8k_post_cmd(hw, &cmd->header);
2582 stats->dot11ACKFailureCount =
2583 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2584 stats->dot11RTSFailureCount =
2585 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2586 stats->dot11FCSErrorCount =
2587 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2588 stats->dot11RTSSuccessCount =
2589 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2597 * CMD_RADIO_CONTROL.
2599 struct mwl8k_cmd_radio_control {
2600 struct mwl8k_cmd_pkt header;
2607 mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
2609 struct mwl8k_priv *priv = hw->priv;
2610 struct mwl8k_cmd_radio_control *cmd;
2613 if (enable == priv->radio_on && !force)
2616 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2620 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2621 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2622 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2623 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
2624 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2626 rc = mwl8k_post_cmd(hw, &cmd->header);
2630 priv->radio_on = enable;
2635 static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
2637 return mwl8k_cmd_radio_control(hw, 0, 0);
2640 static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
2642 return mwl8k_cmd_radio_control(hw, 1, 0);
2646 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2648 struct mwl8k_priv *priv = hw->priv;
2650 priv->radio_short_preamble = short_preamble;
2652 return mwl8k_cmd_radio_control(hw, 1, 1);
2658 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2660 struct mwl8k_cmd_rf_tx_power {
2661 struct mwl8k_cmd_pkt header;
2663 __le16 support_level;
2664 __le16 current_level;
2666 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
2669 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
2671 struct mwl8k_cmd_rf_tx_power *cmd;
2674 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2678 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2679 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2680 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2681 cmd->support_level = cpu_to_le16(dBm);
2683 rc = mwl8k_post_cmd(hw, &cmd->header);
2692 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2694 struct mwl8k_cmd_tx_power {
2695 struct mwl8k_cmd_pkt header;
2701 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2704 static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2705 struct ieee80211_conf *conf,
2708 struct ieee80211_channel *channel = conf->channel;
2709 struct mwl8k_cmd_tx_power *cmd;
2713 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2717 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2718 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2719 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2721 if (channel->band == IEEE80211_BAND_2GHZ)
2722 cmd->band = cpu_to_le16(0x1);
2723 else if (channel->band == IEEE80211_BAND_5GHZ)
2724 cmd->band = cpu_to_le16(0x4);
2726 cmd->channel = channel->hw_value;
2728 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2729 conf->channel_type == NL80211_CHAN_HT20) {
2730 cmd->bw = cpu_to_le16(0x2);
2732 cmd->bw = cpu_to_le16(0x4);
2733 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2734 cmd->sub_ch = cpu_to_le16(0x3);
2735 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2736 cmd->sub_ch = cpu_to_le16(0x1);
2739 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2740 cmd->power_level_list[i] = cpu_to_le16(pwr);
2742 rc = mwl8k_post_cmd(hw, &cmd->header);
2751 struct mwl8k_cmd_rf_antenna {
2752 struct mwl8k_cmd_pkt header;
2757 #define MWL8K_RF_ANTENNA_RX 1
2758 #define MWL8K_RF_ANTENNA_TX 2
2761 mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2763 struct mwl8k_cmd_rf_antenna *cmd;
2766 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2770 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2771 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2772 cmd->antenna = cpu_to_le16(antenna);
2773 cmd->mode = cpu_to_le16(mask);
2775 rc = mwl8k_post_cmd(hw, &cmd->header);
2784 struct mwl8k_cmd_set_beacon {
2785 struct mwl8k_cmd_pkt header;
2790 static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2791 struct ieee80211_vif *vif, u8 *beacon, int len)
2793 struct mwl8k_cmd_set_beacon *cmd;
2796 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2800 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2801 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2802 cmd->beacon_len = cpu_to_le16(len);
2803 memcpy(cmd->beacon, beacon, len);
2805 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2814 struct mwl8k_cmd_set_pre_scan {
2815 struct mwl8k_cmd_pkt header;
2818 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2820 struct mwl8k_cmd_set_pre_scan *cmd;
2823 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2827 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2828 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2830 rc = mwl8k_post_cmd(hw, &cmd->header);
2837 * CMD_SET_POST_SCAN.
2839 struct mwl8k_cmd_set_post_scan {
2840 struct mwl8k_cmd_pkt header;
2842 __u8 bssid[ETH_ALEN];
2846 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2848 struct mwl8k_cmd_set_post_scan *cmd;
2851 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2855 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2856 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2858 memcpy(cmd->bssid, mac, ETH_ALEN);
2860 rc = mwl8k_post_cmd(hw, &cmd->header);
2867 * CMD_SET_RF_CHANNEL.
2869 struct mwl8k_cmd_set_rf_channel {
2870 struct mwl8k_cmd_pkt header;
2872 __u8 current_channel;
2873 __le32 channel_flags;
2876 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2877 struct ieee80211_conf *conf)
2879 struct ieee80211_channel *channel = conf->channel;
2880 struct mwl8k_cmd_set_rf_channel *cmd;
2883 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2887 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2888 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2889 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2890 cmd->current_channel = channel->hw_value;
2892 if (channel->band == IEEE80211_BAND_2GHZ)
2893 cmd->channel_flags |= cpu_to_le32(0x00000001);
2894 else if (channel->band == IEEE80211_BAND_5GHZ)
2895 cmd->channel_flags |= cpu_to_le32(0x00000004);
2897 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2898 conf->channel_type == NL80211_CHAN_HT20)
2899 cmd->channel_flags |= cpu_to_le32(0x00000080);
2900 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2901 cmd->channel_flags |= cpu_to_le32(0x000001900);
2902 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2903 cmd->channel_flags |= cpu_to_le32(0x000000900);
2905 rc = mwl8k_post_cmd(hw, &cmd->header);
2914 #define MWL8K_FRAME_PROT_DISABLED 0x00
2915 #define MWL8K_FRAME_PROT_11G 0x07
2916 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2917 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2919 struct mwl8k_cmd_update_set_aid {
2920 struct mwl8k_cmd_pkt header;
2923 /* AP's MAC address (BSSID) */
2924 __u8 bssid[ETH_ALEN];
2925 __le16 protection_mode;
2926 __u8 supp_rates[14];
2929 static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2935 * Clear nonstandard rates 4 and 13.
2939 for (i = 0, j = 0; i < 14; i++) {
2940 if (mask & (1 << i))
2941 rates[j++] = mwl8k_rates_24[i].hw_value;
2946 mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2947 struct ieee80211_vif *vif, u32 legacy_rate_mask)
2949 struct mwl8k_cmd_update_set_aid *cmd;
2953 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2957 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2958 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2959 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
2960 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
2962 if (vif->bss_conf.use_cts_prot) {
2963 prot_mode = MWL8K_FRAME_PROT_11G;
2965 switch (vif->bss_conf.ht_operation_mode &
2966 IEEE80211_HT_OP_MODE_PROTECTION) {
2967 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2968 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2970 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2971 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2974 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2978 cmd->protection_mode = cpu_to_le16(prot_mode);
2980 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
2982 rc = mwl8k_post_cmd(hw, &cmd->header);
2991 struct mwl8k_cmd_set_rate {
2992 struct mwl8k_cmd_pkt header;
2993 __u8 legacy_rates[14];
2995 /* Bitmap for supported MCS codes. */
3001 mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3002 u32 legacy_rate_mask, u8 *mcs_rates)
3004 struct mwl8k_cmd_set_rate *cmd;
3007 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3011 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
3012 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3013 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
3014 memcpy(cmd->mcs_set, mcs_rates, 16);
3016 rc = mwl8k_post_cmd(hw, &cmd->header);
3023 * CMD_FINALIZE_JOIN.
3025 #define MWL8K_FJ_BEACON_MAXLEN 128
3027 struct mwl8k_cmd_finalize_join {
3028 struct mwl8k_cmd_pkt header;
3029 __le32 sleep_interval; /* Number of beacon periods to sleep */
3030 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
3033 static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
3034 int framelen, int dtim)
3036 struct mwl8k_cmd_finalize_join *cmd;
3037 struct ieee80211_mgmt *payload = frame;
3041 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3045 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
3046 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3047 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
3049 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
3050 if (payload_len < 0)
3052 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
3053 payload_len = MWL8K_FJ_BEACON_MAXLEN;
3055 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
3057 rc = mwl8k_post_cmd(hw, &cmd->header);
3064 * CMD_SET_RTS_THRESHOLD.
3066 struct mwl8k_cmd_set_rts_threshold {
3067 struct mwl8k_cmd_pkt header;
3073 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
3075 struct mwl8k_cmd_set_rts_threshold *cmd;
3078 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3082 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
3083 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3084 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3085 cmd->threshold = cpu_to_le16(rts_thresh);
3087 rc = mwl8k_post_cmd(hw, &cmd->header);
3096 struct mwl8k_cmd_set_slot {
3097 struct mwl8k_cmd_pkt header;
3102 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
3104 struct mwl8k_cmd_set_slot *cmd;
3107 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3111 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
3112 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3113 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3114 cmd->short_slot = short_slot_time;
3116 rc = mwl8k_post_cmd(hw, &cmd->header);
3123 * CMD_SET_EDCA_PARAMS.
3125 struct mwl8k_cmd_set_edca_params {
3126 struct mwl8k_cmd_pkt header;
3128 /* See MWL8K_SET_EDCA_XXX below */
3131 /* TX opportunity in units of 32 us */
3136 /* Log exponent of max contention period: 0...15 */
3139 /* Log exponent of min contention period: 0...15 */
3142 /* Adaptive interframe spacing in units of 32us */
3145 /* TX queue to configure */
3149 /* Log exponent of max contention period: 0...15 */
3152 /* Log exponent of min contention period: 0...15 */
3155 /* Adaptive interframe spacing in units of 32us */
3158 /* TX queue to configure */
3164 #define MWL8K_SET_EDCA_CW 0x01
3165 #define MWL8K_SET_EDCA_TXOP 0x02
3166 #define MWL8K_SET_EDCA_AIFS 0x04
3168 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3169 MWL8K_SET_EDCA_TXOP | \
3170 MWL8K_SET_EDCA_AIFS)
3173 mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
3174 __u16 cw_min, __u16 cw_max,
3175 __u8 aifs, __u16 txop)
3177 struct mwl8k_priv *priv = hw->priv;
3178 struct mwl8k_cmd_set_edca_params *cmd;
3181 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3185 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
3186 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3187 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
3188 cmd->txop = cpu_to_le16(txop);
3190 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
3191 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
3192 cmd->ap.aifs = aifs;
3195 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
3196 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
3197 cmd->sta.aifs = aifs;
3198 cmd->sta.txq = qnum;
3201 rc = mwl8k_post_cmd(hw, &cmd->header);
3210 struct mwl8k_cmd_set_wmm_mode {
3211 struct mwl8k_cmd_pkt header;
3215 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
3217 struct mwl8k_priv *priv = hw->priv;
3218 struct mwl8k_cmd_set_wmm_mode *cmd;
3221 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3225 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
3226 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3227 cmd->action = cpu_to_le16(!!enable);
3229 rc = mwl8k_post_cmd(hw, &cmd->header);
3233 priv->wmm_enabled = enable;
3241 struct mwl8k_cmd_mimo_config {
3242 struct mwl8k_cmd_pkt header;
3244 __u8 rx_antenna_map;
3245 __u8 tx_antenna_map;
3248 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
3250 struct mwl8k_cmd_mimo_config *cmd;
3253 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3257 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
3258 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3259 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
3260 cmd->rx_antenna_map = rx;
3261 cmd->tx_antenna_map = tx;
3263 rc = mwl8k_post_cmd(hw, &cmd->header);
3270 * CMD_USE_FIXED_RATE (STA version).
3272 struct mwl8k_cmd_use_fixed_rate_sta {
3273 struct mwl8k_cmd_pkt header;
3275 __le32 allow_rate_drop;
3279 __le32 enable_retry;
3288 #define MWL8K_USE_AUTO_RATE 0x0002
3289 #define MWL8K_UCAST_RATE 0
3291 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
3293 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
3296 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3300 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3301 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3302 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3303 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
3305 rc = mwl8k_post_cmd(hw, &cmd->header);
3312 * CMD_USE_FIXED_RATE (AP version).
3314 struct mwl8k_cmd_use_fixed_rate_ap {
3315 struct mwl8k_cmd_pkt header;
3317 __le32 allow_rate_drop;
3319 struct mwl8k_rate_entry_ap {
3321 __le32 enable_retry;
3326 u8 multicast_rate_type;
3331 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
3333 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
3336 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3340 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3341 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3342 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3343 cmd->multicast_rate = mcast;
3344 cmd->management_rate = mgmt;
3346 rc = mwl8k_post_cmd(hw, &cmd->header);
3353 * CMD_ENABLE_SNIFFER.
3355 struct mwl8k_cmd_enable_sniffer {
3356 struct mwl8k_cmd_pkt header;
3360 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3362 struct mwl8k_cmd_enable_sniffer *cmd;
3365 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3369 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3370 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3371 cmd->action = cpu_to_le32(!!enable);
3373 rc = mwl8k_post_cmd(hw, &cmd->header);
3382 struct mwl8k_cmd_set_mac_addr {
3383 struct mwl8k_cmd_pkt header;
3387 __u8 mac_addr[ETH_ALEN];
3389 __u8 mac_addr[ETH_ALEN];
3393 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3394 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3395 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
3396 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
3398 static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3399 struct ieee80211_vif *vif, u8 *mac)
3401 struct mwl8k_priv *priv = hw->priv;
3402 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3403 struct mwl8k_cmd_set_mac_addr *cmd;
3407 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3408 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3409 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
3410 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
3412 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3413 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3414 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3415 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3417 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3420 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3424 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3425 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3427 cmd->mbss.mac_type = cpu_to_le16(mac_type);
3428 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3430 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3433 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3440 * CMD_SET_RATEADAPT_MODE.
3442 struct mwl8k_cmd_set_rate_adapt_mode {
3443 struct mwl8k_cmd_pkt header;
3448 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3450 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
3453 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3457 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
3458 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3459 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3460 cmd->mode = cpu_to_le16(mode);
3462 rc = mwl8k_post_cmd(hw, &cmd->header);
3469 * CMD_GET_WATCHDOG_BITMAP.
3471 struct mwl8k_cmd_get_watchdog_bitmap {
3472 struct mwl8k_cmd_pkt header;
3476 static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
3478 struct mwl8k_cmd_get_watchdog_bitmap *cmd;
3481 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3485 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
3486 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3488 rc = mwl8k_post_cmd(hw, &cmd->header);
3490 *bitmap = cmd->bitmap;
3497 #define INVALID_BA 0xAA
3498 static void mwl8k_watchdog_ba_events(struct work_struct *work)
3501 u8 bitmap = 0, stream_index;
3502 struct mwl8k_ampdu_stream *streams;
3503 struct mwl8k_priv *priv =
3504 container_of(work, struct mwl8k_priv, watchdog_ba_handle);
3506 rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
3510 if (bitmap == INVALID_BA)
3513 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
3514 stream_index = bitmap - MWL8K_TX_WMM_QUEUES;
3516 BUG_ON(stream_index >= priv->num_ampdu_queues);
3518 streams = &priv->ampdu[stream_index];
3520 if (streams->state == AMPDU_STREAM_ACTIVE)
3521 ieee80211_stop_tx_ba_session(streams->sta, streams->tid);
3530 struct mwl8k_cmd_bss_start {
3531 struct mwl8k_cmd_pkt header;
3535 static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3536 struct ieee80211_vif *vif, int enable)
3538 struct mwl8k_cmd_bss_start *cmd;
3541 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3545 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3546 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3547 cmd->enable = cpu_to_le32(enable);
3549 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3560 * UPSTREAM is tx direction
3562 #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3563 #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3565 enum ba_stream_action_type {
3574 struct mwl8k_create_ba_stream {
3579 u8 peer_mac_addr[6];
3585 u8 reset_seq_no_flag;
3587 u8 sta_src_mac_addr[6];
3590 struct mwl8k_destroy_ba_stream {
3595 struct mwl8k_cmd_bastream {
3596 struct mwl8k_cmd_pkt header;
3599 struct mwl8k_create_ba_stream create_params;
3600 struct mwl8k_destroy_ba_stream destroy_params;
3605 mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
3607 struct mwl8k_cmd_bastream *cmd;
3610 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3614 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3615 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3617 cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
3619 cmd->create_params.queue_id = stream->idx;
3620 memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
3622 cmd->create_params.tid = stream->tid;
3624 cmd->create_params.flags =
3625 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
3626 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
3628 rc = mwl8k_post_cmd(hw, &cmd->header);
3636 mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3639 struct mwl8k_cmd_bastream *cmd;
3642 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3647 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3648 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3650 cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
3652 cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
3653 cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
3654 cmd->create_params.queue_id = stream->idx;
3656 memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
3657 cmd->create_params.tid = stream->tid;
3658 cmd->create_params.curr_seq_no = cpu_to_le16(0);
3659 cmd->create_params.reset_seq_no_flag = 1;
3661 cmd->create_params.param_info =
3662 (stream->sta->ht_cap.ampdu_factor &
3663 IEEE80211_HT_AMPDU_PARM_FACTOR) |
3664 ((stream->sta->ht_cap.ampdu_density << 2) &
3665 IEEE80211_HT_AMPDU_PARM_DENSITY);
3667 cmd->create_params.flags =
3668 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
3669 BASTREAM_FLAG_DIRECTION_UPSTREAM);
3671 rc = mwl8k_post_cmd(hw, &cmd->header);
3673 wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
3674 stream->sta->addr, stream->tid);
3680 static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3681 struct mwl8k_ampdu_stream *stream)
3683 struct mwl8k_cmd_bastream *cmd;
3685 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3689 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3690 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3691 cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
3693 cmd->destroy_params.ba_context = cpu_to_le32(stream->idx);
3694 mwl8k_post_cmd(hw, &cmd->header);
3696 wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", stream->idx);
3704 struct mwl8k_cmd_set_new_stn {
3705 struct mwl8k_cmd_pkt header;
3711 __le32 legacy_rates;
3714 __le16 ht_capabilities_info;
3715 __u8 mac_ht_param_info;
3717 __u8 control_channel;
3726 #define MWL8K_STA_ACTION_ADD 0
3727 #define MWL8K_STA_ACTION_REMOVE 2
3729 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3730 struct ieee80211_vif *vif,
3731 struct ieee80211_sta *sta)
3733 struct mwl8k_cmd_set_new_stn *cmd;
3737 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3741 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3742 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3743 cmd->aid = cpu_to_le16(sta->aid);
3744 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3745 cmd->stn_id = cpu_to_le16(sta->aid);
3746 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
3747 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3748 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3750 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3751 cmd->legacy_rates = cpu_to_le32(rates);
3752 if (sta->ht_cap.ht_supported) {
3753 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3754 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3755 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3756 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3757 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3758 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3759 ((sta->ht_cap.ampdu_density & 7) << 2);
3760 cmd->is_qos_sta = 1;
3763 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3769 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3770 struct ieee80211_vif *vif)
3772 struct mwl8k_cmd_set_new_stn *cmd;
3775 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3779 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3780 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3781 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3783 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3789 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
3790 struct ieee80211_vif *vif, u8 *addr)
3792 struct mwl8k_cmd_set_new_stn *cmd;
3795 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3799 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3800 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3801 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3802 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
3804 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3811 * CMD_UPDATE_ENCRYPTION.
3814 #define MAX_ENCR_KEY_LENGTH 16
3815 #define MIC_KEY_LENGTH 8
3817 struct mwl8k_cmd_update_encryption {
3818 struct mwl8k_cmd_pkt header;
3827 struct mwl8k_cmd_set_key {
3828 struct mwl8k_cmd_pkt header;
3837 __u8 key_material[MAX_ENCR_KEY_LENGTH];
3838 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
3839 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
3840 __le16 tkip_rsc_low;
3841 __le32 tkip_rsc_high;
3842 __le16 tkip_tsc_low;
3843 __le32 tkip_tsc_high;
3850 MWL8K_ENCR_REMOVE_KEY,
3851 MWL8K_ENCR_SET_GROUP_KEY,
3854 #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
3855 #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
3856 #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
3857 #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
3858 #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
3866 #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
3867 #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
3868 #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
3869 #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
3870 #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
3872 static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
3873 struct ieee80211_vif *vif,
3877 struct mwl8k_cmd_update_encryption *cmd;
3880 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3884 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3885 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3886 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
3887 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3888 cmd->encr_type = encr_type;
3890 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3896 static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
3898 struct ieee80211_key_conf *key)
3900 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3901 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3902 cmd->length = cpu_to_le16(sizeof(*cmd) -
3903 offsetof(struct mwl8k_cmd_set_key, length));
3904 cmd->key_id = cpu_to_le32(key->keyidx);
3905 cmd->key_len = cpu_to_le16(key->keylen);
3906 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3908 switch (key->cipher) {
3909 case WLAN_CIPHER_SUITE_WEP40:
3910 case WLAN_CIPHER_SUITE_WEP104:
3911 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
3912 if (key->keyidx == 0)
3913 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
3916 case WLAN_CIPHER_SUITE_TKIP:
3917 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
3918 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3919 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
3920 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
3921 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
3922 | MWL8K_KEY_FLAG_TSC_VALID);
3924 case WLAN_CIPHER_SUITE_CCMP:
3925 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
3926 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3927 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
3928 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
3937 static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
3938 struct ieee80211_vif *vif,
3940 struct ieee80211_key_conf *key)
3942 struct mwl8k_cmd_set_key *cmd;
3947 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3949 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3953 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
3959 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3960 action = MWL8K_ENCR_SET_KEY;
3962 action = MWL8K_ENCR_SET_GROUP_KEY;
3964 switch (key->cipher) {
3965 case WLAN_CIPHER_SUITE_WEP40:
3966 case WLAN_CIPHER_SUITE_WEP104:
3967 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
3968 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
3969 sizeof(*key) + key->keylen);
3970 mwl8k_vif->wep_key_conf[idx].enabled = 1;
3974 action = MWL8K_ENCR_SET_KEY;
3976 case WLAN_CIPHER_SUITE_TKIP:
3977 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
3979 case WLAN_CIPHER_SUITE_CCMP:
3980 keymlen = key->keylen;
3987 memcpy(cmd->key_material, key->key, keymlen);
3988 cmd->action = cpu_to_le32(action);
3990 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3997 static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
3998 struct ieee80211_vif *vif,
4000 struct ieee80211_key_conf *key)
4002 struct mwl8k_cmd_set_key *cmd;
4004 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4006 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4010 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4014 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4015 WLAN_CIPHER_SUITE_WEP104)
4016 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
4018 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
4020 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4027 static int mwl8k_set_key(struct ieee80211_hw *hw,
4028 enum set_key_cmd cmd_param,
4029 struct ieee80211_vif *vif,
4030 struct ieee80211_sta *sta,
4031 struct ieee80211_key_conf *key)
4036 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4038 if (vif->type == NL80211_IFTYPE_STATION)
4042 addr = hw->wiphy->perm_addr;
4046 if (cmd_param == SET_KEY) {
4047 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4048 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
4052 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
4053 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
4054 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
4056 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
4058 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
4063 mwl8k_vif->is_hw_crypto_enabled = true;
4066 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
4071 mwl8k_vif->is_hw_crypto_enabled = false;
4081 struct ewc_ht_info {
4087 struct peer_capability_info {
4088 /* Peer type - AP vs. STA. */
4091 /* Basic 802.11 capabilities from assoc resp. */
4094 /* Set if peer supports 802.11n high throughput (HT). */
4097 /* Valid if HT is supported. */
4099 __u8 extended_ht_caps;
4100 struct ewc_ht_info ewc_info;
4102 /* Legacy rate table. Intersection of our rates and peer rates. */
4103 __u8 legacy_rates[12];
4105 /* HT rate table. Intersection of our rates and peer rates. */
4109 /* If set, interoperability mode, no proprietary extensions. */
4113 __le16 amsdu_enabled;
4116 struct mwl8k_cmd_update_stadb {
4117 struct mwl8k_cmd_pkt header;
4119 /* See STADB_ACTION_TYPE */
4122 /* Peer MAC address */
4123 __u8 peer_addr[ETH_ALEN];
4127 /* Peer info - valid during add/update. */
4128 struct peer_capability_info peer_info;
4131 #define MWL8K_STA_DB_MODIFY_ENTRY 1
4132 #define MWL8K_STA_DB_DEL_ENTRY 2
4134 /* Peer Entry flags - used to define the type of the peer node */
4135 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
4137 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
4138 struct ieee80211_vif *vif,
4139 struct ieee80211_sta *sta)
4141 struct mwl8k_cmd_update_stadb *cmd;
4142 struct peer_capability_info *p;
4146 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4150 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4151 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4152 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
4153 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
4155 p = &cmd->peer_info;
4156 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
4157 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
4158 p->ht_support = sta->ht_cap.ht_supported;
4159 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
4160 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
4161 ((sta->ht_cap.ampdu_density & 7) << 2);
4162 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4163 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
4165 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4166 legacy_rate_mask_to_array(p->legacy_rates, rates);
4167 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
4169 p->amsdu_enabled = 0;
4171 rc = mwl8k_post_cmd(hw, &cmd->header);
4174 return rc ? rc : p->station_id;
4177 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
4178 struct ieee80211_vif *vif, u8 *addr)
4180 struct mwl8k_cmd_update_stadb *cmd;
4183 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4187 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4188 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4189 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
4190 memcpy(cmd->peer_addr, addr, ETH_ALEN);
4192 rc = mwl8k_post_cmd(hw, &cmd->header);
4200 * Interrupt handling.
4202 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
4204 struct ieee80211_hw *hw = dev_id;
4205 struct mwl8k_priv *priv = hw->priv;
4208 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4212 if (status & MWL8K_A2H_INT_TX_DONE) {
4213 status &= ~MWL8K_A2H_INT_TX_DONE;
4214 tasklet_schedule(&priv->poll_tx_task);
4217 if (status & MWL8K_A2H_INT_RX_READY) {
4218 status &= ~MWL8K_A2H_INT_RX_READY;
4219 tasklet_schedule(&priv->poll_rx_task);
4222 if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
4223 status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
4224 ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
4228 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4230 if (status & MWL8K_A2H_INT_OPC_DONE) {
4231 if (priv->hostcmd_wait != NULL)
4232 complete(priv->hostcmd_wait);
4235 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
4236 if (!mutex_is_locked(&priv->fw_mutex) &&
4237 priv->radio_on && priv->pending_tx_pkts)
4238 mwl8k_tx_start(priv);
4244 static void mwl8k_tx_poll(unsigned long data)
4246 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4247 struct mwl8k_priv *priv = hw->priv;
4253 spin_lock_bh(&priv->tx_lock);
4255 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4256 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
4258 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
4259 complete(priv->tx_wait);
4260 priv->tx_wait = NULL;
4263 spin_unlock_bh(&priv->tx_lock);
4266 writel(~MWL8K_A2H_INT_TX_DONE,
4267 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4269 tasklet_schedule(&priv->poll_tx_task);
4273 static void mwl8k_rx_poll(unsigned long data)
4275 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4276 struct mwl8k_priv *priv = hw->priv;
4280 limit -= rxq_process(hw, 0, limit);
4281 limit -= rxq_refill(hw, 0, limit);
4284 writel(~MWL8K_A2H_INT_RX_READY,
4285 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4287 tasklet_schedule(&priv->poll_rx_task);
4293 * Core driver operations.
4295 static void mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
4297 struct mwl8k_priv *priv = hw->priv;
4298 int index = skb_get_queue_mapping(skb);
4300 if (!priv->radio_on) {
4301 wiphy_debug(hw->wiphy,
4302 "dropped TX frame since radio disabled\n");
4307 mwl8k_txq_xmit(hw, index, skb);
4310 static int mwl8k_start(struct ieee80211_hw *hw)
4312 struct mwl8k_priv *priv = hw->priv;
4315 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
4316 IRQF_SHARED, MWL8K_NAME, hw);
4319 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
4322 priv->irq = priv->pdev->irq;
4324 /* Enable TX reclaim and RX tasklets. */
4325 tasklet_enable(&priv->poll_tx_task);
4326 tasklet_enable(&priv->poll_rx_task);
4328 /* Enable interrupts */
4329 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4330 iowrite32(MWL8K_A2H_EVENTS,
4331 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4333 rc = mwl8k_fw_lock(hw);
4335 rc = mwl8k_cmd_radio_enable(hw);
4339 rc = mwl8k_cmd_enable_sniffer(hw, 0);
4342 rc = mwl8k_cmd_set_pre_scan(hw);
4345 rc = mwl8k_cmd_set_post_scan(hw,
4346 "\x00\x00\x00\x00\x00\x00");
4350 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
4353 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
4355 mwl8k_fw_unlock(hw);
4359 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4360 free_irq(priv->pdev->irq, hw);
4362 tasklet_disable(&priv->poll_tx_task);
4363 tasklet_disable(&priv->poll_rx_task);
4369 static void mwl8k_stop(struct ieee80211_hw *hw)
4371 struct mwl8k_priv *priv = hw->priv;
4374 mwl8k_cmd_radio_disable(hw);
4376 ieee80211_stop_queues(hw);
4378 /* Disable interrupts */
4379 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4380 if (priv->irq != -1) {
4381 free_irq(priv->pdev->irq, hw);
4385 /* Stop finalize join worker */
4386 cancel_work_sync(&priv->finalize_join_worker);
4387 cancel_work_sync(&priv->watchdog_ba_handle);
4388 if (priv->beacon_skb != NULL)
4389 dev_kfree_skb(priv->beacon_skb);
4391 /* Stop TX reclaim and RX tasklets. */
4392 tasklet_disable(&priv->poll_tx_task);
4393 tasklet_disable(&priv->poll_rx_task);
4395 /* Return all skbs to mac80211 */
4396 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4397 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
4400 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
4402 static int mwl8k_add_interface(struct ieee80211_hw *hw,
4403 struct ieee80211_vif *vif)
4405 struct mwl8k_priv *priv = hw->priv;
4406 struct mwl8k_vif *mwl8k_vif;
4407 u32 macids_supported;
4409 struct mwl8k_device_info *di;
4412 * Reject interface creation if sniffer mode is active, as
4413 * STA operation is mutually exclusive with hardware sniffer
4414 * mode. (Sniffer mode is only used on STA firmware.)
4416 if (priv->sniffer_enabled) {
4417 wiphy_info(hw->wiphy,
4418 "unable to create STA interface because sniffer mode is enabled\n");
4422 di = priv->device_info;
4423 switch (vif->type) {
4424 case NL80211_IFTYPE_AP:
4425 if (!priv->ap_fw && di->fw_image_ap) {
4426 /* we must load the ap fw to meet this request */
4427 if (!list_empty(&priv->vif_list))
4429 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4433 macids_supported = priv->ap_macids_supported;
4435 case NL80211_IFTYPE_STATION:
4436 if (priv->ap_fw && di->fw_image_sta) {
4437 /* we must load the sta fw to meet this request */
4438 if (!list_empty(&priv->vif_list))
4440 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4444 macids_supported = priv->sta_macids_supported;
4450 macid = ffs(macids_supported & ~priv->macids_used);
4454 /* Setup driver private area. */
4455 mwl8k_vif = MWL8K_VIF(vif);
4456 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
4457 mwl8k_vif->vif = vif;
4458 mwl8k_vif->macid = macid;
4459 mwl8k_vif->seqno = 0;
4460 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
4461 mwl8k_vif->is_hw_crypto_enabled = false;
4463 /* Set the mac address. */
4464 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
4467 mwl8k_cmd_set_new_stn_add_self(hw, vif);
4469 priv->macids_used |= 1 << mwl8k_vif->macid;
4470 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
4475 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
4476 struct ieee80211_vif *vif)
4478 struct mwl8k_priv *priv = hw->priv;
4479 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4482 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
4484 mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
4486 priv->macids_used &= ~(1 << mwl8k_vif->macid);
4487 list_del(&mwl8k_vif->list);
4490 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
4492 struct ieee80211_conf *conf = &hw->conf;
4493 struct mwl8k_priv *priv = hw->priv;
4496 if (conf->flags & IEEE80211_CONF_IDLE) {
4497 mwl8k_cmd_radio_disable(hw);
4501 rc = mwl8k_fw_lock(hw);
4505 rc = mwl8k_cmd_radio_enable(hw);
4509 rc = mwl8k_cmd_set_rf_channel(hw, conf);
4513 if (conf->power_level > 18)
4514 conf->power_level = 18;
4518 if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
4519 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
4524 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
4526 wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
4527 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
4529 wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
4532 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
4535 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
4539 mwl8k_fw_unlock(hw);
4545 mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4546 struct ieee80211_bss_conf *info, u32 changed)
4548 struct mwl8k_priv *priv = hw->priv;
4549 u32 ap_legacy_rates = 0;
4550 u8 ap_mcs_rates[16];
4553 if (mwl8k_fw_lock(hw))
4557 * No need to capture a beacon if we're no longer associated.
4559 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
4560 priv->capture_beacon = false;
4563 * Get the AP's legacy and MCS rates.
4565 if (vif->bss_conf.assoc) {
4566 struct ieee80211_sta *ap;
4570 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
4576 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
4577 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
4580 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4582 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
4587 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
4588 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
4592 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
4597 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4598 rc = mwl8k_set_radio_preamble(hw,
4599 vif->bss_conf.use_short_preamble);
4604 if (changed & BSS_CHANGED_ERP_SLOT) {
4605 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
4610 if (vif->bss_conf.assoc &&
4611 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4613 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
4618 if (vif->bss_conf.assoc &&
4619 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
4621 * Finalize the join. Tell rx handler to process
4622 * next beacon from our BSSID.
4624 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
4625 priv->capture_beacon = true;
4629 mwl8k_fw_unlock(hw);
4633 mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4634 struct ieee80211_bss_conf *info, u32 changed)
4638 if (mwl8k_fw_lock(hw))
4641 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4642 rc = mwl8k_set_radio_preamble(hw,
4643 vif->bss_conf.use_short_preamble);
4648 if (changed & BSS_CHANGED_BASIC_RATES) {
4653 * Use lowest supported basic rate for multicasts
4654 * and management frames (such as probe responses --
4655 * beacons will always go out at 1 Mb/s).
4657 idx = ffs(vif->bss_conf.basic_rates);
4661 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4662 rate = mwl8k_rates_24[idx].hw_value;
4664 rate = mwl8k_rates_50[idx].hw_value;
4666 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4669 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
4670 struct sk_buff *skb;
4672 skb = ieee80211_beacon_get(hw, vif);
4674 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
4679 if (changed & BSS_CHANGED_BEACON_ENABLED)
4680 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
4683 mwl8k_fw_unlock(hw);
4687 mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4688 struct ieee80211_bss_conf *info, u32 changed)
4690 struct mwl8k_priv *priv = hw->priv;
4693 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
4695 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
4698 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
4699 struct netdev_hw_addr_list *mc_list)
4701 struct mwl8k_cmd_pkt *cmd;
4704 * Synthesize and return a command packet that programs the
4705 * hardware multicast address filter. At this point we don't
4706 * know whether FIF_ALLMULTI is being requested, but if it is,
4707 * we'll end up throwing this packet away and creating a new
4708 * one in mwl8k_configure_filter().
4710 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
4712 return (unsigned long)cmd;
4716 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
4717 unsigned int changed_flags,
4718 unsigned int *total_flags)
4720 struct mwl8k_priv *priv = hw->priv;
4723 * Hardware sniffer mode is mutually exclusive with STA
4724 * operation, so refuse to enable sniffer mode if a STA
4725 * interface is active.
4727 if (!list_empty(&priv->vif_list)) {
4728 if (net_ratelimit())
4729 wiphy_info(hw->wiphy,
4730 "not enabling sniffer mode because STA interface is active\n");
4734 if (!priv->sniffer_enabled) {
4735 if (mwl8k_cmd_enable_sniffer(hw, 1))
4737 priv->sniffer_enabled = true;
4740 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
4741 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
4747 static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
4749 if (!list_empty(&priv->vif_list))
4750 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
4755 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
4756 unsigned int changed_flags,
4757 unsigned int *total_flags,
4760 struct mwl8k_priv *priv = hw->priv;
4761 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
4764 * AP firmware doesn't allow fine-grained control over
4765 * the receive filter.
4768 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4774 * Enable hardware sniffer mode if FIF_CONTROL or
4775 * FIF_OTHER_BSS is requested.
4777 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
4778 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
4783 /* Clear unsupported feature flags */
4784 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4786 if (mwl8k_fw_lock(hw)) {
4791 if (priv->sniffer_enabled) {
4792 mwl8k_cmd_enable_sniffer(hw, 0);
4793 priv->sniffer_enabled = false;
4796 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
4797 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
4799 * Disable the BSS filter.
4801 mwl8k_cmd_set_pre_scan(hw);
4803 struct mwl8k_vif *mwl8k_vif;
4807 * Enable the BSS filter.
4809 * If there is an active STA interface, use that
4810 * interface's BSSID, otherwise use a dummy one
4811 * (where the OUI part needs to be nonzero for
4812 * the BSSID to be accepted by POST_SCAN).
4814 mwl8k_vif = mwl8k_first_vif(priv);
4815 if (mwl8k_vif != NULL)
4816 bssid = mwl8k_vif->vif->bss_conf.bssid;
4818 bssid = "\x01\x00\x00\x00\x00\x00";
4820 mwl8k_cmd_set_post_scan(hw, bssid);
4825 * If FIF_ALLMULTI is being requested, throw away the command
4826 * packet that ->prepare_multicast() built and replace it with
4827 * a command packet that enables reception of all multicast
4830 if (*total_flags & FIF_ALLMULTI) {
4832 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
4836 mwl8k_post_cmd(hw, cmd);
4840 mwl8k_fw_unlock(hw);
4843 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4845 return mwl8k_cmd_set_rts_threshold(hw, value);
4848 static int mwl8k_sta_remove(struct ieee80211_hw *hw,
4849 struct ieee80211_vif *vif,
4850 struct ieee80211_sta *sta)
4852 struct mwl8k_priv *priv = hw->priv;
4855 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
4857 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
4860 static int mwl8k_sta_add(struct ieee80211_hw *hw,
4861 struct ieee80211_vif *vif,
4862 struct ieee80211_sta *sta)
4864 struct mwl8k_priv *priv = hw->priv;
4867 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4868 struct ieee80211_key_conf *key;
4871 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
4873 MWL8K_STA(sta)->peer_id = ret;
4874 if (sta->ht_cap.ht_supported)
4875 MWL8K_STA(sta)->is_ampdu_allowed = true;
4880 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
4883 for (i = 0; i < NUM_WEP_KEYS; i++) {
4884 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
4885 if (mwl8k_vif->wep_key_conf[i].enabled)
4886 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
4891 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
4892 const struct ieee80211_tx_queue_params *params)
4894 struct mwl8k_priv *priv = hw->priv;
4897 rc = mwl8k_fw_lock(hw);
4899 BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
4900 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
4902 if (!priv->wmm_enabled)
4903 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
4906 int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
4907 rc = mwl8k_cmd_set_edca_params(hw, q,
4914 mwl8k_fw_unlock(hw);
4920 static int mwl8k_get_stats(struct ieee80211_hw *hw,
4921 struct ieee80211_low_level_stats *stats)
4923 return mwl8k_cmd_get_stat(hw, stats);
4926 static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
4927 struct survey_info *survey)
4929 struct mwl8k_priv *priv = hw->priv;
4930 struct ieee80211_conf *conf = &hw->conf;
4935 survey->channel = conf->channel;
4936 survey->filled = SURVEY_INFO_NOISE_DBM;
4937 survey->noise = priv->noise;
4942 #define MAX_AMPDU_ATTEMPTS 5
4945 mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4946 enum ieee80211_ampdu_mlme_action action,
4947 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4952 struct mwl8k_priv *priv = hw->priv;
4953 struct mwl8k_ampdu_stream *stream;
4954 u8 *addr = sta->addr;
4956 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
4959 spin_lock(&priv->stream_lock);
4960 stream = mwl8k_lookup_stream(hw, addr, tid);
4963 case IEEE80211_AMPDU_RX_START:
4964 case IEEE80211_AMPDU_RX_STOP:
4966 case IEEE80211_AMPDU_TX_START:
4967 /* By the time we get here the hw queues may contain outgoing
4968 * packets for this RA/TID that are not part of this BA
4969 * session. The hw will assign sequence numbers to these
4970 * packets as they go out. So if we query the hw for its next
4971 * sequence number and use that for the SSN here, it may end up
4972 * being wrong, which will lead to sequence number mismatch at
4973 * the recipient. To avoid this, we reset the sequence number
4974 * to O for the first MPDU in this BA stream.
4977 if (stream == NULL) {
4978 /* This means that somebody outside this driver called
4979 * ieee80211_start_tx_ba_session. This is unexpected
4980 * because we do our own rate control. Just warn and
4983 wiphy_warn(hw->wiphy, "Unexpected call to %s. "
4984 "Proceeding anyway.\n", __func__);
4985 stream = mwl8k_add_stream(hw, sta, tid);
4987 if (stream == NULL) {
4988 wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
4992 stream->state = AMPDU_STREAM_IN_PROGRESS;
4994 /* Release the lock before we do the time consuming stuff */
4995 spin_unlock(&priv->stream_lock);
4996 for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
4997 rc = mwl8k_check_ba(hw, stream);
5002 * HW queues take time to be flushed, give them
5008 spin_lock(&priv->stream_lock);
5010 wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
5011 " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
5012 mwl8k_remove_stream(hw, stream);
5016 ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
5018 case IEEE80211_AMPDU_TX_STOP:
5021 if (stream->state == AMPDU_STREAM_ACTIVE) {
5022 spin_unlock(&priv->stream_lock);
5023 mwl8k_destroy_ba(hw, stream);
5024 spin_lock(&priv->stream_lock);
5026 mwl8k_remove_stream(hw, stream);
5027 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
5029 case IEEE80211_AMPDU_TX_OPERATIONAL:
5030 BUG_ON(stream == NULL);
5031 BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
5032 spin_unlock(&priv->stream_lock);
5033 rc = mwl8k_create_ba(hw, stream, buf_size);
5034 spin_lock(&priv->stream_lock);
5036 stream->state = AMPDU_STREAM_ACTIVE;
5038 spin_unlock(&priv->stream_lock);
5039 mwl8k_destroy_ba(hw, stream);
5040 spin_lock(&priv->stream_lock);
5041 wiphy_debug(hw->wiphy,
5042 "Failed adding stream for sta %pM tid %d\n",
5044 mwl8k_remove_stream(hw, stream);
5052 spin_unlock(&priv->stream_lock);
5056 static const struct ieee80211_ops mwl8k_ops = {
5058 .start = mwl8k_start,
5060 .add_interface = mwl8k_add_interface,
5061 .remove_interface = mwl8k_remove_interface,
5062 .config = mwl8k_config,
5063 .bss_info_changed = mwl8k_bss_info_changed,
5064 .prepare_multicast = mwl8k_prepare_multicast,
5065 .configure_filter = mwl8k_configure_filter,
5066 .set_key = mwl8k_set_key,
5067 .set_rts_threshold = mwl8k_set_rts_threshold,
5068 .sta_add = mwl8k_sta_add,
5069 .sta_remove = mwl8k_sta_remove,
5070 .conf_tx = mwl8k_conf_tx,
5071 .get_stats = mwl8k_get_stats,
5072 .get_survey = mwl8k_get_survey,
5073 .ampdu_action = mwl8k_ampdu_action,
5076 static void mwl8k_finalize_join_worker(struct work_struct *work)
5078 struct mwl8k_priv *priv =
5079 container_of(work, struct mwl8k_priv, finalize_join_worker);
5080 struct sk_buff *skb = priv->beacon_skb;
5081 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5082 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
5083 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
5084 mgmt->u.beacon.variable, len);
5085 int dtim_period = 1;
5087 if (tim && tim[1] >= 2)
5088 dtim_period = tim[3];
5090 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
5093 priv->beacon_skb = NULL;
5102 #define MWL8K_8366_AP_FW_API 2
5103 #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5104 #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5106 static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
5108 .part_name = "88w8363",
5109 .helper_image = "mwl8k/helper_8363.fw",
5110 .fw_image_sta = "mwl8k/fmimage_8363.fw",
5113 .part_name = "88w8687",
5114 .helper_image = "mwl8k/helper_8687.fw",
5115 .fw_image_sta = "mwl8k/fmimage_8687.fw",
5118 .part_name = "88w8366",
5119 .helper_image = "mwl8k/helper_8366.fw",
5120 .fw_image_sta = "mwl8k/fmimage_8366.fw",
5121 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
5122 .fw_api_ap = MWL8K_8366_AP_FW_API,
5123 .ap_rxd_ops = &rxd_8366_ap_ops,
5127 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5128 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5129 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5130 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5131 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5132 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
5133 MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
5135 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
5136 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
5137 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
5138 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
5139 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
5140 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
5141 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
5142 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
5145 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
5147 static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
5150 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
5151 "Trying alternative firmware %s\n", pci_name(priv->pdev),
5152 priv->fw_pref, priv->fw_alt);
5153 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
5155 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5156 pci_name(priv->pdev), priv->fw_alt);
5162 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
5163 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
5165 struct mwl8k_priv *priv = context;
5166 struct mwl8k_device_info *di = priv->device_info;
5169 switch (priv->fw_state) {
5172 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
5173 pci_name(priv->pdev), di->helper_image);
5176 priv->fw_helper = fw;
5177 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
5179 if (rc && priv->fw_alt) {
5180 rc = mwl8k_request_alt_fw(priv);
5183 priv->fw_state = FW_STATE_LOADING_ALT;
5187 priv->fw_state = FW_STATE_LOADING_PREF;
5190 case FW_STATE_LOADING_PREF:
5193 rc = mwl8k_request_alt_fw(priv);
5196 priv->fw_state = FW_STATE_LOADING_ALT;
5200 priv->fw_ucode = fw;
5201 rc = mwl8k_firmware_load_success(priv);
5205 complete(&priv->firmware_loading_complete);
5209 case FW_STATE_LOADING_ALT:
5211 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5212 pci_name(priv->pdev), di->helper_image);
5215 priv->fw_ucode = fw;
5216 rc = mwl8k_firmware_load_success(priv);
5220 complete(&priv->firmware_loading_complete);
5224 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
5225 MWL8K_NAME, priv->fw_state);
5232 priv->fw_state = FW_STATE_ERROR;
5233 complete(&priv->firmware_loading_complete);
5234 device_release_driver(&priv->pdev->dev);
5235 mwl8k_release_firmware(priv);
5238 static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
5241 struct mwl8k_priv *priv = hw->priv;
5244 /* Reset firmware and hardware */
5245 mwl8k_hw_reset(priv);
5247 /* Ask userland hotplug daemon for the device firmware */
5248 rc = mwl8k_request_firmware(priv, fw_image, nowait);
5250 wiphy_err(hw->wiphy, "Firmware files not found\n");
5257 /* Load firmware into hardware */
5258 rc = mwl8k_load_firmware(hw);
5260 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5262 /* Reclaim memory once firmware is successfully loaded */
5263 mwl8k_release_firmware(priv);
5268 static int mwl8k_init_txqs(struct ieee80211_hw *hw)
5270 struct mwl8k_priv *priv = hw->priv;
5274 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
5275 rc = mwl8k_txq_init(hw, i);
5279 iowrite32(priv->txq[i].txd_dma,
5280 priv->sram + priv->txq_offset[i]);
5285 /* initialize hw after successfully loading a firmware image */
5286 static int mwl8k_probe_hw(struct ieee80211_hw *hw)
5288 struct mwl8k_priv *priv = hw->priv;
5293 priv->rxd_ops = priv->device_info->ap_rxd_ops;
5294 if (priv->rxd_ops == NULL) {
5295 wiphy_err(hw->wiphy,
5296 "Driver does not have AP firmware image support for this hardware\n");
5297 goto err_stop_firmware;
5300 priv->rxd_ops = &rxd_sta_ops;
5303 priv->sniffer_enabled = false;
5304 priv->wmm_enabled = false;
5305 priv->pending_tx_pkts = 0;
5307 rc = mwl8k_rxq_init(hw, 0);
5309 goto err_stop_firmware;
5310 rxq_refill(hw, 0, INT_MAX);
5312 /* For the sta firmware, we need to know the dma addresses of tx queues
5313 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5314 * prior to issuing this command. But for the AP case, we learn the
5315 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5316 * case we must initialize the tx queues after.
5318 priv->num_ampdu_queues = 0;
5320 rc = mwl8k_init_txqs(hw);
5322 goto err_free_queues;
5325 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
5326 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5327 iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
5328 MWL8K_A2H_INT_BA_WATCHDOG,
5329 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
5330 iowrite32(MWL8K_A2H_INT_OPC_DONE,
5331 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
5333 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
5334 IRQF_SHARED, MWL8K_NAME, hw);
5336 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
5337 goto err_free_queues;
5340 memset(priv->ampdu, 0, sizeof(priv->ampdu));
5343 * Temporarily enable interrupts. Initial firmware host
5344 * commands use interrupts and avoid polling. Disable
5345 * interrupts when done.
5347 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5349 /* Get config data, mac addrs etc */
5351 rc = mwl8k_cmd_get_hw_spec_ap(hw);
5353 rc = mwl8k_init_txqs(hw);
5355 rc = mwl8k_cmd_set_hw_spec(hw);
5357 rc = mwl8k_cmd_get_hw_spec_sta(hw);
5360 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
5364 /* Turn radio off */
5365 rc = mwl8k_cmd_radio_disable(hw);
5367 wiphy_err(hw->wiphy, "Cannot disable\n");
5371 /* Clear MAC address */
5372 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
5374 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
5378 /* Disable interrupts */
5379 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5380 free_irq(priv->pdev->irq, hw);
5382 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5383 priv->device_info->part_name,
5384 priv->hw_rev, hw->wiphy->perm_addr,
5385 priv->ap_fw ? "AP" : "STA",
5386 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
5387 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
5392 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5393 free_irq(priv->pdev->irq, hw);
5396 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5397 mwl8k_txq_deinit(hw, i);
5398 mwl8k_rxq_deinit(hw, 0);
5401 mwl8k_hw_reset(priv);
5407 * invoke mwl8k_reload_firmware to change the firmware image after the device
5408 * has already been registered
5410 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
5413 struct mwl8k_priv *priv = hw->priv;
5416 mwl8k_rxq_deinit(hw, 0);
5418 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5419 mwl8k_txq_deinit(hw, i);
5421 rc = mwl8k_init_firmware(hw, fw_image, false);
5425 rc = mwl8k_probe_hw(hw);
5429 rc = mwl8k_start(hw);
5433 rc = mwl8k_config(hw, ~0);
5437 for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
5438 rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
5446 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
5450 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
5452 struct ieee80211_hw *hw = priv->hw;
5455 rc = mwl8k_load_firmware(hw);
5456 mwl8k_release_firmware(priv);
5458 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5463 * Extra headroom is the size of the required DMA header
5464 * minus the size of the smallest 802.11 frame (CTS frame).
5466 hw->extra_tx_headroom =
5467 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
5469 hw->channel_change_time = 10;
5471 hw->queues = MWL8K_TX_WMM_QUEUES;
5473 /* Set rssi values to dBm */
5474 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
5475 hw->vif_data_size = sizeof(struct mwl8k_vif);
5476 hw->sta_data_size = sizeof(struct mwl8k_sta);
5478 priv->macids_used = 0;
5479 INIT_LIST_HEAD(&priv->vif_list);
5481 /* Set default radio state and preamble */
5483 priv->radio_short_preamble = 0;
5485 /* Finalize join worker */
5486 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
5487 /* Handle watchdog ba events */
5488 INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
5490 /* TX reclaim and RX tasklets. */
5491 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
5492 tasklet_disable(&priv->poll_tx_task);
5493 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
5494 tasklet_disable(&priv->poll_rx_task);
5496 /* Power management cookie */
5497 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
5498 if (priv->cookie == NULL)
5501 mutex_init(&priv->fw_mutex);
5502 priv->fw_mutex_owner = NULL;
5503 priv->fw_mutex_depth = 0;
5504 priv->hostcmd_wait = NULL;
5506 spin_lock_init(&priv->tx_lock);
5508 spin_lock_init(&priv->stream_lock);
5510 priv->tx_wait = NULL;
5512 rc = mwl8k_probe_hw(hw);
5514 goto err_free_cookie;
5516 hw->wiphy->interface_modes = 0;
5517 if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
5518 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
5519 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
5520 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
5522 rc = ieee80211_register_hw(hw);
5524 wiphy_err(hw->wiphy, "Cannot register device\n");
5525 goto err_unprobe_hw;
5531 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5532 mwl8k_txq_deinit(hw, i);
5533 mwl8k_rxq_deinit(hw, 0);
5536 if (priv->cookie != NULL)
5537 pci_free_consistent(priv->pdev, 4,
5538 priv->cookie, priv->cookie_dma);
5542 static int __devinit mwl8k_probe(struct pci_dev *pdev,
5543 const struct pci_device_id *id)
5545 static int printed_version;
5546 struct ieee80211_hw *hw;
5547 struct mwl8k_priv *priv;
5548 struct mwl8k_device_info *di;
5551 if (!printed_version) {
5552 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
5553 printed_version = 1;
5557 rc = pci_enable_device(pdev);
5559 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
5564 rc = pci_request_regions(pdev, MWL8K_NAME);
5566 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
5568 goto err_disable_device;
5571 pci_set_master(pdev);
5574 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
5576 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
5581 SET_IEEE80211_DEV(hw, &pdev->dev);
5582 pci_set_drvdata(pdev, hw);
5587 priv->device_info = &mwl8k_info_tbl[id->driver_data];
5590 priv->sram = pci_iomap(pdev, 0, 0x10000);
5591 if (priv->sram == NULL) {
5592 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
5597 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
5598 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
5600 priv->regs = pci_iomap(pdev, 1, 0x10000);
5601 if (priv->regs == NULL) {
5602 priv->regs = pci_iomap(pdev, 2, 0x10000);
5603 if (priv->regs == NULL) {
5604 wiphy_err(hw->wiphy, "Cannot map device registers\n");
5610 * Choose the initial fw image depending on user input. If a second
5611 * image is available, make it the alternative image that will be
5612 * loaded if the first one fails.
5614 init_completion(&priv->firmware_loading_complete);
5615 di = priv->device_info;
5616 if (ap_mode_default && di->fw_image_ap) {
5617 priv->fw_pref = di->fw_image_ap;
5618 priv->fw_alt = di->fw_image_sta;
5619 } else if (!ap_mode_default && di->fw_image_sta) {
5620 priv->fw_pref = di->fw_image_sta;
5621 priv->fw_alt = di->fw_image_ap;
5622 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
5623 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
5624 priv->fw_pref = di->fw_image_sta;
5625 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
5626 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
5627 priv->fw_pref = di->fw_image_ap;
5629 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
5631 goto err_stop_firmware;
5635 mwl8k_hw_reset(priv);
5638 if (priv->regs != NULL)
5639 pci_iounmap(pdev, priv->regs);
5641 if (priv->sram != NULL)
5642 pci_iounmap(pdev, priv->sram);
5644 pci_set_drvdata(pdev, NULL);
5645 ieee80211_free_hw(hw);
5648 pci_release_regions(pdev);
5651 pci_disable_device(pdev);
5656 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
5658 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
5661 static void __devexit mwl8k_remove(struct pci_dev *pdev)
5663 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
5664 struct mwl8k_priv *priv;
5671 wait_for_completion(&priv->firmware_loading_complete);
5673 if (priv->fw_state == FW_STATE_ERROR) {
5674 mwl8k_hw_reset(priv);
5678 ieee80211_stop_queues(hw);
5680 ieee80211_unregister_hw(hw);
5682 /* Remove TX reclaim and RX tasklets. */
5683 tasklet_kill(&priv->poll_tx_task);
5684 tasklet_kill(&priv->poll_rx_task);
5687 mwl8k_hw_reset(priv);
5689 /* Return all skbs to mac80211 */
5690 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5691 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
5693 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5694 mwl8k_txq_deinit(hw, i);
5696 mwl8k_rxq_deinit(hw, 0);
5698 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
5701 pci_iounmap(pdev, priv->regs);
5702 pci_iounmap(pdev, priv->sram);
5703 pci_set_drvdata(pdev, NULL);
5704 ieee80211_free_hw(hw);
5705 pci_release_regions(pdev);
5706 pci_disable_device(pdev);
5709 static struct pci_driver mwl8k_driver = {
5711 .id_table = mwl8k_pci_id_table,
5712 .probe = mwl8k_probe,
5713 .remove = __devexit_p(mwl8k_remove),
5714 .shutdown = __devexit_p(mwl8k_shutdown),
5717 static int __init mwl8k_init(void)
5719 return pci_register_driver(&mwl8k_driver);
5722 static void __exit mwl8k_exit(void)
5724 pci_unregister_driver(&mwl8k_driver);
5727 module_init(mwl8k_init);
5728 module_exit(mwl8k_exit);
5730 MODULE_DESCRIPTION(MWL8K_DESC);
5731 MODULE_VERSION(MWL8K_VERSION);
5732 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
5733 MODULE_LICENSE("GPL");