2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008 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/spinlock.h>
16 #include <linux/list.h>
17 #include <linux/pci.h>
18 #include <linux/delay.h>
19 #include <linux/completion.h>
20 #include <linux/etherdevice.h>
21 #include <net/mac80211.h>
22 #include <linux/moduleparam.h>
23 #include <linux/firmware.h>
24 #include <linux/workqueue.h>
26 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
27 #define MWL8K_NAME KBUILD_MODNAME
28 #define MWL8K_VERSION "0.9.1"
30 MODULE_DESCRIPTION(MWL8K_DESC);
31 MODULE_VERSION(MWL8K_VERSION);
32 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
33 MODULE_LICENSE("GPL");
35 static DEFINE_PCI_DEVICE_TABLE(mwl8k_table) = {
36 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = 8687, },
37 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = 8687, },
40 MODULE_DEVICE_TABLE(pci, mwl8k_table);
42 /* Register definitions */
43 #define MWL8K_HIU_GEN_PTR 0x00000c10
44 #define MWL8K_MODE_STA 0x0000005a
45 #define MWL8K_MODE_AP 0x000000a5
46 #define MWL8K_HIU_INT_CODE 0x00000c14
47 #define MWL8K_FWSTA_READY 0xf0f1f2f4
48 #define MWL8K_FWAP_READY 0xf1f2f4a5
49 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
50 #define MWL8K_HIU_SCRATCH 0x00000c40
52 /* Host->device communications */
53 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
54 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
55 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
56 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
57 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
58 #define MWL8K_H2A_INT_DUMMY (1 << 20)
59 #define MWL8K_H2A_INT_RESET (1 << 15)
60 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
61 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
63 /* Device->host communications */
64 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
65 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
66 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
67 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
68 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
69 #define MWL8K_A2H_INT_DUMMY (1 << 20)
70 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
71 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
72 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
73 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
74 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
75 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
76 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
77 #define MWL8K_A2H_INT_RX_READY (1 << 1)
78 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
80 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
81 MWL8K_A2H_INT_CHNL_SWITCHED | \
82 MWL8K_A2H_INT_QUEUE_EMPTY | \
83 MWL8K_A2H_INT_RADAR_DETECT | \
84 MWL8K_A2H_INT_RADIO_ON | \
85 MWL8K_A2H_INT_RADIO_OFF | \
86 MWL8K_A2H_INT_MAC_EVENT | \
87 MWL8K_A2H_INT_OPC_DONE | \
88 MWL8K_A2H_INT_RX_READY | \
89 MWL8K_A2H_INT_TX_DONE)
91 /* WME stream classes */
92 #define WME_AC_BE 0 /* best effort */
93 #define WME_AC_BK 1 /* background */
94 #define WME_AC_VI 2 /* video */
95 #define WME_AC_VO 3 /* voice */
97 #define MWL8K_RX_QUEUES 1
98 #define MWL8K_TX_QUEUES 4
100 struct mwl8k_rx_queue {
103 /* hw receives here */
106 /* refill descs here */
109 struct mwl8k_rx_desc *rx_desc_area;
110 dma_addr_t rx_desc_dma;
111 struct sk_buff **rx_skb;
116 * The DMA engine requires a modification to the payload.
117 * If the skbuff is shared/cloned, it needs to be unshared.
118 * This method is used to ensure the stack always gets back
119 * the skbuff it sent for transmission.
121 struct sk_buff *clone;
125 struct mwl8k_tx_queue {
126 /* hw transmits here */
129 /* sw appends here */
132 struct ieee80211_tx_queue_stats tx_stats;
133 struct mwl8k_tx_desc *tx_desc_area;
134 dma_addr_t tx_desc_dma;
135 struct mwl8k_skb *tx_skb;
138 /* Pointers to the firmware data and meta information about it. */
139 struct mwl8k_firmware {
141 struct firmware *ucode;
143 /* Boot helper code */
144 struct firmware *helper;
149 struct ieee80211_hw *hw;
151 struct pci_dev *pdev;
153 /* firmware access lock */
156 /* firmware files and meta data */
157 struct mwl8k_firmware fw;
160 /* lock held over TX and TX reap */
163 struct ieee80211_vif *vif;
165 struct ieee80211_channel *current_channel;
167 /* power management status cookie from firmware */
169 dma_addr_t cookie_dma;
176 * Running count of TX packets in flight, to avoid
177 * iterating over the transmit rings each time.
181 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
182 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
185 struct ieee80211_supported_band band;
186 struct ieee80211_channel channels[14];
187 struct ieee80211_rate rates[12];
191 /* RF preamble: Short, Long or Auto */
194 /* WMM MODE 1 for enabled; 0 for disabled */
197 /* Set if PHY config is in progress */
200 /* XXX need to convert this to handle multiple interfaces */
202 u8 capture_bssid[ETH_ALEN];
203 struct sk_buff *beacon_skb;
206 * This FJ worker has to be global as it is scheduled from the
207 * RX handler. At this point we don't know which interface it
208 * belongs to until the list of bssids waiting to complete join
211 struct work_struct finalize_join_worker;
213 /* Tasklet to reclaim TX descriptors and buffers after tx */
214 struct tasklet_struct tx_reclaim_task;
216 /* Work thread to serialize configuration requests */
217 struct workqueue_struct *config_wq;
218 struct completion *hostcmd_wait;
219 struct completion *tx_wait;
222 /* Per interface specific private data */
224 /* backpointer to parent config block */
225 struct mwl8k_priv *priv;
227 /* BSS config of AP or IBSS from mac80211*/
228 struct ieee80211_bss_conf bss_info;
230 /* BSSID of AP or IBSS */
232 u8 mac_addr[ETH_ALEN];
235 * Subset of supported legacy rates.
236 * Intersection of AP and STA supported rates.
238 struct ieee80211_rate legacy_rates[12];
240 /* number of supported legacy rates */
243 /* Index into station database.Returned by update_sta_db call */
246 /* Non AMPDU sequence number assigned by driver */
250 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
252 static const struct ieee80211_channel mwl8k_channels[] = {
253 { .center_freq = 2412, .hw_value = 1, },
254 { .center_freq = 2417, .hw_value = 2, },
255 { .center_freq = 2422, .hw_value = 3, },
256 { .center_freq = 2427, .hw_value = 4, },
257 { .center_freq = 2432, .hw_value = 5, },
258 { .center_freq = 2437, .hw_value = 6, },
259 { .center_freq = 2442, .hw_value = 7, },
260 { .center_freq = 2447, .hw_value = 8, },
261 { .center_freq = 2452, .hw_value = 9, },
262 { .center_freq = 2457, .hw_value = 10, },
263 { .center_freq = 2462, .hw_value = 11, },
266 static const struct ieee80211_rate mwl8k_rates[] = {
267 { .bitrate = 10, .hw_value = 2, },
268 { .bitrate = 20, .hw_value = 4, },
269 { .bitrate = 55, .hw_value = 11, },
270 { .bitrate = 60, .hw_value = 12, },
271 { .bitrate = 90, .hw_value = 18, },
272 { .bitrate = 110, .hw_value = 22, },
273 { .bitrate = 120, .hw_value = 24, },
274 { .bitrate = 180, .hw_value = 36, },
275 { .bitrate = 240, .hw_value = 48, },
276 { .bitrate = 360, .hw_value = 72, },
277 { .bitrate = 480, .hw_value = 96, },
278 { .bitrate = 540, .hw_value = 108, },
282 #define MWL8K_RADIO_AUTO_PREAMBLE 0x0005
283 #define MWL8K_RADIO_SHORT_PREAMBLE 0x0003
284 #define MWL8K_RADIO_LONG_PREAMBLE 0x0001
287 #define MWL8K_WMM_ENABLE 1
288 #define MWL8K_WMM_DISABLE 0
290 #define MWL8K_RADIO_DEFAULT_PREAMBLE MWL8K_RADIO_LONG_PREAMBLE
294 /* Short Slot: 9us slot time */
295 #define MWL8K_SHORT_SLOTTIME 1
297 /* Long slot: 20us slot time */
298 #define MWL8K_LONG_SLOTTIME 0
300 /* Set or get info from Firmware */
301 #define MWL8K_CMD_SET 0x0001
302 #define MWL8K_CMD_GET 0x0000
304 /* Firmware command codes */
305 #define MWL8K_CMD_CODE_DNLD 0x0001
306 #define MWL8K_CMD_GET_HW_SPEC 0x0003
307 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
308 #define MWL8K_CMD_GET_STAT 0x0014
309 #define MWL8K_CMD_RADIO_CONTROL 0x001c
310 #define MWL8K_CMD_RF_TX_POWER 0x001e
311 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
312 #define MWL8K_CMD_SET_POST_SCAN 0x0108
313 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
314 #define MWL8K_CMD_SET_AID 0x010d
315 #define MWL8K_CMD_SET_RATE 0x0110
316 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
317 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
318 #define MWL8K_CMD_SET_SLOT 0x0114
319 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
320 #define MWL8K_CMD_SET_WMM_MODE 0x0123
321 #define MWL8K_CMD_MIMO_CONFIG 0x0125
322 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
323 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
324 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
325 #define MWL8K_CMD_UPDATE_STADB 0x1123
327 static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
329 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
330 snprintf(buf, bufsize, "%s", #x);\
333 switch (cmd & ~0x8000) {
334 MWL8K_CMDNAME(CODE_DNLD);
335 MWL8K_CMDNAME(GET_HW_SPEC);
336 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
337 MWL8K_CMDNAME(GET_STAT);
338 MWL8K_CMDNAME(RADIO_CONTROL);
339 MWL8K_CMDNAME(RF_TX_POWER);
340 MWL8K_CMDNAME(SET_PRE_SCAN);
341 MWL8K_CMDNAME(SET_POST_SCAN);
342 MWL8K_CMDNAME(SET_RF_CHANNEL);
343 MWL8K_CMDNAME(SET_AID);
344 MWL8K_CMDNAME(SET_RATE);
345 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
346 MWL8K_CMDNAME(RTS_THRESHOLD);
347 MWL8K_CMDNAME(SET_SLOT);
348 MWL8K_CMDNAME(SET_EDCA_PARAMS);
349 MWL8K_CMDNAME(SET_WMM_MODE);
350 MWL8K_CMDNAME(MIMO_CONFIG);
351 MWL8K_CMDNAME(USE_FIXED_RATE);
352 MWL8K_CMDNAME(ENABLE_SNIFFER);
353 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
354 MWL8K_CMDNAME(UPDATE_STADB);
356 snprintf(buf, bufsize, "0x%x", cmd);
363 /* Hardware and firmware reset */
364 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
366 iowrite32(MWL8K_H2A_INT_RESET,
367 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
368 iowrite32(MWL8K_H2A_INT_RESET,
369 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
373 /* Release fw image */
374 static void mwl8k_release_fw(struct firmware **fw)
378 release_firmware(*fw);
382 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
384 mwl8k_release_fw(&priv->fw.ucode);
385 mwl8k_release_fw(&priv->fw.helper);
388 /* Request fw image */
389 static int mwl8k_request_fw(struct mwl8k_priv *priv,
390 const char *fname, struct firmware **fw)
392 /* release current image */
394 mwl8k_release_fw(fw);
396 return request_firmware((const struct firmware **)fw,
397 fname, &priv->pdev->dev);
400 static int mwl8k_request_firmware(struct mwl8k_priv *priv, u32 part_num)
405 priv->part_num = part_num;
407 snprintf(filename, sizeof(filename),
408 "mwl8k/helper_%u.fw", priv->part_num);
410 rc = mwl8k_request_fw(priv, filename, &priv->fw.helper);
413 "%s Error requesting helper firmware file %s\n",
414 pci_name(priv->pdev), filename);
418 snprintf(filename, sizeof(filename),
419 "mwl8k/fmimage_%u.fw", priv->part_num);
421 rc = mwl8k_request_fw(priv, filename, &priv->fw.ucode);
423 printk(KERN_ERR "%s Error requesting firmware file %s\n",
424 pci_name(priv->pdev), filename);
425 mwl8k_release_fw(&priv->fw.helper);
432 struct mwl8k_cmd_pkt {
438 } __attribute__((packed));
444 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
446 void __iomem *regs = priv->regs;
451 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
452 if (pci_dma_mapping_error(priv->pdev, dma_addr))
455 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
456 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
457 iowrite32(MWL8K_H2A_INT_DOORBELL,
458 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
459 iowrite32(MWL8K_H2A_INT_DUMMY,
460 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
467 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
468 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
469 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
477 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
480 * Clear 'command done' interrupt bit.
486 status = ioread32(priv->regs +
487 MWL8K_HIU_A2H_INTERRUPT_STATUS);
488 if (status & MWL8K_A2H_INT_OPC_DONE) {
489 iowrite32(~MWL8K_A2H_INT_OPC_DONE,
490 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
491 ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
501 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
502 const u8 *data, size_t length)
504 struct mwl8k_cmd_pkt *cmd;
508 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
512 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
518 int block_size = length > 256 ? 256 : length;
520 memcpy(cmd->payload, data + done, block_size);
521 cmd->length = cpu_to_le16(block_size);
523 rc = mwl8k_send_fw_load_cmd(priv, cmd,
524 sizeof(*cmd) + block_size);
529 length -= block_size;
534 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
542 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
543 const u8 *data, size_t length)
545 unsigned char *buffer;
546 int may_continue, rc = 0;
547 u32 done, prev_block_size;
549 buffer = kmalloc(1024, GFP_KERNEL);
556 while (may_continue > 0) {
559 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
560 if (block_size & 1) {
564 done += prev_block_size;
565 length -= prev_block_size;
568 if (block_size > 1024 || block_size > length) {
578 if (block_size == 0) {
585 prev_block_size = block_size;
586 memcpy(buffer, data + done, block_size);
588 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
593 if (!rc && length != 0)
601 static int mwl8k_load_firmware(struct mwl8k_priv *priv)
605 const u8 *ucode = priv->fw.ucode->data;
606 size_t ucode_len = priv->fw.ucode->size;
607 const u8 *helper = priv->fw.helper->data;
608 size_t helper_len = priv->fw.helper->size;
610 if (!memcmp(ucode, "\x01\x00\x00\x00", 4)) {
611 rc = mwl8k_load_fw_image(priv, helper, helper_len);
613 printk(KERN_ERR "%s: unable to load firmware "
614 "helper image\n", pci_name(priv->pdev));
619 rc = mwl8k_feed_fw_image(priv, ucode, ucode_len);
621 rc = mwl8k_load_fw_image(priv, ucode, ucode_len);
625 printk(KERN_ERR "%s: unable to load firmware data\n",
626 pci_name(priv->pdev));
630 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
635 if (ioread32(priv->regs + MWL8K_HIU_INT_CODE)
636 == MWL8K_FWSTA_READY)
641 return loops ? 0 : -ETIMEDOUT;
646 * Defines shared between transmission and reception.
648 /* HT control fields for firmware */
653 } __attribute__((packed));
655 /* Firmware Station database operations */
656 #define MWL8K_STA_DB_ADD_ENTRY 0
657 #define MWL8K_STA_DB_MODIFY_ENTRY 1
658 #define MWL8K_STA_DB_DEL_ENTRY 2
659 #define MWL8K_STA_DB_FLUSH 3
661 /* Peer Entry flags - used to define the type of the peer node */
662 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
664 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
665 #define MWL8K_MCS_BITMAP_SIZE 16
667 struct peer_capability_info {
668 /* Peer type - AP vs. STA. */
671 /* Basic 802.11 capabilities from assoc resp. */
674 /* Set if peer supports 802.11n high throughput (HT). */
677 /* Valid if HT is supported. */
679 __u8 extended_ht_caps;
680 struct ewc_ht_info ewc_info;
682 /* Legacy rate table. Intersection of our rates and peer rates. */
683 __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
685 /* HT rate table. Intersection of our rates and peer rates. */
686 __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
689 /* If set, interoperability mode, no proprietary extensions. */
693 __le16 amsdu_enabled;
694 } __attribute__((packed));
696 /* Inline functions to manipulate QoS field in data descriptor. */
697 static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
699 u16 val_mask = 1 << 4;
701 /* End of Service Period Bit 4 */
702 return qos | val_mask;
705 static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
709 u16 qos_mask = ~(val_mask << shift);
711 /* Ack Policy Bit 5-6 */
712 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
715 static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
717 u16 val_mask = 1 << 7;
719 /* AMSDU present Bit 7 */
720 return qos | val_mask;
723 static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
727 u16 qos_mask = ~(val_mask << shift);
729 /* Queue Length Bits 8-15 */
730 return (qos & qos_mask) | ((len & val_mask) << shift);
733 /* DMA header used by firmware and hardware. */
734 struct mwl8k_dma_data {
736 struct ieee80211_hdr wh;
737 } __attribute__((packed));
739 /* Routines to add/remove DMA header from skb. */
740 static inline int mwl8k_remove_dma_header(struct sk_buff *skb)
742 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)(skb->data);
743 void *dst, *src = &tr->wh;
744 __le16 fc = tr->wh.frame_control;
745 int hdrlen = ieee80211_hdrlen(fc);
746 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
748 dst = (void *)tr + space;
750 memmove(dst, src, hdrlen);
751 skb_pull(skb, space);
757 static inline struct sk_buff *mwl8k_add_dma_header(struct sk_buff *skb)
759 struct ieee80211_hdr *wh;
761 struct mwl8k_dma_data *tr;
763 wh = (struct ieee80211_hdr *)skb->data;
764 hdrlen = ieee80211_hdrlen(wh->frame_control);
768 * Copy up/down the 802.11 header; the firmware requires
769 * we present a 2-byte payload length followed by a
770 * 4-address header (w/o QoS), followed (optionally) by
771 * any WEP/ExtIV header (but only filled in for CCMP).
773 if (hdrlen != sizeof(struct mwl8k_dma_data))
774 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
776 tr = (struct mwl8k_dma_data *)skb->data;
778 memmove(&tr->wh, wh, hdrlen);
781 memset(tr->wh.addr4, 0, ETH_ALEN);
784 * Firmware length is the length of the fully formed "802.11
785 * payload". That is, everything except for the 802.11 header.
786 * This includes all crypto material including the MIC.
788 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
797 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
799 struct mwl8k_rx_desc {
803 __le32 pkt_phys_addr;
804 __le32 next_rx_desc_phys_addr;
814 } __attribute__((packed));
816 #define MWL8K_RX_DESCS 256
817 #define MWL8K_RX_MAXSZ 3800
819 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
821 struct mwl8k_priv *priv = hw->priv;
822 struct mwl8k_rx_queue *rxq = priv->rxq + index;
826 rxq->rx_desc_count = 0;
830 size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc);
833 pci_alloc_consistent(priv->pdev, size, &rxq->rx_desc_dma);
834 if (rxq->rx_desc_area == NULL) {
835 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
839 memset(rxq->rx_desc_area, 0, size);
841 rxq->rx_skb = kmalloc(MWL8K_RX_DESCS *
842 sizeof(*rxq->rx_skb), GFP_KERNEL);
843 if (rxq->rx_skb == NULL) {
844 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
846 pci_free_consistent(priv->pdev, size,
847 rxq->rx_desc_area, rxq->rx_desc_dma);
850 memset(rxq->rx_skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->rx_skb));
852 for (i = 0; i < MWL8K_RX_DESCS; i++) {
853 struct mwl8k_rx_desc *rx_desc;
856 rx_desc = rxq->rx_desc_area + i;
857 nexti = (i + 1) % MWL8K_RX_DESCS;
859 rx_desc->next_rx_desc_phys_addr =
860 cpu_to_le32(rxq->rx_desc_dma
861 + nexti * sizeof(*rx_desc));
862 rx_desc->rx_ctrl = MWL8K_RX_CTRL_OWNED_BY_HOST;
868 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
870 struct mwl8k_priv *priv = hw->priv;
871 struct mwl8k_rx_queue *rxq = priv->rxq + index;
875 while (rxq->rx_desc_count < MWL8K_RX_DESCS && limit--) {
879 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
883 rxq->rx_desc_count++;
886 rxq->rx_tail = (rx + 1) % MWL8K_RX_DESCS;
888 rxq->rx_desc_area[rx].pkt_phys_addr =
889 cpu_to_le32(pci_map_single(priv->pdev, skb->data,
890 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE));
892 rxq->rx_desc_area[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ);
893 rxq->rx_skb[rx] = skb;
895 rxq->rx_desc_area[rx].rx_ctrl = 0;
903 /* Must be called only when the card's reception is completely halted */
904 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
906 struct mwl8k_priv *priv = hw->priv;
907 struct mwl8k_rx_queue *rxq = priv->rxq + index;
910 for (i = 0; i < MWL8K_RX_DESCS; i++) {
911 if (rxq->rx_skb[i] != NULL) {
914 addr = le32_to_cpu(rxq->rx_desc_area[i].pkt_phys_addr);
915 pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ,
917 kfree_skb(rxq->rx_skb[i]);
918 rxq->rx_skb[i] = NULL;
925 pci_free_consistent(priv->pdev,
926 MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc),
927 rxq->rx_desc_area, rxq->rx_desc_dma);
928 rxq->rx_desc_area = NULL;
933 * Scan a list of BSSIDs to process for finalize join.
934 * Allows for extension to process multiple BSSIDs.
937 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
939 return priv->capture_beacon &&
940 ieee80211_is_beacon(wh->frame_control) &&
941 !compare_ether_addr(wh->addr3, priv->capture_bssid);
944 static inline void mwl8k_save_beacon(struct mwl8k_priv *priv,
947 priv->capture_beacon = false;
948 memset(priv->capture_bssid, 0, ETH_ALEN);
951 * Use GFP_ATOMIC as rxq_process is called from
952 * the primary interrupt handler, memory allocation call
955 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
956 if (priv->beacon_skb != NULL)
957 queue_work(priv->config_wq,
958 &priv->finalize_join_worker);
961 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
963 struct mwl8k_priv *priv = hw->priv;
964 struct mwl8k_rx_queue *rxq = priv->rxq + index;
968 while (rxq->rx_desc_count && limit--) {
969 struct mwl8k_rx_desc *rx_desc;
971 struct ieee80211_rx_status status;
973 struct ieee80211_hdr *wh;
975 rx_desc = rxq->rx_desc_area + rxq->rx_head;
976 if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST))
980 skb = rxq->rx_skb[rxq->rx_head];
983 rxq->rx_skb[rxq->rx_head] = NULL;
985 rxq->rx_head = (rxq->rx_head + 1) % MWL8K_RX_DESCS;
986 rxq->rx_desc_count--;
988 addr = le32_to_cpu(rx_desc->pkt_phys_addr);
989 pci_unmap_single(priv->pdev, addr,
990 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
992 skb_put(skb, le16_to_cpu(rx_desc->pkt_len));
993 if (mwl8k_remove_dma_header(skb)) {
998 wh = (struct ieee80211_hdr *)skb->data;
1001 * Check for pending join operation. save a copy of
1002 * the beacon and schedule a tasklet to send finalize
1003 * join command to the firmware.
1005 if (mwl8k_capture_bssid(priv, wh))
1006 mwl8k_save_beacon(priv, skb);
1008 memset(&status, 0, sizeof(status));
1010 status.signal = -rx_desc->rssi;
1011 status.noise = -rx_desc->noise_level;
1012 status.qual = rx_desc->link_quality;
1014 status.rate_idx = 1;
1016 status.band = IEEE80211_BAND_2GHZ;
1017 status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
1018 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1019 ieee80211_rx_irqsafe(hw, skb);
1029 * Packet transmission.
1032 /* Transmit queue assignment. */
1034 MWL8K_WME_AC_BK = 0, /* background access */
1035 MWL8K_WME_AC_BE = 1, /* best effort access */
1036 MWL8K_WME_AC_VI = 2, /* video access */
1037 MWL8K_WME_AC_VO = 3, /* voice access */
1040 /* Transmit packet ACK policy */
1041 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
1042 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1044 #define GET_TXQ(_ac) (\
1045 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
1046 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
1047 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
1050 #define MWL8K_TXD_STATUS_OK 0x00000001
1051 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1052 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1053 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1054 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1056 struct mwl8k_tx_desc {
1061 __le32 pkt_phys_addr;
1063 __u8 dest_MAC_addr[ETH_ALEN];
1064 __le32 next_tx_desc_phys_addr;
1069 } __attribute__((packed));
1071 #define MWL8K_TX_DESCS 128
1073 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1075 struct mwl8k_priv *priv = hw->priv;
1076 struct mwl8k_tx_queue *txq = priv->txq + index;
1080 memset(&txq->tx_stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1081 txq->tx_stats.limit = MWL8K_TX_DESCS;
1085 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1088 pci_alloc_consistent(priv->pdev, size, &txq->tx_desc_dma);
1089 if (txq->tx_desc_area == NULL) {
1090 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1094 memset(txq->tx_desc_area, 0, size);
1096 txq->tx_skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->tx_skb),
1098 if (txq->tx_skb == NULL) {
1099 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1101 pci_free_consistent(priv->pdev, size,
1102 txq->tx_desc_area, txq->tx_desc_dma);
1105 memset(txq->tx_skb, 0, MWL8K_TX_DESCS * sizeof(*txq->tx_skb));
1107 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1108 struct mwl8k_tx_desc *tx_desc;
1111 tx_desc = txq->tx_desc_area + i;
1112 nexti = (i + 1) % MWL8K_TX_DESCS;
1114 tx_desc->status = 0;
1115 tx_desc->next_tx_desc_phys_addr =
1116 cpu_to_le32(txq->tx_desc_dma +
1117 nexti * sizeof(*tx_desc));
1123 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1125 iowrite32(MWL8K_H2A_INT_PPA_READY,
1126 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1127 iowrite32(MWL8K_H2A_INT_DUMMY,
1128 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1129 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1132 static inline int mwl8k_txq_busy(struct mwl8k_priv *priv)
1134 return priv->pending_tx_pkts;
1137 struct mwl8k_txq_info {
1146 static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
1147 struct mwl8k_txq_info txinfo[],
1150 int count, desc, status;
1151 struct mwl8k_tx_queue *txq;
1152 struct mwl8k_tx_desc *tx_desc;
1155 memset(txinfo, 0, num_queues * sizeof(struct mwl8k_txq_info));
1156 spin_lock_bh(&priv->tx_lock);
1157 for (count = 0; count < num_queues; count++) {
1158 txq = priv->txq + count;
1159 txinfo[count].len = txq->tx_stats.len;
1160 txinfo[count].head = txq->tx_head;
1161 txinfo[count].tail = txq->tx_tail;
1162 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1163 tx_desc = txq->tx_desc_area + desc;
1164 status = le32_to_cpu(tx_desc->status);
1166 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1167 txinfo[count].fw_owned++;
1169 txinfo[count].drv_owned++;
1171 if (tx_desc->pkt_len == 0)
1172 txinfo[count].unused++;
1175 spin_unlock_bh(&priv->tx_lock);
1180 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw, u32 delay_ms)
1182 struct mwl8k_priv *priv = hw->priv;
1183 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1185 unsigned long timeout;
1189 if (priv->tx_wait != NULL)
1190 printk(KERN_ERR "WARNING Previous TXWaitEmpty instance\n");
1192 spin_lock_bh(&priv->tx_lock);
1193 count = mwl8k_txq_busy(priv);
1195 priv->tx_wait = &cmd_wait;
1197 mwl8k_tx_start(priv);
1199 spin_unlock_bh(&priv->tx_lock);
1202 struct mwl8k_txq_info txinfo[4];
1206 timeout = wait_for_completion_timeout(&cmd_wait,
1207 msecs_to_jiffies(delay_ms));
1211 spin_lock_bh(&priv->tx_lock);
1212 priv->tx_wait = NULL;
1213 newcount = mwl8k_txq_busy(priv);
1214 spin_unlock_bh(&priv->tx_lock);
1216 printk(KERN_ERR "%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
1217 __func__, __LINE__, delay_ms, count, newcount);
1219 mwl8k_scan_tx_ring(priv, txinfo, 4);
1220 for (index = 0; index < 4; index++)
1222 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
1227 txinfo[index].fw_owned,
1228 txinfo[index].drv_owned,
1229 txinfo[index].unused);
1237 #define MWL8K_TXD_SUCCESS(status) \
1238 ((status) & (MWL8K_TXD_STATUS_OK | \
1239 MWL8K_TXD_STATUS_OK_RETRY | \
1240 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1242 static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1244 struct mwl8k_priv *priv = hw->priv;
1245 struct mwl8k_tx_queue *txq = priv->txq + index;
1248 while (txq->tx_stats.len > 0) {
1251 struct mwl8k_tx_desc *tx_desc;
1254 struct sk_buff *skb;
1255 struct ieee80211_tx_info *info;
1260 tx_desc = txq->tx_desc_area + tx;
1262 status = le32_to_cpu(tx_desc->status);
1264 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1268 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1271 txq->tx_head = (tx + 1) % MWL8K_TX_DESCS;
1272 BUG_ON(txq->tx_stats.len == 0);
1273 txq->tx_stats.len--;
1274 priv->pending_tx_pkts--;
1276 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1277 size = le16_to_cpu(tx_desc->pkt_len);
1278 skb = txq->tx_skb[tx].skb;
1279 txq->tx_skb[tx].skb = NULL;
1281 BUG_ON(skb == NULL);
1282 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1284 rc = mwl8k_remove_dma_header(skb);
1286 /* Mark descriptor as unused */
1287 tx_desc->pkt_phys_addr = 0;
1288 tx_desc->pkt_len = 0;
1290 if (txq->tx_skb[tx].clone) {
1291 /* Replace with original skb
1292 * before returning to stack
1293 * as buffer has been cloned
1296 skb = txq->tx_skb[tx].clone;
1297 txq->tx_skb[tx].clone = NULL;
1301 /* Something has gone wrong here.
1302 * Failed to remove DMA header.
1303 * Print error message and drop packet.
1305 printk(KERN_ERR "%s: Error removing DMA header from "
1306 "tx skb 0x%p.\n", priv->name, skb);
1312 info = IEEE80211_SKB_CB(skb);
1313 ieee80211_tx_info_clear_status(info);
1314 if (MWL8K_TXD_SUCCESS(status))
1315 info->flags |= IEEE80211_TX_STAT_ACK;
1317 ieee80211_tx_status_irqsafe(hw, skb);
1319 wake = !priv->inconfig && priv->radio_on;
1323 ieee80211_wake_queue(hw, index);
1326 /* must be called only when the card's transmit is completely halted */
1327 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1329 struct mwl8k_priv *priv = hw->priv;
1330 struct mwl8k_tx_queue *txq = priv->txq + index;
1332 mwl8k_txq_reclaim(hw, index, 1);
1337 pci_free_consistent(priv->pdev,
1338 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1339 txq->tx_desc_area, txq->tx_desc_dma);
1340 txq->tx_desc_area = NULL;
1344 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1346 struct mwl8k_priv *priv = hw->priv;
1347 struct ieee80211_tx_info *tx_info;
1348 struct ieee80211_hdr *wh;
1349 struct mwl8k_tx_queue *txq;
1350 struct mwl8k_tx_desc *tx;
1351 struct mwl8k_dma_data *tr;
1352 struct mwl8k_vif *mwl8k_vif;
1353 struct sk_buff *org_skb = skb;
1356 bool qosframe = false, ampduframe = false;
1357 bool mcframe = false, eapolframe = false;
1358 bool amsduframe = false;
1361 txq = priv->txq + index;
1362 tx = txq->tx_desc_area + txq->tx_tail;
1364 BUG_ON(txq->tx_skb[txq->tx_tail].skb != NULL);
1367 * Append HW DMA header to start of packet. Drop packet if
1368 * there is not enough space or a failure to unshare/unclone
1371 skb = mwl8k_add_dma_header(skb);
1374 printk(KERN_DEBUG "%s: failed to prepend HW DMA "
1375 "header, dropping TX frame.\n", priv->name);
1376 dev_kfree_skb(org_skb);
1377 return NETDEV_TX_OK;
1380 tx_info = IEEE80211_SKB_CB(skb);
1381 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1382 tr = (struct mwl8k_dma_data *)skb->data;
1384 fc = wh->frame_control;
1385 qosframe = ieee80211_is_data_qos(fc);
1386 mcframe = is_multicast_ether_addr(wh->addr1);
1387 ampduframe = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
1389 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1390 u16 seqno = mwl8k_vif->seqno;
1391 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1392 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1393 mwl8k_vif->seqno = seqno++ % 4096;
1397 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1399 dma = pci_map_single(priv->pdev, skb->data,
1400 skb->len, PCI_DMA_TODEVICE);
1402 if (pci_dma_mapping_error(priv->pdev, dma)) {
1403 printk(KERN_DEBUG "%s: failed to dma map skb, "
1404 "dropping TX frame.\n", priv->name);
1406 if (org_skb != NULL)
1407 dev_kfree_skb(org_skb);
1410 return NETDEV_TX_OK;
1413 /* Set desc header, cpu bit order. */
1416 tx->tx_priority = index;
1417 tx->qos_control = 0;
1419 tx->peer_id = mwl8k_vif->peer_id;
1421 amsduframe = !!(qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT);
1423 /* Setup firmware control bit fields for each frame type. */
1424 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) {
1426 qos = mwl8k_qos_setbit_eosp(qos);
1427 /* Set Queue size to unspecified */
1428 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1429 } else if (ieee80211_is_data(fc)) {
1432 tx->status |= MWL8K_TXD_STATUS_MULTICAST_TX;
1435 * Tell firmware to not send EAPOL pkts in an
1436 * aggregate. Verify against mac80211 tx path. If
1437 * stack turns off AMPDU for an EAPOL frame this
1438 * check will be removed.
1441 qos = mwl8k_qos_setbit_ack(qos,
1442 MWL8K_TXD_ACK_POLICY_NORMAL);
1444 /* Send pkt in an aggregate if AMPDU frame. */
1446 qos = mwl8k_qos_setbit_ack(qos,
1447 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1449 qos = mwl8k_qos_setbit_ack(qos,
1450 MWL8K_TXD_ACK_POLICY_NORMAL);
1453 qos = mwl8k_qos_setbit_amsdu(qos);
1457 /* Convert to little endian */
1458 tx->qos_control = cpu_to_le16(qos);
1459 tx->status = cpu_to_le32(tx->status);
1460 tx->pkt_phys_addr = cpu_to_le32(dma);
1461 tx->pkt_len = cpu_to_le16(skb->len);
1463 txq->tx_skb[txq->tx_tail].skb = skb;
1464 txq->tx_skb[txq->tx_tail].clone =
1465 skb == org_skb ? NULL : org_skb;
1467 spin_lock_bh(&priv->tx_lock);
1469 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_OK |
1470 MWL8K_TXD_STATUS_FW_OWNED);
1472 txq->tx_stats.len++;
1473 priv->pending_tx_pkts++;
1474 txq->tx_stats.count++;
1477 if (txq->tx_tail == MWL8K_TX_DESCS)
1479 if (txq->tx_head == txq->tx_tail)
1480 ieee80211_stop_queue(hw, index);
1482 if (priv->inconfig) {
1484 * Silently queue packet when we are in the middle of
1485 * a config cycle. Notify firmware only if we are
1486 * waiting for TXQs to empty. If a packet is sent
1487 * before .config() is complete, perhaps it is better
1488 * to drop the packet, as the channel is being changed
1489 * and the packet will end up on the wrong channel.
1491 printk(KERN_ERR "%s(): WARNING TX activity while "
1492 "in config\n", __func__);
1494 if (priv->tx_wait != NULL)
1495 mwl8k_tx_start(priv);
1497 mwl8k_tx_start(priv);
1499 spin_unlock_bh(&priv->tx_lock);
1501 return NETDEV_TX_OK;
1506 * Command processing.
1509 /* Timeout firmware commands after 2000ms */
1510 #define MWL8K_CMD_TIMEOUT_MS 2000
1512 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1514 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1515 struct mwl8k_priv *priv = hw->priv;
1516 void __iomem *regs = priv->regs;
1517 dma_addr_t dma_addr;
1518 unsigned int dma_size;
1520 unsigned long timeout = 0;
1523 cmd->result = 0xFFFF;
1524 dma_size = le16_to_cpu(cmd->length);
1525 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1526 PCI_DMA_BIDIRECTIONAL);
1527 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1530 if (priv->hostcmd_wait != NULL)
1531 printk(KERN_ERR "WARNING host command in progress\n");
1533 spin_lock_irq(&priv->fw_lock);
1534 priv->hostcmd_wait = &cmd_wait;
1535 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1536 iowrite32(MWL8K_H2A_INT_DOORBELL,
1537 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1538 iowrite32(MWL8K_H2A_INT_DUMMY,
1539 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1540 spin_unlock_irq(&priv->fw_lock);
1542 timeout = wait_for_completion_timeout(&cmd_wait,
1543 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1545 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1546 PCI_DMA_BIDIRECTIONAL);
1549 spin_lock_irq(&priv->fw_lock);
1550 priv->hostcmd_wait = NULL;
1551 spin_unlock_irq(&priv->fw_lock);
1552 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1554 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1555 MWL8K_CMD_TIMEOUT_MS);
1558 rc = cmd->result ? -EINVAL : 0;
1560 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1562 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1572 struct mwl8k_cmd_get_hw_spec {
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;
1588 __le32 total_rx_desc;
1589 } __attribute__((packed));
1591 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
1593 struct mwl8k_priv *priv = hw->priv;
1594 struct mwl8k_cmd_get_hw_spec *cmd;
1598 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1602 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1603 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1605 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1606 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1607 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rx_desc_dma);
1608 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1609 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1610 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].tx_desc_dma);
1611 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1612 cmd->total_rx_desc = cpu_to_le32(MWL8K_RX_DESCS);
1614 rc = mwl8k_post_cmd(hw, &cmd->header);
1617 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1618 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1619 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1620 priv->hw_rev = cmd->hw_rev;
1628 * CMD_MAC_MULTICAST_ADR.
1630 struct mwl8k_cmd_mac_multicast_adr {
1631 struct mwl8k_cmd_pkt header;
1634 __u8 addr[0][ETH_ALEN];
1637 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
1639 static int mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
1641 struct dev_addr_list *mclist)
1643 struct mwl8k_cmd_mac_multicast_adr *cmd;
1646 int size = sizeof(*cmd) + mc_count * ETH_ALEN;
1648 cmd = kzalloc(size, GFP_KERNEL);
1652 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1653 cmd->header.length = cpu_to_le16(size);
1654 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1655 cmd->numaddr = cpu_to_le16(mc_count);
1657 while (index < mc_count && mclist) {
1658 if (mclist->da_addrlen != ETH_ALEN) {
1660 goto mwl8k_cmd_mac_multicast_adr_exit;
1662 memcpy(cmd->addr[index++], mclist->da_addr, ETH_ALEN);
1663 mclist = mclist->next;
1666 rc = mwl8k_post_cmd(hw, &cmd->header);
1668 mwl8k_cmd_mac_multicast_adr_exit:
1674 * CMD_802_11_GET_STAT.
1676 struct mwl8k_cmd_802_11_get_stat {
1677 struct mwl8k_cmd_pkt header;
1680 } __attribute__((packed));
1682 #define MWL8K_STAT_ACK_FAILURE 9
1683 #define MWL8K_STAT_RTS_FAILURE 12
1684 #define MWL8K_STAT_FCS_ERROR 24
1685 #define MWL8K_STAT_RTS_SUCCESS 11
1687 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1688 struct ieee80211_low_level_stats *stats)
1690 struct mwl8k_cmd_802_11_get_stat *cmd;
1693 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1697 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1698 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1699 cmd->action = cpu_to_le16(MWL8K_CMD_GET);
1701 rc = mwl8k_post_cmd(hw, &cmd->header);
1703 stats->dot11ACKFailureCount =
1704 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1705 stats->dot11RTSFailureCount =
1706 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1707 stats->dot11FCSErrorCount =
1708 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1709 stats->dot11RTSSuccessCount =
1710 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1718 * CMD_802_11_RADIO_CONTROL.
1720 struct mwl8k_cmd_802_11_radio_control {
1721 struct mwl8k_cmd_pkt header;
1725 } __attribute__((packed));
1728 mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
1730 struct mwl8k_priv *priv = hw->priv;
1731 struct mwl8k_cmd_802_11_radio_control *cmd;
1734 if (enable == priv->radio_on && !force)
1737 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1741 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1742 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1743 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1744 cmd->control = cpu_to_le16(priv->radio_preamble);
1745 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1747 rc = mwl8k_post_cmd(hw, &cmd->header);
1751 priv->radio_on = enable;
1756 static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1758 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1761 static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1763 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1767 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1769 struct mwl8k_priv *priv;
1771 if (hw == NULL || hw->priv == NULL)
1775 priv->radio_preamble = (short_preamble ?
1776 MWL8K_RADIO_SHORT_PREAMBLE :
1777 MWL8K_RADIO_LONG_PREAMBLE);
1779 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
1783 * CMD_802_11_RF_TX_POWER.
1785 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1787 struct mwl8k_cmd_802_11_rf_tx_power {
1788 struct mwl8k_cmd_pkt header;
1790 __le16 support_level;
1791 __le16 current_level;
1793 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1794 } __attribute__((packed));
1796 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1798 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1801 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1805 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1806 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1807 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1808 cmd->support_level = cpu_to_le16(dBm);
1810 rc = mwl8k_post_cmd(hw, &cmd->header);
1819 struct mwl8k_cmd_set_pre_scan {
1820 struct mwl8k_cmd_pkt header;
1821 } __attribute__((packed));
1823 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
1825 struct mwl8k_cmd_set_pre_scan *cmd;
1828 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1832 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
1833 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1835 rc = mwl8k_post_cmd(hw, &cmd->header);
1842 * CMD_SET_POST_SCAN.
1844 struct mwl8k_cmd_set_post_scan {
1845 struct mwl8k_cmd_pkt header;
1847 __u8 bssid[ETH_ALEN];
1848 } __attribute__((packed));
1851 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
1853 struct mwl8k_cmd_set_post_scan *cmd;
1856 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1860 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
1861 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1863 memcpy(cmd->bssid, mac, ETH_ALEN);
1865 rc = mwl8k_post_cmd(hw, &cmd->header);
1872 * CMD_SET_RF_CHANNEL.
1874 struct mwl8k_cmd_set_rf_channel {
1875 struct mwl8k_cmd_pkt header;
1877 __u8 current_channel;
1878 __le32 channel_flags;
1879 } __attribute__((packed));
1881 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
1882 struct ieee80211_channel *channel)
1884 struct mwl8k_cmd_set_rf_channel *cmd;
1887 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1891 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
1892 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1893 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1894 cmd->current_channel = channel->hw_value;
1895 if (channel->band == IEEE80211_BAND_2GHZ)
1896 cmd->channel_flags = cpu_to_le32(0x00000081);
1898 cmd->channel_flags = cpu_to_le32(0x00000000);
1900 rc = mwl8k_post_cmd(hw, &cmd->header);
1909 struct mwl8k_cmd_set_slot {
1910 struct mwl8k_cmd_pkt header;
1913 } __attribute__((packed));
1915 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, int slot_time)
1917 struct mwl8k_cmd_set_slot *cmd;
1920 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1924 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
1925 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1926 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1927 cmd->short_slot = slot_time == MWL8K_SHORT_SLOTTIME ? 1 : 0;
1929 rc = mwl8k_post_cmd(hw, &cmd->header);
1938 struct mwl8k_cmd_mimo_config {
1939 struct mwl8k_cmd_pkt header;
1941 __u8 rx_antenna_map;
1942 __u8 tx_antenna_map;
1943 } __attribute__((packed));
1945 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
1947 struct mwl8k_cmd_mimo_config *cmd;
1950 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1954 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
1955 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1956 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
1957 cmd->rx_antenna_map = rx;
1958 cmd->tx_antenna_map = tx;
1960 rc = mwl8k_post_cmd(hw, &cmd->header);
1967 * CMD_ENABLE_SNIFFER.
1969 struct mwl8k_cmd_enable_sniffer {
1970 struct mwl8k_cmd_pkt header;
1972 } __attribute__((packed));
1974 static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
1976 struct mwl8k_cmd_enable_sniffer *cmd;
1979 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1983 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
1984 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1985 cmd->action = cpu_to_le32(!!enable);
1987 rc = mwl8k_post_cmd(hw, &cmd->header);
1994 * CMD_SET_RATEADAPT_MODE.
1996 struct mwl8k_cmd_set_rate_adapt_mode {
1997 struct mwl8k_cmd_pkt header;
2000 } __attribute__((packed));
2002 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2004 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2007 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2011 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2012 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2013 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2014 cmd->mode = cpu_to_le16(mode);
2016 rc = mwl8k_post_cmd(hw, &cmd->header);
2025 struct mwl8k_cmd_set_wmm {
2026 struct mwl8k_cmd_pkt header;
2028 } __attribute__((packed));
2030 static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2032 struct mwl8k_priv *priv = hw->priv;
2033 struct mwl8k_cmd_set_wmm *cmd;
2036 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2040 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2041 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2042 cmd->action = enable ? cpu_to_le16(MWL8K_CMD_SET) : 0;
2044 rc = mwl8k_post_cmd(hw, &cmd->header);
2048 priv->wmm_mode = enable;
2054 * CMD_SET_RTS_THRESHOLD.
2056 struct mwl8k_cmd_rts_threshold {
2057 struct mwl8k_cmd_pkt header;
2060 } __attribute__((packed));
2062 static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
2063 u16 action, u16 *threshold)
2065 struct mwl8k_cmd_rts_threshold *cmd;
2068 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2072 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2073 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2074 cmd->action = cpu_to_le16(action);
2075 cmd->threshold = cpu_to_le16(*threshold);
2077 rc = mwl8k_post_cmd(hw, &cmd->header);
2084 * CMD_SET_EDCA_PARAMS.
2086 struct mwl8k_cmd_set_edca_params {
2087 struct mwl8k_cmd_pkt header;
2089 /* See MWL8K_SET_EDCA_XXX below */
2092 /* TX opportunity in units of 32 us */
2095 /* Log exponent of max contention period: 0...15*/
2098 /* Log exponent of min contention period: 0...15 */
2101 /* Adaptive interframe spacing in units of 32us */
2104 /* TX queue to configure */
2106 } __attribute__((packed));
2108 #define MWL8K_SET_EDCA_CW 0x01
2109 #define MWL8K_SET_EDCA_TXOP 0x02
2110 #define MWL8K_SET_EDCA_AIFS 0x04
2112 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2113 MWL8K_SET_EDCA_TXOP | \
2114 MWL8K_SET_EDCA_AIFS)
2117 mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2118 __u16 cw_min, __u16 cw_max,
2119 __u8 aifs, __u16 txop)
2121 struct mwl8k_cmd_set_edca_params *cmd;
2124 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2128 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2129 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2130 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2131 cmd->txop = cpu_to_le16(txop);
2132 cmd->log_cw_max = (u8)ilog2(cw_max + 1);
2133 cmd->log_cw_min = (u8)ilog2(cw_min + 1);
2137 rc = mwl8k_post_cmd(hw, &cmd->header);
2144 * CMD_FINALIZE_JOIN.
2147 /* FJ beacon buffer size is compiled into the firmware. */
2148 #define MWL8K_FJ_BEACON_MAXLEN 128
2150 struct mwl8k_cmd_finalize_join {
2151 struct mwl8k_cmd_pkt header;
2152 __le32 sleep_interval; /* Number of beacon periods to sleep */
2153 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2154 } __attribute__((packed));
2156 static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2157 __u16 framelen, __u16 dtim)
2159 struct mwl8k_cmd_finalize_join *cmd;
2160 struct ieee80211_mgmt *payload = frame;
2168 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2172 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2173 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2174 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2176 hdrlen = ieee80211_hdrlen(payload->frame_control);
2178 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2180 /* XXX TBD Might just have to abort and return an error */
2181 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2182 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
2183 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2184 payload_len, MWL8K_FJ_BEACON_MAXLEN);
2186 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2187 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2189 if (payload && payload_len)
2190 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2192 rc = mwl8k_post_cmd(hw, &cmd->header);
2200 struct mwl8k_cmd_update_sta_db {
2201 struct mwl8k_cmd_pkt header;
2203 /* See STADB_ACTION_TYPE */
2206 /* Peer MAC address */
2207 __u8 peer_addr[ETH_ALEN];
2211 /* Peer info - valid during add/update. */
2212 struct peer_capability_info peer_info;
2213 } __attribute__((packed));
2215 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2216 struct ieee80211_vif *vif, __u32 action)
2218 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2219 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2220 struct mwl8k_cmd_update_sta_db *cmd;
2221 struct peer_capability_info *peer_info;
2222 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2226 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2230 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2231 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2233 cmd->action = cpu_to_le32(action);
2234 peer_info = &cmd->peer_info;
2235 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2238 case MWL8K_STA_DB_ADD_ENTRY:
2239 case MWL8K_STA_DB_MODIFY_ENTRY:
2240 /* Build peer_info block */
2241 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2242 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2243 peer_info->interop = 1;
2244 peer_info->amsdu_enabled = 0;
2246 rates = peer_info->legacy_rates;
2247 for (count = 0; count < mv_vif->legacy_nrates; count++)
2248 rates[count] = bitrates[count].hw_value;
2250 rc = mwl8k_post_cmd(hw, &cmd->header);
2252 mv_vif->peer_id = peer_info->station_id;
2256 case MWL8K_STA_DB_DEL_ENTRY:
2257 case MWL8K_STA_DB_FLUSH:
2259 rc = mwl8k_post_cmd(hw, &cmd->header);
2261 mv_vif->peer_id = 0;
2272 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2274 #define MWL8K_FRAME_PROT_DISABLED 0x00
2275 #define MWL8K_FRAME_PROT_11G 0x07
2276 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2277 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2279 struct mwl8k_cmd_update_set_aid {
2280 struct mwl8k_cmd_pkt header;
2283 /* AP's MAC address (BSSID) */
2284 __u8 bssid[ETH_ALEN];
2285 __le16 protection_mode;
2286 __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2287 } __attribute__((packed));
2289 static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2290 struct ieee80211_vif *vif)
2292 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2293 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2294 struct mwl8k_cmd_update_set_aid *cmd;
2295 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2300 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2304 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2305 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2306 cmd->aid = cpu_to_le16(info->aid);
2308 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
2310 if (info->use_cts_prot) {
2311 prot_mode = MWL8K_FRAME_PROT_11G;
2313 switch (info->ht_operation_mode &
2314 IEEE80211_HT_OP_MODE_PROTECTION) {
2315 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2316 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2318 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2319 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2322 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2326 cmd->protection_mode = cpu_to_le16(prot_mode);
2328 for (count = 0; count < mv_vif->legacy_nrates; count++)
2329 cmd->supp_rates[count] = bitrates[count].hw_value;
2331 rc = mwl8k_post_cmd(hw, &cmd->header);
2340 struct mwl8k_cmd_update_rateset {
2341 struct mwl8k_cmd_pkt header;
2342 __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2344 /* Bitmap for supported MCS codes. */
2345 __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
2346 __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
2347 } __attribute__((packed));
2349 static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2350 struct ieee80211_vif *vif)
2352 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2353 struct mwl8k_cmd_update_rateset *cmd;
2354 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2358 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2362 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2363 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2365 for (count = 0; count < mv_vif->legacy_nrates; count++)
2366 cmd->legacy_rates[count] = bitrates[count].hw_value;
2368 rc = mwl8k_post_cmd(hw, &cmd->header);
2375 * CMD_USE_FIXED_RATE.
2377 #define MWL8K_RATE_TABLE_SIZE 8
2378 #define MWL8K_UCAST_RATE 0
2379 #define MWL8K_USE_AUTO_RATE 0x0002
2381 struct mwl8k_rate_entry {
2382 /* Set to 1 if HT rate, 0 if legacy. */
2385 /* Set to 1 to use retry_count field. */
2386 __le32 enable_retry;
2388 /* Specified legacy rate or MCS. */
2391 /* Number of allowed retries. */
2393 } __attribute__((packed));
2395 struct mwl8k_rate_table {
2396 /* 1 to allow specified rate and below */
2397 __le32 allow_rate_drop;
2399 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2400 } __attribute__((packed));
2402 struct mwl8k_cmd_use_fixed_rate {
2403 struct mwl8k_cmd_pkt header;
2405 struct mwl8k_rate_table rate_table;
2407 /* Unicast, Broadcast or Multicast */
2411 } __attribute__((packed));
2413 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2414 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2416 struct mwl8k_cmd_use_fixed_rate *cmd;
2420 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2424 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2425 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2427 cmd->action = cpu_to_le32(action);
2428 cmd->rate_type = cpu_to_le32(rate_type);
2430 if (rate_table != NULL) {
2431 /* Copy over each field manually so
2432 * that bitflipping can be done
2434 cmd->rate_table.allow_rate_drop =
2435 cpu_to_le32(rate_table->allow_rate_drop);
2436 cmd->rate_table.num_rates =
2437 cpu_to_le32(rate_table->num_rates);
2439 for (count = 0; count < rate_table->num_rates; count++) {
2440 struct mwl8k_rate_entry *dst =
2441 &cmd->rate_table.rate_entry[count];
2442 struct mwl8k_rate_entry *src =
2443 &rate_table->rate_entry[count];
2445 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2446 dst->enable_retry = cpu_to_le32(src->enable_retry);
2447 dst->rate = cpu_to_le32(src->rate);
2448 dst->retry_count = cpu_to_le32(src->retry_count);
2452 rc = mwl8k_post_cmd(hw, &cmd->header);
2460 * Interrupt handling.
2462 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2464 struct ieee80211_hw *hw = dev_id;
2465 struct mwl8k_priv *priv = hw->priv;
2468 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2469 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2474 if (status & MWL8K_A2H_INT_TX_DONE)
2475 tasklet_schedule(&priv->tx_reclaim_task);
2477 if (status & MWL8K_A2H_INT_RX_READY) {
2478 while (rxq_process(hw, 0, 1))
2479 rxq_refill(hw, 0, 1);
2482 if (status & MWL8K_A2H_INT_OPC_DONE) {
2483 if (priv->hostcmd_wait != NULL) {
2484 complete(priv->hostcmd_wait);
2485 priv->hostcmd_wait = NULL;
2489 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
2490 if (!priv->inconfig &&
2492 mwl8k_txq_busy(priv))
2493 mwl8k_tx_start(priv);
2501 * Core driver operations.
2503 static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2505 struct mwl8k_priv *priv = hw->priv;
2506 int index = skb_get_queue_mapping(skb);
2509 if (priv->current_channel == NULL) {
2510 printk(KERN_DEBUG "%s: dropped TX frame since radio "
2511 "disabled\n", priv->name);
2513 return NETDEV_TX_OK;
2516 rc = mwl8k_txq_xmit(hw, index, skb);
2521 struct mwl8k_work_struct {
2522 /* Initialized by mwl8k_queue_work(). */
2523 struct work_struct wt;
2525 /* Required field passed in to mwl8k_queue_work(). */
2526 struct ieee80211_hw *hw;
2528 /* Required field passed in to mwl8k_queue_work(). */
2529 int (*wfunc)(struct work_struct *w);
2531 /* Initialized by mwl8k_queue_work(). */
2532 struct completion *cmd_wait;
2538 * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
2539 * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
2543 /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
2544 unsigned long timeout_ms;
2546 /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
2547 u32 txwait_attempts;
2549 /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
2554 /* Flags controlling behavior of config queue requests */
2556 /* Caller spins while waiting for completion. */
2557 #define MWL8K_WQ_SPIN 0x00000001
2559 /* Wait for TX queues to empty before proceeding with configuration. */
2560 #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
2562 /* Queue request and return immediately. */
2563 #define MWL8K_WQ_POST_REQUEST 0x00000004
2566 * Caller sleeps and waits for task complete notification.
2567 * Do not use in atomic context.
2569 #define MWL8K_WQ_SLEEP 0x00000008
2571 /* Free work struct when task is done. */
2572 #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
2575 * Config request is queued and returns to caller imediately. Use
2576 * this in atomic context. Work struct is freed by mwl8k_queue_work()
2577 * when this flag is set.
2579 #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
2580 MWL8K_WQ_FREE_WORKSTRUCT)
2582 /* Default work queue behavior is to sleep and wait for tx completion. */
2583 #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
2586 * Default config request timeout. Add adjustments to make sure the
2587 * config thread waits long enough for both tx wait and cmd wait before
2591 /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
2592 #define MWL8K_TXWAIT_TIMEOUT_MS 1000
2594 /* Default number of TX wait attempts. */
2595 #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
2597 /* Total time to wait for TXQ to drain. */
2598 #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
2599 MWL8K_WQ_TXWAIT_ATTEMPTS)
2601 /* Scheduling slop. */
2602 #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
2604 #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
2606 MWL8K_OS_SCHEDULE_OVERHEAD_MS)
2608 static void mwl8k_config_thread(struct work_struct *wt)
2610 struct mwl8k_work_struct *worker = (struct mwl8k_work_struct *)wt;
2611 struct ieee80211_hw *hw = worker->hw;
2612 struct mwl8k_priv *priv = hw->priv;
2615 spin_lock_irq(&priv->tx_lock);
2616 priv->inconfig = true;
2617 spin_unlock_irq(&priv->tx_lock);
2619 ieee80211_stop_queues(hw);
2622 * Wait for host queues to drain before doing PHY
2623 * reconfiguration. This avoids interrupting any in-flight
2624 * DMA transfers to the hardware.
2626 if (worker->options & MWL8K_WQ_TX_WAIT_EMPTY) {
2630 u32 tx_wait_attempts = worker->txwait_attempts;
2632 time_remaining = worker->tx_timeout_ms;
2633 if (!tx_wait_attempts)
2634 tx_wait_attempts = 1;
2636 timeout = worker->tx_timeout_ms/tx_wait_attempts;
2640 iter = tx_wait_attempts;
2644 if (time_remaining > timeout) {
2645 time_remaining -= timeout;
2646 wait_time = timeout;
2648 wait_time = time_remaining;
2653 rc = mwl8k_tx_wait_empty(hw, wait_time);
2655 printk(KERN_ERR "%s() txwait timeout=%ums "
2656 "Retry:%u/%u\n", __func__, timeout,
2657 tx_wait_attempts - iter + 1,
2660 } while (rc && --iter);
2662 rc = iter ? 0 : -ETIMEDOUT;
2665 rc = worker->wfunc(wt);
2667 spin_lock_irq(&priv->tx_lock);
2668 priv->inconfig = false;
2669 if (priv->pending_tx_pkts && priv->radio_on)
2670 mwl8k_tx_start(priv);
2671 spin_unlock_irq(&priv->tx_lock);
2672 ieee80211_wake_queues(hw);
2675 if (worker->options & MWL8K_WQ_SLEEP)
2676 complete(worker->cmd_wait);
2678 if (worker->options & MWL8K_WQ_FREE_WORKSTRUCT)
2682 static int mwl8k_queue_work(struct ieee80211_hw *hw,
2683 struct mwl8k_work_struct *worker,
2684 struct workqueue_struct *wqueue,
2685 int (*wfunc)(struct work_struct *w))
2687 unsigned long timeout = 0;
2690 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2692 if (!worker->timeout_ms)
2693 worker->timeout_ms = MWL8K_CONFIG_TIMEOUT_MS;
2695 if (!worker->options)
2696 worker->options = MWL8K_WQ_DEFAULT_OPTIONS;
2698 if (!worker->txwait_attempts)
2699 worker->txwait_attempts = MWL8K_WQ_TXWAIT_ATTEMPTS;
2701 if (!worker->tx_timeout_ms)
2702 worker->tx_timeout_ms = MWL8K_TXWAIT_MS;
2705 worker->cmd_wait = &cmd_wait;
2707 worker->wfunc = wfunc;
2709 INIT_WORK(&worker->wt, mwl8k_config_thread);
2710 queue_work(wqueue, &worker->wt);
2712 if (worker->options & MWL8K_WQ_POST_REQUEST) {
2715 if (worker->options & MWL8K_WQ_SPIN) {
2716 timeout = worker->timeout_ms;
2717 while (timeout && (worker->rc > 0)) {
2721 } else if (worker->options & MWL8K_WQ_SLEEP)
2722 timeout = wait_for_completion_timeout(&cmd_wait,
2723 msecs_to_jiffies(worker->timeout_ms));
2728 cancel_work_sync(&worker->wt);
2736 struct mwl8k_start_worker {
2737 struct mwl8k_work_struct header;
2740 static int mwl8k_start_wt(struct work_struct *wt)
2742 struct mwl8k_start_worker *worker = (struct mwl8k_start_worker *)wt;
2743 struct ieee80211_hw *hw = worker->header.hw;
2744 struct mwl8k_priv *priv = hw->priv;
2747 if (priv->vif != NULL) {
2749 goto mwl8k_start_exit;
2753 if (mwl8k_cmd_802_11_radio_enable(hw)) {
2755 goto mwl8k_start_exit;
2758 /* Purge TX/RX HW queues */
2759 if (mwl8k_cmd_set_pre_scan(hw)) {
2761 goto mwl8k_start_exit;
2764 if (mwl8k_cmd_set_post_scan(hw, "\x00\x00\x00\x00\x00\x00")) {
2766 goto mwl8k_start_exit;
2769 /* Enable firmware rate adaptation */
2770 if (mwl8k_cmd_setrateadaptmode(hw, 0)) {
2772 goto mwl8k_start_exit;
2775 /* Disable WMM. WMM gets enabled when stack sends WMM parms */
2776 if (mwl8k_set_wmm(hw, MWL8K_WMM_DISABLE)) {
2778 goto mwl8k_start_exit;
2781 /* Disable sniffer mode */
2782 if (mwl8k_enable_sniffer(hw, 0))
2789 static int mwl8k_start(struct ieee80211_hw *hw)
2791 struct mwl8k_start_worker *worker;
2792 struct mwl8k_priv *priv = hw->priv;
2795 /* Enable tx reclaim tasklet */
2796 tasklet_enable(&priv->tx_reclaim_task);
2798 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
2799 IRQF_SHARED, MWL8K_NAME, hw);
2801 printk(KERN_ERR "%s: failed to register IRQ handler\n",
2804 goto mwl8k_start_disable_tasklet;
2807 /* Enable interrupts */
2808 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2810 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2811 if (worker == NULL) {
2813 goto mwl8k_start_disable_irq;
2816 rc = mwl8k_queue_work(hw, &worker->header,
2817 priv->config_wq, mwl8k_start_wt);
2822 if (rc == -ETIMEDOUT)
2823 printk(KERN_ERR "%s() timed out\n", __func__);
2827 mwl8k_start_disable_irq:
2828 spin_lock_irq(&priv->tx_lock);
2829 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2830 spin_unlock_irq(&priv->tx_lock);
2831 free_irq(priv->pdev->irq, hw);
2833 mwl8k_start_disable_tasklet:
2834 tasklet_disable(&priv->tx_reclaim_task);
2839 struct mwl8k_stop_worker {
2840 struct mwl8k_work_struct header;
2843 static int mwl8k_stop_wt(struct work_struct *wt)
2845 struct mwl8k_stop_worker *worker = (struct mwl8k_stop_worker *)wt;
2846 struct ieee80211_hw *hw = worker->header.hw;
2848 return mwl8k_cmd_802_11_radio_disable(hw);
2851 static void mwl8k_stop(struct ieee80211_hw *hw)
2854 struct mwl8k_stop_worker *worker;
2855 struct mwl8k_priv *priv = hw->priv;
2858 if (priv->vif != NULL)
2861 ieee80211_stop_queues(hw);
2863 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2867 rc = mwl8k_queue_work(hw, &worker->header,
2868 priv->config_wq, mwl8k_stop_wt);
2870 if (rc == -ETIMEDOUT)
2871 printk(KERN_ERR "%s() timed out\n", __func__);
2873 /* Disable interrupts */
2874 spin_lock_irq(&priv->tx_lock);
2875 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2876 spin_unlock_irq(&priv->tx_lock);
2877 free_irq(priv->pdev->irq, hw);
2879 /* Stop finalize join worker */
2880 cancel_work_sync(&priv->finalize_join_worker);
2881 if (priv->beacon_skb != NULL)
2882 dev_kfree_skb(priv->beacon_skb);
2884 /* Stop tx reclaim tasklet */
2885 tasklet_disable(&priv->tx_reclaim_task);
2887 /* Stop config thread */
2888 flush_workqueue(priv->config_wq);
2890 /* Return all skbs to mac80211 */
2891 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2892 mwl8k_txq_reclaim(hw, i, 1);
2895 static int mwl8k_add_interface(struct ieee80211_hw *hw,
2896 struct ieee80211_if_init_conf *conf)
2898 struct mwl8k_priv *priv = hw->priv;
2899 struct mwl8k_vif *mwl8k_vif;
2902 * We only support one active interface at a time.
2904 if (priv->vif != NULL)
2908 * We only support managed interfaces for now.
2910 if (conf->type != NL80211_IFTYPE_STATION &&
2911 conf->type != NL80211_IFTYPE_MONITOR)
2914 /* Clean out driver private area */
2915 mwl8k_vif = MWL8K_VIF(conf->vif);
2916 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2918 /* Save the mac address */
2919 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
2921 /* Back pointer to parent config block */
2922 mwl8k_vif->priv = priv;
2924 /* Setup initial PHY parameters */
2925 memcpy(mwl8k_vif->legacy_rates,
2926 priv->rates, sizeof(mwl8k_vif->legacy_rates));
2927 mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
2929 /* Set Initial sequence number to zero */
2930 mwl8k_vif->seqno = 0;
2932 priv->vif = conf->vif;
2933 priv->current_channel = NULL;
2938 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2939 struct ieee80211_if_init_conf *conf)
2941 struct mwl8k_priv *priv = hw->priv;
2943 if (priv->vif == NULL)
2949 struct mwl8k_config_worker {
2950 struct mwl8k_work_struct header;
2954 static int mwl8k_config_wt(struct work_struct *wt)
2956 struct mwl8k_config_worker *worker =
2957 (struct mwl8k_config_worker *)wt;
2958 struct ieee80211_hw *hw = worker->header.hw;
2959 struct ieee80211_conf *conf = &hw->conf;
2960 struct mwl8k_priv *priv = hw->priv;
2963 if (mwl8k_cmd_802_11_radio_enable(hw)) {
2965 goto mwl8k_config_exit;
2968 priv->current_channel = conf->channel;
2970 if (mwl8k_cmd_set_rf_channel(hw, conf->channel)) {
2972 goto mwl8k_config_exit;
2975 if (conf->power_level > 18)
2976 conf->power_level = 18;
2977 if (mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level)) {
2979 goto mwl8k_config_exit;
2982 if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
2989 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
2992 struct mwl8k_config_worker *worker;
2993 struct mwl8k_priv *priv = hw->priv;
2995 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2999 worker->changed = changed;
3000 rc = mwl8k_queue_work(hw, &worker->header,
3001 priv->config_wq, mwl8k_config_wt);
3002 if (rc == -ETIMEDOUT) {
3003 printk(KERN_ERR "%s() timed out.\n", __func__);
3010 * mac80211 will crash on anything other than -EINVAL on
3011 * error. Looks like wireless extensions which calls mac80211
3012 * may be the actual culprit...
3014 return rc ? -EINVAL : 0;
3017 struct mwl8k_bss_info_changed_worker {
3018 struct mwl8k_work_struct header;
3019 struct ieee80211_vif *vif;
3020 struct ieee80211_bss_conf *info;
3024 static int mwl8k_bss_info_changed_wt(struct work_struct *wt)
3026 struct mwl8k_bss_info_changed_worker *worker =
3027 (struct mwl8k_bss_info_changed_worker *)wt;
3028 struct ieee80211_hw *hw = worker->header.hw;
3029 struct ieee80211_vif *vif = worker->vif;
3030 struct ieee80211_bss_conf *info = worker->info;
3034 struct mwl8k_priv *priv = hw->priv;
3035 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3037 changed = worker->changed;
3038 priv->capture_beacon = false;
3041 memcpy(&mwl8k_vif->bss_info, info,
3042 sizeof(struct ieee80211_bss_conf));
3045 if (mwl8k_update_rateset(hw, vif))
3046 goto mwl8k_bss_info_changed_exit;
3048 /* Turn on rate adaptation */
3049 if (mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3050 MWL8K_UCAST_RATE, NULL))
3051 goto mwl8k_bss_info_changed_exit;
3053 /* Set radio preamble */
3054 if (mwl8k_set_radio_preamble(hw,
3055 info->use_short_preamble))
3056 goto mwl8k_bss_info_changed_exit;
3059 if (mwl8k_cmd_set_slot(hw, info->use_short_slot ?
3060 MWL8K_SHORT_SLOTTIME : MWL8K_LONG_SLOTTIME))
3061 goto mwl8k_bss_info_changed_exit;
3063 /* Update peer rate info */
3064 if (mwl8k_cmd_update_sta_db(hw, vif,
3065 MWL8K_STA_DB_MODIFY_ENTRY))
3066 goto mwl8k_bss_info_changed_exit;
3069 if (mwl8k_cmd_set_aid(hw, vif))
3070 goto mwl8k_bss_info_changed_exit;
3073 * Finalize the join. Tell rx handler to process
3074 * next beacon from our BSSID.
3076 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
3077 priv->capture_beacon = true;
3079 mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
3080 memset(&mwl8k_vif->bss_info, 0,
3081 sizeof(struct ieee80211_bss_conf));
3082 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
3085 mwl8k_bss_info_changed_exit:
3090 static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3091 struct ieee80211_vif *vif,
3092 struct ieee80211_bss_conf *info,
3095 struct mwl8k_bss_info_changed_worker *worker;
3096 struct mwl8k_priv *priv = hw->priv;
3097 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
3100 if (changed & BSS_CHANGED_BSSID)
3101 memcpy(mv_vif->bssid, info->bssid, ETH_ALEN);
3103 if ((changed & BSS_CHANGED_ASSOC) == 0)
3106 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3111 worker->info = info;
3112 worker->changed = changed;
3113 rc = mwl8k_queue_work(hw, &worker->header,
3115 mwl8k_bss_info_changed_wt);
3117 if (rc == -ETIMEDOUT)
3118 printk(KERN_ERR "%s() timed out\n", __func__);
3121 struct mwl8k_configure_filter_worker {
3122 struct mwl8k_work_struct header;
3123 unsigned int changed_flags;
3124 unsigned int *total_flags;
3126 struct dev_addr_list *mclist;
3129 #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
3131 static int mwl8k_configure_filter_wt(struct work_struct *wt)
3133 struct mwl8k_configure_filter_worker *worker =
3134 (struct mwl8k_configure_filter_worker *)wt;
3136 struct ieee80211_hw *hw = worker->header.hw;
3137 unsigned int changed_flags = worker->changed_flags;
3138 unsigned int *total_flags = worker->total_flags;
3139 int mc_count = worker->mc_count;
3140 struct dev_addr_list *mclist = worker->mclist;
3142 struct mwl8k_priv *priv = hw->priv;
3145 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
3146 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
3147 rc = mwl8k_cmd_set_pre_scan(hw);
3151 bssid = "\x00\x00\x00\x00\x00\x00";
3152 if (priv->vif != NULL)
3153 bssid = MWL8K_VIF(priv->vif)->bssid;
3155 rc = mwl8k_cmd_set_post_scan(hw, bssid);
3160 goto mwl8k_configure_filter_exit;
3162 if (mc_count > priv->num_mcaddrs)
3163 mc_count = priv->num_mcaddrs;
3165 rc = mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist);
3168 "%s()Error setting multicast addresses\n",
3172 mwl8k_configure_filter_exit:
3176 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3177 int mc_count, struct dev_addr_list *mclist)
3179 struct mwl8k_configure_filter_worker *worker;
3181 worker = kzalloc(sizeof(*worker), GFP_ATOMIC);
3187 * XXX: This is _HORRIBLY_ broken!!
3189 * No locking, the mclist pointer might be invalid as soon as this
3190 * function returns, something in the list might be invalidated
3191 * once we get to the worker, etc...
3193 worker->mc_count = mc_count;
3194 worker->mclist = mclist;
3199 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3200 unsigned int changed_flags,
3201 unsigned int *total_flags,
3205 struct mwl8k_configure_filter_worker *worker = (void *)multicast;
3206 struct mwl8k_priv *priv = hw->priv;
3208 /* Clear unsupported feature flags */
3209 *total_flags &= MWL8K_SUPPORTED_IF_FLAGS;
3211 if (!(changed_flags & MWL8K_SUPPORTED_IF_FLAGS))
3217 worker->header.options = MWL8K_WQ_QUEUE_ONLY | MWL8K_WQ_TX_WAIT_EMPTY;
3218 worker->changed_flags = changed_flags;
3219 worker->total_flags = total_flags;
3221 mwl8k_queue_work(hw, &worker->header, priv->config_wq,
3222 mwl8k_configure_filter_wt);
3225 struct mwl8k_set_rts_threshold_worker {
3226 struct mwl8k_work_struct header;
3230 static int mwl8k_set_rts_threshold_wt(struct work_struct *wt)
3232 struct mwl8k_set_rts_threshold_worker *worker =
3233 (struct mwl8k_set_rts_threshold_worker *)wt;
3235 struct ieee80211_hw *hw = worker->header.hw;
3236 u16 threshold = (u16)(worker->value);
3239 rc = mwl8k_rts_threshold(hw, MWL8K_CMD_SET, &threshold);
3244 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3247 struct mwl8k_set_rts_threshold_worker *worker;
3248 struct mwl8k_priv *priv = hw->priv;
3250 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3254 worker->value = value;
3256 rc = mwl8k_queue_work(hw, &worker->header,
3258 mwl8k_set_rts_threshold_wt);
3261 if (rc == -ETIMEDOUT) {
3262 printk(KERN_ERR "%s() timed out\n", __func__);
3269 struct mwl8k_conf_tx_worker {
3270 struct mwl8k_work_struct header;
3272 const struct ieee80211_tx_queue_params *params;
3275 static int mwl8k_conf_tx_wt(struct work_struct *wt)
3277 struct mwl8k_conf_tx_worker *worker =
3278 (struct mwl8k_conf_tx_worker *)wt;
3280 struct ieee80211_hw *hw = worker->header.hw;
3281 u16 queue = worker->queue;
3282 const struct ieee80211_tx_queue_params *params = worker->params;
3284 struct mwl8k_priv *priv = hw->priv;
3287 if (priv->wmm_mode == MWL8K_WMM_DISABLE)
3288 if (mwl8k_set_wmm(hw, MWL8K_WMM_ENABLE)) {
3290 goto mwl8k_conf_tx_exit;
3293 if (mwl8k_set_edca_params(hw, GET_TXQ(queue), params->cw_min,
3294 params->cw_max, params->aifs, params->txop))
3300 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3301 const struct ieee80211_tx_queue_params *params)
3304 struct mwl8k_conf_tx_worker *worker;
3305 struct mwl8k_priv *priv = hw->priv;
3307 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3311 worker->queue = queue;
3312 worker->params = params;
3313 rc = mwl8k_queue_work(hw, &worker->header,
3314 priv->config_wq, mwl8k_conf_tx_wt);
3316 if (rc == -ETIMEDOUT) {
3317 printk(KERN_ERR "%s() timed out\n", __func__);
3323 static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3324 struct ieee80211_tx_queue_stats *stats)
3326 struct mwl8k_priv *priv = hw->priv;
3327 struct mwl8k_tx_queue *txq;
3330 spin_lock_bh(&priv->tx_lock);
3331 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3332 txq = priv->txq + index;
3333 memcpy(&stats[index], &txq->tx_stats,
3334 sizeof(struct ieee80211_tx_queue_stats));
3336 spin_unlock_bh(&priv->tx_lock);
3340 struct mwl8k_get_stats_worker {
3341 struct mwl8k_work_struct header;
3342 struct ieee80211_low_level_stats *stats;
3345 static int mwl8k_get_stats_wt(struct work_struct *wt)
3347 struct mwl8k_get_stats_worker *worker =
3348 (struct mwl8k_get_stats_worker *)wt;
3350 return mwl8k_cmd_802_11_get_stat(worker->header.hw, worker->stats);
3353 static int mwl8k_get_stats(struct ieee80211_hw *hw,
3354 struct ieee80211_low_level_stats *stats)
3357 struct mwl8k_get_stats_worker *worker;
3358 struct mwl8k_priv *priv = hw->priv;
3360 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3364 worker->stats = stats;
3365 rc = mwl8k_queue_work(hw, &worker->header,
3366 priv->config_wq, mwl8k_get_stats_wt);
3369 if (rc == -ETIMEDOUT) {
3370 printk(KERN_ERR "%s() timed out\n", __func__);
3377 static const struct ieee80211_ops mwl8k_ops = {
3379 .start = mwl8k_start,
3381 .add_interface = mwl8k_add_interface,
3382 .remove_interface = mwl8k_remove_interface,
3383 .config = mwl8k_config,
3384 .bss_info_changed = mwl8k_bss_info_changed,
3385 .prepare_multicast = mwl8k_prepare_multicast,
3386 .configure_filter = mwl8k_configure_filter,
3387 .set_rts_threshold = mwl8k_set_rts_threshold,
3388 .conf_tx = mwl8k_conf_tx,
3389 .get_tx_stats = mwl8k_get_tx_stats,
3390 .get_stats = mwl8k_get_stats,
3393 static void mwl8k_tx_reclaim_handler(unsigned long data)
3396 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3397 struct mwl8k_priv *priv = hw->priv;
3399 spin_lock_bh(&priv->tx_lock);
3400 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3401 mwl8k_txq_reclaim(hw, i, 0);
3403 if (priv->tx_wait != NULL && mwl8k_txq_busy(priv) == 0) {
3404 complete(priv->tx_wait);
3405 priv->tx_wait = NULL;
3407 spin_unlock_bh(&priv->tx_lock);
3410 static void mwl8k_finalize_join_worker(struct work_struct *work)
3412 struct mwl8k_priv *priv =
3413 container_of(work, struct mwl8k_priv, finalize_join_worker);
3414 struct sk_buff *skb = priv->beacon_skb;
3415 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
3417 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3420 priv->beacon_skb = NULL;
3423 static int __devinit mwl8k_probe(struct pci_dev *pdev,
3424 const struct pci_device_id *id)
3426 struct ieee80211_hw *hw;
3427 struct mwl8k_priv *priv;
3432 rc = pci_enable_device(pdev);
3434 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3439 rc = pci_request_regions(pdev, MWL8K_NAME);
3441 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3446 pci_set_master(pdev);
3448 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3450 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3458 priv->hostcmd_wait = NULL;
3459 priv->tx_wait = NULL;
3460 priv->inconfig = false;
3461 priv->wmm_mode = false;
3462 priv->pending_tx_pkts = 0;
3463 strncpy(priv->name, MWL8K_NAME, sizeof(priv->name));
3465 spin_lock_init(&priv->fw_lock);
3467 SET_IEEE80211_DEV(hw, &pdev->dev);
3468 pci_set_drvdata(pdev, hw);
3470 priv->regs = pci_iomap(pdev, 1, 0x10000);
3471 if (priv->regs == NULL) {
3472 printk(KERN_ERR "%s: Cannot map device memory\n", priv->name);
3476 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3477 priv->band.band = IEEE80211_BAND_2GHZ;
3478 priv->band.channels = priv->channels;
3479 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3480 priv->band.bitrates = priv->rates;
3481 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3482 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3484 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3485 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3488 * Extra headroom is the size of the required DMA header
3489 * minus the size of the smallest 802.11 frame (CTS frame).
3491 hw->extra_tx_headroom =
3492 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3494 hw->channel_change_time = 10;
3496 hw->queues = MWL8K_TX_QUEUES;
3498 hw->wiphy->interface_modes =
3499 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_MONITOR);
3501 /* Set rssi and noise values to dBm */
3502 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
3503 hw->vif_data_size = sizeof(struct mwl8k_vif);
3506 /* Set default radio state and preamble */
3507 priv->radio_preamble = MWL8K_RADIO_DEFAULT_PREAMBLE;
3510 /* Finalize join worker */
3511 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3513 /* TX reclaim tasklet */
3514 tasklet_init(&priv->tx_reclaim_task,
3515 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3516 tasklet_disable(&priv->tx_reclaim_task);
3518 /* Config workthread */
3519 priv->config_wq = create_singlethread_workqueue("mwl8k_config");
3520 if (priv->config_wq == NULL)
3523 /* Power management cookie */
3524 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3525 if (priv->cookie == NULL)
3528 rc = mwl8k_rxq_init(hw, 0);
3531 rxq_refill(hw, 0, INT_MAX);
3533 spin_lock_init(&priv->tx_lock);
3535 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3536 rc = mwl8k_txq_init(hw, i);
3538 goto err_free_queues;
3541 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3542 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3543 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3544 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3546 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
3547 IRQF_SHARED, MWL8K_NAME, hw);
3549 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3551 goto err_free_queues;
3554 /* Reset firmware and hardware */
3555 mwl8k_hw_reset(priv);
3557 /* Ask userland hotplug daemon for the device firmware */
3558 rc = mwl8k_request_firmware(priv, (u32)id->driver_data);
3560 printk(KERN_ERR "%s: Firmware files not found\n", priv->name);
3564 /* Load firmware into hardware */
3565 rc = mwl8k_load_firmware(priv);
3567 printk(KERN_ERR "%s: Cannot start firmware\n", priv->name);
3568 goto err_stop_firmware;
3571 /* Reclaim memory once firmware is successfully loaded */
3572 mwl8k_release_firmware(priv);
3575 * Temporarily enable interrupts. Initial firmware host
3576 * commands use interrupts and avoids polling. Disable
3577 * interrupts when done.
3579 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3581 /* Get config data, mac addrs etc */
3582 rc = mwl8k_cmd_get_hw_spec(hw);
3584 printk(KERN_ERR "%s: Cannot initialise firmware\n", priv->name);
3585 goto err_stop_firmware;
3588 /* Turn radio off */
3589 rc = mwl8k_cmd_802_11_radio_disable(hw);
3591 printk(KERN_ERR "%s: Cannot disable\n", priv->name);
3592 goto err_stop_firmware;
3595 /* Disable interrupts */
3596 spin_lock_irq(&priv->tx_lock);
3597 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3598 spin_unlock_irq(&priv->tx_lock);
3599 free_irq(priv->pdev->irq, hw);
3601 rc = ieee80211_register_hw(hw);
3603 printk(KERN_ERR "%s: Cannot register device\n", priv->name);
3604 goto err_stop_firmware;
3607 fw = (u8 *)&priv->fw_rev;
3608 printk(KERN_INFO "%s: 88W%u %s\n", priv->name, priv->part_num,
3610 printk(KERN_INFO "%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
3611 priv->name, MWL8K_VERSION, fw[3], fw[2], fw[1], fw[0]);
3612 printk(KERN_INFO "%s: MAC Address: %pM\n", priv->name,
3613 hw->wiphy->perm_addr);
3618 mwl8k_hw_reset(priv);
3619 mwl8k_release_firmware(priv);
3622 spin_lock_irq(&priv->tx_lock);
3623 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3624 spin_unlock_irq(&priv->tx_lock);
3625 free_irq(priv->pdev->irq, hw);
3628 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3629 mwl8k_txq_deinit(hw, i);
3630 mwl8k_rxq_deinit(hw, 0);
3633 if (priv->cookie != NULL)
3634 pci_free_consistent(priv->pdev, 4,
3635 priv->cookie, priv->cookie_dma);
3637 if (priv->regs != NULL)
3638 pci_iounmap(pdev, priv->regs);
3640 if (priv->config_wq != NULL)
3641 destroy_workqueue(priv->config_wq);
3643 pci_set_drvdata(pdev, NULL);
3644 ieee80211_free_hw(hw);
3647 pci_release_regions(pdev);
3648 pci_disable_device(pdev);
3653 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
3655 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3658 static void __devexit mwl8k_remove(struct pci_dev *pdev)
3660 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3661 struct mwl8k_priv *priv;
3668 ieee80211_stop_queues(hw);
3670 ieee80211_unregister_hw(hw);
3672 /* Remove tx reclaim tasklet */
3673 tasklet_kill(&priv->tx_reclaim_task);
3675 /* Stop config thread */
3676 destroy_workqueue(priv->config_wq);
3679 mwl8k_hw_reset(priv);
3681 /* Return all skbs to mac80211 */
3682 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3683 mwl8k_txq_reclaim(hw, i, 1);
3685 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3686 mwl8k_txq_deinit(hw, i);
3688 mwl8k_rxq_deinit(hw, 0);
3690 pci_free_consistent(priv->pdev, 4,
3691 priv->cookie, priv->cookie_dma);
3693 pci_iounmap(pdev, priv->regs);
3694 pci_set_drvdata(pdev, NULL);
3695 ieee80211_free_hw(hw);
3696 pci_release_regions(pdev);
3697 pci_disable_device(pdev);
3700 static struct pci_driver mwl8k_driver = {
3702 .id_table = mwl8k_table,
3703 .probe = mwl8k_probe,
3704 .remove = __devexit_p(mwl8k_remove),
3705 .shutdown = __devexit_p(mwl8k_shutdown),
3708 static int __init mwl8k_init(void)
3710 return pci_register_driver(&mwl8k_driver);
3713 static void __exit mwl8k_exit(void)
3715 pci_unregister_driver(&mwl8k_driver);
3718 module_init(mwl8k_init);
3719 module_exit(mwl8k_exit);