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;
161 struct mwl8k_device_info *device_info;
167 const struct firmware *fw_helper;
168 const struct firmware *fw_ucode;
170 /* hardware/firmware parameters */
172 struct rxd_ops *rxd_ops;
173 struct ieee80211_supported_band band_24;
174 struct ieee80211_channel channels_24[14];
175 struct ieee80211_rate rates_24[14];
176 struct ieee80211_supported_band band_50;
177 struct ieee80211_channel channels_50[4];
178 struct ieee80211_rate rates_50[9];
179 u32 ap_macids_supported;
180 u32 sta_macids_supported;
182 /* Ampdu stream information */
184 spinlock_t stream_lock;
185 struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
186 struct work_struct watchdog_ba_handle;
188 /* firmware access */
189 struct mutex fw_mutex;
190 struct task_struct *fw_mutex_owner;
192 struct completion *hostcmd_wait;
194 /* lock held over TX and TX reap */
197 /* TX quiesce completion, protected by fw_mutex and tx_lock */
198 struct completion *tx_wait;
200 /* List of interfaces. */
202 struct list_head vif_list;
204 /* power management status cookie from firmware */
206 dma_addr_t cookie_dma;
213 * Running count of TX packets in flight, to avoid
214 * iterating over the transmit rings each time.
218 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
219 struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
220 u32 txq_offset[MWL8K_MAX_TX_QUEUES];
223 bool radio_short_preamble;
224 bool sniffer_enabled;
227 /* XXX need to convert this to handle multiple interfaces */
229 u8 capture_bssid[ETH_ALEN];
230 struct sk_buff *beacon_skb;
233 * This FJ worker has to be global as it is scheduled from the
234 * RX handler. At this point we don't know which interface it
235 * belongs to until the list of bssids waiting to complete join
238 struct work_struct finalize_join_worker;
240 /* Tasklet to perform TX reclaim. */
241 struct tasklet_struct poll_tx_task;
243 /* Tasklet to perform RX. */
244 struct tasklet_struct poll_rx_task;
246 /* Most recently reported noise in dBm */
250 * preserve the queue configurations so they can be restored if/when
251 * the firmware image is swapped.
253 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
255 /* async firmware loading state */
259 struct completion firmware_loading_complete;
262 #define MAX_WEP_KEY_LEN 13
263 #define NUM_WEP_KEYS 4
265 /* Per interface specific private data */
267 struct list_head list;
268 struct ieee80211_vif *vif;
270 /* Firmware macid for this vif. */
273 /* Non AMPDU sequence number assigned by driver. */
279 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
280 } wep_key_conf[NUM_WEP_KEYS];
285 /* A flag to indicate is HW crypto is enabled for this bssid */
286 bool is_hw_crypto_enabled;
288 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
289 #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
292 /* Index into station database. Returned by UPDATE_STADB. */
296 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
298 static const struct ieee80211_channel mwl8k_channels_24[] = {
299 { .center_freq = 2412, .hw_value = 1, },
300 { .center_freq = 2417, .hw_value = 2, },
301 { .center_freq = 2422, .hw_value = 3, },
302 { .center_freq = 2427, .hw_value = 4, },
303 { .center_freq = 2432, .hw_value = 5, },
304 { .center_freq = 2437, .hw_value = 6, },
305 { .center_freq = 2442, .hw_value = 7, },
306 { .center_freq = 2447, .hw_value = 8, },
307 { .center_freq = 2452, .hw_value = 9, },
308 { .center_freq = 2457, .hw_value = 10, },
309 { .center_freq = 2462, .hw_value = 11, },
310 { .center_freq = 2467, .hw_value = 12, },
311 { .center_freq = 2472, .hw_value = 13, },
312 { .center_freq = 2484, .hw_value = 14, },
315 static const struct ieee80211_rate mwl8k_rates_24[] = {
316 { .bitrate = 10, .hw_value = 2, },
317 { .bitrate = 20, .hw_value = 4, },
318 { .bitrate = 55, .hw_value = 11, },
319 { .bitrate = 110, .hw_value = 22, },
320 { .bitrate = 220, .hw_value = 44, },
321 { .bitrate = 60, .hw_value = 12, },
322 { .bitrate = 90, .hw_value = 18, },
323 { .bitrate = 120, .hw_value = 24, },
324 { .bitrate = 180, .hw_value = 36, },
325 { .bitrate = 240, .hw_value = 48, },
326 { .bitrate = 360, .hw_value = 72, },
327 { .bitrate = 480, .hw_value = 96, },
328 { .bitrate = 540, .hw_value = 108, },
329 { .bitrate = 720, .hw_value = 144, },
332 static const struct ieee80211_channel mwl8k_channels_50[] = {
333 { .center_freq = 5180, .hw_value = 36, },
334 { .center_freq = 5200, .hw_value = 40, },
335 { .center_freq = 5220, .hw_value = 44, },
336 { .center_freq = 5240, .hw_value = 48, },
339 static const struct ieee80211_rate mwl8k_rates_50[] = {
340 { .bitrate = 60, .hw_value = 12, },
341 { .bitrate = 90, .hw_value = 18, },
342 { .bitrate = 120, .hw_value = 24, },
343 { .bitrate = 180, .hw_value = 36, },
344 { .bitrate = 240, .hw_value = 48, },
345 { .bitrate = 360, .hw_value = 72, },
346 { .bitrate = 480, .hw_value = 96, },
347 { .bitrate = 540, .hw_value = 108, },
348 { .bitrate = 720, .hw_value = 144, },
351 /* Set or get info from Firmware */
352 #define MWL8K_CMD_GET 0x0000
353 #define MWL8K_CMD_SET 0x0001
354 #define MWL8K_CMD_SET_LIST 0x0002
356 /* Firmware command codes */
357 #define MWL8K_CMD_CODE_DNLD 0x0001
358 #define MWL8K_CMD_GET_HW_SPEC 0x0003
359 #define MWL8K_CMD_SET_HW_SPEC 0x0004
360 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
361 #define MWL8K_CMD_GET_STAT 0x0014
362 #define MWL8K_CMD_RADIO_CONTROL 0x001c
363 #define MWL8K_CMD_RF_TX_POWER 0x001e
364 #define MWL8K_CMD_TX_POWER 0x001f
365 #define MWL8K_CMD_RF_ANTENNA 0x0020
366 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
367 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
368 #define MWL8K_CMD_SET_POST_SCAN 0x0108
369 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
370 #define MWL8K_CMD_SET_AID 0x010d
371 #define MWL8K_CMD_SET_RATE 0x0110
372 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
373 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
374 #define MWL8K_CMD_SET_SLOT 0x0114
375 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
376 #define MWL8K_CMD_SET_WMM_MODE 0x0123
377 #define MWL8K_CMD_MIMO_CONFIG 0x0125
378 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
379 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
380 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
381 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
382 #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
383 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
384 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
385 #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
386 #define MWL8K_CMD_UPDATE_STADB 0x1123
387 #define MWL8K_CMD_BASTREAM 0x1125
389 static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
391 u16 command = le16_to_cpu(cmd);
393 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
394 snprintf(buf, bufsize, "%s", #x);\
397 switch (command & ~0x8000) {
398 MWL8K_CMDNAME(CODE_DNLD);
399 MWL8K_CMDNAME(GET_HW_SPEC);
400 MWL8K_CMDNAME(SET_HW_SPEC);
401 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
402 MWL8K_CMDNAME(GET_STAT);
403 MWL8K_CMDNAME(RADIO_CONTROL);
404 MWL8K_CMDNAME(RF_TX_POWER);
405 MWL8K_CMDNAME(TX_POWER);
406 MWL8K_CMDNAME(RF_ANTENNA);
407 MWL8K_CMDNAME(SET_BEACON);
408 MWL8K_CMDNAME(SET_PRE_SCAN);
409 MWL8K_CMDNAME(SET_POST_SCAN);
410 MWL8K_CMDNAME(SET_RF_CHANNEL);
411 MWL8K_CMDNAME(SET_AID);
412 MWL8K_CMDNAME(SET_RATE);
413 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
414 MWL8K_CMDNAME(RTS_THRESHOLD);
415 MWL8K_CMDNAME(SET_SLOT);
416 MWL8K_CMDNAME(SET_EDCA_PARAMS);
417 MWL8K_CMDNAME(SET_WMM_MODE);
418 MWL8K_CMDNAME(MIMO_CONFIG);
419 MWL8K_CMDNAME(USE_FIXED_RATE);
420 MWL8K_CMDNAME(ENABLE_SNIFFER);
421 MWL8K_CMDNAME(SET_MAC_ADDR);
422 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
423 MWL8K_CMDNAME(BSS_START);
424 MWL8K_CMDNAME(SET_NEW_STN);
425 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
426 MWL8K_CMDNAME(UPDATE_STADB);
427 MWL8K_CMDNAME(BASTREAM);
428 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
430 snprintf(buf, bufsize, "0x%x", cmd);
437 /* Hardware and firmware reset */
438 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
440 iowrite32(MWL8K_H2A_INT_RESET,
441 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
442 iowrite32(MWL8K_H2A_INT_RESET,
443 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
447 /* Release fw image */
448 static void mwl8k_release_fw(const struct firmware **fw)
452 release_firmware(*fw);
456 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
458 mwl8k_release_fw(&priv->fw_ucode);
459 mwl8k_release_fw(&priv->fw_helper);
462 /* states for asynchronous f/w loading */
463 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
466 FW_STATE_LOADING_PREF,
467 FW_STATE_LOADING_ALT,
471 /* Request fw image */
472 static int mwl8k_request_fw(struct mwl8k_priv *priv,
473 const char *fname, const struct firmware **fw,
476 /* release current image */
478 mwl8k_release_fw(fw);
481 return request_firmware_nowait(THIS_MODULE, 1, fname,
482 &priv->pdev->dev, GFP_KERNEL,
483 priv, mwl8k_fw_state_machine);
485 return request_firmware(fw, fname, &priv->pdev->dev);
488 static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
491 struct mwl8k_device_info *di = priv->device_info;
494 if (di->helper_image != NULL) {
496 rc = mwl8k_request_fw(priv, di->helper_image,
497 &priv->fw_helper, true);
499 rc = mwl8k_request_fw(priv, di->helper_image,
500 &priv->fw_helper, false);
502 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
503 pci_name(priv->pdev), di->helper_image);
511 * if we get here, no helper image is needed. Skip the
512 * FW_STATE_INIT state.
514 priv->fw_state = FW_STATE_LOADING_PREF;
515 rc = mwl8k_request_fw(priv, fw_image,
519 rc = mwl8k_request_fw(priv, fw_image,
520 &priv->fw_ucode, false);
522 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
523 pci_name(priv->pdev), fw_image);
524 mwl8k_release_fw(&priv->fw_helper);
531 struct mwl8k_cmd_pkt {
544 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
546 void __iomem *regs = priv->regs;
550 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
551 if (pci_dma_mapping_error(priv->pdev, dma_addr))
554 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
555 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
556 iowrite32(MWL8K_H2A_INT_DOORBELL,
557 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
558 iowrite32(MWL8K_H2A_INT_DUMMY,
559 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
565 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
566 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
567 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
575 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
577 return loops ? 0 : -ETIMEDOUT;
580 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
581 const u8 *data, size_t length)
583 struct mwl8k_cmd_pkt *cmd;
587 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
591 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
598 int block_size = length > 256 ? 256 : length;
600 memcpy(cmd->payload, data + done, block_size);
601 cmd->length = cpu_to_le16(block_size);
603 rc = mwl8k_send_fw_load_cmd(priv, cmd,
604 sizeof(*cmd) + block_size);
609 length -= block_size;
614 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
622 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
623 const u8 *data, size_t length)
625 unsigned char *buffer;
626 int may_continue, rc = 0;
627 u32 done, prev_block_size;
629 buffer = kmalloc(1024, GFP_KERNEL);
636 while (may_continue > 0) {
639 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
640 if (block_size & 1) {
644 done += prev_block_size;
645 length -= prev_block_size;
648 if (block_size > 1024 || block_size > length) {
658 if (block_size == 0) {
665 prev_block_size = block_size;
666 memcpy(buffer, data + done, block_size);
668 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
673 if (!rc && length != 0)
681 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
683 struct mwl8k_priv *priv = hw->priv;
684 const struct firmware *fw = priv->fw_ucode;
688 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
689 const struct firmware *helper = priv->fw_helper;
691 if (helper == NULL) {
692 printk(KERN_ERR "%s: helper image needed but none "
693 "given\n", pci_name(priv->pdev));
697 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
699 printk(KERN_ERR "%s: unable to load firmware "
700 "helper image\n", pci_name(priv->pdev));
705 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
707 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
711 printk(KERN_ERR "%s: unable to load firmware image\n",
712 pci_name(priv->pdev));
716 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
722 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
723 if (ready_code == MWL8K_FWAP_READY) {
726 } else if (ready_code == MWL8K_FWSTA_READY) {
735 return loops ? 0 : -ETIMEDOUT;
739 /* DMA header used by firmware and hardware. */
740 struct mwl8k_dma_data {
742 struct ieee80211_hdr wh;
746 /* Routines to add/remove DMA header from skb. */
747 static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
749 struct mwl8k_dma_data *tr;
752 tr = (struct mwl8k_dma_data *)skb->data;
753 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
755 if (hdrlen != sizeof(tr->wh)) {
756 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
757 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
758 *((__le16 *)(tr->data - 2)) = qos;
760 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
764 if (hdrlen != sizeof(*tr))
765 skb_pull(skb, sizeof(*tr) - hdrlen);
769 mwl8k_add_dma_header(struct sk_buff *skb, int tail_pad)
771 struct ieee80211_hdr *wh;
774 struct mwl8k_dma_data *tr;
777 * Add a firmware DMA header; the firmware requires that we
778 * present a 2-byte payload length followed by a 4-address
779 * header (without QoS field), followed (optionally) by any
780 * WEP/ExtIV header (but only filled in for CCMP).
782 wh = (struct ieee80211_hdr *)skb->data;
784 hdrlen = ieee80211_hdrlen(wh->frame_control);
785 reqd_hdrlen = sizeof(*tr);
787 if (hdrlen != reqd_hdrlen)
788 skb_push(skb, reqd_hdrlen - hdrlen);
790 if (ieee80211_is_data_qos(wh->frame_control))
791 hdrlen -= IEEE80211_QOS_CTL_LEN;
793 tr = (struct mwl8k_dma_data *)skb->data;
795 memmove(&tr->wh, wh, hdrlen);
796 if (hdrlen != sizeof(tr->wh))
797 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
800 * Firmware length is the length of the fully formed "802.11
801 * payload". That is, everything except for the 802.11 header.
802 * This includes all crypto material including the MIC.
804 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
807 static void mwl8k_encapsulate_tx_frame(struct sk_buff *skb)
809 struct ieee80211_hdr *wh;
810 struct ieee80211_tx_info *tx_info;
811 struct ieee80211_key_conf *key_conf;
814 wh = (struct ieee80211_hdr *)skb->data;
816 tx_info = IEEE80211_SKB_CB(skb);
819 if (ieee80211_is_data(wh->frame_control))
820 key_conf = tx_info->control.hw_key;
823 * Make sure the packet header is in the DMA header format (4-address
824 * without QoS), the necessary crypto padding between the header and the
825 * payload has already been provided by mac80211, but it doesn't add tail
826 * padding when HW crypto is enabled.
828 * We have the following trailer padding requirements:
829 * - WEP: 4 trailer bytes (ICV)
830 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
831 * - CCMP: 8 trailer bytes (MIC)
834 if (key_conf != NULL) {
835 switch (key_conf->cipher) {
836 case WLAN_CIPHER_SUITE_WEP40:
837 case WLAN_CIPHER_SUITE_WEP104:
840 case WLAN_CIPHER_SUITE_TKIP:
843 case WLAN_CIPHER_SUITE_CCMP:
848 mwl8k_add_dma_header(skb, data_pad);
852 * Packet reception for 88w8366 AP firmware.
854 struct mwl8k_rxd_8366_ap {
858 __le32 pkt_phys_addr;
859 __le32 next_rxd_phys_addr;
863 __le32 hw_noise_floor_info;
872 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
873 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
874 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
876 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
878 /* 8366 AP rx_status bits */
879 #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
880 #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
881 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
882 #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
883 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
885 static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
887 struct mwl8k_rxd_8366_ap *rxd = _rxd;
889 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
890 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
893 static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
895 struct mwl8k_rxd_8366_ap *rxd = _rxd;
897 rxd->pkt_len = cpu_to_le16(len);
898 rxd->pkt_phys_addr = cpu_to_le32(addr);
904 mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
905 __le16 *qos, s8 *noise)
907 struct mwl8k_rxd_8366_ap *rxd = _rxd;
909 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
913 memset(status, 0, sizeof(*status));
915 status->signal = -rxd->rssi;
916 *noise = -rxd->noise_floor;
918 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
919 status->flag |= RX_FLAG_HT;
920 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
921 status->flag |= RX_FLAG_40MHZ;
922 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
926 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
927 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
928 status->rate_idx = i;
934 if (rxd->channel > 14) {
935 status->band = IEEE80211_BAND_5GHZ;
936 if (!(status->flag & RX_FLAG_HT))
937 status->rate_idx -= 5;
939 status->band = IEEE80211_BAND_2GHZ;
941 status->freq = ieee80211_channel_to_frequency(rxd->channel,
944 *qos = rxd->qos_control;
946 if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
947 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) &&
948 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
949 status->flag |= RX_FLAG_MMIC_ERROR;
951 return le16_to_cpu(rxd->pkt_len);
954 static struct rxd_ops rxd_8366_ap_ops = {
955 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
956 .rxd_init = mwl8k_rxd_8366_ap_init,
957 .rxd_refill = mwl8k_rxd_8366_ap_refill,
958 .rxd_process = mwl8k_rxd_8366_ap_process,
962 * Packet reception for STA firmware.
964 struct mwl8k_rxd_sta {
968 __le32 pkt_phys_addr;
969 __le32 next_rxd_phys_addr;
981 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
982 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
983 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
984 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
985 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
986 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
988 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
989 #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
991 #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
992 /* Key is uploaded only in failure case */
993 #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
995 static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
997 struct mwl8k_rxd_sta *rxd = _rxd;
999 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
1000 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
1003 static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
1005 struct mwl8k_rxd_sta *rxd = _rxd;
1007 rxd->pkt_len = cpu_to_le16(len);
1008 rxd->pkt_phys_addr = cpu_to_le32(addr);
1014 mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
1015 __le16 *qos, s8 *noise)
1017 struct mwl8k_rxd_sta *rxd = _rxd;
1020 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
1024 rate_info = le16_to_cpu(rxd->rate_info);
1026 memset(status, 0, sizeof(*status));
1028 status->signal = -rxd->rssi;
1029 *noise = -rxd->noise_level;
1030 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
1031 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
1033 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
1034 status->flag |= RX_FLAG_SHORTPRE;
1035 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
1036 status->flag |= RX_FLAG_40MHZ;
1037 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
1038 status->flag |= RX_FLAG_SHORT_GI;
1039 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
1040 status->flag |= RX_FLAG_HT;
1042 if (rxd->channel > 14) {
1043 status->band = IEEE80211_BAND_5GHZ;
1044 if (!(status->flag & RX_FLAG_HT))
1045 status->rate_idx -= 5;
1047 status->band = IEEE80211_BAND_2GHZ;
1049 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1052 *qos = rxd->qos_control;
1053 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1054 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1055 status->flag |= RX_FLAG_MMIC_ERROR;
1057 return le16_to_cpu(rxd->pkt_len);
1060 static struct rxd_ops rxd_sta_ops = {
1061 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1062 .rxd_init = mwl8k_rxd_sta_init,
1063 .rxd_refill = mwl8k_rxd_sta_refill,
1064 .rxd_process = mwl8k_rxd_sta_process,
1068 #define MWL8K_RX_DESCS 256
1069 #define MWL8K_RX_MAXSZ 3800
1071 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1073 struct mwl8k_priv *priv = hw->priv;
1074 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1082 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
1084 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1085 if (rxq->rxd == NULL) {
1086 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
1089 memset(rxq->rxd, 0, size);
1091 rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
1092 if (rxq->buf == NULL) {
1093 wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
1094 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
1098 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1102 dma_addr_t next_dma_addr;
1104 desc_size = priv->rxd_ops->rxd_size;
1105 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
1108 if (nexti == MWL8K_RX_DESCS)
1110 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1112 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
1118 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1120 struct mwl8k_priv *priv = hw->priv;
1121 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1125 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
1126 struct sk_buff *skb;
1131 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1135 addr = pci_map_single(priv->pdev, skb->data,
1136 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
1140 if (rxq->tail == MWL8K_RX_DESCS)
1142 rxq->buf[rx].skb = skb;
1143 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
1145 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1146 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
1154 /* Must be called only when the card's reception is completely halted */
1155 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1157 struct mwl8k_priv *priv = hw->priv;
1158 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1161 if (rxq->rxd == NULL)
1164 for (i = 0; i < MWL8K_RX_DESCS; i++) {
1165 if (rxq->buf[i].skb != NULL) {
1166 pci_unmap_single(priv->pdev,
1167 dma_unmap_addr(&rxq->buf[i], dma),
1168 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1169 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
1171 kfree_skb(rxq->buf[i].skb);
1172 rxq->buf[i].skb = NULL;
1179 pci_free_consistent(priv->pdev,
1180 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
1181 rxq->rxd, rxq->rxd_dma);
1187 * Scan a list of BSSIDs to process for finalize join.
1188 * Allows for extension to process multiple BSSIDs.
1191 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1193 return priv->capture_beacon &&
1194 ieee80211_is_beacon(wh->frame_control) &&
1195 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1198 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1199 struct sk_buff *skb)
1201 struct mwl8k_priv *priv = hw->priv;
1203 priv->capture_beacon = false;
1204 memset(priv->capture_bssid, 0, ETH_ALEN);
1207 * Use GFP_ATOMIC as rxq_process is called from
1208 * the primary interrupt handler, memory allocation call
1211 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1212 if (priv->beacon_skb != NULL)
1213 ieee80211_queue_work(hw, &priv->finalize_join_worker);
1216 static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1219 struct mwl8k_vif *mwl8k_vif;
1221 list_for_each_entry(mwl8k_vif,
1223 if (memcmp(bssid, mwl8k_vif->bssid,
1231 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1233 struct mwl8k_priv *priv = hw->priv;
1234 struct mwl8k_vif *mwl8k_vif = NULL;
1235 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1239 while (rxq->rxd_count && limit--) {
1240 struct sk_buff *skb;
1243 struct ieee80211_rx_status status;
1244 struct ieee80211_hdr *wh;
1247 skb = rxq->buf[rxq->head].skb;
1251 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1253 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1258 rxq->buf[rxq->head].skb = NULL;
1260 pci_unmap_single(priv->pdev,
1261 dma_unmap_addr(&rxq->buf[rxq->head], dma),
1262 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1263 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1266 if (rxq->head == MWL8K_RX_DESCS)
1271 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1274 * Check for a pending join operation. Save a
1275 * copy of the beacon and schedule a tasklet to
1276 * send a FINALIZE_JOIN command to the firmware.
1278 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1279 mwl8k_save_beacon(hw, skb);
1281 if (ieee80211_has_protected(wh->frame_control)) {
1283 /* Check if hw crypto has been enabled for
1284 * this bss. If yes, set the status flags
1287 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1290 if (mwl8k_vif != NULL &&
1291 mwl8k_vif->is_hw_crypto_enabled == true) {
1293 * When MMIC ERROR is encountered
1294 * by the firmware, payload is
1295 * dropped and only 32 bytes of
1296 * mwl8k Firmware header is sent
1299 * We need to add four bytes of
1300 * key information. In it
1301 * MAC80211 expects keyidx set to
1302 * 0 for triggering Counter
1303 * Measure of MMIC failure.
1305 if (status.flag & RX_FLAG_MMIC_ERROR) {
1306 struct mwl8k_dma_data *tr;
1307 tr = (struct mwl8k_dma_data *)skb->data;
1308 memset((void *)&(tr->data), 0, 4);
1312 if (!ieee80211_is_auth(wh->frame_control))
1313 status.flag |= RX_FLAG_IV_STRIPPED |
1315 RX_FLAG_MMIC_STRIPPED;
1319 skb_put(skb, pkt_len);
1320 mwl8k_remove_dma_header(skb, qos);
1321 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1322 ieee80211_rx_irqsafe(hw, skb);
1332 * Packet transmission.
1335 #define MWL8K_TXD_STATUS_OK 0x00000001
1336 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1337 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1338 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1339 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1341 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1342 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1343 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1344 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1345 #define MWL8K_QOS_EOSP 0x0010
1347 struct mwl8k_tx_desc {
1352 __le32 pkt_phys_addr;
1354 __u8 dest_MAC_addr[ETH_ALEN];
1355 __le32 next_txd_phys_addr;
1362 #define MWL8K_TX_DESCS 128
1364 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1366 struct mwl8k_priv *priv = hw->priv;
1367 struct mwl8k_tx_queue *txq = priv->txq + index;
1375 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1377 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1378 if (txq->txd == NULL) {
1379 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
1382 memset(txq->txd, 0, size);
1384 txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
1385 if (txq->skb == NULL) {
1386 wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
1387 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1391 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1392 struct mwl8k_tx_desc *tx_desc;
1395 tx_desc = txq->txd + i;
1396 nexti = (i + 1) % MWL8K_TX_DESCS;
1398 tx_desc->status = 0;
1399 tx_desc->next_txd_phys_addr =
1400 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1406 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1408 iowrite32(MWL8K_H2A_INT_PPA_READY,
1409 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1410 iowrite32(MWL8K_H2A_INT_DUMMY,
1411 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1412 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1415 static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1417 struct mwl8k_priv *priv = hw->priv;
1420 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
1421 struct mwl8k_tx_queue *txq = priv->txq + i;
1427 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1428 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1431 status = le32_to_cpu(tx_desc->status);
1432 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1437 if (tx_desc->pkt_len == 0)
1441 wiphy_err(hw->wiphy,
1442 "txq[%d] len=%d head=%d tail=%d "
1443 "fw_owned=%d drv_owned=%d unused=%d\n",
1445 txq->len, txq->head, txq->tail,
1446 fw_owned, drv_owned, unused);
1451 * Must be called with priv->fw_mutex held and tx queues stopped.
1453 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1455 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1457 struct mwl8k_priv *priv = hw->priv;
1458 DECLARE_COMPLETION_ONSTACK(tx_wait);
1465 * The TX queues are stopped at this point, so this test
1466 * doesn't need to take ->tx_lock.
1468 if (!priv->pending_tx_pkts)
1474 spin_lock_bh(&priv->tx_lock);
1475 priv->tx_wait = &tx_wait;
1478 unsigned long timeout;
1480 oldcount = priv->pending_tx_pkts;
1482 spin_unlock_bh(&priv->tx_lock);
1483 timeout = wait_for_completion_timeout(&tx_wait,
1484 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1485 spin_lock_bh(&priv->tx_lock);
1488 WARN_ON(priv->pending_tx_pkts);
1490 wiphy_notice(hw->wiphy, "tx rings drained\n");
1495 if (priv->pending_tx_pkts < oldcount) {
1496 wiphy_notice(hw->wiphy,
1497 "waiting for tx rings to drain (%d -> %d pkts)\n",
1498 oldcount, priv->pending_tx_pkts);
1503 priv->tx_wait = NULL;
1505 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1506 MWL8K_TX_WAIT_TIMEOUT_MS);
1507 mwl8k_dump_tx_rings(hw);
1511 spin_unlock_bh(&priv->tx_lock);
1516 #define MWL8K_TXD_SUCCESS(status) \
1517 ((status) & (MWL8K_TXD_STATUS_OK | \
1518 MWL8K_TXD_STATUS_OK_RETRY | \
1519 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1521 static int mwl8k_tid_queue_mapping(u8 tid)
1528 return IEEE80211_AC_BE;
1532 return IEEE80211_AC_BK;
1536 return IEEE80211_AC_VI;
1540 return IEEE80211_AC_VO;
1548 /* The firmware will fill in the rate information
1549 * for each packet that gets queued in the hardware
1556 __le16 band_width:1;
1557 __le16 rate_id_mcs:6;
1558 __le16 adv_coding:2;
1560 __le16 act_sub_chan:2;
1561 __le16 preamble_type:1;
1565 __le16 tx_bf_frame:1;
1566 __le16 green_field:1;
1570 mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1572 struct mwl8k_priv *priv = hw->priv;
1573 struct mwl8k_tx_queue *txq = priv->txq + index;
1577 while (txq->len > 0 && limit--) {
1579 struct mwl8k_tx_desc *tx_desc;
1582 struct sk_buff *skb;
1583 struct ieee80211_tx_info *info;
1585 struct ieee80211_sta *sta;
1586 struct mwl8k_sta *sta_info = NULL;
1588 struct rateinfo *rate;
1589 struct ieee80211_hdr *wh;
1592 tx_desc = txq->txd + tx;
1594 status = le32_to_cpu(tx_desc->status);
1596 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1600 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1603 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1604 BUG_ON(txq->len == 0);
1606 priv->pending_tx_pkts--;
1608 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1609 size = le16_to_cpu(tx_desc->pkt_len);
1611 txq->skb[tx] = NULL;
1613 BUG_ON(skb == NULL);
1614 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1616 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
1618 wh = (struct ieee80211_hdr *) skb->data;
1620 /* Mark descriptor as unused */
1621 tx_desc->pkt_phys_addr = 0;
1622 tx_desc->pkt_len = 0;
1624 info = IEEE80211_SKB_CB(skb);
1625 if (ieee80211_is_data(wh->frame_control)) {
1626 sta = info->control.sta;
1628 sta_info = MWL8K_STA(sta);
1629 BUG_ON(sta_info == NULL);
1630 rate_info = le16_to_cpu(tx_desc->rate_info);
1631 rate = (struct rateinfo *)&rate_info;
1632 /* If rate is < 6.5 Mpbs for an ht station
1633 * do not form an ampdu. If the station is a
1634 * legacy station (format = 0), do not form an
1637 if (rate->rate_id_mcs < 1 ||
1638 rate->format == 0) {
1639 sta_info->is_ampdu_allowed = false;
1641 sta_info->is_ampdu_allowed = true;
1646 ieee80211_tx_info_clear_status(info);
1648 /* Rate control is happening in the firmware.
1649 * Ensure no tx rate is being reported.
1651 info->status.rates[0].idx = -1;
1652 info->status.rates[0].count = 1;
1654 if (MWL8K_TXD_SUCCESS(status))
1655 info->flags |= IEEE80211_TX_STAT_ACK;
1657 ieee80211_tx_status_irqsafe(hw, skb);
1662 if (index < MWL8K_TX_WMM_QUEUES && processed && priv->radio_on &&
1663 !mutex_is_locked(&priv->fw_mutex))
1664 ieee80211_wake_queue(hw, index);
1669 /* must be called only when the card's transmit is completely halted */
1670 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1672 struct mwl8k_priv *priv = hw->priv;
1673 struct mwl8k_tx_queue *txq = priv->txq + index;
1675 if (txq->txd == NULL)
1678 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1683 pci_free_consistent(priv->pdev,
1684 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1685 txq->txd, txq->txd_dma);
1689 /* caller must hold priv->stream_lock when calling the stream functions */
1690 struct mwl8k_ampdu_stream *
1691 mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
1693 struct mwl8k_ampdu_stream *stream;
1694 struct mwl8k_priv *priv = hw->priv;
1697 for (i = 0; i < priv->num_ampdu_queues; i++) {
1698 stream = &priv->ampdu[i];
1699 if (stream->state == AMPDU_NO_STREAM) {
1701 stream->state = AMPDU_STREAM_NEW;
1704 stream->txq_idx = MWL8K_TX_WMM_QUEUES + i;
1705 wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
1714 mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1718 /* if the stream has already been started, don't start it again */
1719 if (stream->state != AMPDU_STREAM_NEW)
1721 ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
1723 wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
1724 "%d\n", stream->sta->addr, stream->tid, ret);
1726 wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
1727 stream->sta->addr, stream->tid);
1732 mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1734 wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
1736 memset(stream, 0, sizeof(*stream));
1739 static struct mwl8k_ampdu_stream *
1740 mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
1742 struct mwl8k_priv *priv = hw->priv;
1745 for (i = 0 ; i < priv->num_ampdu_queues; i++) {
1746 struct mwl8k_ampdu_stream *stream;
1747 stream = &priv->ampdu[i];
1748 if (stream->state == AMPDU_NO_STREAM)
1750 if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
1758 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1760 struct mwl8k_priv *priv = hw->priv;
1761 struct ieee80211_tx_info *tx_info;
1762 struct mwl8k_vif *mwl8k_vif;
1763 struct ieee80211_sta *sta;
1764 struct ieee80211_hdr *wh;
1765 struct mwl8k_tx_queue *txq;
1766 struct mwl8k_tx_desc *tx;
1773 struct mwl8k_ampdu_stream *stream = NULL;
1774 bool start_ba_session = false;
1775 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
1777 wh = (struct ieee80211_hdr *)skb->data;
1778 if (ieee80211_is_data_qos(wh->frame_control))
1779 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1784 mwl8k_encapsulate_tx_frame(skb);
1786 mwl8k_add_dma_header(skb, 0);
1788 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1790 tx_info = IEEE80211_SKB_CB(skb);
1791 sta = tx_info->control.sta;
1792 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1794 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1795 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1796 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1797 mwl8k_vif->seqno += 0x10;
1800 /* Setup firmware control bit fields for each frame type. */
1803 if (ieee80211_is_mgmt(wh->frame_control) ||
1804 ieee80211_is_ctl(wh->frame_control)) {
1806 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1807 } else if (ieee80211_is_data(wh->frame_control)) {
1809 if (is_multicast_ether_addr(wh->addr1))
1810 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1812 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1813 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1814 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1816 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1819 /* Queue ADDBA request in the respective data queue. While setting up
1820 * the ampdu stream, mac80211 queues further packets for that
1821 * particular ra/tid pair. However, packets piled up in the hardware
1822 * for that ra/tid pair will still go out. ADDBA request and the
1823 * related data packets going out from different queues asynchronously
1824 * will cause a shift in the receiver window which might result in
1825 * ampdu packets getting dropped at the receiver after the stream has
1828 if (unlikely(ieee80211_is_action(wh->frame_control) &&
1829 mgmt->u.action.category == WLAN_CATEGORY_BACK &&
1830 mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
1832 u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1833 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1834 index = mwl8k_tid_queue_mapping(tid);
1839 if (ieee80211_is_data_qos(wh->frame_control) &&
1840 skb->protocol != cpu_to_be16(ETH_P_PAE) &&
1841 sta->ht_cap.ht_supported && priv->ap_fw) {
1843 spin_lock(&priv->stream_lock);
1844 stream = mwl8k_lookup_stream(hw, sta->addr, tid);
1845 if (stream != NULL) {
1846 if (stream->state == AMPDU_STREAM_ACTIVE) {
1847 txpriority = stream->txq_idx;
1848 index = stream->txq_idx;
1849 } else if (stream->state == AMPDU_STREAM_NEW) {
1850 /* We get here if the driver sends us packets
1851 * after we've initiated a stream, but before
1852 * our ampdu_action routine has been called
1853 * with IEEE80211_AMPDU_TX_START to get the SSN
1854 * for the ADDBA request. So this packet can
1855 * go out with no risk of sequence number
1856 * mismatch. No special handling is required.
1859 /* Drop packets that would go out after the
1860 * ADDBA request was sent but before the ADDBA
1861 * response is received. If we don't do this,
1862 * the recipient would probably receive it
1863 * after the ADDBA request with SSN 0. This
1864 * will cause the recipient's BA receive window
1865 * to shift, which would cause the subsequent
1866 * packets in the BA stream to be discarded.
1867 * mac80211 queues our packets for us in this
1868 * case, so this is really just a safety check.
1870 wiphy_warn(hw->wiphy,
1871 "Cannot send packet while ADDBA "
1872 "dialog is underway.\n");
1873 spin_unlock(&priv->stream_lock);
1878 /* Defer calling mwl8k_start_stream so that the current
1879 * skb can go out before the ADDBA request. This
1880 * prevents sequence number mismatch at the recepient
1881 * as described above.
1883 if (MWL8K_STA(sta)->is_ampdu_allowed) {
1884 stream = mwl8k_add_stream(hw, sta, tid);
1886 start_ba_session = true;
1889 spin_unlock(&priv->stream_lock);
1892 dma = pci_map_single(priv->pdev, skb->data,
1893 skb->len, PCI_DMA_TODEVICE);
1895 if (pci_dma_mapping_error(priv->pdev, dma)) {
1896 wiphy_debug(hw->wiphy,
1897 "failed to dma map skb, dropping TX frame.\n");
1898 if (start_ba_session) {
1899 spin_lock(&priv->stream_lock);
1900 mwl8k_remove_stream(hw, stream);
1901 spin_unlock(&priv->stream_lock);
1907 spin_lock_bh(&priv->tx_lock);
1909 txq = priv->txq + index;
1911 if (index >= MWL8K_TX_WMM_QUEUES && txq->len >= MWL8K_TX_DESCS) {
1912 /* This is the case in which the tx packet is destined for an
1913 * AMPDU queue and that AMPDU queue is full. Because we don't
1914 * start and stop the AMPDU queues, we must drop these packets.
1917 spin_unlock_bh(&priv->tx_lock);
1921 BUG_ON(txq->skb[txq->tail] != NULL);
1922 txq->skb[txq->tail] = skb;
1924 tx = txq->txd + txq->tail;
1925 tx->data_rate = txdatarate;
1926 tx->tx_priority = txpriority;
1927 tx->qos_control = cpu_to_le16(qos);
1928 tx->pkt_phys_addr = cpu_to_le32(dma);
1929 tx->pkt_len = cpu_to_le16(skb->len);
1931 if (!priv->ap_fw && tx_info->control.sta != NULL)
1932 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1936 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1939 priv->pending_tx_pkts++;
1942 if (txq->tail == MWL8K_TX_DESCS)
1945 if (txq->head == txq->tail && index < MWL8K_TX_WMM_QUEUES)
1946 ieee80211_stop_queue(hw, index);
1948 mwl8k_tx_start(priv);
1950 spin_unlock_bh(&priv->tx_lock);
1952 /* Initiate the ampdu session here */
1953 if (start_ba_session) {
1954 spin_lock(&priv->stream_lock);
1955 if (mwl8k_start_stream(hw, stream))
1956 mwl8k_remove_stream(hw, stream);
1957 spin_unlock(&priv->stream_lock);
1965 * We have the following requirements for issuing firmware commands:
1966 * - Some commands require that the packet transmit path is idle when
1967 * the command is issued. (For simplicity, we'll just quiesce the
1968 * transmit path for every command.)
1969 * - There are certain sequences of commands that need to be issued to
1970 * the hardware sequentially, with no other intervening commands.
1972 * This leads to an implementation of a "firmware lock" as a mutex that
1973 * can be taken recursively, and which is taken by both the low-level
1974 * command submission function (mwl8k_post_cmd) as well as any users of
1975 * that function that require issuing of an atomic sequence of commands,
1976 * and quiesces the transmit path whenever it's taken.
1978 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1980 struct mwl8k_priv *priv = hw->priv;
1982 if (priv->fw_mutex_owner != current) {
1985 mutex_lock(&priv->fw_mutex);
1986 ieee80211_stop_queues(hw);
1988 rc = mwl8k_tx_wait_empty(hw);
1990 ieee80211_wake_queues(hw);
1991 mutex_unlock(&priv->fw_mutex);
1996 priv->fw_mutex_owner = current;
1999 priv->fw_mutex_depth++;
2004 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
2006 struct mwl8k_priv *priv = hw->priv;
2008 if (!--priv->fw_mutex_depth) {
2009 ieee80211_wake_queues(hw);
2010 priv->fw_mutex_owner = NULL;
2011 mutex_unlock(&priv->fw_mutex);
2017 * Command processing.
2020 /* Timeout firmware commands after 10s */
2021 #define MWL8K_CMD_TIMEOUT_MS 10000
2023 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
2025 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2026 struct mwl8k_priv *priv = hw->priv;
2027 void __iomem *regs = priv->regs;
2028 dma_addr_t dma_addr;
2029 unsigned int dma_size;
2031 unsigned long timeout = 0;
2034 cmd->result = (__force __le16) 0xffff;
2035 dma_size = le16_to_cpu(cmd->length);
2036 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
2037 PCI_DMA_BIDIRECTIONAL);
2038 if (pci_dma_mapping_error(priv->pdev, dma_addr))
2041 rc = mwl8k_fw_lock(hw);
2043 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2044 PCI_DMA_BIDIRECTIONAL);
2048 priv->hostcmd_wait = &cmd_wait;
2049 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
2050 iowrite32(MWL8K_H2A_INT_DOORBELL,
2051 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2052 iowrite32(MWL8K_H2A_INT_DUMMY,
2053 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2055 timeout = wait_for_completion_timeout(&cmd_wait,
2056 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
2058 priv->hostcmd_wait = NULL;
2060 mwl8k_fw_unlock(hw);
2062 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2063 PCI_DMA_BIDIRECTIONAL);
2066 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
2067 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2068 MWL8K_CMD_TIMEOUT_MS);
2073 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
2075 rc = cmd->result ? -EINVAL : 0;
2077 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
2078 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2079 le16_to_cpu(cmd->result));
2081 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
2082 mwl8k_cmd_name(cmd->code,
2090 static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
2091 struct ieee80211_vif *vif,
2092 struct mwl8k_cmd_pkt *cmd)
2095 cmd->macid = MWL8K_VIF(vif)->macid;
2096 return mwl8k_post_cmd(hw, cmd);
2100 * Setup code shared between STA and AP firmware images.
2102 static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
2104 struct mwl8k_priv *priv = hw->priv;
2106 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
2107 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
2109 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
2110 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
2112 priv->band_24.band = IEEE80211_BAND_2GHZ;
2113 priv->band_24.channels = priv->channels_24;
2114 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
2115 priv->band_24.bitrates = priv->rates_24;
2116 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
2118 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
2121 static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
2123 struct mwl8k_priv *priv = hw->priv;
2125 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
2126 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
2128 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
2129 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
2131 priv->band_50.band = IEEE80211_BAND_5GHZ;
2132 priv->band_50.channels = priv->channels_50;
2133 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
2134 priv->band_50.bitrates = priv->rates_50;
2135 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
2137 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
2141 * CMD_GET_HW_SPEC (STA version).
2143 struct mwl8k_cmd_get_hw_spec_sta {
2144 struct mwl8k_cmd_pkt header;
2146 __u8 host_interface;
2148 __u8 perm_addr[ETH_ALEN];
2153 __u8 mcs_bitmap[16];
2154 __le32 rx_queue_ptr;
2155 __le32 num_tx_queues;
2156 __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
2158 __le32 num_tx_desc_per_queue;
2162 #define MWL8K_CAP_MAX_AMSDU 0x20000000
2163 #define MWL8K_CAP_GREENFIELD 0x08000000
2164 #define MWL8K_CAP_AMPDU 0x04000000
2165 #define MWL8K_CAP_RX_STBC 0x01000000
2166 #define MWL8K_CAP_TX_STBC 0x00800000
2167 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2168 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2169 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2170 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2171 #define MWL8K_CAP_DELAY_BA 0x00003000
2172 #define MWL8K_CAP_MIMO 0x00000200
2173 #define MWL8K_CAP_40MHZ 0x00000100
2174 #define MWL8K_CAP_BAND_MASK 0x00000007
2175 #define MWL8K_CAP_5GHZ 0x00000004
2176 #define MWL8K_CAP_2GHZ4 0x00000001
2179 mwl8k_set_ht_caps(struct ieee80211_hw *hw,
2180 struct ieee80211_supported_band *band, u32 cap)
2185 band->ht_cap.ht_supported = 1;
2187 if (cap & MWL8K_CAP_MAX_AMSDU)
2188 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
2189 if (cap & MWL8K_CAP_GREENFIELD)
2190 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
2191 if (cap & MWL8K_CAP_AMPDU) {
2192 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
2193 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2194 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2196 if (cap & MWL8K_CAP_RX_STBC)
2197 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
2198 if (cap & MWL8K_CAP_TX_STBC)
2199 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
2200 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
2201 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
2202 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
2203 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
2204 if (cap & MWL8K_CAP_DELAY_BA)
2205 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
2206 if (cap & MWL8K_CAP_40MHZ)
2207 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2209 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
2210 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
2212 band->ht_cap.mcs.rx_mask[0] = 0xff;
2213 if (rx_streams >= 2)
2214 band->ht_cap.mcs.rx_mask[1] = 0xff;
2215 if (rx_streams >= 3)
2216 band->ht_cap.mcs.rx_mask[2] = 0xff;
2217 band->ht_cap.mcs.rx_mask[4] = 0x01;
2218 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2220 if (rx_streams != tx_streams) {
2221 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
2222 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
2223 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2228 mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
2230 struct mwl8k_priv *priv = hw->priv;
2232 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
2233 mwl8k_setup_2ghz_band(hw);
2234 if (caps & MWL8K_CAP_MIMO)
2235 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
2238 if (caps & MWL8K_CAP_5GHZ) {
2239 mwl8k_setup_5ghz_band(hw);
2240 if (caps & MWL8K_CAP_MIMO)
2241 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
2245 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
2247 struct mwl8k_priv *priv = hw->priv;
2248 struct mwl8k_cmd_get_hw_spec_sta *cmd;
2252 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2256 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2257 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2259 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2260 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2261 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2262 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2263 for (i = 0; i < mwl8k_tx_queues(priv); i++)
2264 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
2265 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2266 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2268 rc = mwl8k_post_cmd(hw, &cmd->header);
2271 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2272 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2273 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2274 priv->hw_rev = cmd->hw_rev;
2275 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2276 priv->ap_macids_supported = 0x00000000;
2277 priv->sta_macids_supported = 0x00000001;
2285 * CMD_GET_HW_SPEC (AP version).
2287 struct mwl8k_cmd_get_hw_spec_ap {
2288 struct mwl8k_cmd_pkt header;
2290 __u8 host_interface;
2293 __u8 perm_addr[ETH_ALEN];
2304 __le32 fw_api_version;
2306 __le32 num_of_ampdu_queues;
2307 __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
2310 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2312 struct mwl8k_priv *priv = hw->priv;
2313 struct mwl8k_cmd_get_hw_spec_ap *cmd;
2317 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2321 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2322 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2324 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2325 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2327 rc = mwl8k_post_cmd(hw, &cmd->header);
2332 api_version = le32_to_cpu(cmd->fw_api_version);
2333 if (priv->device_info->fw_api_ap != api_version) {
2334 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2335 " Expected %d got %d.\n", MWL8K_NAME,
2336 priv->device_info->part_name,
2337 priv->device_info->fw_api_ap,
2342 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2343 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2344 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2345 priv->hw_rev = cmd->hw_rev;
2346 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
2347 priv->ap_macids_supported = 0x000000ff;
2348 priv->sta_macids_supported = 0x00000000;
2349 priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
2350 if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
2351 wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
2352 " but we only support %d.\n",
2353 priv->num_ampdu_queues,
2354 MWL8K_MAX_AMPDU_QUEUES);
2355 priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
2357 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
2358 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2360 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
2361 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
2363 priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
2364 priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
2365 priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
2366 priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
2368 for (i = 0; i < priv->num_ampdu_queues; i++)
2369 priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
2370 le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
2381 struct mwl8k_cmd_set_hw_spec {
2382 struct mwl8k_cmd_pkt header;
2384 __u8 host_interface;
2386 __u8 perm_addr[ETH_ALEN];
2391 __le32 rx_queue_ptr;
2392 __le32 num_tx_queues;
2393 __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
2395 __le32 num_tx_desc_per_queue;
2399 /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2400 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2401 * the packets that are queued for more than 500ms, will be dropped in the
2402 * hardware. This helps minimizing the issues caused due to head-of-line
2403 * blocking where a slow client can hog the bandwidth and affect traffic to a
2406 #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
2407 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2408 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2409 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
2411 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2413 struct mwl8k_priv *priv = hw->priv;
2414 struct mwl8k_cmd_set_hw_spec *cmd;
2418 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2422 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2423 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2425 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2426 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2427 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2430 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2431 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2432 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2433 * priority is interpreted the right way in firmware.
2435 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
2436 int j = mwl8k_tx_queues(priv) - 1 - i;
2437 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
2440 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2441 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
2442 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
2443 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2444 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2446 rc = mwl8k_post_cmd(hw, &cmd->header);
2453 * CMD_MAC_MULTICAST_ADR.
2455 struct mwl8k_cmd_mac_multicast_adr {
2456 struct mwl8k_cmd_pkt header;
2459 __u8 addr[0][ETH_ALEN];
2462 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
2463 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
2464 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2465 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
2467 static struct mwl8k_cmd_pkt *
2468 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
2469 struct netdev_hw_addr_list *mc_list)
2471 struct mwl8k_priv *priv = hw->priv;
2472 struct mwl8k_cmd_mac_multicast_adr *cmd;
2477 mc_count = netdev_hw_addr_list_count(mc_list);
2479 if (allmulti || mc_count > priv->num_mcaddrs) {
2484 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2486 cmd = kzalloc(size, GFP_ATOMIC);
2490 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2491 cmd->header.length = cpu_to_le16(size);
2492 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2493 MWL8K_ENABLE_RX_BROADCAST);
2496 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2497 } else if (mc_count) {
2498 struct netdev_hw_addr *ha;
2501 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2502 cmd->numaddr = cpu_to_le16(mc_count);
2503 netdev_hw_addr_list_for_each(ha, mc_list) {
2504 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
2508 return &cmd->header;
2514 struct mwl8k_cmd_get_stat {
2515 struct mwl8k_cmd_pkt header;
2519 #define MWL8K_STAT_ACK_FAILURE 9
2520 #define MWL8K_STAT_RTS_FAILURE 12
2521 #define MWL8K_STAT_FCS_ERROR 24
2522 #define MWL8K_STAT_RTS_SUCCESS 11
2524 static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2525 struct ieee80211_low_level_stats *stats)
2527 struct mwl8k_cmd_get_stat *cmd;
2530 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2534 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2535 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2537 rc = mwl8k_post_cmd(hw, &cmd->header);
2539 stats->dot11ACKFailureCount =
2540 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2541 stats->dot11RTSFailureCount =
2542 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2543 stats->dot11FCSErrorCount =
2544 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2545 stats->dot11RTSSuccessCount =
2546 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2554 * CMD_RADIO_CONTROL.
2556 struct mwl8k_cmd_radio_control {
2557 struct mwl8k_cmd_pkt header;
2564 mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
2566 struct mwl8k_priv *priv = hw->priv;
2567 struct mwl8k_cmd_radio_control *cmd;
2570 if (enable == priv->radio_on && !force)
2573 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2577 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2578 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2579 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2580 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
2581 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2583 rc = mwl8k_post_cmd(hw, &cmd->header);
2587 priv->radio_on = enable;
2592 static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
2594 return mwl8k_cmd_radio_control(hw, 0, 0);
2597 static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
2599 return mwl8k_cmd_radio_control(hw, 1, 0);
2603 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2605 struct mwl8k_priv *priv = hw->priv;
2607 priv->radio_short_preamble = short_preamble;
2609 return mwl8k_cmd_radio_control(hw, 1, 1);
2615 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2617 struct mwl8k_cmd_rf_tx_power {
2618 struct mwl8k_cmd_pkt header;
2620 __le16 support_level;
2621 __le16 current_level;
2623 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
2626 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
2628 struct mwl8k_cmd_rf_tx_power *cmd;
2631 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2635 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2636 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2637 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2638 cmd->support_level = cpu_to_le16(dBm);
2640 rc = mwl8k_post_cmd(hw, &cmd->header);
2649 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2651 struct mwl8k_cmd_tx_power {
2652 struct mwl8k_cmd_pkt header;
2658 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2659 } __attribute__((packed));
2661 static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2662 struct ieee80211_conf *conf,
2665 struct ieee80211_channel *channel = conf->channel;
2666 struct mwl8k_cmd_tx_power *cmd;
2670 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2674 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2675 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2676 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2678 if (channel->band == IEEE80211_BAND_2GHZ)
2679 cmd->band = cpu_to_le16(0x1);
2680 else if (channel->band == IEEE80211_BAND_5GHZ)
2681 cmd->band = cpu_to_le16(0x4);
2683 cmd->channel = channel->hw_value;
2685 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2686 conf->channel_type == NL80211_CHAN_HT20) {
2687 cmd->bw = cpu_to_le16(0x2);
2689 cmd->bw = cpu_to_le16(0x4);
2690 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2691 cmd->sub_ch = cpu_to_le16(0x3);
2692 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2693 cmd->sub_ch = cpu_to_le16(0x1);
2696 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2697 cmd->power_level_list[i] = cpu_to_le16(pwr);
2699 rc = mwl8k_post_cmd(hw, &cmd->header);
2708 struct mwl8k_cmd_rf_antenna {
2709 struct mwl8k_cmd_pkt header;
2714 #define MWL8K_RF_ANTENNA_RX 1
2715 #define MWL8K_RF_ANTENNA_TX 2
2718 mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2720 struct mwl8k_cmd_rf_antenna *cmd;
2723 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2727 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2728 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2729 cmd->antenna = cpu_to_le16(antenna);
2730 cmd->mode = cpu_to_le16(mask);
2732 rc = mwl8k_post_cmd(hw, &cmd->header);
2741 struct mwl8k_cmd_set_beacon {
2742 struct mwl8k_cmd_pkt header;
2747 static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2748 struct ieee80211_vif *vif, u8 *beacon, int len)
2750 struct mwl8k_cmd_set_beacon *cmd;
2753 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2757 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2758 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2759 cmd->beacon_len = cpu_to_le16(len);
2760 memcpy(cmd->beacon, beacon, len);
2762 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2771 struct mwl8k_cmd_set_pre_scan {
2772 struct mwl8k_cmd_pkt header;
2775 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2777 struct mwl8k_cmd_set_pre_scan *cmd;
2780 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2784 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2785 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2787 rc = mwl8k_post_cmd(hw, &cmd->header);
2794 * CMD_SET_POST_SCAN.
2796 struct mwl8k_cmd_set_post_scan {
2797 struct mwl8k_cmd_pkt header;
2799 __u8 bssid[ETH_ALEN];
2803 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2805 struct mwl8k_cmd_set_post_scan *cmd;
2808 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2812 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2813 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2815 memcpy(cmd->bssid, mac, ETH_ALEN);
2817 rc = mwl8k_post_cmd(hw, &cmd->header);
2824 * CMD_SET_RF_CHANNEL.
2826 struct mwl8k_cmd_set_rf_channel {
2827 struct mwl8k_cmd_pkt header;
2829 __u8 current_channel;
2830 __le32 channel_flags;
2833 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2834 struct ieee80211_conf *conf)
2836 struct ieee80211_channel *channel = conf->channel;
2837 struct mwl8k_cmd_set_rf_channel *cmd;
2840 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2844 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2845 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2846 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2847 cmd->current_channel = channel->hw_value;
2849 if (channel->band == IEEE80211_BAND_2GHZ)
2850 cmd->channel_flags |= cpu_to_le32(0x00000001);
2851 else if (channel->band == IEEE80211_BAND_5GHZ)
2852 cmd->channel_flags |= cpu_to_le32(0x00000004);
2854 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2855 conf->channel_type == NL80211_CHAN_HT20)
2856 cmd->channel_flags |= cpu_to_le32(0x00000080);
2857 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2858 cmd->channel_flags |= cpu_to_le32(0x000001900);
2859 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2860 cmd->channel_flags |= cpu_to_le32(0x000000900);
2862 rc = mwl8k_post_cmd(hw, &cmd->header);
2871 #define MWL8K_FRAME_PROT_DISABLED 0x00
2872 #define MWL8K_FRAME_PROT_11G 0x07
2873 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2874 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2876 struct mwl8k_cmd_update_set_aid {
2877 struct mwl8k_cmd_pkt header;
2880 /* AP's MAC address (BSSID) */
2881 __u8 bssid[ETH_ALEN];
2882 __le16 protection_mode;
2883 __u8 supp_rates[14];
2886 static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2892 * Clear nonstandard rates 4 and 13.
2896 for (i = 0, j = 0; i < 14; i++) {
2897 if (mask & (1 << i))
2898 rates[j++] = mwl8k_rates_24[i].hw_value;
2903 mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2904 struct ieee80211_vif *vif, u32 legacy_rate_mask)
2906 struct mwl8k_cmd_update_set_aid *cmd;
2910 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2914 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2915 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2916 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
2917 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
2919 if (vif->bss_conf.use_cts_prot) {
2920 prot_mode = MWL8K_FRAME_PROT_11G;
2922 switch (vif->bss_conf.ht_operation_mode &
2923 IEEE80211_HT_OP_MODE_PROTECTION) {
2924 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2925 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2927 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2928 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2931 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2935 cmd->protection_mode = cpu_to_le16(prot_mode);
2937 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
2939 rc = mwl8k_post_cmd(hw, &cmd->header);
2948 struct mwl8k_cmd_set_rate {
2949 struct mwl8k_cmd_pkt header;
2950 __u8 legacy_rates[14];
2952 /* Bitmap for supported MCS codes. */
2958 mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2959 u32 legacy_rate_mask, u8 *mcs_rates)
2961 struct mwl8k_cmd_set_rate *cmd;
2964 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2968 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2969 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2970 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
2971 memcpy(cmd->mcs_set, mcs_rates, 16);
2973 rc = mwl8k_post_cmd(hw, &cmd->header);
2980 * CMD_FINALIZE_JOIN.
2982 #define MWL8K_FJ_BEACON_MAXLEN 128
2984 struct mwl8k_cmd_finalize_join {
2985 struct mwl8k_cmd_pkt header;
2986 __le32 sleep_interval; /* Number of beacon periods to sleep */
2987 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2990 static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2991 int framelen, int dtim)
2993 struct mwl8k_cmd_finalize_join *cmd;
2994 struct ieee80211_mgmt *payload = frame;
2998 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3002 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
3003 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3004 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
3006 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
3007 if (payload_len < 0)
3009 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
3010 payload_len = MWL8K_FJ_BEACON_MAXLEN;
3012 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
3014 rc = mwl8k_post_cmd(hw, &cmd->header);
3021 * CMD_SET_RTS_THRESHOLD.
3023 struct mwl8k_cmd_set_rts_threshold {
3024 struct mwl8k_cmd_pkt header;
3030 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
3032 struct mwl8k_cmd_set_rts_threshold *cmd;
3035 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3039 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
3040 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3041 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3042 cmd->threshold = cpu_to_le16(rts_thresh);
3044 rc = mwl8k_post_cmd(hw, &cmd->header);
3053 struct mwl8k_cmd_set_slot {
3054 struct mwl8k_cmd_pkt header;
3059 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
3061 struct mwl8k_cmd_set_slot *cmd;
3064 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3068 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
3069 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3070 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3071 cmd->short_slot = short_slot_time;
3073 rc = mwl8k_post_cmd(hw, &cmd->header);
3080 * CMD_SET_EDCA_PARAMS.
3082 struct mwl8k_cmd_set_edca_params {
3083 struct mwl8k_cmd_pkt header;
3085 /* See MWL8K_SET_EDCA_XXX below */
3088 /* TX opportunity in units of 32 us */
3093 /* Log exponent of max contention period: 0...15 */
3096 /* Log exponent of min contention period: 0...15 */
3099 /* Adaptive interframe spacing in units of 32us */
3102 /* TX queue to configure */
3106 /* Log exponent of max contention period: 0...15 */
3109 /* Log exponent of min contention period: 0...15 */
3112 /* Adaptive interframe spacing in units of 32us */
3115 /* TX queue to configure */
3121 #define MWL8K_SET_EDCA_CW 0x01
3122 #define MWL8K_SET_EDCA_TXOP 0x02
3123 #define MWL8K_SET_EDCA_AIFS 0x04
3125 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3126 MWL8K_SET_EDCA_TXOP | \
3127 MWL8K_SET_EDCA_AIFS)
3130 mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
3131 __u16 cw_min, __u16 cw_max,
3132 __u8 aifs, __u16 txop)
3134 struct mwl8k_priv *priv = hw->priv;
3135 struct mwl8k_cmd_set_edca_params *cmd;
3138 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3142 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
3143 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3144 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
3145 cmd->txop = cpu_to_le16(txop);
3147 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
3148 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
3149 cmd->ap.aifs = aifs;
3152 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
3153 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
3154 cmd->sta.aifs = aifs;
3155 cmd->sta.txq = qnum;
3158 rc = mwl8k_post_cmd(hw, &cmd->header);
3167 struct mwl8k_cmd_set_wmm_mode {
3168 struct mwl8k_cmd_pkt header;
3172 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
3174 struct mwl8k_priv *priv = hw->priv;
3175 struct mwl8k_cmd_set_wmm_mode *cmd;
3178 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3182 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
3183 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3184 cmd->action = cpu_to_le16(!!enable);
3186 rc = mwl8k_post_cmd(hw, &cmd->header);
3190 priv->wmm_enabled = enable;
3198 struct mwl8k_cmd_mimo_config {
3199 struct mwl8k_cmd_pkt header;
3201 __u8 rx_antenna_map;
3202 __u8 tx_antenna_map;
3205 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
3207 struct mwl8k_cmd_mimo_config *cmd;
3210 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3214 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
3215 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3216 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
3217 cmd->rx_antenna_map = rx;
3218 cmd->tx_antenna_map = tx;
3220 rc = mwl8k_post_cmd(hw, &cmd->header);
3227 * CMD_USE_FIXED_RATE (STA version).
3229 struct mwl8k_cmd_use_fixed_rate_sta {
3230 struct mwl8k_cmd_pkt header;
3232 __le32 allow_rate_drop;
3236 __le32 enable_retry;
3245 #define MWL8K_USE_AUTO_RATE 0x0002
3246 #define MWL8K_UCAST_RATE 0
3248 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
3250 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
3253 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3257 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3258 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3259 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3260 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
3262 rc = mwl8k_post_cmd(hw, &cmd->header);
3269 * CMD_USE_FIXED_RATE (AP version).
3271 struct mwl8k_cmd_use_fixed_rate_ap {
3272 struct mwl8k_cmd_pkt header;
3274 __le32 allow_rate_drop;
3276 struct mwl8k_rate_entry_ap {
3278 __le32 enable_retry;
3283 u8 multicast_rate_type;
3288 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
3290 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
3293 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3297 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3298 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3299 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3300 cmd->multicast_rate = mcast;
3301 cmd->management_rate = mgmt;
3303 rc = mwl8k_post_cmd(hw, &cmd->header);
3310 * CMD_ENABLE_SNIFFER.
3312 struct mwl8k_cmd_enable_sniffer {
3313 struct mwl8k_cmd_pkt header;
3317 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3319 struct mwl8k_cmd_enable_sniffer *cmd;
3322 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3326 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3327 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3328 cmd->action = cpu_to_le32(!!enable);
3330 rc = mwl8k_post_cmd(hw, &cmd->header);
3339 struct mwl8k_cmd_set_mac_addr {
3340 struct mwl8k_cmd_pkt header;
3344 __u8 mac_addr[ETH_ALEN];
3346 __u8 mac_addr[ETH_ALEN];
3350 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3351 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3352 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
3353 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
3355 static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3356 struct ieee80211_vif *vif, u8 *mac)
3358 struct mwl8k_priv *priv = hw->priv;
3359 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3360 struct mwl8k_cmd_set_mac_addr *cmd;
3364 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3365 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3366 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
3367 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
3369 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3370 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3371 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3372 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3374 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3377 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3381 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3382 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3384 cmd->mbss.mac_type = cpu_to_le16(mac_type);
3385 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3387 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3390 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3397 * CMD_SET_RATEADAPT_MODE.
3399 struct mwl8k_cmd_set_rate_adapt_mode {
3400 struct mwl8k_cmd_pkt header;
3405 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3407 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
3410 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3414 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
3415 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3416 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3417 cmd->mode = cpu_to_le16(mode);
3419 rc = mwl8k_post_cmd(hw, &cmd->header);
3426 * CMD_GET_WATCHDOG_BITMAP.
3428 struct mwl8k_cmd_get_watchdog_bitmap {
3429 struct mwl8k_cmd_pkt header;
3433 static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
3435 struct mwl8k_cmd_get_watchdog_bitmap *cmd;
3438 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3442 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
3443 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3445 rc = mwl8k_post_cmd(hw, &cmd->header);
3447 *bitmap = cmd->bitmap;
3454 #define INVALID_BA 0xAA
3455 static void mwl8k_watchdog_ba_events(struct work_struct *work)
3458 u8 bitmap = 0, stream_index;
3459 struct mwl8k_ampdu_stream *streams;
3460 struct mwl8k_priv *priv =
3461 container_of(work, struct mwl8k_priv, watchdog_ba_handle);
3463 rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
3467 if (bitmap == INVALID_BA)
3470 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
3471 stream_index = bitmap - MWL8K_TX_WMM_QUEUES;
3473 BUG_ON(stream_index >= priv->num_ampdu_queues);
3475 streams = &priv->ampdu[stream_index];
3477 if (streams->state == AMPDU_STREAM_ACTIVE)
3478 ieee80211_stop_tx_ba_session(streams->sta, streams->tid);
3487 struct mwl8k_cmd_bss_start {
3488 struct mwl8k_cmd_pkt header;
3492 static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3493 struct ieee80211_vif *vif, int enable)
3495 struct mwl8k_cmd_bss_start *cmd;
3498 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3502 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3503 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3504 cmd->enable = cpu_to_le32(enable);
3506 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3517 * UPSTREAM is tx direction
3519 #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3520 #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3528 } ba_stream_action_type;
3531 struct mwl8k_create_ba_stream {
3536 u8 peer_mac_addr[6];
3542 u8 reset_seq_no_flag;
3544 u8 sta_src_mac_addr[6];
3547 struct mwl8k_destroy_ba_stream {
3552 struct mwl8k_cmd_bastream {
3553 struct mwl8k_cmd_pkt header;
3556 struct mwl8k_create_ba_stream create_params;
3557 struct mwl8k_destroy_ba_stream destroy_params;
3562 mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
3564 struct mwl8k_cmd_bastream *cmd;
3567 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3571 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3572 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3574 cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
3576 cmd->create_params.queue_id = stream->idx;
3577 memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
3579 cmd->create_params.tid = stream->tid;
3581 cmd->create_params.flags =
3582 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
3583 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
3585 rc = mwl8k_post_cmd(hw, &cmd->header);
3593 mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3596 struct mwl8k_cmd_bastream *cmd;
3599 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3604 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3605 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3607 cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
3609 cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
3610 cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
3611 cmd->create_params.queue_id = stream->idx;
3613 memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
3614 cmd->create_params.tid = stream->tid;
3615 cmd->create_params.curr_seq_no = cpu_to_le16(0);
3616 cmd->create_params.reset_seq_no_flag = 1;
3618 cmd->create_params.param_info =
3619 (stream->sta->ht_cap.ampdu_factor &
3620 IEEE80211_HT_AMPDU_PARM_FACTOR) |
3621 ((stream->sta->ht_cap.ampdu_density << 2) &
3622 IEEE80211_HT_AMPDU_PARM_DENSITY);
3624 cmd->create_params.flags =
3625 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
3626 BASTREAM_FLAG_DIRECTION_UPSTREAM);
3628 rc = mwl8k_post_cmd(hw, &cmd->header);
3630 wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
3631 stream->sta->addr, stream->tid);
3637 static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3638 struct mwl8k_ampdu_stream *stream)
3640 struct mwl8k_cmd_bastream *cmd;
3642 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3646 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3647 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3648 cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
3650 cmd->destroy_params.ba_context = cpu_to_le32(stream->idx);
3651 mwl8k_post_cmd(hw, &cmd->header);
3653 wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", stream->idx);
3661 struct mwl8k_cmd_set_new_stn {
3662 struct mwl8k_cmd_pkt header;
3668 __le32 legacy_rates;
3671 __le16 ht_capabilities_info;
3672 __u8 mac_ht_param_info;
3674 __u8 control_channel;
3683 #define MWL8K_STA_ACTION_ADD 0
3684 #define MWL8K_STA_ACTION_REMOVE 2
3686 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3687 struct ieee80211_vif *vif,
3688 struct ieee80211_sta *sta)
3690 struct mwl8k_cmd_set_new_stn *cmd;
3694 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3698 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3699 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3700 cmd->aid = cpu_to_le16(sta->aid);
3701 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3702 cmd->stn_id = cpu_to_le16(sta->aid);
3703 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
3704 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3705 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3707 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3708 cmd->legacy_rates = cpu_to_le32(rates);
3709 if (sta->ht_cap.ht_supported) {
3710 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3711 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3712 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3713 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3714 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3715 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3716 ((sta->ht_cap.ampdu_density & 7) << 2);
3717 cmd->is_qos_sta = 1;
3720 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3726 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3727 struct ieee80211_vif *vif)
3729 struct mwl8k_cmd_set_new_stn *cmd;
3732 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3736 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3737 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3738 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3740 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3746 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
3747 struct ieee80211_vif *vif, u8 *addr)
3749 struct mwl8k_cmd_set_new_stn *cmd;
3752 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3756 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3757 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3758 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3759 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
3761 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3768 * CMD_UPDATE_ENCRYPTION.
3771 #define MAX_ENCR_KEY_LENGTH 16
3772 #define MIC_KEY_LENGTH 8
3774 struct mwl8k_cmd_update_encryption {
3775 struct mwl8k_cmd_pkt header;
3782 } __attribute__((packed));
3784 struct mwl8k_cmd_set_key {
3785 struct mwl8k_cmd_pkt header;
3794 __u8 key_material[MAX_ENCR_KEY_LENGTH];
3795 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
3796 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
3797 __le16 tkip_rsc_low;
3798 __le32 tkip_rsc_high;
3799 __le16 tkip_tsc_low;
3800 __le32 tkip_tsc_high;
3802 } __attribute__((packed));
3807 MWL8K_ENCR_REMOVE_KEY,
3808 MWL8K_ENCR_SET_GROUP_KEY,
3811 #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
3812 #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
3813 #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
3814 #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
3815 #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
3823 #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
3824 #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
3825 #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
3826 #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
3827 #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
3829 static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
3830 struct ieee80211_vif *vif,
3834 struct mwl8k_cmd_update_encryption *cmd;
3837 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3841 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3842 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3843 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
3844 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3845 cmd->encr_type = encr_type;
3847 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3853 static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
3855 struct ieee80211_key_conf *key)
3857 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3858 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3859 cmd->length = cpu_to_le16(sizeof(*cmd) -
3860 offsetof(struct mwl8k_cmd_set_key, length));
3861 cmd->key_id = cpu_to_le32(key->keyidx);
3862 cmd->key_len = cpu_to_le16(key->keylen);
3863 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3865 switch (key->cipher) {
3866 case WLAN_CIPHER_SUITE_WEP40:
3867 case WLAN_CIPHER_SUITE_WEP104:
3868 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
3869 if (key->keyidx == 0)
3870 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
3873 case WLAN_CIPHER_SUITE_TKIP:
3874 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
3875 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3876 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
3877 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
3878 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
3879 | MWL8K_KEY_FLAG_TSC_VALID);
3881 case WLAN_CIPHER_SUITE_CCMP:
3882 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
3883 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3884 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
3885 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
3894 static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
3895 struct ieee80211_vif *vif,
3897 struct ieee80211_key_conf *key)
3899 struct mwl8k_cmd_set_key *cmd;
3904 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3906 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3910 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
3916 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3917 action = MWL8K_ENCR_SET_KEY;
3919 action = MWL8K_ENCR_SET_GROUP_KEY;
3921 switch (key->cipher) {
3922 case WLAN_CIPHER_SUITE_WEP40:
3923 case WLAN_CIPHER_SUITE_WEP104:
3924 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
3925 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
3926 sizeof(*key) + key->keylen);
3927 mwl8k_vif->wep_key_conf[idx].enabled = 1;
3931 action = MWL8K_ENCR_SET_KEY;
3933 case WLAN_CIPHER_SUITE_TKIP:
3934 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
3936 case WLAN_CIPHER_SUITE_CCMP:
3937 keymlen = key->keylen;
3944 memcpy(cmd->key_material, key->key, keymlen);
3945 cmd->action = cpu_to_le32(action);
3947 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3954 static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
3955 struct ieee80211_vif *vif,
3957 struct ieee80211_key_conf *key)
3959 struct mwl8k_cmd_set_key *cmd;
3961 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3963 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3967 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
3971 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3972 WLAN_CIPHER_SUITE_WEP104)
3973 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
3975 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
3977 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3984 static int mwl8k_set_key(struct ieee80211_hw *hw,
3985 enum set_key_cmd cmd_param,
3986 struct ieee80211_vif *vif,
3987 struct ieee80211_sta *sta,
3988 struct ieee80211_key_conf *key)
3993 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3995 if (vif->type == NL80211_IFTYPE_STATION)
3999 addr = hw->wiphy->perm_addr;
4003 if (cmd_param == SET_KEY) {
4004 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4005 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
4009 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
4010 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
4011 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
4013 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
4015 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
4020 mwl8k_vif->is_hw_crypto_enabled = true;
4023 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
4028 mwl8k_vif->is_hw_crypto_enabled = false;
4038 struct ewc_ht_info {
4044 struct peer_capability_info {
4045 /* Peer type - AP vs. STA. */
4048 /* Basic 802.11 capabilities from assoc resp. */
4051 /* Set if peer supports 802.11n high throughput (HT). */
4054 /* Valid if HT is supported. */
4056 __u8 extended_ht_caps;
4057 struct ewc_ht_info ewc_info;
4059 /* Legacy rate table. Intersection of our rates and peer rates. */
4060 __u8 legacy_rates[12];
4062 /* HT rate table. Intersection of our rates and peer rates. */
4066 /* If set, interoperability mode, no proprietary extensions. */
4070 __le16 amsdu_enabled;
4073 struct mwl8k_cmd_update_stadb {
4074 struct mwl8k_cmd_pkt header;
4076 /* See STADB_ACTION_TYPE */
4079 /* Peer MAC address */
4080 __u8 peer_addr[ETH_ALEN];
4084 /* Peer info - valid during add/update. */
4085 struct peer_capability_info peer_info;
4088 #define MWL8K_STA_DB_MODIFY_ENTRY 1
4089 #define MWL8K_STA_DB_DEL_ENTRY 2
4091 /* Peer Entry flags - used to define the type of the peer node */
4092 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
4094 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
4095 struct ieee80211_vif *vif,
4096 struct ieee80211_sta *sta)
4098 struct mwl8k_cmd_update_stadb *cmd;
4099 struct peer_capability_info *p;
4103 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4107 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4108 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4109 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
4110 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
4112 p = &cmd->peer_info;
4113 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
4114 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
4115 p->ht_support = sta->ht_cap.ht_supported;
4116 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
4117 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
4118 ((sta->ht_cap.ampdu_density & 7) << 2);
4119 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4120 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
4122 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4123 legacy_rate_mask_to_array(p->legacy_rates, rates);
4124 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
4126 p->amsdu_enabled = 0;
4128 rc = mwl8k_post_cmd(hw, &cmd->header);
4131 return rc ? rc : p->station_id;
4134 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
4135 struct ieee80211_vif *vif, u8 *addr)
4137 struct mwl8k_cmd_update_stadb *cmd;
4140 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4144 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4145 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4146 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
4147 memcpy(cmd->peer_addr, addr, ETH_ALEN);
4149 rc = mwl8k_post_cmd(hw, &cmd->header);
4157 * Interrupt handling.
4159 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
4161 struct ieee80211_hw *hw = dev_id;
4162 struct mwl8k_priv *priv = hw->priv;
4165 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4169 if (status & MWL8K_A2H_INT_TX_DONE) {
4170 status &= ~MWL8K_A2H_INT_TX_DONE;
4171 tasklet_schedule(&priv->poll_tx_task);
4174 if (status & MWL8K_A2H_INT_RX_READY) {
4175 status &= ~MWL8K_A2H_INT_RX_READY;
4176 tasklet_schedule(&priv->poll_rx_task);
4179 if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
4180 status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
4181 ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
4185 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4187 if (status & MWL8K_A2H_INT_OPC_DONE) {
4188 if (priv->hostcmd_wait != NULL)
4189 complete(priv->hostcmd_wait);
4192 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
4193 if (!mutex_is_locked(&priv->fw_mutex) &&
4194 priv->radio_on && priv->pending_tx_pkts)
4195 mwl8k_tx_start(priv);
4201 static void mwl8k_tx_poll(unsigned long data)
4203 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4204 struct mwl8k_priv *priv = hw->priv;
4210 spin_lock_bh(&priv->tx_lock);
4212 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4213 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
4215 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
4216 complete(priv->tx_wait);
4217 priv->tx_wait = NULL;
4220 spin_unlock_bh(&priv->tx_lock);
4223 writel(~MWL8K_A2H_INT_TX_DONE,
4224 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4226 tasklet_schedule(&priv->poll_tx_task);
4230 static void mwl8k_rx_poll(unsigned long data)
4232 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4233 struct mwl8k_priv *priv = hw->priv;
4237 limit -= rxq_process(hw, 0, limit);
4238 limit -= rxq_refill(hw, 0, limit);
4241 writel(~MWL8K_A2H_INT_RX_READY,
4242 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4244 tasklet_schedule(&priv->poll_rx_task);
4250 * Core driver operations.
4252 static void mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
4254 struct mwl8k_priv *priv = hw->priv;
4255 int index = skb_get_queue_mapping(skb);
4257 if (!priv->radio_on) {
4258 wiphy_debug(hw->wiphy,
4259 "dropped TX frame since radio disabled\n");
4264 mwl8k_txq_xmit(hw, index, skb);
4267 static int mwl8k_start(struct ieee80211_hw *hw)
4269 struct mwl8k_priv *priv = hw->priv;
4272 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
4273 IRQF_SHARED, MWL8K_NAME, hw);
4275 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
4279 /* Enable TX reclaim and RX tasklets. */
4280 tasklet_enable(&priv->poll_tx_task);
4281 tasklet_enable(&priv->poll_rx_task);
4283 /* Enable interrupts */
4284 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4286 rc = mwl8k_fw_lock(hw);
4288 rc = mwl8k_cmd_radio_enable(hw);
4292 rc = mwl8k_cmd_enable_sniffer(hw, 0);
4295 rc = mwl8k_cmd_set_pre_scan(hw);
4298 rc = mwl8k_cmd_set_post_scan(hw,
4299 "\x00\x00\x00\x00\x00\x00");
4303 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
4306 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
4308 mwl8k_fw_unlock(hw);
4312 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4313 free_irq(priv->pdev->irq, hw);
4314 tasklet_disable(&priv->poll_tx_task);
4315 tasklet_disable(&priv->poll_rx_task);
4321 static void mwl8k_stop(struct ieee80211_hw *hw)
4323 struct mwl8k_priv *priv = hw->priv;
4326 mwl8k_cmd_radio_disable(hw);
4328 ieee80211_stop_queues(hw);
4330 /* Disable interrupts */
4331 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4332 free_irq(priv->pdev->irq, hw);
4334 /* Stop finalize join worker */
4335 cancel_work_sync(&priv->finalize_join_worker);
4336 cancel_work_sync(&priv->watchdog_ba_handle);
4337 if (priv->beacon_skb != NULL)
4338 dev_kfree_skb(priv->beacon_skb);
4340 /* Stop TX reclaim and RX tasklets. */
4341 tasklet_disable(&priv->poll_tx_task);
4342 tasklet_disable(&priv->poll_rx_task);
4344 /* Return all skbs to mac80211 */
4345 for (i = 0; i < mwl8k_tx_queues(priv); i++)
4346 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
4349 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
4351 static int mwl8k_add_interface(struct ieee80211_hw *hw,
4352 struct ieee80211_vif *vif)
4354 struct mwl8k_priv *priv = hw->priv;
4355 struct mwl8k_vif *mwl8k_vif;
4356 u32 macids_supported;
4358 struct mwl8k_device_info *di;
4361 * Reject interface creation if sniffer mode is active, as
4362 * STA operation is mutually exclusive with hardware sniffer
4363 * mode. (Sniffer mode is only used on STA firmware.)
4365 if (priv->sniffer_enabled) {
4366 wiphy_info(hw->wiphy,
4367 "unable to create STA interface because sniffer mode is enabled\n");
4371 di = priv->device_info;
4372 switch (vif->type) {
4373 case NL80211_IFTYPE_AP:
4374 if (!priv->ap_fw && di->fw_image_ap) {
4375 /* we must load the ap fw to meet this request */
4376 if (!list_empty(&priv->vif_list))
4378 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4382 macids_supported = priv->ap_macids_supported;
4384 case NL80211_IFTYPE_STATION:
4385 if (priv->ap_fw && di->fw_image_sta) {
4386 /* we must load the sta fw to meet this request */
4387 if (!list_empty(&priv->vif_list))
4389 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4393 macids_supported = priv->sta_macids_supported;
4399 macid = ffs(macids_supported & ~priv->macids_used);
4403 /* Setup driver private area. */
4404 mwl8k_vif = MWL8K_VIF(vif);
4405 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
4406 mwl8k_vif->vif = vif;
4407 mwl8k_vif->macid = macid;
4408 mwl8k_vif->seqno = 0;
4409 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
4410 mwl8k_vif->is_hw_crypto_enabled = false;
4412 /* Set the mac address. */
4413 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
4416 mwl8k_cmd_set_new_stn_add_self(hw, vif);
4418 priv->macids_used |= 1 << mwl8k_vif->macid;
4419 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
4424 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
4425 struct ieee80211_vif *vif)
4427 struct mwl8k_priv *priv = hw->priv;
4428 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4431 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
4433 mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
4435 priv->macids_used &= ~(1 << mwl8k_vif->macid);
4436 list_del(&mwl8k_vif->list);
4439 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
4441 struct ieee80211_conf *conf = &hw->conf;
4442 struct mwl8k_priv *priv = hw->priv;
4445 if (conf->flags & IEEE80211_CONF_IDLE) {
4446 mwl8k_cmd_radio_disable(hw);
4450 rc = mwl8k_fw_lock(hw);
4454 rc = mwl8k_cmd_radio_enable(hw);
4458 rc = mwl8k_cmd_set_rf_channel(hw, conf);
4462 if (conf->power_level > 18)
4463 conf->power_level = 18;
4467 if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
4468 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
4473 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
4475 wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
4476 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
4478 wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
4481 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
4484 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
4488 mwl8k_fw_unlock(hw);
4494 mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4495 struct ieee80211_bss_conf *info, u32 changed)
4497 struct mwl8k_priv *priv = hw->priv;
4498 u32 ap_legacy_rates;
4499 u8 ap_mcs_rates[16];
4502 if (mwl8k_fw_lock(hw))
4506 * No need to capture a beacon if we're no longer associated.
4508 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
4509 priv->capture_beacon = false;
4512 * Get the AP's legacy and MCS rates.
4514 if (vif->bss_conf.assoc) {
4515 struct ieee80211_sta *ap;
4519 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
4525 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
4526 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
4529 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4531 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
4536 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
4537 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
4541 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
4546 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4547 rc = mwl8k_set_radio_preamble(hw,
4548 vif->bss_conf.use_short_preamble);
4553 if (changed & BSS_CHANGED_ERP_SLOT) {
4554 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
4559 if (vif->bss_conf.assoc &&
4560 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4562 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
4567 if (vif->bss_conf.assoc &&
4568 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
4570 * Finalize the join. Tell rx handler to process
4571 * next beacon from our BSSID.
4573 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
4574 priv->capture_beacon = true;
4578 mwl8k_fw_unlock(hw);
4582 mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4583 struct ieee80211_bss_conf *info, u32 changed)
4587 if (mwl8k_fw_lock(hw))
4590 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4591 rc = mwl8k_set_radio_preamble(hw,
4592 vif->bss_conf.use_short_preamble);
4597 if (changed & BSS_CHANGED_BASIC_RATES) {
4602 * Use lowest supported basic rate for multicasts
4603 * and management frames (such as probe responses --
4604 * beacons will always go out at 1 Mb/s).
4606 idx = ffs(vif->bss_conf.basic_rates);
4610 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4611 rate = mwl8k_rates_24[idx].hw_value;
4613 rate = mwl8k_rates_50[idx].hw_value;
4615 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4618 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
4619 struct sk_buff *skb;
4621 skb = ieee80211_beacon_get(hw, vif);
4623 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
4628 if (changed & BSS_CHANGED_BEACON_ENABLED)
4629 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
4632 mwl8k_fw_unlock(hw);
4636 mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4637 struct ieee80211_bss_conf *info, u32 changed)
4639 struct mwl8k_priv *priv = hw->priv;
4642 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
4644 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
4647 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
4648 struct netdev_hw_addr_list *mc_list)
4650 struct mwl8k_cmd_pkt *cmd;
4653 * Synthesize and return a command packet that programs the
4654 * hardware multicast address filter. At this point we don't
4655 * know whether FIF_ALLMULTI is being requested, but if it is,
4656 * we'll end up throwing this packet away and creating a new
4657 * one in mwl8k_configure_filter().
4659 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
4661 return (unsigned long)cmd;
4665 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
4666 unsigned int changed_flags,
4667 unsigned int *total_flags)
4669 struct mwl8k_priv *priv = hw->priv;
4672 * Hardware sniffer mode is mutually exclusive with STA
4673 * operation, so refuse to enable sniffer mode if a STA
4674 * interface is active.
4676 if (!list_empty(&priv->vif_list)) {
4677 if (net_ratelimit())
4678 wiphy_info(hw->wiphy,
4679 "not enabling sniffer mode because STA interface is active\n");
4683 if (!priv->sniffer_enabled) {
4684 if (mwl8k_cmd_enable_sniffer(hw, 1))
4686 priv->sniffer_enabled = true;
4689 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
4690 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
4696 static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
4698 if (!list_empty(&priv->vif_list))
4699 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
4704 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
4705 unsigned int changed_flags,
4706 unsigned int *total_flags,
4709 struct mwl8k_priv *priv = hw->priv;
4710 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
4713 * AP firmware doesn't allow fine-grained control over
4714 * the receive filter.
4717 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4723 * Enable hardware sniffer mode if FIF_CONTROL or
4724 * FIF_OTHER_BSS is requested.
4726 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
4727 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
4732 /* Clear unsupported feature flags */
4733 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4735 if (mwl8k_fw_lock(hw)) {
4740 if (priv->sniffer_enabled) {
4741 mwl8k_cmd_enable_sniffer(hw, 0);
4742 priv->sniffer_enabled = false;
4745 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
4746 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
4748 * Disable the BSS filter.
4750 mwl8k_cmd_set_pre_scan(hw);
4752 struct mwl8k_vif *mwl8k_vif;
4756 * Enable the BSS filter.
4758 * If there is an active STA interface, use that
4759 * interface's BSSID, otherwise use a dummy one
4760 * (where the OUI part needs to be nonzero for
4761 * the BSSID to be accepted by POST_SCAN).
4763 mwl8k_vif = mwl8k_first_vif(priv);
4764 if (mwl8k_vif != NULL)
4765 bssid = mwl8k_vif->vif->bss_conf.bssid;
4767 bssid = "\x01\x00\x00\x00\x00\x00";
4769 mwl8k_cmd_set_post_scan(hw, bssid);
4774 * If FIF_ALLMULTI is being requested, throw away the command
4775 * packet that ->prepare_multicast() built and replace it with
4776 * a command packet that enables reception of all multicast
4779 if (*total_flags & FIF_ALLMULTI) {
4781 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
4785 mwl8k_post_cmd(hw, cmd);
4789 mwl8k_fw_unlock(hw);
4792 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4794 return mwl8k_cmd_set_rts_threshold(hw, value);
4797 static int mwl8k_sta_remove(struct ieee80211_hw *hw,
4798 struct ieee80211_vif *vif,
4799 struct ieee80211_sta *sta)
4801 struct mwl8k_priv *priv = hw->priv;
4804 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
4806 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
4809 static int mwl8k_sta_add(struct ieee80211_hw *hw,
4810 struct ieee80211_vif *vif,
4811 struct ieee80211_sta *sta)
4813 struct mwl8k_priv *priv = hw->priv;
4816 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4817 struct ieee80211_key_conf *key;
4820 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
4822 MWL8K_STA(sta)->peer_id = ret;
4823 if (sta->ht_cap.ht_supported)
4824 MWL8K_STA(sta)->is_ampdu_allowed = true;
4829 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
4832 for (i = 0; i < NUM_WEP_KEYS; i++) {
4833 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
4834 if (mwl8k_vif->wep_key_conf[i].enabled)
4835 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
4840 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
4841 const struct ieee80211_tx_queue_params *params)
4843 struct mwl8k_priv *priv = hw->priv;
4846 rc = mwl8k_fw_lock(hw);
4848 BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
4849 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
4851 if (!priv->wmm_enabled)
4852 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
4855 int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
4856 rc = mwl8k_cmd_set_edca_params(hw, q,
4863 mwl8k_fw_unlock(hw);
4869 static int mwl8k_get_stats(struct ieee80211_hw *hw,
4870 struct ieee80211_low_level_stats *stats)
4872 return mwl8k_cmd_get_stat(hw, stats);
4875 static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
4876 struct survey_info *survey)
4878 struct mwl8k_priv *priv = hw->priv;
4879 struct ieee80211_conf *conf = &hw->conf;
4884 survey->channel = conf->channel;
4885 survey->filled = SURVEY_INFO_NOISE_DBM;
4886 survey->noise = priv->noise;
4891 #define MAX_AMPDU_ATTEMPTS 5
4894 mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4895 enum ieee80211_ampdu_mlme_action action,
4896 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4901 struct mwl8k_priv *priv = hw->priv;
4902 struct mwl8k_ampdu_stream *stream;
4903 u8 *addr = sta->addr;
4905 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
4908 spin_lock(&priv->stream_lock);
4909 stream = mwl8k_lookup_stream(hw, addr, tid);
4912 case IEEE80211_AMPDU_RX_START:
4913 case IEEE80211_AMPDU_RX_STOP:
4915 case IEEE80211_AMPDU_TX_START:
4916 /* By the time we get here the hw queues may contain outgoing
4917 * packets for this RA/TID that are not part of this BA
4918 * session. The hw will assign sequence numbers to these
4919 * packets as they go out. So if we query the hw for its next
4920 * sequence number and use that for the SSN here, it may end up
4921 * being wrong, which will lead to sequence number mismatch at
4922 * the recipient. To avoid this, we reset the sequence number
4923 * to O for the first MPDU in this BA stream.
4926 if (stream == NULL) {
4927 /* This means that somebody outside this driver called
4928 * ieee80211_start_tx_ba_session. This is unexpected
4929 * because we do our own rate control. Just warn and
4932 wiphy_warn(hw->wiphy, "Unexpected call to %s. "
4933 "Proceeding anyway.\n", __func__);
4934 stream = mwl8k_add_stream(hw, sta, tid);
4936 if (stream == NULL) {
4937 wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
4941 stream->state = AMPDU_STREAM_IN_PROGRESS;
4943 /* Release the lock before we do the time consuming stuff */
4944 spin_unlock(&priv->stream_lock);
4945 for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
4946 rc = mwl8k_check_ba(hw, stream);
4951 * HW queues take time to be flushed, give them
4957 spin_lock(&priv->stream_lock);
4959 wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
4960 " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
4961 mwl8k_remove_stream(hw, stream);
4965 ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
4967 case IEEE80211_AMPDU_TX_STOP:
4970 if (stream->state == AMPDU_STREAM_ACTIVE) {
4971 spin_unlock(&priv->stream_lock);
4972 mwl8k_destroy_ba(hw, stream);
4973 spin_lock(&priv->stream_lock);
4975 mwl8k_remove_stream(hw, stream);
4976 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
4978 case IEEE80211_AMPDU_TX_OPERATIONAL:
4979 BUG_ON(stream == NULL);
4980 BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
4981 spin_unlock(&priv->stream_lock);
4982 rc = mwl8k_create_ba(hw, stream, buf_size);
4983 spin_lock(&priv->stream_lock);
4985 stream->state = AMPDU_STREAM_ACTIVE;
4987 spin_unlock(&priv->stream_lock);
4988 mwl8k_destroy_ba(hw, stream);
4989 spin_lock(&priv->stream_lock);
4990 wiphy_debug(hw->wiphy,
4991 "Failed adding stream for sta %pM tid %d\n",
4993 mwl8k_remove_stream(hw, stream);
5001 spin_unlock(&priv->stream_lock);
5005 static const struct ieee80211_ops mwl8k_ops = {
5007 .start = mwl8k_start,
5009 .add_interface = mwl8k_add_interface,
5010 .remove_interface = mwl8k_remove_interface,
5011 .config = mwl8k_config,
5012 .bss_info_changed = mwl8k_bss_info_changed,
5013 .prepare_multicast = mwl8k_prepare_multicast,
5014 .configure_filter = mwl8k_configure_filter,
5015 .set_key = mwl8k_set_key,
5016 .set_rts_threshold = mwl8k_set_rts_threshold,
5017 .sta_add = mwl8k_sta_add,
5018 .sta_remove = mwl8k_sta_remove,
5019 .conf_tx = mwl8k_conf_tx,
5020 .get_stats = mwl8k_get_stats,
5021 .get_survey = mwl8k_get_survey,
5022 .ampdu_action = mwl8k_ampdu_action,
5025 static void mwl8k_finalize_join_worker(struct work_struct *work)
5027 struct mwl8k_priv *priv =
5028 container_of(work, struct mwl8k_priv, finalize_join_worker);
5029 struct sk_buff *skb = priv->beacon_skb;
5030 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5031 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
5032 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
5033 mgmt->u.beacon.variable, len);
5034 int dtim_period = 1;
5036 if (tim && tim[1] >= 2)
5037 dtim_period = tim[3];
5039 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
5042 priv->beacon_skb = NULL;
5051 #define MWL8K_8366_AP_FW_API 2
5052 #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5053 #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5055 static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
5057 .part_name = "88w8363",
5058 .helper_image = "mwl8k/helper_8363.fw",
5059 .fw_image_sta = "mwl8k/fmimage_8363.fw",
5062 .part_name = "88w8687",
5063 .helper_image = "mwl8k/helper_8687.fw",
5064 .fw_image_sta = "mwl8k/fmimage_8687.fw",
5067 .part_name = "88w8366",
5068 .helper_image = "mwl8k/helper_8366.fw",
5069 .fw_image_sta = "mwl8k/fmimage_8366.fw",
5070 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
5071 .fw_api_ap = MWL8K_8366_AP_FW_API,
5072 .ap_rxd_ops = &rxd_8366_ap_ops,
5076 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5077 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5078 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5079 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5080 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5081 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
5082 MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
5084 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
5085 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
5086 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
5087 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
5088 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
5089 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
5090 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
5091 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
5094 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
5096 static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
5099 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
5100 "Trying alternative firmware %s\n", pci_name(priv->pdev),
5101 priv->fw_pref, priv->fw_alt);
5102 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
5104 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5105 pci_name(priv->pdev), priv->fw_alt);
5111 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
5112 static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
5114 struct mwl8k_priv *priv = context;
5115 struct mwl8k_device_info *di = priv->device_info;
5118 switch (priv->fw_state) {
5121 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
5122 pci_name(priv->pdev), di->helper_image);
5125 priv->fw_helper = fw;
5126 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
5128 if (rc && priv->fw_alt) {
5129 rc = mwl8k_request_alt_fw(priv);
5132 priv->fw_state = FW_STATE_LOADING_ALT;
5136 priv->fw_state = FW_STATE_LOADING_PREF;
5139 case FW_STATE_LOADING_PREF:
5142 rc = mwl8k_request_alt_fw(priv);
5145 priv->fw_state = FW_STATE_LOADING_ALT;
5149 priv->fw_ucode = fw;
5150 rc = mwl8k_firmware_load_success(priv);
5154 complete(&priv->firmware_loading_complete);
5158 case FW_STATE_LOADING_ALT:
5160 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5161 pci_name(priv->pdev), di->helper_image);
5164 priv->fw_ucode = fw;
5165 rc = mwl8k_firmware_load_success(priv);
5169 complete(&priv->firmware_loading_complete);
5173 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
5174 MWL8K_NAME, priv->fw_state);
5181 priv->fw_state = FW_STATE_ERROR;
5182 complete(&priv->firmware_loading_complete);
5183 device_release_driver(&priv->pdev->dev);
5184 mwl8k_release_firmware(priv);
5187 static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
5190 struct mwl8k_priv *priv = hw->priv;
5193 /* Reset firmware and hardware */
5194 mwl8k_hw_reset(priv);
5196 /* Ask userland hotplug daemon for the device firmware */
5197 rc = mwl8k_request_firmware(priv, fw_image, nowait);
5199 wiphy_err(hw->wiphy, "Firmware files not found\n");
5206 /* Load firmware into hardware */
5207 rc = mwl8k_load_firmware(hw);
5209 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5211 /* Reclaim memory once firmware is successfully loaded */
5212 mwl8k_release_firmware(priv);
5217 static int mwl8k_init_txqs(struct ieee80211_hw *hw)
5219 struct mwl8k_priv *priv = hw->priv;
5223 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
5224 rc = mwl8k_txq_init(hw, i);
5228 iowrite32(priv->txq[i].txd_dma,
5229 priv->sram + priv->txq_offset[i]);
5234 /* initialize hw after successfully loading a firmware image */
5235 static int mwl8k_probe_hw(struct ieee80211_hw *hw)
5237 struct mwl8k_priv *priv = hw->priv;
5242 priv->rxd_ops = priv->device_info->ap_rxd_ops;
5243 if (priv->rxd_ops == NULL) {
5244 wiphy_err(hw->wiphy,
5245 "Driver does not have AP firmware image support for this hardware\n");
5246 goto err_stop_firmware;
5249 priv->rxd_ops = &rxd_sta_ops;
5252 priv->sniffer_enabled = false;
5253 priv->wmm_enabled = false;
5254 priv->pending_tx_pkts = 0;
5256 rc = mwl8k_rxq_init(hw, 0);
5258 goto err_stop_firmware;
5259 rxq_refill(hw, 0, INT_MAX);
5261 /* For the sta firmware, we need to know the dma addresses of tx queues
5262 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5263 * prior to issuing this command. But for the AP case, we learn the
5264 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5265 * case we must initialize the tx queues after.
5267 priv->num_ampdu_queues = 0;
5269 rc = mwl8k_init_txqs(hw);
5271 goto err_free_queues;
5274 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
5275 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5276 iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
5277 MWL8K_A2H_INT_BA_WATCHDOG,
5278 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
5279 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
5281 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
5282 IRQF_SHARED, MWL8K_NAME, hw);
5284 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
5285 goto err_free_queues;
5288 memset(priv->ampdu, 0, sizeof(priv->ampdu));
5291 * Temporarily enable interrupts. Initial firmware host
5292 * commands use interrupts and avoid polling. Disable
5293 * interrupts when done.
5295 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5297 /* Get config data, mac addrs etc */
5299 rc = mwl8k_cmd_get_hw_spec_ap(hw);
5301 rc = mwl8k_init_txqs(hw);
5303 rc = mwl8k_cmd_set_hw_spec(hw);
5305 rc = mwl8k_cmd_get_hw_spec_sta(hw);
5308 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
5312 /* Turn radio off */
5313 rc = mwl8k_cmd_radio_disable(hw);
5315 wiphy_err(hw->wiphy, "Cannot disable\n");
5319 /* Clear MAC address */
5320 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
5322 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
5326 /* Disable interrupts */
5327 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5328 free_irq(priv->pdev->irq, hw);
5330 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5331 priv->device_info->part_name,
5332 priv->hw_rev, hw->wiphy->perm_addr,
5333 priv->ap_fw ? "AP" : "STA",
5334 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
5335 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
5340 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5341 free_irq(priv->pdev->irq, hw);
5344 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5345 mwl8k_txq_deinit(hw, i);
5346 mwl8k_rxq_deinit(hw, 0);
5349 mwl8k_hw_reset(priv);
5355 * invoke mwl8k_reload_firmware to change the firmware image after the device
5356 * has already been registered
5358 static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
5361 struct mwl8k_priv *priv = hw->priv;
5364 mwl8k_rxq_deinit(hw, 0);
5366 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5367 mwl8k_txq_deinit(hw, i);
5369 rc = mwl8k_init_firmware(hw, fw_image, false);
5373 rc = mwl8k_probe_hw(hw);
5377 rc = mwl8k_start(hw);
5381 rc = mwl8k_config(hw, ~0);
5385 for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
5386 rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
5394 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
5398 static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
5400 struct ieee80211_hw *hw = priv->hw;
5403 rc = mwl8k_load_firmware(hw);
5404 mwl8k_release_firmware(priv);
5406 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5411 * Extra headroom is the size of the required DMA header
5412 * minus the size of the smallest 802.11 frame (CTS frame).
5414 hw->extra_tx_headroom =
5415 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
5417 hw->channel_change_time = 10;
5419 hw->queues = MWL8K_TX_WMM_QUEUES;
5421 /* Set rssi values to dBm */
5422 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
5423 hw->vif_data_size = sizeof(struct mwl8k_vif);
5424 hw->sta_data_size = sizeof(struct mwl8k_sta);
5426 priv->macids_used = 0;
5427 INIT_LIST_HEAD(&priv->vif_list);
5429 /* Set default radio state and preamble */
5431 priv->radio_short_preamble = 0;
5433 /* Finalize join worker */
5434 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
5435 /* Handle watchdog ba events */
5436 INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
5438 /* TX reclaim and RX tasklets. */
5439 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
5440 tasklet_disable(&priv->poll_tx_task);
5441 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
5442 tasklet_disable(&priv->poll_rx_task);
5444 /* Power management cookie */
5445 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
5446 if (priv->cookie == NULL)
5449 mutex_init(&priv->fw_mutex);
5450 priv->fw_mutex_owner = NULL;
5451 priv->fw_mutex_depth = 0;
5452 priv->hostcmd_wait = NULL;
5454 spin_lock_init(&priv->tx_lock);
5456 spin_lock_init(&priv->stream_lock);
5458 priv->tx_wait = NULL;
5460 rc = mwl8k_probe_hw(hw);
5462 goto err_free_cookie;
5464 hw->wiphy->interface_modes = 0;
5465 if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
5466 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
5467 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
5468 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
5470 rc = ieee80211_register_hw(hw);
5472 wiphy_err(hw->wiphy, "Cannot register device\n");
5473 goto err_unprobe_hw;
5479 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5480 mwl8k_txq_deinit(hw, i);
5481 mwl8k_rxq_deinit(hw, 0);
5484 if (priv->cookie != NULL)
5485 pci_free_consistent(priv->pdev, 4,
5486 priv->cookie, priv->cookie_dma);
5490 static int __devinit mwl8k_probe(struct pci_dev *pdev,
5491 const struct pci_device_id *id)
5493 static int printed_version;
5494 struct ieee80211_hw *hw;
5495 struct mwl8k_priv *priv;
5496 struct mwl8k_device_info *di;
5499 if (!printed_version) {
5500 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
5501 printed_version = 1;
5505 rc = pci_enable_device(pdev);
5507 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
5512 rc = pci_request_regions(pdev, MWL8K_NAME);
5514 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
5516 goto err_disable_device;
5519 pci_set_master(pdev);
5522 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
5524 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
5529 SET_IEEE80211_DEV(hw, &pdev->dev);
5530 pci_set_drvdata(pdev, hw);
5535 priv->device_info = &mwl8k_info_tbl[id->driver_data];
5538 priv->sram = pci_iomap(pdev, 0, 0x10000);
5539 if (priv->sram == NULL) {
5540 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
5545 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
5546 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
5548 priv->regs = pci_iomap(pdev, 1, 0x10000);
5549 if (priv->regs == NULL) {
5550 priv->regs = pci_iomap(pdev, 2, 0x10000);
5551 if (priv->regs == NULL) {
5552 wiphy_err(hw->wiphy, "Cannot map device registers\n");
5558 * Choose the initial fw image depending on user input. If a second
5559 * image is available, make it the alternative image that will be
5560 * loaded if the first one fails.
5562 init_completion(&priv->firmware_loading_complete);
5563 di = priv->device_info;
5564 if (ap_mode_default && di->fw_image_ap) {
5565 priv->fw_pref = di->fw_image_ap;
5566 priv->fw_alt = di->fw_image_sta;
5567 } else if (!ap_mode_default && di->fw_image_sta) {
5568 priv->fw_pref = di->fw_image_sta;
5569 priv->fw_alt = di->fw_image_ap;
5570 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
5571 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
5572 priv->fw_pref = di->fw_image_sta;
5573 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
5574 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
5575 priv->fw_pref = di->fw_image_ap;
5577 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
5579 goto err_stop_firmware;
5583 mwl8k_hw_reset(priv);
5586 if (priv->regs != NULL)
5587 pci_iounmap(pdev, priv->regs);
5589 if (priv->sram != NULL)
5590 pci_iounmap(pdev, priv->sram);
5592 pci_set_drvdata(pdev, NULL);
5593 ieee80211_free_hw(hw);
5596 pci_release_regions(pdev);
5599 pci_disable_device(pdev);
5604 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
5606 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
5609 static void __devexit mwl8k_remove(struct pci_dev *pdev)
5611 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
5612 struct mwl8k_priv *priv;
5619 wait_for_completion(&priv->firmware_loading_complete);
5621 if (priv->fw_state == FW_STATE_ERROR) {
5622 mwl8k_hw_reset(priv);
5626 ieee80211_stop_queues(hw);
5628 ieee80211_unregister_hw(hw);
5630 /* Remove TX reclaim and RX tasklets. */
5631 tasklet_kill(&priv->poll_tx_task);
5632 tasklet_kill(&priv->poll_rx_task);
5635 mwl8k_hw_reset(priv);
5637 /* Return all skbs to mac80211 */
5638 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5639 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
5641 for (i = 0; i < mwl8k_tx_queues(priv); i++)
5642 mwl8k_txq_deinit(hw, i);
5644 mwl8k_rxq_deinit(hw, 0);
5646 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
5649 pci_iounmap(pdev, priv->regs);
5650 pci_iounmap(pdev, priv->sram);
5651 pci_set_drvdata(pdev, NULL);
5652 ieee80211_free_hw(hw);
5653 pci_release_regions(pdev);
5654 pci_disable_device(pdev);
5657 static struct pci_driver mwl8k_driver = {
5659 .id_table = mwl8k_pci_id_table,
5660 .probe = mwl8k_probe,
5661 .remove = __devexit_p(mwl8k_remove),
5662 .shutdown = __devexit_p(mwl8k_shutdown),
5665 static int __init mwl8k_init(void)
5667 return pci_register_driver(&mwl8k_driver);
5670 static void __exit mwl8k_exit(void)
5672 pci_unregister_driver(&mwl8k_driver);
5675 module_init(mwl8k_init);
5676 module_exit(mwl8k_exit);
5678 MODULE_DESCRIPTION(MWL8K_DESC);
5679 MODULE_VERSION(MWL8K_VERSION);
5680 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
5681 MODULE_LICENSE("GPL");