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;
145 /* firmware access */
146 struct mutex fw_mutex;
147 struct task_struct *fw_mutex_owner;
149 struct completion *hostcmd_wait;
151 /* lock held over TX and TX reap */
154 /* TX quiesce completion, protected by fw_mutex and tx_lock */
155 struct completion *tx_wait;
157 struct ieee80211_vif *vif;
159 struct ieee80211_channel *current_channel;
161 /* power management status cookie from firmware */
163 dma_addr_t cookie_dma;
170 * Running count of TX packets in flight, to avoid
171 * iterating over the transmit rings each time.
175 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
176 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
179 struct ieee80211_supported_band band;
180 struct ieee80211_channel channels[14];
181 struct ieee80211_rate rates[14];
184 bool radio_short_preamble;
185 bool sniffer_enabled;
188 struct work_struct sta_notify_worker;
189 spinlock_t sta_notify_list_lock;
190 struct list_head sta_notify_list;
192 /* XXX need to convert this to handle multiple interfaces */
194 u8 capture_bssid[ETH_ALEN];
195 struct sk_buff *beacon_skb;
198 * This FJ worker has to be global as it is scheduled from the
199 * RX handler. At this point we don't know which interface it
200 * belongs to until the list of bssids waiting to complete join
203 struct work_struct finalize_join_worker;
205 /* Tasklet to perform TX reclaim. */
206 struct tasklet_struct poll_tx_task;
208 /* Tasklet to perform RX. */
209 struct tasklet_struct poll_rx_task;
212 /* Per interface specific private data */
214 /* Non AMPDU sequence number assigned by driver. */
217 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
220 /* Index into station database. Returned by UPDATE_STADB. */
223 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
225 static const struct ieee80211_channel mwl8k_channels[] = {
226 { .center_freq = 2412, .hw_value = 1, },
227 { .center_freq = 2417, .hw_value = 2, },
228 { .center_freq = 2422, .hw_value = 3, },
229 { .center_freq = 2427, .hw_value = 4, },
230 { .center_freq = 2432, .hw_value = 5, },
231 { .center_freq = 2437, .hw_value = 6, },
232 { .center_freq = 2442, .hw_value = 7, },
233 { .center_freq = 2447, .hw_value = 8, },
234 { .center_freq = 2452, .hw_value = 9, },
235 { .center_freq = 2457, .hw_value = 10, },
236 { .center_freq = 2462, .hw_value = 11, },
237 { .center_freq = 2467, .hw_value = 12, },
238 { .center_freq = 2472, .hw_value = 13, },
239 { .center_freq = 2484, .hw_value = 14, },
242 static const struct ieee80211_rate mwl8k_rates[] = {
243 { .bitrate = 10, .hw_value = 2, },
244 { .bitrate = 20, .hw_value = 4, },
245 { .bitrate = 55, .hw_value = 11, },
246 { .bitrate = 110, .hw_value = 22, },
247 { .bitrate = 220, .hw_value = 44, },
248 { .bitrate = 60, .hw_value = 12, },
249 { .bitrate = 90, .hw_value = 18, },
250 { .bitrate = 120, .hw_value = 24, },
251 { .bitrate = 180, .hw_value = 36, },
252 { .bitrate = 240, .hw_value = 48, },
253 { .bitrate = 360, .hw_value = 72, },
254 { .bitrate = 480, .hw_value = 96, },
255 { .bitrate = 540, .hw_value = 108, },
256 { .bitrate = 720, .hw_value = 144, },
259 /* Set or get info from Firmware */
260 #define MWL8K_CMD_SET 0x0001
261 #define MWL8K_CMD_GET 0x0000
263 /* Firmware command codes */
264 #define MWL8K_CMD_CODE_DNLD 0x0001
265 #define MWL8K_CMD_GET_HW_SPEC 0x0003
266 #define MWL8K_CMD_SET_HW_SPEC 0x0004
267 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
268 #define MWL8K_CMD_GET_STAT 0x0014
269 #define MWL8K_CMD_RADIO_CONTROL 0x001c
270 #define MWL8K_CMD_RF_TX_POWER 0x001e
271 #define MWL8K_CMD_RF_ANTENNA 0x0020
272 #define MWL8K_CMD_SET_BEACON 0x0100
273 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
274 #define MWL8K_CMD_SET_POST_SCAN 0x0108
275 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
276 #define MWL8K_CMD_SET_AID 0x010d
277 #define MWL8K_CMD_SET_RATE 0x0110
278 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
279 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
280 #define MWL8K_CMD_SET_SLOT 0x0114
281 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
282 #define MWL8K_CMD_SET_WMM_MODE 0x0123
283 #define MWL8K_CMD_MIMO_CONFIG 0x0125
284 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
285 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
286 #define MWL8K_CMD_SET_MAC_ADDR 0x0202
287 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
288 #define MWL8K_CMD_BSS_START 0x1100
289 #define MWL8K_CMD_SET_NEW_STN 0x1111
290 #define MWL8K_CMD_UPDATE_STADB 0x1123
292 static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
294 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
295 snprintf(buf, bufsize, "%s", #x);\
298 switch (cmd & ~0x8000) {
299 MWL8K_CMDNAME(CODE_DNLD);
300 MWL8K_CMDNAME(GET_HW_SPEC);
301 MWL8K_CMDNAME(SET_HW_SPEC);
302 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
303 MWL8K_CMDNAME(GET_STAT);
304 MWL8K_CMDNAME(RADIO_CONTROL);
305 MWL8K_CMDNAME(RF_TX_POWER);
306 MWL8K_CMDNAME(RF_ANTENNA);
307 MWL8K_CMDNAME(SET_BEACON);
308 MWL8K_CMDNAME(SET_PRE_SCAN);
309 MWL8K_CMDNAME(SET_POST_SCAN);
310 MWL8K_CMDNAME(SET_RF_CHANNEL);
311 MWL8K_CMDNAME(SET_AID);
312 MWL8K_CMDNAME(SET_RATE);
313 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
314 MWL8K_CMDNAME(RTS_THRESHOLD);
315 MWL8K_CMDNAME(SET_SLOT);
316 MWL8K_CMDNAME(SET_EDCA_PARAMS);
317 MWL8K_CMDNAME(SET_WMM_MODE);
318 MWL8K_CMDNAME(MIMO_CONFIG);
319 MWL8K_CMDNAME(USE_FIXED_RATE);
320 MWL8K_CMDNAME(ENABLE_SNIFFER);
321 MWL8K_CMDNAME(SET_MAC_ADDR);
322 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
323 MWL8K_CMDNAME(BSS_START);
324 MWL8K_CMDNAME(SET_NEW_STN);
325 MWL8K_CMDNAME(UPDATE_STADB);
327 snprintf(buf, bufsize, "0x%x", cmd);
334 /* Hardware and firmware reset */
335 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
337 iowrite32(MWL8K_H2A_INT_RESET,
338 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
339 iowrite32(MWL8K_H2A_INT_RESET,
340 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
344 /* Release fw image */
345 static void mwl8k_release_fw(struct firmware **fw)
349 release_firmware(*fw);
353 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
355 mwl8k_release_fw(&priv->fw_ucode);
356 mwl8k_release_fw(&priv->fw_helper);
359 /* Request fw image */
360 static int mwl8k_request_fw(struct mwl8k_priv *priv,
361 const char *fname, struct firmware **fw)
363 /* release current image */
365 mwl8k_release_fw(fw);
367 return request_firmware((const struct firmware **)fw,
368 fname, &priv->pdev->dev);
371 static int mwl8k_request_firmware(struct mwl8k_priv *priv)
373 struct mwl8k_device_info *di = priv->device_info;
376 if (di->helper_image != NULL) {
377 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
379 printk(KERN_ERR "%s: Error requesting helper "
380 "firmware file %s\n", pci_name(priv->pdev),
386 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
388 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
389 pci_name(priv->pdev), di->fw_image);
390 mwl8k_release_fw(&priv->fw_helper);
397 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
398 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
400 struct mwl8k_cmd_pkt {
406 } __attribute__((packed));
412 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
414 void __iomem *regs = priv->regs;
418 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
419 if (pci_dma_mapping_error(priv->pdev, dma_addr))
422 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
423 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
424 iowrite32(MWL8K_H2A_INT_DOORBELL,
425 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
426 iowrite32(MWL8K_H2A_INT_DUMMY,
427 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
433 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
434 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
435 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
443 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
445 return loops ? 0 : -ETIMEDOUT;
448 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
449 const u8 *data, size_t length)
451 struct mwl8k_cmd_pkt *cmd;
455 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
459 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
465 int block_size = length > 256 ? 256 : length;
467 memcpy(cmd->payload, data + done, block_size);
468 cmd->length = cpu_to_le16(block_size);
470 rc = mwl8k_send_fw_load_cmd(priv, cmd,
471 sizeof(*cmd) + block_size);
476 length -= block_size;
481 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
489 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
490 const u8 *data, size_t length)
492 unsigned char *buffer;
493 int may_continue, rc = 0;
494 u32 done, prev_block_size;
496 buffer = kmalloc(1024, GFP_KERNEL);
503 while (may_continue > 0) {
506 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
507 if (block_size & 1) {
511 done += prev_block_size;
512 length -= prev_block_size;
515 if (block_size > 1024 || block_size > length) {
525 if (block_size == 0) {
532 prev_block_size = block_size;
533 memcpy(buffer, data + done, block_size);
535 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
540 if (!rc && length != 0)
548 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
550 struct mwl8k_priv *priv = hw->priv;
551 struct firmware *fw = priv->fw_ucode;
555 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
556 struct firmware *helper = priv->fw_helper;
558 if (helper == NULL) {
559 printk(KERN_ERR "%s: helper image needed but none "
560 "given\n", pci_name(priv->pdev));
564 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
566 printk(KERN_ERR "%s: unable to load firmware "
567 "helper image\n", pci_name(priv->pdev));
572 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
574 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
578 printk(KERN_ERR "%s: unable to load firmware image\n",
579 pci_name(priv->pdev));
583 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
589 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
590 if (ready_code == MWL8K_FWAP_READY) {
593 } else if (ready_code == MWL8K_FWSTA_READY) {
602 return loops ? 0 : -ETIMEDOUT;
606 /* DMA header used by firmware and hardware. */
607 struct mwl8k_dma_data {
609 struct ieee80211_hdr wh;
611 } __attribute__((packed));
613 /* Routines to add/remove DMA header from skb. */
614 static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
616 struct mwl8k_dma_data *tr;
619 tr = (struct mwl8k_dma_data *)skb->data;
620 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
622 if (hdrlen != sizeof(tr->wh)) {
623 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
624 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
625 *((__le16 *)(tr->data - 2)) = qos;
627 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
631 if (hdrlen != sizeof(*tr))
632 skb_pull(skb, sizeof(*tr) - hdrlen);
635 static inline void mwl8k_add_dma_header(struct sk_buff *skb)
637 struct ieee80211_hdr *wh;
639 struct mwl8k_dma_data *tr;
642 * Add a firmware DMA header; the firmware requires that we
643 * present a 2-byte payload length followed by a 4-address
644 * header (without QoS field), followed (optionally) by any
645 * WEP/ExtIV header (but only filled in for CCMP).
647 wh = (struct ieee80211_hdr *)skb->data;
649 hdrlen = ieee80211_hdrlen(wh->frame_control);
650 if (hdrlen != sizeof(*tr))
651 skb_push(skb, sizeof(*tr) - hdrlen);
653 if (ieee80211_is_data_qos(wh->frame_control))
656 tr = (struct mwl8k_dma_data *)skb->data;
658 memmove(&tr->wh, wh, hdrlen);
659 if (hdrlen != sizeof(tr->wh))
660 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
663 * Firmware length is the length of the fully formed "802.11
664 * payload". That is, everything except for the 802.11 header.
665 * This includes all crypto material including the MIC.
667 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
672 * Packet reception for 88w8366 AP firmware.
674 struct mwl8k_rxd_8366_ap {
678 __le32 pkt_phys_addr;
679 __le32 next_rxd_phys_addr;
683 __le32 hw_noise_floor_info;
690 } __attribute__((packed));
692 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
693 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
694 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
696 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
698 static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
700 struct mwl8k_rxd_8366_ap *rxd = _rxd;
702 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
703 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
706 static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
708 struct mwl8k_rxd_8366_ap *rxd = _rxd;
710 rxd->pkt_len = cpu_to_le16(len);
711 rxd->pkt_phys_addr = cpu_to_le32(addr);
717 mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
720 struct mwl8k_rxd_8366_ap *rxd = _rxd;
722 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
726 memset(status, 0, sizeof(*status));
728 status->signal = -rxd->rssi;
729 status->noise = -rxd->noise_floor;
731 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
732 status->flag |= RX_FLAG_HT;
733 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
734 status->flag |= RX_FLAG_40MHZ;
735 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
739 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
740 if (mwl8k_rates[i].hw_value == rxd->rate) {
741 status->rate_idx = i;
747 status->band = IEEE80211_BAND_2GHZ;
748 status->freq = ieee80211_channel_to_frequency(rxd->channel);
750 *qos = rxd->qos_control;
752 return le16_to_cpu(rxd->pkt_len);
755 static struct rxd_ops rxd_8366_ap_ops = {
756 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
757 .rxd_init = mwl8k_rxd_8366_ap_init,
758 .rxd_refill = mwl8k_rxd_8366_ap_refill,
759 .rxd_process = mwl8k_rxd_8366_ap_process,
763 * Packet reception for STA firmware.
765 struct mwl8k_rxd_sta {
769 __le32 pkt_phys_addr;
770 __le32 next_rxd_phys_addr;
780 } __attribute__((packed));
782 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
783 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
784 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
785 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
786 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
787 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
789 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
791 static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
793 struct mwl8k_rxd_sta *rxd = _rxd;
795 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
796 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
799 static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
801 struct mwl8k_rxd_sta *rxd = _rxd;
803 rxd->pkt_len = cpu_to_le16(len);
804 rxd->pkt_phys_addr = cpu_to_le32(addr);
810 mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
813 struct mwl8k_rxd_sta *rxd = _rxd;
816 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
820 rate_info = le16_to_cpu(rxd->rate_info);
822 memset(status, 0, sizeof(*status));
824 status->signal = -rxd->rssi;
825 status->noise = -rxd->noise_level;
826 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
827 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
829 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
830 status->flag |= RX_FLAG_SHORTPRE;
831 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
832 status->flag |= RX_FLAG_40MHZ;
833 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
834 status->flag |= RX_FLAG_SHORT_GI;
835 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
836 status->flag |= RX_FLAG_HT;
838 status->band = IEEE80211_BAND_2GHZ;
839 status->freq = ieee80211_channel_to_frequency(rxd->channel);
841 *qos = rxd->qos_control;
843 return le16_to_cpu(rxd->pkt_len);
846 static struct rxd_ops rxd_sta_ops = {
847 .rxd_size = sizeof(struct mwl8k_rxd_sta),
848 .rxd_init = mwl8k_rxd_sta_init,
849 .rxd_refill = mwl8k_rxd_sta_refill,
850 .rxd_process = mwl8k_rxd_sta_process,
854 #define MWL8K_RX_DESCS 256
855 #define MWL8K_RX_MAXSZ 3800
857 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
859 struct mwl8k_priv *priv = hw->priv;
860 struct mwl8k_rx_queue *rxq = priv->rxq + index;
868 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
870 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
871 if (rxq->rxd == NULL) {
872 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
873 wiphy_name(hw->wiphy));
876 memset(rxq->rxd, 0, size);
878 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
879 if (rxq->buf == NULL) {
880 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
881 wiphy_name(hw->wiphy));
882 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
885 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
887 for (i = 0; i < MWL8K_RX_DESCS; i++) {
891 dma_addr_t next_dma_addr;
893 desc_size = priv->rxd_ops->rxd_size;
894 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
897 if (nexti == MWL8K_RX_DESCS)
899 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
901 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
907 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
909 struct mwl8k_priv *priv = hw->priv;
910 struct mwl8k_rx_queue *rxq = priv->rxq + index;
914 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
920 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
924 addr = pci_map_single(priv->pdev, skb->data,
925 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
929 if (rxq->tail == MWL8K_RX_DESCS)
931 rxq->buf[rx].skb = skb;
932 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
934 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
935 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
943 /* Must be called only when the card's reception is completely halted */
944 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
946 struct mwl8k_priv *priv = hw->priv;
947 struct mwl8k_rx_queue *rxq = priv->rxq + index;
950 for (i = 0; i < MWL8K_RX_DESCS; i++) {
951 if (rxq->buf[i].skb != NULL) {
952 pci_unmap_single(priv->pdev,
953 pci_unmap_addr(&rxq->buf[i], dma),
954 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
955 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
957 kfree_skb(rxq->buf[i].skb);
958 rxq->buf[i].skb = NULL;
965 pci_free_consistent(priv->pdev,
966 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
967 rxq->rxd, rxq->rxd_dma);
973 * Scan a list of BSSIDs to process for finalize join.
974 * Allows for extension to process multiple BSSIDs.
977 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
979 return priv->capture_beacon &&
980 ieee80211_is_beacon(wh->frame_control) &&
981 !compare_ether_addr(wh->addr3, priv->capture_bssid);
984 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
987 struct mwl8k_priv *priv = hw->priv;
989 priv->capture_beacon = false;
990 memset(priv->capture_bssid, 0, ETH_ALEN);
993 * Use GFP_ATOMIC as rxq_process is called from
994 * the primary interrupt handler, memory allocation call
997 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
998 if (priv->beacon_skb != NULL)
999 ieee80211_queue_work(hw, &priv->finalize_join_worker);
1002 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1004 struct mwl8k_priv *priv = hw->priv;
1005 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1009 while (rxq->rxd_count && limit--) {
1010 struct sk_buff *skb;
1013 struct ieee80211_rx_status status;
1016 skb = rxq->buf[rxq->head].skb;
1020 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1022 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
1026 rxq->buf[rxq->head].skb = NULL;
1028 pci_unmap_single(priv->pdev,
1029 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1030 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1031 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1034 if (rxq->head == MWL8K_RX_DESCS)
1039 skb_put(skb, pkt_len);
1040 mwl8k_remove_dma_header(skb, qos);
1043 * Check for a pending join operation. Save a
1044 * copy of the beacon and schedule a tasklet to
1045 * send a FINALIZE_JOIN command to the firmware.
1047 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1048 mwl8k_save_beacon(hw, skb);
1050 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1051 ieee80211_rx_irqsafe(hw, skb);
1061 * Packet transmission.
1064 #define MWL8K_TXD_STATUS_OK 0x00000001
1065 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1066 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1067 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1068 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1070 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1071 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1072 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1073 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1074 #define MWL8K_QOS_EOSP 0x0010
1076 struct mwl8k_tx_desc {
1081 __le32 pkt_phys_addr;
1083 __u8 dest_MAC_addr[ETH_ALEN];
1084 __le32 next_txd_phys_addr;
1089 } __attribute__((packed));
1091 #define MWL8K_TX_DESCS 128
1093 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1095 struct mwl8k_priv *priv = hw->priv;
1096 struct mwl8k_tx_queue *txq = priv->txq + index;
1100 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1101 txq->stats.limit = MWL8K_TX_DESCS;
1105 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1107 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1108 if (txq->txd == NULL) {
1109 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1110 wiphy_name(hw->wiphy));
1113 memset(txq->txd, 0, size);
1115 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1116 if (txq->skb == NULL) {
1117 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1118 wiphy_name(hw->wiphy));
1119 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1122 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
1124 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1125 struct mwl8k_tx_desc *tx_desc;
1128 tx_desc = txq->txd + i;
1129 nexti = (i + 1) % MWL8K_TX_DESCS;
1131 tx_desc->status = 0;
1132 tx_desc->next_txd_phys_addr =
1133 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1139 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1141 iowrite32(MWL8K_H2A_INT_PPA_READY,
1142 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1143 iowrite32(MWL8K_H2A_INT_DUMMY,
1144 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1145 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1148 static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1150 struct mwl8k_priv *priv = hw->priv;
1153 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1154 struct mwl8k_tx_queue *txq = priv->txq + i;
1160 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1161 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1164 status = le32_to_cpu(tx_desc->status);
1165 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1170 if (tx_desc->pkt_len == 0)
1174 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1175 "fw_owned=%d drv_owned=%d unused=%d\n",
1176 wiphy_name(hw->wiphy), i,
1177 txq->stats.len, txq->head, txq->tail,
1178 fw_owned, drv_owned, unused);
1183 * Must be called with priv->fw_mutex held and tx queues stopped.
1185 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1187 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1189 struct mwl8k_priv *priv = hw->priv;
1190 DECLARE_COMPLETION_ONSTACK(tx_wait);
1197 * The TX queues are stopped at this point, so this test
1198 * doesn't need to take ->tx_lock.
1200 if (!priv->pending_tx_pkts)
1206 spin_lock_bh(&priv->tx_lock);
1207 priv->tx_wait = &tx_wait;
1210 unsigned long timeout;
1212 oldcount = priv->pending_tx_pkts;
1214 spin_unlock_bh(&priv->tx_lock);
1215 timeout = wait_for_completion_timeout(&tx_wait,
1216 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1217 spin_lock_bh(&priv->tx_lock);
1220 WARN_ON(priv->pending_tx_pkts);
1222 printk(KERN_NOTICE "%s: tx rings drained\n",
1223 wiphy_name(hw->wiphy));
1228 if (priv->pending_tx_pkts < oldcount) {
1229 printk(KERN_NOTICE "%s: waiting for tx rings "
1230 "to drain (%d -> %d pkts)\n",
1231 wiphy_name(hw->wiphy), oldcount,
1232 priv->pending_tx_pkts);
1237 priv->tx_wait = NULL;
1239 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1240 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1241 mwl8k_dump_tx_rings(hw);
1245 spin_unlock_bh(&priv->tx_lock);
1250 #define MWL8K_TXD_SUCCESS(status) \
1251 ((status) & (MWL8K_TXD_STATUS_OK | \
1252 MWL8K_TXD_STATUS_OK_RETRY | \
1253 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1256 mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1258 struct mwl8k_priv *priv = hw->priv;
1259 struct mwl8k_tx_queue *txq = priv->txq + index;
1263 while (txq->stats.len > 0 && limit--) {
1265 struct mwl8k_tx_desc *tx_desc;
1268 struct sk_buff *skb;
1269 struct ieee80211_tx_info *info;
1273 tx_desc = txq->txd + tx;
1275 status = le32_to_cpu(tx_desc->status);
1277 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1281 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1284 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1285 BUG_ON(txq->stats.len == 0);
1287 priv->pending_tx_pkts--;
1289 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1290 size = le16_to_cpu(tx_desc->pkt_len);
1292 txq->skb[tx] = NULL;
1294 BUG_ON(skb == NULL);
1295 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1297 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
1299 /* Mark descriptor as unused */
1300 tx_desc->pkt_phys_addr = 0;
1301 tx_desc->pkt_len = 0;
1303 info = IEEE80211_SKB_CB(skb);
1304 ieee80211_tx_info_clear_status(info);
1305 if (MWL8K_TXD_SUCCESS(status))
1306 info->flags |= IEEE80211_TX_STAT_ACK;
1308 ieee80211_tx_status_irqsafe(hw, skb);
1313 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
1314 ieee80211_wake_queue(hw, index);
1319 /* must be called only when the card's transmit is completely halted */
1320 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1322 struct mwl8k_priv *priv = hw->priv;
1323 struct mwl8k_tx_queue *txq = priv->txq + index;
1325 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1330 pci_free_consistent(priv->pdev,
1331 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1332 txq->txd, txq->txd_dma);
1337 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1339 struct mwl8k_priv *priv = hw->priv;
1340 struct ieee80211_tx_info *tx_info;
1341 struct mwl8k_vif *mwl8k_vif;
1342 struct ieee80211_hdr *wh;
1343 struct mwl8k_tx_queue *txq;
1344 struct mwl8k_tx_desc *tx;
1350 wh = (struct ieee80211_hdr *)skb->data;
1351 if (ieee80211_is_data_qos(wh->frame_control))
1352 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1356 mwl8k_add_dma_header(skb);
1357 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1359 tx_info = IEEE80211_SKB_CB(skb);
1360 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1362 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1363 u16 seqno = mwl8k_vif->seqno;
1365 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1366 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1367 mwl8k_vif->seqno = seqno++ % 4096;
1370 /* Setup firmware control bit fields for each frame type. */
1373 if (ieee80211_is_mgmt(wh->frame_control) ||
1374 ieee80211_is_ctl(wh->frame_control)) {
1376 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1377 } else if (ieee80211_is_data(wh->frame_control)) {
1379 if (is_multicast_ether_addr(wh->addr1))
1380 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1382 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1383 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1384 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1386 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1389 dma = pci_map_single(priv->pdev, skb->data,
1390 skb->len, PCI_DMA_TODEVICE);
1392 if (pci_dma_mapping_error(priv->pdev, dma)) {
1393 printk(KERN_DEBUG "%s: failed to dma map skb, "
1394 "dropping TX frame.\n", wiphy_name(hw->wiphy));
1396 return NETDEV_TX_OK;
1399 spin_lock_bh(&priv->tx_lock);
1401 txq = priv->txq + index;
1403 BUG_ON(txq->skb[txq->tail] != NULL);
1404 txq->skb[txq->tail] = skb;
1406 tx = txq->txd + txq->tail;
1407 tx->data_rate = txdatarate;
1408 tx->tx_priority = index;
1409 tx->qos_control = cpu_to_le16(qos);
1410 tx->pkt_phys_addr = cpu_to_le32(dma);
1411 tx->pkt_len = cpu_to_le16(skb->len);
1413 if (!priv->ap_fw && tx_info->control.sta != NULL)
1414 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1418 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1422 priv->pending_tx_pkts++;
1425 if (txq->tail == MWL8K_TX_DESCS)
1428 if (txq->head == txq->tail)
1429 ieee80211_stop_queue(hw, index);
1431 mwl8k_tx_start(priv);
1433 spin_unlock_bh(&priv->tx_lock);
1435 return NETDEV_TX_OK;
1442 * We have the following requirements for issuing firmware commands:
1443 * - Some commands require that the packet transmit path is idle when
1444 * the command is issued. (For simplicity, we'll just quiesce the
1445 * transmit path for every command.)
1446 * - There are certain sequences of commands that need to be issued to
1447 * the hardware sequentially, with no other intervening commands.
1449 * This leads to an implementation of a "firmware lock" as a mutex that
1450 * can be taken recursively, and which is taken by both the low-level
1451 * command submission function (mwl8k_post_cmd) as well as any users of
1452 * that function that require issuing of an atomic sequence of commands,
1453 * and quiesces the transmit path whenever it's taken.
1455 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1457 struct mwl8k_priv *priv = hw->priv;
1459 if (priv->fw_mutex_owner != current) {
1462 mutex_lock(&priv->fw_mutex);
1463 ieee80211_stop_queues(hw);
1465 rc = mwl8k_tx_wait_empty(hw);
1467 ieee80211_wake_queues(hw);
1468 mutex_unlock(&priv->fw_mutex);
1473 priv->fw_mutex_owner = current;
1476 priv->fw_mutex_depth++;
1481 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1483 struct mwl8k_priv *priv = hw->priv;
1485 if (!--priv->fw_mutex_depth) {
1486 ieee80211_wake_queues(hw);
1487 priv->fw_mutex_owner = NULL;
1488 mutex_unlock(&priv->fw_mutex);
1494 * Command processing.
1497 /* Timeout firmware commands after 10s */
1498 #define MWL8K_CMD_TIMEOUT_MS 10000
1500 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1502 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1503 struct mwl8k_priv *priv = hw->priv;
1504 void __iomem *regs = priv->regs;
1505 dma_addr_t dma_addr;
1506 unsigned int dma_size;
1508 unsigned long timeout = 0;
1511 cmd->result = 0xffff;
1512 dma_size = le16_to_cpu(cmd->length);
1513 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1514 PCI_DMA_BIDIRECTIONAL);
1515 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1518 rc = mwl8k_fw_lock(hw);
1520 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1521 PCI_DMA_BIDIRECTIONAL);
1525 priv->hostcmd_wait = &cmd_wait;
1526 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1527 iowrite32(MWL8K_H2A_INT_DOORBELL,
1528 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1529 iowrite32(MWL8K_H2A_INT_DUMMY,
1530 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1532 timeout = wait_for_completion_timeout(&cmd_wait,
1533 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1535 priv->hostcmd_wait = NULL;
1537 mwl8k_fw_unlock(hw);
1539 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1540 PCI_DMA_BIDIRECTIONAL);
1543 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1544 wiphy_name(hw->wiphy),
1545 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1546 MWL8K_CMD_TIMEOUT_MS);
1551 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1553 rc = cmd->result ? -EINVAL : 0;
1555 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1556 wiphy_name(hw->wiphy),
1557 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1558 le16_to_cpu(cmd->result));
1560 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1561 wiphy_name(hw->wiphy),
1562 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1570 * CMD_GET_HW_SPEC (STA version).
1572 struct mwl8k_cmd_get_hw_spec_sta {
1573 struct mwl8k_cmd_pkt header;
1575 __u8 host_interface;
1577 __u8 perm_addr[ETH_ALEN];
1582 __u8 mcs_bitmap[16];
1583 __le32 rx_queue_ptr;
1584 __le32 num_tx_queues;
1585 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1587 __le32 num_tx_desc_per_queue;
1589 } __attribute__((packed));
1591 #define MWL8K_CAP_MAX_AMSDU 0x20000000
1592 #define MWL8K_CAP_GREENFIELD 0x08000000
1593 #define MWL8K_CAP_AMPDU 0x04000000
1594 #define MWL8K_CAP_RX_STBC 0x01000000
1595 #define MWL8K_CAP_TX_STBC 0x00800000
1596 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1597 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1598 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1599 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1600 #define MWL8K_CAP_DELAY_BA 0x00003000
1601 #define MWL8K_CAP_MIMO 0x00000200
1602 #define MWL8K_CAP_40MHZ 0x00000100
1604 static void mwl8k_set_ht_caps(struct ieee80211_hw *hw, u32 cap)
1606 struct mwl8k_priv *priv = hw->priv;
1610 priv->band.ht_cap.ht_supported = 1;
1612 if (cap & MWL8K_CAP_MAX_AMSDU)
1613 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
1614 if (cap & MWL8K_CAP_GREENFIELD)
1615 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
1616 if (cap & MWL8K_CAP_AMPDU) {
1617 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
1618 priv->band.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1619 priv->band.ht_cap.ampdu_density =
1620 IEEE80211_HT_MPDU_DENSITY_NONE;
1622 if (cap & MWL8K_CAP_RX_STBC)
1623 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
1624 if (cap & MWL8K_CAP_TX_STBC)
1625 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
1626 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
1627 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
1628 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
1629 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
1630 if (cap & MWL8K_CAP_DELAY_BA)
1631 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
1632 if (cap & MWL8K_CAP_40MHZ)
1633 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1635 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1636 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1638 priv->band.ht_cap.mcs.rx_mask[0] = 0xff;
1639 if (rx_streams >= 2)
1640 priv->band.ht_cap.mcs.rx_mask[1] = 0xff;
1641 if (rx_streams >= 3)
1642 priv->band.ht_cap.mcs.rx_mask[2] = 0xff;
1643 priv->band.ht_cap.mcs.rx_mask[4] = 0x01;
1644 priv->band.ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1646 if (rx_streams != tx_streams) {
1647 priv->band.ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1648 priv->band.ht_cap.mcs.tx_params |= (tx_streams - 1) <<
1649 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1653 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
1655 struct mwl8k_priv *priv = hw->priv;
1656 struct mwl8k_cmd_get_hw_spec_sta *cmd;
1660 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1664 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1665 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1667 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1668 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1669 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1670 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1671 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1672 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1673 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1674 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1676 rc = mwl8k_post_cmd(hw, &cmd->header);
1679 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1680 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1681 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1682 priv->hw_rev = cmd->hw_rev;
1683 if (cmd->caps & cpu_to_le32(MWL8K_CAP_MIMO))
1684 mwl8k_set_ht_caps(hw, le32_to_cpu(cmd->caps));
1692 * CMD_GET_HW_SPEC (AP version).
1694 struct mwl8k_cmd_get_hw_spec_ap {
1695 struct mwl8k_cmd_pkt header;
1697 __u8 host_interface;
1700 __u8 perm_addr[ETH_ALEN];
1711 } __attribute__((packed));
1713 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1715 struct mwl8k_priv *priv = hw->priv;
1716 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1719 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1723 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1724 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1726 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1727 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1729 rc = mwl8k_post_cmd(hw, &cmd->header);
1734 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1735 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1736 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1737 priv->hw_rev = cmd->hw_rev;
1739 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1740 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1742 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1743 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1745 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1746 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1748 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1749 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1751 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1752 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1754 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1755 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1765 struct mwl8k_cmd_set_hw_spec {
1766 struct mwl8k_cmd_pkt header;
1768 __u8 host_interface;
1770 __u8 perm_addr[ETH_ALEN];
1775 __le32 rx_queue_ptr;
1776 __le32 num_tx_queues;
1777 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1779 __le32 num_tx_desc_per_queue;
1781 } __attribute__((packed));
1783 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1784 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1785 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
1787 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1789 struct mwl8k_priv *priv = hw->priv;
1790 struct mwl8k_cmd_set_hw_spec *cmd;
1794 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1798 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1799 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1801 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1802 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1803 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1804 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1805 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1806 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1807 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1808 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
1809 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1810 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1812 rc = mwl8k_post_cmd(hw, &cmd->header);
1819 * CMD_MAC_MULTICAST_ADR.
1821 struct mwl8k_cmd_mac_multicast_adr {
1822 struct mwl8k_cmd_pkt header;
1825 __u8 addr[0][ETH_ALEN];
1828 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
1829 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
1830 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1831 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
1833 static struct mwl8k_cmd_pkt *
1834 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
1835 int mc_count, struct dev_addr_list *mclist)
1837 struct mwl8k_priv *priv = hw->priv;
1838 struct mwl8k_cmd_mac_multicast_adr *cmd;
1841 if (allmulti || mc_count > priv->num_mcaddrs) {
1846 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1848 cmd = kzalloc(size, GFP_ATOMIC);
1852 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1853 cmd->header.length = cpu_to_le16(size);
1854 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1855 MWL8K_ENABLE_RX_BROADCAST);
1858 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1859 } else if (mc_count) {
1862 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1863 cmd->numaddr = cpu_to_le16(mc_count);
1864 for (i = 0; i < mc_count && mclist; i++) {
1865 if (mclist->da_addrlen != ETH_ALEN) {
1869 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1870 mclist = mclist->next;
1874 return &cmd->header;
1880 struct mwl8k_cmd_get_stat {
1881 struct mwl8k_cmd_pkt header;
1883 } __attribute__((packed));
1885 #define MWL8K_STAT_ACK_FAILURE 9
1886 #define MWL8K_STAT_RTS_FAILURE 12
1887 #define MWL8K_STAT_FCS_ERROR 24
1888 #define MWL8K_STAT_RTS_SUCCESS 11
1890 static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1891 struct ieee80211_low_level_stats *stats)
1893 struct mwl8k_cmd_get_stat *cmd;
1896 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1900 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1901 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1903 rc = mwl8k_post_cmd(hw, &cmd->header);
1905 stats->dot11ACKFailureCount =
1906 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1907 stats->dot11RTSFailureCount =
1908 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1909 stats->dot11FCSErrorCount =
1910 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1911 stats->dot11RTSSuccessCount =
1912 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1920 * CMD_RADIO_CONTROL.
1922 struct mwl8k_cmd_radio_control {
1923 struct mwl8k_cmd_pkt header;
1927 } __attribute__((packed));
1930 mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
1932 struct mwl8k_priv *priv = hw->priv;
1933 struct mwl8k_cmd_radio_control *cmd;
1936 if (enable == priv->radio_on && !force)
1939 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1943 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1944 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1945 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1946 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
1947 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1949 rc = mwl8k_post_cmd(hw, &cmd->header);
1953 priv->radio_on = enable;
1958 static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
1960 return mwl8k_cmd_radio_control(hw, 0, 0);
1963 static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
1965 return mwl8k_cmd_radio_control(hw, 1, 0);
1969 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1971 struct mwl8k_priv *priv = hw->priv;
1973 priv->radio_short_preamble = short_preamble;
1975 return mwl8k_cmd_radio_control(hw, 1, 1);
1981 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1983 struct mwl8k_cmd_rf_tx_power {
1984 struct mwl8k_cmd_pkt header;
1986 __le16 support_level;
1987 __le16 current_level;
1989 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1990 } __attribute__((packed));
1992 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1994 struct mwl8k_cmd_rf_tx_power *cmd;
1997 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2001 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2002 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2003 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2004 cmd->support_level = cpu_to_le16(dBm);
2006 rc = mwl8k_post_cmd(hw, &cmd->header);
2015 struct mwl8k_cmd_rf_antenna {
2016 struct mwl8k_cmd_pkt header;
2019 } __attribute__((packed));
2021 #define MWL8K_RF_ANTENNA_RX 1
2022 #define MWL8K_RF_ANTENNA_TX 2
2025 mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2027 struct mwl8k_cmd_rf_antenna *cmd;
2030 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2034 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2035 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2036 cmd->antenna = cpu_to_le16(antenna);
2037 cmd->mode = cpu_to_le16(mask);
2039 rc = mwl8k_post_cmd(hw, &cmd->header);
2048 struct mwl8k_cmd_set_beacon {
2049 struct mwl8k_cmd_pkt header;
2054 static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, u8 *beacon, int len)
2056 struct mwl8k_cmd_set_beacon *cmd;
2059 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2063 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2064 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2065 cmd->beacon_len = cpu_to_le16(len);
2066 memcpy(cmd->beacon, beacon, len);
2068 rc = mwl8k_post_cmd(hw, &cmd->header);
2077 struct mwl8k_cmd_set_pre_scan {
2078 struct mwl8k_cmd_pkt header;
2079 } __attribute__((packed));
2081 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2083 struct mwl8k_cmd_set_pre_scan *cmd;
2086 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2090 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2091 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2093 rc = mwl8k_post_cmd(hw, &cmd->header);
2100 * CMD_SET_POST_SCAN.
2102 struct mwl8k_cmd_set_post_scan {
2103 struct mwl8k_cmd_pkt header;
2105 __u8 bssid[ETH_ALEN];
2106 } __attribute__((packed));
2109 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2111 struct mwl8k_cmd_set_post_scan *cmd;
2114 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2118 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2119 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2121 memcpy(cmd->bssid, mac, ETH_ALEN);
2123 rc = mwl8k_post_cmd(hw, &cmd->header);
2130 * CMD_SET_RF_CHANNEL.
2132 struct mwl8k_cmd_set_rf_channel {
2133 struct mwl8k_cmd_pkt header;
2135 __u8 current_channel;
2136 __le32 channel_flags;
2137 } __attribute__((packed));
2139 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2140 struct ieee80211_conf *conf)
2142 struct ieee80211_channel *channel = conf->channel;
2143 struct mwl8k_cmd_set_rf_channel *cmd;
2146 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2150 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2151 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2152 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2153 cmd->current_channel = channel->hw_value;
2155 if (channel->band == IEEE80211_BAND_2GHZ)
2156 cmd->channel_flags |= cpu_to_le32(0x00000001);
2158 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2159 conf->channel_type == NL80211_CHAN_HT20)
2160 cmd->channel_flags |= cpu_to_le32(0x00000080);
2161 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2162 cmd->channel_flags |= cpu_to_le32(0x000001900);
2163 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2164 cmd->channel_flags |= cpu_to_le32(0x000000900);
2166 rc = mwl8k_post_cmd(hw, &cmd->header);
2175 #define MWL8K_FRAME_PROT_DISABLED 0x00
2176 #define MWL8K_FRAME_PROT_11G 0x07
2177 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2178 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2180 struct mwl8k_cmd_update_set_aid {
2181 struct mwl8k_cmd_pkt header;
2184 /* AP's MAC address (BSSID) */
2185 __u8 bssid[ETH_ALEN];
2186 __le16 protection_mode;
2187 __u8 supp_rates[14];
2188 } __attribute__((packed));
2190 static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2196 * Clear nonstandard rates 4 and 13.
2200 for (i = 0, j = 0; i < 14; i++) {
2201 if (mask & (1 << i))
2202 rates[j++] = mwl8k_rates[i].hw_value;
2207 mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2208 struct ieee80211_vif *vif, u32 legacy_rate_mask)
2210 struct mwl8k_cmd_update_set_aid *cmd;
2214 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2218 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2219 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2220 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
2221 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
2223 if (vif->bss_conf.use_cts_prot) {
2224 prot_mode = MWL8K_FRAME_PROT_11G;
2226 switch (vif->bss_conf.ht_operation_mode &
2227 IEEE80211_HT_OP_MODE_PROTECTION) {
2228 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2229 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2231 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2232 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2235 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2239 cmd->protection_mode = cpu_to_le16(prot_mode);
2241 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
2243 rc = mwl8k_post_cmd(hw, &cmd->header);
2252 struct mwl8k_cmd_set_rate {
2253 struct mwl8k_cmd_pkt header;
2254 __u8 legacy_rates[14];
2256 /* Bitmap for supported MCS codes. */
2259 } __attribute__((packed));
2262 mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2263 u32 legacy_rate_mask, u8 *mcs_rates)
2265 struct mwl8k_cmd_set_rate *cmd;
2268 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2272 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2273 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2274 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
2275 memcpy(cmd->mcs_set, mcs_rates, 16);
2277 rc = mwl8k_post_cmd(hw, &cmd->header);
2284 * CMD_FINALIZE_JOIN.
2286 #define MWL8K_FJ_BEACON_MAXLEN 128
2288 struct mwl8k_cmd_finalize_join {
2289 struct mwl8k_cmd_pkt header;
2290 __le32 sleep_interval; /* Number of beacon periods to sleep */
2291 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2292 } __attribute__((packed));
2294 static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2295 int framelen, int dtim)
2297 struct mwl8k_cmd_finalize_join *cmd;
2298 struct ieee80211_mgmt *payload = frame;
2302 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2306 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2307 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2308 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2310 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2311 if (payload_len < 0)
2313 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2314 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2316 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2318 rc = mwl8k_post_cmd(hw, &cmd->header);
2325 * CMD_SET_RTS_THRESHOLD.
2327 struct mwl8k_cmd_set_rts_threshold {
2328 struct mwl8k_cmd_pkt header;
2331 } __attribute__((packed));
2334 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
2336 struct mwl8k_cmd_set_rts_threshold *cmd;
2339 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2343 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2344 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2345 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2346 cmd->threshold = cpu_to_le16(rts_thresh);
2348 rc = mwl8k_post_cmd(hw, &cmd->header);
2357 struct mwl8k_cmd_set_slot {
2358 struct mwl8k_cmd_pkt header;
2361 } __attribute__((packed));
2363 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
2365 struct mwl8k_cmd_set_slot *cmd;
2368 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2372 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2373 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2374 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2375 cmd->short_slot = short_slot_time;
2377 rc = mwl8k_post_cmd(hw, &cmd->header);
2384 * CMD_SET_EDCA_PARAMS.
2386 struct mwl8k_cmd_set_edca_params {
2387 struct mwl8k_cmd_pkt header;
2389 /* See MWL8K_SET_EDCA_XXX below */
2392 /* TX opportunity in units of 32 us */
2397 /* Log exponent of max contention period: 0...15 */
2400 /* Log exponent of min contention period: 0...15 */
2403 /* Adaptive interframe spacing in units of 32us */
2406 /* TX queue to configure */
2410 /* Log exponent of max contention period: 0...15 */
2413 /* Log exponent of min contention period: 0...15 */
2416 /* Adaptive interframe spacing in units of 32us */
2419 /* TX queue to configure */
2423 } __attribute__((packed));
2425 #define MWL8K_SET_EDCA_CW 0x01
2426 #define MWL8K_SET_EDCA_TXOP 0x02
2427 #define MWL8K_SET_EDCA_AIFS 0x04
2429 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2430 MWL8K_SET_EDCA_TXOP | \
2431 MWL8K_SET_EDCA_AIFS)
2434 mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2435 __u16 cw_min, __u16 cw_max,
2436 __u8 aifs, __u16 txop)
2438 struct mwl8k_priv *priv = hw->priv;
2439 struct mwl8k_cmd_set_edca_params *cmd;
2442 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2446 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2447 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2448 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2449 cmd->txop = cpu_to_le16(txop);
2451 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2452 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2453 cmd->ap.aifs = aifs;
2456 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2457 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2458 cmd->sta.aifs = aifs;
2459 cmd->sta.txq = qnum;
2462 rc = mwl8k_post_cmd(hw, &cmd->header);
2471 struct mwl8k_cmd_set_wmm_mode {
2472 struct mwl8k_cmd_pkt header;
2474 } __attribute__((packed));
2476 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
2478 struct mwl8k_priv *priv = hw->priv;
2479 struct mwl8k_cmd_set_wmm_mode *cmd;
2482 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2486 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2487 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2488 cmd->action = cpu_to_le16(!!enable);
2490 rc = mwl8k_post_cmd(hw, &cmd->header);
2494 priv->wmm_enabled = enable;
2502 struct mwl8k_cmd_mimo_config {
2503 struct mwl8k_cmd_pkt header;
2505 __u8 rx_antenna_map;
2506 __u8 tx_antenna_map;
2507 } __attribute__((packed));
2509 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2511 struct mwl8k_cmd_mimo_config *cmd;
2514 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2518 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2519 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2520 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2521 cmd->rx_antenna_map = rx;
2522 cmd->tx_antenna_map = tx;
2524 rc = mwl8k_post_cmd(hw, &cmd->header);
2531 * CMD_USE_FIXED_RATE (STA version).
2533 struct mwl8k_cmd_use_fixed_rate_sta {
2534 struct mwl8k_cmd_pkt header;
2536 __le32 allow_rate_drop;
2540 __le32 enable_retry;
2547 } __attribute__((packed));
2549 #define MWL8K_USE_AUTO_RATE 0x0002
2550 #define MWL8K_UCAST_RATE 0
2552 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
2554 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
2557 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2561 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2562 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2563 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2564 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
2566 rc = mwl8k_post_cmd(hw, &cmd->header);
2573 * CMD_USE_FIXED_RATE (AP version).
2575 struct mwl8k_cmd_use_fixed_rate_ap {
2576 struct mwl8k_cmd_pkt header;
2578 __le32 allow_rate_drop;
2580 struct mwl8k_rate_entry_ap {
2582 __le32 enable_retry;
2587 u8 multicast_rate_type;
2589 } __attribute__((packed));
2592 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2594 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2597 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2601 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2602 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2603 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2604 cmd->multicast_rate = mcast;
2605 cmd->management_rate = mgmt;
2607 rc = mwl8k_post_cmd(hw, &cmd->header);
2614 * CMD_ENABLE_SNIFFER.
2616 struct mwl8k_cmd_enable_sniffer {
2617 struct mwl8k_cmd_pkt header;
2619 } __attribute__((packed));
2621 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2623 struct mwl8k_cmd_enable_sniffer *cmd;
2626 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2630 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2631 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2632 cmd->action = cpu_to_le32(!!enable);
2634 rc = mwl8k_post_cmd(hw, &cmd->header);
2643 struct mwl8k_cmd_set_mac_addr {
2644 struct mwl8k_cmd_pkt header;
2648 __u8 mac_addr[ETH_ALEN];
2650 __u8 mac_addr[ETH_ALEN];
2652 } __attribute__((packed));
2654 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2655 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
2657 static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2659 struct mwl8k_priv *priv = hw->priv;
2660 struct mwl8k_cmd_set_mac_addr *cmd;
2663 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2667 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2668 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2670 cmd->mbss.mac_type = cpu_to_le16(MWL8K_MAC_TYPE_PRIMARY_AP);
2671 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2673 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2676 rc = mwl8k_post_cmd(hw, &cmd->header);
2683 * CMD_SET_RATEADAPT_MODE.
2685 struct mwl8k_cmd_set_rate_adapt_mode {
2686 struct mwl8k_cmd_pkt header;
2689 } __attribute__((packed));
2691 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2693 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2696 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2700 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2701 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2702 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2703 cmd->mode = cpu_to_le16(mode);
2705 rc = mwl8k_post_cmd(hw, &cmd->header);
2714 struct mwl8k_cmd_bss_start {
2715 struct mwl8k_cmd_pkt header;
2717 } __attribute__((packed));
2719 static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, int enable)
2721 struct mwl8k_cmd_bss_start *cmd;
2724 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2728 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2729 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2730 cmd->enable = cpu_to_le32(enable);
2732 rc = mwl8k_post_cmd(hw, &cmd->header);
2741 struct mwl8k_cmd_set_new_stn {
2742 struct mwl8k_cmd_pkt header;
2748 __le32 legacy_rates;
2751 __le16 ht_capabilities_info;
2752 __u8 mac_ht_param_info;
2754 __u8 control_channel;
2761 } __attribute__((packed));
2763 #define MWL8K_STA_ACTION_ADD 0
2764 #define MWL8K_STA_ACTION_REMOVE 2
2766 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2767 struct ieee80211_vif *vif,
2768 struct ieee80211_sta *sta)
2770 struct mwl8k_cmd_set_new_stn *cmd;
2773 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2777 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2778 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2779 cmd->aid = cpu_to_le16(sta->aid);
2780 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2781 cmd->stn_id = cpu_to_le16(sta->aid);
2782 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
2783 cmd->legacy_rates = cpu_to_le32(sta->supp_rates[IEEE80211_BAND_2GHZ]);
2784 if (sta->ht_cap.ht_supported) {
2785 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2786 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2787 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2788 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2789 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2790 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2791 ((sta->ht_cap.ampdu_density & 7) << 2);
2792 cmd->is_qos_sta = 1;
2795 rc = mwl8k_post_cmd(hw, &cmd->header);
2801 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2802 struct ieee80211_vif *vif)
2804 struct mwl8k_cmd_set_new_stn *cmd;
2807 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2811 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2812 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2813 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2815 rc = mwl8k_post_cmd(hw, &cmd->header);
2821 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2822 struct ieee80211_vif *vif, u8 *addr)
2824 struct mwl8k_cmd_set_new_stn *cmd;
2827 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2831 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2832 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2833 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2834 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2836 rc = mwl8k_post_cmd(hw, &cmd->header);
2845 struct ewc_ht_info {
2849 } __attribute__((packed));
2851 struct peer_capability_info {
2852 /* Peer type - AP vs. STA. */
2855 /* Basic 802.11 capabilities from assoc resp. */
2858 /* Set if peer supports 802.11n high throughput (HT). */
2861 /* Valid if HT is supported. */
2863 __u8 extended_ht_caps;
2864 struct ewc_ht_info ewc_info;
2866 /* Legacy rate table. Intersection of our rates and peer rates. */
2867 __u8 legacy_rates[12];
2869 /* HT rate table. Intersection of our rates and peer rates. */
2873 /* If set, interoperability mode, no proprietary extensions. */
2877 __le16 amsdu_enabled;
2878 } __attribute__((packed));
2880 struct mwl8k_cmd_update_stadb {
2881 struct mwl8k_cmd_pkt header;
2883 /* See STADB_ACTION_TYPE */
2886 /* Peer MAC address */
2887 __u8 peer_addr[ETH_ALEN];
2891 /* Peer info - valid during add/update. */
2892 struct peer_capability_info peer_info;
2893 } __attribute__((packed));
2895 #define MWL8K_STA_DB_MODIFY_ENTRY 1
2896 #define MWL8K_STA_DB_DEL_ENTRY 2
2898 /* Peer Entry flags - used to define the type of the peer node */
2899 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
2901 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
2902 struct ieee80211_vif *vif,
2903 struct ieee80211_sta *sta)
2905 struct mwl8k_cmd_update_stadb *cmd;
2906 struct peer_capability_info *p;
2909 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2913 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2914 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2915 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
2916 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
2918 p = &cmd->peer_info;
2919 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2920 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
2921 p->ht_support = sta->ht_cap.ht_supported;
2922 p->ht_caps = sta->ht_cap.cap;
2923 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
2924 ((sta->ht_cap.ampdu_density & 7) << 2);
2925 legacy_rate_mask_to_array(p->legacy_rates,
2926 sta->supp_rates[IEEE80211_BAND_2GHZ]);
2927 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
2929 p->amsdu_enabled = 0;
2931 rc = mwl8k_post_cmd(hw, &cmd->header);
2934 return rc ? rc : p->station_id;
2937 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
2938 struct ieee80211_vif *vif, u8 *addr)
2940 struct mwl8k_cmd_update_stadb *cmd;
2943 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2947 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2948 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2949 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
2950 memcpy(cmd->peer_addr, addr, ETH_ALEN);
2952 rc = mwl8k_post_cmd(hw, &cmd->header);
2960 * Interrupt handling.
2962 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2964 struct ieee80211_hw *hw = dev_id;
2965 struct mwl8k_priv *priv = hw->priv;
2968 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2972 if (status & MWL8K_A2H_INT_TX_DONE) {
2973 status &= ~MWL8K_A2H_INT_TX_DONE;
2974 tasklet_schedule(&priv->poll_tx_task);
2977 if (status & MWL8K_A2H_INT_RX_READY) {
2978 status &= ~MWL8K_A2H_INT_RX_READY;
2979 tasklet_schedule(&priv->poll_rx_task);
2983 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2985 if (status & MWL8K_A2H_INT_OPC_DONE) {
2986 if (priv->hostcmd_wait != NULL)
2987 complete(priv->hostcmd_wait);
2990 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
2991 if (!mutex_is_locked(&priv->fw_mutex) &&
2992 priv->radio_on && priv->pending_tx_pkts)
2993 mwl8k_tx_start(priv);
2999 static void mwl8k_tx_poll(unsigned long data)
3001 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3002 struct mwl8k_priv *priv = hw->priv;
3008 spin_lock_bh(&priv->tx_lock);
3010 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3011 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3013 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3014 complete(priv->tx_wait);
3015 priv->tx_wait = NULL;
3018 spin_unlock_bh(&priv->tx_lock);
3021 writel(~MWL8K_A2H_INT_TX_DONE,
3022 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3024 tasklet_schedule(&priv->poll_tx_task);
3028 static void mwl8k_rx_poll(unsigned long data)
3030 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3031 struct mwl8k_priv *priv = hw->priv;
3035 limit -= rxq_process(hw, 0, limit);
3036 limit -= rxq_refill(hw, 0, limit);
3039 writel(~MWL8K_A2H_INT_RX_READY,
3040 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3042 tasklet_schedule(&priv->poll_rx_task);
3048 * Core driver operations.
3050 static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3052 struct mwl8k_priv *priv = hw->priv;
3053 int index = skb_get_queue_mapping(skb);
3056 if (priv->current_channel == NULL) {
3057 printk(KERN_DEBUG "%s: dropped TX frame since radio "
3058 "disabled\n", wiphy_name(hw->wiphy));
3060 return NETDEV_TX_OK;
3063 rc = mwl8k_txq_xmit(hw, index, skb);
3068 static int mwl8k_start(struct ieee80211_hw *hw)
3070 struct mwl8k_priv *priv = hw->priv;
3073 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
3074 IRQF_SHARED, MWL8K_NAME, hw);
3076 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3077 wiphy_name(hw->wiphy));
3081 /* Enable TX reclaim and RX tasklets. */
3082 tasklet_enable(&priv->poll_tx_task);
3083 tasklet_enable(&priv->poll_rx_task);
3085 /* Enable interrupts */
3086 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3088 rc = mwl8k_fw_lock(hw);
3090 rc = mwl8k_cmd_radio_enable(hw);
3094 rc = mwl8k_cmd_enable_sniffer(hw, 0);
3097 rc = mwl8k_cmd_set_pre_scan(hw);
3100 rc = mwl8k_cmd_set_post_scan(hw,
3101 "\x00\x00\x00\x00\x00\x00");
3105 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
3108 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
3110 mwl8k_fw_unlock(hw);
3114 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3115 free_irq(priv->pdev->irq, hw);
3116 tasklet_disable(&priv->poll_tx_task);
3117 tasklet_disable(&priv->poll_rx_task);
3123 static void mwl8k_stop(struct ieee80211_hw *hw)
3125 struct mwl8k_priv *priv = hw->priv;
3128 mwl8k_cmd_radio_disable(hw);
3130 ieee80211_stop_queues(hw);
3132 /* Disable interrupts */
3133 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3134 free_irq(priv->pdev->irq, hw);
3136 /* Stop finalize join worker */
3137 cancel_work_sync(&priv->finalize_join_worker);
3138 if (priv->beacon_skb != NULL)
3139 dev_kfree_skb(priv->beacon_skb);
3141 /* Stop TX reclaim and RX tasklets. */
3142 tasklet_disable(&priv->poll_tx_task);
3143 tasklet_disable(&priv->poll_rx_task);
3145 /* Return all skbs to mac80211 */
3146 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3147 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
3150 static int mwl8k_add_interface(struct ieee80211_hw *hw,
3151 struct ieee80211_vif *vif)
3153 struct mwl8k_priv *priv = hw->priv;
3154 struct mwl8k_vif *mwl8k_vif;
3157 * We only support one active interface at a time.
3159 if (priv->vif != NULL)
3163 * Reject interface creation if sniffer mode is active, as
3164 * STA operation is mutually exclusive with hardware sniffer
3165 * mode. (Sniffer mode is only used on STA firmware.)
3167 if (priv->sniffer_enabled) {
3168 printk(KERN_INFO "%s: unable to create STA "
3169 "interface due to sniffer mode being enabled\n",
3170 wiphy_name(hw->wiphy));
3174 /* Set the mac address. */
3175 mwl8k_cmd_set_mac_addr(hw, vif->addr);
3178 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3180 /* Clean out driver private area */
3181 mwl8k_vif = MWL8K_VIF(vif);
3182 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
3184 /* Set Initial sequence number to zero */
3185 mwl8k_vif->seqno = 0;
3188 priv->current_channel = NULL;
3193 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
3194 struct ieee80211_vif *vif)
3196 struct mwl8k_priv *priv = hw->priv;
3199 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3201 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3206 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
3208 struct ieee80211_conf *conf = &hw->conf;
3209 struct mwl8k_priv *priv = hw->priv;
3212 if (conf->flags & IEEE80211_CONF_IDLE) {
3213 mwl8k_cmd_radio_disable(hw);
3214 priv->current_channel = NULL;
3218 rc = mwl8k_fw_lock(hw);
3222 rc = mwl8k_cmd_radio_enable(hw);
3226 rc = mwl8k_cmd_set_rf_channel(hw, conf);
3230 priv->current_channel = conf->channel;
3232 if (conf->power_level > 18)
3233 conf->power_level = 18;
3234 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
3239 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3241 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3243 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3247 mwl8k_fw_unlock(hw);
3253 mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3254 struct ieee80211_bss_conf *info, u32 changed)
3256 struct mwl8k_priv *priv = hw->priv;
3257 u32 ap_legacy_rates;
3258 u8 ap_mcs_rates[16];
3261 if (mwl8k_fw_lock(hw))
3265 * No need to capture a beacon if we're no longer associated.
3267 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3268 priv->capture_beacon = false;
3271 * Get the AP's legacy and MCS rates.
3273 ap_legacy_rates = 0;
3274 if (vif->bss_conf.assoc) {
3275 struct ieee80211_sta *ap;
3278 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
3284 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3285 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
3290 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
3291 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
3295 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
3300 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3301 rc = mwl8k_set_radio_preamble(hw,
3302 vif->bss_conf.use_short_preamble);
3307 if (changed & BSS_CHANGED_ERP_SLOT) {
3308 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
3313 if (((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) ||
3314 (changed & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT))) {
3315 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
3320 if (vif->bss_conf.assoc &&
3321 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
3323 * Finalize the join. Tell rx handler to process
3324 * next beacon from our BSSID.
3326 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
3327 priv->capture_beacon = true;
3331 mwl8k_fw_unlock(hw);
3335 mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3336 struct ieee80211_bss_conf *info, u32 changed)
3340 if (mwl8k_fw_lock(hw))
3343 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3344 rc = mwl8k_set_radio_preamble(hw,
3345 vif->bss_conf.use_short_preamble);
3350 if (changed & BSS_CHANGED_BASIC_RATES) {
3355 * Use lowest supported basic rate for multicasts
3356 * and management frames (such as probe responses --
3357 * beacons will always go out at 1 Mb/s).
3359 idx = ffs(vif->bss_conf.basic_rates);
3360 rate = idx ? mwl8k_rates[idx - 1].hw_value : 2;
3362 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3365 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3366 struct sk_buff *skb;
3368 skb = ieee80211_beacon_get(hw, vif);
3370 mwl8k_cmd_set_beacon(hw, skb->data, skb->len);
3375 if (changed & BSS_CHANGED_BEACON_ENABLED)
3376 mwl8k_cmd_bss_start(hw, info->enable_beacon);
3379 mwl8k_fw_unlock(hw);
3383 mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3384 struct ieee80211_bss_conf *info, u32 changed)
3386 struct mwl8k_priv *priv = hw->priv;
3389 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3391 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3394 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3395 int mc_count, struct dev_addr_list *mclist)
3397 struct mwl8k_cmd_pkt *cmd;
3400 * Synthesize and return a command packet that programs the
3401 * hardware multicast address filter. At this point we don't
3402 * know whether FIF_ALLMULTI is being requested, but if it is,
3403 * we'll end up throwing this packet away and creating a new
3404 * one in mwl8k_configure_filter().
3406 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
3408 return (unsigned long)cmd;
3412 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3413 unsigned int changed_flags,
3414 unsigned int *total_flags)
3416 struct mwl8k_priv *priv = hw->priv;
3419 * Hardware sniffer mode is mutually exclusive with STA
3420 * operation, so refuse to enable sniffer mode if a STA
3421 * interface is active.
3423 if (priv->vif != NULL) {
3424 if (net_ratelimit())
3425 printk(KERN_INFO "%s: not enabling sniffer "
3426 "mode because STA interface is active\n",
3427 wiphy_name(hw->wiphy));
3431 if (!priv->sniffer_enabled) {
3432 if (mwl8k_cmd_enable_sniffer(hw, 1))
3434 priv->sniffer_enabled = true;
3437 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3438 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3444 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3445 unsigned int changed_flags,
3446 unsigned int *total_flags,
3449 struct mwl8k_priv *priv = hw->priv;
3450 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3453 * AP firmware doesn't allow fine-grained control over
3454 * the receive filter.
3457 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3463 * Enable hardware sniffer mode if FIF_CONTROL or
3464 * FIF_OTHER_BSS is requested.
3466 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3467 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3472 /* Clear unsupported feature flags */
3473 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3475 if (mwl8k_fw_lock(hw)) {
3480 if (priv->sniffer_enabled) {
3481 mwl8k_cmd_enable_sniffer(hw, 0);
3482 priv->sniffer_enabled = false;
3485 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
3486 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3488 * Disable the BSS filter.
3490 mwl8k_cmd_set_pre_scan(hw);
3495 * Enable the BSS filter.
3497 * If there is an active STA interface, use that
3498 * interface's BSSID, otherwise use a dummy one
3499 * (where the OUI part needs to be nonzero for
3500 * the BSSID to be accepted by POST_SCAN).
3502 bssid = "\x01\x00\x00\x00\x00\x00";
3503 if (priv->vif != NULL)
3504 bssid = priv->vif->bss_conf.bssid;
3506 mwl8k_cmd_set_post_scan(hw, bssid);
3511 * If FIF_ALLMULTI is being requested, throw away the command
3512 * packet that ->prepare_multicast() built and replace it with
3513 * a command packet that enables reception of all multicast
3516 if (*total_flags & FIF_ALLMULTI) {
3518 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3522 mwl8k_post_cmd(hw, cmd);
3526 mwl8k_fw_unlock(hw);
3529 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3531 return mwl8k_cmd_set_rts_threshold(hw, value);
3534 struct mwl8k_sta_notify_item
3536 struct list_head list;
3537 struct ieee80211_vif *vif;
3538 enum sta_notify_cmd cmd;
3539 struct ieee80211_sta sta;
3543 mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3545 struct mwl8k_priv *priv = hw->priv;
3548 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3550 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3553 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3555 struct ieee80211_sta *sta;
3558 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3560 MWL8K_STA(sta)->peer_id = rc;
3563 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3564 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3565 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3566 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3567 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3568 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3572 static void mwl8k_sta_notify_worker(struct work_struct *work)
3574 struct mwl8k_priv *priv =
3575 container_of(work, struct mwl8k_priv, sta_notify_worker);
3576 struct ieee80211_hw *hw = priv->hw;
3578 spin_lock_bh(&priv->sta_notify_list_lock);
3579 while (!list_empty(&priv->sta_notify_list)) {
3580 struct mwl8k_sta_notify_item *s;
3582 s = list_entry(priv->sta_notify_list.next,
3583 struct mwl8k_sta_notify_item, list);
3586 spin_unlock_bh(&priv->sta_notify_list_lock);
3588 mwl8k_do_sta_notify(hw, s);
3591 spin_lock_bh(&priv->sta_notify_list_lock);
3593 spin_unlock_bh(&priv->sta_notify_list_lock);
3597 mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3598 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3600 struct mwl8k_priv *priv = hw->priv;
3601 struct mwl8k_sta_notify_item *s;
3603 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3606 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3612 spin_lock(&priv->sta_notify_list_lock);
3613 list_add_tail(&s->list, &priv->sta_notify_list);
3614 spin_unlock(&priv->sta_notify_list_lock);
3616 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3620 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3621 const struct ieee80211_tx_queue_params *params)
3623 struct mwl8k_priv *priv = hw->priv;
3626 rc = mwl8k_fw_lock(hw);
3628 if (!priv->wmm_enabled)
3629 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
3632 rc = mwl8k_cmd_set_edca_params(hw, queue,
3638 mwl8k_fw_unlock(hw);
3644 static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3645 struct ieee80211_tx_queue_stats *stats)
3647 struct mwl8k_priv *priv = hw->priv;
3648 struct mwl8k_tx_queue *txq;
3651 spin_lock_bh(&priv->tx_lock);
3652 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3653 txq = priv->txq + index;
3654 memcpy(&stats[index], &txq->stats,
3655 sizeof(struct ieee80211_tx_queue_stats));
3657 spin_unlock_bh(&priv->tx_lock);
3662 static int mwl8k_get_stats(struct ieee80211_hw *hw,
3663 struct ieee80211_low_level_stats *stats)
3665 return mwl8k_cmd_get_stat(hw, stats);
3669 mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3670 enum ieee80211_ampdu_mlme_action action,
3671 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3674 case IEEE80211_AMPDU_RX_START:
3675 case IEEE80211_AMPDU_RX_STOP:
3676 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3684 static const struct ieee80211_ops mwl8k_ops = {
3686 .start = mwl8k_start,
3688 .add_interface = mwl8k_add_interface,
3689 .remove_interface = mwl8k_remove_interface,
3690 .config = mwl8k_config,
3691 .bss_info_changed = mwl8k_bss_info_changed,
3692 .prepare_multicast = mwl8k_prepare_multicast,
3693 .configure_filter = mwl8k_configure_filter,
3694 .set_rts_threshold = mwl8k_set_rts_threshold,
3695 .sta_notify = mwl8k_sta_notify,
3696 .conf_tx = mwl8k_conf_tx,
3697 .get_tx_stats = mwl8k_get_tx_stats,
3698 .get_stats = mwl8k_get_stats,
3699 .ampdu_action = mwl8k_ampdu_action,
3702 static void mwl8k_finalize_join_worker(struct work_struct *work)
3704 struct mwl8k_priv *priv =
3705 container_of(work, struct mwl8k_priv, finalize_join_worker);
3706 struct sk_buff *skb = priv->beacon_skb;
3708 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len,
3709 priv->vif->bss_conf.dtim_period);
3712 priv->beacon_skb = NULL;
3721 static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3723 .part_name = "88w8363",
3724 .helper_image = "mwl8k/helper_8363.fw",
3725 .fw_image = "mwl8k/fmimage_8363.fw",
3728 .part_name = "88w8687",
3729 .helper_image = "mwl8k/helper_8687.fw",
3730 .fw_image = "mwl8k/fmimage_8687.fw",
3733 .part_name = "88w8366",
3734 .helper_image = "mwl8k/helper_8366.fw",
3735 .fw_image = "mwl8k/fmimage_8366.fw",
3736 .ap_rxd_ops = &rxd_8366_ap_ops,
3740 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
3741 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3742 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
3743 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3744 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3745 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3748 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3750 static int __devinit mwl8k_probe(struct pci_dev *pdev,
3751 const struct pci_device_id *id)
3753 static int printed_version = 0;
3754 struct ieee80211_hw *hw;
3755 struct mwl8k_priv *priv;
3759 if (!printed_version) {
3760 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3761 printed_version = 1;
3765 rc = pci_enable_device(pdev);
3767 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3772 rc = pci_request_regions(pdev, MWL8K_NAME);
3774 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3776 goto err_disable_device;
3779 pci_set_master(pdev);
3782 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3784 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3789 SET_IEEE80211_DEV(hw, &pdev->dev);
3790 pci_set_drvdata(pdev, hw);
3795 priv->device_info = &mwl8k_info_tbl[id->driver_data];
3798 priv->sram = pci_iomap(pdev, 0, 0x10000);
3799 if (priv->sram == NULL) {
3800 printk(KERN_ERR "%s: Cannot map device SRAM\n",
3801 wiphy_name(hw->wiphy));
3806 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3807 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3809 priv->regs = pci_iomap(pdev, 1, 0x10000);
3810 if (priv->regs == NULL) {
3811 priv->regs = pci_iomap(pdev, 2, 0x10000);
3812 if (priv->regs == NULL) {
3813 printk(KERN_ERR "%s: Cannot map device registers\n",
3814 wiphy_name(hw->wiphy));
3820 /* Reset firmware and hardware */
3821 mwl8k_hw_reset(priv);
3823 /* Ask userland hotplug daemon for the device firmware */
3824 rc = mwl8k_request_firmware(priv);
3826 printk(KERN_ERR "%s: Firmware files not found\n",
3827 wiphy_name(hw->wiphy));
3828 goto err_stop_firmware;
3831 /* Load firmware into hardware */
3832 rc = mwl8k_load_firmware(hw);
3834 printk(KERN_ERR "%s: Cannot start firmware\n",
3835 wiphy_name(hw->wiphy));
3836 goto err_stop_firmware;
3839 /* Reclaim memory once firmware is successfully loaded */
3840 mwl8k_release_firmware(priv);
3844 priv->rxd_ops = priv->device_info->ap_rxd_ops;
3845 if (priv->rxd_ops == NULL) {
3846 printk(KERN_ERR "%s: Driver does not have AP "
3847 "firmware image support for this hardware\n",
3848 wiphy_name(hw->wiphy));
3849 goto err_stop_firmware;
3852 priv->rxd_ops = &rxd_sta_ops;
3855 priv->sniffer_enabled = false;
3856 priv->wmm_enabled = false;
3857 priv->pending_tx_pkts = 0;
3860 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3861 priv->band.band = IEEE80211_BAND_2GHZ;
3862 priv->band.channels = priv->channels;
3863 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3864 priv->band.bitrates = priv->rates;
3865 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3866 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3868 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3869 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3872 * Extra headroom is the size of the required DMA header
3873 * minus the size of the smallest 802.11 frame (CTS frame).
3875 hw->extra_tx_headroom =
3876 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3878 hw->channel_change_time = 10;
3880 hw->queues = MWL8K_TX_QUEUES;
3882 /* Set rssi and noise values to dBm */
3883 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
3884 hw->vif_data_size = sizeof(struct mwl8k_vif);
3885 hw->sta_data_size = sizeof(struct mwl8k_sta);
3888 /* Set default radio state and preamble */
3890 priv->radio_short_preamble = 0;
3892 /* Station database handling */
3893 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
3894 spin_lock_init(&priv->sta_notify_list_lock);
3895 INIT_LIST_HEAD(&priv->sta_notify_list);
3897 /* Finalize join worker */
3898 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3900 /* TX reclaim and RX tasklets. */
3901 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
3902 tasklet_disable(&priv->poll_tx_task);
3903 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
3904 tasklet_disable(&priv->poll_rx_task);
3906 /* Power management cookie */
3907 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3908 if (priv->cookie == NULL)
3909 goto err_stop_firmware;
3911 rc = mwl8k_rxq_init(hw, 0);
3913 goto err_free_cookie;
3914 rxq_refill(hw, 0, INT_MAX);
3916 mutex_init(&priv->fw_mutex);
3917 priv->fw_mutex_owner = NULL;
3918 priv->fw_mutex_depth = 0;
3919 priv->hostcmd_wait = NULL;
3921 spin_lock_init(&priv->tx_lock);
3923 priv->tx_wait = NULL;
3925 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3926 rc = mwl8k_txq_init(hw, i);
3928 goto err_free_queues;
3931 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3932 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3933 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
3934 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3935 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3937 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
3938 IRQF_SHARED, MWL8K_NAME, hw);
3940 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3941 wiphy_name(hw->wiphy));
3942 goto err_free_queues;
3946 * Temporarily enable interrupts. Initial firmware host
3947 * commands use interrupts and avoid polling. Disable
3948 * interrupts when done.
3950 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3952 /* Get config data, mac addrs etc */
3954 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3956 rc = mwl8k_cmd_set_hw_spec(hw);
3958 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_AP);
3960 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3962 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
3965 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3966 wiphy_name(hw->wiphy));
3970 /* Turn radio off */
3971 rc = mwl8k_cmd_radio_disable(hw);
3973 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
3977 /* Clear MAC address */
3978 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3980 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3981 wiphy_name(hw->wiphy));
3985 /* Disable interrupts */
3986 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3987 free_irq(priv->pdev->irq, hw);
3989 rc = ieee80211_register_hw(hw);
3991 printk(KERN_ERR "%s: Cannot register device\n",
3992 wiphy_name(hw->wiphy));
3993 goto err_free_queues;
3996 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
3997 wiphy_name(hw->wiphy), priv->device_info->part_name,
3998 priv->hw_rev, hw->wiphy->perm_addr,
3999 priv->ap_fw ? "AP" : "STA",
4000 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4001 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
4006 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4007 free_irq(priv->pdev->irq, hw);
4010 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4011 mwl8k_txq_deinit(hw, i);
4012 mwl8k_rxq_deinit(hw, 0);
4015 if (priv->cookie != NULL)
4016 pci_free_consistent(priv->pdev, 4,
4017 priv->cookie, priv->cookie_dma);
4020 mwl8k_hw_reset(priv);
4021 mwl8k_release_firmware(priv);
4024 if (priv->regs != NULL)
4025 pci_iounmap(pdev, priv->regs);
4027 if (priv->sram != NULL)
4028 pci_iounmap(pdev, priv->sram);
4030 pci_set_drvdata(pdev, NULL);
4031 ieee80211_free_hw(hw);
4034 pci_release_regions(pdev);
4037 pci_disable_device(pdev);
4042 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
4044 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4047 static void __devexit mwl8k_remove(struct pci_dev *pdev)
4049 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4050 struct mwl8k_priv *priv;
4057 ieee80211_stop_queues(hw);
4059 ieee80211_unregister_hw(hw);
4061 /* Remove TX reclaim and RX tasklets. */
4062 tasklet_kill(&priv->poll_tx_task);
4063 tasklet_kill(&priv->poll_rx_task);
4066 mwl8k_hw_reset(priv);
4068 /* Return all skbs to mac80211 */
4069 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4070 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
4072 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4073 mwl8k_txq_deinit(hw, i);
4075 mwl8k_rxq_deinit(hw, 0);
4077 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
4079 pci_iounmap(pdev, priv->regs);
4080 pci_iounmap(pdev, priv->sram);
4081 pci_set_drvdata(pdev, NULL);
4082 ieee80211_free_hw(hw);
4083 pci_release_regions(pdev);
4084 pci_disable_device(pdev);
4087 static struct pci_driver mwl8k_driver = {
4089 .id_table = mwl8k_pci_id_table,
4090 .probe = mwl8k_probe,
4091 .remove = __devexit_p(mwl8k_remove),
4092 .shutdown = __devexit_p(mwl8k_shutdown),
4095 static int __init mwl8k_init(void)
4097 return pci_register_driver(&mwl8k_driver);
4100 static void __exit mwl8k_exit(void)
4102 pci_unregister_driver(&mwl8k_driver);
4105 module_init(mwl8k_init);
4106 module_exit(mwl8k_exit);
4108 MODULE_DESCRIPTION(MWL8K_DESC);
4109 MODULE_VERSION(MWL8K_VERSION);
4110 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4111 MODULE_LICENSE("GPL");