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 <net/mac80211.h>
23 #include <linux/moduleparam.h>
24 #include <linux/firmware.h>
25 #include <linux/workqueue.h>
27 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
28 #define MWL8K_NAME KBUILD_MODNAME
29 #define MWL8K_VERSION "0.12"
31 /* Register definitions */
32 #define MWL8K_HIU_GEN_PTR 0x00000c10
33 #define MWL8K_MODE_STA 0x0000005a
34 #define MWL8K_MODE_AP 0x000000a5
35 #define MWL8K_HIU_INT_CODE 0x00000c14
36 #define MWL8K_FWSTA_READY 0xf0f1f2f4
37 #define MWL8K_FWAP_READY 0xf1f2f4a5
38 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
39 #define MWL8K_HIU_SCRATCH 0x00000c40
41 /* Host->device communications */
42 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
43 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
44 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
45 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
46 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
47 #define MWL8K_H2A_INT_DUMMY (1 << 20)
48 #define MWL8K_H2A_INT_RESET (1 << 15)
49 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
50 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
52 /* Device->host communications */
53 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
54 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
55 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
56 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
57 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
58 #define MWL8K_A2H_INT_DUMMY (1 << 20)
59 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
60 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
61 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
62 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
63 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
64 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
65 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
66 #define MWL8K_A2H_INT_RX_READY (1 << 1)
67 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
69 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
70 MWL8K_A2H_INT_CHNL_SWITCHED | \
71 MWL8K_A2H_INT_QUEUE_EMPTY | \
72 MWL8K_A2H_INT_RADAR_DETECT | \
73 MWL8K_A2H_INT_RADIO_ON | \
74 MWL8K_A2H_INT_RADIO_OFF | \
75 MWL8K_A2H_INT_MAC_EVENT | \
76 MWL8K_A2H_INT_OPC_DONE | \
77 MWL8K_A2H_INT_RX_READY | \
78 MWL8K_A2H_INT_TX_DONE)
80 #define MWL8K_RX_QUEUES 1
81 #define MWL8K_TX_QUEUES 4
85 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
86 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
87 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
91 struct mwl8k_device_info {
95 struct rxd_ops *ap_rxd_ops;
98 struct mwl8k_rx_queue {
101 /* hw receives here */
104 /* refill descs here */
111 DECLARE_PCI_UNMAP_ADDR(dma)
115 struct mwl8k_tx_queue {
116 /* hw transmits here */
119 /* sw appends here */
123 struct mwl8k_tx_desc *txd;
125 struct sk_buff **skb;
129 struct ieee80211_hw *hw;
130 struct pci_dev *pdev;
132 struct mwl8k_device_info *device_info;
138 struct firmware *fw_helper;
139 struct firmware *fw_ucode;
141 /* hardware/firmware parameters */
143 struct rxd_ops *rxd_ops;
144 struct ieee80211_supported_band band_24;
145 struct ieee80211_channel channels_24[14];
146 struct ieee80211_rate rates_24[14];
147 struct ieee80211_supported_band band_50;
148 struct ieee80211_channel channels_50[4];
149 struct ieee80211_rate rates_50[9];
150 u32 ap_macids_supported;
151 u32 sta_macids_supported;
153 /* firmware access */
154 struct mutex fw_mutex;
155 struct task_struct *fw_mutex_owner;
157 struct completion *hostcmd_wait;
159 /* lock held over TX and TX reap */
162 /* TX quiesce completion, protected by fw_mutex and tx_lock */
163 struct completion *tx_wait;
165 /* List of interfaces. */
167 struct list_head vif_list;
169 /* power management status cookie from firmware */
171 dma_addr_t cookie_dma;
178 * Running count of TX packets in flight, to avoid
179 * iterating over the transmit rings each time.
183 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
184 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
187 bool radio_short_preamble;
188 bool sniffer_enabled;
191 struct work_struct sta_notify_worker;
192 spinlock_t sta_notify_list_lock;
193 struct list_head sta_notify_list;
195 /* XXX need to convert this to handle multiple interfaces */
197 u8 capture_bssid[ETH_ALEN];
198 struct sk_buff *beacon_skb;
201 * This FJ worker has to be global as it is scheduled from the
202 * RX handler. At this point we don't know which interface it
203 * belongs to until the list of bssids waiting to complete join
206 struct work_struct finalize_join_worker;
208 /* Tasklet to perform TX reclaim. */
209 struct tasklet_struct poll_tx_task;
211 /* Tasklet to perform RX. */
212 struct tasklet_struct poll_rx_task;
215 /* Per interface specific private data */
217 struct list_head list;
218 struct ieee80211_vif *vif;
220 /* Firmware macid for this vif. */
223 /* Non AMPDU sequence number assigned by driver. */
226 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
229 /* Index into station database. Returned by UPDATE_STADB. */
232 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
234 static const struct ieee80211_channel mwl8k_channels_24[] = {
235 { .center_freq = 2412, .hw_value = 1, },
236 { .center_freq = 2417, .hw_value = 2, },
237 { .center_freq = 2422, .hw_value = 3, },
238 { .center_freq = 2427, .hw_value = 4, },
239 { .center_freq = 2432, .hw_value = 5, },
240 { .center_freq = 2437, .hw_value = 6, },
241 { .center_freq = 2442, .hw_value = 7, },
242 { .center_freq = 2447, .hw_value = 8, },
243 { .center_freq = 2452, .hw_value = 9, },
244 { .center_freq = 2457, .hw_value = 10, },
245 { .center_freq = 2462, .hw_value = 11, },
246 { .center_freq = 2467, .hw_value = 12, },
247 { .center_freq = 2472, .hw_value = 13, },
248 { .center_freq = 2484, .hw_value = 14, },
251 static const struct ieee80211_rate mwl8k_rates_24[] = {
252 { .bitrate = 10, .hw_value = 2, },
253 { .bitrate = 20, .hw_value = 4, },
254 { .bitrate = 55, .hw_value = 11, },
255 { .bitrate = 110, .hw_value = 22, },
256 { .bitrate = 220, .hw_value = 44, },
257 { .bitrate = 60, .hw_value = 12, },
258 { .bitrate = 90, .hw_value = 18, },
259 { .bitrate = 120, .hw_value = 24, },
260 { .bitrate = 180, .hw_value = 36, },
261 { .bitrate = 240, .hw_value = 48, },
262 { .bitrate = 360, .hw_value = 72, },
263 { .bitrate = 480, .hw_value = 96, },
264 { .bitrate = 540, .hw_value = 108, },
265 { .bitrate = 720, .hw_value = 144, },
268 static const struct ieee80211_channel mwl8k_channels_50[] = {
269 { .center_freq = 5180, .hw_value = 36, },
270 { .center_freq = 5200, .hw_value = 40, },
271 { .center_freq = 5220, .hw_value = 44, },
272 { .center_freq = 5240, .hw_value = 48, },
275 static const struct ieee80211_rate mwl8k_rates_50[] = {
276 { .bitrate = 60, .hw_value = 12, },
277 { .bitrate = 90, .hw_value = 18, },
278 { .bitrate = 120, .hw_value = 24, },
279 { .bitrate = 180, .hw_value = 36, },
280 { .bitrate = 240, .hw_value = 48, },
281 { .bitrate = 360, .hw_value = 72, },
282 { .bitrate = 480, .hw_value = 96, },
283 { .bitrate = 540, .hw_value = 108, },
284 { .bitrate = 720, .hw_value = 144, },
287 /* Set or get info from Firmware */
288 #define MWL8K_CMD_SET 0x0001
289 #define MWL8K_CMD_GET 0x0000
291 /* Firmware command codes */
292 #define MWL8K_CMD_CODE_DNLD 0x0001
293 #define MWL8K_CMD_GET_HW_SPEC 0x0003
294 #define MWL8K_CMD_SET_HW_SPEC 0x0004
295 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
296 #define MWL8K_CMD_GET_STAT 0x0014
297 #define MWL8K_CMD_RADIO_CONTROL 0x001c
298 #define MWL8K_CMD_RF_TX_POWER 0x001e
299 #define MWL8K_CMD_RF_ANTENNA 0x0020
300 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
301 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
302 #define MWL8K_CMD_SET_POST_SCAN 0x0108
303 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
304 #define MWL8K_CMD_SET_AID 0x010d
305 #define MWL8K_CMD_SET_RATE 0x0110
306 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
307 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
308 #define MWL8K_CMD_SET_SLOT 0x0114
309 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
310 #define MWL8K_CMD_SET_WMM_MODE 0x0123
311 #define MWL8K_CMD_MIMO_CONFIG 0x0125
312 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
313 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
314 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
315 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
316 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
317 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
318 #define MWL8K_CMD_UPDATE_STADB 0x1123
320 static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
322 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
323 snprintf(buf, bufsize, "%s", #x);\
326 switch (cmd & ~0x8000) {
327 MWL8K_CMDNAME(CODE_DNLD);
328 MWL8K_CMDNAME(GET_HW_SPEC);
329 MWL8K_CMDNAME(SET_HW_SPEC);
330 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
331 MWL8K_CMDNAME(GET_STAT);
332 MWL8K_CMDNAME(RADIO_CONTROL);
333 MWL8K_CMDNAME(RF_TX_POWER);
334 MWL8K_CMDNAME(RF_ANTENNA);
335 MWL8K_CMDNAME(SET_BEACON);
336 MWL8K_CMDNAME(SET_PRE_SCAN);
337 MWL8K_CMDNAME(SET_POST_SCAN);
338 MWL8K_CMDNAME(SET_RF_CHANNEL);
339 MWL8K_CMDNAME(SET_AID);
340 MWL8K_CMDNAME(SET_RATE);
341 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
342 MWL8K_CMDNAME(RTS_THRESHOLD);
343 MWL8K_CMDNAME(SET_SLOT);
344 MWL8K_CMDNAME(SET_EDCA_PARAMS);
345 MWL8K_CMDNAME(SET_WMM_MODE);
346 MWL8K_CMDNAME(MIMO_CONFIG);
347 MWL8K_CMDNAME(USE_FIXED_RATE);
348 MWL8K_CMDNAME(ENABLE_SNIFFER);
349 MWL8K_CMDNAME(SET_MAC_ADDR);
350 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
351 MWL8K_CMDNAME(BSS_START);
352 MWL8K_CMDNAME(SET_NEW_STN);
353 MWL8K_CMDNAME(UPDATE_STADB);
355 snprintf(buf, bufsize, "0x%x", cmd);
362 /* Hardware and firmware reset */
363 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
365 iowrite32(MWL8K_H2A_INT_RESET,
366 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
367 iowrite32(MWL8K_H2A_INT_RESET,
368 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
372 /* Release fw image */
373 static void mwl8k_release_fw(struct firmware **fw)
377 release_firmware(*fw);
381 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
383 mwl8k_release_fw(&priv->fw_ucode);
384 mwl8k_release_fw(&priv->fw_helper);
387 /* Request fw image */
388 static int mwl8k_request_fw(struct mwl8k_priv *priv,
389 const char *fname, struct firmware **fw)
391 /* release current image */
393 mwl8k_release_fw(fw);
395 return request_firmware((const struct firmware **)fw,
396 fname, &priv->pdev->dev);
399 static int mwl8k_request_firmware(struct mwl8k_priv *priv)
401 struct mwl8k_device_info *di = priv->device_info;
404 if (di->helper_image != NULL) {
405 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
407 printk(KERN_ERR "%s: Error requesting helper "
408 "firmware file %s\n", pci_name(priv->pdev),
414 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
416 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
417 pci_name(priv->pdev), di->fw_image);
418 mwl8k_release_fw(&priv->fw_helper);
425 struct mwl8k_cmd_pkt {
432 } __attribute__((packed));
438 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
440 void __iomem *regs = priv->regs;
444 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
445 if (pci_dma_mapping_error(priv->pdev, dma_addr))
448 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
449 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
450 iowrite32(MWL8K_H2A_INT_DOORBELL,
451 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
452 iowrite32(MWL8K_H2A_INT_DUMMY,
453 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
459 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
460 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
461 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
469 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
471 return loops ? 0 : -ETIMEDOUT;
474 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
475 const u8 *data, size_t length)
477 struct mwl8k_cmd_pkt *cmd;
481 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
485 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
492 int block_size = length > 256 ? 256 : length;
494 memcpy(cmd->payload, data + done, block_size);
495 cmd->length = cpu_to_le16(block_size);
497 rc = mwl8k_send_fw_load_cmd(priv, cmd,
498 sizeof(*cmd) + block_size);
503 length -= block_size;
508 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
516 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
517 const u8 *data, size_t length)
519 unsigned char *buffer;
520 int may_continue, rc = 0;
521 u32 done, prev_block_size;
523 buffer = kmalloc(1024, GFP_KERNEL);
530 while (may_continue > 0) {
533 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
534 if (block_size & 1) {
538 done += prev_block_size;
539 length -= prev_block_size;
542 if (block_size > 1024 || block_size > length) {
552 if (block_size == 0) {
559 prev_block_size = block_size;
560 memcpy(buffer, data + done, block_size);
562 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
567 if (!rc && length != 0)
575 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
577 struct mwl8k_priv *priv = hw->priv;
578 struct firmware *fw = priv->fw_ucode;
582 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
583 struct firmware *helper = priv->fw_helper;
585 if (helper == NULL) {
586 printk(KERN_ERR "%s: helper image needed but none "
587 "given\n", pci_name(priv->pdev));
591 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
593 printk(KERN_ERR "%s: unable to load firmware "
594 "helper image\n", pci_name(priv->pdev));
599 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
601 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
605 printk(KERN_ERR "%s: unable to load firmware image\n",
606 pci_name(priv->pdev));
610 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
616 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
617 if (ready_code == MWL8K_FWAP_READY) {
620 } else if (ready_code == MWL8K_FWSTA_READY) {
629 return loops ? 0 : -ETIMEDOUT;
633 /* DMA header used by firmware and hardware. */
634 struct mwl8k_dma_data {
636 struct ieee80211_hdr wh;
638 } __attribute__((packed));
640 /* Routines to add/remove DMA header from skb. */
641 static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
643 struct mwl8k_dma_data *tr;
646 tr = (struct mwl8k_dma_data *)skb->data;
647 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
649 if (hdrlen != sizeof(tr->wh)) {
650 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
651 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
652 *((__le16 *)(tr->data - 2)) = qos;
654 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
658 if (hdrlen != sizeof(*tr))
659 skb_pull(skb, sizeof(*tr) - hdrlen);
662 static inline void mwl8k_add_dma_header(struct sk_buff *skb)
664 struct ieee80211_hdr *wh;
666 struct mwl8k_dma_data *tr;
669 * Add a firmware DMA header; the firmware requires that we
670 * present a 2-byte payload length followed by a 4-address
671 * header (without QoS field), followed (optionally) by any
672 * WEP/ExtIV header (but only filled in for CCMP).
674 wh = (struct ieee80211_hdr *)skb->data;
676 hdrlen = ieee80211_hdrlen(wh->frame_control);
677 if (hdrlen != sizeof(*tr))
678 skb_push(skb, sizeof(*tr) - hdrlen);
680 if (ieee80211_is_data_qos(wh->frame_control))
683 tr = (struct mwl8k_dma_data *)skb->data;
685 memmove(&tr->wh, wh, hdrlen);
686 if (hdrlen != sizeof(tr->wh))
687 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
690 * Firmware length is the length of the fully formed "802.11
691 * payload". That is, everything except for the 802.11 header.
692 * This includes all crypto material including the MIC.
694 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
699 * Packet reception for 88w8366 AP firmware.
701 struct mwl8k_rxd_8366_ap {
705 __le32 pkt_phys_addr;
706 __le32 next_rxd_phys_addr;
710 __le32 hw_noise_floor_info;
717 } __attribute__((packed));
719 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
720 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
721 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
723 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
725 static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
727 struct mwl8k_rxd_8366_ap *rxd = _rxd;
729 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
730 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
733 static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
735 struct mwl8k_rxd_8366_ap *rxd = _rxd;
737 rxd->pkt_len = cpu_to_le16(len);
738 rxd->pkt_phys_addr = cpu_to_le32(addr);
744 mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
747 struct mwl8k_rxd_8366_ap *rxd = _rxd;
749 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
753 memset(status, 0, sizeof(*status));
755 status->signal = -rxd->rssi;
756 status->noise = -rxd->noise_floor;
758 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
759 status->flag |= RX_FLAG_HT;
760 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
761 status->flag |= RX_FLAG_40MHZ;
762 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
766 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
767 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
768 status->rate_idx = i;
774 if (rxd->channel > 14) {
775 status->band = IEEE80211_BAND_5GHZ;
776 if (!(status->flag & RX_FLAG_HT))
777 status->rate_idx -= 5;
779 status->band = IEEE80211_BAND_2GHZ;
781 status->freq = ieee80211_channel_to_frequency(rxd->channel);
783 *qos = rxd->qos_control;
785 return le16_to_cpu(rxd->pkt_len);
788 static struct rxd_ops rxd_8366_ap_ops = {
789 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
790 .rxd_init = mwl8k_rxd_8366_ap_init,
791 .rxd_refill = mwl8k_rxd_8366_ap_refill,
792 .rxd_process = mwl8k_rxd_8366_ap_process,
796 * Packet reception for STA firmware.
798 struct mwl8k_rxd_sta {
802 __le32 pkt_phys_addr;
803 __le32 next_rxd_phys_addr;
813 } __attribute__((packed));
815 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
816 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
817 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
818 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
819 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
820 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
822 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
824 static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
826 struct mwl8k_rxd_sta *rxd = _rxd;
828 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
829 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
832 static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
834 struct mwl8k_rxd_sta *rxd = _rxd;
836 rxd->pkt_len = cpu_to_le16(len);
837 rxd->pkt_phys_addr = cpu_to_le32(addr);
843 mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
846 struct mwl8k_rxd_sta *rxd = _rxd;
849 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
853 rate_info = le16_to_cpu(rxd->rate_info);
855 memset(status, 0, sizeof(*status));
857 status->signal = -rxd->rssi;
858 status->noise = -rxd->noise_level;
859 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
860 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
862 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
863 status->flag |= RX_FLAG_SHORTPRE;
864 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
865 status->flag |= RX_FLAG_40MHZ;
866 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
867 status->flag |= RX_FLAG_SHORT_GI;
868 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
869 status->flag |= RX_FLAG_HT;
871 if (rxd->channel > 14) {
872 status->band = IEEE80211_BAND_5GHZ;
873 if (!(status->flag & RX_FLAG_HT))
874 status->rate_idx -= 5;
876 status->band = IEEE80211_BAND_2GHZ;
878 status->freq = ieee80211_channel_to_frequency(rxd->channel);
880 *qos = rxd->qos_control;
882 return le16_to_cpu(rxd->pkt_len);
885 static struct rxd_ops rxd_sta_ops = {
886 .rxd_size = sizeof(struct mwl8k_rxd_sta),
887 .rxd_init = mwl8k_rxd_sta_init,
888 .rxd_refill = mwl8k_rxd_sta_refill,
889 .rxd_process = mwl8k_rxd_sta_process,
893 #define MWL8K_RX_DESCS 256
894 #define MWL8K_RX_MAXSZ 3800
896 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
898 struct mwl8k_priv *priv = hw->priv;
899 struct mwl8k_rx_queue *rxq = priv->rxq + index;
907 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
909 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
910 if (rxq->rxd == NULL) {
911 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
912 wiphy_name(hw->wiphy));
915 memset(rxq->rxd, 0, size);
917 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
918 if (rxq->buf == NULL) {
919 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
920 wiphy_name(hw->wiphy));
921 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
924 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
926 for (i = 0; i < MWL8K_RX_DESCS; i++) {
930 dma_addr_t next_dma_addr;
932 desc_size = priv->rxd_ops->rxd_size;
933 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
936 if (nexti == MWL8K_RX_DESCS)
938 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
940 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
946 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
948 struct mwl8k_priv *priv = hw->priv;
949 struct mwl8k_rx_queue *rxq = priv->rxq + index;
953 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
959 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
963 addr = pci_map_single(priv->pdev, skb->data,
964 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
968 if (rxq->tail == MWL8K_RX_DESCS)
970 rxq->buf[rx].skb = skb;
971 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
973 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
974 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
982 /* Must be called only when the card's reception is completely halted */
983 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
985 struct mwl8k_priv *priv = hw->priv;
986 struct mwl8k_rx_queue *rxq = priv->rxq + index;
989 for (i = 0; i < MWL8K_RX_DESCS; i++) {
990 if (rxq->buf[i].skb != NULL) {
991 pci_unmap_single(priv->pdev,
992 pci_unmap_addr(&rxq->buf[i], dma),
993 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
994 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
996 kfree_skb(rxq->buf[i].skb);
997 rxq->buf[i].skb = NULL;
1004 pci_free_consistent(priv->pdev,
1005 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
1006 rxq->rxd, rxq->rxd_dma);
1012 * Scan a list of BSSIDs to process for finalize join.
1013 * Allows for extension to process multiple BSSIDs.
1016 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1018 return priv->capture_beacon &&
1019 ieee80211_is_beacon(wh->frame_control) &&
1020 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1023 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1024 struct sk_buff *skb)
1026 struct mwl8k_priv *priv = hw->priv;
1028 priv->capture_beacon = false;
1029 memset(priv->capture_bssid, 0, ETH_ALEN);
1032 * Use GFP_ATOMIC as rxq_process is called from
1033 * the primary interrupt handler, memory allocation call
1036 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1037 if (priv->beacon_skb != NULL)
1038 ieee80211_queue_work(hw, &priv->finalize_join_worker);
1041 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1043 struct mwl8k_priv *priv = hw->priv;
1044 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1048 while (rxq->rxd_count && limit--) {
1049 struct sk_buff *skb;
1052 struct ieee80211_rx_status status;
1055 skb = rxq->buf[rxq->head].skb;
1059 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1061 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
1065 rxq->buf[rxq->head].skb = NULL;
1067 pci_unmap_single(priv->pdev,
1068 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1069 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1070 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1073 if (rxq->head == MWL8K_RX_DESCS)
1078 skb_put(skb, pkt_len);
1079 mwl8k_remove_dma_header(skb, qos);
1082 * Check for a pending join operation. Save a
1083 * copy of the beacon and schedule a tasklet to
1084 * send a FINALIZE_JOIN command to the firmware.
1086 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1087 mwl8k_save_beacon(hw, skb);
1089 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1090 ieee80211_rx_irqsafe(hw, skb);
1100 * Packet transmission.
1103 #define MWL8K_TXD_STATUS_OK 0x00000001
1104 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1105 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1106 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1107 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1109 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1110 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1111 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1112 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1113 #define MWL8K_QOS_EOSP 0x0010
1115 struct mwl8k_tx_desc {
1120 __le32 pkt_phys_addr;
1122 __u8 dest_MAC_addr[ETH_ALEN];
1123 __le32 next_txd_phys_addr;
1128 } __attribute__((packed));
1130 #define MWL8K_TX_DESCS 128
1132 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1134 struct mwl8k_priv *priv = hw->priv;
1135 struct mwl8k_tx_queue *txq = priv->txq + index;
1143 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1145 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1146 if (txq->txd == NULL) {
1147 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1148 wiphy_name(hw->wiphy));
1151 memset(txq->txd, 0, size);
1153 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1154 if (txq->skb == NULL) {
1155 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1156 wiphy_name(hw->wiphy));
1157 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1160 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
1162 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1163 struct mwl8k_tx_desc *tx_desc;
1166 tx_desc = txq->txd + i;
1167 nexti = (i + 1) % MWL8K_TX_DESCS;
1169 tx_desc->status = 0;
1170 tx_desc->next_txd_phys_addr =
1171 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1177 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1179 iowrite32(MWL8K_H2A_INT_PPA_READY,
1180 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1181 iowrite32(MWL8K_H2A_INT_DUMMY,
1182 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1183 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1186 static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1188 struct mwl8k_priv *priv = hw->priv;
1191 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1192 struct mwl8k_tx_queue *txq = priv->txq + i;
1198 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1199 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1202 status = le32_to_cpu(tx_desc->status);
1203 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1208 if (tx_desc->pkt_len == 0)
1212 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1213 "fw_owned=%d drv_owned=%d unused=%d\n",
1214 wiphy_name(hw->wiphy), i,
1215 txq->len, txq->head, txq->tail,
1216 fw_owned, drv_owned, unused);
1221 * Must be called with priv->fw_mutex held and tx queues stopped.
1223 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1225 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1227 struct mwl8k_priv *priv = hw->priv;
1228 DECLARE_COMPLETION_ONSTACK(tx_wait);
1235 * The TX queues are stopped at this point, so this test
1236 * doesn't need to take ->tx_lock.
1238 if (!priv->pending_tx_pkts)
1244 spin_lock_bh(&priv->tx_lock);
1245 priv->tx_wait = &tx_wait;
1248 unsigned long timeout;
1250 oldcount = priv->pending_tx_pkts;
1252 spin_unlock_bh(&priv->tx_lock);
1253 timeout = wait_for_completion_timeout(&tx_wait,
1254 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1255 spin_lock_bh(&priv->tx_lock);
1258 WARN_ON(priv->pending_tx_pkts);
1260 printk(KERN_NOTICE "%s: tx rings drained\n",
1261 wiphy_name(hw->wiphy));
1266 if (priv->pending_tx_pkts < oldcount) {
1267 printk(KERN_NOTICE "%s: waiting for tx rings "
1268 "to drain (%d -> %d pkts)\n",
1269 wiphy_name(hw->wiphy), oldcount,
1270 priv->pending_tx_pkts);
1275 priv->tx_wait = NULL;
1277 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1278 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1279 mwl8k_dump_tx_rings(hw);
1283 spin_unlock_bh(&priv->tx_lock);
1288 #define MWL8K_TXD_SUCCESS(status) \
1289 ((status) & (MWL8K_TXD_STATUS_OK | \
1290 MWL8K_TXD_STATUS_OK_RETRY | \
1291 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1294 mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1296 struct mwl8k_priv *priv = hw->priv;
1297 struct mwl8k_tx_queue *txq = priv->txq + index;
1301 while (txq->len > 0 && limit--) {
1303 struct mwl8k_tx_desc *tx_desc;
1306 struct sk_buff *skb;
1307 struct ieee80211_tx_info *info;
1311 tx_desc = txq->txd + tx;
1313 status = le32_to_cpu(tx_desc->status);
1315 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1319 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1322 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1323 BUG_ON(txq->len == 0);
1325 priv->pending_tx_pkts--;
1327 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1328 size = le16_to_cpu(tx_desc->pkt_len);
1330 txq->skb[tx] = NULL;
1332 BUG_ON(skb == NULL);
1333 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1335 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
1337 /* Mark descriptor as unused */
1338 tx_desc->pkt_phys_addr = 0;
1339 tx_desc->pkt_len = 0;
1341 info = IEEE80211_SKB_CB(skb);
1342 ieee80211_tx_info_clear_status(info);
1343 if (MWL8K_TXD_SUCCESS(status))
1344 info->flags |= IEEE80211_TX_STAT_ACK;
1346 ieee80211_tx_status_irqsafe(hw, skb);
1351 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
1352 ieee80211_wake_queue(hw, index);
1357 /* must be called only when the card's transmit is completely halted */
1358 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1360 struct mwl8k_priv *priv = hw->priv;
1361 struct mwl8k_tx_queue *txq = priv->txq + index;
1363 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1368 pci_free_consistent(priv->pdev,
1369 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1370 txq->txd, txq->txd_dma);
1375 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1377 struct mwl8k_priv *priv = hw->priv;
1378 struct ieee80211_tx_info *tx_info;
1379 struct mwl8k_vif *mwl8k_vif;
1380 struct ieee80211_hdr *wh;
1381 struct mwl8k_tx_queue *txq;
1382 struct mwl8k_tx_desc *tx;
1388 wh = (struct ieee80211_hdr *)skb->data;
1389 if (ieee80211_is_data_qos(wh->frame_control))
1390 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1394 mwl8k_add_dma_header(skb);
1395 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1397 tx_info = IEEE80211_SKB_CB(skb);
1398 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1400 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1401 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1402 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1403 mwl8k_vif->seqno += 0x10;
1406 /* Setup firmware control bit fields for each frame type. */
1409 if (ieee80211_is_mgmt(wh->frame_control) ||
1410 ieee80211_is_ctl(wh->frame_control)) {
1412 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1413 } else if (ieee80211_is_data(wh->frame_control)) {
1415 if (is_multicast_ether_addr(wh->addr1))
1416 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1418 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1419 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1420 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1422 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1425 dma = pci_map_single(priv->pdev, skb->data,
1426 skb->len, PCI_DMA_TODEVICE);
1428 if (pci_dma_mapping_error(priv->pdev, dma)) {
1429 printk(KERN_DEBUG "%s: failed to dma map skb, "
1430 "dropping TX frame.\n", wiphy_name(hw->wiphy));
1432 return NETDEV_TX_OK;
1435 spin_lock_bh(&priv->tx_lock);
1437 txq = priv->txq + index;
1439 BUG_ON(txq->skb[txq->tail] != NULL);
1440 txq->skb[txq->tail] = skb;
1442 tx = txq->txd + txq->tail;
1443 tx->data_rate = txdatarate;
1444 tx->tx_priority = index;
1445 tx->qos_control = cpu_to_le16(qos);
1446 tx->pkt_phys_addr = cpu_to_le32(dma);
1447 tx->pkt_len = cpu_to_le16(skb->len);
1449 if (!priv->ap_fw && tx_info->control.sta != NULL)
1450 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1454 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1457 priv->pending_tx_pkts++;
1460 if (txq->tail == MWL8K_TX_DESCS)
1463 if (txq->head == txq->tail)
1464 ieee80211_stop_queue(hw, index);
1466 mwl8k_tx_start(priv);
1468 spin_unlock_bh(&priv->tx_lock);
1470 return NETDEV_TX_OK;
1477 * We have the following requirements for issuing firmware commands:
1478 * - Some commands require that the packet transmit path is idle when
1479 * the command is issued. (For simplicity, we'll just quiesce the
1480 * transmit path for every command.)
1481 * - There are certain sequences of commands that need to be issued to
1482 * the hardware sequentially, with no other intervening commands.
1484 * This leads to an implementation of a "firmware lock" as a mutex that
1485 * can be taken recursively, and which is taken by both the low-level
1486 * command submission function (mwl8k_post_cmd) as well as any users of
1487 * that function that require issuing of an atomic sequence of commands,
1488 * and quiesces the transmit path whenever it's taken.
1490 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1492 struct mwl8k_priv *priv = hw->priv;
1494 if (priv->fw_mutex_owner != current) {
1497 mutex_lock(&priv->fw_mutex);
1498 ieee80211_stop_queues(hw);
1500 rc = mwl8k_tx_wait_empty(hw);
1502 ieee80211_wake_queues(hw);
1503 mutex_unlock(&priv->fw_mutex);
1508 priv->fw_mutex_owner = current;
1511 priv->fw_mutex_depth++;
1516 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1518 struct mwl8k_priv *priv = hw->priv;
1520 if (!--priv->fw_mutex_depth) {
1521 ieee80211_wake_queues(hw);
1522 priv->fw_mutex_owner = NULL;
1523 mutex_unlock(&priv->fw_mutex);
1529 * Command processing.
1532 /* Timeout firmware commands after 10s */
1533 #define MWL8K_CMD_TIMEOUT_MS 10000
1535 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1537 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1538 struct mwl8k_priv *priv = hw->priv;
1539 void __iomem *regs = priv->regs;
1540 dma_addr_t dma_addr;
1541 unsigned int dma_size;
1543 unsigned long timeout = 0;
1546 cmd->result = 0xffff;
1547 dma_size = le16_to_cpu(cmd->length);
1548 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1549 PCI_DMA_BIDIRECTIONAL);
1550 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1553 rc = mwl8k_fw_lock(hw);
1555 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1556 PCI_DMA_BIDIRECTIONAL);
1560 priv->hostcmd_wait = &cmd_wait;
1561 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1562 iowrite32(MWL8K_H2A_INT_DOORBELL,
1563 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1564 iowrite32(MWL8K_H2A_INT_DUMMY,
1565 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1567 timeout = wait_for_completion_timeout(&cmd_wait,
1568 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1570 priv->hostcmd_wait = NULL;
1572 mwl8k_fw_unlock(hw);
1574 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1575 PCI_DMA_BIDIRECTIONAL);
1578 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1579 wiphy_name(hw->wiphy),
1580 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1581 MWL8K_CMD_TIMEOUT_MS);
1586 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1588 rc = cmd->result ? -EINVAL : 0;
1590 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1591 wiphy_name(hw->wiphy),
1592 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1593 le16_to_cpu(cmd->result));
1595 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1596 wiphy_name(hw->wiphy),
1597 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1604 static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
1605 struct ieee80211_vif *vif,
1606 struct mwl8k_cmd_pkt *cmd)
1609 cmd->macid = MWL8K_VIF(vif)->macid;
1610 return mwl8k_post_cmd(hw, cmd);
1614 * Setup code shared between STA and AP firmware images.
1616 static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1618 struct mwl8k_priv *priv = hw->priv;
1620 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1621 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1623 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1624 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1626 priv->band_24.band = IEEE80211_BAND_2GHZ;
1627 priv->band_24.channels = priv->channels_24;
1628 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1629 priv->band_24.bitrates = priv->rates_24;
1630 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1632 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1635 static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
1637 struct mwl8k_priv *priv = hw->priv;
1639 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
1640 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
1642 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
1643 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
1645 priv->band_50.band = IEEE80211_BAND_5GHZ;
1646 priv->band_50.channels = priv->channels_50;
1647 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
1648 priv->band_50.bitrates = priv->rates_50;
1649 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
1651 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
1655 * CMD_GET_HW_SPEC (STA version).
1657 struct mwl8k_cmd_get_hw_spec_sta {
1658 struct mwl8k_cmd_pkt header;
1660 __u8 host_interface;
1662 __u8 perm_addr[ETH_ALEN];
1667 __u8 mcs_bitmap[16];
1668 __le32 rx_queue_ptr;
1669 __le32 num_tx_queues;
1670 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1672 __le32 num_tx_desc_per_queue;
1674 } __attribute__((packed));
1676 #define MWL8K_CAP_MAX_AMSDU 0x20000000
1677 #define MWL8K_CAP_GREENFIELD 0x08000000
1678 #define MWL8K_CAP_AMPDU 0x04000000
1679 #define MWL8K_CAP_RX_STBC 0x01000000
1680 #define MWL8K_CAP_TX_STBC 0x00800000
1681 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1682 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1683 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1684 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1685 #define MWL8K_CAP_DELAY_BA 0x00003000
1686 #define MWL8K_CAP_MIMO 0x00000200
1687 #define MWL8K_CAP_40MHZ 0x00000100
1688 #define MWL8K_CAP_BAND_MASK 0x00000007
1689 #define MWL8K_CAP_5GHZ 0x00000004
1690 #define MWL8K_CAP_2GHZ4 0x00000001
1693 mwl8k_set_ht_caps(struct ieee80211_hw *hw,
1694 struct ieee80211_supported_band *band, u32 cap)
1699 band->ht_cap.ht_supported = 1;
1701 if (cap & MWL8K_CAP_MAX_AMSDU)
1702 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
1703 if (cap & MWL8K_CAP_GREENFIELD)
1704 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
1705 if (cap & MWL8K_CAP_AMPDU) {
1706 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
1707 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1708 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1710 if (cap & MWL8K_CAP_RX_STBC)
1711 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
1712 if (cap & MWL8K_CAP_TX_STBC)
1713 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
1714 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
1715 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
1716 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
1717 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
1718 if (cap & MWL8K_CAP_DELAY_BA)
1719 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
1720 if (cap & MWL8K_CAP_40MHZ)
1721 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1723 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1724 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1726 band->ht_cap.mcs.rx_mask[0] = 0xff;
1727 if (rx_streams >= 2)
1728 band->ht_cap.mcs.rx_mask[1] = 0xff;
1729 if (rx_streams >= 3)
1730 band->ht_cap.mcs.rx_mask[2] = 0xff;
1731 band->ht_cap.mcs.rx_mask[4] = 0x01;
1732 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1734 if (rx_streams != tx_streams) {
1735 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1736 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
1737 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1742 mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
1744 struct mwl8k_priv *priv = hw->priv;
1746 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
1747 mwl8k_setup_2ghz_band(hw);
1748 if (caps & MWL8K_CAP_MIMO)
1749 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
1752 if (caps & MWL8K_CAP_5GHZ) {
1753 mwl8k_setup_5ghz_band(hw);
1754 if (caps & MWL8K_CAP_MIMO)
1755 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
1759 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
1761 struct mwl8k_priv *priv = hw->priv;
1762 struct mwl8k_cmd_get_hw_spec_sta *cmd;
1766 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1770 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1771 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1773 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1774 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1775 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1776 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1777 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1778 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1779 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1780 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1782 rc = mwl8k_post_cmd(hw, &cmd->header);
1785 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1786 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1787 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1788 priv->hw_rev = cmd->hw_rev;
1789 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
1790 priv->ap_macids_supported = 0x00000000;
1791 priv->sta_macids_supported = 0x00000001;
1799 * CMD_GET_HW_SPEC (AP version).
1801 struct mwl8k_cmd_get_hw_spec_ap {
1802 struct mwl8k_cmd_pkt header;
1804 __u8 host_interface;
1807 __u8 perm_addr[ETH_ALEN];
1818 } __attribute__((packed));
1820 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1822 struct mwl8k_priv *priv = hw->priv;
1823 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1826 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1830 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1831 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1833 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1834 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1836 rc = mwl8k_post_cmd(hw, &cmd->header);
1841 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1842 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1843 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1844 priv->hw_rev = cmd->hw_rev;
1845 mwl8k_setup_2ghz_band(hw);
1846 priv->ap_macids_supported = 0x000000ff;
1847 priv->sta_macids_supported = 0x00000000;
1849 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1850 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1852 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1853 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1855 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1856 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1858 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1859 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1861 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1862 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1864 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1865 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1875 struct mwl8k_cmd_set_hw_spec {
1876 struct mwl8k_cmd_pkt header;
1878 __u8 host_interface;
1880 __u8 perm_addr[ETH_ALEN];
1885 __le32 rx_queue_ptr;
1886 __le32 num_tx_queues;
1887 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1889 __le32 num_tx_desc_per_queue;
1891 } __attribute__((packed));
1893 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1894 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1895 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
1897 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1899 struct mwl8k_priv *priv = hw->priv;
1900 struct mwl8k_cmd_set_hw_spec *cmd;
1904 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1908 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1909 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1911 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1912 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1913 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1914 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1915 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1916 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1917 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1918 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
1919 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1920 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1922 rc = mwl8k_post_cmd(hw, &cmd->header);
1929 * CMD_MAC_MULTICAST_ADR.
1931 struct mwl8k_cmd_mac_multicast_adr {
1932 struct mwl8k_cmd_pkt header;
1935 __u8 addr[0][ETH_ALEN];
1938 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
1939 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
1940 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1941 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
1943 static struct mwl8k_cmd_pkt *
1944 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
1945 int mc_count, struct dev_addr_list *mclist)
1947 struct mwl8k_priv *priv = hw->priv;
1948 struct mwl8k_cmd_mac_multicast_adr *cmd;
1951 if (allmulti || mc_count > priv->num_mcaddrs) {
1956 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1958 cmd = kzalloc(size, GFP_ATOMIC);
1962 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1963 cmd->header.length = cpu_to_le16(size);
1964 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1965 MWL8K_ENABLE_RX_BROADCAST);
1968 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1969 } else if (mc_count) {
1972 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1973 cmd->numaddr = cpu_to_le16(mc_count);
1974 for (i = 0; i < mc_count && mclist; i++) {
1975 if (mclist->da_addrlen != ETH_ALEN) {
1979 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1980 mclist = mclist->next;
1984 return &cmd->header;
1990 struct mwl8k_cmd_get_stat {
1991 struct mwl8k_cmd_pkt header;
1993 } __attribute__((packed));
1995 #define MWL8K_STAT_ACK_FAILURE 9
1996 #define MWL8K_STAT_RTS_FAILURE 12
1997 #define MWL8K_STAT_FCS_ERROR 24
1998 #define MWL8K_STAT_RTS_SUCCESS 11
2000 static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2001 struct ieee80211_low_level_stats *stats)
2003 struct mwl8k_cmd_get_stat *cmd;
2006 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2010 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2011 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2013 rc = mwl8k_post_cmd(hw, &cmd->header);
2015 stats->dot11ACKFailureCount =
2016 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2017 stats->dot11RTSFailureCount =
2018 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2019 stats->dot11FCSErrorCount =
2020 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2021 stats->dot11RTSSuccessCount =
2022 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2030 * CMD_RADIO_CONTROL.
2032 struct mwl8k_cmd_radio_control {
2033 struct mwl8k_cmd_pkt header;
2037 } __attribute__((packed));
2040 mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
2042 struct mwl8k_priv *priv = hw->priv;
2043 struct mwl8k_cmd_radio_control *cmd;
2046 if (enable == priv->radio_on && !force)
2049 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2053 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2054 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2055 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2056 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
2057 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2059 rc = mwl8k_post_cmd(hw, &cmd->header);
2063 priv->radio_on = enable;
2068 static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
2070 return mwl8k_cmd_radio_control(hw, 0, 0);
2073 static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
2075 return mwl8k_cmd_radio_control(hw, 1, 0);
2079 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2081 struct mwl8k_priv *priv = hw->priv;
2083 priv->radio_short_preamble = short_preamble;
2085 return mwl8k_cmd_radio_control(hw, 1, 1);
2091 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
2093 struct mwl8k_cmd_rf_tx_power {
2094 struct mwl8k_cmd_pkt header;
2096 __le16 support_level;
2097 __le16 current_level;
2099 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2100 } __attribute__((packed));
2102 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
2104 struct mwl8k_cmd_rf_tx_power *cmd;
2107 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2111 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2112 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2113 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2114 cmd->support_level = cpu_to_le16(dBm);
2116 rc = mwl8k_post_cmd(hw, &cmd->header);
2125 struct mwl8k_cmd_rf_antenna {
2126 struct mwl8k_cmd_pkt header;
2129 } __attribute__((packed));
2131 #define MWL8K_RF_ANTENNA_RX 1
2132 #define MWL8K_RF_ANTENNA_TX 2
2135 mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2137 struct mwl8k_cmd_rf_antenna *cmd;
2140 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2144 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2145 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2146 cmd->antenna = cpu_to_le16(antenna);
2147 cmd->mode = cpu_to_le16(mask);
2149 rc = mwl8k_post_cmd(hw, &cmd->header);
2158 struct mwl8k_cmd_set_beacon {
2159 struct mwl8k_cmd_pkt header;
2164 static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2165 struct ieee80211_vif *vif, u8 *beacon, int len)
2167 struct mwl8k_cmd_set_beacon *cmd;
2170 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2174 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2175 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2176 cmd->beacon_len = cpu_to_le16(len);
2177 memcpy(cmd->beacon, beacon, len);
2179 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2188 struct mwl8k_cmd_set_pre_scan {
2189 struct mwl8k_cmd_pkt header;
2190 } __attribute__((packed));
2192 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2194 struct mwl8k_cmd_set_pre_scan *cmd;
2197 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2201 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2202 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2204 rc = mwl8k_post_cmd(hw, &cmd->header);
2211 * CMD_SET_POST_SCAN.
2213 struct mwl8k_cmd_set_post_scan {
2214 struct mwl8k_cmd_pkt header;
2216 __u8 bssid[ETH_ALEN];
2217 } __attribute__((packed));
2220 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2222 struct mwl8k_cmd_set_post_scan *cmd;
2225 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2229 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2230 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2232 memcpy(cmd->bssid, mac, ETH_ALEN);
2234 rc = mwl8k_post_cmd(hw, &cmd->header);
2241 * CMD_SET_RF_CHANNEL.
2243 struct mwl8k_cmd_set_rf_channel {
2244 struct mwl8k_cmd_pkt header;
2246 __u8 current_channel;
2247 __le32 channel_flags;
2248 } __attribute__((packed));
2250 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2251 struct ieee80211_conf *conf)
2253 struct ieee80211_channel *channel = conf->channel;
2254 struct mwl8k_cmd_set_rf_channel *cmd;
2257 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2261 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2262 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2263 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2264 cmd->current_channel = channel->hw_value;
2266 if (channel->band == IEEE80211_BAND_2GHZ)
2267 cmd->channel_flags |= cpu_to_le32(0x00000001);
2268 else if (channel->band == IEEE80211_BAND_5GHZ)
2269 cmd->channel_flags |= cpu_to_le32(0x00000004);
2271 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2272 conf->channel_type == NL80211_CHAN_HT20)
2273 cmd->channel_flags |= cpu_to_le32(0x00000080);
2274 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2275 cmd->channel_flags |= cpu_to_le32(0x000001900);
2276 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2277 cmd->channel_flags |= cpu_to_le32(0x000000900);
2279 rc = mwl8k_post_cmd(hw, &cmd->header);
2288 #define MWL8K_FRAME_PROT_DISABLED 0x00
2289 #define MWL8K_FRAME_PROT_11G 0x07
2290 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2291 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2293 struct mwl8k_cmd_update_set_aid {
2294 struct mwl8k_cmd_pkt header;
2297 /* AP's MAC address (BSSID) */
2298 __u8 bssid[ETH_ALEN];
2299 __le16 protection_mode;
2300 __u8 supp_rates[14];
2301 } __attribute__((packed));
2303 static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2309 * Clear nonstandard rates 4 and 13.
2313 for (i = 0, j = 0; i < 14; i++) {
2314 if (mask & (1 << i))
2315 rates[j++] = mwl8k_rates_24[i].hw_value;
2320 mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2321 struct ieee80211_vif *vif, u32 legacy_rate_mask)
2323 struct mwl8k_cmd_update_set_aid *cmd;
2327 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2331 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2332 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2333 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
2334 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
2336 if (vif->bss_conf.use_cts_prot) {
2337 prot_mode = MWL8K_FRAME_PROT_11G;
2339 switch (vif->bss_conf.ht_operation_mode &
2340 IEEE80211_HT_OP_MODE_PROTECTION) {
2341 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2342 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2344 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2345 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2348 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2352 cmd->protection_mode = cpu_to_le16(prot_mode);
2354 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
2356 rc = mwl8k_post_cmd(hw, &cmd->header);
2365 struct mwl8k_cmd_set_rate {
2366 struct mwl8k_cmd_pkt header;
2367 __u8 legacy_rates[14];
2369 /* Bitmap for supported MCS codes. */
2372 } __attribute__((packed));
2375 mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2376 u32 legacy_rate_mask, u8 *mcs_rates)
2378 struct mwl8k_cmd_set_rate *cmd;
2381 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2385 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2386 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2387 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
2388 memcpy(cmd->mcs_set, mcs_rates, 16);
2390 rc = mwl8k_post_cmd(hw, &cmd->header);
2397 * CMD_FINALIZE_JOIN.
2399 #define MWL8K_FJ_BEACON_MAXLEN 128
2401 struct mwl8k_cmd_finalize_join {
2402 struct mwl8k_cmd_pkt header;
2403 __le32 sleep_interval; /* Number of beacon periods to sleep */
2404 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2405 } __attribute__((packed));
2407 static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2408 int framelen, int dtim)
2410 struct mwl8k_cmd_finalize_join *cmd;
2411 struct ieee80211_mgmt *payload = frame;
2415 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2419 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2420 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2421 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2423 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2424 if (payload_len < 0)
2426 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2427 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2429 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2431 rc = mwl8k_post_cmd(hw, &cmd->header);
2438 * CMD_SET_RTS_THRESHOLD.
2440 struct mwl8k_cmd_set_rts_threshold {
2441 struct mwl8k_cmd_pkt header;
2444 } __attribute__((packed));
2447 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
2449 struct mwl8k_cmd_set_rts_threshold *cmd;
2452 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2456 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2457 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2458 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2459 cmd->threshold = cpu_to_le16(rts_thresh);
2461 rc = mwl8k_post_cmd(hw, &cmd->header);
2470 struct mwl8k_cmd_set_slot {
2471 struct mwl8k_cmd_pkt header;
2474 } __attribute__((packed));
2476 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
2478 struct mwl8k_cmd_set_slot *cmd;
2481 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2485 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2486 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2487 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2488 cmd->short_slot = short_slot_time;
2490 rc = mwl8k_post_cmd(hw, &cmd->header);
2497 * CMD_SET_EDCA_PARAMS.
2499 struct mwl8k_cmd_set_edca_params {
2500 struct mwl8k_cmd_pkt header;
2502 /* See MWL8K_SET_EDCA_XXX below */
2505 /* TX opportunity in units of 32 us */
2510 /* Log exponent of max contention period: 0...15 */
2513 /* Log exponent of min contention period: 0...15 */
2516 /* Adaptive interframe spacing in units of 32us */
2519 /* TX queue to configure */
2523 /* Log exponent of max contention period: 0...15 */
2526 /* Log exponent of min contention period: 0...15 */
2529 /* Adaptive interframe spacing in units of 32us */
2532 /* TX queue to configure */
2536 } __attribute__((packed));
2538 #define MWL8K_SET_EDCA_CW 0x01
2539 #define MWL8K_SET_EDCA_TXOP 0x02
2540 #define MWL8K_SET_EDCA_AIFS 0x04
2542 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2543 MWL8K_SET_EDCA_TXOP | \
2544 MWL8K_SET_EDCA_AIFS)
2547 mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2548 __u16 cw_min, __u16 cw_max,
2549 __u8 aifs, __u16 txop)
2551 struct mwl8k_priv *priv = hw->priv;
2552 struct mwl8k_cmd_set_edca_params *cmd;
2555 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2559 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2560 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2561 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2562 cmd->txop = cpu_to_le16(txop);
2564 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2565 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2566 cmd->ap.aifs = aifs;
2569 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2570 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2571 cmd->sta.aifs = aifs;
2572 cmd->sta.txq = qnum;
2575 rc = mwl8k_post_cmd(hw, &cmd->header);
2584 struct mwl8k_cmd_set_wmm_mode {
2585 struct mwl8k_cmd_pkt header;
2587 } __attribute__((packed));
2589 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
2591 struct mwl8k_priv *priv = hw->priv;
2592 struct mwl8k_cmd_set_wmm_mode *cmd;
2595 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2599 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2600 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2601 cmd->action = cpu_to_le16(!!enable);
2603 rc = mwl8k_post_cmd(hw, &cmd->header);
2607 priv->wmm_enabled = enable;
2615 struct mwl8k_cmd_mimo_config {
2616 struct mwl8k_cmd_pkt header;
2618 __u8 rx_antenna_map;
2619 __u8 tx_antenna_map;
2620 } __attribute__((packed));
2622 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2624 struct mwl8k_cmd_mimo_config *cmd;
2627 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2631 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2632 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2633 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2634 cmd->rx_antenna_map = rx;
2635 cmd->tx_antenna_map = tx;
2637 rc = mwl8k_post_cmd(hw, &cmd->header);
2644 * CMD_USE_FIXED_RATE (STA version).
2646 struct mwl8k_cmd_use_fixed_rate_sta {
2647 struct mwl8k_cmd_pkt header;
2649 __le32 allow_rate_drop;
2653 __le32 enable_retry;
2660 } __attribute__((packed));
2662 #define MWL8K_USE_AUTO_RATE 0x0002
2663 #define MWL8K_UCAST_RATE 0
2665 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
2667 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
2670 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2674 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2675 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2676 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2677 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
2679 rc = mwl8k_post_cmd(hw, &cmd->header);
2686 * CMD_USE_FIXED_RATE (AP version).
2688 struct mwl8k_cmd_use_fixed_rate_ap {
2689 struct mwl8k_cmd_pkt header;
2691 __le32 allow_rate_drop;
2693 struct mwl8k_rate_entry_ap {
2695 __le32 enable_retry;
2700 u8 multicast_rate_type;
2702 } __attribute__((packed));
2705 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2707 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2710 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2714 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2715 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2716 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2717 cmd->multicast_rate = mcast;
2718 cmd->management_rate = mgmt;
2720 rc = mwl8k_post_cmd(hw, &cmd->header);
2727 * CMD_ENABLE_SNIFFER.
2729 struct mwl8k_cmd_enable_sniffer {
2730 struct mwl8k_cmd_pkt header;
2732 } __attribute__((packed));
2734 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2736 struct mwl8k_cmd_enable_sniffer *cmd;
2739 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2743 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2744 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2745 cmd->action = cpu_to_le32(!!enable);
2747 rc = mwl8k_post_cmd(hw, &cmd->header);
2756 struct mwl8k_cmd_set_mac_addr {
2757 struct mwl8k_cmd_pkt header;
2761 __u8 mac_addr[ETH_ALEN];
2763 __u8 mac_addr[ETH_ALEN];
2765 } __attribute__((packed));
2767 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2768 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
2769 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
2770 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
2772 static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
2773 struct ieee80211_vif *vif, u8 *mac)
2775 struct mwl8k_priv *priv = hw->priv;
2776 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
2777 struct mwl8k_cmd_set_mac_addr *cmd;
2781 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
2782 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
2783 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
2784 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
2786 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
2787 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
2788 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
2789 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
2791 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
2794 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2798 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2799 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2801 cmd->mbss.mac_type = cpu_to_le16(mac_type);
2802 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2804 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2807 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2814 * CMD_SET_RATEADAPT_MODE.
2816 struct mwl8k_cmd_set_rate_adapt_mode {
2817 struct mwl8k_cmd_pkt header;
2820 } __attribute__((packed));
2822 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2824 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2827 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2831 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2832 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2833 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2834 cmd->mode = cpu_to_le16(mode);
2836 rc = mwl8k_post_cmd(hw, &cmd->header);
2845 struct mwl8k_cmd_bss_start {
2846 struct mwl8k_cmd_pkt header;
2848 } __attribute__((packed));
2850 static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
2851 struct ieee80211_vif *vif, int enable)
2853 struct mwl8k_cmd_bss_start *cmd;
2856 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2860 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2861 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2862 cmd->enable = cpu_to_le32(enable);
2864 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2873 struct mwl8k_cmd_set_new_stn {
2874 struct mwl8k_cmd_pkt header;
2880 __le32 legacy_rates;
2883 __le16 ht_capabilities_info;
2884 __u8 mac_ht_param_info;
2886 __u8 control_channel;
2893 } __attribute__((packed));
2895 #define MWL8K_STA_ACTION_ADD 0
2896 #define MWL8K_STA_ACTION_REMOVE 2
2898 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2899 struct ieee80211_vif *vif,
2900 struct ieee80211_sta *sta)
2902 struct mwl8k_cmd_set_new_stn *cmd;
2906 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2910 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2911 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2912 cmd->aid = cpu_to_le16(sta->aid);
2913 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2914 cmd->stn_id = cpu_to_le16(sta->aid);
2915 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
2916 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
2917 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
2919 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
2920 cmd->legacy_rates = cpu_to_le32(rates);
2921 if (sta->ht_cap.ht_supported) {
2922 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2923 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2924 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2925 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2926 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2927 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2928 ((sta->ht_cap.ampdu_density & 7) << 2);
2929 cmd->is_qos_sta = 1;
2932 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2938 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2939 struct ieee80211_vif *vif)
2941 struct mwl8k_cmd_set_new_stn *cmd;
2944 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2948 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2949 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2950 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2952 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2958 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2959 struct ieee80211_vif *vif, u8 *addr)
2961 struct mwl8k_cmd_set_new_stn *cmd;
2964 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2968 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2969 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2970 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2971 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2973 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2982 struct ewc_ht_info {
2986 } __attribute__((packed));
2988 struct peer_capability_info {
2989 /* Peer type - AP vs. STA. */
2992 /* Basic 802.11 capabilities from assoc resp. */
2995 /* Set if peer supports 802.11n high throughput (HT). */
2998 /* Valid if HT is supported. */
3000 __u8 extended_ht_caps;
3001 struct ewc_ht_info ewc_info;
3003 /* Legacy rate table. Intersection of our rates and peer rates. */
3004 __u8 legacy_rates[12];
3006 /* HT rate table. Intersection of our rates and peer rates. */
3010 /* If set, interoperability mode, no proprietary extensions. */
3014 __le16 amsdu_enabled;
3015 } __attribute__((packed));
3017 struct mwl8k_cmd_update_stadb {
3018 struct mwl8k_cmd_pkt header;
3020 /* See STADB_ACTION_TYPE */
3023 /* Peer MAC address */
3024 __u8 peer_addr[ETH_ALEN];
3028 /* Peer info - valid during add/update. */
3029 struct peer_capability_info peer_info;
3030 } __attribute__((packed));
3032 #define MWL8K_STA_DB_MODIFY_ENTRY 1
3033 #define MWL8K_STA_DB_DEL_ENTRY 2
3035 /* Peer Entry flags - used to define the type of the peer node */
3036 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
3038 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
3039 struct ieee80211_vif *vif,
3040 struct ieee80211_sta *sta)
3042 struct mwl8k_cmd_update_stadb *cmd;
3043 struct peer_capability_info *p;
3047 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3051 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3052 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3053 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
3054 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
3056 p = &cmd->peer_info;
3057 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
3058 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
3059 p->ht_support = sta->ht_cap.ht_supported;
3060 p->ht_caps = sta->ht_cap.cap;
3061 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
3062 ((sta->ht_cap.ampdu_density & 7) << 2);
3063 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3064 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3066 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3067 legacy_rate_mask_to_array(p->legacy_rates, rates);
3068 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
3070 p->amsdu_enabled = 0;
3072 rc = mwl8k_post_cmd(hw, &cmd->header);
3075 return rc ? rc : p->station_id;
3078 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
3079 struct ieee80211_vif *vif, u8 *addr)
3081 struct mwl8k_cmd_update_stadb *cmd;
3084 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3088 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3089 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3090 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
3091 memcpy(cmd->peer_addr, addr, ETH_ALEN);
3093 rc = mwl8k_post_cmd(hw, &cmd->header);
3101 * Interrupt handling.
3103 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
3105 struct ieee80211_hw *hw = dev_id;
3106 struct mwl8k_priv *priv = hw->priv;
3109 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3113 if (status & MWL8K_A2H_INT_TX_DONE) {
3114 status &= ~MWL8K_A2H_INT_TX_DONE;
3115 tasklet_schedule(&priv->poll_tx_task);
3118 if (status & MWL8K_A2H_INT_RX_READY) {
3119 status &= ~MWL8K_A2H_INT_RX_READY;
3120 tasklet_schedule(&priv->poll_rx_task);
3124 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3126 if (status & MWL8K_A2H_INT_OPC_DONE) {
3127 if (priv->hostcmd_wait != NULL)
3128 complete(priv->hostcmd_wait);
3131 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
3132 if (!mutex_is_locked(&priv->fw_mutex) &&
3133 priv->radio_on && priv->pending_tx_pkts)
3134 mwl8k_tx_start(priv);
3140 static void mwl8k_tx_poll(unsigned long data)
3142 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3143 struct mwl8k_priv *priv = hw->priv;
3149 spin_lock_bh(&priv->tx_lock);
3151 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3152 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3154 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3155 complete(priv->tx_wait);
3156 priv->tx_wait = NULL;
3159 spin_unlock_bh(&priv->tx_lock);
3162 writel(~MWL8K_A2H_INT_TX_DONE,
3163 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3165 tasklet_schedule(&priv->poll_tx_task);
3169 static void mwl8k_rx_poll(unsigned long data)
3171 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3172 struct mwl8k_priv *priv = hw->priv;
3176 limit -= rxq_process(hw, 0, limit);
3177 limit -= rxq_refill(hw, 0, limit);
3180 writel(~MWL8K_A2H_INT_RX_READY,
3181 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3183 tasklet_schedule(&priv->poll_rx_task);
3189 * Core driver operations.
3191 static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3193 struct mwl8k_priv *priv = hw->priv;
3194 int index = skb_get_queue_mapping(skb);
3197 if (!priv->radio_on) {
3198 printk(KERN_DEBUG "%s: dropped TX frame since radio "
3199 "disabled\n", wiphy_name(hw->wiphy));
3201 return NETDEV_TX_OK;
3204 rc = mwl8k_txq_xmit(hw, index, skb);
3209 static int mwl8k_start(struct ieee80211_hw *hw)
3211 struct mwl8k_priv *priv = hw->priv;
3214 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
3215 IRQF_SHARED, MWL8K_NAME, hw);
3217 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3218 wiphy_name(hw->wiphy));
3222 /* Enable TX reclaim and RX tasklets. */
3223 tasklet_enable(&priv->poll_tx_task);
3224 tasklet_enable(&priv->poll_rx_task);
3226 /* Enable interrupts */
3227 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3229 rc = mwl8k_fw_lock(hw);
3231 rc = mwl8k_cmd_radio_enable(hw);
3235 rc = mwl8k_cmd_enable_sniffer(hw, 0);
3238 rc = mwl8k_cmd_set_pre_scan(hw);
3241 rc = mwl8k_cmd_set_post_scan(hw,
3242 "\x00\x00\x00\x00\x00\x00");
3246 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
3249 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
3251 mwl8k_fw_unlock(hw);
3255 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3256 free_irq(priv->pdev->irq, hw);
3257 tasklet_disable(&priv->poll_tx_task);
3258 tasklet_disable(&priv->poll_rx_task);
3264 static void mwl8k_stop(struct ieee80211_hw *hw)
3266 struct mwl8k_priv *priv = hw->priv;
3269 mwl8k_cmd_radio_disable(hw);
3271 ieee80211_stop_queues(hw);
3273 /* Disable interrupts */
3274 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3275 free_irq(priv->pdev->irq, hw);
3277 /* Stop finalize join worker */
3278 cancel_work_sync(&priv->finalize_join_worker);
3279 if (priv->beacon_skb != NULL)
3280 dev_kfree_skb(priv->beacon_skb);
3282 /* Stop TX reclaim and RX tasklets. */
3283 tasklet_disable(&priv->poll_tx_task);
3284 tasklet_disable(&priv->poll_rx_task);
3286 /* Return all skbs to mac80211 */
3287 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3288 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
3291 static int mwl8k_add_interface(struct ieee80211_hw *hw,
3292 struct ieee80211_vif *vif)
3294 struct mwl8k_priv *priv = hw->priv;
3295 struct mwl8k_vif *mwl8k_vif;
3296 u32 macids_supported;
3300 * Reject interface creation if sniffer mode is active, as
3301 * STA operation is mutually exclusive with hardware sniffer
3302 * mode. (Sniffer mode is only used on STA firmware.)
3304 if (priv->sniffer_enabled) {
3305 printk(KERN_INFO "%s: unable to create STA "
3306 "interface due to sniffer mode being enabled\n",
3307 wiphy_name(hw->wiphy));
3312 switch (vif->type) {
3313 case NL80211_IFTYPE_AP:
3314 macids_supported = priv->ap_macids_supported;
3316 case NL80211_IFTYPE_STATION:
3317 macids_supported = priv->sta_macids_supported;
3323 macid = ffs(macids_supported & ~priv->macids_used);
3327 /* Setup driver private area. */
3328 mwl8k_vif = MWL8K_VIF(vif);
3329 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
3330 mwl8k_vif->vif = vif;
3331 mwl8k_vif->macid = macid;
3332 mwl8k_vif->seqno = 0;
3334 /* Set the mac address. */
3335 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
3338 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3340 priv->macids_used |= 1 << mwl8k_vif->macid;
3341 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
3346 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
3347 struct ieee80211_vif *vif)
3349 struct mwl8k_priv *priv = hw->priv;
3350 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3353 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3355 mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
3357 priv->macids_used &= ~(1 << mwl8k_vif->macid);
3358 list_del(&mwl8k_vif->list);
3361 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
3363 struct ieee80211_conf *conf = &hw->conf;
3364 struct mwl8k_priv *priv = hw->priv;
3367 if (conf->flags & IEEE80211_CONF_IDLE) {
3368 mwl8k_cmd_radio_disable(hw);
3372 rc = mwl8k_fw_lock(hw);
3376 rc = mwl8k_cmd_radio_enable(hw);
3380 rc = mwl8k_cmd_set_rf_channel(hw, conf);
3384 if (conf->power_level > 18)
3385 conf->power_level = 18;
3386 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
3391 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3393 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3395 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3399 mwl8k_fw_unlock(hw);
3405 mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3406 struct ieee80211_bss_conf *info, u32 changed)
3408 struct mwl8k_priv *priv = hw->priv;
3409 u32 ap_legacy_rates;
3410 u8 ap_mcs_rates[16];
3413 if (mwl8k_fw_lock(hw))
3417 * No need to capture a beacon if we're no longer associated.
3419 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3420 priv->capture_beacon = false;
3423 * Get the AP's legacy and MCS rates.
3425 if (vif->bss_conf.assoc) {
3426 struct ieee80211_sta *ap;
3430 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
3436 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
3437 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3440 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3442 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
3447 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
3448 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
3452 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
3457 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3458 rc = mwl8k_set_radio_preamble(hw,
3459 vif->bss_conf.use_short_preamble);
3464 if (changed & BSS_CHANGED_ERP_SLOT) {
3465 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
3470 if (vif->bss_conf.assoc &&
3471 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3473 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
3478 if (vif->bss_conf.assoc &&
3479 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
3481 * Finalize the join. Tell rx handler to process
3482 * next beacon from our BSSID.
3484 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
3485 priv->capture_beacon = true;
3489 mwl8k_fw_unlock(hw);
3493 mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3494 struct ieee80211_bss_conf *info, u32 changed)
3498 if (mwl8k_fw_lock(hw))
3501 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3502 rc = mwl8k_set_radio_preamble(hw,
3503 vif->bss_conf.use_short_preamble);
3508 if (changed & BSS_CHANGED_BASIC_RATES) {
3513 * Use lowest supported basic rate for multicasts
3514 * and management frames (such as probe responses --
3515 * beacons will always go out at 1 Mb/s).
3517 idx = ffs(vif->bss_conf.basic_rates);
3521 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3522 rate = mwl8k_rates_24[idx].hw_value;
3524 rate = mwl8k_rates_50[idx].hw_value;
3526 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3529 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3530 struct sk_buff *skb;
3532 skb = ieee80211_beacon_get(hw, vif);
3534 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
3539 if (changed & BSS_CHANGED_BEACON_ENABLED)
3540 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
3543 mwl8k_fw_unlock(hw);
3547 mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3548 struct ieee80211_bss_conf *info, u32 changed)
3550 struct mwl8k_priv *priv = hw->priv;
3553 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3555 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3558 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3559 int mc_count, struct dev_addr_list *mclist)
3561 struct mwl8k_cmd_pkt *cmd;
3564 * Synthesize and return a command packet that programs the
3565 * hardware multicast address filter. At this point we don't
3566 * know whether FIF_ALLMULTI is being requested, but if it is,
3567 * we'll end up throwing this packet away and creating a new
3568 * one in mwl8k_configure_filter().
3570 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
3572 return (unsigned long)cmd;
3576 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3577 unsigned int changed_flags,
3578 unsigned int *total_flags)
3580 struct mwl8k_priv *priv = hw->priv;
3583 * Hardware sniffer mode is mutually exclusive with STA
3584 * operation, so refuse to enable sniffer mode if a STA
3585 * interface is active.
3587 if (!list_empty(&priv->vif_list)) {
3588 if (net_ratelimit())
3589 printk(KERN_INFO "%s: not enabling sniffer "
3590 "mode because STA interface is active\n",
3591 wiphy_name(hw->wiphy));
3595 if (!priv->sniffer_enabled) {
3596 if (mwl8k_cmd_enable_sniffer(hw, 1))
3598 priv->sniffer_enabled = true;
3601 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3602 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3608 static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
3610 if (!list_empty(&priv->vif_list))
3611 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
3616 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3617 unsigned int changed_flags,
3618 unsigned int *total_flags,
3621 struct mwl8k_priv *priv = hw->priv;
3622 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3625 * AP firmware doesn't allow fine-grained control over
3626 * the receive filter.
3629 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3635 * Enable hardware sniffer mode if FIF_CONTROL or
3636 * FIF_OTHER_BSS is requested.
3638 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3639 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3644 /* Clear unsupported feature flags */
3645 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3647 if (mwl8k_fw_lock(hw)) {
3652 if (priv->sniffer_enabled) {
3653 mwl8k_cmd_enable_sniffer(hw, 0);
3654 priv->sniffer_enabled = false;
3657 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
3658 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3660 * Disable the BSS filter.
3662 mwl8k_cmd_set_pre_scan(hw);
3664 struct mwl8k_vif *mwl8k_vif;
3668 * Enable the BSS filter.
3670 * If there is an active STA interface, use that
3671 * interface's BSSID, otherwise use a dummy one
3672 * (where the OUI part needs to be nonzero for
3673 * the BSSID to be accepted by POST_SCAN).
3675 mwl8k_vif = mwl8k_first_vif(priv);
3676 if (mwl8k_vif != NULL)
3677 bssid = mwl8k_vif->vif->bss_conf.bssid;
3679 bssid = "\x01\x00\x00\x00\x00\x00";
3681 mwl8k_cmd_set_post_scan(hw, bssid);
3686 * If FIF_ALLMULTI is being requested, throw away the command
3687 * packet that ->prepare_multicast() built and replace it with
3688 * a command packet that enables reception of all multicast
3691 if (*total_flags & FIF_ALLMULTI) {
3693 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3697 mwl8k_post_cmd(hw, cmd);
3701 mwl8k_fw_unlock(hw);
3704 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3706 return mwl8k_cmd_set_rts_threshold(hw, value);
3709 struct mwl8k_sta_notify_item
3711 struct list_head list;
3712 struct ieee80211_vif *vif;
3713 enum sta_notify_cmd cmd;
3714 struct ieee80211_sta sta;
3718 mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3720 struct mwl8k_priv *priv = hw->priv;
3723 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3725 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3728 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3730 struct ieee80211_sta *sta;
3733 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3735 MWL8K_STA(sta)->peer_id = rc;
3738 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3739 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3740 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3741 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3742 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3743 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3747 static void mwl8k_sta_notify_worker(struct work_struct *work)
3749 struct mwl8k_priv *priv =
3750 container_of(work, struct mwl8k_priv, sta_notify_worker);
3751 struct ieee80211_hw *hw = priv->hw;
3753 spin_lock_bh(&priv->sta_notify_list_lock);
3754 while (!list_empty(&priv->sta_notify_list)) {
3755 struct mwl8k_sta_notify_item *s;
3757 s = list_entry(priv->sta_notify_list.next,
3758 struct mwl8k_sta_notify_item, list);
3761 spin_unlock_bh(&priv->sta_notify_list_lock);
3763 mwl8k_do_sta_notify(hw, s);
3766 spin_lock_bh(&priv->sta_notify_list_lock);
3768 spin_unlock_bh(&priv->sta_notify_list_lock);
3772 mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3773 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3775 struct mwl8k_priv *priv = hw->priv;
3776 struct mwl8k_sta_notify_item *s;
3778 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3781 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3787 spin_lock(&priv->sta_notify_list_lock);
3788 list_add_tail(&s->list, &priv->sta_notify_list);
3789 spin_unlock(&priv->sta_notify_list_lock);
3791 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3795 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3796 const struct ieee80211_tx_queue_params *params)
3798 struct mwl8k_priv *priv = hw->priv;
3801 rc = mwl8k_fw_lock(hw);
3803 if (!priv->wmm_enabled)
3804 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
3807 rc = mwl8k_cmd_set_edca_params(hw, queue,
3813 mwl8k_fw_unlock(hw);
3819 static int mwl8k_get_stats(struct ieee80211_hw *hw,
3820 struct ieee80211_low_level_stats *stats)
3822 return mwl8k_cmd_get_stat(hw, stats);
3826 mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3827 enum ieee80211_ampdu_mlme_action action,
3828 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3831 case IEEE80211_AMPDU_RX_START:
3832 case IEEE80211_AMPDU_RX_STOP:
3833 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3841 static const struct ieee80211_ops mwl8k_ops = {
3843 .start = mwl8k_start,
3845 .add_interface = mwl8k_add_interface,
3846 .remove_interface = mwl8k_remove_interface,
3847 .config = mwl8k_config,
3848 .bss_info_changed = mwl8k_bss_info_changed,
3849 .prepare_multicast = mwl8k_prepare_multicast,
3850 .configure_filter = mwl8k_configure_filter,
3851 .set_rts_threshold = mwl8k_set_rts_threshold,
3852 .sta_notify = mwl8k_sta_notify,
3853 .conf_tx = mwl8k_conf_tx,
3854 .get_stats = mwl8k_get_stats,
3855 .ampdu_action = mwl8k_ampdu_action,
3858 static void mwl8k_finalize_join_worker(struct work_struct *work)
3860 struct mwl8k_priv *priv =
3861 container_of(work, struct mwl8k_priv, finalize_join_worker);
3862 struct sk_buff *skb = priv->beacon_skb;
3863 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3864 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
3865 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
3866 mgmt->u.beacon.variable, len);
3867 int dtim_period = 1;
3869 if (tim && tim[1] >= 2)
3870 dtim_period = tim[3];
3872 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
3875 priv->beacon_skb = NULL;
3884 static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3886 .part_name = "88w8363",
3887 .helper_image = "mwl8k/helper_8363.fw",
3888 .fw_image = "mwl8k/fmimage_8363.fw",
3891 .part_name = "88w8687",
3892 .helper_image = "mwl8k/helper_8687.fw",
3893 .fw_image = "mwl8k/fmimage_8687.fw",
3896 .part_name = "88w8366",
3897 .helper_image = "mwl8k/helper_8366.fw",
3898 .fw_image = "mwl8k/fmimage_8366.fw",
3899 .ap_rxd_ops = &rxd_8366_ap_ops,
3903 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3904 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3905 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3906 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3907 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3908 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3910 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
3911 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3912 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
3913 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3914 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3915 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3916 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
3919 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3921 static int __devinit mwl8k_probe(struct pci_dev *pdev,
3922 const struct pci_device_id *id)
3924 static int printed_version = 0;
3925 struct ieee80211_hw *hw;
3926 struct mwl8k_priv *priv;
3930 if (!printed_version) {
3931 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3932 printed_version = 1;
3936 rc = pci_enable_device(pdev);
3938 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3943 rc = pci_request_regions(pdev, MWL8K_NAME);
3945 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3947 goto err_disable_device;
3950 pci_set_master(pdev);
3953 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3955 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3960 SET_IEEE80211_DEV(hw, &pdev->dev);
3961 pci_set_drvdata(pdev, hw);
3966 priv->device_info = &mwl8k_info_tbl[id->driver_data];
3969 priv->sram = pci_iomap(pdev, 0, 0x10000);
3970 if (priv->sram == NULL) {
3971 printk(KERN_ERR "%s: Cannot map device SRAM\n",
3972 wiphy_name(hw->wiphy));
3977 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3978 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3980 priv->regs = pci_iomap(pdev, 1, 0x10000);
3981 if (priv->regs == NULL) {
3982 priv->regs = pci_iomap(pdev, 2, 0x10000);
3983 if (priv->regs == NULL) {
3984 printk(KERN_ERR "%s: Cannot map device registers\n",
3985 wiphy_name(hw->wiphy));
3991 /* Reset firmware and hardware */
3992 mwl8k_hw_reset(priv);
3994 /* Ask userland hotplug daemon for the device firmware */
3995 rc = mwl8k_request_firmware(priv);
3997 printk(KERN_ERR "%s: Firmware files not found\n",
3998 wiphy_name(hw->wiphy));
3999 goto err_stop_firmware;
4002 /* Load firmware into hardware */
4003 rc = mwl8k_load_firmware(hw);
4005 printk(KERN_ERR "%s: Cannot start firmware\n",
4006 wiphy_name(hw->wiphy));
4007 goto err_stop_firmware;
4010 /* Reclaim memory once firmware is successfully loaded */
4011 mwl8k_release_firmware(priv);
4015 priv->rxd_ops = priv->device_info->ap_rxd_ops;
4016 if (priv->rxd_ops == NULL) {
4017 printk(KERN_ERR "%s: Driver does not have AP "
4018 "firmware image support for this hardware\n",
4019 wiphy_name(hw->wiphy));
4020 goto err_stop_firmware;
4023 priv->rxd_ops = &rxd_sta_ops;
4026 priv->sniffer_enabled = false;
4027 priv->wmm_enabled = false;
4028 priv->pending_tx_pkts = 0;
4032 * Extra headroom is the size of the required DMA header
4033 * minus the size of the smallest 802.11 frame (CTS frame).
4035 hw->extra_tx_headroom =
4036 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
4038 hw->channel_change_time = 10;
4040 hw->queues = MWL8K_TX_QUEUES;
4042 /* Set rssi and noise values to dBm */
4043 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
4044 hw->vif_data_size = sizeof(struct mwl8k_vif);
4045 hw->sta_data_size = sizeof(struct mwl8k_sta);
4047 priv->macids_used = 0;
4048 INIT_LIST_HEAD(&priv->vif_list);
4050 /* Set default radio state and preamble */
4052 priv->radio_short_preamble = 0;
4054 /* Station database handling */
4055 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
4056 spin_lock_init(&priv->sta_notify_list_lock);
4057 INIT_LIST_HEAD(&priv->sta_notify_list);
4059 /* Finalize join worker */
4060 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
4062 /* TX reclaim and RX tasklets. */
4063 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
4064 tasklet_disable(&priv->poll_tx_task);
4065 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
4066 tasklet_disable(&priv->poll_rx_task);
4068 /* Power management cookie */
4069 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
4070 if (priv->cookie == NULL)
4071 goto err_stop_firmware;
4073 rc = mwl8k_rxq_init(hw, 0);
4075 goto err_free_cookie;
4076 rxq_refill(hw, 0, INT_MAX);
4078 mutex_init(&priv->fw_mutex);
4079 priv->fw_mutex_owner = NULL;
4080 priv->fw_mutex_depth = 0;
4081 priv->hostcmd_wait = NULL;
4083 spin_lock_init(&priv->tx_lock);
4085 priv->tx_wait = NULL;
4087 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
4088 rc = mwl8k_txq_init(hw, i);
4090 goto err_free_queues;
4093 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4094 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4095 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
4096 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
4097 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4099 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
4100 IRQF_SHARED, MWL8K_NAME, hw);
4102 printk(KERN_ERR "%s: failed to register IRQ handler\n",
4103 wiphy_name(hw->wiphy));
4104 goto err_free_queues;
4108 * Temporarily enable interrupts. Initial firmware host
4109 * commands use interrupts and avoid polling. Disable
4110 * interrupts when done.
4112 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4114 /* Get config data, mac addrs etc */
4116 rc = mwl8k_cmd_get_hw_spec_ap(hw);
4118 rc = mwl8k_cmd_set_hw_spec(hw);
4120 rc = mwl8k_cmd_get_hw_spec_sta(hw);
4123 printk(KERN_ERR "%s: Cannot initialise firmware\n",
4124 wiphy_name(hw->wiphy));
4128 hw->wiphy->interface_modes = 0;
4129 if (priv->ap_macids_supported)
4130 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
4131 if (priv->sta_macids_supported)
4132 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
4135 /* Turn radio off */
4136 rc = mwl8k_cmd_radio_disable(hw);
4138 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
4142 /* Clear MAC address */
4143 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
4145 printk(KERN_ERR "%s: Cannot clear MAC address\n",
4146 wiphy_name(hw->wiphy));
4150 /* Disable interrupts */
4151 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4152 free_irq(priv->pdev->irq, hw);
4154 rc = ieee80211_register_hw(hw);
4156 printk(KERN_ERR "%s: Cannot register device\n",
4157 wiphy_name(hw->wiphy));
4158 goto err_free_queues;
4161 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
4162 wiphy_name(hw->wiphy), priv->device_info->part_name,
4163 priv->hw_rev, hw->wiphy->perm_addr,
4164 priv->ap_fw ? "AP" : "STA",
4165 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4166 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
4171 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4172 free_irq(priv->pdev->irq, hw);
4175 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4176 mwl8k_txq_deinit(hw, i);
4177 mwl8k_rxq_deinit(hw, 0);
4180 if (priv->cookie != NULL)
4181 pci_free_consistent(priv->pdev, 4,
4182 priv->cookie, priv->cookie_dma);
4185 mwl8k_hw_reset(priv);
4186 mwl8k_release_firmware(priv);
4189 if (priv->regs != NULL)
4190 pci_iounmap(pdev, priv->regs);
4192 if (priv->sram != NULL)
4193 pci_iounmap(pdev, priv->sram);
4195 pci_set_drvdata(pdev, NULL);
4196 ieee80211_free_hw(hw);
4199 pci_release_regions(pdev);
4202 pci_disable_device(pdev);
4207 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
4209 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4212 static void __devexit mwl8k_remove(struct pci_dev *pdev)
4214 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4215 struct mwl8k_priv *priv;
4222 ieee80211_stop_queues(hw);
4224 ieee80211_unregister_hw(hw);
4226 /* Remove TX reclaim and RX tasklets. */
4227 tasklet_kill(&priv->poll_tx_task);
4228 tasklet_kill(&priv->poll_rx_task);
4231 mwl8k_hw_reset(priv);
4233 /* Return all skbs to mac80211 */
4234 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4235 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
4237 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4238 mwl8k_txq_deinit(hw, i);
4240 mwl8k_rxq_deinit(hw, 0);
4242 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
4244 pci_iounmap(pdev, priv->regs);
4245 pci_iounmap(pdev, priv->sram);
4246 pci_set_drvdata(pdev, NULL);
4247 ieee80211_free_hw(hw);
4248 pci_release_regions(pdev);
4249 pci_disable_device(pdev);
4252 static struct pci_driver mwl8k_driver = {
4254 .id_table = mwl8k_pci_id_table,
4255 .probe = mwl8k_probe,
4256 .remove = __devexit_p(mwl8k_remove),
4257 .shutdown = __devexit_p(mwl8k_shutdown),
4260 static int __init mwl8k_init(void)
4262 return pci_register_driver(&mwl8k_driver);
4265 static void __exit mwl8k_exit(void)
4267 pci_unregister_driver(&mwl8k_driver);
4270 module_init(mwl8k_init);
4271 module_exit(mwl8k_exit);
4273 MODULE_DESCRIPTION(MWL8K_DESC);
4274 MODULE_VERSION(MWL8K_VERSION);
4275 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4276 MODULE_LICENSE("GPL");