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];
190 bool radio_short_preamble;
193 /* Set if PHY config is in progress */
196 /* XXX need to convert this to handle multiple interfaces */
198 u8 capture_bssid[ETH_ALEN];
199 struct sk_buff *beacon_skb;
202 * This FJ worker has to be global as it is scheduled from the
203 * RX handler. At this point we don't know which interface it
204 * belongs to until the list of bssids waiting to complete join
207 struct work_struct finalize_join_worker;
209 /* Tasklet to reclaim TX descriptors and buffers after tx */
210 struct tasklet_struct tx_reclaim_task;
212 /* Work thread to serialize configuration requests */
213 struct workqueue_struct *config_wq;
214 struct completion *hostcmd_wait;
215 struct completion *tx_wait;
218 /* Per interface specific private data */
220 /* backpointer to parent config block */
221 struct mwl8k_priv *priv;
223 /* BSS config of AP or IBSS from mac80211*/
224 struct ieee80211_bss_conf bss_info;
226 /* BSSID of AP or IBSS */
228 u8 mac_addr[ETH_ALEN];
231 * Subset of supported legacy rates.
232 * Intersection of AP and STA supported rates.
234 struct ieee80211_rate legacy_rates[12];
236 /* number of supported legacy rates */
239 /* Index into station database.Returned by update_sta_db call */
242 /* Non AMPDU sequence number assigned by driver */
246 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
248 static const struct ieee80211_channel mwl8k_channels[] = {
249 { .center_freq = 2412, .hw_value = 1, },
250 { .center_freq = 2417, .hw_value = 2, },
251 { .center_freq = 2422, .hw_value = 3, },
252 { .center_freq = 2427, .hw_value = 4, },
253 { .center_freq = 2432, .hw_value = 5, },
254 { .center_freq = 2437, .hw_value = 6, },
255 { .center_freq = 2442, .hw_value = 7, },
256 { .center_freq = 2447, .hw_value = 8, },
257 { .center_freq = 2452, .hw_value = 9, },
258 { .center_freq = 2457, .hw_value = 10, },
259 { .center_freq = 2462, .hw_value = 11, },
262 static const struct ieee80211_rate mwl8k_rates[] = {
263 { .bitrate = 10, .hw_value = 2, },
264 { .bitrate = 20, .hw_value = 4, },
265 { .bitrate = 55, .hw_value = 11, },
266 { .bitrate = 60, .hw_value = 12, },
267 { .bitrate = 90, .hw_value = 18, },
268 { .bitrate = 110, .hw_value = 22, },
269 { .bitrate = 120, .hw_value = 24, },
270 { .bitrate = 180, .hw_value = 36, },
271 { .bitrate = 240, .hw_value = 48, },
272 { .bitrate = 360, .hw_value = 72, },
273 { .bitrate = 480, .hw_value = 96, },
274 { .bitrate = 540, .hw_value = 108, },
277 /* Set or get info from Firmware */
278 #define MWL8K_CMD_SET 0x0001
279 #define MWL8K_CMD_GET 0x0000
281 /* Firmware command codes */
282 #define MWL8K_CMD_CODE_DNLD 0x0001
283 #define MWL8K_CMD_GET_HW_SPEC 0x0003
284 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
285 #define MWL8K_CMD_GET_STAT 0x0014
286 #define MWL8K_CMD_RADIO_CONTROL 0x001c
287 #define MWL8K_CMD_RF_TX_POWER 0x001e
288 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
289 #define MWL8K_CMD_SET_POST_SCAN 0x0108
290 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
291 #define MWL8K_CMD_SET_AID 0x010d
292 #define MWL8K_CMD_SET_RATE 0x0110
293 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
294 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
295 #define MWL8K_CMD_SET_SLOT 0x0114
296 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
297 #define MWL8K_CMD_SET_WMM_MODE 0x0123
298 #define MWL8K_CMD_MIMO_CONFIG 0x0125
299 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
300 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
301 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
302 #define MWL8K_CMD_UPDATE_STADB 0x1123
304 static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
306 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
307 snprintf(buf, bufsize, "%s", #x);\
310 switch (cmd & ~0x8000) {
311 MWL8K_CMDNAME(CODE_DNLD);
312 MWL8K_CMDNAME(GET_HW_SPEC);
313 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
314 MWL8K_CMDNAME(GET_STAT);
315 MWL8K_CMDNAME(RADIO_CONTROL);
316 MWL8K_CMDNAME(RF_TX_POWER);
317 MWL8K_CMDNAME(SET_PRE_SCAN);
318 MWL8K_CMDNAME(SET_POST_SCAN);
319 MWL8K_CMDNAME(SET_RF_CHANNEL);
320 MWL8K_CMDNAME(SET_AID);
321 MWL8K_CMDNAME(SET_RATE);
322 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
323 MWL8K_CMDNAME(RTS_THRESHOLD);
324 MWL8K_CMDNAME(SET_SLOT);
325 MWL8K_CMDNAME(SET_EDCA_PARAMS);
326 MWL8K_CMDNAME(SET_WMM_MODE);
327 MWL8K_CMDNAME(MIMO_CONFIG);
328 MWL8K_CMDNAME(USE_FIXED_RATE);
329 MWL8K_CMDNAME(ENABLE_SNIFFER);
330 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
331 MWL8K_CMDNAME(UPDATE_STADB);
333 snprintf(buf, bufsize, "0x%x", cmd);
340 /* Hardware and firmware reset */
341 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
343 iowrite32(MWL8K_H2A_INT_RESET,
344 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
345 iowrite32(MWL8K_H2A_INT_RESET,
346 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
350 /* Release fw image */
351 static void mwl8k_release_fw(struct firmware **fw)
355 release_firmware(*fw);
359 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
361 mwl8k_release_fw(&priv->fw.ucode);
362 mwl8k_release_fw(&priv->fw.helper);
365 /* Request fw image */
366 static int mwl8k_request_fw(struct mwl8k_priv *priv,
367 const char *fname, struct firmware **fw)
369 /* release current image */
371 mwl8k_release_fw(fw);
373 return request_firmware((const struct firmware **)fw,
374 fname, &priv->pdev->dev);
377 static int mwl8k_request_firmware(struct mwl8k_priv *priv, u32 part_num)
382 priv->part_num = part_num;
384 snprintf(filename, sizeof(filename),
385 "mwl8k/helper_%u.fw", priv->part_num);
387 rc = mwl8k_request_fw(priv, filename, &priv->fw.helper);
390 "%s Error requesting helper firmware file %s\n",
391 pci_name(priv->pdev), filename);
395 snprintf(filename, sizeof(filename),
396 "mwl8k/fmimage_%u.fw", priv->part_num);
398 rc = mwl8k_request_fw(priv, filename, &priv->fw.ucode);
400 printk(KERN_ERR "%s Error requesting firmware file %s\n",
401 pci_name(priv->pdev), filename);
402 mwl8k_release_fw(&priv->fw.helper);
409 struct mwl8k_cmd_pkt {
415 } __attribute__((packed));
421 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
423 void __iomem *regs = priv->regs;
428 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
429 if (pci_dma_mapping_error(priv->pdev, dma_addr))
432 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
433 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
434 iowrite32(MWL8K_H2A_INT_DOORBELL,
435 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
436 iowrite32(MWL8K_H2A_INT_DUMMY,
437 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
444 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
445 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
446 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
454 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
457 * Clear 'command done' interrupt bit.
463 status = ioread32(priv->regs +
464 MWL8K_HIU_A2H_INTERRUPT_STATUS);
465 if (status & MWL8K_A2H_INT_OPC_DONE) {
466 iowrite32(~MWL8K_A2H_INT_OPC_DONE,
467 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
468 ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
478 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
479 const u8 *data, size_t length)
481 struct mwl8k_cmd_pkt *cmd;
485 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
489 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
495 int block_size = length > 256 ? 256 : length;
497 memcpy(cmd->payload, data + done, block_size);
498 cmd->length = cpu_to_le16(block_size);
500 rc = mwl8k_send_fw_load_cmd(priv, cmd,
501 sizeof(*cmd) + block_size);
506 length -= block_size;
511 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
519 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
520 const u8 *data, size_t length)
522 unsigned char *buffer;
523 int may_continue, rc = 0;
524 u32 done, prev_block_size;
526 buffer = kmalloc(1024, GFP_KERNEL);
533 while (may_continue > 0) {
536 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
537 if (block_size & 1) {
541 done += prev_block_size;
542 length -= prev_block_size;
545 if (block_size > 1024 || block_size > length) {
555 if (block_size == 0) {
562 prev_block_size = block_size;
563 memcpy(buffer, data + done, block_size);
565 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
570 if (!rc && length != 0)
578 static int mwl8k_load_firmware(struct mwl8k_priv *priv)
582 const u8 *ucode = priv->fw.ucode->data;
583 size_t ucode_len = priv->fw.ucode->size;
584 const u8 *helper = priv->fw.helper->data;
585 size_t helper_len = priv->fw.helper->size;
587 if (!memcmp(ucode, "\x01\x00\x00\x00", 4)) {
588 rc = mwl8k_load_fw_image(priv, helper, helper_len);
590 printk(KERN_ERR "%s: unable to load firmware "
591 "helper image\n", pci_name(priv->pdev));
596 rc = mwl8k_feed_fw_image(priv, ucode, ucode_len);
598 rc = mwl8k_load_fw_image(priv, ucode, ucode_len);
602 printk(KERN_ERR "%s: unable to load firmware data\n",
603 pci_name(priv->pdev));
607 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
612 if (ioread32(priv->regs + MWL8K_HIU_INT_CODE)
613 == MWL8K_FWSTA_READY)
618 return loops ? 0 : -ETIMEDOUT;
623 * Defines shared between transmission and reception.
625 /* HT control fields for firmware */
630 } __attribute__((packed));
632 /* Firmware Station database operations */
633 #define MWL8K_STA_DB_ADD_ENTRY 0
634 #define MWL8K_STA_DB_MODIFY_ENTRY 1
635 #define MWL8K_STA_DB_DEL_ENTRY 2
636 #define MWL8K_STA_DB_FLUSH 3
638 /* Peer Entry flags - used to define the type of the peer node */
639 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
641 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
642 #define MWL8K_MCS_BITMAP_SIZE 16
644 struct peer_capability_info {
645 /* Peer type - AP vs. STA. */
648 /* Basic 802.11 capabilities from assoc resp. */
651 /* Set if peer supports 802.11n high throughput (HT). */
654 /* Valid if HT is supported. */
656 __u8 extended_ht_caps;
657 struct ewc_ht_info ewc_info;
659 /* Legacy rate table. Intersection of our rates and peer rates. */
660 __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
662 /* HT rate table. Intersection of our rates and peer rates. */
663 __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
666 /* If set, interoperability mode, no proprietary extensions. */
670 __le16 amsdu_enabled;
671 } __attribute__((packed));
673 /* Inline functions to manipulate QoS field in data descriptor. */
674 static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
676 u16 val_mask = 1 << 4;
678 /* End of Service Period Bit 4 */
679 return qos | val_mask;
682 static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
686 u16 qos_mask = ~(val_mask << shift);
688 /* Ack Policy Bit 5-6 */
689 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
692 static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
694 u16 val_mask = 1 << 7;
696 /* AMSDU present Bit 7 */
697 return qos | val_mask;
700 static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
704 u16 qos_mask = ~(val_mask << shift);
706 /* Queue Length Bits 8-15 */
707 return (qos & qos_mask) | ((len & val_mask) << shift);
710 /* DMA header used by firmware and hardware. */
711 struct mwl8k_dma_data {
713 struct ieee80211_hdr wh;
714 } __attribute__((packed));
716 /* Routines to add/remove DMA header from skb. */
717 static inline int mwl8k_remove_dma_header(struct sk_buff *skb)
719 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)(skb->data);
720 void *dst, *src = &tr->wh;
721 __le16 fc = tr->wh.frame_control;
722 int hdrlen = ieee80211_hdrlen(fc);
723 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
725 dst = (void *)tr + space;
727 memmove(dst, src, hdrlen);
728 skb_pull(skb, space);
734 static inline struct sk_buff *mwl8k_add_dma_header(struct sk_buff *skb)
736 struct ieee80211_hdr *wh;
738 struct mwl8k_dma_data *tr;
740 wh = (struct ieee80211_hdr *)skb->data;
741 hdrlen = ieee80211_hdrlen(wh->frame_control);
745 * Copy up/down the 802.11 header; the firmware requires
746 * we present a 2-byte payload length followed by a
747 * 4-address header (w/o QoS), followed (optionally) by
748 * any WEP/ExtIV header (but only filled in for CCMP).
750 if (hdrlen != sizeof(struct mwl8k_dma_data))
751 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
753 tr = (struct mwl8k_dma_data *)skb->data;
755 memmove(&tr->wh, wh, hdrlen);
758 memset(tr->wh.addr4, 0, ETH_ALEN);
761 * Firmware length is the length of the fully formed "802.11
762 * payload". That is, everything except for the 802.11 header.
763 * This includes all crypto material including the MIC.
765 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
774 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
776 struct mwl8k_rx_desc {
780 __le32 pkt_phys_addr;
781 __le32 next_rx_desc_phys_addr;
791 } __attribute__((packed));
793 #define MWL8K_RX_DESCS 256
794 #define MWL8K_RX_MAXSZ 3800
796 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
798 struct mwl8k_priv *priv = hw->priv;
799 struct mwl8k_rx_queue *rxq = priv->rxq + index;
803 rxq->rx_desc_count = 0;
807 size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc);
810 pci_alloc_consistent(priv->pdev, size, &rxq->rx_desc_dma);
811 if (rxq->rx_desc_area == NULL) {
812 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
816 memset(rxq->rx_desc_area, 0, size);
818 rxq->rx_skb = kmalloc(MWL8K_RX_DESCS *
819 sizeof(*rxq->rx_skb), GFP_KERNEL);
820 if (rxq->rx_skb == NULL) {
821 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
823 pci_free_consistent(priv->pdev, size,
824 rxq->rx_desc_area, rxq->rx_desc_dma);
827 memset(rxq->rx_skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->rx_skb));
829 for (i = 0; i < MWL8K_RX_DESCS; i++) {
830 struct mwl8k_rx_desc *rx_desc;
833 rx_desc = rxq->rx_desc_area + i;
834 nexti = (i + 1) % MWL8K_RX_DESCS;
836 rx_desc->next_rx_desc_phys_addr =
837 cpu_to_le32(rxq->rx_desc_dma
838 + nexti * sizeof(*rx_desc));
839 rx_desc->rx_ctrl = MWL8K_RX_CTRL_OWNED_BY_HOST;
845 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
847 struct mwl8k_priv *priv = hw->priv;
848 struct mwl8k_rx_queue *rxq = priv->rxq + index;
852 while (rxq->rx_desc_count < MWL8K_RX_DESCS && limit--) {
856 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
860 rxq->rx_desc_count++;
863 rxq->rx_tail = (rx + 1) % MWL8K_RX_DESCS;
865 rxq->rx_desc_area[rx].pkt_phys_addr =
866 cpu_to_le32(pci_map_single(priv->pdev, skb->data,
867 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE));
869 rxq->rx_desc_area[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ);
870 rxq->rx_skb[rx] = skb;
872 rxq->rx_desc_area[rx].rx_ctrl = 0;
880 /* Must be called only when the card's reception is completely halted */
881 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
883 struct mwl8k_priv *priv = hw->priv;
884 struct mwl8k_rx_queue *rxq = priv->rxq + index;
887 for (i = 0; i < MWL8K_RX_DESCS; i++) {
888 if (rxq->rx_skb[i] != NULL) {
891 addr = le32_to_cpu(rxq->rx_desc_area[i].pkt_phys_addr);
892 pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ,
894 kfree_skb(rxq->rx_skb[i]);
895 rxq->rx_skb[i] = NULL;
902 pci_free_consistent(priv->pdev,
903 MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc),
904 rxq->rx_desc_area, rxq->rx_desc_dma);
905 rxq->rx_desc_area = NULL;
910 * Scan a list of BSSIDs to process for finalize join.
911 * Allows for extension to process multiple BSSIDs.
914 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
916 return priv->capture_beacon &&
917 ieee80211_is_beacon(wh->frame_control) &&
918 !compare_ether_addr(wh->addr3, priv->capture_bssid);
921 static inline void mwl8k_save_beacon(struct mwl8k_priv *priv,
924 priv->capture_beacon = false;
925 memset(priv->capture_bssid, 0, ETH_ALEN);
928 * Use GFP_ATOMIC as rxq_process is called from
929 * the primary interrupt handler, memory allocation call
932 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
933 if (priv->beacon_skb != NULL)
934 queue_work(priv->config_wq,
935 &priv->finalize_join_worker);
938 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
940 struct mwl8k_priv *priv = hw->priv;
941 struct mwl8k_rx_queue *rxq = priv->rxq + index;
945 while (rxq->rx_desc_count && limit--) {
946 struct mwl8k_rx_desc *rx_desc;
948 struct ieee80211_rx_status status;
950 struct ieee80211_hdr *wh;
952 rx_desc = rxq->rx_desc_area + rxq->rx_head;
953 if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST))
957 skb = rxq->rx_skb[rxq->rx_head];
960 rxq->rx_skb[rxq->rx_head] = NULL;
962 rxq->rx_head = (rxq->rx_head + 1) % MWL8K_RX_DESCS;
963 rxq->rx_desc_count--;
965 addr = le32_to_cpu(rx_desc->pkt_phys_addr);
966 pci_unmap_single(priv->pdev, addr,
967 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
969 skb_put(skb, le16_to_cpu(rx_desc->pkt_len));
970 if (mwl8k_remove_dma_header(skb)) {
975 wh = (struct ieee80211_hdr *)skb->data;
978 * Check for pending join operation. save a copy of
979 * the beacon and schedule a tasklet to send finalize
980 * join command to the firmware.
982 if (mwl8k_capture_bssid(priv, wh))
983 mwl8k_save_beacon(priv, skb);
985 memset(&status, 0, sizeof(status));
987 status.signal = -rx_desc->rssi;
988 status.noise = -rx_desc->noise_level;
989 status.qual = rx_desc->link_quality;
993 status.band = IEEE80211_BAND_2GHZ;
994 status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
995 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
996 ieee80211_rx_irqsafe(hw, skb);
1006 * Packet transmission.
1009 /* Transmit queue assignment. */
1011 MWL8K_WME_AC_BK = 0, /* background access */
1012 MWL8K_WME_AC_BE = 1, /* best effort access */
1013 MWL8K_WME_AC_VI = 2, /* video access */
1014 MWL8K_WME_AC_VO = 3, /* voice access */
1017 /* Transmit packet ACK policy */
1018 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
1019 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1021 #define GET_TXQ(_ac) (\
1022 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
1023 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
1024 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
1027 #define MWL8K_TXD_STATUS_OK 0x00000001
1028 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1029 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1030 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1031 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1033 struct mwl8k_tx_desc {
1038 __le32 pkt_phys_addr;
1040 __u8 dest_MAC_addr[ETH_ALEN];
1041 __le32 next_tx_desc_phys_addr;
1046 } __attribute__((packed));
1048 #define MWL8K_TX_DESCS 128
1050 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1052 struct mwl8k_priv *priv = hw->priv;
1053 struct mwl8k_tx_queue *txq = priv->txq + index;
1057 memset(&txq->tx_stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1058 txq->tx_stats.limit = MWL8K_TX_DESCS;
1062 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1065 pci_alloc_consistent(priv->pdev, size, &txq->tx_desc_dma);
1066 if (txq->tx_desc_area == NULL) {
1067 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1071 memset(txq->tx_desc_area, 0, size);
1073 txq->tx_skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->tx_skb),
1075 if (txq->tx_skb == NULL) {
1076 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1078 pci_free_consistent(priv->pdev, size,
1079 txq->tx_desc_area, txq->tx_desc_dma);
1082 memset(txq->tx_skb, 0, MWL8K_TX_DESCS * sizeof(*txq->tx_skb));
1084 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1085 struct mwl8k_tx_desc *tx_desc;
1088 tx_desc = txq->tx_desc_area + i;
1089 nexti = (i + 1) % MWL8K_TX_DESCS;
1091 tx_desc->status = 0;
1092 tx_desc->next_tx_desc_phys_addr =
1093 cpu_to_le32(txq->tx_desc_dma +
1094 nexti * sizeof(*tx_desc));
1100 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1102 iowrite32(MWL8K_H2A_INT_PPA_READY,
1103 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1104 iowrite32(MWL8K_H2A_INT_DUMMY,
1105 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1106 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1109 static inline int mwl8k_txq_busy(struct mwl8k_priv *priv)
1111 return priv->pending_tx_pkts;
1114 struct mwl8k_txq_info {
1123 static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
1124 struct mwl8k_txq_info txinfo[],
1127 int count, desc, status;
1128 struct mwl8k_tx_queue *txq;
1129 struct mwl8k_tx_desc *tx_desc;
1132 memset(txinfo, 0, num_queues * sizeof(struct mwl8k_txq_info));
1133 spin_lock_bh(&priv->tx_lock);
1134 for (count = 0; count < num_queues; count++) {
1135 txq = priv->txq + count;
1136 txinfo[count].len = txq->tx_stats.len;
1137 txinfo[count].head = txq->tx_head;
1138 txinfo[count].tail = txq->tx_tail;
1139 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1140 tx_desc = txq->tx_desc_area + desc;
1141 status = le32_to_cpu(tx_desc->status);
1143 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1144 txinfo[count].fw_owned++;
1146 txinfo[count].drv_owned++;
1148 if (tx_desc->pkt_len == 0)
1149 txinfo[count].unused++;
1152 spin_unlock_bh(&priv->tx_lock);
1157 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw, u32 delay_ms)
1159 struct mwl8k_priv *priv = hw->priv;
1160 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1162 unsigned long timeout;
1166 if (priv->tx_wait != NULL)
1167 printk(KERN_ERR "WARNING Previous TXWaitEmpty instance\n");
1169 spin_lock_bh(&priv->tx_lock);
1170 count = mwl8k_txq_busy(priv);
1172 priv->tx_wait = &cmd_wait;
1174 mwl8k_tx_start(priv);
1176 spin_unlock_bh(&priv->tx_lock);
1179 struct mwl8k_txq_info txinfo[4];
1183 timeout = wait_for_completion_timeout(&cmd_wait,
1184 msecs_to_jiffies(delay_ms));
1188 spin_lock_bh(&priv->tx_lock);
1189 priv->tx_wait = NULL;
1190 newcount = mwl8k_txq_busy(priv);
1191 spin_unlock_bh(&priv->tx_lock);
1193 printk(KERN_ERR "%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
1194 __func__, __LINE__, delay_ms, count, newcount);
1196 mwl8k_scan_tx_ring(priv, txinfo, 4);
1197 for (index = 0; index < 4; index++)
1199 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
1204 txinfo[index].fw_owned,
1205 txinfo[index].drv_owned,
1206 txinfo[index].unused);
1214 #define MWL8K_TXD_SUCCESS(status) \
1215 ((status) & (MWL8K_TXD_STATUS_OK | \
1216 MWL8K_TXD_STATUS_OK_RETRY | \
1217 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1219 static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1221 struct mwl8k_priv *priv = hw->priv;
1222 struct mwl8k_tx_queue *txq = priv->txq + index;
1225 while (txq->tx_stats.len > 0) {
1228 struct mwl8k_tx_desc *tx_desc;
1231 struct sk_buff *skb;
1232 struct ieee80211_tx_info *info;
1237 tx_desc = txq->tx_desc_area + tx;
1239 status = le32_to_cpu(tx_desc->status);
1241 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1245 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1248 txq->tx_head = (tx + 1) % MWL8K_TX_DESCS;
1249 BUG_ON(txq->tx_stats.len == 0);
1250 txq->tx_stats.len--;
1251 priv->pending_tx_pkts--;
1253 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1254 size = le16_to_cpu(tx_desc->pkt_len);
1255 skb = txq->tx_skb[tx].skb;
1256 txq->tx_skb[tx].skb = NULL;
1258 BUG_ON(skb == NULL);
1259 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1261 rc = mwl8k_remove_dma_header(skb);
1263 /* Mark descriptor as unused */
1264 tx_desc->pkt_phys_addr = 0;
1265 tx_desc->pkt_len = 0;
1267 if (txq->tx_skb[tx].clone) {
1268 /* Replace with original skb
1269 * before returning to stack
1270 * as buffer has been cloned
1273 skb = txq->tx_skb[tx].clone;
1274 txq->tx_skb[tx].clone = NULL;
1278 /* Something has gone wrong here.
1279 * Failed to remove DMA header.
1280 * Print error message and drop packet.
1282 printk(KERN_ERR "%s: Error removing DMA header from "
1283 "tx skb 0x%p.\n", priv->name, skb);
1289 info = IEEE80211_SKB_CB(skb);
1290 ieee80211_tx_info_clear_status(info);
1291 if (MWL8K_TXD_SUCCESS(status))
1292 info->flags |= IEEE80211_TX_STAT_ACK;
1294 ieee80211_tx_status_irqsafe(hw, skb);
1296 wake = !priv->inconfig && priv->radio_on;
1300 ieee80211_wake_queue(hw, index);
1303 /* must be called only when the card's transmit is completely halted */
1304 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1306 struct mwl8k_priv *priv = hw->priv;
1307 struct mwl8k_tx_queue *txq = priv->txq + index;
1309 mwl8k_txq_reclaim(hw, index, 1);
1314 pci_free_consistent(priv->pdev,
1315 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1316 txq->tx_desc_area, txq->tx_desc_dma);
1317 txq->tx_desc_area = NULL;
1321 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1323 struct mwl8k_priv *priv = hw->priv;
1324 struct ieee80211_tx_info *tx_info;
1325 struct ieee80211_hdr *wh;
1326 struct mwl8k_tx_queue *txq;
1327 struct mwl8k_tx_desc *tx;
1328 struct mwl8k_dma_data *tr;
1329 struct mwl8k_vif *mwl8k_vif;
1330 struct sk_buff *org_skb = skb;
1333 bool qosframe = false, ampduframe = false;
1334 bool mcframe = false, eapolframe = false;
1335 bool amsduframe = false;
1338 txq = priv->txq + index;
1339 tx = txq->tx_desc_area + txq->tx_tail;
1341 BUG_ON(txq->tx_skb[txq->tx_tail].skb != NULL);
1344 * Append HW DMA header to start of packet. Drop packet if
1345 * there is not enough space or a failure to unshare/unclone
1348 skb = mwl8k_add_dma_header(skb);
1351 printk(KERN_DEBUG "%s: failed to prepend HW DMA "
1352 "header, dropping TX frame.\n", priv->name);
1353 dev_kfree_skb(org_skb);
1354 return NETDEV_TX_OK;
1357 tx_info = IEEE80211_SKB_CB(skb);
1358 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1359 tr = (struct mwl8k_dma_data *)skb->data;
1361 fc = wh->frame_control;
1362 qosframe = ieee80211_is_data_qos(fc);
1363 mcframe = is_multicast_ether_addr(wh->addr1);
1364 ampduframe = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
1366 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1367 u16 seqno = mwl8k_vif->seqno;
1368 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1369 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1370 mwl8k_vif->seqno = seqno++ % 4096;
1374 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1376 dma = pci_map_single(priv->pdev, skb->data,
1377 skb->len, PCI_DMA_TODEVICE);
1379 if (pci_dma_mapping_error(priv->pdev, dma)) {
1380 printk(KERN_DEBUG "%s: failed to dma map skb, "
1381 "dropping TX frame.\n", priv->name);
1383 if (org_skb != NULL)
1384 dev_kfree_skb(org_skb);
1387 return NETDEV_TX_OK;
1390 /* Set desc header, cpu bit order. */
1393 tx->tx_priority = index;
1394 tx->qos_control = 0;
1396 tx->peer_id = mwl8k_vif->peer_id;
1398 amsduframe = !!(qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT);
1400 /* Setup firmware control bit fields for each frame type. */
1401 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) {
1403 qos = mwl8k_qos_setbit_eosp(qos);
1404 /* Set Queue size to unspecified */
1405 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1406 } else if (ieee80211_is_data(fc)) {
1409 tx->status |= MWL8K_TXD_STATUS_MULTICAST_TX;
1412 * Tell firmware to not send EAPOL pkts in an
1413 * aggregate. Verify against mac80211 tx path. If
1414 * stack turns off AMPDU for an EAPOL frame this
1415 * check will be removed.
1418 qos = mwl8k_qos_setbit_ack(qos,
1419 MWL8K_TXD_ACK_POLICY_NORMAL);
1421 /* Send pkt in an aggregate if AMPDU frame. */
1423 qos = mwl8k_qos_setbit_ack(qos,
1424 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1426 qos = mwl8k_qos_setbit_ack(qos,
1427 MWL8K_TXD_ACK_POLICY_NORMAL);
1430 qos = mwl8k_qos_setbit_amsdu(qos);
1434 /* Convert to little endian */
1435 tx->qos_control = cpu_to_le16(qos);
1436 tx->status = cpu_to_le32(tx->status);
1437 tx->pkt_phys_addr = cpu_to_le32(dma);
1438 tx->pkt_len = cpu_to_le16(skb->len);
1440 txq->tx_skb[txq->tx_tail].skb = skb;
1441 txq->tx_skb[txq->tx_tail].clone =
1442 skb == org_skb ? NULL : org_skb;
1444 spin_lock_bh(&priv->tx_lock);
1446 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_OK |
1447 MWL8K_TXD_STATUS_FW_OWNED);
1449 txq->tx_stats.len++;
1450 priv->pending_tx_pkts++;
1451 txq->tx_stats.count++;
1454 if (txq->tx_tail == MWL8K_TX_DESCS)
1456 if (txq->tx_head == txq->tx_tail)
1457 ieee80211_stop_queue(hw, index);
1459 if (priv->inconfig) {
1461 * Silently queue packet when we are in the middle of
1462 * a config cycle. Notify firmware only if we are
1463 * waiting for TXQs to empty. If a packet is sent
1464 * before .config() is complete, perhaps it is better
1465 * to drop the packet, as the channel is being changed
1466 * and the packet will end up on the wrong channel.
1468 printk(KERN_ERR "%s(): WARNING TX activity while "
1469 "in config\n", __func__);
1471 if (priv->tx_wait != NULL)
1472 mwl8k_tx_start(priv);
1474 mwl8k_tx_start(priv);
1476 spin_unlock_bh(&priv->tx_lock);
1478 return NETDEV_TX_OK;
1483 * Command processing.
1486 /* Timeout firmware commands after 2000ms */
1487 #define MWL8K_CMD_TIMEOUT_MS 2000
1489 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1491 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1492 struct mwl8k_priv *priv = hw->priv;
1493 void __iomem *regs = priv->regs;
1494 dma_addr_t dma_addr;
1495 unsigned int dma_size;
1497 unsigned long timeout = 0;
1500 cmd->result = 0xFFFF;
1501 dma_size = le16_to_cpu(cmd->length);
1502 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1503 PCI_DMA_BIDIRECTIONAL);
1504 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1507 if (priv->hostcmd_wait != NULL)
1508 printk(KERN_ERR "WARNING host command in progress\n");
1510 spin_lock_irq(&priv->fw_lock);
1511 priv->hostcmd_wait = &cmd_wait;
1512 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1513 iowrite32(MWL8K_H2A_INT_DOORBELL,
1514 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1515 iowrite32(MWL8K_H2A_INT_DUMMY,
1516 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1517 spin_unlock_irq(&priv->fw_lock);
1519 timeout = wait_for_completion_timeout(&cmd_wait,
1520 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1522 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1523 PCI_DMA_BIDIRECTIONAL);
1526 spin_lock_irq(&priv->fw_lock);
1527 priv->hostcmd_wait = NULL;
1528 spin_unlock_irq(&priv->fw_lock);
1529 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1531 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1532 MWL8K_CMD_TIMEOUT_MS);
1535 rc = cmd->result ? -EINVAL : 0;
1537 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1539 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1549 struct mwl8k_cmd_get_hw_spec {
1550 struct mwl8k_cmd_pkt header;
1552 __u8 host_interface;
1554 __u8 perm_addr[ETH_ALEN];
1559 __u8 mcs_bitmap[16];
1560 __le32 rx_queue_ptr;
1561 __le32 num_tx_queues;
1562 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1564 __le32 num_tx_desc_per_queue;
1565 __le32 total_rx_desc;
1566 } __attribute__((packed));
1568 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
1570 struct mwl8k_priv *priv = hw->priv;
1571 struct mwl8k_cmd_get_hw_spec *cmd;
1575 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1579 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1580 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1582 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1583 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1584 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rx_desc_dma);
1585 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1586 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1587 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].tx_desc_dma);
1588 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1589 cmd->total_rx_desc = cpu_to_le32(MWL8K_RX_DESCS);
1591 rc = mwl8k_post_cmd(hw, &cmd->header);
1594 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1595 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1596 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1597 priv->hw_rev = cmd->hw_rev;
1605 * CMD_MAC_MULTICAST_ADR.
1607 struct mwl8k_cmd_mac_multicast_adr {
1608 struct mwl8k_cmd_pkt header;
1611 __u8 addr[0][ETH_ALEN];
1614 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
1616 static struct mwl8k_cmd_pkt *
1617 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
1618 int mc_count, struct dev_addr_list *mclist)
1620 struct mwl8k_priv *priv = hw->priv;
1621 struct mwl8k_cmd_mac_multicast_adr *cmd;
1625 if (mc_count > priv->num_mcaddrs)
1626 mc_count = priv->num_mcaddrs;
1628 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1630 cmd = kzalloc(size, GFP_ATOMIC);
1634 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1635 cmd->header.length = cpu_to_le16(size);
1636 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1637 cmd->numaddr = cpu_to_le16(mc_count);
1639 for (i = 0; i < mc_count && mclist; i++) {
1640 if (mclist->da_addrlen != ETH_ALEN) {
1644 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1645 mclist = mclist->next;
1648 return &cmd->header;
1652 * CMD_802_11_GET_STAT.
1654 struct mwl8k_cmd_802_11_get_stat {
1655 struct mwl8k_cmd_pkt header;
1658 } __attribute__((packed));
1660 #define MWL8K_STAT_ACK_FAILURE 9
1661 #define MWL8K_STAT_RTS_FAILURE 12
1662 #define MWL8K_STAT_FCS_ERROR 24
1663 #define MWL8K_STAT_RTS_SUCCESS 11
1665 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1666 struct ieee80211_low_level_stats *stats)
1668 struct mwl8k_cmd_802_11_get_stat *cmd;
1671 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1675 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1676 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1677 cmd->action = cpu_to_le16(MWL8K_CMD_GET);
1679 rc = mwl8k_post_cmd(hw, &cmd->header);
1681 stats->dot11ACKFailureCount =
1682 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1683 stats->dot11RTSFailureCount =
1684 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1685 stats->dot11FCSErrorCount =
1686 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1687 stats->dot11RTSSuccessCount =
1688 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1696 * CMD_802_11_RADIO_CONTROL.
1698 struct mwl8k_cmd_802_11_radio_control {
1699 struct mwl8k_cmd_pkt header;
1703 } __attribute__((packed));
1706 mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
1708 struct mwl8k_priv *priv = hw->priv;
1709 struct mwl8k_cmd_802_11_radio_control *cmd;
1712 if (enable == priv->radio_on && !force)
1715 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1719 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1720 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1721 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1722 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
1723 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1725 rc = mwl8k_post_cmd(hw, &cmd->header);
1729 priv->radio_on = enable;
1734 static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1736 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1739 static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1741 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1745 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1747 struct mwl8k_priv *priv;
1749 if (hw == NULL || hw->priv == NULL)
1753 priv->radio_short_preamble = short_preamble;
1755 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
1759 * CMD_802_11_RF_TX_POWER.
1761 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1763 struct mwl8k_cmd_802_11_rf_tx_power {
1764 struct mwl8k_cmd_pkt header;
1766 __le16 support_level;
1767 __le16 current_level;
1769 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1770 } __attribute__((packed));
1772 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1774 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1777 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1781 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1782 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1783 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1784 cmd->support_level = cpu_to_le16(dBm);
1786 rc = mwl8k_post_cmd(hw, &cmd->header);
1795 struct mwl8k_cmd_set_pre_scan {
1796 struct mwl8k_cmd_pkt header;
1797 } __attribute__((packed));
1799 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
1801 struct mwl8k_cmd_set_pre_scan *cmd;
1804 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1808 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
1809 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1811 rc = mwl8k_post_cmd(hw, &cmd->header);
1818 * CMD_SET_POST_SCAN.
1820 struct mwl8k_cmd_set_post_scan {
1821 struct mwl8k_cmd_pkt header;
1823 __u8 bssid[ETH_ALEN];
1824 } __attribute__((packed));
1827 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
1829 struct mwl8k_cmd_set_post_scan *cmd;
1832 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1836 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
1837 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1839 memcpy(cmd->bssid, mac, ETH_ALEN);
1841 rc = mwl8k_post_cmd(hw, &cmd->header);
1848 * CMD_SET_RF_CHANNEL.
1850 struct mwl8k_cmd_set_rf_channel {
1851 struct mwl8k_cmd_pkt header;
1853 __u8 current_channel;
1854 __le32 channel_flags;
1855 } __attribute__((packed));
1857 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
1858 struct ieee80211_channel *channel)
1860 struct mwl8k_cmd_set_rf_channel *cmd;
1863 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1867 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
1868 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1869 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1870 cmd->current_channel = channel->hw_value;
1871 if (channel->band == IEEE80211_BAND_2GHZ)
1872 cmd->channel_flags = cpu_to_le32(0x00000081);
1874 cmd->channel_flags = cpu_to_le32(0x00000000);
1876 rc = mwl8k_post_cmd(hw, &cmd->header);
1885 struct mwl8k_cmd_set_slot {
1886 struct mwl8k_cmd_pkt header;
1889 } __attribute__((packed));
1891 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
1893 struct mwl8k_cmd_set_slot *cmd;
1896 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1900 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
1901 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1902 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1903 cmd->short_slot = short_slot_time;
1905 rc = mwl8k_post_cmd(hw, &cmd->header);
1914 struct mwl8k_cmd_mimo_config {
1915 struct mwl8k_cmd_pkt header;
1917 __u8 rx_antenna_map;
1918 __u8 tx_antenna_map;
1919 } __attribute__((packed));
1921 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
1923 struct mwl8k_cmd_mimo_config *cmd;
1926 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1930 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
1931 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1932 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
1933 cmd->rx_antenna_map = rx;
1934 cmd->tx_antenna_map = tx;
1936 rc = mwl8k_post_cmd(hw, &cmd->header);
1943 * CMD_ENABLE_SNIFFER.
1945 struct mwl8k_cmd_enable_sniffer {
1946 struct mwl8k_cmd_pkt header;
1948 } __attribute__((packed));
1950 static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
1952 struct mwl8k_cmd_enable_sniffer *cmd;
1955 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1959 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
1960 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1961 cmd->action = cpu_to_le32(!!enable);
1963 rc = mwl8k_post_cmd(hw, &cmd->header);
1970 * CMD_SET_RATEADAPT_MODE.
1972 struct mwl8k_cmd_set_rate_adapt_mode {
1973 struct mwl8k_cmd_pkt header;
1976 } __attribute__((packed));
1978 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
1980 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
1983 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1987 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
1988 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1989 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1990 cmd->mode = cpu_to_le16(mode);
1992 rc = mwl8k_post_cmd(hw, &cmd->header);
2001 struct mwl8k_cmd_set_wmm {
2002 struct mwl8k_cmd_pkt header;
2004 } __attribute__((packed));
2006 static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2008 struct mwl8k_priv *priv = hw->priv;
2009 struct mwl8k_cmd_set_wmm *cmd;
2012 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2016 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2017 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2018 cmd->action = cpu_to_le16(!!enable);
2020 rc = mwl8k_post_cmd(hw, &cmd->header);
2024 priv->wmm_enabled = enable;
2030 * CMD_SET_RTS_THRESHOLD.
2032 struct mwl8k_cmd_rts_threshold {
2033 struct mwl8k_cmd_pkt header;
2036 } __attribute__((packed));
2038 static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
2039 u16 action, u16 *threshold)
2041 struct mwl8k_cmd_rts_threshold *cmd;
2044 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2048 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2049 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2050 cmd->action = cpu_to_le16(action);
2051 cmd->threshold = cpu_to_le16(*threshold);
2053 rc = mwl8k_post_cmd(hw, &cmd->header);
2060 * CMD_SET_EDCA_PARAMS.
2062 struct mwl8k_cmd_set_edca_params {
2063 struct mwl8k_cmd_pkt header;
2065 /* See MWL8K_SET_EDCA_XXX below */
2068 /* TX opportunity in units of 32 us */
2071 /* Log exponent of max contention period: 0...15*/
2074 /* Log exponent of min contention period: 0...15 */
2077 /* Adaptive interframe spacing in units of 32us */
2080 /* TX queue to configure */
2082 } __attribute__((packed));
2084 #define MWL8K_SET_EDCA_CW 0x01
2085 #define MWL8K_SET_EDCA_TXOP 0x02
2086 #define MWL8K_SET_EDCA_AIFS 0x04
2088 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2089 MWL8K_SET_EDCA_TXOP | \
2090 MWL8K_SET_EDCA_AIFS)
2093 mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2094 __u16 cw_min, __u16 cw_max,
2095 __u8 aifs, __u16 txop)
2097 struct mwl8k_cmd_set_edca_params *cmd;
2100 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2104 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2105 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2106 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2107 cmd->txop = cpu_to_le16(txop);
2108 cmd->log_cw_max = (u8)ilog2(cw_max + 1);
2109 cmd->log_cw_min = (u8)ilog2(cw_min + 1);
2113 rc = mwl8k_post_cmd(hw, &cmd->header);
2120 * CMD_FINALIZE_JOIN.
2123 /* FJ beacon buffer size is compiled into the firmware. */
2124 #define MWL8K_FJ_BEACON_MAXLEN 128
2126 struct mwl8k_cmd_finalize_join {
2127 struct mwl8k_cmd_pkt header;
2128 __le32 sleep_interval; /* Number of beacon periods to sleep */
2129 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2130 } __attribute__((packed));
2132 static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2133 __u16 framelen, __u16 dtim)
2135 struct mwl8k_cmd_finalize_join *cmd;
2136 struct ieee80211_mgmt *payload = frame;
2144 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2148 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2149 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2150 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2152 hdrlen = ieee80211_hdrlen(payload->frame_control);
2154 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2156 /* XXX TBD Might just have to abort and return an error */
2157 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2158 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
2159 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2160 payload_len, MWL8K_FJ_BEACON_MAXLEN);
2162 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2163 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2165 if (payload && payload_len)
2166 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2168 rc = mwl8k_post_cmd(hw, &cmd->header);
2176 struct mwl8k_cmd_update_sta_db {
2177 struct mwl8k_cmd_pkt header;
2179 /* See STADB_ACTION_TYPE */
2182 /* Peer MAC address */
2183 __u8 peer_addr[ETH_ALEN];
2187 /* Peer info - valid during add/update. */
2188 struct peer_capability_info peer_info;
2189 } __attribute__((packed));
2191 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2192 struct ieee80211_vif *vif, __u32 action)
2194 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2195 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2196 struct mwl8k_cmd_update_sta_db *cmd;
2197 struct peer_capability_info *peer_info;
2198 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2202 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2206 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2207 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2209 cmd->action = cpu_to_le32(action);
2210 peer_info = &cmd->peer_info;
2211 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2214 case MWL8K_STA_DB_ADD_ENTRY:
2215 case MWL8K_STA_DB_MODIFY_ENTRY:
2216 /* Build peer_info block */
2217 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2218 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2219 peer_info->interop = 1;
2220 peer_info->amsdu_enabled = 0;
2222 rates = peer_info->legacy_rates;
2223 for (count = 0; count < mv_vif->legacy_nrates; count++)
2224 rates[count] = bitrates[count].hw_value;
2226 rc = mwl8k_post_cmd(hw, &cmd->header);
2228 mv_vif->peer_id = peer_info->station_id;
2232 case MWL8K_STA_DB_DEL_ENTRY:
2233 case MWL8K_STA_DB_FLUSH:
2235 rc = mwl8k_post_cmd(hw, &cmd->header);
2237 mv_vif->peer_id = 0;
2248 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2250 #define MWL8K_FRAME_PROT_DISABLED 0x00
2251 #define MWL8K_FRAME_PROT_11G 0x07
2252 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2253 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2255 struct mwl8k_cmd_update_set_aid {
2256 struct mwl8k_cmd_pkt header;
2259 /* AP's MAC address (BSSID) */
2260 __u8 bssid[ETH_ALEN];
2261 __le16 protection_mode;
2262 __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2263 } __attribute__((packed));
2265 static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2266 struct ieee80211_vif *vif)
2268 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2269 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2270 struct mwl8k_cmd_update_set_aid *cmd;
2271 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2276 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2280 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2281 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2282 cmd->aid = cpu_to_le16(info->aid);
2284 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
2286 if (info->use_cts_prot) {
2287 prot_mode = MWL8K_FRAME_PROT_11G;
2289 switch (info->ht_operation_mode &
2290 IEEE80211_HT_OP_MODE_PROTECTION) {
2291 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2292 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2294 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2295 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2298 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2302 cmd->protection_mode = cpu_to_le16(prot_mode);
2304 for (count = 0; count < mv_vif->legacy_nrates; count++)
2305 cmd->supp_rates[count] = bitrates[count].hw_value;
2307 rc = mwl8k_post_cmd(hw, &cmd->header);
2316 struct mwl8k_cmd_update_rateset {
2317 struct mwl8k_cmd_pkt header;
2318 __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2320 /* Bitmap for supported MCS codes. */
2321 __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
2322 __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
2323 } __attribute__((packed));
2325 static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2326 struct ieee80211_vif *vif)
2328 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2329 struct mwl8k_cmd_update_rateset *cmd;
2330 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2334 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2338 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2339 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2341 for (count = 0; count < mv_vif->legacy_nrates; count++)
2342 cmd->legacy_rates[count] = bitrates[count].hw_value;
2344 rc = mwl8k_post_cmd(hw, &cmd->header);
2351 * CMD_USE_FIXED_RATE.
2353 #define MWL8K_RATE_TABLE_SIZE 8
2354 #define MWL8K_UCAST_RATE 0
2355 #define MWL8K_USE_AUTO_RATE 0x0002
2357 struct mwl8k_rate_entry {
2358 /* Set to 1 if HT rate, 0 if legacy. */
2361 /* Set to 1 to use retry_count field. */
2362 __le32 enable_retry;
2364 /* Specified legacy rate or MCS. */
2367 /* Number of allowed retries. */
2369 } __attribute__((packed));
2371 struct mwl8k_rate_table {
2372 /* 1 to allow specified rate and below */
2373 __le32 allow_rate_drop;
2375 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2376 } __attribute__((packed));
2378 struct mwl8k_cmd_use_fixed_rate {
2379 struct mwl8k_cmd_pkt header;
2381 struct mwl8k_rate_table rate_table;
2383 /* Unicast, Broadcast or Multicast */
2387 } __attribute__((packed));
2389 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2390 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2392 struct mwl8k_cmd_use_fixed_rate *cmd;
2396 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2400 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2401 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2403 cmd->action = cpu_to_le32(action);
2404 cmd->rate_type = cpu_to_le32(rate_type);
2406 if (rate_table != NULL) {
2407 /* Copy over each field manually so
2408 * that bitflipping can be done
2410 cmd->rate_table.allow_rate_drop =
2411 cpu_to_le32(rate_table->allow_rate_drop);
2412 cmd->rate_table.num_rates =
2413 cpu_to_le32(rate_table->num_rates);
2415 for (count = 0; count < rate_table->num_rates; count++) {
2416 struct mwl8k_rate_entry *dst =
2417 &cmd->rate_table.rate_entry[count];
2418 struct mwl8k_rate_entry *src =
2419 &rate_table->rate_entry[count];
2421 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2422 dst->enable_retry = cpu_to_le32(src->enable_retry);
2423 dst->rate = cpu_to_le32(src->rate);
2424 dst->retry_count = cpu_to_le32(src->retry_count);
2428 rc = mwl8k_post_cmd(hw, &cmd->header);
2436 * Interrupt handling.
2438 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2440 struct ieee80211_hw *hw = dev_id;
2441 struct mwl8k_priv *priv = hw->priv;
2444 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2445 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2450 if (status & MWL8K_A2H_INT_TX_DONE)
2451 tasklet_schedule(&priv->tx_reclaim_task);
2453 if (status & MWL8K_A2H_INT_RX_READY) {
2454 while (rxq_process(hw, 0, 1))
2455 rxq_refill(hw, 0, 1);
2458 if (status & MWL8K_A2H_INT_OPC_DONE) {
2459 if (priv->hostcmd_wait != NULL) {
2460 complete(priv->hostcmd_wait);
2461 priv->hostcmd_wait = NULL;
2465 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
2466 if (!priv->inconfig &&
2468 mwl8k_txq_busy(priv))
2469 mwl8k_tx_start(priv);
2477 * Core driver operations.
2479 static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2481 struct mwl8k_priv *priv = hw->priv;
2482 int index = skb_get_queue_mapping(skb);
2485 if (priv->current_channel == NULL) {
2486 printk(KERN_DEBUG "%s: dropped TX frame since radio "
2487 "disabled\n", priv->name);
2489 return NETDEV_TX_OK;
2492 rc = mwl8k_txq_xmit(hw, index, skb);
2497 struct mwl8k_work_struct {
2498 /* Initialized by mwl8k_queue_work(). */
2499 struct work_struct wt;
2501 /* Required field passed in to mwl8k_queue_work(). */
2502 struct ieee80211_hw *hw;
2504 /* Required field passed in to mwl8k_queue_work(). */
2505 int (*wfunc)(struct work_struct *w);
2507 /* Initialized by mwl8k_queue_work(). */
2508 struct completion *cmd_wait;
2514 * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
2515 * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
2519 /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
2520 unsigned long timeout_ms;
2522 /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
2523 u32 txwait_attempts;
2525 /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
2530 /* Flags controlling behavior of config queue requests */
2532 /* Caller spins while waiting for completion. */
2533 #define MWL8K_WQ_SPIN 0x00000001
2535 /* Wait for TX queues to empty before proceeding with configuration. */
2536 #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
2538 /* Queue request and return immediately. */
2539 #define MWL8K_WQ_POST_REQUEST 0x00000004
2542 * Caller sleeps and waits for task complete notification.
2543 * Do not use in atomic context.
2545 #define MWL8K_WQ_SLEEP 0x00000008
2547 /* Free work struct when task is done. */
2548 #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
2551 * Config request is queued and returns to caller imediately. Use
2552 * this in atomic context. Work struct is freed by mwl8k_queue_work()
2553 * when this flag is set.
2555 #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
2556 MWL8K_WQ_FREE_WORKSTRUCT)
2558 /* Default work queue behavior is to sleep and wait for tx completion. */
2559 #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
2562 * Default config request timeout. Add adjustments to make sure the
2563 * config thread waits long enough for both tx wait and cmd wait before
2567 /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
2568 #define MWL8K_TXWAIT_TIMEOUT_MS 1000
2570 /* Default number of TX wait attempts. */
2571 #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
2573 /* Total time to wait for TXQ to drain. */
2574 #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
2575 MWL8K_WQ_TXWAIT_ATTEMPTS)
2577 /* Scheduling slop. */
2578 #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
2580 #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
2582 MWL8K_OS_SCHEDULE_OVERHEAD_MS)
2584 static void mwl8k_config_thread(struct work_struct *wt)
2586 struct mwl8k_work_struct *worker = (struct mwl8k_work_struct *)wt;
2587 struct ieee80211_hw *hw = worker->hw;
2588 struct mwl8k_priv *priv = hw->priv;
2591 spin_lock_irq(&priv->tx_lock);
2592 priv->inconfig = true;
2593 spin_unlock_irq(&priv->tx_lock);
2595 ieee80211_stop_queues(hw);
2598 * Wait for host queues to drain before doing PHY
2599 * reconfiguration. This avoids interrupting any in-flight
2600 * DMA transfers to the hardware.
2602 if (worker->options & MWL8K_WQ_TX_WAIT_EMPTY) {
2606 u32 tx_wait_attempts = worker->txwait_attempts;
2608 time_remaining = worker->tx_timeout_ms;
2609 if (!tx_wait_attempts)
2610 tx_wait_attempts = 1;
2612 timeout = worker->tx_timeout_ms/tx_wait_attempts;
2616 iter = tx_wait_attempts;
2620 if (time_remaining > timeout) {
2621 time_remaining -= timeout;
2622 wait_time = timeout;
2624 wait_time = time_remaining;
2629 rc = mwl8k_tx_wait_empty(hw, wait_time);
2631 printk(KERN_ERR "%s() txwait timeout=%ums "
2632 "Retry:%u/%u\n", __func__, timeout,
2633 tx_wait_attempts - iter + 1,
2636 } while (rc && --iter);
2638 rc = iter ? 0 : -ETIMEDOUT;
2641 rc = worker->wfunc(wt);
2643 spin_lock_irq(&priv->tx_lock);
2644 priv->inconfig = false;
2645 if (priv->pending_tx_pkts && priv->radio_on)
2646 mwl8k_tx_start(priv);
2647 spin_unlock_irq(&priv->tx_lock);
2648 ieee80211_wake_queues(hw);
2651 if (worker->options & MWL8K_WQ_SLEEP)
2652 complete(worker->cmd_wait);
2654 if (worker->options & MWL8K_WQ_FREE_WORKSTRUCT)
2658 static int mwl8k_queue_work(struct ieee80211_hw *hw,
2659 struct mwl8k_work_struct *worker,
2660 struct workqueue_struct *wqueue,
2661 int (*wfunc)(struct work_struct *w))
2663 unsigned long timeout = 0;
2666 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2668 if (!worker->timeout_ms)
2669 worker->timeout_ms = MWL8K_CONFIG_TIMEOUT_MS;
2671 if (!worker->options)
2672 worker->options = MWL8K_WQ_DEFAULT_OPTIONS;
2674 if (!worker->txwait_attempts)
2675 worker->txwait_attempts = MWL8K_WQ_TXWAIT_ATTEMPTS;
2677 if (!worker->tx_timeout_ms)
2678 worker->tx_timeout_ms = MWL8K_TXWAIT_MS;
2681 worker->cmd_wait = &cmd_wait;
2683 worker->wfunc = wfunc;
2685 INIT_WORK(&worker->wt, mwl8k_config_thread);
2686 queue_work(wqueue, &worker->wt);
2688 if (worker->options & MWL8K_WQ_POST_REQUEST) {
2691 if (worker->options & MWL8K_WQ_SPIN) {
2692 timeout = worker->timeout_ms;
2693 while (timeout && (worker->rc > 0)) {
2697 } else if (worker->options & MWL8K_WQ_SLEEP)
2698 timeout = wait_for_completion_timeout(&cmd_wait,
2699 msecs_to_jiffies(worker->timeout_ms));
2704 cancel_work_sync(&worker->wt);
2712 struct mwl8k_start_worker {
2713 struct mwl8k_work_struct header;
2716 static int mwl8k_start_wt(struct work_struct *wt)
2718 struct mwl8k_start_worker *worker = (struct mwl8k_start_worker *)wt;
2719 struct ieee80211_hw *hw = worker->header.hw;
2720 struct mwl8k_priv *priv = hw->priv;
2723 if (priv->vif != NULL) {
2725 goto mwl8k_start_exit;
2729 if (mwl8k_cmd_802_11_radio_enable(hw)) {
2731 goto mwl8k_start_exit;
2734 /* Purge TX/RX HW queues */
2735 if (mwl8k_cmd_set_pre_scan(hw)) {
2737 goto mwl8k_start_exit;
2740 if (mwl8k_cmd_set_post_scan(hw, "\x00\x00\x00\x00\x00\x00")) {
2742 goto mwl8k_start_exit;
2745 /* Enable firmware rate adaptation */
2746 if (mwl8k_cmd_setrateadaptmode(hw, 0)) {
2748 goto mwl8k_start_exit;
2751 /* Disable WMM. WMM gets enabled when stack sends WMM parms */
2752 if (mwl8k_set_wmm(hw, 0)) {
2754 goto mwl8k_start_exit;
2757 /* Disable sniffer mode */
2758 if (mwl8k_enable_sniffer(hw, 0))
2765 static int mwl8k_start(struct ieee80211_hw *hw)
2767 struct mwl8k_start_worker *worker;
2768 struct mwl8k_priv *priv = hw->priv;
2771 /* Enable tx reclaim tasklet */
2772 tasklet_enable(&priv->tx_reclaim_task);
2774 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
2775 IRQF_SHARED, MWL8K_NAME, hw);
2777 printk(KERN_ERR "%s: failed to register IRQ handler\n",
2780 goto mwl8k_start_disable_tasklet;
2783 /* Enable interrupts */
2784 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2786 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2787 if (worker == NULL) {
2789 goto mwl8k_start_disable_irq;
2792 rc = mwl8k_queue_work(hw, &worker->header,
2793 priv->config_wq, mwl8k_start_wt);
2798 if (rc == -ETIMEDOUT)
2799 printk(KERN_ERR "%s() timed out\n", __func__);
2803 mwl8k_start_disable_irq:
2804 spin_lock_irq(&priv->tx_lock);
2805 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2806 spin_unlock_irq(&priv->tx_lock);
2807 free_irq(priv->pdev->irq, hw);
2809 mwl8k_start_disable_tasklet:
2810 tasklet_disable(&priv->tx_reclaim_task);
2815 struct mwl8k_stop_worker {
2816 struct mwl8k_work_struct header;
2819 static int mwl8k_stop_wt(struct work_struct *wt)
2821 struct mwl8k_stop_worker *worker = (struct mwl8k_stop_worker *)wt;
2822 struct ieee80211_hw *hw = worker->header.hw;
2824 return mwl8k_cmd_802_11_radio_disable(hw);
2827 static void mwl8k_stop(struct ieee80211_hw *hw)
2830 struct mwl8k_stop_worker *worker;
2831 struct mwl8k_priv *priv = hw->priv;
2834 if (priv->vif != NULL)
2837 ieee80211_stop_queues(hw);
2839 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2843 rc = mwl8k_queue_work(hw, &worker->header,
2844 priv->config_wq, mwl8k_stop_wt);
2846 if (rc == -ETIMEDOUT)
2847 printk(KERN_ERR "%s() timed out\n", __func__);
2849 /* Disable interrupts */
2850 spin_lock_irq(&priv->tx_lock);
2851 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2852 spin_unlock_irq(&priv->tx_lock);
2853 free_irq(priv->pdev->irq, hw);
2855 /* Stop finalize join worker */
2856 cancel_work_sync(&priv->finalize_join_worker);
2857 if (priv->beacon_skb != NULL)
2858 dev_kfree_skb(priv->beacon_skb);
2860 /* Stop tx reclaim tasklet */
2861 tasklet_disable(&priv->tx_reclaim_task);
2863 /* Stop config thread */
2864 flush_workqueue(priv->config_wq);
2866 /* Return all skbs to mac80211 */
2867 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2868 mwl8k_txq_reclaim(hw, i, 1);
2871 static int mwl8k_add_interface(struct ieee80211_hw *hw,
2872 struct ieee80211_if_init_conf *conf)
2874 struct mwl8k_priv *priv = hw->priv;
2875 struct mwl8k_vif *mwl8k_vif;
2878 * We only support one active interface at a time.
2880 if (priv->vif != NULL)
2884 * We only support managed interfaces for now.
2886 if (conf->type != NL80211_IFTYPE_STATION &&
2887 conf->type != NL80211_IFTYPE_MONITOR)
2890 /* Clean out driver private area */
2891 mwl8k_vif = MWL8K_VIF(conf->vif);
2892 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2894 /* Save the mac address */
2895 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
2897 /* Back pointer to parent config block */
2898 mwl8k_vif->priv = priv;
2900 /* Setup initial PHY parameters */
2901 memcpy(mwl8k_vif->legacy_rates,
2902 priv->rates, sizeof(mwl8k_vif->legacy_rates));
2903 mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
2905 /* Set Initial sequence number to zero */
2906 mwl8k_vif->seqno = 0;
2908 priv->vif = conf->vif;
2909 priv->current_channel = NULL;
2914 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2915 struct ieee80211_if_init_conf *conf)
2917 struct mwl8k_priv *priv = hw->priv;
2919 if (priv->vif == NULL)
2925 struct mwl8k_config_worker {
2926 struct mwl8k_work_struct header;
2930 static int mwl8k_config_wt(struct work_struct *wt)
2932 struct mwl8k_config_worker *worker =
2933 (struct mwl8k_config_worker *)wt;
2934 struct ieee80211_hw *hw = worker->header.hw;
2935 struct ieee80211_conf *conf = &hw->conf;
2936 struct mwl8k_priv *priv = hw->priv;
2939 if (mwl8k_cmd_802_11_radio_enable(hw)) {
2941 goto mwl8k_config_exit;
2944 priv->current_channel = conf->channel;
2946 if (mwl8k_cmd_set_rf_channel(hw, conf->channel)) {
2948 goto mwl8k_config_exit;
2951 if (conf->power_level > 18)
2952 conf->power_level = 18;
2953 if (mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level)) {
2955 goto mwl8k_config_exit;
2958 if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
2965 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
2968 struct mwl8k_config_worker *worker;
2969 struct mwl8k_priv *priv = hw->priv;
2971 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2975 worker->changed = changed;
2976 rc = mwl8k_queue_work(hw, &worker->header,
2977 priv->config_wq, mwl8k_config_wt);
2978 if (rc == -ETIMEDOUT) {
2979 printk(KERN_ERR "%s() timed out.\n", __func__);
2986 * mac80211 will crash on anything other than -EINVAL on
2987 * error. Looks like wireless extensions which calls mac80211
2988 * may be the actual culprit...
2990 return rc ? -EINVAL : 0;
2993 struct mwl8k_bss_info_changed_worker {
2994 struct mwl8k_work_struct header;
2995 struct ieee80211_vif *vif;
2996 struct ieee80211_bss_conf *info;
3000 static int mwl8k_bss_info_changed_wt(struct work_struct *wt)
3002 struct mwl8k_bss_info_changed_worker *worker =
3003 (struct mwl8k_bss_info_changed_worker *)wt;
3004 struct ieee80211_hw *hw = worker->header.hw;
3005 struct ieee80211_vif *vif = worker->vif;
3006 struct ieee80211_bss_conf *info = worker->info;
3010 struct mwl8k_priv *priv = hw->priv;
3011 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3013 changed = worker->changed;
3014 priv->capture_beacon = false;
3017 memcpy(&mwl8k_vif->bss_info, info,
3018 sizeof(struct ieee80211_bss_conf));
3021 if (mwl8k_update_rateset(hw, vif))
3022 goto mwl8k_bss_info_changed_exit;
3024 /* Turn on rate adaptation */
3025 if (mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3026 MWL8K_UCAST_RATE, NULL))
3027 goto mwl8k_bss_info_changed_exit;
3029 /* Set radio preamble */
3030 if (mwl8k_set_radio_preamble(hw, info->use_short_preamble))
3031 goto mwl8k_bss_info_changed_exit;
3034 if (mwl8k_cmd_set_slot(hw, info->use_short_slot))
3035 goto mwl8k_bss_info_changed_exit;
3037 /* Update peer rate info */
3038 if (mwl8k_cmd_update_sta_db(hw, vif,
3039 MWL8K_STA_DB_MODIFY_ENTRY))
3040 goto mwl8k_bss_info_changed_exit;
3043 if (mwl8k_cmd_set_aid(hw, vif))
3044 goto mwl8k_bss_info_changed_exit;
3047 * Finalize the join. Tell rx handler to process
3048 * next beacon from our BSSID.
3050 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
3051 priv->capture_beacon = true;
3053 mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
3054 memset(&mwl8k_vif->bss_info, 0,
3055 sizeof(struct ieee80211_bss_conf));
3056 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
3059 mwl8k_bss_info_changed_exit:
3064 static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3065 struct ieee80211_vif *vif,
3066 struct ieee80211_bss_conf *info,
3069 struct mwl8k_bss_info_changed_worker *worker;
3070 struct mwl8k_priv *priv = hw->priv;
3071 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
3074 if (changed & BSS_CHANGED_BSSID)
3075 memcpy(mv_vif->bssid, info->bssid, ETH_ALEN);
3077 if ((changed & BSS_CHANGED_ASSOC) == 0)
3080 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3085 worker->info = info;
3086 worker->changed = changed;
3087 rc = mwl8k_queue_work(hw, &worker->header,
3089 mwl8k_bss_info_changed_wt);
3091 if (rc == -ETIMEDOUT)
3092 printk(KERN_ERR "%s() timed out\n", __func__);
3095 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3096 int mc_count, struct dev_addr_list *mclist)
3098 struct mwl8k_cmd_pkt *cmd;
3100 cmd = __mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist);
3102 return (unsigned long)cmd;
3105 struct mwl8k_configure_filter_worker {
3106 struct mwl8k_work_struct header;
3107 unsigned int changed_flags;
3108 unsigned int total_flags;
3109 struct mwl8k_cmd_pkt *multicast_adr_cmd;
3112 #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
3114 static int mwl8k_configure_filter_wt(struct work_struct *wt)
3116 struct mwl8k_configure_filter_worker *worker =
3117 (struct mwl8k_configure_filter_worker *)wt;
3118 struct ieee80211_hw *hw = worker->header.hw;
3119 struct mwl8k_priv *priv = hw->priv;
3122 if (worker->changed_flags & FIF_BCN_PRBRESP_PROMISC) {
3123 if (worker->total_flags & FIF_BCN_PRBRESP_PROMISC)
3124 rc = mwl8k_cmd_set_pre_scan(hw);
3128 bssid = "\x00\x00\x00\x00\x00\x00";
3129 if (priv->vif != NULL)
3130 bssid = MWL8K_VIF(priv->vif)->bssid;
3132 rc = mwl8k_cmd_set_post_scan(hw, bssid);
3136 if (!rc && worker->multicast_adr_cmd != NULL)
3137 rc = mwl8k_post_cmd(hw, worker->multicast_adr_cmd);
3138 kfree(worker->multicast_adr_cmd);
3143 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3144 unsigned int changed_flags,
3145 unsigned int *total_flags,
3148 struct mwl8k_priv *priv = hw->priv;
3149 struct mwl8k_configure_filter_worker *worker;
3151 /* Clear unsupported feature flags */
3152 *total_flags &= MWL8K_SUPPORTED_IF_FLAGS;
3154 if (!(changed_flags & MWL8K_SUPPORTED_IF_FLAGS))
3157 worker = kzalloc(sizeof(*worker), GFP_ATOMIC);
3161 worker->changed_flags = changed_flags;
3162 worker->total_flags = *total_flags;
3163 worker->multicast_adr_cmd = (void *)(unsigned long)multicast;
3165 mwl8k_queue_work(hw, &worker->header, priv->config_wq,
3166 mwl8k_configure_filter_wt);
3169 struct mwl8k_set_rts_threshold_worker {
3170 struct mwl8k_work_struct header;
3174 static int mwl8k_set_rts_threshold_wt(struct work_struct *wt)
3176 struct mwl8k_set_rts_threshold_worker *worker =
3177 (struct mwl8k_set_rts_threshold_worker *)wt;
3179 struct ieee80211_hw *hw = worker->header.hw;
3180 u16 threshold = (u16)(worker->value);
3183 rc = mwl8k_rts_threshold(hw, MWL8K_CMD_SET, &threshold);
3188 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3191 struct mwl8k_set_rts_threshold_worker *worker;
3192 struct mwl8k_priv *priv = hw->priv;
3194 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3198 worker->value = value;
3200 rc = mwl8k_queue_work(hw, &worker->header,
3202 mwl8k_set_rts_threshold_wt);
3205 if (rc == -ETIMEDOUT) {
3206 printk(KERN_ERR "%s() timed out\n", __func__);
3213 struct mwl8k_conf_tx_worker {
3214 struct mwl8k_work_struct header;
3216 const struct ieee80211_tx_queue_params *params;
3219 static int mwl8k_conf_tx_wt(struct work_struct *wt)
3221 struct mwl8k_conf_tx_worker *worker =
3222 (struct mwl8k_conf_tx_worker *)wt;
3224 struct ieee80211_hw *hw = worker->header.hw;
3225 u16 queue = worker->queue;
3226 const struct ieee80211_tx_queue_params *params = worker->params;
3228 struct mwl8k_priv *priv = hw->priv;
3231 if (!priv->wmm_enabled) {
3232 if (mwl8k_set_wmm(hw, 1)) {
3234 goto mwl8k_conf_tx_exit;
3238 if (mwl8k_set_edca_params(hw, GET_TXQ(queue), params->cw_min,
3239 params->cw_max, params->aifs, params->txop))
3245 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3246 const struct ieee80211_tx_queue_params *params)
3249 struct mwl8k_conf_tx_worker *worker;
3250 struct mwl8k_priv *priv = hw->priv;
3252 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3256 worker->queue = queue;
3257 worker->params = params;
3258 rc = mwl8k_queue_work(hw, &worker->header,
3259 priv->config_wq, mwl8k_conf_tx_wt);
3261 if (rc == -ETIMEDOUT) {
3262 printk(KERN_ERR "%s() timed out\n", __func__);
3268 static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3269 struct ieee80211_tx_queue_stats *stats)
3271 struct mwl8k_priv *priv = hw->priv;
3272 struct mwl8k_tx_queue *txq;
3275 spin_lock_bh(&priv->tx_lock);
3276 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3277 txq = priv->txq + index;
3278 memcpy(&stats[index], &txq->tx_stats,
3279 sizeof(struct ieee80211_tx_queue_stats));
3281 spin_unlock_bh(&priv->tx_lock);
3285 struct mwl8k_get_stats_worker {
3286 struct mwl8k_work_struct header;
3287 struct ieee80211_low_level_stats *stats;
3290 static int mwl8k_get_stats_wt(struct work_struct *wt)
3292 struct mwl8k_get_stats_worker *worker =
3293 (struct mwl8k_get_stats_worker *)wt;
3295 return mwl8k_cmd_802_11_get_stat(worker->header.hw, worker->stats);
3298 static int mwl8k_get_stats(struct ieee80211_hw *hw,
3299 struct ieee80211_low_level_stats *stats)
3302 struct mwl8k_get_stats_worker *worker;
3303 struct mwl8k_priv *priv = hw->priv;
3305 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3309 worker->stats = stats;
3310 rc = mwl8k_queue_work(hw, &worker->header,
3311 priv->config_wq, mwl8k_get_stats_wt);
3314 if (rc == -ETIMEDOUT) {
3315 printk(KERN_ERR "%s() timed out\n", __func__);
3322 static const struct ieee80211_ops mwl8k_ops = {
3324 .start = mwl8k_start,
3326 .add_interface = mwl8k_add_interface,
3327 .remove_interface = mwl8k_remove_interface,
3328 .config = mwl8k_config,
3329 .bss_info_changed = mwl8k_bss_info_changed,
3330 .prepare_multicast = mwl8k_prepare_multicast,
3331 .configure_filter = mwl8k_configure_filter,
3332 .set_rts_threshold = mwl8k_set_rts_threshold,
3333 .conf_tx = mwl8k_conf_tx,
3334 .get_tx_stats = mwl8k_get_tx_stats,
3335 .get_stats = mwl8k_get_stats,
3338 static void mwl8k_tx_reclaim_handler(unsigned long data)
3341 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3342 struct mwl8k_priv *priv = hw->priv;
3344 spin_lock_bh(&priv->tx_lock);
3345 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3346 mwl8k_txq_reclaim(hw, i, 0);
3348 if (priv->tx_wait != NULL && mwl8k_txq_busy(priv) == 0) {
3349 complete(priv->tx_wait);
3350 priv->tx_wait = NULL;
3352 spin_unlock_bh(&priv->tx_lock);
3355 static void mwl8k_finalize_join_worker(struct work_struct *work)
3357 struct mwl8k_priv *priv =
3358 container_of(work, struct mwl8k_priv, finalize_join_worker);
3359 struct sk_buff *skb = priv->beacon_skb;
3360 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
3362 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3365 priv->beacon_skb = NULL;
3368 static int __devinit mwl8k_probe(struct pci_dev *pdev,
3369 const struct pci_device_id *id)
3371 struct ieee80211_hw *hw;
3372 struct mwl8k_priv *priv;
3377 rc = pci_enable_device(pdev);
3379 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3384 rc = pci_request_regions(pdev, MWL8K_NAME);
3386 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3391 pci_set_master(pdev);
3393 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3395 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3403 priv->hostcmd_wait = NULL;
3404 priv->tx_wait = NULL;
3405 priv->inconfig = false;
3406 priv->wmm_enabled = false;
3407 priv->pending_tx_pkts = 0;
3408 strncpy(priv->name, MWL8K_NAME, sizeof(priv->name));
3410 spin_lock_init(&priv->fw_lock);
3412 SET_IEEE80211_DEV(hw, &pdev->dev);
3413 pci_set_drvdata(pdev, hw);
3415 priv->regs = pci_iomap(pdev, 1, 0x10000);
3416 if (priv->regs == NULL) {
3417 printk(KERN_ERR "%s: Cannot map device memory\n", priv->name);
3421 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3422 priv->band.band = IEEE80211_BAND_2GHZ;
3423 priv->band.channels = priv->channels;
3424 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3425 priv->band.bitrates = priv->rates;
3426 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3427 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3429 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3430 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3433 * Extra headroom is the size of the required DMA header
3434 * minus the size of the smallest 802.11 frame (CTS frame).
3436 hw->extra_tx_headroom =
3437 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3439 hw->channel_change_time = 10;
3441 hw->queues = MWL8K_TX_QUEUES;
3443 hw->wiphy->interface_modes =
3444 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_MONITOR);
3446 /* Set rssi and noise values to dBm */
3447 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
3448 hw->vif_data_size = sizeof(struct mwl8k_vif);
3451 /* Set default radio state and preamble */
3453 priv->radio_short_preamble = 0;
3455 /* Finalize join worker */
3456 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3458 /* TX reclaim tasklet */
3459 tasklet_init(&priv->tx_reclaim_task,
3460 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3461 tasklet_disable(&priv->tx_reclaim_task);
3463 /* Config workthread */
3464 priv->config_wq = create_singlethread_workqueue("mwl8k_config");
3465 if (priv->config_wq == NULL)
3468 /* Power management cookie */
3469 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3470 if (priv->cookie == NULL)
3473 rc = mwl8k_rxq_init(hw, 0);
3476 rxq_refill(hw, 0, INT_MAX);
3478 spin_lock_init(&priv->tx_lock);
3480 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3481 rc = mwl8k_txq_init(hw, i);
3483 goto err_free_queues;
3486 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3487 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3488 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3489 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3491 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
3492 IRQF_SHARED, MWL8K_NAME, hw);
3494 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3496 goto err_free_queues;
3499 /* Reset firmware and hardware */
3500 mwl8k_hw_reset(priv);
3502 /* Ask userland hotplug daemon for the device firmware */
3503 rc = mwl8k_request_firmware(priv, (u32)id->driver_data);
3505 printk(KERN_ERR "%s: Firmware files not found\n", priv->name);
3509 /* Load firmware into hardware */
3510 rc = mwl8k_load_firmware(priv);
3512 printk(KERN_ERR "%s: Cannot start firmware\n", priv->name);
3513 goto err_stop_firmware;
3516 /* Reclaim memory once firmware is successfully loaded */
3517 mwl8k_release_firmware(priv);
3520 * Temporarily enable interrupts. Initial firmware host
3521 * commands use interrupts and avoids polling. Disable
3522 * interrupts when done.
3524 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3526 /* Get config data, mac addrs etc */
3527 rc = mwl8k_cmd_get_hw_spec(hw);
3529 printk(KERN_ERR "%s: Cannot initialise firmware\n", priv->name);
3530 goto err_stop_firmware;
3533 /* Turn radio off */
3534 rc = mwl8k_cmd_802_11_radio_disable(hw);
3536 printk(KERN_ERR "%s: Cannot disable\n", priv->name);
3537 goto err_stop_firmware;
3540 /* Disable interrupts */
3541 spin_lock_irq(&priv->tx_lock);
3542 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3543 spin_unlock_irq(&priv->tx_lock);
3544 free_irq(priv->pdev->irq, hw);
3546 rc = ieee80211_register_hw(hw);
3548 printk(KERN_ERR "%s: Cannot register device\n", priv->name);
3549 goto err_stop_firmware;
3552 fw = (u8 *)&priv->fw_rev;
3553 printk(KERN_INFO "%s: 88W%u %s\n", priv->name, priv->part_num,
3555 printk(KERN_INFO "%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
3556 priv->name, MWL8K_VERSION, fw[3], fw[2], fw[1], fw[0]);
3557 printk(KERN_INFO "%s: MAC Address: %pM\n", priv->name,
3558 hw->wiphy->perm_addr);
3563 mwl8k_hw_reset(priv);
3564 mwl8k_release_firmware(priv);
3567 spin_lock_irq(&priv->tx_lock);
3568 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3569 spin_unlock_irq(&priv->tx_lock);
3570 free_irq(priv->pdev->irq, hw);
3573 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3574 mwl8k_txq_deinit(hw, i);
3575 mwl8k_rxq_deinit(hw, 0);
3578 if (priv->cookie != NULL)
3579 pci_free_consistent(priv->pdev, 4,
3580 priv->cookie, priv->cookie_dma);
3582 if (priv->regs != NULL)
3583 pci_iounmap(pdev, priv->regs);
3585 if (priv->config_wq != NULL)
3586 destroy_workqueue(priv->config_wq);
3588 pci_set_drvdata(pdev, NULL);
3589 ieee80211_free_hw(hw);
3592 pci_release_regions(pdev);
3593 pci_disable_device(pdev);
3598 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
3600 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3603 static void __devexit mwl8k_remove(struct pci_dev *pdev)
3605 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3606 struct mwl8k_priv *priv;
3613 ieee80211_stop_queues(hw);
3615 ieee80211_unregister_hw(hw);
3617 /* Remove tx reclaim tasklet */
3618 tasklet_kill(&priv->tx_reclaim_task);
3620 /* Stop config thread */
3621 destroy_workqueue(priv->config_wq);
3624 mwl8k_hw_reset(priv);
3626 /* Return all skbs to mac80211 */
3627 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3628 mwl8k_txq_reclaim(hw, i, 1);
3630 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3631 mwl8k_txq_deinit(hw, i);
3633 mwl8k_rxq_deinit(hw, 0);
3635 pci_free_consistent(priv->pdev, 4,
3636 priv->cookie, priv->cookie_dma);
3638 pci_iounmap(pdev, priv->regs);
3639 pci_set_drvdata(pdev, NULL);
3640 ieee80211_free_hw(hw);
3641 pci_release_regions(pdev);
3642 pci_disable_device(pdev);
3645 static struct pci_driver mwl8k_driver = {
3647 .id_table = mwl8k_table,
3648 .probe = mwl8k_probe,
3649 .remove = __devexit_p(mwl8k_remove),
3650 .shutdown = __devexit_p(mwl8k_shutdown),
3653 static int __init mwl8k_init(void)
3655 return pci_register_driver(&mwl8k_driver);
3658 static void __exit mwl8k_exit(void)
3660 pci_unregister_driver(&mwl8k_driver);
3663 module_init(mwl8k_init);
3664 module_exit(mwl8k_exit);