2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008-2009 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.11"
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 */
122 struct ieee80211_tx_queue_stats stats;
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];
148 /* firmware access */
149 struct mutex fw_mutex;
150 struct task_struct *fw_mutex_owner;
152 struct completion *hostcmd_wait;
154 /* lock held over TX and TX reap */
157 /* TX quiesce completion, protected by fw_mutex and tx_lock */
158 struct completion *tx_wait;
160 struct ieee80211_vif *vif;
162 /* power management status cookie from firmware */
164 dma_addr_t cookie_dma;
171 * Running count of TX packets in flight, to avoid
172 * iterating over the transmit rings each time.
176 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
177 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
180 bool radio_short_preamble;
181 bool sniffer_enabled;
184 struct work_struct sta_notify_worker;
185 spinlock_t sta_notify_list_lock;
186 struct list_head sta_notify_list;
188 /* XXX need to convert this to handle multiple interfaces */
190 u8 capture_bssid[ETH_ALEN];
191 struct sk_buff *beacon_skb;
194 * This FJ worker has to be global as it is scheduled from the
195 * RX handler. At this point we don't know which interface it
196 * belongs to until the list of bssids waiting to complete join
199 struct work_struct finalize_join_worker;
201 /* Tasklet to perform TX reclaim. */
202 struct tasklet_struct poll_tx_task;
204 /* Tasklet to perform RX. */
205 struct tasklet_struct poll_rx_task;
208 /* Per interface specific private data */
210 /* Non AMPDU sequence number assigned by driver. */
213 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
216 /* Index into station database. Returned by UPDATE_STADB. */
219 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
221 static const struct ieee80211_channel mwl8k_channels_24[] = {
222 { .center_freq = 2412, .hw_value = 1, },
223 { .center_freq = 2417, .hw_value = 2, },
224 { .center_freq = 2422, .hw_value = 3, },
225 { .center_freq = 2427, .hw_value = 4, },
226 { .center_freq = 2432, .hw_value = 5, },
227 { .center_freq = 2437, .hw_value = 6, },
228 { .center_freq = 2442, .hw_value = 7, },
229 { .center_freq = 2447, .hw_value = 8, },
230 { .center_freq = 2452, .hw_value = 9, },
231 { .center_freq = 2457, .hw_value = 10, },
232 { .center_freq = 2462, .hw_value = 11, },
233 { .center_freq = 2467, .hw_value = 12, },
234 { .center_freq = 2472, .hw_value = 13, },
235 { .center_freq = 2484, .hw_value = 14, },
238 static const struct ieee80211_rate mwl8k_rates_24[] = {
239 { .bitrate = 10, .hw_value = 2, },
240 { .bitrate = 20, .hw_value = 4, },
241 { .bitrate = 55, .hw_value = 11, },
242 { .bitrate = 110, .hw_value = 22, },
243 { .bitrate = 220, .hw_value = 44, },
244 { .bitrate = 60, .hw_value = 12, },
245 { .bitrate = 90, .hw_value = 18, },
246 { .bitrate = 120, .hw_value = 24, },
247 { .bitrate = 180, .hw_value = 36, },
248 { .bitrate = 240, .hw_value = 48, },
249 { .bitrate = 360, .hw_value = 72, },
250 { .bitrate = 480, .hw_value = 96, },
251 { .bitrate = 540, .hw_value = 108, },
252 { .bitrate = 720, .hw_value = 144, },
255 /* Set or get info from Firmware */
256 #define MWL8K_CMD_SET 0x0001
257 #define MWL8K_CMD_GET 0x0000
259 /* Firmware command codes */
260 #define MWL8K_CMD_CODE_DNLD 0x0001
261 #define MWL8K_CMD_GET_HW_SPEC 0x0003
262 #define MWL8K_CMD_SET_HW_SPEC 0x0004
263 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
264 #define MWL8K_CMD_GET_STAT 0x0014
265 #define MWL8K_CMD_RADIO_CONTROL 0x001c
266 #define MWL8K_CMD_RF_TX_POWER 0x001e
267 #define MWL8K_CMD_RF_ANTENNA 0x0020
268 #define MWL8K_CMD_SET_BEACON 0x0100
269 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
270 #define MWL8K_CMD_SET_POST_SCAN 0x0108
271 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
272 #define MWL8K_CMD_SET_AID 0x010d
273 #define MWL8K_CMD_SET_RATE 0x0110
274 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
275 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
276 #define MWL8K_CMD_SET_SLOT 0x0114
277 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
278 #define MWL8K_CMD_SET_WMM_MODE 0x0123
279 #define MWL8K_CMD_MIMO_CONFIG 0x0125
280 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
281 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
282 #define MWL8K_CMD_SET_MAC_ADDR 0x0202
283 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
284 #define MWL8K_CMD_BSS_START 0x1100
285 #define MWL8K_CMD_SET_NEW_STN 0x1111
286 #define MWL8K_CMD_UPDATE_STADB 0x1123
288 static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
290 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
291 snprintf(buf, bufsize, "%s", #x);\
294 switch (cmd & ~0x8000) {
295 MWL8K_CMDNAME(CODE_DNLD);
296 MWL8K_CMDNAME(GET_HW_SPEC);
297 MWL8K_CMDNAME(SET_HW_SPEC);
298 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
299 MWL8K_CMDNAME(GET_STAT);
300 MWL8K_CMDNAME(RADIO_CONTROL);
301 MWL8K_CMDNAME(RF_TX_POWER);
302 MWL8K_CMDNAME(RF_ANTENNA);
303 MWL8K_CMDNAME(SET_BEACON);
304 MWL8K_CMDNAME(SET_PRE_SCAN);
305 MWL8K_CMDNAME(SET_POST_SCAN);
306 MWL8K_CMDNAME(SET_RF_CHANNEL);
307 MWL8K_CMDNAME(SET_AID);
308 MWL8K_CMDNAME(SET_RATE);
309 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
310 MWL8K_CMDNAME(RTS_THRESHOLD);
311 MWL8K_CMDNAME(SET_SLOT);
312 MWL8K_CMDNAME(SET_EDCA_PARAMS);
313 MWL8K_CMDNAME(SET_WMM_MODE);
314 MWL8K_CMDNAME(MIMO_CONFIG);
315 MWL8K_CMDNAME(USE_FIXED_RATE);
316 MWL8K_CMDNAME(ENABLE_SNIFFER);
317 MWL8K_CMDNAME(SET_MAC_ADDR);
318 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
319 MWL8K_CMDNAME(BSS_START);
320 MWL8K_CMDNAME(SET_NEW_STN);
321 MWL8K_CMDNAME(UPDATE_STADB);
323 snprintf(buf, bufsize, "0x%x", cmd);
330 /* Hardware and firmware reset */
331 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
333 iowrite32(MWL8K_H2A_INT_RESET,
334 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
335 iowrite32(MWL8K_H2A_INT_RESET,
336 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
340 /* Release fw image */
341 static void mwl8k_release_fw(struct firmware **fw)
345 release_firmware(*fw);
349 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
351 mwl8k_release_fw(&priv->fw_ucode);
352 mwl8k_release_fw(&priv->fw_helper);
355 /* Request fw image */
356 static int mwl8k_request_fw(struct mwl8k_priv *priv,
357 const char *fname, struct firmware **fw)
359 /* release current image */
361 mwl8k_release_fw(fw);
363 return request_firmware((const struct firmware **)fw,
364 fname, &priv->pdev->dev);
367 static int mwl8k_request_firmware(struct mwl8k_priv *priv)
369 struct mwl8k_device_info *di = priv->device_info;
372 if (di->helper_image != NULL) {
373 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
375 printk(KERN_ERR "%s: Error requesting helper "
376 "firmware file %s\n", pci_name(priv->pdev),
382 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
384 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
385 pci_name(priv->pdev), di->fw_image);
386 mwl8k_release_fw(&priv->fw_helper);
393 struct mwl8k_cmd_pkt {
399 } __attribute__((packed));
405 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
407 void __iomem *regs = priv->regs;
411 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
412 if (pci_dma_mapping_error(priv->pdev, dma_addr))
415 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
416 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
417 iowrite32(MWL8K_H2A_INT_DOORBELL,
418 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
419 iowrite32(MWL8K_H2A_INT_DUMMY,
420 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
426 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
427 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
428 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
436 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
438 return loops ? 0 : -ETIMEDOUT;
441 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
442 const u8 *data, size_t length)
444 struct mwl8k_cmd_pkt *cmd;
448 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
452 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
458 int block_size = length > 256 ? 256 : length;
460 memcpy(cmd->payload, data + done, block_size);
461 cmd->length = cpu_to_le16(block_size);
463 rc = mwl8k_send_fw_load_cmd(priv, cmd,
464 sizeof(*cmd) + block_size);
469 length -= block_size;
474 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
482 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
483 const u8 *data, size_t length)
485 unsigned char *buffer;
486 int may_continue, rc = 0;
487 u32 done, prev_block_size;
489 buffer = kmalloc(1024, GFP_KERNEL);
496 while (may_continue > 0) {
499 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
500 if (block_size & 1) {
504 done += prev_block_size;
505 length -= prev_block_size;
508 if (block_size > 1024 || block_size > length) {
518 if (block_size == 0) {
525 prev_block_size = block_size;
526 memcpy(buffer, data + done, block_size);
528 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
533 if (!rc && length != 0)
541 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
543 struct mwl8k_priv *priv = hw->priv;
544 struct firmware *fw = priv->fw_ucode;
548 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
549 struct firmware *helper = priv->fw_helper;
551 if (helper == NULL) {
552 printk(KERN_ERR "%s: helper image needed but none "
553 "given\n", pci_name(priv->pdev));
557 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
559 printk(KERN_ERR "%s: unable to load firmware "
560 "helper image\n", pci_name(priv->pdev));
565 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
567 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
571 printk(KERN_ERR "%s: unable to load firmware image\n",
572 pci_name(priv->pdev));
576 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
582 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
583 if (ready_code == MWL8K_FWAP_READY) {
586 } else if (ready_code == MWL8K_FWSTA_READY) {
595 return loops ? 0 : -ETIMEDOUT;
599 /* DMA header used by firmware and hardware. */
600 struct mwl8k_dma_data {
602 struct ieee80211_hdr wh;
604 } __attribute__((packed));
606 /* Routines to add/remove DMA header from skb. */
607 static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
609 struct mwl8k_dma_data *tr;
612 tr = (struct mwl8k_dma_data *)skb->data;
613 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
615 if (hdrlen != sizeof(tr->wh)) {
616 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
617 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
618 *((__le16 *)(tr->data - 2)) = qos;
620 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
624 if (hdrlen != sizeof(*tr))
625 skb_pull(skb, sizeof(*tr) - hdrlen);
628 static inline void mwl8k_add_dma_header(struct sk_buff *skb)
630 struct ieee80211_hdr *wh;
632 struct mwl8k_dma_data *tr;
635 * Add a firmware DMA header; the firmware requires that we
636 * present a 2-byte payload length followed by a 4-address
637 * header (without QoS field), followed (optionally) by any
638 * WEP/ExtIV header (but only filled in for CCMP).
640 wh = (struct ieee80211_hdr *)skb->data;
642 hdrlen = ieee80211_hdrlen(wh->frame_control);
643 if (hdrlen != sizeof(*tr))
644 skb_push(skb, sizeof(*tr) - hdrlen);
646 if (ieee80211_is_data_qos(wh->frame_control))
649 tr = (struct mwl8k_dma_data *)skb->data;
651 memmove(&tr->wh, wh, hdrlen);
652 if (hdrlen != sizeof(tr->wh))
653 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
656 * Firmware length is the length of the fully formed "802.11
657 * payload". That is, everything except for the 802.11 header.
658 * This includes all crypto material including the MIC.
660 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
665 * Packet reception for 88w8366 AP firmware.
667 struct mwl8k_rxd_8366_ap {
671 __le32 pkt_phys_addr;
672 __le32 next_rxd_phys_addr;
676 __le32 hw_noise_floor_info;
683 } __attribute__((packed));
685 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
686 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
687 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
689 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
691 static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
693 struct mwl8k_rxd_8366_ap *rxd = _rxd;
695 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
696 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
699 static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
701 struct mwl8k_rxd_8366_ap *rxd = _rxd;
703 rxd->pkt_len = cpu_to_le16(len);
704 rxd->pkt_phys_addr = cpu_to_le32(addr);
710 mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
713 struct mwl8k_rxd_8366_ap *rxd = _rxd;
715 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
719 memset(status, 0, sizeof(*status));
721 status->signal = -rxd->rssi;
722 status->noise = -rxd->noise_floor;
724 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
725 status->flag |= RX_FLAG_HT;
726 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
727 status->flag |= RX_FLAG_40MHZ;
728 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
732 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
733 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
734 status->rate_idx = i;
740 status->band = IEEE80211_BAND_2GHZ;
741 status->freq = ieee80211_channel_to_frequency(rxd->channel);
743 *qos = rxd->qos_control;
745 return le16_to_cpu(rxd->pkt_len);
748 static struct rxd_ops rxd_8366_ap_ops = {
749 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
750 .rxd_init = mwl8k_rxd_8366_ap_init,
751 .rxd_refill = mwl8k_rxd_8366_ap_refill,
752 .rxd_process = mwl8k_rxd_8366_ap_process,
756 * Packet reception for STA firmware.
758 struct mwl8k_rxd_sta {
762 __le32 pkt_phys_addr;
763 __le32 next_rxd_phys_addr;
773 } __attribute__((packed));
775 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
776 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
777 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
778 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
779 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
780 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
782 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
784 static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
786 struct mwl8k_rxd_sta *rxd = _rxd;
788 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
789 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
792 static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
794 struct mwl8k_rxd_sta *rxd = _rxd;
796 rxd->pkt_len = cpu_to_le16(len);
797 rxd->pkt_phys_addr = cpu_to_le32(addr);
803 mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
806 struct mwl8k_rxd_sta *rxd = _rxd;
809 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
813 rate_info = le16_to_cpu(rxd->rate_info);
815 memset(status, 0, sizeof(*status));
817 status->signal = -rxd->rssi;
818 status->noise = -rxd->noise_level;
819 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
820 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
822 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
823 status->flag |= RX_FLAG_SHORTPRE;
824 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
825 status->flag |= RX_FLAG_40MHZ;
826 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
827 status->flag |= RX_FLAG_SHORT_GI;
828 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
829 status->flag |= RX_FLAG_HT;
831 status->band = IEEE80211_BAND_2GHZ;
832 status->freq = ieee80211_channel_to_frequency(rxd->channel);
834 *qos = rxd->qos_control;
836 return le16_to_cpu(rxd->pkt_len);
839 static struct rxd_ops rxd_sta_ops = {
840 .rxd_size = sizeof(struct mwl8k_rxd_sta),
841 .rxd_init = mwl8k_rxd_sta_init,
842 .rxd_refill = mwl8k_rxd_sta_refill,
843 .rxd_process = mwl8k_rxd_sta_process,
847 #define MWL8K_RX_DESCS 256
848 #define MWL8K_RX_MAXSZ 3800
850 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
852 struct mwl8k_priv *priv = hw->priv;
853 struct mwl8k_rx_queue *rxq = priv->rxq + index;
861 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
863 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
864 if (rxq->rxd == NULL) {
865 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
866 wiphy_name(hw->wiphy));
869 memset(rxq->rxd, 0, size);
871 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
872 if (rxq->buf == NULL) {
873 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
874 wiphy_name(hw->wiphy));
875 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
878 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
880 for (i = 0; i < MWL8K_RX_DESCS; i++) {
884 dma_addr_t next_dma_addr;
886 desc_size = priv->rxd_ops->rxd_size;
887 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
890 if (nexti == MWL8K_RX_DESCS)
892 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
894 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
900 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
902 struct mwl8k_priv *priv = hw->priv;
903 struct mwl8k_rx_queue *rxq = priv->rxq + index;
907 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
913 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
917 addr = pci_map_single(priv->pdev, skb->data,
918 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
922 if (rxq->tail == MWL8K_RX_DESCS)
924 rxq->buf[rx].skb = skb;
925 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
927 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
928 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
936 /* Must be called only when the card's reception is completely halted */
937 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
939 struct mwl8k_priv *priv = hw->priv;
940 struct mwl8k_rx_queue *rxq = priv->rxq + index;
943 for (i = 0; i < MWL8K_RX_DESCS; i++) {
944 if (rxq->buf[i].skb != NULL) {
945 pci_unmap_single(priv->pdev,
946 pci_unmap_addr(&rxq->buf[i], dma),
947 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
948 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
950 kfree_skb(rxq->buf[i].skb);
951 rxq->buf[i].skb = NULL;
958 pci_free_consistent(priv->pdev,
959 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
960 rxq->rxd, rxq->rxd_dma);
966 * Scan a list of BSSIDs to process for finalize join.
967 * Allows for extension to process multiple BSSIDs.
970 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
972 return priv->capture_beacon &&
973 ieee80211_is_beacon(wh->frame_control) &&
974 !compare_ether_addr(wh->addr3, priv->capture_bssid);
977 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
980 struct mwl8k_priv *priv = hw->priv;
982 priv->capture_beacon = false;
983 memset(priv->capture_bssid, 0, ETH_ALEN);
986 * Use GFP_ATOMIC as rxq_process is called from
987 * the primary interrupt handler, memory allocation call
990 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
991 if (priv->beacon_skb != NULL)
992 ieee80211_queue_work(hw, &priv->finalize_join_worker);
995 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
997 struct mwl8k_priv *priv = hw->priv;
998 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1002 while (rxq->rxd_count && limit--) {
1003 struct sk_buff *skb;
1006 struct ieee80211_rx_status status;
1009 skb = rxq->buf[rxq->head].skb;
1013 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1015 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
1019 rxq->buf[rxq->head].skb = NULL;
1021 pci_unmap_single(priv->pdev,
1022 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1023 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1024 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1027 if (rxq->head == MWL8K_RX_DESCS)
1032 skb_put(skb, pkt_len);
1033 mwl8k_remove_dma_header(skb, qos);
1036 * Check for a pending join operation. Save a
1037 * copy of the beacon and schedule a tasklet to
1038 * send a FINALIZE_JOIN command to the firmware.
1040 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1041 mwl8k_save_beacon(hw, skb);
1043 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1044 ieee80211_rx_irqsafe(hw, skb);
1054 * Packet transmission.
1057 #define MWL8K_TXD_STATUS_OK 0x00000001
1058 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1059 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1060 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1061 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1063 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1064 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1065 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1066 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1067 #define MWL8K_QOS_EOSP 0x0010
1069 struct mwl8k_tx_desc {
1074 __le32 pkt_phys_addr;
1076 __u8 dest_MAC_addr[ETH_ALEN];
1077 __le32 next_txd_phys_addr;
1082 } __attribute__((packed));
1084 #define MWL8K_TX_DESCS 128
1086 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1088 struct mwl8k_priv *priv = hw->priv;
1089 struct mwl8k_tx_queue *txq = priv->txq + index;
1093 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1094 txq->stats.limit = MWL8K_TX_DESCS;
1098 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1100 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1101 if (txq->txd == NULL) {
1102 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1103 wiphy_name(hw->wiphy));
1106 memset(txq->txd, 0, size);
1108 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1109 if (txq->skb == NULL) {
1110 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1111 wiphy_name(hw->wiphy));
1112 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1115 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
1117 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1118 struct mwl8k_tx_desc *tx_desc;
1121 tx_desc = txq->txd + i;
1122 nexti = (i + 1) % MWL8K_TX_DESCS;
1124 tx_desc->status = 0;
1125 tx_desc->next_txd_phys_addr =
1126 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1132 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1134 iowrite32(MWL8K_H2A_INT_PPA_READY,
1135 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1136 iowrite32(MWL8K_H2A_INT_DUMMY,
1137 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1138 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1141 static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1143 struct mwl8k_priv *priv = hw->priv;
1146 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1147 struct mwl8k_tx_queue *txq = priv->txq + i;
1153 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1154 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1157 status = le32_to_cpu(tx_desc->status);
1158 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1163 if (tx_desc->pkt_len == 0)
1167 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1168 "fw_owned=%d drv_owned=%d unused=%d\n",
1169 wiphy_name(hw->wiphy), i,
1170 txq->stats.len, txq->head, txq->tail,
1171 fw_owned, drv_owned, unused);
1176 * Must be called with priv->fw_mutex held and tx queues stopped.
1178 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1180 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1182 struct mwl8k_priv *priv = hw->priv;
1183 DECLARE_COMPLETION_ONSTACK(tx_wait);
1190 * The TX queues are stopped at this point, so this test
1191 * doesn't need to take ->tx_lock.
1193 if (!priv->pending_tx_pkts)
1199 spin_lock_bh(&priv->tx_lock);
1200 priv->tx_wait = &tx_wait;
1203 unsigned long timeout;
1205 oldcount = priv->pending_tx_pkts;
1207 spin_unlock_bh(&priv->tx_lock);
1208 timeout = wait_for_completion_timeout(&tx_wait,
1209 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1210 spin_lock_bh(&priv->tx_lock);
1213 WARN_ON(priv->pending_tx_pkts);
1215 printk(KERN_NOTICE "%s: tx rings drained\n",
1216 wiphy_name(hw->wiphy));
1221 if (priv->pending_tx_pkts < oldcount) {
1222 printk(KERN_NOTICE "%s: waiting for tx rings "
1223 "to drain (%d -> %d pkts)\n",
1224 wiphy_name(hw->wiphy), oldcount,
1225 priv->pending_tx_pkts);
1230 priv->tx_wait = NULL;
1232 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1233 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1234 mwl8k_dump_tx_rings(hw);
1238 spin_unlock_bh(&priv->tx_lock);
1243 #define MWL8K_TXD_SUCCESS(status) \
1244 ((status) & (MWL8K_TXD_STATUS_OK | \
1245 MWL8K_TXD_STATUS_OK_RETRY | \
1246 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1249 mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1251 struct mwl8k_priv *priv = hw->priv;
1252 struct mwl8k_tx_queue *txq = priv->txq + index;
1256 while (txq->stats.len > 0 && limit--) {
1258 struct mwl8k_tx_desc *tx_desc;
1261 struct sk_buff *skb;
1262 struct ieee80211_tx_info *info;
1266 tx_desc = txq->txd + tx;
1268 status = le32_to_cpu(tx_desc->status);
1270 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1274 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1277 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1278 BUG_ON(txq->stats.len == 0);
1280 priv->pending_tx_pkts--;
1282 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1283 size = le16_to_cpu(tx_desc->pkt_len);
1285 txq->skb[tx] = NULL;
1287 BUG_ON(skb == NULL);
1288 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1290 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
1292 /* Mark descriptor as unused */
1293 tx_desc->pkt_phys_addr = 0;
1294 tx_desc->pkt_len = 0;
1296 info = IEEE80211_SKB_CB(skb);
1297 ieee80211_tx_info_clear_status(info);
1298 if (MWL8K_TXD_SUCCESS(status))
1299 info->flags |= IEEE80211_TX_STAT_ACK;
1301 ieee80211_tx_status_irqsafe(hw, skb);
1306 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
1307 ieee80211_wake_queue(hw, index);
1312 /* must be called only when the card's transmit is completely halted */
1313 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1315 struct mwl8k_priv *priv = hw->priv;
1316 struct mwl8k_tx_queue *txq = priv->txq + index;
1318 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1323 pci_free_consistent(priv->pdev,
1324 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1325 txq->txd, txq->txd_dma);
1330 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1332 struct mwl8k_priv *priv = hw->priv;
1333 struct ieee80211_tx_info *tx_info;
1334 struct mwl8k_vif *mwl8k_vif;
1335 struct ieee80211_hdr *wh;
1336 struct mwl8k_tx_queue *txq;
1337 struct mwl8k_tx_desc *tx;
1343 wh = (struct ieee80211_hdr *)skb->data;
1344 if (ieee80211_is_data_qos(wh->frame_control))
1345 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1349 mwl8k_add_dma_header(skb);
1350 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1352 tx_info = IEEE80211_SKB_CB(skb);
1353 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1355 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1356 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1357 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1358 mwl8k_vif->seqno += 0x10;
1361 /* Setup firmware control bit fields for each frame type. */
1364 if (ieee80211_is_mgmt(wh->frame_control) ||
1365 ieee80211_is_ctl(wh->frame_control)) {
1367 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1368 } else if (ieee80211_is_data(wh->frame_control)) {
1370 if (is_multicast_ether_addr(wh->addr1))
1371 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1373 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1374 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1375 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1377 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1380 dma = pci_map_single(priv->pdev, skb->data,
1381 skb->len, PCI_DMA_TODEVICE);
1383 if (pci_dma_mapping_error(priv->pdev, dma)) {
1384 printk(KERN_DEBUG "%s: failed to dma map skb, "
1385 "dropping TX frame.\n", wiphy_name(hw->wiphy));
1387 return NETDEV_TX_OK;
1390 spin_lock_bh(&priv->tx_lock);
1392 txq = priv->txq + index;
1394 BUG_ON(txq->skb[txq->tail] != NULL);
1395 txq->skb[txq->tail] = skb;
1397 tx = txq->txd + txq->tail;
1398 tx->data_rate = txdatarate;
1399 tx->tx_priority = index;
1400 tx->qos_control = cpu_to_le16(qos);
1401 tx->pkt_phys_addr = cpu_to_le32(dma);
1402 tx->pkt_len = cpu_to_le16(skb->len);
1404 if (!priv->ap_fw && tx_info->control.sta != NULL)
1405 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1409 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1413 priv->pending_tx_pkts++;
1416 if (txq->tail == MWL8K_TX_DESCS)
1419 if (txq->head == txq->tail)
1420 ieee80211_stop_queue(hw, index);
1422 mwl8k_tx_start(priv);
1424 spin_unlock_bh(&priv->tx_lock);
1426 return NETDEV_TX_OK;
1433 * We have the following requirements for issuing firmware commands:
1434 * - Some commands require that the packet transmit path is idle when
1435 * the command is issued. (For simplicity, we'll just quiesce the
1436 * transmit path for every command.)
1437 * - There are certain sequences of commands that need to be issued to
1438 * the hardware sequentially, with no other intervening commands.
1440 * This leads to an implementation of a "firmware lock" as a mutex that
1441 * can be taken recursively, and which is taken by both the low-level
1442 * command submission function (mwl8k_post_cmd) as well as any users of
1443 * that function that require issuing of an atomic sequence of commands,
1444 * and quiesces the transmit path whenever it's taken.
1446 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1448 struct mwl8k_priv *priv = hw->priv;
1450 if (priv->fw_mutex_owner != current) {
1453 mutex_lock(&priv->fw_mutex);
1454 ieee80211_stop_queues(hw);
1456 rc = mwl8k_tx_wait_empty(hw);
1458 ieee80211_wake_queues(hw);
1459 mutex_unlock(&priv->fw_mutex);
1464 priv->fw_mutex_owner = current;
1467 priv->fw_mutex_depth++;
1472 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1474 struct mwl8k_priv *priv = hw->priv;
1476 if (!--priv->fw_mutex_depth) {
1477 ieee80211_wake_queues(hw);
1478 priv->fw_mutex_owner = NULL;
1479 mutex_unlock(&priv->fw_mutex);
1485 * Command processing.
1488 /* Timeout firmware commands after 10s */
1489 #define MWL8K_CMD_TIMEOUT_MS 10000
1491 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1493 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1494 struct mwl8k_priv *priv = hw->priv;
1495 void __iomem *regs = priv->regs;
1496 dma_addr_t dma_addr;
1497 unsigned int dma_size;
1499 unsigned long timeout = 0;
1502 cmd->result = 0xffff;
1503 dma_size = le16_to_cpu(cmd->length);
1504 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1505 PCI_DMA_BIDIRECTIONAL);
1506 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1509 rc = mwl8k_fw_lock(hw);
1511 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1512 PCI_DMA_BIDIRECTIONAL);
1516 priv->hostcmd_wait = &cmd_wait;
1517 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1518 iowrite32(MWL8K_H2A_INT_DOORBELL,
1519 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1520 iowrite32(MWL8K_H2A_INT_DUMMY,
1521 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1523 timeout = wait_for_completion_timeout(&cmd_wait,
1524 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1526 priv->hostcmd_wait = NULL;
1528 mwl8k_fw_unlock(hw);
1530 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1531 PCI_DMA_BIDIRECTIONAL);
1534 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1535 wiphy_name(hw->wiphy),
1536 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1537 MWL8K_CMD_TIMEOUT_MS);
1542 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1544 rc = cmd->result ? -EINVAL : 0;
1546 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1547 wiphy_name(hw->wiphy),
1548 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1549 le16_to_cpu(cmd->result));
1551 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1552 wiphy_name(hw->wiphy),
1553 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1561 * Setup code shared between STA and AP firmware images.
1563 static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1565 struct mwl8k_priv *priv = hw->priv;
1567 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1568 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1570 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1571 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1573 priv->band_24.band = IEEE80211_BAND_2GHZ;
1574 priv->band_24.channels = priv->channels_24;
1575 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1576 priv->band_24.bitrates = priv->rates_24;
1577 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1579 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1583 * CMD_GET_HW_SPEC (STA version).
1585 struct mwl8k_cmd_get_hw_spec_sta {
1586 struct mwl8k_cmd_pkt header;
1588 __u8 host_interface;
1590 __u8 perm_addr[ETH_ALEN];
1595 __u8 mcs_bitmap[16];
1596 __le32 rx_queue_ptr;
1597 __le32 num_tx_queues;
1598 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1600 __le32 num_tx_desc_per_queue;
1602 } __attribute__((packed));
1604 #define MWL8K_CAP_MAX_AMSDU 0x20000000
1605 #define MWL8K_CAP_GREENFIELD 0x08000000
1606 #define MWL8K_CAP_AMPDU 0x04000000
1607 #define MWL8K_CAP_RX_STBC 0x01000000
1608 #define MWL8K_CAP_TX_STBC 0x00800000
1609 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1610 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1611 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1612 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1613 #define MWL8K_CAP_DELAY_BA 0x00003000
1614 #define MWL8K_CAP_MIMO 0x00000200
1615 #define MWL8K_CAP_40MHZ 0x00000100
1617 static void mwl8k_set_ht_caps(struct ieee80211_hw *hw, u32 cap)
1619 struct mwl8k_priv *priv = hw->priv;
1620 struct ieee80211_supported_band *band = &priv->band_24;
1624 band->ht_cap.ht_supported = 1;
1626 if (cap & MWL8K_CAP_MAX_AMSDU)
1627 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
1628 if (cap & MWL8K_CAP_GREENFIELD)
1629 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
1630 if (cap & MWL8K_CAP_AMPDU) {
1631 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
1632 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1633 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1635 if (cap & MWL8K_CAP_RX_STBC)
1636 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
1637 if (cap & MWL8K_CAP_TX_STBC)
1638 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
1639 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
1640 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
1641 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
1642 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
1643 if (cap & MWL8K_CAP_DELAY_BA)
1644 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
1645 if (cap & MWL8K_CAP_40MHZ)
1646 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1648 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1649 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1651 band->ht_cap.mcs.rx_mask[0] = 0xff;
1652 if (rx_streams >= 2)
1653 band->ht_cap.mcs.rx_mask[1] = 0xff;
1654 if (rx_streams >= 3)
1655 band->ht_cap.mcs.rx_mask[2] = 0xff;
1656 band->ht_cap.mcs.rx_mask[4] = 0x01;
1657 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1659 if (rx_streams != tx_streams) {
1660 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1661 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
1662 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1666 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
1668 struct mwl8k_priv *priv = hw->priv;
1669 struct mwl8k_cmd_get_hw_spec_sta *cmd;
1673 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1677 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1678 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1680 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1681 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1682 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1683 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1684 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1685 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1686 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1687 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1689 rc = mwl8k_post_cmd(hw, &cmd->header);
1692 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1693 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1694 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1695 priv->hw_rev = cmd->hw_rev;
1696 mwl8k_setup_2ghz_band(hw);
1697 if (cmd->caps & cpu_to_le32(MWL8K_CAP_MIMO))
1698 mwl8k_set_ht_caps(hw, le32_to_cpu(cmd->caps));
1706 * CMD_GET_HW_SPEC (AP version).
1708 struct mwl8k_cmd_get_hw_spec_ap {
1709 struct mwl8k_cmd_pkt header;
1711 __u8 host_interface;
1714 __u8 perm_addr[ETH_ALEN];
1725 } __attribute__((packed));
1727 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1729 struct mwl8k_priv *priv = hw->priv;
1730 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1733 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1737 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1738 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1740 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1741 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1743 rc = mwl8k_post_cmd(hw, &cmd->header);
1748 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1749 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1750 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1751 priv->hw_rev = cmd->hw_rev;
1752 mwl8k_setup_2ghz_band(hw);
1754 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1755 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1757 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1758 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1760 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1761 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1763 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1764 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1766 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1767 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1769 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1770 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1780 struct mwl8k_cmd_set_hw_spec {
1781 struct mwl8k_cmd_pkt header;
1783 __u8 host_interface;
1785 __u8 perm_addr[ETH_ALEN];
1790 __le32 rx_queue_ptr;
1791 __le32 num_tx_queues;
1792 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1794 __le32 num_tx_desc_per_queue;
1796 } __attribute__((packed));
1798 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1799 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1800 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
1802 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1804 struct mwl8k_priv *priv = hw->priv;
1805 struct mwl8k_cmd_set_hw_spec *cmd;
1809 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1813 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1814 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1816 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1817 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1818 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1819 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1820 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1821 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1822 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1823 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
1824 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1825 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1827 rc = mwl8k_post_cmd(hw, &cmd->header);
1834 * CMD_MAC_MULTICAST_ADR.
1836 struct mwl8k_cmd_mac_multicast_adr {
1837 struct mwl8k_cmd_pkt header;
1840 __u8 addr[0][ETH_ALEN];
1843 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
1844 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
1845 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1846 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
1848 static struct mwl8k_cmd_pkt *
1849 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
1850 int mc_count, struct dev_addr_list *mclist)
1852 struct mwl8k_priv *priv = hw->priv;
1853 struct mwl8k_cmd_mac_multicast_adr *cmd;
1856 if (allmulti || mc_count > priv->num_mcaddrs) {
1861 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1863 cmd = kzalloc(size, GFP_ATOMIC);
1867 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1868 cmd->header.length = cpu_to_le16(size);
1869 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1870 MWL8K_ENABLE_RX_BROADCAST);
1873 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1874 } else if (mc_count) {
1877 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1878 cmd->numaddr = cpu_to_le16(mc_count);
1879 for (i = 0; i < mc_count && mclist; i++) {
1880 if (mclist->da_addrlen != ETH_ALEN) {
1884 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1885 mclist = mclist->next;
1889 return &cmd->header;
1895 struct mwl8k_cmd_get_stat {
1896 struct mwl8k_cmd_pkt header;
1898 } __attribute__((packed));
1900 #define MWL8K_STAT_ACK_FAILURE 9
1901 #define MWL8K_STAT_RTS_FAILURE 12
1902 #define MWL8K_STAT_FCS_ERROR 24
1903 #define MWL8K_STAT_RTS_SUCCESS 11
1905 static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1906 struct ieee80211_low_level_stats *stats)
1908 struct mwl8k_cmd_get_stat *cmd;
1911 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1915 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1916 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1918 rc = mwl8k_post_cmd(hw, &cmd->header);
1920 stats->dot11ACKFailureCount =
1921 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1922 stats->dot11RTSFailureCount =
1923 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1924 stats->dot11FCSErrorCount =
1925 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1926 stats->dot11RTSSuccessCount =
1927 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1935 * CMD_RADIO_CONTROL.
1937 struct mwl8k_cmd_radio_control {
1938 struct mwl8k_cmd_pkt header;
1942 } __attribute__((packed));
1945 mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
1947 struct mwl8k_priv *priv = hw->priv;
1948 struct mwl8k_cmd_radio_control *cmd;
1951 if (enable == priv->radio_on && !force)
1954 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1958 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1959 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1960 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1961 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
1962 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1964 rc = mwl8k_post_cmd(hw, &cmd->header);
1968 priv->radio_on = enable;
1973 static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
1975 return mwl8k_cmd_radio_control(hw, 0, 0);
1978 static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
1980 return mwl8k_cmd_radio_control(hw, 1, 0);
1984 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1986 struct mwl8k_priv *priv = hw->priv;
1988 priv->radio_short_preamble = short_preamble;
1990 return mwl8k_cmd_radio_control(hw, 1, 1);
1996 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1998 struct mwl8k_cmd_rf_tx_power {
1999 struct mwl8k_cmd_pkt header;
2001 __le16 support_level;
2002 __le16 current_level;
2004 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2005 } __attribute__((packed));
2007 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
2009 struct mwl8k_cmd_rf_tx_power *cmd;
2012 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2016 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2017 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2018 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2019 cmd->support_level = cpu_to_le16(dBm);
2021 rc = mwl8k_post_cmd(hw, &cmd->header);
2030 struct mwl8k_cmd_rf_antenna {
2031 struct mwl8k_cmd_pkt header;
2034 } __attribute__((packed));
2036 #define MWL8K_RF_ANTENNA_RX 1
2037 #define MWL8K_RF_ANTENNA_TX 2
2040 mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2042 struct mwl8k_cmd_rf_antenna *cmd;
2045 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2049 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2050 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2051 cmd->antenna = cpu_to_le16(antenna);
2052 cmd->mode = cpu_to_le16(mask);
2054 rc = mwl8k_post_cmd(hw, &cmd->header);
2063 struct mwl8k_cmd_set_beacon {
2064 struct mwl8k_cmd_pkt header;
2069 static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, u8 *beacon, int len)
2071 struct mwl8k_cmd_set_beacon *cmd;
2074 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2078 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2079 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2080 cmd->beacon_len = cpu_to_le16(len);
2081 memcpy(cmd->beacon, beacon, len);
2083 rc = mwl8k_post_cmd(hw, &cmd->header);
2092 struct mwl8k_cmd_set_pre_scan {
2093 struct mwl8k_cmd_pkt header;
2094 } __attribute__((packed));
2096 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2098 struct mwl8k_cmd_set_pre_scan *cmd;
2101 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2105 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2106 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2108 rc = mwl8k_post_cmd(hw, &cmd->header);
2115 * CMD_SET_POST_SCAN.
2117 struct mwl8k_cmd_set_post_scan {
2118 struct mwl8k_cmd_pkt header;
2120 __u8 bssid[ETH_ALEN];
2121 } __attribute__((packed));
2124 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2126 struct mwl8k_cmd_set_post_scan *cmd;
2129 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2133 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2134 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2136 memcpy(cmd->bssid, mac, ETH_ALEN);
2138 rc = mwl8k_post_cmd(hw, &cmd->header);
2145 * CMD_SET_RF_CHANNEL.
2147 struct mwl8k_cmd_set_rf_channel {
2148 struct mwl8k_cmd_pkt header;
2150 __u8 current_channel;
2151 __le32 channel_flags;
2152 } __attribute__((packed));
2154 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2155 struct ieee80211_conf *conf)
2157 struct ieee80211_channel *channel = conf->channel;
2158 struct mwl8k_cmd_set_rf_channel *cmd;
2161 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2165 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2166 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2167 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2168 cmd->current_channel = channel->hw_value;
2170 if (channel->band == IEEE80211_BAND_2GHZ)
2171 cmd->channel_flags |= cpu_to_le32(0x00000001);
2173 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2174 conf->channel_type == NL80211_CHAN_HT20)
2175 cmd->channel_flags |= cpu_to_le32(0x00000080);
2176 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2177 cmd->channel_flags |= cpu_to_le32(0x000001900);
2178 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2179 cmd->channel_flags |= cpu_to_le32(0x000000900);
2181 rc = mwl8k_post_cmd(hw, &cmd->header);
2190 #define MWL8K_FRAME_PROT_DISABLED 0x00
2191 #define MWL8K_FRAME_PROT_11G 0x07
2192 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2193 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2195 struct mwl8k_cmd_update_set_aid {
2196 struct mwl8k_cmd_pkt header;
2199 /* AP's MAC address (BSSID) */
2200 __u8 bssid[ETH_ALEN];
2201 __le16 protection_mode;
2202 __u8 supp_rates[14];
2203 } __attribute__((packed));
2205 static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2211 * Clear nonstandard rates 4 and 13.
2215 for (i = 0, j = 0; i < 14; i++) {
2216 if (mask & (1 << i))
2217 rates[j++] = mwl8k_rates_24[i].hw_value;
2222 mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2223 struct ieee80211_vif *vif, u32 legacy_rate_mask)
2225 struct mwl8k_cmd_update_set_aid *cmd;
2229 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2233 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2234 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2235 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
2236 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
2238 if (vif->bss_conf.use_cts_prot) {
2239 prot_mode = MWL8K_FRAME_PROT_11G;
2241 switch (vif->bss_conf.ht_operation_mode &
2242 IEEE80211_HT_OP_MODE_PROTECTION) {
2243 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2244 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2246 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2247 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2250 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2254 cmd->protection_mode = cpu_to_le16(prot_mode);
2256 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
2258 rc = mwl8k_post_cmd(hw, &cmd->header);
2267 struct mwl8k_cmd_set_rate {
2268 struct mwl8k_cmd_pkt header;
2269 __u8 legacy_rates[14];
2271 /* Bitmap for supported MCS codes. */
2274 } __attribute__((packed));
2277 mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2278 u32 legacy_rate_mask, u8 *mcs_rates)
2280 struct mwl8k_cmd_set_rate *cmd;
2283 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2287 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2288 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2289 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
2290 memcpy(cmd->mcs_set, mcs_rates, 16);
2292 rc = mwl8k_post_cmd(hw, &cmd->header);
2299 * CMD_FINALIZE_JOIN.
2301 #define MWL8K_FJ_BEACON_MAXLEN 128
2303 struct mwl8k_cmd_finalize_join {
2304 struct mwl8k_cmd_pkt header;
2305 __le32 sleep_interval; /* Number of beacon periods to sleep */
2306 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2307 } __attribute__((packed));
2309 static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2310 int framelen, int dtim)
2312 struct mwl8k_cmd_finalize_join *cmd;
2313 struct ieee80211_mgmt *payload = frame;
2317 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2321 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2322 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2323 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2325 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2326 if (payload_len < 0)
2328 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2329 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2331 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2333 rc = mwl8k_post_cmd(hw, &cmd->header);
2340 * CMD_SET_RTS_THRESHOLD.
2342 struct mwl8k_cmd_set_rts_threshold {
2343 struct mwl8k_cmd_pkt header;
2346 } __attribute__((packed));
2349 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
2351 struct mwl8k_cmd_set_rts_threshold *cmd;
2354 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2358 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2359 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2360 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2361 cmd->threshold = cpu_to_le16(rts_thresh);
2363 rc = mwl8k_post_cmd(hw, &cmd->header);
2372 struct mwl8k_cmd_set_slot {
2373 struct mwl8k_cmd_pkt header;
2376 } __attribute__((packed));
2378 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
2380 struct mwl8k_cmd_set_slot *cmd;
2383 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2387 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2388 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2389 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2390 cmd->short_slot = short_slot_time;
2392 rc = mwl8k_post_cmd(hw, &cmd->header);
2399 * CMD_SET_EDCA_PARAMS.
2401 struct mwl8k_cmd_set_edca_params {
2402 struct mwl8k_cmd_pkt header;
2404 /* See MWL8K_SET_EDCA_XXX below */
2407 /* TX opportunity in units of 32 us */
2412 /* Log exponent of max contention period: 0...15 */
2415 /* Log exponent of min contention period: 0...15 */
2418 /* Adaptive interframe spacing in units of 32us */
2421 /* TX queue to configure */
2425 /* Log exponent of max contention period: 0...15 */
2428 /* Log exponent of min contention period: 0...15 */
2431 /* Adaptive interframe spacing in units of 32us */
2434 /* TX queue to configure */
2438 } __attribute__((packed));
2440 #define MWL8K_SET_EDCA_CW 0x01
2441 #define MWL8K_SET_EDCA_TXOP 0x02
2442 #define MWL8K_SET_EDCA_AIFS 0x04
2444 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2445 MWL8K_SET_EDCA_TXOP | \
2446 MWL8K_SET_EDCA_AIFS)
2449 mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2450 __u16 cw_min, __u16 cw_max,
2451 __u8 aifs, __u16 txop)
2453 struct mwl8k_priv *priv = hw->priv;
2454 struct mwl8k_cmd_set_edca_params *cmd;
2457 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2461 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2462 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2463 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2464 cmd->txop = cpu_to_le16(txop);
2466 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2467 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2468 cmd->ap.aifs = aifs;
2471 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2472 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2473 cmd->sta.aifs = aifs;
2474 cmd->sta.txq = qnum;
2477 rc = mwl8k_post_cmd(hw, &cmd->header);
2486 struct mwl8k_cmd_set_wmm_mode {
2487 struct mwl8k_cmd_pkt header;
2489 } __attribute__((packed));
2491 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
2493 struct mwl8k_priv *priv = hw->priv;
2494 struct mwl8k_cmd_set_wmm_mode *cmd;
2497 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2501 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2502 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2503 cmd->action = cpu_to_le16(!!enable);
2505 rc = mwl8k_post_cmd(hw, &cmd->header);
2509 priv->wmm_enabled = enable;
2517 struct mwl8k_cmd_mimo_config {
2518 struct mwl8k_cmd_pkt header;
2520 __u8 rx_antenna_map;
2521 __u8 tx_antenna_map;
2522 } __attribute__((packed));
2524 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2526 struct mwl8k_cmd_mimo_config *cmd;
2529 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2533 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2534 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2535 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2536 cmd->rx_antenna_map = rx;
2537 cmd->tx_antenna_map = tx;
2539 rc = mwl8k_post_cmd(hw, &cmd->header);
2546 * CMD_USE_FIXED_RATE (STA version).
2548 struct mwl8k_cmd_use_fixed_rate_sta {
2549 struct mwl8k_cmd_pkt header;
2551 __le32 allow_rate_drop;
2555 __le32 enable_retry;
2562 } __attribute__((packed));
2564 #define MWL8K_USE_AUTO_RATE 0x0002
2565 #define MWL8K_UCAST_RATE 0
2567 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
2569 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
2572 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2576 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2577 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2578 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2579 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
2581 rc = mwl8k_post_cmd(hw, &cmd->header);
2588 * CMD_USE_FIXED_RATE (AP version).
2590 struct mwl8k_cmd_use_fixed_rate_ap {
2591 struct mwl8k_cmd_pkt header;
2593 __le32 allow_rate_drop;
2595 struct mwl8k_rate_entry_ap {
2597 __le32 enable_retry;
2602 u8 multicast_rate_type;
2604 } __attribute__((packed));
2607 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2609 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2612 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2616 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2617 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2618 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2619 cmd->multicast_rate = mcast;
2620 cmd->management_rate = mgmt;
2622 rc = mwl8k_post_cmd(hw, &cmd->header);
2629 * CMD_ENABLE_SNIFFER.
2631 struct mwl8k_cmd_enable_sniffer {
2632 struct mwl8k_cmd_pkt header;
2634 } __attribute__((packed));
2636 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2638 struct mwl8k_cmd_enable_sniffer *cmd;
2641 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2645 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2646 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2647 cmd->action = cpu_to_le32(!!enable);
2649 rc = mwl8k_post_cmd(hw, &cmd->header);
2658 struct mwl8k_cmd_set_mac_addr {
2659 struct mwl8k_cmd_pkt header;
2663 __u8 mac_addr[ETH_ALEN];
2665 __u8 mac_addr[ETH_ALEN];
2667 } __attribute__((packed));
2669 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2670 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
2672 static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2674 struct mwl8k_priv *priv = hw->priv;
2675 struct mwl8k_cmd_set_mac_addr *cmd;
2678 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2682 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2683 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2685 cmd->mbss.mac_type = cpu_to_le16(MWL8K_MAC_TYPE_PRIMARY_AP);
2686 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2688 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2691 rc = mwl8k_post_cmd(hw, &cmd->header);
2698 * CMD_SET_RATEADAPT_MODE.
2700 struct mwl8k_cmd_set_rate_adapt_mode {
2701 struct mwl8k_cmd_pkt header;
2704 } __attribute__((packed));
2706 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2708 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2711 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2715 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2716 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2717 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2718 cmd->mode = cpu_to_le16(mode);
2720 rc = mwl8k_post_cmd(hw, &cmd->header);
2729 struct mwl8k_cmd_bss_start {
2730 struct mwl8k_cmd_pkt header;
2732 } __attribute__((packed));
2734 static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, int enable)
2736 struct mwl8k_cmd_bss_start *cmd;
2739 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2743 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2744 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2745 cmd->enable = cpu_to_le32(enable);
2747 rc = mwl8k_post_cmd(hw, &cmd->header);
2756 struct mwl8k_cmd_set_new_stn {
2757 struct mwl8k_cmd_pkt header;
2763 __le32 legacy_rates;
2766 __le16 ht_capabilities_info;
2767 __u8 mac_ht_param_info;
2769 __u8 control_channel;
2776 } __attribute__((packed));
2778 #define MWL8K_STA_ACTION_ADD 0
2779 #define MWL8K_STA_ACTION_REMOVE 2
2781 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2782 struct ieee80211_vif *vif,
2783 struct ieee80211_sta *sta)
2785 struct mwl8k_cmd_set_new_stn *cmd;
2788 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2792 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2793 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2794 cmd->aid = cpu_to_le16(sta->aid);
2795 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2796 cmd->stn_id = cpu_to_le16(sta->aid);
2797 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
2798 cmd->legacy_rates = cpu_to_le32(sta->supp_rates[IEEE80211_BAND_2GHZ]);
2799 if (sta->ht_cap.ht_supported) {
2800 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2801 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2802 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2803 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2804 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2805 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2806 ((sta->ht_cap.ampdu_density & 7) << 2);
2807 cmd->is_qos_sta = 1;
2810 rc = mwl8k_post_cmd(hw, &cmd->header);
2816 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2817 struct ieee80211_vif *vif)
2819 struct mwl8k_cmd_set_new_stn *cmd;
2822 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2826 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2827 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2828 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2830 rc = mwl8k_post_cmd(hw, &cmd->header);
2836 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2837 struct ieee80211_vif *vif, u8 *addr)
2839 struct mwl8k_cmd_set_new_stn *cmd;
2842 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2846 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2847 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2848 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2849 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2851 rc = mwl8k_post_cmd(hw, &cmd->header);
2860 struct ewc_ht_info {
2864 } __attribute__((packed));
2866 struct peer_capability_info {
2867 /* Peer type - AP vs. STA. */
2870 /* Basic 802.11 capabilities from assoc resp. */
2873 /* Set if peer supports 802.11n high throughput (HT). */
2876 /* Valid if HT is supported. */
2878 __u8 extended_ht_caps;
2879 struct ewc_ht_info ewc_info;
2881 /* Legacy rate table. Intersection of our rates and peer rates. */
2882 __u8 legacy_rates[12];
2884 /* HT rate table. Intersection of our rates and peer rates. */
2888 /* If set, interoperability mode, no proprietary extensions. */
2892 __le16 amsdu_enabled;
2893 } __attribute__((packed));
2895 struct mwl8k_cmd_update_stadb {
2896 struct mwl8k_cmd_pkt header;
2898 /* See STADB_ACTION_TYPE */
2901 /* Peer MAC address */
2902 __u8 peer_addr[ETH_ALEN];
2906 /* Peer info - valid during add/update. */
2907 struct peer_capability_info peer_info;
2908 } __attribute__((packed));
2910 #define MWL8K_STA_DB_MODIFY_ENTRY 1
2911 #define MWL8K_STA_DB_DEL_ENTRY 2
2913 /* Peer Entry flags - used to define the type of the peer node */
2914 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
2916 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
2917 struct ieee80211_vif *vif,
2918 struct ieee80211_sta *sta)
2920 struct mwl8k_cmd_update_stadb *cmd;
2921 struct peer_capability_info *p;
2924 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2928 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2929 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2930 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
2931 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
2933 p = &cmd->peer_info;
2934 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2935 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
2936 p->ht_support = sta->ht_cap.ht_supported;
2937 p->ht_caps = sta->ht_cap.cap;
2938 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
2939 ((sta->ht_cap.ampdu_density & 7) << 2);
2940 legacy_rate_mask_to_array(p->legacy_rates,
2941 sta->supp_rates[IEEE80211_BAND_2GHZ]);
2942 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
2944 p->amsdu_enabled = 0;
2946 rc = mwl8k_post_cmd(hw, &cmd->header);
2949 return rc ? rc : p->station_id;
2952 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
2953 struct ieee80211_vif *vif, u8 *addr)
2955 struct mwl8k_cmd_update_stadb *cmd;
2958 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2962 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2963 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2964 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
2965 memcpy(cmd->peer_addr, addr, ETH_ALEN);
2967 rc = mwl8k_post_cmd(hw, &cmd->header);
2975 * Interrupt handling.
2977 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2979 struct ieee80211_hw *hw = dev_id;
2980 struct mwl8k_priv *priv = hw->priv;
2983 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2987 if (status & MWL8K_A2H_INT_TX_DONE) {
2988 status &= ~MWL8K_A2H_INT_TX_DONE;
2989 tasklet_schedule(&priv->poll_tx_task);
2992 if (status & MWL8K_A2H_INT_RX_READY) {
2993 status &= ~MWL8K_A2H_INT_RX_READY;
2994 tasklet_schedule(&priv->poll_rx_task);
2998 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3000 if (status & MWL8K_A2H_INT_OPC_DONE) {
3001 if (priv->hostcmd_wait != NULL)
3002 complete(priv->hostcmd_wait);
3005 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
3006 if (!mutex_is_locked(&priv->fw_mutex) &&
3007 priv->radio_on && priv->pending_tx_pkts)
3008 mwl8k_tx_start(priv);
3014 static void mwl8k_tx_poll(unsigned long data)
3016 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3017 struct mwl8k_priv *priv = hw->priv;
3023 spin_lock_bh(&priv->tx_lock);
3025 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3026 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3028 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3029 complete(priv->tx_wait);
3030 priv->tx_wait = NULL;
3033 spin_unlock_bh(&priv->tx_lock);
3036 writel(~MWL8K_A2H_INT_TX_DONE,
3037 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3039 tasklet_schedule(&priv->poll_tx_task);
3043 static void mwl8k_rx_poll(unsigned long data)
3045 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3046 struct mwl8k_priv *priv = hw->priv;
3050 limit -= rxq_process(hw, 0, limit);
3051 limit -= rxq_refill(hw, 0, limit);
3054 writel(~MWL8K_A2H_INT_RX_READY,
3055 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3057 tasklet_schedule(&priv->poll_rx_task);
3063 * Core driver operations.
3065 static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3067 struct mwl8k_priv *priv = hw->priv;
3068 int index = skb_get_queue_mapping(skb);
3071 if (!priv->radio_on) {
3072 printk(KERN_DEBUG "%s: dropped TX frame since radio "
3073 "disabled\n", wiphy_name(hw->wiphy));
3075 return NETDEV_TX_OK;
3078 rc = mwl8k_txq_xmit(hw, index, skb);
3083 static int mwl8k_start(struct ieee80211_hw *hw)
3085 struct mwl8k_priv *priv = hw->priv;
3088 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
3089 IRQF_SHARED, MWL8K_NAME, hw);
3091 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3092 wiphy_name(hw->wiphy));
3096 /* Enable TX reclaim and RX tasklets. */
3097 tasklet_enable(&priv->poll_tx_task);
3098 tasklet_enable(&priv->poll_rx_task);
3100 /* Enable interrupts */
3101 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3103 rc = mwl8k_fw_lock(hw);
3105 rc = mwl8k_cmd_radio_enable(hw);
3109 rc = mwl8k_cmd_enable_sniffer(hw, 0);
3112 rc = mwl8k_cmd_set_pre_scan(hw);
3115 rc = mwl8k_cmd_set_post_scan(hw,
3116 "\x00\x00\x00\x00\x00\x00");
3120 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
3123 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
3125 mwl8k_fw_unlock(hw);
3129 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3130 free_irq(priv->pdev->irq, hw);
3131 tasklet_disable(&priv->poll_tx_task);
3132 tasklet_disable(&priv->poll_rx_task);
3138 static void mwl8k_stop(struct ieee80211_hw *hw)
3140 struct mwl8k_priv *priv = hw->priv;
3143 mwl8k_cmd_radio_disable(hw);
3145 ieee80211_stop_queues(hw);
3147 /* Disable interrupts */
3148 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3149 free_irq(priv->pdev->irq, hw);
3151 /* Stop finalize join worker */
3152 cancel_work_sync(&priv->finalize_join_worker);
3153 if (priv->beacon_skb != NULL)
3154 dev_kfree_skb(priv->beacon_skb);
3156 /* Stop TX reclaim and RX tasklets. */
3157 tasklet_disable(&priv->poll_tx_task);
3158 tasklet_disable(&priv->poll_rx_task);
3160 /* Return all skbs to mac80211 */
3161 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3162 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
3165 static int mwl8k_add_interface(struct ieee80211_hw *hw,
3166 struct ieee80211_vif *vif)
3168 struct mwl8k_priv *priv = hw->priv;
3169 struct mwl8k_vif *mwl8k_vif;
3172 * We only support one active interface at a time.
3174 if (priv->vif != NULL)
3178 * Reject interface creation if sniffer mode is active, as
3179 * STA operation is mutually exclusive with hardware sniffer
3180 * mode. (Sniffer mode is only used on STA firmware.)
3182 if (priv->sniffer_enabled) {
3183 printk(KERN_INFO "%s: unable to create STA "
3184 "interface due to sniffer mode being enabled\n",
3185 wiphy_name(hw->wiphy));
3189 /* Set the mac address. */
3190 mwl8k_cmd_set_mac_addr(hw, vif->addr);
3193 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3195 /* Clean out driver private area */
3196 mwl8k_vif = MWL8K_VIF(vif);
3197 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
3199 /* Set Initial sequence number to zero */
3200 mwl8k_vif->seqno = 0;
3207 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
3208 struct ieee80211_vif *vif)
3210 struct mwl8k_priv *priv = hw->priv;
3213 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3215 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3220 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
3222 struct ieee80211_conf *conf = &hw->conf;
3223 struct mwl8k_priv *priv = hw->priv;
3226 if (conf->flags & IEEE80211_CONF_IDLE) {
3227 mwl8k_cmd_radio_disable(hw);
3231 rc = mwl8k_fw_lock(hw);
3235 rc = mwl8k_cmd_radio_enable(hw);
3239 rc = mwl8k_cmd_set_rf_channel(hw, conf);
3243 if (conf->power_level > 18)
3244 conf->power_level = 18;
3245 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
3250 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3252 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3254 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3258 mwl8k_fw_unlock(hw);
3264 mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3265 struct ieee80211_bss_conf *info, u32 changed)
3267 struct mwl8k_priv *priv = hw->priv;
3268 u32 ap_legacy_rates;
3269 u8 ap_mcs_rates[16];
3272 if (mwl8k_fw_lock(hw))
3276 * No need to capture a beacon if we're no longer associated.
3278 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3279 priv->capture_beacon = false;
3282 * Get the AP's legacy and MCS rates.
3284 if (vif->bss_conf.assoc) {
3285 struct ieee80211_sta *ap;
3289 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
3295 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3296 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
3301 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
3302 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
3306 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
3311 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3312 rc = mwl8k_set_radio_preamble(hw,
3313 vif->bss_conf.use_short_preamble);
3318 if (changed & BSS_CHANGED_ERP_SLOT) {
3319 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
3324 if (vif->bss_conf.assoc &&
3325 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3327 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
3332 if (vif->bss_conf.assoc &&
3333 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
3335 * Finalize the join. Tell rx handler to process
3336 * next beacon from our BSSID.
3338 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
3339 priv->capture_beacon = true;
3343 mwl8k_fw_unlock(hw);
3347 mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3348 struct ieee80211_bss_conf *info, u32 changed)
3352 if (mwl8k_fw_lock(hw))
3355 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3356 rc = mwl8k_set_radio_preamble(hw,
3357 vif->bss_conf.use_short_preamble);
3362 if (changed & BSS_CHANGED_BASIC_RATES) {
3367 * Use lowest supported basic rate for multicasts
3368 * and management frames (such as probe responses --
3369 * beacons will always go out at 1 Mb/s).
3371 idx = ffs(vif->bss_conf.basic_rates);
3372 rate = idx ? mwl8k_rates_24[idx - 1].hw_value : 2;
3374 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3377 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3378 struct sk_buff *skb;
3380 skb = ieee80211_beacon_get(hw, vif);
3382 mwl8k_cmd_set_beacon(hw, skb->data, skb->len);
3387 if (changed & BSS_CHANGED_BEACON_ENABLED)
3388 mwl8k_cmd_bss_start(hw, info->enable_beacon);
3391 mwl8k_fw_unlock(hw);
3395 mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3396 struct ieee80211_bss_conf *info, u32 changed)
3398 struct mwl8k_priv *priv = hw->priv;
3401 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3403 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3406 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3407 int mc_count, struct dev_addr_list *mclist)
3409 struct mwl8k_cmd_pkt *cmd;
3412 * Synthesize and return a command packet that programs the
3413 * hardware multicast address filter. At this point we don't
3414 * know whether FIF_ALLMULTI is being requested, but if it is,
3415 * we'll end up throwing this packet away and creating a new
3416 * one in mwl8k_configure_filter().
3418 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
3420 return (unsigned long)cmd;
3424 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3425 unsigned int changed_flags,
3426 unsigned int *total_flags)
3428 struct mwl8k_priv *priv = hw->priv;
3431 * Hardware sniffer mode is mutually exclusive with STA
3432 * operation, so refuse to enable sniffer mode if a STA
3433 * interface is active.
3435 if (priv->vif != NULL) {
3436 if (net_ratelimit())
3437 printk(KERN_INFO "%s: not enabling sniffer "
3438 "mode because STA interface is active\n",
3439 wiphy_name(hw->wiphy));
3443 if (!priv->sniffer_enabled) {
3444 if (mwl8k_cmd_enable_sniffer(hw, 1))
3446 priv->sniffer_enabled = true;
3449 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3450 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3456 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3457 unsigned int changed_flags,
3458 unsigned int *total_flags,
3461 struct mwl8k_priv *priv = hw->priv;
3462 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3465 * AP firmware doesn't allow fine-grained control over
3466 * the receive filter.
3469 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3475 * Enable hardware sniffer mode if FIF_CONTROL or
3476 * FIF_OTHER_BSS is requested.
3478 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3479 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3484 /* Clear unsupported feature flags */
3485 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3487 if (mwl8k_fw_lock(hw)) {
3492 if (priv->sniffer_enabled) {
3493 mwl8k_cmd_enable_sniffer(hw, 0);
3494 priv->sniffer_enabled = false;
3497 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
3498 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3500 * Disable the BSS filter.
3502 mwl8k_cmd_set_pre_scan(hw);
3507 * Enable the BSS filter.
3509 * If there is an active STA interface, use that
3510 * interface's BSSID, otherwise use a dummy one
3511 * (where the OUI part needs to be nonzero for
3512 * the BSSID to be accepted by POST_SCAN).
3514 bssid = "\x01\x00\x00\x00\x00\x00";
3515 if (priv->vif != NULL)
3516 bssid = priv->vif->bss_conf.bssid;
3518 mwl8k_cmd_set_post_scan(hw, bssid);
3523 * If FIF_ALLMULTI is being requested, throw away the command
3524 * packet that ->prepare_multicast() built and replace it with
3525 * a command packet that enables reception of all multicast
3528 if (*total_flags & FIF_ALLMULTI) {
3530 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3534 mwl8k_post_cmd(hw, cmd);
3538 mwl8k_fw_unlock(hw);
3541 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3543 return mwl8k_cmd_set_rts_threshold(hw, value);
3546 struct mwl8k_sta_notify_item
3548 struct list_head list;
3549 struct ieee80211_vif *vif;
3550 enum sta_notify_cmd cmd;
3551 struct ieee80211_sta sta;
3555 mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3557 struct mwl8k_priv *priv = hw->priv;
3560 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3562 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3565 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3567 struct ieee80211_sta *sta;
3570 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3572 MWL8K_STA(sta)->peer_id = rc;
3575 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3576 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3577 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3578 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3579 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3580 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3584 static void mwl8k_sta_notify_worker(struct work_struct *work)
3586 struct mwl8k_priv *priv =
3587 container_of(work, struct mwl8k_priv, sta_notify_worker);
3588 struct ieee80211_hw *hw = priv->hw;
3590 spin_lock_bh(&priv->sta_notify_list_lock);
3591 while (!list_empty(&priv->sta_notify_list)) {
3592 struct mwl8k_sta_notify_item *s;
3594 s = list_entry(priv->sta_notify_list.next,
3595 struct mwl8k_sta_notify_item, list);
3598 spin_unlock_bh(&priv->sta_notify_list_lock);
3600 mwl8k_do_sta_notify(hw, s);
3603 spin_lock_bh(&priv->sta_notify_list_lock);
3605 spin_unlock_bh(&priv->sta_notify_list_lock);
3609 mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3610 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3612 struct mwl8k_priv *priv = hw->priv;
3613 struct mwl8k_sta_notify_item *s;
3615 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3618 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3624 spin_lock(&priv->sta_notify_list_lock);
3625 list_add_tail(&s->list, &priv->sta_notify_list);
3626 spin_unlock(&priv->sta_notify_list_lock);
3628 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3632 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3633 const struct ieee80211_tx_queue_params *params)
3635 struct mwl8k_priv *priv = hw->priv;
3638 rc = mwl8k_fw_lock(hw);
3640 if (!priv->wmm_enabled)
3641 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
3644 rc = mwl8k_cmd_set_edca_params(hw, queue,
3650 mwl8k_fw_unlock(hw);
3656 static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3657 struct ieee80211_tx_queue_stats *stats)
3659 struct mwl8k_priv *priv = hw->priv;
3660 struct mwl8k_tx_queue *txq;
3663 spin_lock_bh(&priv->tx_lock);
3664 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3665 txq = priv->txq + index;
3666 memcpy(&stats[index], &txq->stats,
3667 sizeof(struct ieee80211_tx_queue_stats));
3669 spin_unlock_bh(&priv->tx_lock);
3674 static int mwl8k_get_stats(struct ieee80211_hw *hw,
3675 struct ieee80211_low_level_stats *stats)
3677 return mwl8k_cmd_get_stat(hw, stats);
3681 mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3682 enum ieee80211_ampdu_mlme_action action,
3683 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3686 case IEEE80211_AMPDU_RX_START:
3687 case IEEE80211_AMPDU_RX_STOP:
3688 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3696 static const struct ieee80211_ops mwl8k_ops = {
3698 .start = mwl8k_start,
3700 .add_interface = mwl8k_add_interface,
3701 .remove_interface = mwl8k_remove_interface,
3702 .config = mwl8k_config,
3703 .bss_info_changed = mwl8k_bss_info_changed,
3704 .prepare_multicast = mwl8k_prepare_multicast,
3705 .configure_filter = mwl8k_configure_filter,
3706 .set_rts_threshold = mwl8k_set_rts_threshold,
3707 .sta_notify = mwl8k_sta_notify,
3708 .conf_tx = mwl8k_conf_tx,
3709 .get_tx_stats = mwl8k_get_tx_stats,
3710 .get_stats = mwl8k_get_stats,
3711 .ampdu_action = mwl8k_ampdu_action,
3714 static void mwl8k_finalize_join_worker(struct work_struct *work)
3716 struct mwl8k_priv *priv =
3717 container_of(work, struct mwl8k_priv, finalize_join_worker);
3718 struct sk_buff *skb = priv->beacon_skb;
3720 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len,
3721 priv->vif->bss_conf.dtim_period);
3724 priv->beacon_skb = NULL;
3733 static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3735 .part_name = "88w8363",
3736 .helper_image = "mwl8k/helper_8363.fw",
3737 .fw_image = "mwl8k/fmimage_8363.fw",
3740 .part_name = "88w8687",
3741 .helper_image = "mwl8k/helper_8687.fw",
3742 .fw_image = "mwl8k/fmimage_8687.fw",
3745 .part_name = "88w8366",
3746 .helper_image = "mwl8k/helper_8366.fw",
3747 .fw_image = "mwl8k/fmimage_8366.fw",
3748 .ap_rxd_ops = &rxd_8366_ap_ops,
3752 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3753 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3754 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3755 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3756 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3757 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3759 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
3760 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3761 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
3762 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3763 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3764 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3765 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
3768 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3770 static int __devinit mwl8k_probe(struct pci_dev *pdev,
3771 const struct pci_device_id *id)
3773 static int printed_version = 0;
3774 struct ieee80211_hw *hw;
3775 struct mwl8k_priv *priv;
3779 if (!printed_version) {
3780 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3781 printed_version = 1;
3785 rc = pci_enable_device(pdev);
3787 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3792 rc = pci_request_regions(pdev, MWL8K_NAME);
3794 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3796 goto err_disable_device;
3799 pci_set_master(pdev);
3802 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3804 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3809 SET_IEEE80211_DEV(hw, &pdev->dev);
3810 pci_set_drvdata(pdev, hw);
3815 priv->device_info = &mwl8k_info_tbl[id->driver_data];
3818 priv->sram = pci_iomap(pdev, 0, 0x10000);
3819 if (priv->sram == NULL) {
3820 printk(KERN_ERR "%s: Cannot map device SRAM\n",
3821 wiphy_name(hw->wiphy));
3826 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3827 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3829 priv->regs = pci_iomap(pdev, 1, 0x10000);
3830 if (priv->regs == NULL) {
3831 priv->regs = pci_iomap(pdev, 2, 0x10000);
3832 if (priv->regs == NULL) {
3833 printk(KERN_ERR "%s: Cannot map device registers\n",
3834 wiphy_name(hw->wiphy));
3840 /* Reset firmware and hardware */
3841 mwl8k_hw_reset(priv);
3843 /* Ask userland hotplug daemon for the device firmware */
3844 rc = mwl8k_request_firmware(priv);
3846 printk(KERN_ERR "%s: Firmware files not found\n",
3847 wiphy_name(hw->wiphy));
3848 goto err_stop_firmware;
3851 /* Load firmware into hardware */
3852 rc = mwl8k_load_firmware(hw);
3854 printk(KERN_ERR "%s: Cannot start firmware\n",
3855 wiphy_name(hw->wiphy));
3856 goto err_stop_firmware;
3859 /* Reclaim memory once firmware is successfully loaded */
3860 mwl8k_release_firmware(priv);
3864 priv->rxd_ops = priv->device_info->ap_rxd_ops;
3865 if (priv->rxd_ops == NULL) {
3866 printk(KERN_ERR "%s: Driver does not have AP "
3867 "firmware image support for this hardware\n",
3868 wiphy_name(hw->wiphy));
3869 goto err_stop_firmware;
3872 priv->rxd_ops = &rxd_sta_ops;
3875 priv->sniffer_enabled = false;
3876 priv->wmm_enabled = false;
3877 priv->pending_tx_pkts = 0;
3881 * Extra headroom is the size of the required DMA header
3882 * minus the size of the smallest 802.11 frame (CTS frame).
3884 hw->extra_tx_headroom =
3885 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3887 hw->channel_change_time = 10;
3889 hw->queues = MWL8K_TX_QUEUES;
3891 /* Set rssi and noise values to dBm */
3892 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
3893 hw->vif_data_size = sizeof(struct mwl8k_vif);
3894 hw->sta_data_size = sizeof(struct mwl8k_sta);
3897 /* Set default radio state and preamble */
3899 priv->radio_short_preamble = 0;
3901 /* Station database handling */
3902 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
3903 spin_lock_init(&priv->sta_notify_list_lock);
3904 INIT_LIST_HEAD(&priv->sta_notify_list);
3906 /* Finalize join worker */
3907 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3909 /* TX reclaim and RX tasklets. */
3910 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
3911 tasklet_disable(&priv->poll_tx_task);
3912 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
3913 tasklet_disable(&priv->poll_rx_task);
3915 /* Power management cookie */
3916 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3917 if (priv->cookie == NULL)
3918 goto err_stop_firmware;
3920 rc = mwl8k_rxq_init(hw, 0);
3922 goto err_free_cookie;
3923 rxq_refill(hw, 0, INT_MAX);
3925 mutex_init(&priv->fw_mutex);
3926 priv->fw_mutex_owner = NULL;
3927 priv->fw_mutex_depth = 0;
3928 priv->hostcmd_wait = NULL;
3930 spin_lock_init(&priv->tx_lock);
3932 priv->tx_wait = NULL;
3934 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3935 rc = mwl8k_txq_init(hw, i);
3937 goto err_free_queues;
3940 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3941 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3942 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
3943 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3944 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3946 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
3947 IRQF_SHARED, MWL8K_NAME, hw);
3949 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3950 wiphy_name(hw->wiphy));
3951 goto err_free_queues;
3955 * Temporarily enable interrupts. Initial firmware host
3956 * commands use interrupts and avoid polling. Disable
3957 * interrupts when done.
3959 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3961 /* Get config data, mac addrs etc */
3963 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3965 rc = mwl8k_cmd_set_hw_spec(hw);
3967 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_AP);
3969 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3971 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
3974 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3975 wiphy_name(hw->wiphy));
3979 /* Turn radio off */
3980 rc = mwl8k_cmd_radio_disable(hw);
3982 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
3986 /* Clear MAC address */
3987 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3989 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3990 wiphy_name(hw->wiphy));
3994 /* Disable interrupts */
3995 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3996 free_irq(priv->pdev->irq, hw);
3998 rc = ieee80211_register_hw(hw);
4000 printk(KERN_ERR "%s: Cannot register device\n",
4001 wiphy_name(hw->wiphy));
4002 goto err_free_queues;
4005 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
4006 wiphy_name(hw->wiphy), priv->device_info->part_name,
4007 priv->hw_rev, hw->wiphy->perm_addr,
4008 priv->ap_fw ? "AP" : "STA",
4009 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4010 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
4015 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4016 free_irq(priv->pdev->irq, hw);
4019 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4020 mwl8k_txq_deinit(hw, i);
4021 mwl8k_rxq_deinit(hw, 0);
4024 if (priv->cookie != NULL)
4025 pci_free_consistent(priv->pdev, 4,
4026 priv->cookie, priv->cookie_dma);
4029 mwl8k_hw_reset(priv);
4030 mwl8k_release_firmware(priv);
4033 if (priv->regs != NULL)
4034 pci_iounmap(pdev, priv->regs);
4036 if (priv->sram != NULL)
4037 pci_iounmap(pdev, priv->sram);
4039 pci_set_drvdata(pdev, NULL);
4040 ieee80211_free_hw(hw);
4043 pci_release_regions(pdev);
4046 pci_disable_device(pdev);
4051 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
4053 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4056 static void __devexit mwl8k_remove(struct pci_dev *pdev)
4058 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4059 struct mwl8k_priv *priv;
4066 ieee80211_stop_queues(hw);
4068 ieee80211_unregister_hw(hw);
4070 /* Remove TX reclaim and RX tasklets. */
4071 tasklet_kill(&priv->poll_tx_task);
4072 tasklet_kill(&priv->poll_rx_task);
4075 mwl8k_hw_reset(priv);
4077 /* Return all skbs to mac80211 */
4078 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4079 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
4081 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4082 mwl8k_txq_deinit(hw, i);
4084 mwl8k_rxq_deinit(hw, 0);
4086 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
4088 pci_iounmap(pdev, priv->regs);
4089 pci_iounmap(pdev, priv->sram);
4090 pci_set_drvdata(pdev, NULL);
4091 ieee80211_free_hw(hw);
4092 pci_release_regions(pdev);
4093 pci_disable_device(pdev);
4096 static struct pci_driver mwl8k_driver = {
4098 .id_table = mwl8k_pci_id_table,
4099 .probe = mwl8k_probe,
4100 .remove = __devexit_p(mwl8k_remove),
4101 .shutdown = __devexit_p(mwl8k_shutdown),
4104 static int __init mwl8k_init(void)
4106 return pci_register_driver(&mwl8k_driver);
4109 static void __exit mwl8k_exit(void)
4111 pci_unregister_driver(&mwl8k_driver);
4114 module_init(mwl8k_init);
4115 module_exit(mwl8k_exit);
4117 MODULE_DESCRIPTION(MWL8K_DESC);
4118 MODULE_VERSION(MWL8K_VERSION);
4119 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4120 MODULE_LICENSE("GPL");