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 #define IEEE80211_ADDR_LEN ETH_ALEN
43 /* Register definitions */
44 #define MWL8K_HIU_GEN_PTR 0x00000c10
45 #define MWL8K_MODE_STA 0x0000005a
46 #define MWL8K_MODE_AP 0x000000a5
47 #define MWL8K_HIU_INT_CODE 0x00000c14
48 #define MWL8K_FWSTA_READY 0xf0f1f2f4
49 #define MWL8K_FWAP_READY 0xf1f2f4a5
50 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
51 #define MWL8K_HIU_SCRATCH 0x00000c40
53 /* Host->device communications */
54 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
55 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
56 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
57 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
58 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
59 #define MWL8K_H2A_INT_DUMMY (1 << 20)
60 #define MWL8K_H2A_INT_RESET (1 << 15)
61 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
62 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
64 /* Device->host communications */
65 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
66 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
67 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
68 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
69 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
70 #define MWL8K_A2H_INT_DUMMY (1 << 20)
71 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
72 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
73 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
74 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
75 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
76 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
77 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
78 #define MWL8K_A2H_INT_RX_READY (1 << 1)
79 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
81 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
82 MWL8K_A2H_INT_CHNL_SWITCHED | \
83 MWL8K_A2H_INT_QUEUE_EMPTY | \
84 MWL8K_A2H_INT_RADAR_DETECT | \
85 MWL8K_A2H_INT_RADIO_ON | \
86 MWL8K_A2H_INT_RADIO_OFF | \
87 MWL8K_A2H_INT_MAC_EVENT | \
88 MWL8K_A2H_INT_OPC_DONE | \
89 MWL8K_A2H_INT_RX_READY | \
90 MWL8K_A2H_INT_TX_DONE)
92 /* WME stream classes */
93 #define WME_AC_BE 0 /* best effort */
94 #define WME_AC_BK 1 /* background */
95 #define WME_AC_VI 2 /* video */
96 #define WME_AC_VO 3 /* voice */
98 #define MWL8K_RX_QUEUES 1
99 #define MWL8K_TX_QUEUES 4
101 struct mwl8k_rx_queue {
104 /* hw receives here */
107 /* refill descs here */
110 struct mwl8k_rx_desc *rx_desc_area;
111 dma_addr_t rx_desc_dma;
112 struct sk_buff **rx_skb;
117 * The DMA engine requires a modification to the payload.
118 * If the skbuff is shared/cloned, it needs to be unshared.
119 * This method is used to ensure the stack always gets back
120 * the skbuff it sent for transmission.
122 struct sk_buff *clone;
126 struct mwl8k_tx_queue {
127 /* hw transmits here */
130 /* sw appends here */
133 struct ieee80211_tx_queue_stats tx_stats;
134 struct mwl8k_tx_desc *tx_desc_area;
135 dma_addr_t tx_desc_dma;
136 struct mwl8k_skb *tx_skb;
139 /* Pointers to the firmware data and meta information about it. */
140 struct mwl8k_firmware {
142 struct firmware *ucode;
144 /* Boot helper code */
145 struct firmware *helper;
150 struct ieee80211_hw *hw;
152 struct pci_dev *pdev;
154 /* firmware access lock */
157 /* firmware files and meta data */
158 struct mwl8k_firmware fw;
161 /* lock held over TX and TX reap */
164 struct ieee80211_vif *vif;
166 struct ieee80211_channel *current_channel;
168 /* power management status cookie from firmware */
170 dma_addr_t cookie_dma;
177 * Running count of TX packets in flight, to avoid
178 * iterating over the transmit rings each time.
182 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
183 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
186 struct ieee80211_supported_band band;
187 struct ieee80211_channel channels[14];
188 struct ieee80211_rate rates[12];
190 /* RF preamble: Short, Long or Auto */
194 /* WMM MODE 1 for enabled; 0 for disabled */
197 /* Set if PHY config is in progress */
200 /* XXX need to convert this to handle multiple interfaces */
202 u8 capture_bssid[IEEE80211_ADDR_LEN];
203 struct sk_buff *beacon_skb;
206 * This FJ worker has to be global as it is scheduled from the
207 * RX handler. At this point we don't know which interface it
208 * belongs to until the list of bssids waiting to complete join
211 struct work_struct finalize_join_worker;
213 /* Tasklet to reclaim TX descriptors and buffers after tx */
214 struct tasklet_struct tx_reclaim_task;
216 /* Work thread to serialize configuration requests */
217 struct workqueue_struct *config_wq;
218 struct completion *hostcmd_wait;
219 struct completion *tx_wait;
222 /* Per interface specific private data */
224 /* backpointer to parent config block */
225 struct mwl8k_priv *priv;
227 /* BSS config of AP or IBSS from mac80211*/
228 struct ieee80211_bss_conf bss_info;
230 /* BSSID of AP or IBSS */
231 u8 bssid[IEEE80211_ADDR_LEN];
232 u8 mac_addr[IEEE80211_ADDR_LEN];
235 * Subset of supported legacy rates.
236 * Intersection of AP and STA supported rates.
238 struct ieee80211_rate legacy_rates[12];
240 /* number of supported legacy rates */
243 /* Index into station database.Returned by update_sta_db call */
246 /* Non AMPDU sequence number assigned by driver */
250 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
252 static const struct ieee80211_channel mwl8k_channels[] = {
253 { .center_freq = 2412, .hw_value = 1, },
254 { .center_freq = 2417, .hw_value = 2, },
255 { .center_freq = 2422, .hw_value = 3, },
256 { .center_freq = 2427, .hw_value = 4, },
257 { .center_freq = 2432, .hw_value = 5, },
258 { .center_freq = 2437, .hw_value = 6, },
259 { .center_freq = 2442, .hw_value = 7, },
260 { .center_freq = 2447, .hw_value = 8, },
261 { .center_freq = 2452, .hw_value = 9, },
262 { .center_freq = 2457, .hw_value = 10, },
263 { .center_freq = 2462, .hw_value = 11, },
266 static const struct ieee80211_rate mwl8k_rates[] = {
267 { .bitrate = 10, .hw_value = 2, },
268 { .bitrate = 20, .hw_value = 4, },
269 { .bitrate = 55, .hw_value = 11, },
270 { .bitrate = 60, .hw_value = 12, },
271 { .bitrate = 90, .hw_value = 18, },
272 { .bitrate = 110, .hw_value = 22, },
273 { .bitrate = 120, .hw_value = 24, },
274 { .bitrate = 180, .hw_value = 36, },
275 { .bitrate = 240, .hw_value = 48, },
276 { .bitrate = 360, .hw_value = 72, },
277 { .bitrate = 480, .hw_value = 96, },
278 { .bitrate = 540, .hw_value = 108, },
282 #define MWL8K_RADIO_FORCE 0x2
283 #define MWL8K_RADIO_ENABLE 0x1
284 #define MWL8K_RADIO_DISABLE 0x0
285 #define MWL8K_RADIO_AUTO_PREAMBLE 0x0005
286 #define MWL8K_RADIO_SHORT_PREAMBLE 0x0003
287 #define MWL8K_RADIO_LONG_PREAMBLE 0x0001
290 #define MWL8K_WMM_ENABLE 1
291 #define MWL8K_WMM_DISABLE 0
293 #define MWL8K_RADIO_DEFAULT_PREAMBLE MWL8K_RADIO_LONG_PREAMBLE
297 /* Short Slot: 9us slot time */
298 #define MWL8K_SHORT_SLOTTIME 1
300 /* Long slot: 20us slot time */
301 #define MWL8K_LONG_SLOTTIME 0
303 /* Set or get info from Firmware */
304 #define MWL8K_CMD_SET 0x0001
305 #define MWL8K_CMD_GET 0x0000
307 /* Firmware command codes */
308 #define MWL8K_CMD_CODE_DNLD 0x0001
309 #define MWL8K_CMD_GET_HW_SPEC 0x0003
310 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
311 #define MWL8K_CMD_GET_STAT 0x0014
312 #define MWL8K_CMD_RADIO_CONTROL 0x001C
313 #define MWL8K_CMD_RF_TX_POWER 0x001E
314 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
315 #define MWL8K_CMD_SET_POST_SCAN 0x0108
316 #define MWL8K_CMD_SET_RF_CHANNEL 0x010A
317 #define MWL8K_CMD_SET_SLOT 0x0114
318 #define MWL8K_CMD_MIMO_CONFIG 0x0125
319 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
320 #define MWL8K_CMD_SET_WMM_MODE 0x0123
321 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
322 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
323 #define MWL8K_CMD_UPDATE_STADB 0x1123
324 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
325 #define MWL8K_CMD_SET_LINKADAPT_MODE 0x0129
326 #define MWL8K_CMD_SET_AID 0x010d
327 #define MWL8K_CMD_SET_RATE 0x0110
328 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
329 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
330 #define MWL8K_CMD_ENCRYPTION 0x1122
332 static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
334 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
335 snprintf(buf, bufsize, "%s", #x);\
338 switch (cmd & (~0x8000)) {
339 MWL8K_CMDNAME(CODE_DNLD);
340 MWL8K_CMDNAME(GET_HW_SPEC);
341 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
342 MWL8K_CMDNAME(GET_STAT);
343 MWL8K_CMDNAME(RADIO_CONTROL);
344 MWL8K_CMDNAME(RF_TX_POWER);
345 MWL8K_CMDNAME(SET_PRE_SCAN);
346 MWL8K_CMDNAME(SET_POST_SCAN);
347 MWL8K_CMDNAME(SET_RF_CHANNEL);
348 MWL8K_CMDNAME(SET_SLOT);
349 MWL8K_CMDNAME(MIMO_CONFIG);
350 MWL8K_CMDNAME(ENABLE_SNIFFER);
351 MWL8K_CMDNAME(SET_WMM_MODE);
352 MWL8K_CMDNAME(SET_EDCA_PARAMS);
353 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
354 MWL8K_CMDNAME(UPDATE_STADB);
355 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
356 MWL8K_CMDNAME(SET_LINKADAPT_MODE);
357 MWL8K_CMDNAME(SET_AID);
358 MWL8K_CMDNAME(SET_RATE);
359 MWL8K_CMDNAME(USE_FIXED_RATE);
360 MWL8K_CMDNAME(RTS_THRESHOLD);
361 MWL8K_CMDNAME(ENCRYPTION);
363 snprintf(buf, bufsize, "0x%x", cmd);
370 /* Hardware and firmware reset */
371 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
373 iowrite32(MWL8K_H2A_INT_RESET,
374 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
375 iowrite32(MWL8K_H2A_INT_RESET,
376 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
380 /* Release fw image */
381 static void mwl8k_release_fw(struct firmware **fw)
385 release_firmware(*fw);
389 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
391 mwl8k_release_fw(&priv->fw.ucode);
392 mwl8k_release_fw(&priv->fw.helper);
395 /* Request fw image */
396 static int mwl8k_request_fw(struct mwl8k_priv *priv,
397 const char *fname, struct firmware **fw)
399 /* release current image */
401 mwl8k_release_fw(fw);
403 return request_firmware((const struct firmware **)fw,
404 fname, &priv->pdev->dev);
407 static int mwl8k_request_firmware(struct mwl8k_priv *priv, u32 part_num)
412 priv->part_num = part_num;
414 snprintf(filename, sizeof(filename),
415 "mwl8k/helper_%u.fw", priv->part_num);
417 rc = mwl8k_request_fw(priv, filename, &priv->fw.helper);
420 "%s Error requesting helper firmware file %s\n",
421 pci_name(priv->pdev), filename);
425 snprintf(filename, sizeof(filename),
426 "mwl8k/fmimage_%u.fw", priv->part_num);
428 rc = mwl8k_request_fw(priv, filename, &priv->fw.ucode);
430 printk(KERN_ERR "%s Error requesting firmware file %s\n",
431 pci_name(priv->pdev), filename);
432 mwl8k_release_fw(&priv->fw.helper);
439 struct mwl8k_cmd_pkt {
445 } __attribute__((packed));
451 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
453 void __iomem *regs = priv->regs;
458 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
459 if (pci_dma_mapping_error(priv->pdev, dma_addr))
462 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
463 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
464 iowrite32(MWL8K_H2A_INT_DOORBELL,
465 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
466 iowrite32(MWL8K_H2A_INT_DUMMY,
467 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
474 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
475 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
476 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
484 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
487 * Clear 'command done' interrupt bit.
493 status = ioread32(priv->regs +
494 MWL8K_HIU_A2H_INTERRUPT_STATUS);
495 if (status & MWL8K_A2H_INT_OPC_DONE) {
496 iowrite32(~MWL8K_A2H_INT_OPC_DONE,
497 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
498 ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
508 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
509 const u8 *data, size_t length)
511 struct mwl8k_cmd_pkt *cmd;
515 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
519 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
525 int block_size = length > 256 ? 256 : length;
527 memcpy(cmd->payload, data + done, block_size);
528 cmd->length = cpu_to_le16(block_size);
530 rc = mwl8k_send_fw_load_cmd(priv, cmd,
531 sizeof(*cmd) + block_size);
536 length -= block_size;
541 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
549 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
550 const u8 *data, size_t length)
552 unsigned char *buffer;
553 int may_continue, rc = 0;
554 u32 done, prev_block_size;
556 buffer = kmalloc(1024, GFP_KERNEL);
563 while (may_continue > 0) {
566 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
567 if (block_size & 1) {
571 done += prev_block_size;
572 length -= prev_block_size;
575 if (block_size > 1024 || block_size > length) {
585 if (block_size == 0) {
592 prev_block_size = block_size;
593 memcpy(buffer, data + done, block_size);
595 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
600 if (!rc && length != 0)
608 static int mwl8k_load_firmware(struct mwl8k_priv *priv)
612 const u8 *ucode = priv->fw.ucode->data;
613 size_t ucode_len = priv->fw.ucode->size;
614 const u8 *helper = priv->fw.helper->data;
615 size_t helper_len = priv->fw.helper->size;
617 if (!memcmp(ucode, "\x01\x00\x00\x00", 4)) {
618 rc = mwl8k_load_fw_image(priv, helper, helper_len);
620 printk(KERN_ERR "%s: unable to load firmware "
621 "helper image\n", pci_name(priv->pdev));
626 rc = mwl8k_feed_fw_image(priv, ucode, ucode_len);
628 rc = mwl8k_load_fw_image(priv, ucode, ucode_len);
632 printk(KERN_ERR "%s: unable to load firmware data\n",
633 pci_name(priv->pdev));
637 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
642 if (ioread32(priv->regs + MWL8K_HIU_INT_CODE)
643 == MWL8K_FWSTA_READY)
648 return loops ? 0 : -ETIMEDOUT;
653 * Defines shared between transmission and reception.
655 /* HT control fields for firmware */
660 } __attribute__((packed));
662 /* Firmware Station database operations */
663 #define MWL8K_STA_DB_ADD_ENTRY 0
664 #define MWL8K_STA_DB_MODIFY_ENTRY 1
665 #define MWL8K_STA_DB_DEL_ENTRY 2
666 #define MWL8K_STA_DB_FLUSH 3
668 /* Peer Entry flags - used to define the type of the peer node */
669 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
671 #define MWL8K_IEEE_LEGACY_DATA_RATES 12
672 #define MWL8K_MCS_BITMAP_SIZE 16
674 struct peer_capability_info {
675 /* Peer type - AP vs. STA. */
678 /* Basic 802.11 capabilities from assoc resp. */
681 /* Set if peer supports 802.11n high throughput (HT). */
684 /* Valid if HT is supported. */
686 __u8 extended_ht_caps;
687 struct ewc_ht_info ewc_info;
689 /* Legacy rate table. Intersection of our rates and peer rates. */
690 __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
692 /* HT rate table. Intersection of our rates and peer rates. */
693 __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
696 /* If set, interoperability mode, no proprietary extensions. */
700 __le16 amsdu_enabled;
701 } __attribute__((packed));
703 /* Inline functions to manipulate QoS field in data descriptor. */
704 static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
706 u16 val_mask = 1 << 4;
708 /* End of Service Period Bit 4 */
709 return qos | val_mask;
712 static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
716 u16 qos_mask = ~(val_mask << shift);
718 /* Ack Policy Bit 5-6 */
719 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
722 static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
724 u16 val_mask = 1 << 7;
726 /* AMSDU present Bit 7 */
727 return qos | val_mask;
730 static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
734 u16 qos_mask = ~(val_mask << shift);
736 /* Queue Length Bits 8-15 */
737 return (qos & qos_mask) | ((len & val_mask) << shift);
740 /* DMA header used by firmware and hardware. */
741 struct mwl8k_dma_data {
743 struct ieee80211_hdr wh;
744 } __attribute__((packed));
746 /* Routines to add/remove DMA header from skb. */
747 static inline int mwl8k_remove_dma_header(struct sk_buff *skb)
749 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)(skb->data);
750 void *dst, *src = &tr->wh;
751 __le16 fc = tr->wh.frame_control;
752 int hdrlen = ieee80211_hdrlen(fc);
753 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
755 dst = (void *)tr + space;
757 memmove(dst, src, hdrlen);
758 skb_pull(skb, space);
764 static inline struct sk_buff *mwl8k_add_dma_header(struct sk_buff *skb)
766 struct ieee80211_hdr *wh;
768 struct mwl8k_dma_data *tr;
770 wh = (struct ieee80211_hdr *)skb->data;
771 hdrlen = ieee80211_hdrlen(wh->frame_control);
775 * Copy up/down the 802.11 header; the firmware requires
776 * we present a 2-byte payload length followed by a
777 * 4-address header (w/o QoS), followed (optionally) by
778 * any WEP/ExtIV header (but only filled in for CCMP).
780 if (hdrlen != sizeof(struct mwl8k_dma_data))
781 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
783 tr = (struct mwl8k_dma_data *)skb->data;
785 memmove(&tr->wh, wh, hdrlen);
788 memset(tr->wh.addr4, 0, IEEE80211_ADDR_LEN);
791 * Firmware length is the length of the fully formed "802.11
792 * payload". That is, everything except for the 802.11 header.
793 * This includes all crypto material including the MIC.
795 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
804 #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
806 struct mwl8k_rx_desc {
810 __le32 pkt_phys_addr;
811 __le32 next_rx_desc_phys_addr;
821 } __attribute__((packed));
823 #define MWL8K_RX_DESCS 256
824 #define MWL8K_RX_MAXSZ 3800
826 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
828 struct mwl8k_priv *priv = hw->priv;
829 struct mwl8k_rx_queue *rxq = priv->rxq + index;
833 rxq->rx_desc_count = 0;
837 size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc);
840 pci_alloc_consistent(priv->pdev, size, &rxq->rx_desc_dma);
841 if (rxq->rx_desc_area == NULL) {
842 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
846 memset(rxq->rx_desc_area, 0, size);
848 rxq->rx_skb = kmalloc(MWL8K_RX_DESCS *
849 sizeof(*rxq->rx_skb), GFP_KERNEL);
850 if (rxq->rx_skb == NULL) {
851 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
853 pci_free_consistent(priv->pdev, size,
854 rxq->rx_desc_area, rxq->rx_desc_dma);
857 memset(rxq->rx_skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->rx_skb));
859 for (i = 0; i < MWL8K_RX_DESCS; i++) {
860 struct mwl8k_rx_desc *rx_desc;
863 rx_desc = rxq->rx_desc_area + i;
864 nexti = (i + 1) % MWL8K_RX_DESCS;
866 rx_desc->next_rx_desc_phys_addr =
867 cpu_to_le32(rxq->rx_desc_dma
868 + nexti * sizeof(*rx_desc));
869 rx_desc->rx_ctrl = MWL8K_RX_CTRL_OWNED_BY_HOST;
875 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
877 struct mwl8k_priv *priv = hw->priv;
878 struct mwl8k_rx_queue *rxq = priv->rxq + index;
882 while (rxq->rx_desc_count < MWL8K_RX_DESCS && limit--) {
886 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
890 rxq->rx_desc_count++;
893 rxq->rx_tail = (rx + 1) % MWL8K_RX_DESCS;
895 rxq->rx_desc_area[rx].pkt_phys_addr =
896 cpu_to_le32(pci_map_single(priv->pdev, skb->data,
897 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE));
899 rxq->rx_desc_area[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ);
900 rxq->rx_skb[rx] = skb;
902 rxq->rx_desc_area[rx].rx_ctrl = 0;
910 /* Must be called only when the card's reception is completely halted */
911 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
913 struct mwl8k_priv *priv = hw->priv;
914 struct mwl8k_rx_queue *rxq = priv->rxq + index;
917 for (i = 0; i < MWL8K_RX_DESCS; i++) {
918 if (rxq->rx_skb[i] != NULL) {
921 addr = le32_to_cpu(rxq->rx_desc_area[i].pkt_phys_addr);
922 pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ,
924 kfree_skb(rxq->rx_skb[i]);
925 rxq->rx_skb[i] = NULL;
932 pci_free_consistent(priv->pdev,
933 MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc),
934 rxq->rx_desc_area, rxq->rx_desc_dma);
935 rxq->rx_desc_area = NULL;
940 * Scan a list of BSSIDs to process for finalize join.
941 * Allows for extension to process multiple BSSIDs.
944 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
946 return priv->capture_beacon &&
947 ieee80211_is_beacon(wh->frame_control) &&
948 !compare_ether_addr(wh->addr3, priv->capture_bssid);
951 static inline void mwl8k_save_beacon(struct mwl8k_priv *priv,
954 priv->capture_beacon = false;
955 memset(priv->capture_bssid, 0, IEEE80211_ADDR_LEN);
958 * Use GFP_ATOMIC as rxq_process is called from
959 * the primary interrupt handler, memory allocation call
962 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
963 if (priv->beacon_skb != NULL)
964 queue_work(priv->config_wq,
965 &priv->finalize_join_worker);
968 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
970 struct mwl8k_priv *priv = hw->priv;
971 struct mwl8k_rx_queue *rxq = priv->rxq + index;
975 while (rxq->rx_desc_count && limit--) {
976 struct mwl8k_rx_desc *rx_desc;
978 struct ieee80211_rx_status status;
980 struct ieee80211_hdr *wh;
982 rx_desc = rxq->rx_desc_area + rxq->rx_head;
983 if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST))
987 skb = rxq->rx_skb[rxq->rx_head];
990 rxq->rx_skb[rxq->rx_head] = NULL;
992 rxq->rx_head = (rxq->rx_head + 1) % MWL8K_RX_DESCS;
993 rxq->rx_desc_count--;
995 addr = le32_to_cpu(rx_desc->pkt_phys_addr);
996 pci_unmap_single(priv->pdev, addr,
997 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
999 skb_put(skb, le16_to_cpu(rx_desc->pkt_len));
1000 if (mwl8k_remove_dma_header(skb)) {
1005 wh = (struct ieee80211_hdr *)skb->data;
1008 * Check for pending join operation. save a copy of
1009 * the beacon and schedule a tasklet to send finalize
1010 * join command to the firmware.
1012 if (mwl8k_capture_bssid(priv, wh))
1013 mwl8k_save_beacon(priv, skb);
1015 memset(&status, 0, sizeof(status));
1017 status.signal = -rx_desc->rssi;
1018 status.noise = -rx_desc->noise_level;
1019 status.qual = rx_desc->link_quality;
1021 status.rate_idx = 1;
1023 status.band = IEEE80211_BAND_2GHZ;
1024 status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
1025 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1026 ieee80211_rx_irqsafe(hw, skb);
1036 * Packet transmission.
1039 /* Transmit queue assignment. */
1041 MWL8K_WME_AC_BK = 0, /* background access */
1042 MWL8K_WME_AC_BE = 1, /* best effort access */
1043 MWL8K_WME_AC_VI = 2, /* video access */
1044 MWL8K_WME_AC_VO = 3, /* voice access */
1047 /* Transmit packet ACK policy */
1048 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
1049 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1051 #define GET_TXQ(_ac) (\
1052 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
1053 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
1054 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
1057 #define MWL8K_TXD_STATUS_OK 0x00000001
1058 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1059 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1060 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1061 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1063 struct mwl8k_tx_desc {
1068 __le32 pkt_phys_addr;
1070 __u8 dest_MAC_addr[IEEE80211_ADDR_LEN];
1071 __le32 next_tx_desc_phys_addr;
1076 } __attribute__((packed));
1078 #define MWL8K_TX_DESCS 128
1080 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1082 struct mwl8k_priv *priv = hw->priv;
1083 struct mwl8k_tx_queue *txq = priv->txq + index;
1087 memset(&txq->tx_stats, 0,
1088 sizeof(struct ieee80211_tx_queue_stats));
1089 txq->tx_stats.limit = MWL8K_TX_DESCS;
1093 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1096 pci_alloc_consistent(priv->pdev, size, &txq->tx_desc_dma);
1097 if (txq->tx_desc_area == NULL) {
1098 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1102 memset(txq->tx_desc_area, 0, size);
1104 txq->tx_skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->tx_skb),
1106 if (txq->tx_skb == NULL) {
1107 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1109 pci_free_consistent(priv->pdev, size,
1110 txq->tx_desc_area, txq->tx_desc_dma);
1113 memset(txq->tx_skb, 0, MWL8K_TX_DESCS * sizeof(*txq->tx_skb));
1115 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1116 struct mwl8k_tx_desc *tx_desc;
1119 tx_desc = txq->tx_desc_area + i;
1120 nexti = (i + 1) % MWL8K_TX_DESCS;
1122 tx_desc->status = 0;
1123 tx_desc->next_tx_desc_phys_addr =
1124 cpu_to_le32(txq->tx_desc_dma +
1125 nexti * sizeof(*tx_desc));
1131 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1133 iowrite32(MWL8K_H2A_INT_PPA_READY,
1134 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1135 iowrite32(MWL8K_H2A_INT_DUMMY,
1136 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1137 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1140 static inline int mwl8k_txq_busy(struct mwl8k_priv *priv)
1142 return priv->pending_tx_pkts;
1145 struct mwl8k_txq_info {
1154 static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
1155 struct mwl8k_txq_info txinfo[],
1158 int count, desc, status;
1159 struct mwl8k_tx_queue *txq;
1160 struct mwl8k_tx_desc *tx_desc;
1163 memset(txinfo, 0, num_queues * sizeof(struct mwl8k_txq_info));
1164 spin_lock_bh(&priv->tx_lock);
1165 for (count = 0; count < num_queues; count++) {
1166 txq = priv->txq + count;
1167 txinfo[count].len = txq->tx_stats.len;
1168 txinfo[count].head = txq->tx_head;
1169 txinfo[count].tail = txq->tx_tail;
1170 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1171 tx_desc = txq->tx_desc_area + desc;
1172 status = le32_to_cpu(tx_desc->status);
1174 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1175 txinfo[count].fw_owned++;
1177 txinfo[count].drv_owned++;
1179 if (tx_desc->pkt_len == 0)
1180 txinfo[count].unused++;
1183 spin_unlock_bh(&priv->tx_lock);
1188 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw, u32 delay_ms)
1191 unsigned long timeout = 0;
1192 struct mwl8k_priv *priv = hw->priv;
1193 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1197 if (priv->tx_wait != NULL)
1198 printk(KERN_ERR "WARNING Previous TXWaitEmpty instance\n");
1200 spin_lock_bh(&priv->tx_lock);
1201 count = mwl8k_txq_busy(priv);
1203 priv->tx_wait = &cmd_wait;
1204 if (priv->radio_state)
1205 mwl8k_tx_start(priv);
1207 spin_unlock_bh(&priv->tx_lock);
1210 struct mwl8k_txq_info txinfo[4];
1214 timeout = wait_for_completion_timeout(&cmd_wait,
1215 msecs_to_jiffies(delay_ms));
1219 spin_lock_bh(&priv->tx_lock);
1220 priv->tx_wait = NULL;
1221 newcount = mwl8k_txq_busy(priv);
1222 spin_unlock_bh(&priv->tx_lock);
1224 printk(KERN_ERR "%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
1225 __func__, __LINE__, delay_ms, count, newcount);
1227 mwl8k_scan_tx_ring(priv, txinfo, 4);
1228 for (index = 0 ; index < 4; index++)
1230 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
1235 txinfo[index].fw_owned,
1236 txinfo[index].drv_owned,
1237 txinfo[index].unused);
1244 #define MWL8K_TXD_SUCCESS(status) \
1245 ((status) & (MWL8K_TXD_STATUS_OK | \
1246 MWL8K_TXD_STATUS_OK_RETRY | \
1247 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1249 static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1251 struct mwl8k_priv *priv = hw->priv;
1252 struct mwl8k_tx_queue *txq = priv->txq + index;
1255 while (txq->tx_stats.len > 0) {
1258 struct mwl8k_tx_desc *tx_desc;
1261 struct sk_buff *skb;
1262 struct ieee80211_tx_info *info;
1267 tx_desc = txq->tx_desc_area + tx;
1269 status = le32_to_cpu(tx_desc->status);
1271 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1275 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1278 txq->tx_head = (tx + 1) % MWL8K_TX_DESCS;
1279 BUG_ON(txq->tx_stats.len == 0);
1280 txq->tx_stats.len--;
1281 priv->pending_tx_pkts--;
1283 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1284 size = (u32)(le16_to_cpu(tx_desc->pkt_len));
1285 skb = txq->tx_skb[tx].skb;
1286 txq->tx_skb[tx].skb = NULL;
1288 BUG_ON(skb == NULL);
1289 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1291 rc = mwl8k_remove_dma_header(skb);
1293 /* Mark descriptor as unused */
1294 tx_desc->pkt_phys_addr = 0;
1295 tx_desc->pkt_len = 0;
1297 if (txq->tx_skb[tx].clone) {
1298 /* Replace with original skb
1299 * before returning to stack
1300 * as buffer has been cloned
1303 skb = txq->tx_skb[tx].clone;
1304 txq->tx_skb[tx].clone = NULL;
1308 /* Something has gone wrong here.
1309 * Failed to remove DMA header.
1310 * Print error message and drop packet.
1312 printk(KERN_ERR "%s: Error removing DMA header from "
1313 "tx skb 0x%p.\n", priv->name, skb);
1319 info = IEEE80211_SKB_CB(skb);
1320 ieee80211_tx_info_clear_status(info);
1322 /* Convert firmware status stuff into tx_status */
1323 if (MWL8K_TXD_SUCCESS(status)) {
1325 info->flags |= IEEE80211_TX_STAT_ACK;
1328 ieee80211_tx_status_irqsafe(hw, skb);
1330 wake = !priv->inconfig && priv->radio_state;
1334 ieee80211_wake_queue(hw, index);
1337 /* must be called only when the card's transmit is completely halted */
1338 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1340 struct mwl8k_priv *priv = hw->priv;
1341 struct mwl8k_tx_queue *txq = priv->txq + index;
1343 mwl8k_txq_reclaim(hw, index, 1);
1348 pci_free_consistent(priv->pdev,
1349 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1350 txq->tx_desc_area, txq->tx_desc_dma);
1351 txq->tx_desc_area = NULL;
1355 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1357 struct mwl8k_priv *priv = hw->priv;
1358 struct ieee80211_tx_info *tx_info;
1359 struct ieee80211_hdr *wh;
1360 struct mwl8k_tx_queue *txq;
1361 struct mwl8k_tx_desc *tx;
1362 struct mwl8k_dma_data *tr;
1363 struct mwl8k_vif *mwl8k_vif;
1364 struct sk_buff *org_skb = skb;
1367 bool qosframe = false, ampduframe = false;
1368 bool mcframe = false, eapolframe = false;
1369 bool amsduframe = false;
1372 txq = priv->txq + index;
1373 tx = txq->tx_desc_area + txq->tx_tail;
1375 BUG_ON(txq->tx_skb[txq->tx_tail].skb != NULL);
1378 * Append HW DMA header to start of packet. Drop packet if
1379 * there is not enough space or a failure to unshare/unclone
1382 skb = mwl8k_add_dma_header(skb);
1385 printk(KERN_DEBUG "%s: failed to prepend HW DMA "
1386 "header, dropping TX frame.\n", priv->name);
1387 dev_kfree_skb(org_skb);
1388 return NETDEV_TX_OK;
1391 tx_info = IEEE80211_SKB_CB(skb);
1392 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1393 tr = (struct mwl8k_dma_data *)skb->data;
1395 fc = wh->frame_control;
1396 qosframe = ieee80211_is_data_qos(fc);
1397 mcframe = is_multicast_ether_addr(wh->addr1);
1398 ampduframe = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
1400 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1401 u16 seqno = mwl8k_vif->seqno;
1402 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1403 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1404 mwl8k_vif->seqno = seqno++ % 4096;
1408 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1410 dma = pci_map_single(priv->pdev, skb->data,
1411 skb->len, PCI_DMA_TODEVICE);
1413 if (pci_dma_mapping_error(priv->pdev, dma)) {
1414 printk(KERN_DEBUG "%s: failed to dma map skb, "
1415 "dropping TX frame.\n", priv->name);
1417 if (org_skb != NULL)
1418 dev_kfree_skb(org_skb);
1421 return NETDEV_TX_OK;
1424 /* Set desc header, cpu bit order. */
1427 tx->tx_priority = index;
1428 tx->qos_control = 0;
1430 tx->peer_id = mwl8k_vif->peer_id;
1432 amsduframe = !!(qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT);
1434 /* Setup firmware control bit fields for each frame type. */
1435 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) {
1437 qos = mwl8k_qos_setbit_eosp(qos);
1438 /* Set Queue size to unspecified */
1439 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1440 } else if (ieee80211_is_data(fc)) {
1443 tx->status |= MWL8K_TXD_STATUS_MULTICAST_TX;
1446 * Tell firmware to not send EAPOL pkts in an
1447 * aggregate. Verify against mac80211 tx path. If
1448 * stack turns off AMPDU for an EAPOL frame this
1449 * check will be removed.
1452 qos = mwl8k_qos_setbit_ack(qos,
1453 MWL8K_TXD_ACK_POLICY_NORMAL);
1455 /* Send pkt in an aggregate if AMPDU frame. */
1457 qos = mwl8k_qos_setbit_ack(qos,
1458 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1460 qos = mwl8k_qos_setbit_ack(qos,
1461 MWL8K_TXD_ACK_POLICY_NORMAL);
1464 qos = mwl8k_qos_setbit_amsdu(qos);
1468 /* Convert to little endian */
1469 tx->qos_control = cpu_to_le16(qos);
1470 tx->status = cpu_to_le32(tx->status);
1471 tx->pkt_phys_addr = cpu_to_le32(dma);
1472 tx->pkt_len = cpu_to_le16(skb->len);
1474 txq->tx_skb[txq->tx_tail].skb = skb;
1475 txq->tx_skb[txq->tx_tail].clone =
1476 skb == org_skb ? NULL : org_skb;
1478 spin_lock_bh(&priv->tx_lock);
1480 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_OK |
1481 MWL8K_TXD_STATUS_FW_OWNED);
1483 txq->tx_stats.len++;
1484 priv->pending_tx_pkts++;
1485 txq->tx_stats.count++;
1488 if (txq->tx_tail == MWL8K_TX_DESCS)
1490 if (txq->tx_head == txq->tx_tail)
1491 ieee80211_stop_queue(hw, index);
1493 if (priv->inconfig) {
1495 * Silently queue packet when we are in the middle of
1496 * a config cycle. Notify firmware only if we are
1497 * waiting for TXQs to empty. If a packet is sent
1498 * before .config() is complete, perhaps it is better
1499 * to drop the packet, as the channel is being changed
1500 * and the packet will end up on the wrong channel.
1502 printk(KERN_ERR "%s(): WARNING TX activity while "
1503 "in config\n", __func__);
1505 if (priv->tx_wait != NULL)
1506 mwl8k_tx_start(priv);
1508 mwl8k_tx_start(priv);
1510 spin_unlock_bh(&priv->tx_lock);
1512 return NETDEV_TX_OK;
1517 * Command processing.
1520 /* Timeout firmware commands after 2000ms */
1521 #define MWL8K_CMD_TIMEOUT_MS 2000
1523 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1525 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1526 struct mwl8k_priv *priv = hw->priv;
1527 void __iomem *regs = priv->regs;
1528 dma_addr_t dma_addr;
1529 unsigned int dma_size;
1531 u16 __iomem *result;
1532 unsigned long timeout = 0;
1535 cmd->result = 0xFFFF;
1536 dma_size = le16_to_cpu(cmd->length);
1537 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1538 PCI_DMA_BIDIRECTIONAL);
1539 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1542 if (priv->hostcmd_wait != NULL)
1543 printk(KERN_ERR "WARNING host command in progress\n");
1545 spin_lock_irq(&priv->fw_lock);
1546 priv->hostcmd_wait = &cmd_wait;
1547 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1548 iowrite32(MWL8K_H2A_INT_DOORBELL,
1549 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1550 iowrite32(MWL8K_H2A_INT_DUMMY,
1551 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1552 spin_unlock_irq(&priv->fw_lock);
1554 timeout = wait_for_completion_timeout(&cmd_wait,
1555 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1557 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1558 PCI_DMA_BIDIRECTIONAL);
1560 result = &cmd->result;
1562 spin_lock_irq(&priv->fw_lock);
1563 priv->hostcmd_wait = NULL;
1564 spin_unlock_irq(&priv->fw_lock);
1565 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1567 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1568 MWL8K_CMD_TIMEOUT_MS);
1571 rc = *result ? -EINVAL : 0;
1573 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1575 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1585 struct mwl8k_cmd_get_hw_spec {
1586 struct mwl8k_cmd_pkt header;
1588 __u8 host_interface;
1590 __u8 perm_addr[IEEE80211_ADDR_LEN];
1595 __u8 mcs_bitmap[16];
1596 __le32 rx_queue_ptr;
1597 __le32 num_tx_queues;
1598 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1600 __le32 num_tx_desc_per_queue;
1601 __le32 total_rx_desc;
1602 } __attribute__((packed));
1604 static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
1606 struct mwl8k_priv *priv = hw->priv;
1607 struct mwl8k_cmd_get_hw_spec *cmd;
1611 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1615 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1616 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1618 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1619 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1620 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rx_desc_dma);
1621 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1622 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1623 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].tx_desc_dma);
1624 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1625 cmd->total_rx_desc = cpu_to_le32(MWL8K_RX_DESCS);
1627 rc = mwl8k_post_cmd(hw, &cmd->header);
1630 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1631 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1632 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1633 priv->hw_rev = cmd->hw_rev;
1641 * CMD_MAC_MULTICAST_ADR.
1643 struct mwl8k_cmd_mac_multicast_adr {
1644 struct mwl8k_cmd_pkt header;
1647 __u8 addr[1][IEEE80211_ADDR_LEN];
1650 #define MWL8K_ENABLE_RX_MULTICAST 0x000F
1651 static int mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
1653 struct dev_addr_list *mclist)
1655 struct mwl8k_cmd_mac_multicast_adr *cmd;
1658 int size = sizeof(*cmd) + ((mc_count - 1) * IEEE80211_ADDR_LEN);
1659 cmd = kzalloc(size, GFP_KERNEL);
1663 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1664 cmd->header.length = cpu_to_le16(size);
1665 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1666 cmd->numaddr = cpu_to_le16(mc_count);
1667 while ((index < mc_count) && mclist) {
1668 if (mclist->da_addrlen != IEEE80211_ADDR_LEN) {
1670 goto mwl8k_cmd_mac_multicast_adr_exit;
1672 memcpy(cmd->addr[index], mclist->da_addr, IEEE80211_ADDR_LEN);
1674 mclist = mclist->next;
1677 rc = mwl8k_post_cmd(hw, &cmd->header);
1679 mwl8k_cmd_mac_multicast_adr_exit:
1685 * CMD_802_11_GET_STAT.
1687 struct mwl8k_cmd_802_11_get_stat {
1688 struct mwl8k_cmd_pkt header;
1691 } __attribute__((packed));
1693 #define MWL8K_STAT_ACK_FAILURE 9
1694 #define MWL8K_STAT_RTS_FAILURE 12
1695 #define MWL8K_STAT_FCS_ERROR 24
1696 #define MWL8K_STAT_RTS_SUCCESS 11
1698 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1699 struct ieee80211_low_level_stats *stats)
1701 struct mwl8k_cmd_802_11_get_stat *cmd;
1704 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1708 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1709 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1710 cmd->action = cpu_to_le16(MWL8K_CMD_GET);
1712 rc = mwl8k_post_cmd(hw, &cmd->header);
1714 stats->dot11ACKFailureCount =
1715 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1716 stats->dot11RTSFailureCount =
1717 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1718 stats->dot11FCSErrorCount =
1719 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1720 stats->dot11RTSSuccessCount =
1721 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1729 * CMD_802_11_RADIO_CONTROL.
1731 struct mwl8k_cmd_802_11_radio_control {
1732 struct mwl8k_cmd_pkt header;
1736 } __attribute__((packed));
1738 static int mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, int enable)
1740 struct mwl8k_priv *priv = hw->priv;
1741 struct mwl8k_cmd_802_11_radio_control *cmd;
1744 if (((enable & MWL8K_RADIO_ENABLE) == priv->radio_state) &&
1745 !(enable & MWL8K_RADIO_FORCE))
1748 enable &= MWL8K_RADIO_ENABLE;
1750 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1754 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1755 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1756 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1757 cmd->control = cpu_to_le16(priv->radio_preamble);
1758 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1760 rc = mwl8k_post_cmd(hw, &cmd->header);
1764 priv->radio_state = enable;
1770 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1772 struct mwl8k_priv *priv;
1774 if (hw == NULL || hw->priv == NULL)
1778 priv->radio_preamble = (short_preamble ?
1779 MWL8K_RADIO_SHORT_PREAMBLE :
1780 MWL8K_RADIO_LONG_PREAMBLE);
1782 return mwl8k_cmd_802_11_radio_control(hw,
1783 MWL8K_RADIO_ENABLE | MWL8K_RADIO_FORCE);
1787 * CMD_802_11_RF_TX_POWER.
1789 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1791 struct mwl8k_cmd_802_11_rf_tx_power {
1792 struct mwl8k_cmd_pkt header;
1794 __le16 support_level;
1795 __le16 current_level;
1797 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1798 } __attribute__((packed));
1800 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1802 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1805 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1809 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1810 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1811 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1812 cmd->support_level = cpu_to_le16(dBm);
1814 rc = mwl8k_post_cmd(hw, &cmd->header);
1823 struct mwl8k_cmd_set_pre_scan {
1824 struct mwl8k_cmd_pkt header;
1825 } __attribute__((packed));
1827 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
1829 struct mwl8k_cmd_set_pre_scan *cmd;
1832 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1836 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
1837 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1839 rc = mwl8k_post_cmd(hw, &cmd->header);
1846 * CMD_SET_POST_SCAN.
1848 struct mwl8k_cmd_set_post_scan {
1849 struct mwl8k_cmd_pkt header;
1851 __u8 bssid[IEEE80211_ADDR_LEN];
1852 } __attribute__((packed));
1855 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 mac[IEEE80211_ADDR_LEN])
1857 struct mwl8k_cmd_set_post_scan *cmd;
1860 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1864 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
1865 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1867 memcpy(cmd->bssid, mac, IEEE80211_ADDR_LEN);
1869 rc = mwl8k_post_cmd(hw, &cmd->header);
1876 * CMD_SET_RF_CHANNEL.
1878 struct mwl8k_cmd_set_rf_channel {
1879 struct mwl8k_cmd_pkt header;
1881 __u8 current_channel;
1882 __le32 channel_flags;
1883 } __attribute__((packed));
1885 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
1886 struct ieee80211_channel *channel)
1888 struct mwl8k_cmd_set_rf_channel *cmd;
1891 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1895 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
1896 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1897 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1898 cmd->current_channel = channel->hw_value;
1899 if (channel->band == IEEE80211_BAND_2GHZ)
1900 cmd->channel_flags = cpu_to_le32(0x00000081);
1902 cmd->channel_flags = cpu_to_le32(0x00000000);
1904 rc = mwl8k_post_cmd(hw, &cmd->header);
1913 struct mwl8k_cmd_set_slot {
1914 struct mwl8k_cmd_pkt header;
1917 } __attribute__((packed));
1919 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, int slot_time)
1921 struct mwl8k_cmd_set_slot *cmd;
1924 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1928 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
1929 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1930 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1931 cmd->short_slot = slot_time == MWL8K_SHORT_SLOTTIME ? 1 : 0;
1933 rc = mwl8k_post_cmd(hw, &cmd->header);
1942 struct mwl8k_cmd_mimo_config {
1943 struct mwl8k_cmd_pkt header;
1945 __u8 rx_antenna_map;
1946 __u8 tx_antenna_map;
1947 } __attribute__((packed));
1949 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
1951 struct mwl8k_cmd_mimo_config *cmd;
1954 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1958 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
1959 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1960 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
1961 cmd->rx_antenna_map = rx;
1962 cmd->tx_antenna_map = tx;
1964 rc = mwl8k_post_cmd(hw, &cmd->header);
1971 * CMD_ENABLE_SNIFFER.
1973 struct mwl8k_cmd_enable_sniffer {
1974 struct mwl8k_cmd_pkt header;
1976 } __attribute__((packed));
1978 static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
1980 struct mwl8k_cmd_enable_sniffer *cmd;
1983 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1987 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
1988 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1989 cmd->action = enable ? cpu_to_le32((u32)MWL8K_CMD_SET) : 0;
1991 rc = mwl8k_post_cmd(hw, &cmd->header);
1998 * CMD_SET_RATE_ADAPT_MODE.
2000 struct mwl8k_cmd_set_rate_adapt_mode {
2001 struct mwl8k_cmd_pkt header;
2004 } __attribute__((packed));
2006 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2008 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2011 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2015 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2016 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2017 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2018 cmd->mode = cpu_to_le16(mode);
2020 rc = mwl8k_post_cmd(hw, &cmd->header);
2029 struct mwl8k_cmd_set_wmm {
2030 struct mwl8k_cmd_pkt header;
2032 } __attribute__((packed));
2034 static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2036 struct mwl8k_priv *priv = hw->priv;
2037 struct mwl8k_cmd_set_wmm *cmd;
2040 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2044 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2045 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2046 cmd->action = enable ? cpu_to_le16(MWL8K_CMD_SET) : 0;
2048 rc = mwl8k_post_cmd(hw, &cmd->header);
2052 priv->wmm_mode = enable;
2058 * CMD_SET_RTS_THRESHOLD.
2060 struct mwl8k_cmd_rts_threshold {
2061 struct mwl8k_cmd_pkt header;
2064 } __attribute__((packed));
2066 static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
2067 u16 action, u16 *threshold)
2069 struct mwl8k_cmd_rts_threshold *cmd;
2072 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2076 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2077 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2078 cmd->action = cpu_to_le16(action);
2079 cmd->threshold = cpu_to_le16(*threshold);
2081 rc = mwl8k_post_cmd(hw, &cmd->header);
2088 * CMD_SET_EDCA_PARAMS.
2090 struct mwl8k_cmd_set_edca_params {
2091 struct mwl8k_cmd_pkt header;
2093 /* See MWL8K_SET_EDCA_XXX below */
2096 /* TX opportunity in units of 32 us */
2099 /* Log exponent of max contention period: 0...15*/
2102 /* Log exponent of min contention period: 0...15 */
2105 /* Adaptive interframe spacing in units of 32us */
2108 /* TX queue to configure */
2110 } __attribute__((packed));
2112 #define MWL8K_SET_EDCA_CW 0x01
2113 #define MWL8K_SET_EDCA_TXOP 0x02
2114 #define MWL8K_SET_EDCA_AIFS 0x04
2116 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2117 MWL8K_SET_EDCA_TXOP | \
2118 MWL8K_SET_EDCA_AIFS)
2121 mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2122 __u16 cw_min, __u16 cw_max,
2123 __u8 aifs, __u16 txop)
2125 struct mwl8k_cmd_set_edca_params *cmd;
2126 u32 log_cw_min, log_cw_max;
2129 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2133 log_cw_min = ilog2(cw_min+1);
2134 log_cw_max = ilog2(cw_max+1);
2135 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2136 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2138 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2139 cmd->txop = cpu_to_le16(txop);
2140 cmd->log_cw_max = (u8)log_cw_max;
2141 cmd->log_cw_min = (u8)log_cw_min;
2145 rc = mwl8k_post_cmd(hw, &cmd->header);
2152 * CMD_FINALIZE_JOIN.
2155 /* FJ beacon buffer size is compiled into the firmware. */
2156 #define MWL8K_FJ_BEACON_MAXLEN 128
2158 struct mwl8k_cmd_finalize_join {
2159 struct mwl8k_cmd_pkt header;
2160 __le32 sleep_interval; /* Number of beacon periods to sleep */
2161 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2162 } __attribute__((packed));
2164 static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2165 __u16 framelen, __u16 dtim)
2167 struct mwl8k_cmd_finalize_join *cmd;
2168 struct ieee80211_mgmt *payload = frame;
2176 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2180 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2181 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2184 cmd->sleep_interval = cpu_to_le32(dtim);
2186 cmd->sleep_interval = cpu_to_le32(1);
2188 hdrlen = ieee80211_hdrlen(payload->frame_control);
2190 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2192 /* XXX TBD Might just have to abort and return an error */
2193 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2194 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
2195 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2196 payload_len, MWL8K_FJ_BEACON_MAXLEN);
2198 payload_len = payload_len > MWL8K_FJ_BEACON_MAXLEN ?
2199 MWL8K_FJ_BEACON_MAXLEN : payload_len;
2201 if (payload && payload_len)
2202 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2204 rc = mwl8k_post_cmd(hw, &cmd->header);
2212 struct mwl8k_cmd_update_sta_db {
2213 struct mwl8k_cmd_pkt header;
2215 /* See STADB_ACTION_TYPE */
2218 /* Peer MAC address */
2219 __u8 peer_addr[IEEE80211_ADDR_LEN];
2223 /* Peer info - valid during add/update. */
2224 struct peer_capability_info peer_info;
2225 } __attribute__((packed));
2227 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2228 struct ieee80211_vif *vif, __u32 action)
2230 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2231 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2232 struct mwl8k_cmd_update_sta_db *cmd;
2233 struct peer_capability_info *peer_info;
2234 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2238 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2242 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2243 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2245 cmd->action = cpu_to_le32(action);
2246 peer_info = &cmd->peer_info;
2247 memcpy(cmd->peer_addr, mv_vif->bssid, IEEE80211_ADDR_LEN);
2250 case MWL8K_STA_DB_ADD_ENTRY:
2251 case MWL8K_STA_DB_MODIFY_ENTRY:
2252 /* Build peer_info block */
2253 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2254 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2255 peer_info->interop = 1;
2256 peer_info->amsdu_enabled = 0;
2258 rates = peer_info->legacy_rates;
2259 for (count = 0 ; count < mv_vif->legacy_nrates; count++)
2260 rates[count] = bitrates[count].hw_value;
2262 rc = mwl8k_post_cmd(hw, &cmd->header);
2264 mv_vif->peer_id = peer_info->station_id;
2268 case MWL8K_STA_DB_DEL_ENTRY:
2269 case MWL8K_STA_DB_FLUSH:
2271 rc = mwl8k_post_cmd(hw, &cmd->header);
2273 mv_vif->peer_id = 0;
2284 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2286 #define MWL8K_FRAME_PROT_DISABLED 0x00
2287 #define MWL8K_FRAME_PROT_11G 0x07
2288 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2289 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2291 struct mwl8k_cmd_update_set_aid {
2292 struct mwl8k_cmd_pkt header;
2295 /* AP's MAC address (BSSID) */
2296 __u8 bssid[IEEE80211_ADDR_LEN];
2297 __le16 protection_mode;
2298 __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2299 } __attribute__((packed));
2301 static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2302 struct ieee80211_vif *vif)
2304 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2305 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2306 struct mwl8k_cmd_update_set_aid *cmd;
2307 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2312 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2316 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2317 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2318 cmd->aid = cpu_to_le16(info->aid);
2320 memcpy(cmd->bssid, mv_vif->bssid, IEEE80211_ADDR_LEN);
2322 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2324 if (info->use_cts_prot) {
2325 prot_mode = MWL8K_FRAME_PROT_11G;
2327 switch (info->ht_operation_mode &
2328 IEEE80211_HT_OP_MODE_PROTECTION) {
2329 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2330 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2332 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2333 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2336 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2341 cmd->protection_mode = cpu_to_le16(prot_mode);
2343 for (count = 0; count < mv_vif->legacy_nrates; count++)
2344 cmd->supp_rates[count] = bitrates[count].hw_value;
2346 rc = mwl8k_post_cmd(hw, &cmd->header);
2355 struct mwl8k_cmd_update_rateset {
2356 struct mwl8k_cmd_pkt header;
2357 __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2359 /* Bitmap for supported MCS codes. */
2360 __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
2361 __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
2362 } __attribute__((packed));
2364 static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2365 struct ieee80211_vif *vif)
2367 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2368 struct mwl8k_cmd_update_rateset *cmd;
2369 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2373 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2377 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2378 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2380 for (count = 0; count < mv_vif->legacy_nrates; count++)
2381 cmd->legacy_rates[count] = bitrates[count].hw_value;
2383 rc = mwl8k_post_cmd(hw, &cmd->header);
2390 * CMD_USE_FIXED_RATE.
2392 #define MWL8K_RATE_TABLE_SIZE 8
2393 #define MWL8K_UCAST_RATE 0
2394 #define MWL8K_USE_AUTO_RATE 0x0002
2396 struct mwl8k_rate_entry {
2397 /* Set to 1 if HT rate, 0 if legacy. */
2400 /* Set to 1 to use retry_count field. */
2401 __le32 enable_retry;
2403 /* Specified legacy rate or MCS. */
2406 /* Number of allowed retries. */
2408 } __attribute__((packed));
2410 struct mwl8k_rate_table {
2411 /* 1 to allow specified rate and below */
2412 __le32 allow_rate_drop;
2414 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2415 } __attribute__((packed));
2417 struct mwl8k_cmd_use_fixed_rate {
2418 struct mwl8k_cmd_pkt header;
2420 struct mwl8k_rate_table rate_table;
2422 /* Unicast, Broadcast or Multicast */
2426 } __attribute__((packed));
2428 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2429 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2431 struct mwl8k_cmd_use_fixed_rate *cmd;
2435 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2439 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2440 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2442 cmd->action = cpu_to_le32(action);
2443 cmd->rate_type = cpu_to_le32(rate_type);
2445 if (rate_table != NULL) {
2446 /* Copy over each field manually so
2447 * that bitflipping can be done
2449 cmd->rate_table.allow_rate_drop =
2450 cpu_to_le32(rate_table->allow_rate_drop);
2451 cmd->rate_table.num_rates =
2452 cpu_to_le32(rate_table->num_rates);
2454 for (count = 0; count < rate_table->num_rates; count++) {
2455 struct mwl8k_rate_entry *dst =
2456 &cmd->rate_table.rate_entry[count];
2457 struct mwl8k_rate_entry *src =
2458 &rate_table->rate_entry[count];
2460 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2461 dst->enable_retry = cpu_to_le32(src->enable_retry);
2462 dst->rate = cpu_to_le32(src->rate);
2463 dst->retry_count = cpu_to_le32(src->retry_count);
2467 rc = mwl8k_post_cmd(hw, &cmd->header);
2475 * Interrupt handling.
2477 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2479 struct ieee80211_hw *hw = dev_id;
2480 struct mwl8k_priv *priv = hw->priv;
2483 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2484 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2489 if (status & MWL8K_A2H_INT_TX_DONE)
2490 tasklet_schedule(&priv->tx_reclaim_task);
2492 if (status & MWL8K_A2H_INT_RX_READY) {
2493 while (rxq_process(hw, 0, 1))
2494 rxq_refill(hw, 0, 1);
2497 if (status & MWL8K_A2H_INT_OPC_DONE) {
2498 if (priv->hostcmd_wait != NULL) {
2499 complete(priv->hostcmd_wait);
2500 priv->hostcmd_wait = NULL;
2504 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
2505 if (!priv->inconfig &&
2506 priv->radio_state &&
2507 mwl8k_txq_busy(priv))
2508 mwl8k_tx_start(priv);
2516 * Core driver operations.
2518 static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2520 struct mwl8k_priv *priv = hw->priv;
2521 int index = skb_get_queue_mapping(skb);
2524 if (priv->current_channel == NULL) {
2525 printk(KERN_DEBUG "%s: dropped TX frame since radio "
2526 "disabled\n", priv->name);
2528 return NETDEV_TX_OK;
2531 rc = mwl8k_txq_xmit(hw, index, skb);
2536 struct mwl8k_work_struct {
2537 /* Initialized by mwl8k_queue_work(). */
2538 struct work_struct wt;
2540 /* Required field passed in to mwl8k_queue_work(). */
2541 struct ieee80211_hw *hw;
2543 /* Required field passed in to mwl8k_queue_work(). */
2544 int (*wfunc)(struct work_struct *w);
2546 /* Initialized by mwl8k_queue_work(). */
2547 struct completion *cmd_wait;
2553 * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
2554 * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
2558 /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
2559 unsigned long timeout_ms;
2561 /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
2562 u32 txwait_attempts;
2564 /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
2569 /* Flags controlling behavior of config queue requests */
2571 /* Caller spins while waiting for completion. */
2572 #define MWL8K_WQ_SPIN 0x00000001
2574 /* Wait for TX queues to empty before proceeding with configuration. */
2575 #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
2577 /* Queue request and return immediately. */
2578 #define MWL8K_WQ_POST_REQUEST 0x00000004
2581 * Caller sleeps and waits for task complete notification.
2582 * Do not use in atomic context.
2584 #define MWL8K_WQ_SLEEP 0x00000008
2586 /* Free work struct when task is done. */
2587 #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
2590 * Config request is queued and returns to caller imediately. Use
2591 * this in atomic context. Work struct is freed by mwl8k_queue_work()
2592 * when this flag is set.
2594 #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
2595 MWL8K_WQ_FREE_WORKSTRUCT)
2597 /* Default work queue behavior is to sleep and wait for tx completion. */
2598 #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
2601 * Default config request timeout. Add adjustments to make sure the
2602 * config thread waits long enough for both tx wait and cmd wait before
2606 /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
2607 #define MWL8K_TXWAIT_TIMEOUT_MS 1000
2609 /* Default number of TX wait attempts. */
2610 #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
2612 /* Total time to wait for TXQ to drain. */
2613 #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
2614 MWL8K_WQ_TXWAIT_ATTEMPTS)
2616 /* Scheduling slop. */
2617 #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
2619 #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
2621 MWL8K_OS_SCHEDULE_OVERHEAD_MS)
2623 static void mwl8k_config_thread(struct work_struct *wt)
2625 struct mwl8k_work_struct *worker = (struct mwl8k_work_struct *)wt;
2626 struct ieee80211_hw *hw = worker->hw;
2627 struct mwl8k_priv *priv = hw->priv;
2630 spin_lock_irq(&priv->tx_lock);
2631 priv->inconfig = true;
2632 spin_unlock_irq(&priv->tx_lock);
2634 ieee80211_stop_queues(hw);
2637 * Wait for host queues to drain before doing PHY
2638 * reconfiguration. This avoids interrupting any in-flight
2639 * DMA transfers to the hardware.
2641 if (worker->options & MWL8K_WQ_TX_WAIT_EMPTY) {
2645 u32 tx_wait_attempts = worker->txwait_attempts;
2647 time_remaining = worker->tx_timeout_ms;
2648 if (!tx_wait_attempts)
2649 tx_wait_attempts = 1;
2651 timeout = worker->tx_timeout_ms/tx_wait_attempts;
2655 iter = tx_wait_attempts;
2659 if (time_remaining > timeout) {
2660 time_remaining -= timeout;
2661 wait_time = timeout;
2663 wait_time = time_remaining;
2668 rc = mwl8k_tx_wait_empty(hw, wait_time);
2670 printk(KERN_ERR "%s() txwait timeout=%ums "
2671 "Retry:%u/%u\n", __func__, timeout,
2672 tx_wait_attempts - iter + 1,
2675 } while (rc && --iter);
2677 rc = iter ? 0 : -ETIMEDOUT;
2680 rc = worker->wfunc(wt);
2682 spin_lock_irq(&priv->tx_lock);
2683 priv->inconfig = false;
2684 if (priv->pending_tx_pkts && priv->radio_state)
2685 mwl8k_tx_start(priv);
2686 spin_unlock_irq(&priv->tx_lock);
2687 ieee80211_wake_queues(hw);
2690 if (worker->options & MWL8K_WQ_SLEEP)
2691 complete(worker->cmd_wait);
2693 if (worker->options & MWL8K_WQ_FREE_WORKSTRUCT)
2697 static int mwl8k_queue_work(struct ieee80211_hw *hw,
2698 struct mwl8k_work_struct *worker,
2699 struct workqueue_struct *wqueue,
2700 int (*wfunc)(struct work_struct *w))
2702 unsigned long timeout = 0;
2705 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2707 if (!worker->timeout_ms)
2708 worker->timeout_ms = MWL8K_CONFIG_TIMEOUT_MS;
2710 if (!worker->options)
2711 worker->options = MWL8K_WQ_DEFAULT_OPTIONS;
2713 if (!worker->txwait_attempts)
2714 worker->txwait_attempts = MWL8K_WQ_TXWAIT_ATTEMPTS;
2716 if (!worker->tx_timeout_ms)
2717 worker->tx_timeout_ms = MWL8K_TXWAIT_MS;
2720 worker->cmd_wait = &cmd_wait;
2722 worker->wfunc = wfunc;
2724 INIT_WORK(&worker->wt, mwl8k_config_thread);
2725 queue_work(wqueue, &worker->wt);
2727 if (worker->options & MWL8K_WQ_POST_REQUEST) {
2730 if (worker->options & MWL8K_WQ_SPIN) {
2731 timeout = worker->timeout_ms;
2732 while (timeout && (worker->rc > 0)) {
2736 } else if (worker->options & MWL8K_WQ_SLEEP)
2737 timeout = wait_for_completion_timeout(&cmd_wait,
2738 msecs_to_jiffies(worker->timeout_ms));
2743 cancel_work_sync(&worker->wt);
2751 struct mwl8k_start_worker {
2752 struct mwl8k_work_struct header;
2755 static int mwl8k_start_wt(struct work_struct *wt)
2757 struct mwl8k_start_worker *worker = (struct mwl8k_start_worker *)wt;
2758 struct ieee80211_hw *hw = worker->header.hw;
2759 struct mwl8k_priv *priv = hw->priv;
2762 if (priv->vif != NULL) {
2764 goto mwl8k_start_exit;
2768 if (mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_ENABLE)) {
2770 goto mwl8k_start_exit;
2773 /* Purge TX/RX HW queues */
2774 if (mwl8k_cmd_set_pre_scan(hw)) {
2776 goto mwl8k_start_exit;
2779 if (mwl8k_cmd_set_post_scan(hw, "\x00\x00\x00\x00\x00\x00")) {
2781 goto mwl8k_start_exit;
2784 /* Enable firmware rate adaptation */
2785 if (mwl8k_cmd_setrateadaptmode(hw, 0)) {
2787 goto mwl8k_start_exit;
2790 /* Disable WMM. WMM gets enabled when stack sends WMM parms */
2791 if (mwl8k_set_wmm(hw, MWL8K_WMM_DISABLE)) {
2793 goto mwl8k_start_exit;
2796 /* Disable sniffer mode */
2797 if (mwl8k_enable_sniffer(hw, 0))
2804 static int mwl8k_start(struct ieee80211_hw *hw)
2806 struct mwl8k_start_worker *worker;
2807 struct mwl8k_priv *priv = hw->priv;
2810 /* Enable tx reclaim tasklet */
2811 tasklet_enable(&priv->tx_reclaim_task);
2813 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
2814 IRQF_SHARED, MWL8K_NAME, hw);
2816 printk(KERN_ERR "%s: failed to register IRQ handler\n",
2819 goto mwl8k_start_disable_tasklet;
2822 /* Enable interrupts */
2823 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2825 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2826 if (worker == NULL) {
2828 goto mwl8k_start_disable_irq;
2831 rc = mwl8k_queue_work(hw, &worker->header,
2832 priv->config_wq, mwl8k_start_wt);
2837 if (rc == -ETIMEDOUT)
2838 printk(KERN_ERR "%s() timed out\n", __func__);
2842 mwl8k_start_disable_irq:
2843 spin_lock_irq(&priv->tx_lock);
2844 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2845 spin_unlock_irq(&priv->tx_lock);
2846 free_irq(priv->pdev->irq, hw);
2848 mwl8k_start_disable_tasklet:
2849 tasklet_disable(&priv->tx_reclaim_task);
2854 struct mwl8k_stop_worker {
2855 struct mwl8k_work_struct header;
2858 static int mwl8k_stop_wt(struct work_struct *wt)
2860 struct mwl8k_stop_worker *worker = (struct mwl8k_stop_worker *)wt;
2861 struct ieee80211_hw *hw = worker->header.hw;
2864 rc = mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
2869 static void mwl8k_stop(struct ieee80211_hw *hw)
2872 struct mwl8k_stop_worker *worker;
2873 struct mwl8k_priv *priv = hw->priv;
2876 if (priv->vif != NULL)
2879 ieee80211_stop_queues(hw);
2881 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
2885 rc = mwl8k_queue_work(hw, &worker->header,
2886 priv->config_wq, mwl8k_stop_wt);
2888 if (rc == -ETIMEDOUT)
2889 printk(KERN_ERR "%s() timed out\n", __func__);
2891 /* Disable interrupts */
2892 spin_lock_irq(&priv->tx_lock);
2893 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2894 spin_unlock_irq(&priv->tx_lock);
2895 free_irq(priv->pdev->irq, hw);
2897 /* Stop finalize join worker */
2898 cancel_work_sync(&priv->finalize_join_worker);
2899 if (priv->beacon_skb != NULL)
2900 dev_kfree_skb(priv->beacon_skb);
2902 /* Stop tx reclaim tasklet */
2903 tasklet_disable(&priv->tx_reclaim_task);
2905 /* Stop config thread */
2906 flush_workqueue(priv->config_wq);
2908 /* Return all skbs to mac80211 */
2909 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2910 mwl8k_txq_reclaim(hw, i, 1);
2913 static int mwl8k_add_interface(struct ieee80211_hw *hw,
2914 struct ieee80211_if_init_conf *conf)
2916 struct mwl8k_priv *priv = hw->priv;
2917 struct mwl8k_vif *mwl8k_vif;
2920 * We only support one active interface at a time.
2922 if (priv->vif != NULL)
2926 * We only support managed interfaces for now.
2928 if (conf->type != NL80211_IFTYPE_STATION &&
2929 conf->type != NL80211_IFTYPE_MONITOR)
2932 /* Clean out driver private area */
2933 mwl8k_vif = MWL8K_VIF(conf->vif);
2934 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2936 /* Save the mac address */
2937 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, IEEE80211_ADDR_LEN);
2939 /* Back pointer to parent config block */
2940 mwl8k_vif->priv = priv;
2942 /* Setup initial PHY parameters */
2943 memcpy(mwl8k_vif->legacy_rates ,
2944 priv->rates, sizeof(mwl8k_vif->legacy_rates));
2945 mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
2947 /* Set Initial sequence number to zero */
2948 mwl8k_vif->seqno = 0;
2950 priv->vif = conf->vif;
2951 priv->current_channel = NULL;
2956 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2957 struct ieee80211_if_init_conf *conf)
2959 struct mwl8k_priv *priv = hw->priv;
2961 if (priv->vif == NULL)
2967 struct mwl8k_config_worker {
2968 struct mwl8k_work_struct header;
2972 static int mwl8k_config_wt(struct work_struct *wt)
2974 struct mwl8k_config_worker *worker =
2975 (struct mwl8k_config_worker *)wt;
2976 struct ieee80211_hw *hw = worker->header.hw;
2977 struct ieee80211_conf *conf = &hw->conf;
2978 struct mwl8k_priv *priv = hw->priv;
2981 if (mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_ENABLE)) {
2983 goto mwl8k_config_exit;
2986 priv->current_channel = conf->channel;
2988 if (mwl8k_cmd_set_rf_channel(hw, conf->channel)) {
2990 goto mwl8k_config_exit;
2993 if (conf->power_level > 18)
2994 conf->power_level = 18;
2995 if (mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level)) {
2997 goto mwl8k_config_exit;
3000 if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
3007 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
3010 struct mwl8k_config_worker *worker;
3011 struct mwl8k_priv *priv = hw->priv;
3013 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3017 worker->changed = changed;
3018 rc = mwl8k_queue_work(hw, &worker->header,
3019 priv->config_wq, mwl8k_config_wt);
3020 if (rc == -ETIMEDOUT) {
3021 printk(KERN_ERR "%s() timed out.\n", __func__);
3028 * mac80211 will crash on anything other than -EINVAL on
3029 * error. Looks like wireless extensions which calls mac80211
3030 * may be the actual culprit...
3032 return rc ? -EINVAL : 0;
3035 struct mwl8k_bss_info_changed_worker {
3036 struct mwl8k_work_struct header;
3037 struct ieee80211_vif *vif;
3038 struct ieee80211_bss_conf *info;
3042 static int mwl8k_bss_info_changed_wt(struct work_struct *wt)
3044 struct mwl8k_bss_info_changed_worker *worker =
3045 (struct mwl8k_bss_info_changed_worker *)wt;
3046 struct ieee80211_hw *hw = worker->header.hw;
3047 struct ieee80211_vif *vif = worker->vif;
3048 struct ieee80211_bss_conf *info = worker->info;
3052 struct mwl8k_priv *priv = hw->priv;
3053 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3055 changed = worker->changed;
3056 priv->capture_beacon = false;
3059 memcpy(&mwl8k_vif->bss_info, info,
3060 sizeof(struct ieee80211_bss_conf));
3063 if (mwl8k_update_rateset(hw, vif))
3064 goto mwl8k_bss_info_changed_exit;
3066 /* Turn on rate adaptation */
3067 if (mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3068 MWL8K_UCAST_RATE, NULL))
3069 goto mwl8k_bss_info_changed_exit;
3071 /* Set radio preamble */
3072 if (mwl8k_set_radio_preamble(hw,
3073 info->use_short_preamble))
3074 goto mwl8k_bss_info_changed_exit;
3077 if (mwl8k_cmd_set_slot(hw, info->use_short_slot ?
3078 MWL8K_SHORT_SLOTTIME : MWL8K_LONG_SLOTTIME))
3079 goto mwl8k_bss_info_changed_exit;
3081 /* Update peer rate info */
3082 if (mwl8k_cmd_update_sta_db(hw, vif,
3083 MWL8K_STA_DB_MODIFY_ENTRY))
3084 goto mwl8k_bss_info_changed_exit;
3087 if (mwl8k_cmd_set_aid(hw, vif))
3088 goto mwl8k_bss_info_changed_exit;
3091 * Finalize the join. Tell rx handler to process
3092 * next beacon from our BSSID.
3094 memcpy(priv->capture_bssid,
3095 mwl8k_vif->bssid, IEEE80211_ADDR_LEN);
3096 priv->capture_beacon = true;
3098 mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
3099 memset(&mwl8k_vif->bss_info, 0,
3100 sizeof(struct ieee80211_bss_conf));
3101 memset(mwl8k_vif->bssid, 0, IEEE80211_ADDR_LEN);
3104 mwl8k_bss_info_changed_exit:
3109 static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3110 struct ieee80211_vif *vif,
3111 struct ieee80211_bss_conf *info,
3114 struct mwl8k_bss_info_changed_worker *worker;
3115 struct mwl8k_priv *priv = hw->priv;
3116 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
3119 if (changed & BSS_CHANGED_BSSID)
3120 memcpy(mv_vif->bssid, info->bssid, IEEE80211_ADDR_LEN);
3122 if ((changed & BSS_CHANGED_ASSOC) == 0)
3125 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3130 worker->info = info;
3131 worker->changed = changed;
3132 rc = mwl8k_queue_work(hw, &worker->header,
3134 mwl8k_bss_info_changed_wt);
3136 if (rc == -ETIMEDOUT)
3137 printk(KERN_ERR "%s() timed out\n", __func__);
3140 struct mwl8k_configure_filter_worker {
3141 struct mwl8k_work_struct header;
3142 unsigned int changed_flags;
3143 unsigned int *total_flags;
3145 struct dev_addr_list *mclist;
3148 #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
3150 static int mwl8k_configure_filter_wt(struct work_struct *wt)
3152 struct mwl8k_configure_filter_worker *worker =
3153 (struct mwl8k_configure_filter_worker *)wt;
3155 struct ieee80211_hw *hw = worker->header.hw;
3156 unsigned int changed_flags = worker->changed_flags;
3157 unsigned int *total_flags = worker->total_flags;
3158 int mc_count = worker->mc_count;
3159 struct dev_addr_list *mclist = worker->mclist;
3161 struct mwl8k_priv *priv = hw->priv;
3164 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
3165 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
3166 rc = mwl8k_cmd_set_pre_scan(hw);
3170 bssid = "\x00\x00\x00\x00\x00\x00";
3171 if (priv->vif != NULL)
3172 bssid = MWL8K_VIF(priv->vif)->bssid;
3174 rc = mwl8k_cmd_set_post_scan(hw, bssid);
3179 goto mwl8k_configure_filter_exit;
3181 mc_count = mc_count < priv->num_mcaddrs ?
3182 mc_count : priv->num_mcaddrs;
3183 rc = mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist);
3186 "%s()Error setting multicast addresses\n",
3190 mwl8k_configure_filter_exit:
3194 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3195 int mc_count, struct dev_addr_list *mclist)
3197 struct mwl8k_configure_filter_worker *worker;
3199 worker = kzalloc(sizeof(*worker), GFP_ATOMIC);
3205 * XXX: This is _HORRIBLY_ broken!!
3207 * No locking, the mclist pointer might be invalid as soon as this
3208 * function returns, something in the list might be invalidated
3209 * once we get to the worker, etc...
3211 worker->mc_count = mc_count;
3212 worker->mclist = mclist;
3217 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3218 unsigned int changed_flags,
3219 unsigned int *total_flags,
3223 struct mwl8k_configure_filter_worker *worker = (void *)multicast;
3224 struct mwl8k_priv *priv = hw->priv;
3226 /* Clear unsupported feature flags */
3227 *total_flags &= MWL8K_SUPPORTED_IF_FLAGS;
3229 if (!(changed_flags & MWL8K_SUPPORTED_IF_FLAGS))
3235 worker->header.options = MWL8K_WQ_QUEUE_ONLY | MWL8K_WQ_TX_WAIT_EMPTY;
3236 worker->changed_flags = changed_flags;
3237 worker->total_flags = total_flags;
3239 mwl8k_queue_work(hw, &worker->header, priv->config_wq,
3240 mwl8k_configure_filter_wt);
3243 struct mwl8k_set_rts_threshold_worker {
3244 struct mwl8k_work_struct header;
3248 static int mwl8k_set_rts_threshold_wt(struct work_struct *wt)
3250 struct mwl8k_set_rts_threshold_worker *worker =
3251 (struct mwl8k_set_rts_threshold_worker *)wt;
3253 struct ieee80211_hw *hw = worker->header.hw;
3254 u16 threshold = (u16)(worker->value);
3257 rc = mwl8k_rts_threshold(hw, MWL8K_CMD_SET, &threshold);
3262 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3265 struct mwl8k_set_rts_threshold_worker *worker;
3266 struct mwl8k_priv *priv = hw->priv;
3268 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3272 worker->value = value;
3274 rc = mwl8k_queue_work(hw, &worker->header,
3276 mwl8k_set_rts_threshold_wt);
3279 if (rc == -ETIMEDOUT) {
3280 printk(KERN_ERR "%s() timed out\n", __func__);
3287 struct mwl8k_conf_tx_worker {
3288 struct mwl8k_work_struct header;
3290 const struct ieee80211_tx_queue_params *params;
3293 static int mwl8k_conf_tx_wt(struct work_struct *wt)
3295 struct mwl8k_conf_tx_worker *worker =
3296 (struct mwl8k_conf_tx_worker *)wt;
3298 struct ieee80211_hw *hw = worker->header.hw;
3299 u16 queue = worker->queue;
3300 const struct ieee80211_tx_queue_params *params = worker->params;
3302 struct mwl8k_priv *priv = hw->priv;
3305 if (priv->wmm_mode == MWL8K_WMM_DISABLE)
3306 if (mwl8k_set_wmm(hw, MWL8K_WMM_ENABLE)) {
3308 goto mwl8k_conf_tx_exit;
3311 if (mwl8k_set_edca_params(hw, GET_TXQ(queue), params->cw_min,
3312 params->cw_max, params->aifs, params->txop))
3318 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3319 const struct ieee80211_tx_queue_params *params)
3322 struct mwl8k_conf_tx_worker *worker;
3323 struct mwl8k_priv *priv = hw->priv;
3325 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3329 worker->queue = queue;
3330 worker->params = params;
3331 rc = mwl8k_queue_work(hw, &worker->header,
3332 priv->config_wq, mwl8k_conf_tx_wt);
3334 if (rc == -ETIMEDOUT) {
3335 printk(KERN_ERR "%s() timed out\n", __func__);
3341 static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3342 struct ieee80211_tx_queue_stats *stats)
3344 struct mwl8k_priv *priv = hw->priv;
3345 struct mwl8k_tx_queue *txq;
3348 spin_lock_bh(&priv->tx_lock);
3349 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3350 txq = priv->txq + index;
3351 memcpy(&stats[index], &txq->tx_stats,
3352 sizeof(struct ieee80211_tx_queue_stats));
3354 spin_unlock_bh(&priv->tx_lock);
3358 struct mwl8k_get_stats_worker {
3359 struct mwl8k_work_struct header;
3360 struct ieee80211_low_level_stats *stats;
3363 static int mwl8k_get_stats_wt(struct work_struct *wt)
3365 struct mwl8k_get_stats_worker *worker =
3366 (struct mwl8k_get_stats_worker *)wt;
3368 return mwl8k_cmd_802_11_get_stat(worker->header.hw, worker->stats);
3371 static int mwl8k_get_stats(struct ieee80211_hw *hw,
3372 struct ieee80211_low_level_stats *stats)
3375 struct mwl8k_get_stats_worker *worker;
3376 struct mwl8k_priv *priv = hw->priv;
3378 worker = kzalloc(sizeof(*worker), GFP_KERNEL);
3382 worker->stats = stats;
3383 rc = mwl8k_queue_work(hw, &worker->header,
3384 priv->config_wq, mwl8k_get_stats_wt);
3387 if (rc == -ETIMEDOUT) {
3388 printk(KERN_ERR "%s() timed out\n", __func__);
3395 static const struct ieee80211_ops mwl8k_ops = {
3397 .start = mwl8k_start,
3399 .add_interface = mwl8k_add_interface,
3400 .remove_interface = mwl8k_remove_interface,
3401 .config = mwl8k_config,
3402 .bss_info_changed = mwl8k_bss_info_changed,
3403 .prepare_multicast = mwl8k_prepare_multicast,
3404 .configure_filter = mwl8k_configure_filter,
3405 .set_rts_threshold = mwl8k_set_rts_threshold,
3406 .conf_tx = mwl8k_conf_tx,
3407 .get_tx_stats = mwl8k_get_tx_stats,
3408 .get_stats = mwl8k_get_stats,
3411 static void mwl8k_tx_reclaim_handler(unsigned long data)
3414 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3415 struct mwl8k_priv *priv = hw->priv;
3417 spin_lock_bh(&priv->tx_lock);
3418 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3419 mwl8k_txq_reclaim(hw, i, 0);
3421 if (priv->tx_wait != NULL) {
3422 int count = mwl8k_txq_busy(priv);
3424 complete(priv->tx_wait);
3425 priv->tx_wait = NULL;
3428 spin_unlock_bh(&priv->tx_lock);
3431 static void mwl8k_finalize_join_worker(struct work_struct *work)
3433 struct mwl8k_priv *priv =
3434 container_of(work, struct mwl8k_priv, finalize_join_worker);
3435 struct sk_buff *skb = priv->beacon_skb;
3436 u8 dtim = (MWL8K_VIF(priv->vif))->bss_info.dtim_period;
3438 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3441 priv->beacon_skb = NULL;
3444 static int __devinit mwl8k_probe(struct pci_dev *pdev,
3445 const struct pci_device_id *id)
3447 struct ieee80211_hw *hw;
3448 struct mwl8k_priv *priv;
3453 rc = pci_enable_device(pdev);
3455 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3460 rc = pci_request_regions(pdev, MWL8K_NAME);
3462 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3467 pci_set_master(pdev);
3469 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3471 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3479 priv->hostcmd_wait = NULL;
3480 priv->tx_wait = NULL;
3481 priv->inconfig = false;
3482 priv->wmm_mode = false;
3483 priv->pending_tx_pkts = 0;
3484 strncpy(priv->name, MWL8K_NAME, sizeof(priv->name));
3486 spin_lock_init(&priv->fw_lock);
3488 SET_IEEE80211_DEV(hw, &pdev->dev);
3489 pci_set_drvdata(pdev, hw);
3491 priv->regs = pci_iomap(pdev, 1, 0x10000);
3492 if (priv->regs == NULL) {
3493 printk(KERN_ERR "%s: Cannot map device memory\n", priv->name);
3497 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3498 priv->band.band = IEEE80211_BAND_2GHZ;
3499 priv->band.channels = priv->channels;
3500 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3501 priv->band.bitrates = priv->rates;
3502 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3503 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3505 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3506 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3509 * Extra headroom is the size of the required DMA header
3510 * minus the size of the smallest 802.11 frame (CTS frame).
3512 hw->extra_tx_headroom =
3513 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3515 hw->channel_change_time = 10;
3517 hw->queues = MWL8K_TX_QUEUES;
3519 hw->wiphy->interface_modes =
3520 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_MONITOR);
3522 /* Set rssi and noise values to dBm */
3523 hw->flags |= (IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM);
3524 hw->vif_data_size = sizeof(struct mwl8k_vif);
3527 /* Set default radio state and preamble */
3528 priv->radio_preamble = MWL8K_RADIO_DEFAULT_PREAMBLE;
3529 priv->radio_state = MWL8K_RADIO_DISABLE;
3531 /* Finalize join worker */
3532 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3534 /* TX reclaim tasklet */
3535 tasklet_init(&priv->tx_reclaim_task,
3536 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3537 tasklet_disable(&priv->tx_reclaim_task);
3539 /* Config workthread */
3540 priv->config_wq = create_singlethread_workqueue("mwl8k_config");
3541 if (priv->config_wq == NULL)
3544 /* Power management cookie */
3545 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3546 if (priv->cookie == NULL)
3549 rc = mwl8k_rxq_init(hw, 0);
3552 rxq_refill(hw, 0, INT_MAX);
3554 spin_lock_init(&priv->tx_lock);
3556 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3557 rc = mwl8k_txq_init(hw, i);
3559 goto err_free_queues;
3562 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3563 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3564 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3565 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3567 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
3568 IRQF_SHARED, MWL8K_NAME, hw);
3570 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3572 goto err_free_queues;
3575 /* Reset firmware and hardware */
3576 mwl8k_hw_reset(priv);
3578 /* Ask userland hotplug daemon for the device firmware */
3579 rc = mwl8k_request_firmware(priv, (u32)id->driver_data);
3581 printk(KERN_ERR "%s: Firmware files not found\n", priv->name);
3585 /* Load firmware into hardware */
3586 rc = mwl8k_load_firmware(priv);
3588 printk(KERN_ERR "%s: Cannot start firmware\n", priv->name);
3589 goto err_stop_firmware;
3592 /* Reclaim memory once firmware is successfully loaded */
3593 mwl8k_release_firmware(priv);
3596 * Temporarily enable interrupts. Initial firmware host
3597 * commands use interrupts and avoids polling. Disable
3598 * interrupts when done.
3600 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3602 /* Get config data, mac addrs etc */
3603 rc = mwl8k_cmd_get_hw_spec(hw);
3605 printk(KERN_ERR "%s: Cannot initialise firmware\n", priv->name);
3606 goto err_stop_firmware;
3609 /* Turn radio off */
3610 rc = mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
3612 printk(KERN_ERR "%s: Cannot disable\n", priv->name);
3613 goto err_stop_firmware;
3616 /* Disable interrupts */
3617 spin_lock_irq(&priv->tx_lock);
3618 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3619 spin_unlock_irq(&priv->tx_lock);
3620 free_irq(priv->pdev->irq, hw);
3622 rc = ieee80211_register_hw(hw);
3624 printk(KERN_ERR "%s: Cannot register device\n", priv->name);
3625 goto err_stop_firmware;
3628 fw = (u8 *)&priv->fw_rev;
3629 printk(KERN_INFO "%s: 88W%u %s\n", priv->name, priv->part_num,
3631 printk(KERN_INFO "%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
3632 priv->name, MWL8K_VERSION, fw[3], fw[2], fw[1], fw[0]);
3633 printk(KERN_INFO "%s: MAC Address: %pM\n", priv->name,
3634 hw->wiphy->perm_addr);
3639 mwl8k_hw_reset(priv);
3640 mwl8k_release_firmware(priv);
3643 spin_lock_irq(&priv->tx_lock);
3644 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3645 spin_unlock_irq(&priv->tx_lock);
3646 free_irq(priv->pdev->irq, hw);
3649 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3650 mwl8k_txq_deinit(hw, i);
3651 mwl8k_rxq_deinit(hw, 0);
3654 if (priv->cookie != NULL)
3655 pci_free_consistent(priv->pdev, 4,
3656 priv->cookie, priv->cookie_dma);
3658 if (priv->regs != NULL)
3659 pci_iounmap(pdev, priv->regs);
3661 if (priv->config_wq != NULL)
3662 destroy_workqueue(priv->config_wq);
3664 pci_set_drvdata(pdev, NULL);
3665 ieee80211_free_hw(hw);
3668 pci_release_regions(pdev);
3669 pci_disable_device(pdev);
3674 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
3676 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3679 static void __devexit mwl8k_remove(struct pci_dev *pdev)
3681 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3682 struct mwl8k_priv *priv;
3689 ieee80211_stop_queues(hw);
3691 ieee80211_unregister_hw(hw);
3693 /* Remove tx reclaim tasklet */
3694 tasklet_kill(&priv->tx_reclaim_task);
3696 /* Stop config thread */
3697 destroy_workqueue(priv->config_wq);
3700 mwl8k_hw_reset(priv);
3702 /* Return all skbs to mac80211 */
3703 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3704 mwl8k_txq_reclaim(hw, i, 1);
3706 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3707 mwl8k_txq_deinit(hw, i);
3709 mwl8k_rxq_deinit(hw, 0);
3711 pci_free_consistent(priv->pdev, 4,
3712 priv->cookie, priv->cookie_dma);
3714 pci_iounmap(pdev, priv->regs);
3715 pci_set_drvdata(pdev, NULL);
3716 ieee80211_free_hw(hw);
3717 pci_release_regions(pdev);
3718 pci_disable_device(pdev);
3721 static struct pci_driver mwl8k_driver = {
3723 .id_table = mwl8k_table,
3724 .probe = mwl8k_probe,
3725 .remove = __devexit_p(mwl8k_remove),
3726 .shutdown = __devexit_p(mwl8k_shutdown),
3729 static int __init mwl8k_init(void)
3731 return pci_register_driver(&mwl8k_driver);
3734 static void __exit mwl8k_exit(void)
3736 pci_unregister_driver(&mwl8k_driver);
3739 module_init(mwl8k_init);
3740 module_exit(mwl8k_exit);