2 * drivers/net/wireless/mwl8k.c driver for Marvell TOPDOG 802.11 Wireless cards
4 * Copyright (C) 2008 Marvell Semiconductor Inc.
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/spinlock.h>
15 #include <linux/list.h>
16 #include <linux/pci.h>
17 #include <linux/delay.h>
18 #include <linux/completion.h>
19 #include <linux/etherdevice.h>
20 #include <net/mac80211.h>
21 #include <linux/moduleparam.h>
22 #include <linux/firmware.h>
23 #include <linux/workqueue.h>
25 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
26 #define MWL8K_NAME KBUILD_MODNAME
27 #define MWL8K_VERSION "0.9.1"
29 MODULE_DESCRIPTION(MWL8K_DESC);
30 MODULE_VERSION(MWL8K_VERSION);
31 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
32 MODULE_LICENSE("GPL");
34 static DEFINE_PCI_DEVICE_TABLE(mwl8k_table) = {
35 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = 8687, },
36 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = 8687, },
39 MODULE_DEVICE_TABLE(pci, mwl8k_table);
41 /* Register definitions */
42 #define MWL8K_HIU_GEN_PTR 0x00000c10
43 #define MWL8K_MODE_STA 0x0000005a
44 #define MWL8K_MODE_AP 0x000000a5
45 #define MWL8K_HIU_INT_CODE 0x00000c14
46 #define MWL8K_FWSTA_READY 0xf0f1f2f4
47 #define MWL8K_FWAP_READY 0xf1f2f4a5
48 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
49 #define MWL8K_HIU_SCRATCH 0x00000c40
51 /* Host->device communications */
52 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
53 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
54 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
55 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
56 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
57 #define MWL8K_H2A_INT_DUMMY (1 << 20)
58 #define MWL8K_H2A_INT_RESET (1 << 15)
59 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
60 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
62 /* Device->host communications */
63 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
64 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
65 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
66 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
67 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
68 #define MWL8K_A2H_INT_DUMMY (1 << 20)
69 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
70 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
71 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
72 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
73 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
74 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
75 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
76 #define MWL8K_A2H_INT_RX_READY (1 << 1)
77 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
79 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
80 MWL8K_A2H_INT_CHNL_SWITCHED | \
81 MWL8K_A2H_INT_QUEUE_EMPTY | \
82 MWL8K_A2H_INT_RADAR_DETECT | \
83 MWL8K_A2H_INT_RADIO_ON | \
84 MWL8K_A2H_INT_RADIO_OFF | \
85 MWL8K_A2H_INT_MAC_EVENT | \
86 MWL8K_A2H_INT_OPC_DONE | \
87 MWL8K_A2H_INT_RX_READY | \
88 MWL8K_A2H_INT_TX_DONE)
90 /* WME stream classes */
91 #define WME_AC_BE 0 /* best effort */
92 #define WME_AC_BK 1 /* background */
93 #define WME_AC_VI 2 /* video */
94 #define WME_AC_VO 3 /* voice */
96 #define MWL8K_RX_QUEUES 1
97 #define MWL8K_TX_QUEUES 4
99 struct mwl8k_rx_queue {
102 /* hw receives here */
105 /* refill descs here */
108 struct mwl8k_rx_desc *rx_desc_area;
109 dma_addr_t rx_desc_dma;
110 struct sk_buff **rx_skb;
115 * The DMA engine requires a modification to the payload.
116 * If the skbuff is shared/cloned, it needs to be unshared.
117 * This method is used to ensure the stack always gets back
118 * the skbuff it sent for transmission.
120 struct sk_buff *clone;
124 struct mwl8k_tx_queue {
125 /* hw transmits here */
128 /* sw appends here */
131 struct ieee80211_tx_queue_stats tx_stats;
132 struct mwl8k_tx_desc *tx_desc_area;
133 dma_addr_t tx_desc_dma;
134 struct mwl8k_skb *tx_skb;
137 /* Pointers to the firmware data and meta information about it. */
138 struct mwl8k_firmware {
140 struct firmware *ucode;
142 /* Boot helper code */
143 struct firmware *helper;
148 struct ieee80211_hw *hw;
150 struct pci_dev *pdev;
152 /* firmware access lock */
155 /* firmware files and meta data */
156 struct mwl8k_firmware fw;
159 /* lock held over TX and TX reap */
162 struct ieee80211_vif *vif;
164 struct ieee80211_channel *current_channel;
166 /* power management status cookie from firmware */
168 dma_addr_t cookie_dma;
175 * Running count of TX packets in flight, to avoid
176 * iterating over the transmit rings each time.
180 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
181 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
184 struct ieee80211_supported_band band;
185 struct ieee80211_channel channels[14];
186 struct ieee80211_rate rates[12];
188 /* RF preamble: Short, Long or Auto */
192 /* WMM MODE 1 for enabled; 0 for disabled */
195 /* Set if PHY config is in progress */
198 /* XXX need to convert this to handle multiple interfaces */
200 u8 capture_bssid[ETH_ALEN];
201 struct sk_buff *beacon_skb;
204 * This FJ worker has to be global as it is scheduled from the
205 * RX handler. At this point we don't know which interface it
206 * belongs to until the list of bssids waiting to complete join
209 struct work_struct finalize_join_worker;
211 /* Tasklet to reclaim TX descriptors and buffers after tx */
212 struct tasklet_struct tx_reclaim_task;
214 /* Work thread to serialize configuration requests */
215 struct workqueue_struct *config_wq;
216 struct completion *hostcmd_wait;
217 struct completion *tx_wait;
220 /* Per interface specific private data */
222 /* backpointer to parent config block */
223 struct mwl8k_priv *priv;
225 /* BSS config of AP or IBSS from mac80211*/
226 struct ieee80211_bss_conf bss_info;
228 /* BSSID of AP or IBSS */
230 u8 mac_addr[ETH_ALEN];
233 * Subset of supported legacy rates.
234 * Intersection of AP and STA supported rates.
236 struct ieee80211_rate legacy_rates[12];
238 /* number of supported legacy rates */
241 /* Index into station database.Returned by update_sta_db call */
244 /* Non AMPDU sequence number assigned by driver */
248 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
250 static const struct ieee80211_channel mwl8k_channels[] = {
251 { .center_freq = 2412, .hw_value = 1, },
252 { .center_freq = 2417, .hw_value = 2, },
253 { .center_freq = 2422, .hw_value = 3, },
254 { .center_freq = 2427, .hw_value = 4, },
255 { .center_freq = 2432, .hw_value = 5, },
256 { .center_freq = 2437, .hw_value = 6, },
257 { .center_freq = 2442, .hw_value = 7, },
258 { .center_freq = 2447, .hw_value = 8, },
259 { .center_freq = 2452, .hw_value = 9, },
260 { .center_freq = 2457, .hw_value = 10, },
261 { .center_freq = 2462, .hw_value = 11, },
264 static const struct ieee80211_rate mwl8k_rates[] = {
265 { .bitrate = 10, .hw_value = 2, },
266 { .bitrate = 20, .hw_value = 4, },
267 { .bitrate = 55, .hw_value = 11, },
268 { .bitrate = 60, .hw_value = 12, },
269 { .bitrate = 90, .hw_value = 18, },
270 { .bitrate = 110, .hw_value = 22, },
271 { .bitrate = 120, .hw_value = 24, },
272 { .bitrate = 180, .hw_value = 36, },
273 { .bitrate = 240, .hw_value = 48, },
274 { .bitrate = 360, .hw_value = 72, },
275 { .bitrate = 480, .hw_value = 96, },
276 { .bitrate = 540, .hw_value = 108, },
280 #define MWL8K_RADIO_FORCE 0x2
281 #define MWL8K_RADIO_ENABLE 0x1
282 #define MWL8K_RADIO_DISABLE 0x0
283 #define MWL8K_RADIO_AUTO_PREAMBLE 0x0005
284 #define MWL8K_RADIO_SHORT_PREAMBLE 0x0003
285 #define MWL8K_RADIO_LONG_PREAMBLE 0x0001
288 #define MWL8K_WMM_ENABLE 1
289 #define MWL8K_WMM_DISABLE 0
291 #define MWL8K_RADIO_DEFAULT_PREAMBLE MWL8K_RADIO_LONG_PREAMBLE
295 /* Short Slot: 9us slot time */
296 #define MWL8K_SHORT_SLOTTIME 1
298 /* Long slot: 20us slot time */
299 #define MWL8K_LONG_SLOTTIME 0
301 /* Set or get info from Firmware */
302 #define MWL8K_CMD_SET 0x0001
303 #define MWL8K_CMD_GET 0x0000
305 /* Firmware command codes */
306 #define MWL8K_CMD_CODE_DNLD 0x0001
307 #define MWL8K_CMD_GET_HW_SPEC 0x0003
308 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
309 #define MWL8K_CMD_GET_STAT 0x0014
310 #define MWL8K_CMD_RADIO_CONTROL 0x001c
311 #define MWL8K_CMD_RF_TX_POWER 0x001e
312 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
313 #define MWL8K_CMD_SET_POST_SCAN 0x0108
314 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
315 #define MWL8K_CMD_SET_AID 0x010d
316 #define MWL8K_CMD_SET_RATE 0x0110
317 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
318 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
319 #define MWL8K_CMD_SET_SLOT 0x0114
320 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
321 #define MWL8K_CMD_SET_WMM_MODE 0x0123
322 #define MWL8K_CMD_MIMO_CONFIG 0x0125
323 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
324 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
325 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
326 #define MWL8K_CMD_UPDATE_STADB 0x1123
328 static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
330 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
331 snprintf(buf, bufsize, "%s", #x);\
334 switch (cmd & (~0x8000)) {
335 MWL8K_CMDNAME(CODE_DNLD);
336 MWL8K_CMDNAME(GET_HW_SPEC);
337 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
338 MWL8K_CMDNAME(GET_STAT);
339 MWL8K_CMDNAME(RADIO_CONTROL);
340 MWL8K_CMDNAME(RF_TX_POWER);
341 MWL8K_CMDNAME(SET_PRE_SCAN);
342 MWL8K_CMDNAME(SET_POST_SCAN);
343 MWL8K_CMDNAME(SET_RF_CHANNEL);
344 MWL8K_CMDNAME(SET_AID);
345 MWL8K_CMDNAME(SET_RATE);
346 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
347 MWL8K_CMDNAME(RTS_THRESHOLD);
348 MWL8K_CMDNAME(SET_SLOT);
349 MWL8K_CMDNAME(SET_EDCA_PARAMS);
350 MWL8K_CMDNAME(SET_WMM_MODE);
351 MWL8K_CMDNAME(MIMO_CONFIG);
352 MWL8K_CMDNAME(USE_FIXED_RATE);
353 MWL8K_CMDNAME(ENABLE_SNIFFER);
354 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
355 MWL8K_CMDNAME(UPDATE_STADB);
357 snprintf(buf, bufsize, "0x%x", cmd);
364 /* Hardware and firmware reset */
365 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
367 iowrite32(MWL8K_H2A_INT_RESET,
368 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
369 iowrite32(MWL8K_H2A_INT_RESET,
370 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
374 /* Release fw image */
375 static void mwl8k_release_fw(struct firmware **fw)
379 release_firmware(*fw);
383 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
385 mwl8k_release_fw(&priv->fw.ucode);
386 mwl8k_release_fw(&priv->fw.helper);
389 /* Request fw image */
390 static int mwl8k_request_fw(struct mwl8k_priv *priv,
391 const char *fname, struct firmware **fw)
393 /* release current image */
395 mwl8k_release_fw(fw);
397 return request_firmware((const struct firmware **)fw,
398 fname, &priv->pdev->dev);
401 static int mwl8k_request_firmware(struct mwl8k_priv *priv, u32 part_num)
406 priv->part_num = part_num;
408 snprintf(filename, sizeof(filename),
409 "mwl8k/helper_%u.fw", priv->part_num);
411 rc = mwl8k_request_fw(priv, filename, &priv->fw.helper);
414 "%s Error requesting helper firmware file %s\n",
415 pci_name(priv->pdev), filename);
419 snprintf(filename, sizeof(filename),
420 "mwl8k/fmimage_%u.fw", priv->part_num);
422 rc = mwl8k_request_fw(priv, filename, &priv->fw.ucode);
424 printk(KERN_ERR "%s Error requesting firmware file %s\n",
425 pci_name(priv->pdev), filename);
426 mwl8k_release_fw(&priv->fw.helper);
433 struct mwl8k_cmd_pkt {
439 } __attribute__((packed));
445 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
447 void __iomem *regs = priv->regs;
452 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
453 if (pci_dma_mapping_error(priv->pdev, dma_addr))
456 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
457 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
458 iowrite32(MWL8K_H2A_INT_DOORBELL,
459 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
460 iowrite32(MWL8K_H2A_INT_DUMMY,
461 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
468 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
469 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
470 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
478 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
481 * Clear 'command done' interrupt bit.
487 status = ioread32(priv->regs +
488 MWL8K_HIU_A2H_INTERRUPT_STATUS);
489 if (status & MWL8K_A2H_INT_OPC_DONE) {
490 iowrite32(~MWL8K_A2H_INT_OPC_DONE,
491 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
492 ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
502 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
503 const u8 *data, size_t length)
505 struct mwl8k_cmd_pkt *cmd;
509 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
513 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
519 int block_size = length > 256 ? 256 : length;
521 memcpy(cmd->payload, data + done, block_size);
522 cmd->length = cpu_to_le16(block_size);
524 rc = mwl8k_send_fw_load_cmd(priv, cmd,
525 sizeof(*cmd) + block_size);
530 length -= block_size;
535 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
543 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
544 const u8 *data, size_t length)
546 unsigned char *buffer;
547 int may_continue, rc = 0;
548 u32 done, prev_block_size;
550 buffer = kmalloc(1024, GFP_KERNEL);
557 while (may_continue > 0) {
560 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
561 if (block_size & 1) {
565 done += prev_block_size;
566 length -= prev_block_size;
569 if (block_size > 1024 || block_size > length) {
579 if (block_size == 0) {
586 prev_block_size = block_size;
587 memcpy(buffer, data + done, block_size);
589 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
594 if (!rc && length != 0)
602 static int mwl8k_load_firmware(struct mwl8k_priv *priv)
606 const u8 *ucode = priv->fw.ucode->data;
607 size_t ucode_len = priv->fw.ucode->size;
608 const u8 *helper = priv->fw.helper->data;
609 size_t helper_len = priv->fw.helper->size;
611 if (!memcmp(ucode, "\x01\x00\x00\x00", 4)) {
612 rc = mwl8k_load_fw_image(priv, helper, helper_len);
614 printk(KERN_ERR "%s: unable to load firmware "
615 "helper image\n", pci_name(priv->pdev));
620 rc = mwl8k_feed_fw_image(priv, ucode, ucode_len);
622 rc = mwl8k_load_fw_image(priv, ucode, ucode_len);
626 printk(KERN_ERR "%s: unable to load firmware data\n",
627 pci_name(priv->pdev));
631 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
636 if (ioread32(priv->regs + MWL8K_HIU_INT_CODE)
637 == MWL8K_FWSTA_READY)
642 return loops ? 0 : -ETIMEDOUT;
647 * Defines shared between transmission and reception.
649 /* HT control fields for firmware */
654 } __attribute__((packed));
656 /* Firmware Station database operations */
657 #define MWL8K_STA_DB_ADD_ENTRY 0
658 #define MWL8K_STA_DB_MODIFY_ENTRY 1
659 #define MWL8K_STA_DB_DEL_ENTRY 2
660 #define MWL8K_STA_DB_FLUSH 3
662 /* Peer Entry flags - used to define the type of the peer node */
663 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
665 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
666 #define MWL8K_MCS_BITMAP_SIZE 16
668 struct peer_capability_info {
669 /* Peer type - AP vs. STA. */
672 /* Basic 802.11 capabilities from assoc resp. */
675 /* Set if peer supports 802.11n high throughput (HT). */
678 /* Valid if HT is supported. */
680 __u8 extended_ht_caps;
681 struct ewc_ht_info ewc_info;
683 /* Legacy rate table. Intersection of our rates and peer rates. */
684 __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
686 /* HT rate table. Intersection of our rates and peer rates. */
687 __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
690 /* If set, interoperability mode, no proprietary extensions. */
694 __le16 amsdu_enabled;
695 } __attribute__((packed));
697 /* Inline functions to manipulate QoS field in data descriptor. */
698 static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
700 u16 val_mask = 1 << 4;
702 /* End of Service Period Bit 4 */
703 return qos | val_mask;
706 static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
710 u16 qos_mask = ~(val_mask << shift);
712 /* Ack Policy Bit 5-6 */
713 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
716 static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
718 u16 val_mask = 1 << 7;
720 /* AMSDU present Bit 7 */
721 return qos | val_mask;
724 static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
728 u16 qos_mask = ~(val_mask << shift);
730 /* Queue Length Bits 8-15 */
731 return (qos & qos_mask) | ((len & val_mask) << shift);
734 /* DMA header used by firmware and hardware. */
735 struct mwl8k_dma_data {
737 struct ieee80211_hdr wh;
738 } __attribute__((packed));
740 /* Routines to add/remove DMA header from skb. */
741 static inline int mwl8k_remove_dma_header(struct sk_buff *skb)
743 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)(skb->data);
744 void *dst, *src = &tr->wh;
745 __le16 fc = tr->wh.frame_control;
746 int hdrlen = ieee80211_hdrlen(fc);
747 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
749 dst = (void *)tr + space;
751 memmove(dst, src, hdrlen);
752 skb_pull(skb, space);
758 static inline struct sk_buff *mwl8k_add_dma_header(struct sk_buff *skb)
760 struct ieee80211_hdr *wh;
762 struct mwl8k_dma_data *tr;
764 wh = (struct ieee80211_hdr *)skb->data;
765 hdrlen = ieee80211_hdrlen(wh->frame_control);
769 * Copy up/down the 802.11 header; the firmware requires
770 * we present a 2-byte payload length followed by a
771 * 4-address header (w/o QoS), followed (optionally) by
772 * any WEP/ExtIV header (but only filled in for CCMP).
774 if (hdrlen != sizeof(struct mwl8k_dma_data))
775 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
777 tr = (struct mwl8k_dma_data *)skb->data;
779 memmove(&tr->wh, wh, hdrlen);
782 memset(tr->wh.addr4, 0, ETH_ALEN);
785 * Firmware length is the length of the fully formed "802.11
786 * payload". That is, everything except for the 802.11 header.
787 * This includes all crypto material including the MIC.
789 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
798 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
800 struct mwl8k_rx_desc {
804 __le32 pkt_phys_addr;
805 __le32 next_rx_desc_phys_addr;
815 } __attribute__((packed));
817 #define MWL8K_RX_DESCS 256
818 #define MWL8K_RX_MAXSZ 3800
820 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
822 struct mwl8k_priv *priv = hw->priv;
823 struct mwl8k_rx_queue *rxq = priv->rxq + index;
827 rxq->rx_desc_count = 0;
831 size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc);
834 pci_alloc_consistent(priv->pdev, size, &rxq->rx_desc_dma);
835 if (rxq->rx_desc_area == NULL) {
836 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
840 memset(rxq->rx_desc_area, 0, size);
842 rxq->rx_skb = kmalloc(MWL8K_RX_DESCS *
843 sizeof(*rxq->rx_skb), GFP_KERNEL);
844 if (rxq->rx_skb == NULL) {
845 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
847 pci_free_consistent(priv->pdev, size,
848 rxq->rx_desc_area, rxq->rx_desc_dma);
851 memset(rxq->rx_skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->rx_skb));
853 for (i = 0; i < MWL8K_RX_DESCS; i++) {
854 struct mwl8k_rx_desc *rx_desc;
857 rx_desc = rxq->rx_desc_area + i;
858 nexti = (i + 1) % MWL8K_RX_DESCS;
860 rx_desc->next_rx_desc_phys_addr =
861 cpu_to_le32(rxq->rx_desc_dma
862 + nexti * sizeof(*rx_desc));
863 rx_desc->rx_ctrl = MWL8K_RX_CTRL_OWNED_BY_HOST;
869 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
871 struct mwl8k_priv *priv = hw->priv;
872 struct mwl8k_rx_queue *rxq = priv->rxq + index;
876 while (rxq->rx_desc_count < MWL8K_RX_DESCS && limit--) {
880 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
884 rxq->rx_desc_count++;
887 rxq->rx_tail = (rx + 1) % MWL8K_RX_DESCS;
889 rxq->rx_desc_area[rx].pkt_phys_addr =
890 cpu_to_le32(pci_map_single(priv->pdev, skb->data,
891 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE));
893 rxq->rx_desc_area[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ);
894 rxq->rx_skb[rx] = skb;
896 rxq->rx_desc_area[rx].rx_ctrl = 0;
904 /* Must be called only when the card's reception is completely halted */
905 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
907 struct mwl8k_priv *priv = hw->priv;
908 struct mwl8k_rx_queue *rxq = priv->rxq + index;
911 for (i = 0; i < MWL8K_RX_DESCS; i++) {
912 if (rxq->rx_skb[i] != NULL) {
915 addr = le32_to_cpu(rxq->rx_desc_area[i].pkt_phys_addr);
916 pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ,
918 kfree_skb(rxq->rx_skb[i]);
919 rxq->rx_skb[i] = NULL;
926 pci_free_consistent(priv->pdev,
927 MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc),
928 rxq->rx_desc_area, rxq->rx_desc_dma);
929 rxq->rx_desc_area = NULL;
934 * Scan a list of BSSIDs to process for finalize join.
935 * Allows for extension to process multiple BSSIDs.
938 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
940 return priv->capture_beacon &&
941 ieee80211_is_beacon(wh->frame_control) &&
942 !compare_ether_addr(wh->addr3, priv->capture_bssid);
945 static inline void mwl8k_save_beacon(struct mwl8k_priv *priv,
948 priv->capture_beacon = false;
949 memset(priv->capture_bssid, 0, ETH_ALEN);
952 * Use GFP_ATOMIC as rxq_process is called from
953 * the primary interrupt handler, memory allocation call
956 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
957 if (priv->beacon_skb != NULL)
958 queue_work(priv->config_wq,
959 &priv->finalize_join_worker);
962 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
964 struct mwl8k_priv *priv = hw->priv;
965 struct mwl8k_rx_queue *rxq = priv->rxq + index;
969 while (rxq->rx_desc_count && limit--) {
970 struct mwl8k_rx_desc *rx_desc;
972 struct ieee80211_rx_status status;
974 struct ieee80211_hdr *wh;
976 rx_desc = rxq->rx_desc_area + rxq->rx_head;
977 if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST))
981 skb = rxq->rx_skb[rxq->rx_head];
984 rxq->rx_skb[rxq->rx_head] = NULL;
986 rxq->rx_head = (rxq->rx_head + 1) % MWL8K_RX_DESCS;
987 rxq->rx_desc_count--;
989 addr = le32_to_cpu(rx_desc->pkt_phys_addr);
990 pci_unmap_single(priv->pdev, addr,
991 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
993 skb_put(skb, le16_to_cpu(rx_desc->pkt_len));
994 if (mwl8k_remove_dma_header(skb)) {
999 wh = (struct ieee80211_hdr *)skb->data;
1002 * Check for pending join operation. save a copy of
1003 * the beacon and schedule a tasklet to send finalize
1004 * join command to the firmware.
1006 if (mwl8k_capture_bssid(priv, wh))
1007 mwl8k_save_beacon(priv, skb);
1009 memset(&status, 0, sizeof(status));
1011 status.signal = -rx_desc->rssi;
1012 status.noise = -rx_desc->noise_level;
1013 status.qual = rx_desc->link_quality;
1015 status.rate_idx = 1;
1017 status.band = IEEE80211_BAND_2GHZ;
1018 status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
1019 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1020 ieee80211_rx_irqsafe(hw, skb);
1030 * Packet transmission.
1033 /* Transmit queue assignment. */
1035 MWL8K_WME_AC_BK = 0, /* background access */
1036 MWL8K_WME_AC_BE = 1, /* best effort access */
1037 MWL8K_WME_AC_VI = 2, /* video access */
1038 MWL8K_WME_AC_VO = 3, /* voice access */
1041 /* Transmit packet ACK policy */
1042 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
1043 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1045 #define GET_TXQ(_ac) (\
1046 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
1047 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
1048 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
1051 #define MWL8K_TXD_STATUS_OK 0x00000001
1052 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1053 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1054 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1055 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1057 struct mwl8k_tx_desc {
1062 __le32 pkt_phys_addr;
1064 __u8 dest_MAC_addr[ETH_ALEN];
1065 __le32 next_tx_desc_phys_addr;
1070 } __attribute__((packed));
1072 #define MWL8K_TX_DESCS 128
1074 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1076 struct mwl8k_priv *priv = hw->priv;
1077 struct mwl8k_tx_queue *txq = priv->txq + index;
1081 memset(&txq->tx_stats, 0,
1082 sizeof(struct ieee80211_tx_queue_stats));
1083 txq->tx_stats.limit = MWL8K_TX_DESCS;
1087 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1090 pci_alloc_consistent(priv->pdev, size, &txq->tx_desc_dma);
1091 if (txq->tx_desc_area == NULL) {
1092 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1096 memset(txq->tx_desc_area, 0, size);
1098 txq->tx_skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->tx_skb),
1100 if (txq->tx_skb == NULL) {
1101 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1103 pci_free_consistent(priv->pdev, size,
1104 txq->tx_desc_area, txq->tx_desc_dma);
1107 memset(txq->tx_skb, 0, MWL8K_TX_DESCS * sizeof(*txq->tx_skb));
1109 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1110 struct mwl8k_tx_desc *tx_desc;
1113 tx_desc = txq->tx_desc_area + i;
1114 nexti = (i + 1) % MWL8K_TX_DESCS;
1116 tx_desc->status = 0;
1117 tx_desc->next_tx_desc_phys_addr =
1118 cpu_to_le32(txq->tx_desc_dma +
1119 nexti * sizeof(*tx_desc));
1125 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1127 iowrite32(MWL8K_H2A_INT_PPA_READY,
1128 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1129 iowrite32(MWL8K_H2A_INT_DUMMY,
1130 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1131 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1134 static inline int mwl8k_txq_busy(struct mwl8k_priv *priv)
1136 return priv->pending_tx_pkts;
1139 struct mwl8k_txq_info {
1148 static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
1149 struct mwl8k_txq_info txinfo[],
1152 int count, desc, status;
1153 struct mwl8k_tx_queue *txq;
1154 struct mwl8k_tx_desc *tx_desc;
1157 memset(txinfo, 0, num_queues * sizeof(struct mwl8k_txq_info));
1158 spin_lock_bh(&priv->tx_lock);
1159 for (count = 0; count < num_queues; count++) {
1160 txq = priv->txq + count;
1161 txinfo[count].len = txq->tx_stats.len;
1162 txinfo[count].head = txq->tx_head;
1163 txinfo[count].tail = txq->tx_tail;
1164 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1165 tx_desc = txq->tx_desc_area + desc;
1166 status = le32_to_cpu(tx_desc->status);
1168 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1169 txinfo[count].fw_owned++;
1171 txinfo[count].drv_owned++;
1173 if (tx_desc->pkt_len == 0)
1174 txinfo[count].unused++;
1177 spin_unlock_bh(&priv->tx_lock);
1182 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw, u32 delay_ms)
1185 unsigned long timeout = 0;
1186 struct mwl8k_priv *priv = hw->priv;
1187 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1191 if (priv->tx_wait != NULL)
1192 printk(KERN_ERR "WARNING Previous TXWaitEmpty instance\n");
1194 spin_lock_bh(&priv->tx_lock);
1195 count = mwl8k_txq_busy(priv);
1197 priv->tx_wait = &cmd_wait;
1198 if (priv->radio_state)
1199 mwl8k_tx_start(priv);
1201 spin_unlock_bh(&priv->tx_lock);
1204 struct mwl8k_txq_info txinfo[4];
1208 timeout = wait_for_completion_timeout(&cmd_wait,
1209 msecs_to_jiffies(delay_ms));
1213 spin_lock_bh(&priv->tx_lock);
1214 priv->tx_wait = NULL;
1215 newcount = mwl8k_txq_busy(priv);
1216 spin_unlock_bh(&priv->tx_lock);
1218 printk(KERN_ERR "%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
1219 __func__, __LINE__, delay_ms, count, newcount);
1221 mwl8k_scan_tx_ring(priv, txinfo, 4);
1222 for (index = 0 ; index < 4; index++)
1224 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
1229 txinfo[index].fw_owned,
1230 txinfo[index].drv_owned,
1231 txinfo[index].unused);
1238 #define MWL8K_TXD_SUCCESS(status) \
1239 ((status) & (MWL8K_TXD_STATUS_OK | \
1240 MWL8K_TXD_STATUS_OK_RETRY | \
1241 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1243 static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1245 struct mwl8k_priv *priv = hw->priv;
1246 struct mwl8k_tx_queue *txq = priv->txq + index;
1249 while (txq->tx_stats.len > 0) {
1252 struct mwl8k_tx_desc *tx_desc;
1255 struct sk_buff *skb;
1256 struct ieee80211_tx_info *info;
1261 tx_desc = txq->tx_desc_area + tx;
1263 status = le32_to_cpu(tx_desc->status);
1265 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1269 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1272 txq->tx_head = (tx + 1) % MWL8K_TX_DESCS;
1273 BUG_ON(txq->tx_stats.len == 0);
1274 txq->tx_stats.len--;
1275 priv->pending_tx_pkts--;
1277 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1278 size = (u32)(le16_to_cpu(tx_desc->pkt_len));
1279 skb = txq->tx_skb[tx].skb;
1280 txq->tx_skb[tx].skb = NULL;
1282 BUG_ON(skb == NULL);
1283 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1285 rc = mwl8k_remove_dma_header(skb);
1287 /* Mark descriptor as unused */
1288 tx_desc->pkt_phys_addr = 0;
1289 tx_desc->pkt_len = 0;
1291 if (txq->tx_skb[tx].clone) {
1292 /* Replace with original skb
1293 * before returning to stack
1294 * as buffer has been cloned
1297 skb = txq->tx_skb[tx].clone;
1298 txq->tx_skb[tx].clone = NULL;
1302 /* Something has gone wrong here.
1303 * Failed to remove DMA header.
1304 * Print error message and drop packet.
1306 printk(KERN_ERR "%s: Error removing DMA header from "
1307 "tx skb 0x%p.\n", priv->name, skb);
1313 info = IEEE80211_SKB_CB(skb);
1314 ieee80211_tx_info_clear_status(info);
1316 /* Convert firmware status stuff into tx_status */
1317 if (MWL8K_TXD_SUCCESS(status)) {
1319 info->flags |= IEEE80211_TX_STAT_ACK;
1322 ieee80211_tx_status_irqsafe(hw, skb);
1324 wake = !priv->inconfig && priv->radio_state;
1328 ieee80211_wake_queue(hw, index);
1331 /* must be called only when the card's transmit is completely halted */
1332 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1334 struct mwl8k_priv *priv = hw->priv;
1335 struct mwl8k_tx_queue *txq = priv->txq + index;
1337 mwl8k_txq_reclaim(hw, index, 1);
1342 pci_free_consistent(priv->pdev,
1343 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1344 txq->tx_desc_area, txq->tx_desc_dma);
1345 txq->tx_desc_area = NULL;
1349 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1351 struct mwl8k_priv *priv = hw->priv;
1352 struct ieee80211_tx_info *tx_info;
1353 struct ieee80211_hdr *wh;
1354 struct mwl8k_tx_queue *txq;
1355 struct mwl8k_tx_desc *tx;
1356 struct mwl8k_dma_data *tr;
1357 struct mwl8k_vif *mwl8k_vif;
1358 struct sk_buff *org_skb = skb;
1361 bool qosframe = false, ampduframe = false;
1362 bool mcframe = false, eapolframe = false;
1363 bool amsduframe = false;
1366 txq = priv->txq + index;
1367 tx = txq->tx_desc_area + txq->tx_tail;
1369 BUG_ON(txq->tx_skb[txq->tx_tail].skb != NULL);
1372 * Append HW DMA header to start of packet. Drop packet if
1373 * there is not enough space or a failure to unshare/unclone
1376 skb = mwl8k_add_dma_header(skb);
1379 printk(KERN_DEBUG "%s: failed to prepend HW DMA "
1380 "header, dropping TX frame.\n", priv->name);
1381 dev_kfree_skb(org_skb);
1382 return NETDEV_TX_OK;
1385 tx_info = IEEE80211_SKB_CB(skb);
1386 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1387 tr = (struct mwl8k_dma_data *)skb->data;
1389 fc = wh->frame_control;
1390 qosframe = ieee80211_is_data_qos(fc);
1391 mcframe = is_multicast_ether_addr(wh->addr1);
1392 ampduframe = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
1394 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1395 u16 seqno = mwl8k_vif->seqno;
1396 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1397 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1398 mwl8k_vif->seqno = seqno++ % 4096;
1402 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1404 dma = pci_map_single(priv->pdev, skb->data,
1405 skb->len, PCI_DMA_TODEVICE);
1407 if (pci_dma_mapping_error(priv->pdev, dma)) {
1408 printk(KERN_DEBUG "%s: failed to dma map skb, "
1409 "dropping TX frame.\n", priv->name);
1411 if (org_skb != NULL)
1412 dev_kfree_skb(org_skb);
1415 return NETDEV_TX_OK;
1418 /* Set desc header, cpu bit order. */
1421 tx->tx_priority = index;
1422 tx->qos_control = 0;
1424 tx->peer_id = mwl8k_vif->peer_id;
1426 amsduframe = !!(qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT);
1428 /* Setup firmware control bit fields for each frame type. */
1429 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) {
1431 qos = mwl8k_qos_setbit_eosp(qos);
1432 /* Set Queue size to unspecified */
1433 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1434 } else if (ieee80211_is_data(fc)) {
1437 tx->status |= MWL8K_TXD_STATUS_MULTICAST_TX;
1440 * Tell firmware to not send EAPOL pkts in an
1441 * aggregate. Verify against mac80211 tx path. If
1442 * stack turns off AMPDU for an EAPOL frame this
1443 * check will be removed.
1446 qos = mwl8k_qos_setbit_ack(qos,
1447 MWL8K_TXD_ACK_POLICY_NORMAL);
1449 /* Send pkt in an aggregate if AMPDU frame. */
1451 qos = mwl8k_qos_setbit_ack(qos,
1452 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1454 qos = mwl8k_qos_setbit_ack(qos,
1455 MWL8K_TXD_ACK_POLICY_NORMAL);
1458 qos = mwl8k_qos_setbit_amsdu(qos);
1462 /* Convert to little endian */
1463 tx->qos_control = cpu_to_le16(qos);
1464 tx->status = cpu_to_le32(tx->status);
1465 tx->pkt_phys_addr = cpu_to_le32(dma);
1466 tx->pkt_len = cpu_to_le16(skb->len);
1468 txq->tx_skb[txq->tx_tail].skb = skb;
1469 txq->tx_skb[txq->tx_tail].clone =
1470 skb == org_skb ? NULL : org_skb;
1472 spin_lock_bh(&priv->tx_lock);
1474 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_OK |
1475 MWL8K_TXD_STATUS_FW_OWNED);
1477 txq->tx_stats.len++;
1478 priv->pending_tx_pkts++;
1479 txq->tx_stats.count++;
1482 if (txq->tx_tail == MWL8K_TX_DESCS)
1484 if (txq->tx_head == txq->tx_tail)
1485 ieee80211_stop_queue(hw, index);
1487 if (priv->inconfig) {
1489 * Silently queue packet when we are in the middle of
1490 * a config cycle. Notify firmware only if we are
1491 * waiting for TXQs to empty. If a packet is sent
1492 * before .config() is complete, perhaps it is better
1493 * to drop the packet, as the channel is being changed
1494 * and the packet will end up on the wrong channel.
1496 printk(KERN_ERR "%s(): WARNING TX activity while "
1497 "in config\n", __func__);
1499 if (priv->tx_wait != NULL)
1500 mwl8k_tx_start(priv);
1502 mwl8k_tx_start(priv);
1504 spin_unlock_bh(&priv->tx_lock);
1506 return NETDEV_TX_OK;
1511 * Command processing.
1514 /* Timeout firmware commands after 2000ms */
1515 #define MWL8K_CMD_TIMEOUT_MS 2000
1517 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1519 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1520 struct mwl8k_priv *priv = hw->priv;
1521 void __iomem *regs = priv->regs;
1522 dma_addr_t dma_addr;
1523 unsigned int dma_size;
1525 u16 __iomem *result;
1526 unsigned long timeout = 0;
1529 cmd->result = 0xFFFF;
1530 dma_size = le16_to_cpu(cmd->length);
1531 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1532 PCI_DMA_BIDIRECTIONAL);
1533 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1536 if (priv->hostcmd_wait != NULL)
1537 printk(KERN_ERR "WARNING host command in progress\n");
1539 spin_lock_irq(&priv->fw_lock);
1540 priv->hostcmd_wait = &cmd_wait;
1541 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1542 iowrite32(MWL8K_H2A_INT_DOORBELL,
1543 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1544 iowrite32(MWL8K_H2A_INT_DUMMY,
1545 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1546 spin_unlock_irq(&priv->fw_lock);
1548 timeout = wait_for_completion_timeout(&cmd_wait,
1549 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1551 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1552 PCI_DMA_BIDIRECTIONAL);
1554 result = &cmd->result;
1556 spin_lock_irq(&priv->fw_lock);
1557 priv->hostcmd_wait = NULL;
1558 spin_unlock_irq(&priv->fw_lock);
1559 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1561 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1562 MWL8K_CMD_TIMEOUT_MS);
1565 rc = *result ? -EINVAL : 0;
1567 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1569 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1579 struct mwl8k_cmd_get_hw_spec {
1580 struct mwl8k_cmd_pkt header;
1582 __u8 host_interface;
1584 __u8 perm_addr[ETH_ALEN];
1589 __u8 mcs_bitmap[16];
1590 __le32 rx_queue_ptr;
1591 __le32 num_tx_queues;
1592 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1594 __le32 num_tx_desc_per_queue;
1595 __le32 total_rx_desc;
1596 } __attribute__((packed));
1598 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
1600 struct mwl8k_priv *priv = hw->priv;
1601 struct mwl8k_cmd_get_hw_spec *cmd;
1605 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1609 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1610 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1612 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1613 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1614 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rx_desc_dma);
1615 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1616 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1617 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].tx_desc_dma);
1618 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1619 cmd->total_rx_desc = cpu_to_le32(MWL8K_RX_DESCS);
1621 rc = mwl8k_post_cmd(hw, &cmd->header);
1624 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1625 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1626 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1627 priv->hw_rev = cmd->hw_rev;
1635 * CMD_MAC_MULTICAST_ADR.
1637 struct mwl8k_cmd_mac_multicast_adr {
1638 struct mwl8k_cmd_pkt header;
1641 __u8 addr[1][ETH_ALEN];
1644 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
1645 static int mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
1647 struct dev_addr_list *mclist)
1649 struct mwl8k_cmd_mac_multicast_adr *cmd;
1652 int size = sizeof(*cmd) + ((mc_count - 1) * ETH_ALEN);
1653 cmd = kzalloc(size, GFP_KERNEL);
1657 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1658 cmd->header.length = cpu_to_le16(size);
1659 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1660 cmd->numaddr = cpu_to_le16(mc_count);
1661 while ((index < mc_count) && mclist) {
1662 if (mclist->da_addrlen != ETH_ALEN) {
1664 goto mwl8k_cmd_mac_multicast_adr_exit;
1666 memcpy(cmd->addr[index], mclist->da_addr, ETH_ALEN);
1668 mclist = mclist->next;
1671 rc = mwl8k_post_cmd(hw, &cmd->header);
1673 mwl8k_cmd_mac_multicast_adr_exit:
1679 * CMD_802_11_GET_STAT.
1681 struct mwl8k_cmd_802_11_get_stat {
1682 struct mwl8k_cmd_pkt header;
1685 } __attribute__((packed));
1687 #define MWL8K_STAT_ACK_FAILURE 9
1688 #define MWL8K_STAT_RTS_FAILURE 12
1689 #define MWL8K_STAT_FCS_ERROR 24
1690 #define MWL8K_STAT_RTS_SUCCESS 11
1692 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1693 struct ieee80211_low_level_stats *stats)
1695 struct mwl8k_cmd_802_11_get_stat *cmd;
1698 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1702 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1703 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1704 cmd->action = cpu_to_le16(MWL8K_CMD_GET);
1706 rc = mwl8k_post_cmd(hw, &cmd->header);
1708 stats->dot11ACKFailureCount =
1709 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1710 stats->dot11RTSFailureCount =
1711 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1712 stats->dot11FCSErrorCount =
1713 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1714 stats->dot11RTSSuccessCount =
1715 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1723 * CMD_802_11_RADIO_CONTROL.
1725 struct mwl8k_cmd_802_11_radio_control {
1726 struct mwl8k_cmd_pkt header;
1730 } __attribute__((packed));
1732 static int mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, int enable)
1734 struct mwl8k_priv *priv = hw->priv;
1735 struct mwl8k_cmd_802_11_radio_control *cmd;
1738 if (((enable & MWL8K_RADIO_ENABLE) == priv->radio_state) &&
1739 !(enable & MWL8K_RADIO_FORCE))
1742 enable &= MWL8K_RADIO_ENABLE;
1744 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1748 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1749 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1750 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1751 cmd->control = cpu_to_le16(priv->radio_preamble);
1752 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1754 rc = mwl8k_post_cmd(hw, &cmd->header);
1758 priv->radio_state = enable;
1764 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1766 struct mwl8k_priv *priv;
1768 if (hw == NULL || hw->priv == NULL)
1772 priv->radio_preamble = (short_preamble ?
1773 MWL8K_RADIO_SHORT_PREAMBLE :
1774 MWL8K_RADIO_LONG_PREAMBLE);
1776 return mwl8k_cmd_802_11_radio_control(hw,
1777 MWL8K_RADIO_ENABLE | MWL8K_RADIO_FORCE);
1781 * CMD_802_11_RF_TX_POWER.
1783 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1785 struct mwl8k_cmd_802_11_rf_tx_power {
1786 struct mwl8k_cmd_pkt header;
1788 __le16 support_level;
1789 __le16 current_level;
1791 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1792 } __attribute__((packed));
1794 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1796 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1799 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1803 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1804 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1805 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1806 cmd->support_level = cpu_to_le16(dBm);
1808 rc = mwl8k_post_cmd(hw, &cmd->header);
1817 struct mwl8k_cmd_set_pre_scan {
1818 struct mwl8k_cmd_pkt header;
1819 } __attribute__((packed));
1821 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
1823 struct mwl8k_cmd_set_pre_scan *cmd;
1826 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1830 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
1831 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1833 rc = mwl8k_post_cmd(hw, &cmd->header);
1840 * CMD_SET_POST_SCAN.
1842 struct mwl8k_cmd_set_post_scan {
1843 struct mwl8k_cmd_pkt header;
1845 __u8 bssid[ETH_ALEN];
1846 } __attribute__((packed));
1849 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 mac[ETH_ALEN])
1851 struct mwl8k_cmd_set_post_scan *cmd;
1854 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1858 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
1859 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1861 memcpy(cmd->bssid, mac, ETH_ALEN);
1863 rc = mwl8k_post_cmd(hw, &cmd->header);
1870 * CMD_SET_RF_CHANNEL.
1872 struct mwl8k_cmd_set_rf_channel {
1873 struct mwl8k_cmd_pkt header;
1875 __u8 current_channel;
1876 __le32 channel_flags;
1877 } __attribute__((packed));
1879 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
1880 struct ieee80211_channel *channel)
1882 struct mwl8k_cmd_set_rf_channel *cmd;
1885 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1889 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
1890 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1891 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1892 cmd->current_channel = channel->hw_value;
1893 if (channel->band == IEEE80211_BAND_2GHZ)
1894 cmd->channel_flags = cpu_to_le32(0x00000081);
1896 cmd->channel_flags = cpu_to_le32(0x00000000);
1898 rc = mwl8k_post_cmd(hw, &cmd->header);
1907 struct mwl8k_cmd_set_slot {
1908 struct mwl8k_cmd_pkt header;
1911 } __attribute__((packed));
1913 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, int slot_time)
1915 struct mwl8k_cmd_set_slot *cmd;
1918 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1922 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
1923 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1924 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1925 cmd->short_slot = slot_time == MWL8K_SHORT_SLOTTIME ? 1 : 0;
1927 rc = mwl8k_post_cmd(hw, &cmd->header);
1936 struct mwl8k_cmd_mimo_config {
1937 struct mwl8k_cmd_pkt header;
1939 __u8 rx_antenna_map;
1940 __u8 tx_antenna_map;
1941 } __attribute__((packed));
1943 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
1945 struct mwl8k_cmd_mimo_config *cmd;
1948 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1952 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
1953 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1954 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
1955 cmd->rx_antenna_map = rx;
1956 cmd->tx_antenna_map = tx;
1958 rc = mwl8k_post_cmd(hw, &cmd->header);
1965 * CMD_ENABLE_SNIFFER.
1967 struct mwl8k_cmd_enable_sniffer {
1968 struct mwl8k_cmd_pkt header;
1970 } __attribute__((packed));
1972 static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
1974 struct mwl8k_cmd_enable_sniffer *cmd;
1977 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1981 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
1982 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1983 cmd->action = enable ? cpu_to_le32((u32)MWL8K_CMD_SET) : 0;
1985 rc = mwl8k_post_cmd(hw, &cmd->header);
1992 * CMD_SET_RATE_ADAPT_MODE.
1994 struct mwl8k_cmd_set_rate_adapt_mode {
1995 struct mwl8k_cmd_pkt header;
1998 } __attribute__((packed));
2000 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2002 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2005 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2009 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2010 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2011 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2012 cmd->mode = cpu_to_le16(mode);
2014 rc = mwl8k_post_cmd(hw, &cmd->header);
2023 struct mwl8k_cmd_set_wmm {
2024 struct mwl8k_cmd_pkt header;
2026 } __attribute__((packed));
2028 static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2030 struct mwl8k_priv *priv = hw->priv;
2031 struct mwl8k_cmd_set_wmm *cmd;
2034 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2038 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2039 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2040 cmd->action = enable ? cpu_to_le16(MWL8K_CMD_SET) : 0;
2042 rc = mwl8k_post_cmd(hw, &cmd->header);
2046 priv->wmm_mode = enable;
2052 * CMD_SET_RTS_THRESHOLD.
2054 struct mwl8k_cmd_rts_threshold {
2055 struct mwl8k_cmd_pkt header;
2058 } __attribute__((packed));
2060 static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
2061 u16 action, u16 *threshold)
2063 struct mwl8k_cmd_rts_threshold *cmd;
2066 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2070 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2071 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2072 cmd->action = cpu_to_le16(action);
2073 cmd->threshold = cpu_to_le16(*threshold);
2075 rc = mwl8k_post_cmd(hw, &cmd->header);
2082 * CMD_SET_EDCA_PARAMS.
2084 struct mwl8k_cmd_set_edca_params {
2085 struct mwl8k_cmd_pkt header;
2087 /* See MWL8K_SET_EDCA_XXX below */
2090 /* TX opportunity in units of 32 us */
2093 /* Log exponent of max contention period: 0...15*/
2096 /* Log exponent of min contention period: 0...15 */
2099 /* Adaptive interframe spacing in units of 32us */
2102 /* TX queue to configure */
2104 } __attribute__((packed));
2106 #define MWL8K_SET_EDCA_CW 0x01
2107 #define MWL8K_SET_EDCA_TXOP 0x02
2108 #define MWL8K_SET_EDCA_AIFS 0x04
2110 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2111 MWL8K_SET_EDCA_TXOP | \
2112 MWL8K_SET_EDCA_AIFS)
2115 mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2116 __u16 cw_min, __u16 cw_max,
2117 __u8 aifs, __u16 txop)
2119 struct mwl8k_cmd_set_edca_params *cmd;
2120 u32 log_cw_min, log_cw_max;
2123 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2127 log_cw_min = ilog2(cw_min+1);
2128 log_cw_max = ilog2(cw_max+1);
2129 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2130 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2132 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2133 cmd->txop = cpu_to_le16(txop);
2134 cmd->log_cw_max = (u8)log_cw_max;
2135 cmd->log_cw_min = (u8)log_cw_min;
2139 rc = mwl8k_post_cmd(hw, &cmd->header);
2146 * CMD_FINALIZE_JOIN.
2149 /* FJ beacon buffer size is compiled into the firmware. */
2150 #define MWL8K_FJ_BEACON_MAXLEN 128
2152 struct mwl8k_cmd_finalize_join {
2153 struct mwl8k_cmd_pkt header;
2154 __le32 sleep_interval; /* Number of beacon periods to sleep */
2155 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2156 } __attribute__((packed));
2158 static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2159 __u16 framelen, __u16 dtim)
2161 struct mwl8k_cmd_finalize_join *cmd;
2162 struct ieee80211_mgmt *payload = frame;
2170 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2174 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2175 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2178 cmd->sleep_interval = cpu_to_le32(dtim);
2180 cmd->sleep_interval = cpu_to_le32(1);
2182 hdrlen = ieee80211_hdrlen(payload->frame_control);
2184 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2186 /* XXX TBD Might just have to abort and return an error */
2187 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2188 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
2189 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2190 payload_len, MWL8K_FJ_BEACON_MAXLEN);
2192 payload_len = payload_len > MWL8K_FJ_BEACON_MAXLEN ?
2193 MWL8K_FJ_BEACON_MAXLEN : payload_len;
2195 if (payload && payload_len)
2196 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2198 rc = mwl8k_post_cmd(hw, &cmd->header);
2206 struct mwl8k_cmd_update_sta_db {
2207 struct mwl8k_cmd_pkt header;
2209 /* See STADB_ACTION_TYPE */
2212 /* Peer MAC address */
2213 __u8 peer_addr[ETH_ALEN];
2217 /* Peer info - valid during add/update. */
2218 struct peer_capability_info peer_info;
2219 } __attribute__((packed));
2221 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2222 struct ieee80211_vif *vif, __u32 action)
2224 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2225 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2226 struct mwl8k_cmd_update_sta_db *cmd;
2227 struct peer_capability_info *peer_info;
2228 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2232 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2236 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2237 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2239 cmd->action = cpu_to_le32(action);
2240 peer_info = &cmd->peer_info;
2241 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2244 case MWL8K_STA_DB_ADD_ENTRY:
2245 case MWL8K_STA_DB_MODIFY_ENTRY:
2246 /* Build peer_info block */
2247 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2248 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2249 peer_info->interop = 1;
2250 peer_info->amsdu_enabled = 0;
2252 rates = peer_info->legacy_rates;
2253 for (count = 0 ; count < mv_vif->legacy_nrates; count++)
2254 rates[count] = bitrates[count].hw_value;
2256 rc = mwl8k_post_cmd(hw, &cmd->header);
2258 mv_vif->peer_id = peer_info->station_id;
2262 case MWL8K_STA_DB_DEL_ENTRY:
2263 case MWL8K_STA_DB_FLUSH:
2265 rc = mwl8k_post_cmd(hw, &cmd->header);
2267 mv_vif->peer_id = 0;
2278 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2280 #define MWL8K_FRAME_PROT_DISABLED 0x00
2281 #define MWL8K_FRAME_PROT_11G 0x07
2282 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2283 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2285 struct mwl8k_cmd_update_set_aid {
2286 struct mwl8k_cmd_pkt header;
2289 /* AP's MAC address (BSSID) */
2290 __u8 bssid[ETH_ALEN];
2291 __le16 protection_mode;
2292 __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2293 } __attribute__((packed));
2295 static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2296 struct ieee80211_vif *vif)
2298 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2299 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2300 struct mwl8k_cmd_update_set_aid *cmd;
2301 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2306 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2310 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2311 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2312 cmd->aid = cpu_to_le16(info->aid);
2314 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
2316 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2318 if (info->use_cts_prot) {
2319 prot_mode = MWL8K_FRAME_PROT_11G;
2321 switch (info->ht_operation_mode &
2322 IEEE80211_HT_OP_MODE_PROTECTION) {
2323 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2324 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2326 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2327 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2330 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2335 cmd->protection_mode = cpu_to_le16(prot_mode);
2337 for (count = 0; count < mv_vif->legacy_nrates; count++)
2338 cmd->supp_rates[count] = bitrates[count].hw_value;
2340 rc = mwl8k_post_cmd(hw, &cmd->header);
2349 struct mwl8k_cmd_update_rateset {
2350 struct mwl8k_cmd_pkt header;
2351 __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2353 /* Bitmap for supported MCS codes. */
2354 __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
2355 __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
2356 } __attribute__((packed));
2358 static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2359 struct ieee80211_vif *vif)
2361 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2362 struct mwl8k_cmd_update_rateset *cmd;
2363 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2367 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2371 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2372 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2374 for (count = 0; count < mv_vif->legacy_nrates; count++)
2375 cmd->legacy_rates[count] = bitrates[count].hw_value;
2377 rc = mwl8k_post_cmd(hw, &cmd->header);
2384 * CMD_USE_FIXED_RATE.
2386 #define MWL8K_RATE_TABLE_SIZE 8
2387 #define MWL8K_UCAST_RATE 0
2388 #define MWL8K_USE_AUTO_RATE 0x0002
2390 struct mwl8k_rate_entry {
2391 /* Set to 1 if HT rate, 0 if legacy. */
2394 /* Set to 1 to use retry_count field. */
2395 __le32 enable_retry;
2397 /* Specified legacy rate or MCS. */
2400 /* Number of allowed retries. */
2402 } __attribute__((packed));
2404 struct mwl8k_rate_table {
2405 /* 1 to allow specified rate and below */
2406 __le32 allow_rate_drop;
2408 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2409 } __attribute__((packed));
2411 struct mwl8k_cmd_use_fixed_rate {
2412 struct mwl8k_cmd_pkt header;
2414 struct mwl8k_rate_table rate_table;
2416 /* Unicast, Broadcast or Multicast */
2420 } __attribute__((packed));
2422 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2423 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2425 struct mwl8k_cmd_use_fixed_rate *cmd;
2429 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2433 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2434 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2436 cmd->action = cpu_to_le32(action);
2437 cmd->rate_type = cpu_to_le32(rate_type);
2439 if (rate_table != NULL) {
2440 /* Copy over each field manually so
2441 * that bitflipping can be done
2443 cmd->rate_table.allow_rate_drop =
2444 cpu_to_le32(rate_table->allow_rate_drop);
2445 cmd->rate_table.num_rates =
2446 cpu_to_le32(rate_table->num_rates);
2448 for (count = 0; count < rate_table->num_rates; count++) {
2449 struct mwl8k_rate_entry *dst =
2450 &cmd->rate_table.rate_entry[count];
2451 struct mwl8k_rate_entry *src =
2452 &rate_table->rate_entry[count];
2454 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2455 dst->enable_retry = cpu_to_le32(src->enable_retry);
2456 dst->rate = cpu_to_le32(src->rate);
2457 dst->retry_count = cpu_to_le32(src->retry_count);
2461 rc = mwl8k_post_cmd(hw, &cmd->header);
2469 * Interrupt handling.
2471 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2473 struct ieee80211_hw *hw = dev_id;
2474 struct mwl8k_priv *priv = hw->priv;
2477 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2478 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2483 if (status & MWL8K_A2H_INT_TX_DONE)
2484 tasklet_schedule(&priv->tx_reclaim_task);
2486 if (status & MWL8K_A2H_INT_RX_READY) {
2487 while (rxq_process(hw, 0, 1))
2488 rxq_refill(hw, 0, 1);
2491 if (status & MWL8K_A2H_INT_OPC_DONE) {
2492 if (priv->hostcmd_wait != NULL) {
2493 complete(priv->hostcmd_wait);
2494 priv->hostcmd_wait = NULL;
2498 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
2499 if (!priv->inconfig &&
2500 priv->radio_state &&
2501 mwl8k_txq_busy(priv))
2502 mwl8k_tx_start(priv);
2510 * Core driver operations.
2512 static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2514 struct mwl8k_priv *priv = hw->priv;
2515 int index = skb_get_queue_mapping(skb);
2518 if (priv->current_channel == NULL) {
2519 printk(KERN_DEBUG "%s: dropped TX frame since radio "
2520 "disabled\n", priv->name);
2522 return NETDEV_TX_OK;
2525 rc = mwl8k_txq_xmit(hw, index, skb);
2530 struct mwl8k_work_struct {
2531 /* Initialized by mwl8k_queue_work(). */
2532 struct work_struct wt;
2534 /* Required field passed in to mwl8k_queue_work(). */
2535 struct ieee80211_hw *hw;
2537 /* Required field passed in to mwl8k_queue_work(). */
2538 int (*wfunc)(struct work_struct *w);
2540 /* Initialized by mwl8k_queue_work(). */
2541 struct completion *cmd_wait;
2547 * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
2548 * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
2552 /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
2553 unsigned long timeout_ms;
2555 /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
2556 u32 txwait_attempts;
2558 /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
2563 /* Flags controlling behavior of config queue requests */
2565 /* Caller spins while waiting for completion. */
2566 #define MWL8K_WQ_SPIN 0x00000001
2568 /* Wait for TX queues to empty before proceeding with configuration. */
2569 #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
2571 /* Queue request and return immediately. */
2572 #define MWL8K_WQ_POST_REQUEST 0x00000004
2575 * Caller sleeps and waits for task complete notification.
2576 * Do not use in atomic context.
2578 #define MWL8K_WQ_SLEEP 0x00000008
2580 /* Free work struct when task is done. */
2581 #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
2584 * Config request is queued and returns to caller imediately. Use
2585 * this in atomic context. Work struct is freed by mwl8k_queue_work()
2586 * when this flag is set.
2588 #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
2589 MWL8K_WQ_FREE_WORKSTRUCT)
2591 /* Default work queue behavior is to sleep and wait for tx completion. */
2592 #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
2595 * Default config request timeout. Add adjustments to make sure the
2596 * config thread waits long enough for both tx wait and cmd wait before
2600 /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
2601 #define MWL8K_TXWAIT_TIMEOUT_MS 1000
2603 /* Default number of TX wait attempts. */
2604 #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
2606 /* Total time to wait for TXQ to drain. */
2607 #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
2608 MWL8K_WQ_TXWAIT_ATTEMPTS)
2610 /* Scheduling slop. */
2611 #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
2613 #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
2615 MWL8K_OS_SCHEDULE_OVERHEAD_MS)
2617 static void mwl8k_config_thread(struct work_struct *wt)
2619 struct mwl8k_work_struct *worker = (struct mwl8k_work_struct *)wt;
2620 struct ieee80211_hw *hw = worker->hw;
2621 struct mwl8k_priv *priv = hw->priv;
2624 spin_lock_irq(&priv->tx_lock);
2625 priv->inconfig = true;
2626 spin_unlock_irq(&priv->tx_lock);
2628 ieee80211_stop_queues(hw);
2631 * Wait for host queues to drain before doing PHY
2632 * reconfiguration. This avoids interrupting any in-flight
2633 * DMA transfers to the hardware.
2635 if (worker->options & MWL8K_WQ_TX_WAIT_EMPTY) {
2639 u32 tx_wait_attempts = worker->txwait_attempts;
2641 time_remaining = worker->tx_timeout_ms;
2642 if (!tx_wait_attempts)
2643 tx_wait_attempts = 1;
2645 timeout = worker->tx_timeout_ms/tx_wait_attempts;
2649 iter = tx_wait_attempts;
2653 if (time_remaining > timeout) {
2654 time_remaining -= timeout;
2655 wait_time = timeout;
2657 wait_time = time_remaining;
2662 rc = mwl8k_tx_wait_empty(hw, wait_time);
2664 printk(KERN_ERR "%s() txwait timeout=%ums "
2665 "Retry:%u/%u\n", __func__, timeout,
2666 tx_wait_attempts - iter + 1,
2669 } while (rc && --iter);
2671 rc = iter ? 0 : -ETIMEDOUT;
2674 rc = worker->wfunc(wt);
2676 spin_lock_irq(&priv->tx_lock);
2677 priv->inconfig = false;
2678 if (priv->pending_tx_pkts && priv->radio_state)
2679 mwl8k_tx_start(priv);
2680 spin_unlock_irq(&priv->tx_lock);
2681 ieee80211_wake_queues(hw);
2684 if (worker->options & MWL8K_WQ_SLEEP)
2685 complete(worker->cmd_wait);
2687 if (worker->options & MWL8K_WQ_FREE_WORKSTRUCT)
2691 static int mwl8k_queue_work(struct ieee80211_hw *hw,
2692 struct mwl8k_work_struct *worker,
2693 struct workqueue_struct *wqueue,
2694 int (*wfunc)(struct work_struct *w))
2696 unsigned long timeout = 0;
2699 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2701 if (!worker->timeout_ms)
2702 worker->timeout_ms = MWL8K_CONFIG_TIMEOUT_MS;
2704 if (!worker->options)
2705 worker->options = MWL8K_WQ_DEFAULT_OPTIONS;
2707 if (!worker->txwait_attempts)
2708 worker->txwait_attempts = MWL8K_WQ_TXWAIT_ATTEMPTS;
2710 if (!worker->tx_timeout_ms)
2711 worker->tx_timeout_ms = MWL8K_TXWAIT_MS;
2714 worker->cmd_wait = &cmd_wait;
2716 worker->wfunc = wfunc;
2718 INIT_WORK(&worker->wt, mwl8k_config_thread);
2719 queue_work(wqueue, &worker->wt);
2721 if (worker->options & MWL8K_WQ_POST_REQUEST) {
2724 if (worker->options & MWL8K_WQ_SPIN) {
2725 timeout = worker->timeout_ms;
2726 while (timeout && (worker->rc > 0)) {
2730 } else if (worker->options & MWL8K_WQ_SLEEP)
2731 timeout = wait_for_completion_timeout(&cmd_wait,
2732 msecs_to_jiffies(worker->timeout_ms));
2737 cancel_work_sync(&worker->wt);
2745 struct mwl8k_start_worker {
2746 struct mwl8k_work_struct header;
2749 static int mwl8k_start_wt(struct work_struct *wt)
2751 struct mwl8k_start_worker *worker = (struct mwl8k_start_worker *)wt;
2752 struct ieee80211_hw *hw = worker->header.hw;
2753 struct mwl8k_priv *priv = hw->priv;
2756 if (priv->vif != NULL) {
2758 goto mwl8k_start_exit;
2762 if (mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_ENABLE)) {
2764 goto mwl8k_start_exit;
2767 /* Purge TX/RX HW queues */
2768 if (mwl8k_cmd_set_pre_scan(hw)) {
2770 goto mwl8k_start_exit;
2773 if (mwl8k_cmd_set_post_scan(hw, "\x00\x00\x00\x00\x00\x00")) {
2775 goto mwl8k_start_exit;
2778 /* Enable firmware rate adaptation */
2779 if (mwl8k_cmd_setrateadaptmode(hw, 0)) {
2781 goto mwl8k_start_exit;
2784 /* Disable WMM. WMM gets enabled when stack sends WMM parms */
2785 if (mwl8k_set_wmm(hw, MWL8K_WMM_DISABLE)) {
2787 goto mwl8k_start_exit;
2790 /* Disable sniffer mode */
2791 if (mwl8k_enable_sniffer(hw, 0))
2798 static int mwl8k_start(struct ieee80211_hw *hw)
2800 struct mwl8k_start_worker *worker;
2801 struct mwl8k_priv *priv = hw->priv;
2804 /* Enable tx reclaim tasklet */
2805 tasklet_enable(&priv->tx_reclaim_task);
2807 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
2808 IRQF_SHARED, MWL8K_NAME, hw);
2810 printk(KERN_ERR "%s: failed to register IRQ handler\n",
2813 goto mwl8k_start_disable_tasklet;
2816 /* Enable interrupts */
2817 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2819 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2820 if (worker == NULL) {
2822 goto mwl8k_start_disable_irq;
2825 rc = mwl8k_queue_work(hw, &worker->header,
2826 priv->config_wq, mwl8k_start_wt);
2831 if (rc == -ETIMEDOUT)
2832 printk(KERN_ERR "%s() timed out\n", __func__);
2836 mwl8k_start_disable_irq:
2837 spin_lock_irq(&priv->tx_lock);
2838 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2839 spin_unlock_irq(&priv->tx_lock);
2840 free_irq(priv->pdev->irq, hw);
2842 mwl8k_start_disable_tasklet:
2843 tasklet_disable(&priv->tx_reclaim_task);
2848 struct mwl8k_stop_worker {
2849 struct mwl8k_work_struct header;
2852 static int mwl8k_stop_wt(struct work_struct *wt)
2854 struct mwl8k_stop_worker *worker = (struct mwl8k_stop_worker *)wt;
2855 struct ieee80211_hw *hw = worker->header.hw;
2858 rc = mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
2863 static void mwl8k_stop(struct ieee80211_hw *hw)
2866 struct mwl8k_stop_worker *worker;
2867 struct mwl8k_priv *priv = hw->priv;
2870 if (priv->vif != NULL)
2873 ieee80211_stop_queues(hw);
2875 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2879 rc = mwl8k_queue_work(hw, &worker->header,
2880 priv->config_wq, mwl8k_stop_wt);
2882 if (rc == -ETIMEDOUT)
2883 printk(KERN_ERR "%s() timed out\n", __func__);
2885 /* Disable interrupts */
2886 spin_lock_irq(&priv->tx_lock);
2887 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2888 spin_unlock_irq(&priv->tx_lock);
2889 free_irq(priv->pdev->irq, hw);
2891 /* Stop finalize join worker */
2892 cancel_work_sync(&priv->finalize_join_worker);
2893 if (priv->beacon_skb != NULL)
2894 dev_kfree_skb(priv->beacon_skb);
2896 /* Stop tx reclaim tasklet */
2897 tasklet_disable(&priv->tx_reclaim_task);
2899 /* Stop config thread */
2900 flush_workqueue(priv->config_wq);
2902 /* Return all skbs to mac80211 */
2903 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2904 mwl8k_txq_reclaim(hw, i, 1);
2907 static int mwl8k_add_interface(struct ieee80211_hw *hw,
2908 struct ieee80211_if_init_conf *conf)
2910 struct mwl8k_priv *priv = hw->priv;
2911 struct mwl8k_vif *mwl8k_vif;
2914 * We only support one active interface at a time.
2916 if (priv->vif != NULL)
2920 * We only support managed interfaces for now.
2922 if (conf->type != NL80211_IFTYPE_STATION &&
2923 conf->type != NL80211_IFTYPE_MONITOR)
2926 /* Clean out driver private area */
2927 mwl8k_vif = MWL8K_VIF(conf->vif);
2928 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2930 /* Save the mac address */
2931 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
2933 /* Back pointer to parent config block */
2934 mwl8k_vif->priv = priv;
2936 /* Setup initial PHY parameters */
2937 memcpy(mwl8k_vif->legacy_rates ,
2938 priv->rates, sizeof(mwl8k_vif->legacy_rates));
2939 mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
2941 /* Set Initial sequence number to zero */
2942 mwl8k_vif->seqno = 0;
2944 priv->vif = conf->vif;
2945 priv->current_channel = NULL;
2950 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2951 struct ieee80211_if_init_conf *conf)
2953 struct mwl8k_priv *priv = hw->priv;
2955 if (priv->vif == NULL)
2961 struct mwl8k_config_worker {
2962 struct mwl8k_work_struct header;
2966 static int mwl8k_config_wt(struct work_struct *wt)
2968 struct mwl8k_config_worker *worker =
2969 (struct mwl8k_config_worker *)wt;
2970 struct ieee80211_hw *hw = worker->header.hw;
2971 struct ieee80211_conf *conf = &hw->conf;
2972 struct mwl8k_priv *priv = hw->priv;
2975 if (mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_ENABLE)) {
2977 goto mwl8k_config_exit;
2980 priv->current_channel = conf->channel;
2982 if (mwl8k_cmd_set_rf_channel(hw, conf->channel)) {
2984 goto mwl8k_config_exit;
2987 if (conf->power_level > 18)
2988 conf->power_level = 18;
2989 if (mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level)) {
2991 goto mwl8k_config_exit;
2994 if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
3001 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
3004 struct mwl8k_config_worker *worker;
3005 struct mwl8k_priv *priv = hw->priv;
3007 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3011 worker->changed = changed;
3012 rc = mwl8k_queue_work(hw, &worker->header,
3013 priv->config_wq, mwl8k_config_wt);
3014 if (rc == -ETIMEDOUT) {
3015 printk(KERN_ERR "%s() timed out.\n", __func__);
3022 * mac80211 will crash on anything other than -EINVAL on
3023 * error. Looks like wireless extensions which calls mac80211
3024 * may be the actual culprit...
3026 return rc ? -EINVAL : 0;
3029 struct mwl8k_bss_info_changed_worker {
3030 struct mwl8k_work_struct header;
3031 struct ieee80211_vif *vif;
3032 struct ieee80211_bss_conf *info;
3036 static int mwl8k_bss_info_changed_wt(struct work_struct *wt)
3038 struct mwl8k_bss_info_changed_worker *worker =
3039 (struct mwl8k_bss_info_changed_worker *)wt;
3040 struct ieee80211_hw *hw = worker->header.hw;
3041 struct ieee80211_vif *vif = worker->vif;
3042 struct ieee80211_bss_conf *info = worker->info;
3046 struct mwl8k_priv *priv = hw->priv;
3047 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3049 changed = worker->changed;
3050 priv->capture_beacon = false;
3053 memcpy(&mwl8k_vif->bss_info, info,
3054 sizeof(struct ieee80211_bss_conf));
3057 if (mwl8k_update_rateset(hw, vif))
3058 goto mwl8k_bss_info_changed_exit;
3060 /* Turn on rate adaptation */
3061 if (mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3062 MWL8K_UCAST_RATE, NULL))
3063 goto mwl8k_bss_info_changed_exit;
3065 /* Set radio preamble */
3066 if (mwl8k_set_radio_preamble(hw,
3067 info->use_short_preamble))
3068 goto mwl8k_bss_info_changed_exit;
3071 if (mwl8k_cmd_set_slot(hw, info->use_short_slot ?
3072 MWL8K_SHORT_SLOTTIME : MWL8K_LONG_SLOTTIME))
3073 goto mwl8k_bss_info_changed_exit;
3075 /* Update peer rate info */
3076 if (mwl8k_cmd_update_sta_db(hw, vif,
3077 MWL8K_STA_DB_MODIFY_ENTRY))
3078 goto mwl8k_bss_info_changed_exit;
3081 if (mwl8k_cmd_set_aid(hw, vif))
3082 goto mwl8k_bss_info_changed_exit;
3085 * Finalize the join. Tell rx handler to process
3086 * next beacon from our BSSID.
3088 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
3089 priv->capture_beacon = true;
3091 mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
3092 memset(&mwl8k_vif->bss_info, 0,
3093 sizeof(struct ieee80211_bss_conf));
3094 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
3097 mwl8k_bss_info_changed_exit:
3102 static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3103 struct ieee80211_vif *vif,
3104 struct ieee80211_bss_conf *info,
3107 struct mwl8k_bss_info_changed_worker *worker;
3108 struct mwl8k_priv *priv = hw->priv;
3109 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
3112 if (changed & BSS_CHANGED_BSSID)
3113 memcpy(mv_vif->bssid, info->bssid, ETH_ALEN);
3115 if ((changed & BSS_CHANGED_ASSOC) == 0)
3118 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3123 worker->info = info;
3124 worker->changed = changed;
3125 rc = mwl8k_queue_work(hw, &worker->header,
3127 mwl8k_bss_info_changed_wt);
3129 if (rc == -ETIMEDOUT)
3130 printk(KERN_ERR "%s() timed out\n", __func__);
3133 struct mwl8k_configure_filter_worker {
3134 struct mwl8k_work_struct header;
3135 unsigned int changed_flags;
3136 unsigned int *total_flags;
3138 struct dev_addr_list *mclist;
3141 #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
3143 static int mwl8k_configure_filter_wt(struct work_struct *wt)
3145 struct mwl8k_configure_filter_worker *worker =
3146 (struct mwl8k_configure_filter_worker *)wt;
3148 struct ieee80211_hw *hw = worker->header.hw;
3149 unsigned int changed_flags = worker->changed_flags;
3150 unsigned int *total_flags = worker->total_flags;
3151 int mc_count = worker->mc_count;
3152 struct dev_addr_list *mclist = worker->mclist;
3154 struct mwl8k_priv *priv = hw->priv;
3157 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
3158 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
3159 rc = mwl8k_cmd_set_pre_scan(hw);
3163 bssid = "\x00\x00\x00\x00\x00\x00";
3164 if (priv->vif != NULL)
3165 bssid = MWL8K_VIF(priv->vif)->bssid;
3167 rc = mwl8k_cmd_set_post_scan(hw, bssid);
3172 goto mwl8k_configure_filter_exit;
3174 mc_count = mc_count < priv->num_mcaddrs ?
3175 mc_count : priv->num_mcaddrs;
3176 rc = mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist);
3179 "%s()Error setting multicast addresses\n",
3183 mwl8k_configure_filter_exit:
3187 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3188 int mc_count, struct dev_addr_list *mclist)
3190 struct mwl8k_configure_filter_worker *worker;
3192 worker = kzalloc(sizeof(*worker), GFP_ATOMIC);
3198 * XXX: This is _HORRIBLY_ broken!!
3200 * No locking, the mclist pointer might be invalid as soon as this
3201 * function returns, something in the list might be invalidated
3202 * once we get to the worker, etc...
3204 worker->mc_count = mc_count;
3205 worker->mclist = mclist;
3210 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3211 unsigned int changed_flags,
3212 unsigned int *total_flags,
3216 struct mwl8k_configure_filter_worker *worker = (void *)multicast;
3217 struct mwl8k_priv *priv = hw->priv;
3219 /* Clear unsupported feature flags */
3220 *total_flags &= MWL8K_SUPPORTED_IF_FLAGS;
3222 if (!(changed_flags & MWL8K_SUPPORTED_IF_FLAGS))
3228 worker->header.options = MWL8K_WQ_QUEUE_ONLY | MWL8K_WQ_TX_WAIT_EMPTY;
3229 worker->changed_flags = changed_flags;
3230 worker->total_flags = total_flags;
3232 mwl8k_queue_work(hw, &worker->header, priv->config_wq,
3233 mwl8k_configure_filter_wt);
3236 struct mwl8k_set_rts_threshold_worker {
3237 struct mwl8k_work_struct header;
3241 static int mwl8k_set_rts_threshold_wt(struct work_struct *wt)
3243 struct mwl8k_set_rts_threshold_worker *worker =
3244 (struct mwl8k_set_rts_threshold_worker *)wt;
3246 struct ieee80211_hw *hw = worker->header.hw;
3247 u16 threshold = (u16)(worker->value);
3250 rc = mwl8k_rts_threshold(hw, MWL8K_CMD_SET, &threshold);
3255 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3258 struct mwl8k_set_rts_threshold_worker *worker;
3259 struct mwl8k_priv *priv = hw->priv;
3261 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3265 worker->value = value;
3267 rc = mwl8k_queue_work(hw, &worker->header,
3269 mwl8k_set_rts_threshold_wt);
3272 if (rc == -ETIMEDOUT) {
3273 printk(KERN_ERR "%s() timed out\n", __func__);
3280 struct mwl8k_conf_tx_worker {
3281 struct mwl8k_work_struct header;
3283 const struct ieee80211_tx_queue_params *params;
3286 static int mwl8k_conf_tx_wt(struct work_struct *wt)
3288 struct mwl8k_conf_tx_worker *worker =
3289 (struct mwl8k_conf_tx_worker *)wt;
3291 struct ieee80211_hw *hw = worker->header.hw;
3292 u16 queue = worker->queue;
3293 const struct ieee80211_tx_queue_params *params = worker->params;
3295 struct mwl8k_priv *priv = hw->priv;
3298 if (priv->wmm_mode == MWL8K_WMM_DISABLE)
3299 if (mwl8k_set_wmm(hw, MWL8K_WMM_ENABLE)) {
3301 goto mwl8k_conf_tx_exit;
3304 if (mwl8k_set_edca_params(hw, GET_TXQ(queue), params->cw_min,
3305 params->cw_max, params->aifs, params->txop))
3311 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3312 const struct ieee80211_tx_queue_params *params)
3315 struct mwl8k_conf_tx_worker *worker;
3316 struct mwl8k_priv *priv = hw->priv;
3318 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3322 worker->queue = queue;
3323 worker->params = params;
3324 rc = mwl8k_queue_work(hw, &worker->header,
3325 priv->config_wq, mwl8k_conf_tx_wt);
3327 if (rc == -ETIMEDOUT) {
3328 printk(KERN_ERR "%s() timed out\n", __func__);
3334 static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3335 struct ieee80211_tx_queue_stats *stats)
3337 struct mwl8k_priv *priv = hw->priv;
3338 struct mwl8k_tx_queue *txq;
3341 spin_lock_bh(&priv->tx_lock);
3342 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3343 txq = priv->txq + index;
3344 memcpy(&stats[index], &txq->tx_stats,
3345 sizeof(struct ieee80211_tx_queue_stats));
3347 spin_unlock_bh(&priv->tx_lock);
3351 struct mwl8k_get_stats_worker {
3352 struct mwl8k_work_struct header;
3353 struct ieee80211_low_level_stats *stats;
3356 static int mwl8k_get_stats_wt(struct work_struct *wt)
3358 struct mwl8k_get_stats_worker *worker =
3359 (struct mwl8k_get_stats_worker *)wt;
3361 return mwl8k_cmd_802_11_get_stat(worker->header.hw, worker->stats);
3364 static int mwl8k_get_stats(struct ieee80211_hw *hw,
3365 struct ieee80211_low_level_stats *stats)
3368 struct mwl8k_get_stats_worker *worker;
3369 struct mwl8k_priv *priv = hw->priv;
3371 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3375 worker->stats = stats;
3376 rc = mwl8k_queue_work(hw, &worker->header,
3377 priv->config_wq, mwl8k_get_stats_wt);
3380 if (rc == -ETIMEDOUT) {
3381 printk(KERN_ERR "%s() timed out\n", __func__);
3388 static const struct ieee80211_ops mwl8k_ops = {
3390 .start = mwl8k_start,
3392 .add_interface = mwl8k_add_interface,
3393 .remove_interface = mwl8k_remove_interface,
3394 .config = mwl8k_config,
3395 .bss_info_changed = mwl8k_bss_info_changed,
3396 .prepare_multicast = mwl8k_prepare_multicast,
3397 .configure_filter = mwl8k_configure_filter,
3398 .set_rts_threshold = mwl8k_set_rts_threshold,
3399 .conf_tx = mwl8k_conf_tx,
3400 .get_tx_stats = mwl8k_get_tx_stats,
3401 .get_stats = mwl8k_get_stats,
3404 static void mwl8k_tx_reclaim_handler(unsigned long data)
3407 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3408 struct mwl8k_priv *priv = hw->priv;
3410 spin_lock_bh(&priv->tx_lock);
3411 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3412 mwl8k_txq_reclaim(hw, i, 0);
3414 if (priv->tx_wait != NULL) {
3415 int count = mwl8k_txq_busy(priv);
3417 complete(priv->tx_wait);
3418 priv->tx_wait = NULL;
3421 spin_unlock_bh(&priv->tx_lock);
3424 static void mwl8k_finalize_join_worker(struct work_struct *work)
3426 struct mwl8k_priv *priv =
3427 container_of(work, struct mwl8k_priv, finalize_join_worker);
3428 struct sk_buff *skb = priv->beacon_skb;
3429 u8 dtim = (MWL8K_VIF(priv->vif))->bss_info.dtim_period;
3431 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3434 priv->beacon_skb = NULL;
3437 static int __devinit mwl8k_probe(struct pci_dev *pdev,
3438 const struct pci_device_id *id)
3440 struct ieee80211_hw *hw;
3441 struct mwl8k_priv *priv;
3446 rc = pci_enable_device(pdev);
3448 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3453 rc = pci_request_regions(pdev, MWL8K_NAME);
3455 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3460 pci_set_master(pdev);
3462 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3464 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3472 priv->hostcmd_wait = NULL;
3473 priv->tx_wait = NULL;
3474 priv->inconfig = false;
3475 priv->wmm_mode = false;
3476 priv->pending_tx_pkts = 0;
3477 strncpy(priv->name, MWL8K_NAME, sizeof(priv->name));
3479 spin_lock_init(&priv->fw_lock);
3481 SET_IEEE80211_DEV(hw, &pdev->dev);
3482 pci_set_drvdata(pdev, hw);
3484 priv->regs = pci_iomap(pdev, 1, 0x10000);
3485 if (priv->regs == NULL) {
3486 printk(KERN_ERR "%s: Cannot map device memory\n", priv->name);
3490 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3491 priv->band.band = IEEE80211_BAND_2GHZ;
3492 priv->band.channels = priv->channels;
3493 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3494 priv->band.bitrates = priv->rates;
3495 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3496 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3498 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3499 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3502 * Extra headroom is the size of the required DMA header
3503 * minus the size of the smallest 802.11 frame (CTS frame).
3505 hw->extra_tx_headroom =
3506 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3508 hw->channel_change_time = 10;
3510 hw->queues = MWL8K_TX_QUEUES;
3512 hw->wiphy->interface_modes =
3513 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_MONITOR);
3515 /* Set rssi and noise values to dBm */
3516 hw->flags |= (IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM);
3517 hw->vif_data_size = sizeof(struct mwl8k_vif);
3520 /* Set default radio state and preamble */
3521 priv->radio_preamble = MWL8K_RADIO_DEFAULT_PREAMBLE;
3522 priv->radio_state = MWL8K_RADIO_DISABLE;
3524 /* Finalize join worker */
3525 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3527 /* TX reclaim tasklet */
3528 tasklet_init(&priv->tx_reclaim_task,
3529 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3530 tasklet_disable(&priv->tx_reclaim_task);
3532 /* Config workthread */
3533 priv->config_wq = create_singlethread_workqueue("mwl8k_config");
3534 if (priv->config_wq == NULL)
3537 /* Power management cookie */
3538 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3539 if (priv->cookie == NULL)
3542 rc = mwl8k_rxq_init(hw, 0);
3545 rxq_refill(hw, 0, INT_MAX);
3547 spin_lock_init(&priv->tx_lock);
3549 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3550 rc = mwl8k_txq_init(hw, i);
3552 goto err_free_queues;
3555 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3556 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3557 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3558 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3560 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
3561 IRQF_SHARED, MWL8K_NAME, hw);
3563 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3565 goto err_free_queues;
3568 /* Reset firmware and hardware */
3569 mwl8k_hw_reset(priv);
3571 /* Ask userland hotplug daemon for the device firmware */
3572 rc = mwl8k_request_firmware(priv, (u32)id->driver_data);
3574 printk(KERN_ERR "%s: Firmware files not found\n", priv->name);
3578 /* Load firmware into hardware */
3579 rc = mwl8k_load_firmware(priv);
3581 printk(KERN_ERR "%s: Cannot start firmware\n", priv->name);
3582 goto err_stop_firmware;
3585 /* Reclaim memory once firmware is successfully loaded */
3586 mwl8k_release_firmware(priv);
3589 * Temporarily enable interrupts. Initial firmware host
3590 * commands use interrupts and avoids polling. Disable
3591 * interrupts when done.
3593 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3595 /* Get config data, mac addrs etc */
3596 rc = mwl8k_cmd_get_hw_spec(hw);
3598 printk(KERN_ERR "%s: Cannot initialise firmware\n", priv->name);
3599 goto err_stop_firmware;
3602 /* Turn radio off */
3603 rc = mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
3605 printk(KERN_ERR "%s: Cannot disable\n", priv->name);
3606 goto err_stop_firmware;
3609 /* Disable interrupts */
3610 spin_lock_irq(&priv->tx_lock);
3611 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3612 spin_unlock_irq(&priv->tx_lock);
3613 free_irq(priv->pdev->irq, hw);
3615 rc = ieee80211_register_hw(hw);
3617 printk(KERN_ERR "%s: Cannot register device\n", priv->name);
3618 goto err_stop_firmware;
3621 fw = (u8 *)&priv->fw_rev;
3622 printk(KERN_INFO "%s: 88W%u %s\n", priv->name, priv->part_num,
3624 printk(KERN_INFO "%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
3625 priv->name, MWL8K_VERSION, fw[3], fw[2], fw[1], fw[0]);
3626 printk(KERN_INFO "%s: MAC Address: %pM\n", priv->name,
3627 hw->wiphy->perm_addr);
3632 mwl8k_hw_reset(priv);
3633 mwl8k_release_firmware(priv);
3636 spin_lock_irq(&priv->tx_lock);
3637 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3638 spin_unlock_irq(&priv->tx_lock);
3639 free_irq(priv->pdev->irq, hw);
3642 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3643 mwl8k_txq_deinit(hw, i);
3644 mwl8k_rxq_deinit(hw, 0);
3647 if (priv->cookie != NULL)
3648 pci_free_consistent(priv->pdev, 4,
3649 priv->cookie, priv->cookie_dma);
3651 if (priv->regs != NULL)
3652 pci_iounmap(pdev, priv->regs);
3654 if (priv->config_wq != NULL)
3655 destroy_workqueue(priv->config_wq);
3657 pci_set_drvdata(pdev, NULL);
3658 ieee80211_free_hw(hw);
3661 pci_release_regions(pdev);
3662 pci_disable_device(pdev);
3667 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
3669 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3672 static void __devexit mwl8k_remove(struct pci_dev *pdev)
3674 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3675 struct mwl8k_priv *priv;
3682 ieee80211_stop_queues(hw);
3684 ieee80211_unregister_hw(hw);
3686 /* Remove tx reclaim tasklet */
3687 tasklet_kill(&priv->tx_reclaim_task);
3689 /* Stop config thread */
3690 destroy_workqueue(priv->config_wq);
3693 mwl8k_hw_reset(priv);
3695 /* Return all skbs to mac80211 */
3696 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3697 mwl8k_txq_reclaim(hw, i, 1);
3699 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3700 mwl8k_txq_deinit(hw, i);
3702 mwl8k_rxq_deinit(hw, 0);
3704 pci_free_consistent(priv->pdev, 4,
3705 priv->cookie, priv->cookie_dma);
3707 pci_iounmap(pdev, priv->regs);
3708 pci_set_drvdata(pdev, NULL);
3709 ieee80211_free_hw(hw);
3710 pci_release_regions(pdev);
3711 pci_disable_device(pdev);
3714 static struct pci_driver mwl8k_driver = {
3716 .id_table = mwl8k_table,
3717 .probe = mwl8k_probe,
3718 .remove = __devexit_p(mwl8k_remove),
3719 .shutdown = __devexit_p(mwl8k_shutdown),
3722 static int __init mwl8k_init(void)
3724 return pci_register_driver(&mwl8k_driver);
3727 static void __exit mwl8k_exit(void)
3729 pci_unregister_driver(&mwl8k_driver);
3732 module_init(mwl8k_init);
3733 module_exit(mwl8k_exit);