2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008-2009 Marvell Semiconductor Inc.
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/spinlock.h>
17 #include <linux/list.h>
18 #include <linux/pci.h>
19 #include <linux/delay.h>
20 #include <linux/completion.h>
21 #include <linux/etherdevice.h>
22 #include <net/mac80211.h>
23 #include <linux/moduleparam.h>
24 #include <linux/firmware.h>
25 #include <linux/workqueue.h>
27 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
28 #define MWL8K_NAME KBUILD_MODNAME
29 #define MWL8K_VERSION "0.10"
31 /* Register definitions */
32 #define MWL8K_HIU_GEN_PTR 0x00000c10
33 #define MWL8K_MODE_STA 0x0000005a
34 #define MWL8K_MODE_AP 0x000000a5
35 #define MWL8K_HIU_INT_CODE 0x00000c14
36 #define MWL8K_FWSTA_READY 0xf0f1f2f4
37 #define MWL8K_FWAP_READY 0xf1f2f4a5
38 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
39 #define MWL8K_HIU_SCRATCH 0x00000c40
41 /* Host->device communications */
42 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
43 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
44 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
45 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
46 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
47 #define MWL8K_H2A_INT_DUMMY (1 << 20)
48 #define MWL8K_H2A_INT_RESET (1 << 15)
49 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
50 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
52 /* Device->host communications */
53 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
54 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
55 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
56 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
57 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
58 #define MWL8K_A2H_INT_DUMMY (1 << 20)
59 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
60 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
61 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
62 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
63 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
64 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
65 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
66 #define MWL8K_A2H_INT_RX_READY (1 << 1)
67 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
69 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
70 MWL8K_A2H_INT_CHNL_SWITCHED | \
71 MWL8K_A2H_INT_QUEUE_EMPTY | \
72 MWL8K_A2H_INT_RADAR_DETECT | \
73 MWL8K_A2H_INT_RADIO_ON | \
74 MWL8K_A2H_INT_RADIO_OFF | \
75 MWL8K_A2H_INT_MAC_EVENT | \
76 MWL8K_A2H_INT_OPC_DONE | \
77 MWL8K_A2H_INT_RX_READY | \
78 MWL8K_A2H_INT_TX_DONE)
80 #define MWL8K_RX_QUEUES 1
81 #define MWL8K_TX_QUEUES 4
85 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
86 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
87 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status);
90 struct mwl8k_device_info {
94 struct rxd_ops *rxd_ops;
98 struct mwl8k_rx_queue {
101 /* hw receives here */
104 /* refill descs here */
111 DECLARE_PCI_UNMAP_ADDR(dma)
115 struct mwl8k_tx_queue {
116 /* hw transmits here */
119 /* sw appends here */
122 struct ieee80211_tx_queue_stats stats;
123 struct mwl8k_tx_desc *txd;
125 struct sk_buff **skb;
128 /* Pointers to the firmware data and meta information about it. */
129 struct mwl8k_firmware {
130 /* Boot helper code */
131 struct firmware *helper;
134 struct firmware *ucode;
140 struct ieee80211_hw *hw;
142 struct pci_dev *pdev;
144 struct mwl8k_device_info *device_info;
146 struct rxd_ops *rxd_ops;
148 /* firmware files and meta data */
149 struct mwl8k_firmware fw;
151 /* firmware access */
152 struct mutex fw_mutex;
153 struct task_struct *fw_mutex_owner;
155 struct completion *hostcmd_wait;
157 /* lock held over TX and TX reap */
160 /* TX quiesce completion, protected by fw_mutex and tx_lock */
161 struct completion *tx_wait;
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[13];
190 bool radio_short_preamble;
191 bool sniffer_enabled;
194 /* XXX need to convert this to handle multiple interfaces */
196 u8 capture_bssid[ETH_ALEN];
197 struct sk_buff *beacon_skb;
200 * This FJ worker has to be global as it is scheduled from the
201 * RX handler. At this point we don't know which interface it
202 * belongs to until the list of bssids waiting to complete join
205 struct work_struct finalize_join_worker;
207 /* Tasklet to reclaim TX descriptors and buffers after tx */
208 struct tasklet_struct tx_reclaim_task;
211 /* Per interface specific private data */
213 /* backpointer to parent config block */
214 struct mwl8k_priv *priv;
216 /* BSS config of AP or IBSS from mac80211*/
217 struct ieee80211_bss_conf bss_info;
219 /* BSSID of AP or IBSS */
221 u8 mac_addr[ETH_ALEN];
224 * Subset of supported legacy rates.
225 * Intersection of AP and STA supported rates.
227 struct ieee80211_rate legacy_rates[13];
229 /* number of supported legacy rates */
232 /* Index into station database.Returned by update_sta_db call */
235 /* Non AMPDU sequence number assigned by driver */
239 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
241 static const struct ieee80211_channel mwl8k_channels[] = {
242 { .center_freq = 2412, .hw_value = 1, },
243 { .center_freq = 2417, .hw_value = 2, },
244 { .center_freq = 2422, .hw_value = 3, },
245 { .center_freq = 2427, .hw_value = 4, },
246 { .center_freq = 2432, .hw_value = 5, },
247 { .center_freq = 2437, .hw_value = 6, },
248 { .center_freq = 2442, .hw_value = 7, },
249 { .center_freq = 2447, .hw_value = 8, },
250 { .center_freq = 2452, .hw_value = 9, },
251 { .center_freq = 2457, .hw_value = 10, },
252 { .center_freq = 2462, .hw_value = 11, },
255 static const struct ieee80211_rate mwl8k_rates[] = {
256 { .bitrate = 10, .hw_value = 2, },
257 { .bitrate = 20, .hw_value = 4, },
258 { .bitrate = 55, .hw_value = 11, },
259 { .bitrate = 110, .hw_value = 22, },
260 { .bitrate = 220, .hw_value = 44, },
261 { .bitrate = 60, .hw_value = 12, },
262 { .bitrate = 90, .hw_value = 18, },
263 { .bitrate = 120, .hw_value = 24, },
264 { .bitrate = 180, .hw_value = 36, },
265 { .bitrate = 240, .hw_value = 48, },
266 { .bitrate = 360, .hw_value = 72, },
267 { .bitrate = 480, .hw_value = 96, },
268 { .bitrate = 540, .hw_value = 108, },
271 /* Set or get info from Firmware */
272 #define MWL8K_CMD_SET 0x0001
273 #define MWL8K_CMD_GET 0x0000
275 /* Firmware command codes */
276 #define MWL8K_CMD_CODE_DNLD 0x0001
277 #define MWL8K_CMD_GET_HW_SPEC 0x0003
278 #define MWL8K_CMD_SET_HW_SPEC 0x0004
279 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
280 #define MWL8K_CMD_GET_STAT 0x0014
281 #define MWL8K_CMD_RADIO_CONTROL 0x001c
282 #define MWL8K_CMD_RF_TX_POWER 0x001e
283 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
284 #define MWL8K_CMD_SET_POST_SCAN 0x0108
285 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
286 #define MWL8K_CMD_SET_AID 0x010d
287 #define MWL8K_CMD_SET_RATE 0x0110
288 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
289 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
290 #define MWL8K_CMD_SET_SLOT 0x0114
291 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
292 #define MWL8K_CMD_SET_WMM_MODE 0x0123
293 #define MWL8K_CMD_MIMO_CONFIG 0x0125
294 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
295 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
296 #define MWL8K_CMD_SET_MAC_ADDR 0x0202
297 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
298 #define MWL8K_CMD_UPDATE_STADB 0x1123
300 static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
302 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
303 snprintf(buf, bufsize, "%s", #x);\
306 switch (cmd & ~0x8000) {
307 MWL8K_CMDNAME(CODE_DNLD);
308 MWL8K_CMDNAME(GET_HW_SPEC);
309 MWL8K_CMDNAME(SET_HW_SPEC);
310 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
311 MWL8K_CMDNAME(GET_STAT);
312 MWL8K_CMDNAME(RADIO_CONTROL);
313 MWL8K_CMDNAME(RF_TX_POWER);
314 MWL8K_CMDNAME(SET_PRE_SCAN);
315 MWL8K_CMDNAME(SET_POST_SCAN);
316 MWL8K_CMDNAME(SET_RF_CHANNEL);
317 MWL8K_CMDNAME(SET_AID);
318 MWL8K_CMDNAME(SET_RATE);
319 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
320 MWL8K_CMDNAME(RTS_THRESHOLD);
321 MWL8K_CMDNAME(SET_SLOT);
322 MWL8K_CMDNAME(SET_EDCA_PARAMS);
323 MWL8K_CMDNAME(SET_WMM_MODE);
324 MWL8K_CMDNAME(MIMO_CONFIG);
325 MWL8K_CMDNAME(USE_FIXED_RATE);
326 MWL8K_CMDNAME(ENABLE_SNIFFER);
327 MWL8K_CMDNAME(SET_MAC_ADDR);
328 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
329 MWL8K_CMDNAME(UPDATE_STADB);
331 snprintf(buf, bufsize, "0x%x", cmd);
338 /* Hardware and firmware reset */
339 static void mwl8k_hw_reset(struct mwl8k_priv *priv)
341 iowrite32(MWL8K_H2A_INT_RESET,
342 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
343 iowrite32(MWL8K_H2A_INT_RESET,
344 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
348 /* Release fw image */
349 static void mwl8k_release_fw(struct firmware **fw)
353 release_firmware(*fw);
357 static void mwl8k_release_firmware(struct mwl8k_priv *priv)
359 mwl8k_release_fw(&priv->fw.ucode);
360 mwl8k_release_fw(&priv->fw.helper);
363 /* Request fw image */
364 static int mwl8k_request_fw(struct mwl8k_priv *priv,
365 const char *fname, struct firmware **fw)
367 /* release current image */
369 mwl8k_release_fw(fw);
371 return request_firmware((const struct firmware **)fw,
372 fname, &priv->pdev->dev);
375 static int mwl8k_request_firmware(struct mwl8k_priv *priv)
377 struct mwl8k_device_info *di = priv->device_info;
380 if (di->helper_image != NULL) {
381 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
383 printk(KERN_ERR "%s: Error requesting helper "
384 "firmware file %s\n", pci_name(priv->pdev),
390 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
392 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
393 pci_name(priv->pdev), di->fw_image);
394 mwl8k_release_fw(&priv->fw.helper);
401 struct mwl8k_cmd_pkt {
407 } __attribute__((packed));
413 mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
415 void __iomem *regs = priv->regs;
419 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
420 if (pci_dma_mapping_error(priv->pdev, dma_addr))
423 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
424 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
425 iowrite32(MWL8K_H2A_INT_DOORBELL,
426 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
427 iowrite32(MWL8K_H2A_INT_DUMMY,
428 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
434 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
435 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
436 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
444 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
446 return loops ? 0 : -ETIMEDOUT;
449 static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
450 const u8 *data, size_t length)
452 struct mwl8k_cmd_pkt *cmd;
456 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
460 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
466 int block_size = length > 256 ? 256 : length;
468 memcpy(cmd->payload, data + done, block_size);
469 cmd->length = cpu_to_le16(block_size);
471 rc = mwl8k_send_fw_load_cmd(priv, cmd,
472 sizeof(*cmd) + block_size);
477 length -= block_size;
482 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
490 static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
491 const u8 *data, size_t length)
493 unsigned char *buffer;
494 int may_continue, rc = 0;
495 u32 done, prev_block_size;
497 buffer = kmalloc(1024, GFP_KERNEL);
504 while (may_continue > 0) {
507 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
508 if (block_size & 1) {
512 done += prev_block_size;
513 length -= prev_block_size;
516 if (block_size > 1024 || block_size > length) {
526 if (block_size == 0) {
533 prev_block_size = block_size;
534 memcpy(buffer, data + done, block_size);
536 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
541 if (!rc && length != 0)
549 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
551 struct mwl8k_priv *priv = hw->priv;
552 struct firmware *fw = priv->fw.ucode;
553 struct mwl8k_device_info *di = priv->device_info;
557 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
558 struct firmware *helper = priv->fw.helper;
560 if (helper == NULL) {
561 printk(KERN_ERR "%s: helper image needed but none "
562 "given\n", pci_name(priv->pdev));
566 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
568 printk(KERN_ERR "%s: unable to load firmware "
569 "helper image\n", pci_name(priv->pdev));
574 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
576 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
580 printk(KERN_ERR "%s: unable to load firmware image\n",
581 pci_name(priv->pdev));
585 if (di->modes & BIT(NL80211_IFTYPE_AP))
586 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
588 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
595 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
596 if (ready_code == MWL8K_FWAP_READY) {
599 } else if (ready_code == MWL8K_FWSTA_READY) {
608 return loops ? 0 : -ETIMEDOUT;
613 * Defines shared between transmission and reception.
615 /* HT control fields for firmware */
620 } __attribute__((packed));
622 /* Firmware Station database operations */
623 #define MWL8K_STA_DB_ADD_ENTRY 0
624 #define MWL8K_STA_DB_MODIFY_ENTRY 1
625 #define MWL8K_STA_DB_DEL_ENTRY 2
626 #define MWL8K_STA_DB_FLUSH 3
628 /* Peer Entry flags - used to define the type of the peer node */
629 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
631 #define MWL8K_IEEE_LEGACY_DATA_RATES 13
632 #define MWL8K_MCS_BITMAP_SIZE 16
634 struct peer_capability_info {
635 /* Peer type - AP vs. STA. */
638 /* Basic 802.11 capabilities from assoc resp. */
641 /* Set if peer supports 802.11n high throughput (HT). */
644 /* Valid if HT is supported. */
646 __u8 extended_ht_caps;
647 struct ewc_ht_info ewc_info;
649 /* Legacy rate table. Intersection of our rates and peer rates. */
650 __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
652 /* HT rate table. Intersection of our rates and peer rates. */
653 __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
656 /* If set, interoperability mode, no proprietary extensions. */
660 __le16 amsdu_enabled;
661 } __attribute__((packed));
663 /* Inline functions to manipulate QoS field in data descriptor. */
664 static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
666 u16 val_mask = 1 << 4;
668 /* End of Service Period Bit 4 */
669 return qos | val_mask;
672 static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
676 u16 qos_mask = ~(val_mask << shift);
678 /* Ack Policy Bit 5-6 */
679 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
682 static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
684 u16 val_mask = 1 << 7;
686 /* AMSDU present Bit 7 */
687 return qos | val_mask;
690 static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
694 u16 qos_mask = ~(val_mask << shift);
696 /* Queue Length Bits 8-15 */
697 return (qos & qos_mask) | ((len & val_mask) << shift);
700 /* DMA header used by firmware and hardware. */
701 struct mwl8k_dma_data {
703 struct ieee80211_hdr wh;
704 } __attribute__((packed));
706 /* Routines to add/remove DMA header from skb. */
707 static inline void mwl8k_remove_dma_header(struct sk_buff *skb)
709 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)skb->data;
710 void *dst, *src = &tr->wh;
711 int hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
712 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
714 dst = (void *)tr + space;
716 memmove(dst, src, hdrlen);
717 skb_pull(skb, space);
721 static inline void mwl8k_add_dma_header(struct sk_buff *skb)
723 struct ieee80211_hdr *wh;
725 struct mwl8k_dma_data *tr;
727 wh = (struct ieee80211_hdr *)skb->data;
728 hdrlen = ieee80211_hdrlen(wh->frame_control);
732 * Copy up/down the 802.11 header; the firmware requires
733 * we present a 2-byte payload length followed by a
734 * 4-address header (w/o QoS), followed (optionally) by
735 * any WEP/ExtIV header (but only filled in for CCMP).
737 if (hdrlen != sizeof(struct mwl8k_dma_data))
738 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
740 tr = (struct mwl8k_dma_data *)skb->data;
742 memmove(&tr->wh, wh, hdrlen);
745 memset(tr->wh.addr4, 0, ETH_ALEN);
748 * Firmware length is the length of the fully formed "802.11
749 * payload". That is, everything except for the 802.11 header.
750 * This includes all crypto material including the MIC.
752 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
759 struct mwl8k_rxd_8687 {
763 __le32 pkt_phys_addr;
764 __le32 next_rxd_phys_addr;
774 } __attribute__((packed));
776 #define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
777 #define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
778 #define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
779 #define MWL8K_8687_RATE_INFO_40MHZ 0x0004
780 #define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
781 #define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
783 #define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
785 static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
787 struct mwl8k_rxd_8687 *rxd = _rxd;
789 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
790 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
793 static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
795 struct mwl8k_rxd_8687 *rxd = _rxd;
797 rxd->pkt_len = cpu_to_le16(len);
798 rxd->pkt_phys_addr = cpu_to_le32(addr);
804 mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status)
806 struct mwl8k_rxd_8687 *rxd = _rxd;
809 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
813 rate_info = le16_to_cpu(rxd->rate_info);
815 memset(status, 0, sizeof(*status));
817 status->signal = -rxd->rssi;
818 status->noise = -rxd->noise_level;
819 status->qual = rxd->link_quality;
820 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
821 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
823 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
824 status->flag |= RX_FLAG_SHORTPRE;
825 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
826 status->flag |= RX_FLAG_40MHZ;
827 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
828 status->flag |= RX_FLAG_SHORT_GI;
829 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
830 status->flag |= RX_FLAG_HT;
832 status->band = IEEE80211_BAND_2GHZ;
833 status->freq = ieee80211_channel_to_frequency(rxd->channel);
835 return le16_to_cpu(rxd->pkt_len);
838 static struct rxd_ops rxd_8687_ops = {
839 .rxd_size = sizeof(struct mwl8k_rxd_8687),
840 .rxd_init = mwl8k_rxd_8687_init,
841 .rxd_refill = mwl8k_rxd_8687_refill,
842 .rxd_process = mwl8k_rxd_8687_process,
846 #define MWL8K_RX_DESCS 256
847 #define MWL8K_RX_MAXSZ 3800
849 static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
851 struct mwl8k_priv *priv = hw->priv;
852 struct mwl8k_rx_queue *rxq = priv->rxq + index;
860 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
862 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
863 if (rxq->rxd == NULL) {
864 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
865 wiphy_name(hw->wiphy));
868 memset(rxq->rxd, 0, size);
870 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
871 if (rxq->buf == NULL) {
872 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
873 wiphy_name(hw->wiphy));
874 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
877 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
879 for (i = 0; i < MWL8K_RX_DESCS; i++) {
883 dma_addr_t next_dma_addr;
885 desc_size = priv->rxd_ops->rxd_size;
886 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
889 if (nexti == MWL8K_RX_DESCS)
891 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
893 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
899 static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
901 struct mwl8k_priv *priv = hw->priv;
902 struct mwl8k_rx_queue *rxq = priv->rxq + index;
906 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
912 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
916 addr = pci_map_single(priv->pdev, skb->data,
917 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
921 if (rxq->tail == MWL8K_RX_DESCS)
923 rxq->buf[rx].skb = skb;
924 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
926 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
927 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
935 /* Must be called only when the card's reception is completely halted */
936 static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
938 struct mwl8k_priv *priv = hw->priv;
939 struct mwl8k_rx_queue *rxq = priv->rxq + index;
942 for (i = 0; i < MWL8K_RX_DESCS; i++) {
943 if (rxq->buf[i].skb != NULL) {
944 pci_unmap_single(priv->pdev,
945 pci_unmap_addr(&rxq->buf[i], dma),
946 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
947 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
949 kfree_skb(rxq->buf[i].skb);
950 rxq->buf[i].skb = NULL;
957 pci_free_consistent(priv->pdev,
958 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
959 rxq->rxd, rxq->rxd_dma);
965 * Scan a list of BSSIDs to process for finalize join.
966 * Allows for extension to process multiple BSSIDs.
969 mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
971 return priv->capture_beacon &&
972 ieee80211_is_beacon(wh->frame_control) &&
973 !compare_ether_addr(wh->addr3, priv->capture_bssid);
976 static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
979 struct mwl8k_priv *priv = hw->priv;
981 priv->capture_beacon = false;
982 memset(priv->capture_bssid, 0, ETH_ALEN);
985 * Use GFP_ATOMIC as rxq_process is called from
986 * the primary interrupt handler, memory allocation call
989 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
990 if (priv->beacon_skb != NULL)
991 ieee80211_queue_work(hw, &priv->finalize_join_worker);
994 static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
996 struct mwl8k_priv *priv = hw->priv;
997 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1001 while (rxq->rxd_count && limit--) {
1002 struct sk_buff *skb;
1005 struct ieee80211_rx_status status;
1007 skb = rxq->buf[rxq->head].skb;
1011 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1013 pkt_len = priv->rxd_ops->rxd_process(rxd, &status);
1017 rxq->buf[rxq->head].skb = NULL;
1019 pci_unmap_single(priv->pdev,
1020 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1021 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1022 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
1025 if (rxq->head == MWL8K_RX_DESCS)
1030 skb_put(skb, pkt_len);
1031 mwl8k_remove_dma_header(skb);
1034 * Check for a pending join operation. Save a
1035 * copy of the beacon and schedule a tasklet to
1036 * send a FINALIZE_JOIN command to the firmware.
1038 if (mwl8k_capture_bssid(priv, (void *)skb->data))
1039 mwl8k_save_beacon(hw, skb);
1041 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1042 ieee80211_rx_irqsafe(hw, skb);
1052 * Packet transmission.
1055 /* Transmit packet ACK policy */
1056 #define MWL8K_TXD_ACK_POLICY_NORMAL 0
1057 #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1059 #define MWL8K_TXD_STATUS_OK 0x00000001
1060 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1061 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1062 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1063 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1065 struct mwl8k_tx_desc {
1070 __le32 pkt_phys_addr;
1072 __u8 dest_MAC_addr[ETH_ALEN];
1073 __le32 next_txd_phys_addr;
1078 } __attribute__((packed));
1080 #define MWL8K_TX_DESCS 128
1082 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1084 struct mwl8k_priv *priv = hw->priv;
1085 struct mwl8k_tx_queue *txq = priv->txq + index;
1089 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1090 txq->stats.limit = MWL8K_TX_DESCS;
1094 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1096 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1097 if (txq->txd == NULL) {
1098 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1099 wiphy_name(hw->wiphy));
1102 memset(txq->txd, 0, size);
1104 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1105 if (txq->skb == NULL) {
1106 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1107 wiphy_name(hw->wiphy));
1108 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1111 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
1113 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1114 struct mwl8k_tx_desc *tx_desc;
1117 tx_desc = txq->txd + i;
1118 nexti = (i + 1) % MWL8K_TX_DESCS;
1120 tx_desc->status = 0;
1121 tx_desc->next_txd_phys_addr =
1122 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1128 static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1130 iowrite32(MWL8K_H2A_INT_PPA_READY,
1131 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1132 iowrite32(MWL8K_H2A_INT_DUMMY,
1133 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1134 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1137 struct mwl8k_txq_info {
1146 static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
1147 struct mwl8k_txq_info *txinfo)
1149 int count, desc, status;
1150 struct mwl8k_tx_queue *txq;
1151 struct mwl8k_tx_desc *tx_desc;
1154 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
1156 for (count = 0; count < MWL8K_TX_QUEUES; count++) {
1157 txq = priv->txq + count;
1158 txinfo[count].len = txq->stats.len;
1159 txinfo[count].head = txq->head;
1160 txinfo[count].tail = txq->tail;
1161 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1162 tx_desc = txq->txd + desc;
1163 status = le32_to_cpu(tx_desc->status);
1165 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1166 txinfo[count].fw_owned++;
1168 txinfo[count].drv_owned++;
1170 if (tx_desc->pkt_len == 0)
1171 txinfo[count].unused++;
1179 * Must be called with priv->fw_mutex held and tx queues stopped.
1181 static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1183 struct mwl8k_priv *priv = hw->priv;
1184 DECLARE_COMPLETION_ONSTACK(tx_wait);
1186 unsigned long timeout;
1190 spin_lock_bh(&priv->tx_lock);
1191 count = priv->pending_tx_pkts;
1193 priv->tx_wait = &tx_wait;
1194 spin_unlock_bh(&priv->tx_lock);
1197 struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES];
1201 timeout = wait_for_completion_timeout(&tx_wait,
1202 msecs_to_jiffies(5000));
1206 spin_lock_bh(&priv->tx_lock);
1207 priv->tx_wait = NULL;
1208 newcount = priv->pending_tx_pkts;
1209 mwl8k_scan_tx_ring(priv, txinfo);
1210 spin_unlock_bh(&priv->tx_lock);
1212 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
1213 __func__, __LINE__, count, newcount);
1215 for (index = 0; index < MWL8K_TX_QUEUES; index++)
1216 printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u "
1222 txinfo[index].fw_owned,
1223 txinfo[index].drv_owned,
1224 txinfo[index].unused);
1232 #define MWL8K_TXD_SUCCESS(status) \
1233 ((status) & (MWL8K_TXD_STATUS_OK | \
1234 MWL8K_TXD_STATUS_OK_RETRY | \
1235 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1237 static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1239 struct mwl8k_priv *priv = hw->priv;
1240 struct mwl8k_tx_queue *txq = priv->txq + index;
1243 while (txq->stats.len > 0) {
1245 struct mwl8k_tx_desc *tx_desc;
1248 struct sk_buff *skb;
1249 struct ieee80211_tx_info *info;
1253 tx_desc = txq->txd + tx;
1255 status = le32_to_cpu(tx_desc->status);
1257 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1261 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1264 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1265 BUG_ON(txq->stats.len == 0);
1267 priv->pending_tx_pkts--;
1269 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1270 size = le16_to_cpu(tx_desc->pkt_len);
1272 txq->skb[tx] = NULL;
1274 BUG_ON(skb == NULL);
1275 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1277 mwl8k_remove_dma_header(skb);
1279 /* Mark descriptor as unused */
1280 tx_desc->pkt_phys_addr = 0;
1281 tx_desc->pkt_len = 0;
1283 info = IEEE80211_SKB_CB(skb);
1284 ieee80211_tx_info_clear_status(info);
1285 if (MWL8K_TXD_SUCCESS(status))
1286 info->flags |= IEEE80211_TX_STAT_ACK;
1288 ieee80211_tx_status_irqsafe(hw, skb);
1293 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
1294 ieee80211_wake_queue(hw, index);
1297 /* must be called only when the card's transmit is completely halted */
1298 static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1300 struct mwl8k_priv *priv = hw->priv;
1301 struct mwl8k_tx_queue *txq = priv->txq + index;
1303 mwl8k_txq_reclaim(hw, index, 1);
1308 pci_free_consistent(priv->pdev,
1309 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1310 txq->txd, txq->txd_dma);
1315 mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1317 struct mwl8k_priv *priv = hw->priv;
1318 struct ieee80211_tx_info *tx_info;
1319 struct mwl8k_vif *mwl8k_vif;
1320 struct ieee80211_hdr *wh;
1321 struct mwl8k_tx_queue *txq;
1322 struct mwl8k_tx_desc *tx;
1328 wh = (struct ieee80211_hdr *)skb->data;
1329 if (ieee80211_is_data_qos(wh->frame_control))
1330 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1334 mwl8k_add_dma_header(skb);
1335 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
1337 tx_info = IEEE80211_SKB_CB(skb);
1338 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1340 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1341 u16 seqno = mwl8k_vif->seqno;
1343 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1344 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1345 mwl8k_vif->seqno = seqno++ % 4096;
1348 /* Setup firmware control bit fields for each frame type. */
1351 if (ieee80211_is_mgmt(wh->frame_control) ||
1352 ieee80211_is_ctl(wh->frame_control)) {
1354 qos = mwl8k_qos_setbit_eosp(qos);
1355 /* Set Queue size to unspecified */
1356 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1357 } else if (ieee80211_is_data(wh->frame_control)) {
1359 if (is_multicast_ether_addr(wh->addr1))
1360 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1362 /* Send pkt in an aggregate if AMPDU frame. */
1363 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1364 qos = mwl8k_qos_setbit_ack(qos,
1365 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1367 qos = mwl8k_qos_setbit_ack(qos,
1368 MWL8K_TXD_ACK_POLICY_NORMAL);
1370 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1371 qos = mwl8k_qos_setbit_amsdu(qos);
1374 dma = pci_map_single(priv->pdev, skb->data,
1375 skb->len, PCI_DMA_TODEVICE);
1377 if (pci_dma_mapping_error(priv->pdev, dma)) {
1378 printk(KERN_DEBUG "%s: failed to dma map skb, "
1379 "dropping TX frame.\n", wiphy_name(hw->wiphy));
1381 return NETDEV_TX_OK;
1384 spin_lock_bh(&priv->tx_lock);
1386 txq = priv->txq + index;
1388 BUG_ON(txq->skb[txq->tail] != NULL);
1389 txq->skb[txq->tail] = skb;
1391 tx = txq->txd + txq->tail;
1392 tx->data_rate = txdatarate;
1393 tx->tx_priority = index;
1394 tx->qos_control = cpu_to_le16(qos);
1395 tx->pkt_phys_addr = cpu_to_le32(dma);
1396 tx->pkt_len = cpu_to_le16(skb->len);
1398 tx->peer_id = mwl8k_vif->peer_id;
1400 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1404 priv->pending_tx_pkts++;
1407 if (txq->tail == MWL8K_TX_DESCS)
1410 if (txq->head == txq->tail)
1411 ieee80211_stop_queue(hw, index);
1413 mwl8k_tx_start(priv);
1415 spin_unlock_bh(&priv->tx_lock);
1417 return NETDEV_TX_OK;
1424 * We have the following requirements for issuing firmware commands:
1425 * - Some commands require that the packet transmit path is idle when
1426 * the command is issued. (For simplicity, we'll just quiesce the
1427 * transmit path for every command.)
1428 * - There are certain sequences of commands that need to be issued to
1429 * the hardware sequentially, with no other intervening commands.
1431 * This leads to an implementation of a "firmware lock" as a mutex that
1432 * can be taken recursively, and which is taken by both the low-level
1433 * command submission function (mwl8k_post_cmd) as well as any users of
1434 * that function that require issuing of an atomic sequence of commands,
1435 * and quiesces the transmit path whenever it's taken.
1437 static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1439 struct mwl8k_priv *priv = hw->priv;
1441 if (priv->fw_mutex_owner != current) {
1444 mutex_lock(&priv->fw_mutex);
1445 ieee80211_stop_queues(hw);
1447 rc = mwl8k_tx_wait_empty(hw);
1449 ieee80211_wake_queues(hw);
1450 mutex_unlock(&priv->fw_mutex);
1455 priv->fw_mutex_owner = current;
1458 priv->fw_mutex_depth++;
1463 static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1465 struct mwl8k_priv *priv = hw->priv;
1467 if (!--priv->fw_mutex_depth) {
1468 ieee80211_wake_queues(hw);
1469 priv->fw_mutex_owner = NULL;
1470 mutex_unlock(&priv->fw_mutex);
1476 * Command processing.
1479 /* Timeout firmware commands after 2000ms */
1480 #define MWL8K_CMD_TIMEOUT_MS 2000
1482 static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1484 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1485 struct mwl8k_priv *priv = hw->priv;
1486 void __iomem *regs = priv->regs;
1487 dma_addr_t dma_addr;
1488 unsigned int dma_size;
1490 unsigned long timeout = 0;
1493 cmd->result = 0xffff;
1494 dma_size = le16_to_cpu(cmd->length);
1495 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1496 PCI_DMA_BIDIRECTIONAL);
1497 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1500 rc = mwl8k_fw_lock(hw);
1502 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1503 PCI_DMA_BIDIRECTIONAL);
1507 priv->hostcmd_wait = &cmd_wait;
1508 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1509 iowrite32(MWL8K_H2A_INT_DOORBELL,
1510 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1511 iowrite32(MWL8K_H2A_INT_DUMMY,
1512 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1514 timeout = wait_for_completion_timeout(&cmd_wait,
1515 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1517 priv->hostcmd_wait = NULL;
1519 mwl8k_fw_unlock(hw);
1521 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1522 PCI_DMA_BIDIRECTIONAL);
1525 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1526 wiphy_name(hw->wiphy),
1527 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1528 MWL8K_CMD_TIMEOUT_MS);
1531 rc = cmd->result ? -EINVAL : 0;
1533 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1534 wiphy_name(hw->wiphy),
1535 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1536 le16_to_cpu(cmd->result));
1543 * CMD_GET_HW_SPEC (STA version).
1545 struct mwl8k_cmd_get_hw_spec_sta {
1546 struct mwl8k_cmd_pkt header;
1548 __u8 host_interface;
1550 __u8 perm_addr[ETH_ALEN];
1555 __u8 mcs_bitmap[16];
1556 __le32 rx_queue_ptr;
1557 __le32 num_tx_queues;
1558 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1560 __le32 num_tx_desc_per_queue;
1562 } __attribute__((packed));
1564 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
1566 struct mwl8k_priv *priv = hw->priv;
1567 struct mwl8k_cmd_get_hw_spec_sta *cmd;
1571 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1575 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1576 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1578 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1579 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1580 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1581 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1582 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1583 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1584 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1585 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1587 rc = mwl8k_post_cmd(hw, &cmd->header);
1590 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1591 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1592 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1593 priv->hw_rev = cmd->hw_rev;
1601 * CMD_GET_HW_SPEC (AP version).
1603 struct mwl8k_cmd_get_hw_spec_ap {
1604 struct mwl8k_cmd_pkt header;
1606 __u8 host_interface;
1609 __u8 perm_addr[ETH_ALEN];
1620 } __attribute__((packed));
1622 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1624 struct mwl8k_priv *priv = hw->priv;
1625 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1628 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1632 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1633 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1635 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1636 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1638 rc = mwl8k_post_cmd(hw, &cmd->header);
1643 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1644 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1645 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1646 priv->hw_rev = cmd->hw_rev;
1648 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1649 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1651 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1652 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1654 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1655 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1657 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1658 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1660 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1661 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1663 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1664 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1674 struct mwl8k_cmd_set_hw_spec {
1675 struct mwl8k_cmd_pkt header;
1677 __u8 host_interface;
1679 __u8 perm_addr[ETH_ALEN];
1684 __le32 rx_queue_ptr;
1685 __le32 num_tx_queues;
1686 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1688 __le32 num_tx_desc_per_queue;
1690 } __attribute__((packed));
1692 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1694 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1696 struct mwl8k_priv *priv = hw->priv;
1697 struct mwl8k_cmd_set_hw_spec *cmd;
1701 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1705 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1706 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1708 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1709 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1710 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1711 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1712 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1713 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1714 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1715 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1717 rc = mwl8k_post_cmd(hw, &cmd->header);
1724 * CMD_MAC_MULTICAST_ADR.
1726 struct mwl8k_cmd_mac_multicast_adr {
1727 struct mwl8k_cmd_pkt header;
1730 __u8 addr[0][ETH_ALEN];
1733 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
1734 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
1735 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1736 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
1738 static struct mwl8k_cmd_pkt *
1739 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
1740 int mc_count, struct dev_addr_list *mclist)
1742 struct mwl8k_priv *priv = hw->priv;
1743 struct mwl8k_cmd_mac_multicast_adr *cmd;
1746 if (allmulti || mc_count > priv->num_mcaddrs) {
1751 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1753 cmd = kzalloc(size, GFP_ATOMIC);
1757 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1758 cmd->header.length = cpu_to_le16(size);
1759 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1760 MWL8K_ENABLE_RX_BROADCAST);
1763 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1764 } else if (mc_count) {
1767 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1768 cmd->numaddr = cpu_to_le16(mc_count);
1769 for (i = 0; i < mc_count && mclist; i++) {
1770 if (mclist->da_addrlen != ETH_ALEN) {
1774 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1775 mclist = mclist->next;
1779 return &cmd->header;
1783 * CMD_802_11_GET_STAT.
1785 struct mwl8k_cmd_802_11_get_stat {
1786 struct mwl8k_cmd_pkt header;
1788 } __attribute__((packed));
1790 #define MWL8K_STAT_ACK_FAILURE 9
1791 #define MWL8K_STAT_RTS_FAILURE 12
1792 #define MWL8K_STAT_FCS_ERROR 24
1793 #define MWL8K_STAT_RTS_SUCCESS 11
1795 static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1796 struct ieee80211_low_level_stats *stats)
1798 struct mwl8k_cmd_802_11_get_stat *cmd;
1801 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1805 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1806 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1808 rc = mwl8k_post_cmd(hw, &cmd->header);
1810 stats->dot11ACKFailureCount =
1811 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1812 stats->dot11RTSFailureCount =
1813 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1814 stats->dot11FCSErrorCount =
1815 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1816 stats->dot11RTSSuccessCount =
1817 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1825 * CMD_802_11_RADIO_CONTROL.
1827 struct mwl8k_cmd_802_11_radio_control {
1828 struct mwl8k_cmd_pkt header;
1832 } __attribute__((packed));
1835 mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
1837 struct mwl8k_priv *priv = hw->priv;
1838 struct mwl8k_cmd_802_11_radio_control *cmd;
1841 if (enable == priv->radio_on && !force)
1844 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1848 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1849 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1850 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1851 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
1852 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1854 rc = mwl8k_post_cmd(hw, &cmd->header);
1858 priv->radio_on = enable;
1863 static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1865 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1868 static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1870 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1874 mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1876 struct mwl8k_priv *priv;
1878 if (hw == NULL || hw->priv == NULL)
1882 priv->radio_short_preamble = short_preamble;
1884 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
1888 * CMD_802_11_RF_TX_POWER.
1890 #define MWL8K_TX_POWER_LEVEL_TOTAL 8
1892 struct mwl8k_cmd_802_11_rf_tx_power {
1893 struct mwl8k_cmd_pkt header;
1895 __le16 support_level;
1896 __le16 current_level;
1898 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1899 } __attribute__((packed));
1901 static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1903 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1906 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1910 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1911 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1912 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1913 cmd->support_level = cpu_to_le16(dBm);
1915 rc = mwl8k_post_cmd(hw, &cmd->header);
1924 struct mwl8k_cmd_set_pre_scan {
1925 struct mwl8k_cmd_pkt header;
1926 } __attribute__((packed));
1928 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
1930 struct mwl8k_cmd_set_pre_scan *cmd;
1933 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1937 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
1938 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1940 rc = mwl8k_post_cmd(hw, &cmd->header);
1947 * CMD_SET_POST_SCAN.
1949 struct mwl8k_cmd_set_post_scan {
1950 struct mwl8k_cmd_pkt header;
1952 __u8 bssid[ETH_ALEN];
1953 } __attribute__((packed));
1956 mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
1958 struct mwl8k_cmd_set_post_scan *cmd;
1961 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1965 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
1966 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1968 memcpy(cmd->bssid, mac, ETH_ALEN);
1970 rc = mwl8k_post_cmd(hw, &cmd->header);
1977 * CMD_SET_RF_CHANNEL.
1979 struct mwl8k_cmd_set_rf_channel {
1980 struct mwl8k_cmd_pkt header;
1982 __u8 current_channel;
1983 __le32 channel_flags;
1984 } __attribute__((packed));
1986 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
1987 struct ieee80211_channel *channel)
1989 struct mwl8k_cmd_set_rf_channel *cmd;
1992 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1996 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
1997 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1998 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1999 cmd->current_channel = channel->hw_value;
2000 if (channel->band == IEEE80211_BAND_2GHZ)
2001 cmd->channel_flags = cpu_to_le32(0x00000081);
2003 cmd->channel_flags = cpu_to_le32(0x00000000);
2005 rc = mwl8k_post_cmd(hw, &cmd->header);
2014 struct mwl8k_cmd_set_slot {
2015 struct mwl8k_cmd_pkt header;
2018 } __attribute__((packed));
2020 static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
2022 struct mwl8k_cmd_set_slot *cmd;
2025 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2029 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2030 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2031 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2032 cmd->short_slot = short_slot_time;
2034 rc = mwl8k_post_cmd(hw, &cmd->header);
2043 struct mwl8k_cmd_mimo_config {
2044 struct mwl8k_cmd_pkt header;
2046 __u8 rx_antenna_map;
2047 __u8 tx_antenna_map;
2048 } __attribute__((packed));
2050 static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2052 struct mwl8k_cmd_mimo_config *cmd;
2055 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2059 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2060 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2061 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2062 cmd->rx_antenna_map = rx;
2063 cmd->tx_antenna_map = tx;
2065 rc = mwl8k_post_cmd(hw, &cmd->header);
2072 * CMD_ENABLE_SNIFFER.
2074 struct mwl8k_cmd_enable_sniffer {
2075 struct mwl8k_cmd_pkt header;
2077 } __attribute__((packed));
2079 static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2081 struct mwl8k_cmd_enable_sniffer *cmd;
2084 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2088 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2089 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2090 cmd->action = cpu_to_le32(!!enable);
2092 rc = mwl8k_post_cmd(hw, &cmd->header);
2101 struct mwl8k_cmd_set_mac_addr {
2102 struct mwl8k_cmd_pkt header;
2103 __u8 mac_addr[ETH_ALEN];
2104 } __attribute__((packed));
2106 static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2108 struct mwl8k_cmd_set_mac_addr *cmd;
2111 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2115 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2116 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2117 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2119 rc = mwl8k_post_cmd(hw, &cmd->header);
2127 * CMD_SET_RATEADAPT_MODE.
2129 struct mwl8k_cmd_set_rate_adapt_mode {
2130 struct mwl8k_cmd_pkt header;
2133 } __attribute__((packed));
2135 static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2137 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2140 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2144 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2145 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2146 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2147 cmd->mode = cpu_to_le16(mode);
2149 rc = mwl8k_post_cmd(hw, &cmd->header);
2158 struct mwl8k_cmd_set_wmm {
2159 struct mwl8k_cmd_pkt header;
2161 } __attribute__((packed));
2163 static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2165 struct mwl8k_priv *priv = hw->priv;
2166 struct mwl8k_cmd_set_wmm *cmd;
2169 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2173 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2174 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2175 cmd->action = cpu_to_le16(!!enable);
2177 rc = mwl8k_post_cmd(hw, &cmd->header);
2181 priv->wmm_enabled = enable;
2187 * CMD_SET_RTS_THRESHOLD.
2189 struct mwl8k_cmd_rts_threshold {
2190 struct mwl8k_cmd_pkt header;
2193 } __attribute__((packed));
2195 static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
2196 u16 action, u16 threshold)
2198 struct mwl8k_cmd_rts_threshold *cmd;
2201 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2205 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2206 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2207 cmd->action = cpu_to_le16(action);
2208 cmd->threshold = cpu_to_le16(threshold);
2210 rc = mwl8k_post_cmd(hw, &cmd->header);
2217 * CMD_SET_EDCA_PARAMS.
2219 struct mwl8k_cmd_set_edca_params {
2220 struct mwl8k_cmd_pkt header;
2222 /* See MWL8K_SET_EDCA_XXX below */
2225 /* TX opportunity in units of 32 us */
2228 /* Log exponent of max contention period: 0...15*/
2231 /* Log exponent of min contention period: 0...15 */
2234 /* Adaptive interframe spacing in units of 32us */
2237 /* TX queue to configure */
2239 } __attribute__((packed));
2241 #define MWL8K_SET_EDCA_CW 0x01
2242 #define MWL8K_SET_EDCA_TXOP 0x02
2243 #define MWL8K_SET_EDCA_AIFS 0x04
2245 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2246 MWL8K_SET_EDCA_TXOP | \
2247 MWL8K_SET_EDCA_AIFS)
2250 mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2251 __u16 cw_min, __u16 cw_max,
2252 __u8 aifs, __u16 txop)
2254 struct mwl8k_cmd_set_edca_params *cmd;
2257 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2262 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2265 qnum ^= !(qnum >> 1);
2267 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2268 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2269 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2270 cmd->txop = cpu_to_le16(txop);
2271 cmd->log_cw_max = (u8)ilog2(cw_max + 1);
2272 cmd->log_cw_min = (u8)ilog2(cw_min + 1);
2276 rc = mwl8k_post_cmd(hw, &cmd->header);
2283 * CMD_FINALIZE_JOIN.
2286 /* FJ beacon buffer size is compiled into the firmware. */
2287 #define MWL8K_FJ_BEACON_MAXLEN 128
2289 struct mwl8k_cmd_finalize_join {
2290 struct mwl8k_cmd_pkt header;
2291 __le32 sleep_interval; /* Number of beacon periods to sleep */
2292 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2293 } __attribute__((packed));
2295 static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2296 __u16 framelen, __u16 dtim)
2298 struct mwl8k_cmd_finalize_join *cmd;
2299 struct ieee80211_mgmt *payload = frame;
2307 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2311 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2312 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2313 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2315 hdrlen = ieee80211_hdrlen(payload->frame_control);
2317 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2319 /* XXX TBD Might just have to abort and return an error */
2320 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2321 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
2322 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2323 payload_len, MWL8K_FJ_BEACON_MAXLEN);
2325 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2326 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2328 if (payload && payload_len)
2329 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2331 rc = mwl8k_post_cmd(hw, &cmd->header);
2339 struct mwl8k_cmd_update_sta_db {
2340 struct mwl8k_cmd_pkt header;
2342 /* See STADB_ACTION_TYPE */
2345 /* Peer MAC address */
2346 __u8 peer_addr[ETH_ALEN];
2350 /* Peer info - valid during add/update. */
2351 struct peer_capability_info peer_info;
2352 } __attribute__((packed));
2354 static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2355 struct ieee80211_vif *vif, __u32 action)
2357 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2358 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2359 struct mwl8k_cmd_update_sta_db *cmd;
2360 struct peer_capability_info *peer_info;
2361 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2365 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2369 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2370 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2372 cmd->action = cpu_to_le32(action);
2373 peer_info = &cmd->peer_info;
2374 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2377 case MWL8K_STA_DB_ADD_ENTRY:
2378 case MWL8K_STA_DB_MODIFY_ENTRY:
2379 /* Build peer_info block */
2380 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2381 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2382 peer_info->interop = 1;
2383 peer_info->amsdu_enabled = 0;
2385 rates = peer_info->legacy_rates;
2386 for (count = 0; count < mv_vif->legacy_nrates; count++)
2387 rates[count] = bitrates[count].hw_value;
2389 rc = mwl8k_post_cmd(hw, &cmd->header);
2391 mv_vif->peer_id = peer_info->station_id;
2395 case MWL8K_STA_DB_DEL_ENTRY:
2396 case MWL8K_STA_DB_FLUSH:
2398 rc = mwl8k_post_cmd(hw, &cmd->header);
2400 mv_vif->peer_id = 0;
2411 #define MWL8K_RATE_INDEX_MAX_ARRAY 14
2413 #define MWL8K_FRAME_PROT_DISABLED 0x00
2414 #define MWL8K_FRAME_PROT_11G 0x07
2415 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2416 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2418 struct mwl8k_cmd_update_set_aid {
2419 struct mwl8k_cmd_pkt header;
2422 /* AP's MAC address (BSSID) */
2423 __u8 bssid[ETH_ALEN];
2424 __le16 protection_mode;
2425 __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2426 } __attribute__((packed));
2428 static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2429 struct ieee80211_vif *vif)
2431 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2432 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2433 struct mwl8k_cmd_update_set_aid *cmd;
2434 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2439 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2443 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2444 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2445 cmd->aid = cpu_to_le16(info->aid);
2447 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
2449 if (info->use_cts_prot) {
2450 prot_mode = MWL8K_FRAME_PROT_11G;
2452 switch (info->ht_operation_mode &
2453 IEEE80211_HT_OP_MODE_PROTECTION) {
2454 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2455 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2457 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2458 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2461 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2465 cmd->protection_mode = cpu_to_le16(prot_mode);
2467 for (count = 0; count < mv_vif->legacy_nrates; count++)
2468 cmd->supp_rates[count] = bitrates[count].hw_value;
2470 rc = mwl8k_post_cmd(hw, &cmd->header);
2479 struct mwl8k_cmd_update_rateset {
2480 struct mwl8k_cmd_pkt header;
2481 __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2483 /* Bitmap for supported MCS codes. */
2484 __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
2485 __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
2486 } __attribute__((packed));
2488 static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2489 struct ieee80211_vif *vif)
2491 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2492 struct mwl8k_cmd_update_rateset *cmd;
2493 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2497 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2501 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2502 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2504 for (count = 0; count < mv_vif->legacy_nrates; count++)
2505 cmd->legacy_rates[count] = bitrates[count].hw_value;
2507 rc = mwl8k_post_cmd(hw, &cmd->header);
2514 * CMD_USE_FIXED_RATE.
2516 #define MWL8K_RATE_TABLE_SIZE 8
2517 #define MWL8K_UCAST_RATE 0
2518 #define MWL8K_USE_AUTO_RATE 0x0002
2520 struct mwl8k_rate_entry {
2521 /* Set to 1 if HT rate, 0 if legacy. */
2524 /* Set to 1 to use retry_count field. */
2525 __le32 enable_retry;
2527 /* Specified legacy rate or MCS. */
2530 /* Number of allowed retries. */
2532 } __attribute__((packed));
2534 struct mwl8k_rate_table {
2535 /* 1 to allow specified rate and below */
2536 __le32 allow_rate_drop;
2538 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2539 } __attribute__((packed));
2541 struct mwl8k_cmd_use_fixed_rate {
2542 struct mwl8k_cmd_pkt header;
2544 struct mwl8k_rate_table rate_table;
2546 /* Unicast, Broadcast or Multicast */
2550 } __attribute__((packed));
2552 static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2553 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2555 struct mwl8k_cmd_use_fixed_rate *cmd;
2559 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2563 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2564 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2566 cmd->action = cpu_to_le32(action);
2567 cmd->rate_type = cpu_to_le32(rate_type);
2569 if (rate_table != NULL) {
2571 * Copy over each field manually so that endian
2572 * conversion can be done.
2574 cmd->rate_table.allow_rate_drop =
2575 cpu_to_le32(rate_table->allow_rate_drop);
2576 cmd->rate_table.num_rates =
2577 cpu_to_le32(rate_table->num_rates);
2579 for (count = 0; count < rate_table->num_rates; count++) {
2580 struct mwl8k_rate_entry *dst =
2581 &cmd->rate_table.rate_entry[count];
2582 struct mwl8k_rate_entry *src =
2583 &rate_table->rate_entry[count];
2585 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2586 dst->enable_retry = cpu_to_le32(src->enable_retry);
2587 dst->rate = cpu_to_le32(src->rate);
2588 dst->retry_count = cpu_to_le32(src->retry_count);
2592 rc = mwl8k_post_cmd(hw, &cmd->header);
2600 * Interrupt handling.
2602 static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2604 struct ieee80211_hw *hw = dev_id;
2605 struct mwl8k_priv *priv = hw->priv;
2608 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2609 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2614 if (status & MWL8K_A2H_INT_TX_DONE)
2615 tasklet_schedule(&priv->tx_reclaim_task);
2617 if (status & MWL8K_A2H_INT_RX_READY) {
2618 while (rxq_process(hw, 0, 1))
2619 rxq_refill(hw, 0, 1);
2622 if (status & MWL8K_A2H_INT_OPC_DONE) {
2623 if (priv->hostcmd_wait != NULL)
2624 complete(priv->hostcmd_wait);
2627 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
2628 if (!mutex_is_locked(&priv->fw_mutex) &&
2629 priv->radio_on && priv->pending_tx_pkts)
2630 mwl8k_tx_start(priv);
2638 * Core driver operations.
2640 static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2642 struct mwl8k_priv *priv = hw->priv;
2643 int index = skb_get_queue_mapping(skb);
2646 if (priv->current_channel == NULL) {
2647 printk(KERN_DEBUG "%s: dropped TX frame since radio "
2648 "disabled\n", wiphy_name(hw->wiphy));
2650 return NETDEV_TX_OK;
2653 rc = mwl8k_txq_xmit(hw, index, skb);
2658 static int mwl8k_start(struct ieee80211_hw *hw)
2660 struct mwl8k_priv *priv = hw->priv;
2663 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
2664 IRQF_SHARED, MWL8K_NAME, hw);
2666 printk(KERN_ERR "%s: failed to register IRQ handler\n",
2667 wiphy_name(hw->wiphy));
2671 /* Enable tx reclaim tasklet */
2672 tasklet_enable(&priv->tx_reclaim_task);
2674 /* Enable interrupts */
2675 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2677 rc = mwl8k_fw_lock(hw);
2679 rc = mwl8k_cmd_802_11_radio_enable(hw);
2682 rc = mwl8k_cmd_set_pre_scan(hw);
2685 rc = mwl8k_cmd_set_post_scan(hw,
2686 "\x00\x00\x00\x00\x00\x00");
2689 rc = mwl8k_cmd_setrateadaptmode(hw, 0);
2692 rc = mwl8k_set_wmm(hw, 0);
2695 rc = mwl8k_enable_sniffer(hw, 0);
2697 mwl8k_fw_unlock(hw);
2701 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2702 free_irq(priv->pdev->irq, hw);
2703 tasklet_disable(&priv->tx_reclaim_task);
2709 static void mwl8k_stop(struct ieee80211_hw *hw)
2711 struct mwl8k_priv *priv = hw->priv;
2714 mwl8k_cmd_802_11_radio_disable(hw);
2716 ieee80211_stop_queues(hw);
2718 /* Disable interrupts */
2719 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2720 free_irq(priv->pdev->irq, hw);
2722 /* Stop finalize join worker */
2723 cancel_work_sync(&priv->finalize_join_worker);
2724 if (priv->beacon_skb != NULL)
2725 dev_kfree_skb(priv->beacon_skb);
2727 /* Stop tx reclaim tasklet */
2728 tasklet_disable(&priv->tx_reclaim_task);
2730 /* Return all skbs to mac80211 */
2731 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2732 mwl8k_txq_reclaim(hw, i, 1);
2735 static int mwl8k_add_interface(struct ieee80211_hw *hw,
2736 struct ieee80211_if_init_conf *conf)
2738 struct mwl8k_priv *priv = hw->priv;
2739 struct mwl8k_vif *mwl8k_vif;
2742 * We only support one active interface at a time.
2744 if (priv->vif != NULL)
2748 * We only support managed interfaces for now.
2750 if (conf->type != NL80211_IFTYPE_STATION)
2754 * Reject interface creation if sniffer mode is active, as
2755 * STA operation is mutually exclusive with hardware sniffer
2758 if (priv->sniffer_enabled) {
2759 printk(KERN_INFO "%s: unable to create STA "
2760 "interface due to sniffer mode being enabled\n",
2761 wiphy_name(hw->wiphy));
2765 /* Clean out driver private area */
2766 mwl8k_vif = MWL8K_VIF(conf->vif);
2767 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2769 /* Set and save the mac address */
2770 mwl8k_set_mac_addr(hw, conf->mac_addr);
2771 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
2773 /* Back pointer to parent config block */
2774 mwl8k_vif->priv = priv;
2776 /* Setup initial PHY parameters */
2777 memcpy(mwl8k_vif->legacy_rates,
2778 priv->rates, sizeof(mwl8k_vif->legacy_rates));
2779 mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
2781 /* Set Initial sequence number to zero */
2782 mwl8k_vif->seqno = 0;
2784 priv->vif = conf->vif;
2785 priv->current_channel = NULL;
2790 static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2791 struct ieee80211_if_init_conf *conf)
2793 struct mwl8k_priv *priv = hw->priv;
2795 if (priv->vif == NULL)
2798 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
2803 static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
2805 struct ieee80211_conf *conf = &hw->conf;
2806 struct mwl8k_priv *priv = hw->priv;
2809 if (conf->flags & IEEE80211_CONF_IDLE) {
2810 mwl8k_cmd_802_11_radio_disable(hw);
2811 priv->current_channel = NULL;
2815 rc = mwl8k_fw_lock(hw);
2819 rc = mwl8k_cmd_802_11_radio_enable(hw);
2823 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2827 priv->current_channel = conf->channel;
2829 if (conf->power_level > 18)
2830 conf->power_level = 18;
2831 rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level);
2835 if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
2839 mwl8k_fw_unlock(hw);
2844 static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
2845 struct ieee80211_vif *vif,
2846 struct ieee80211_bss_conf *info,
2849 struct mwl8k_priv *priv = hw->priv;
2850 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
2853 if (changed & BSS_CHANGED_BSSID)
2854 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
2856 if ((changed & BSS_CHANGED_ASSOC) == 0)
2859 priv->capture_beacon = false;
2861 rc = mwl8k_fw_lock(hw);
2866 memcpy(&mwl8k_vif->bss_info, info,
2867 sizeof(struct ieee80211_bss_conf));
2870 rc = mwl8k_update_rateset(hw, vif);
2874 /* Turn on rate adaptation */
2875 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
2876 MWL8K_UCAST_RATE, NULL);
2880 /* Set radio preamble */
2881 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
2886 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
2890 /* Update peer rate info */
2891 rc = mwl8k_cmd_update_sta_db(hw, vif,
2892 MWL8K_STA_DB_MODIFY_ENTRY);
2897 rc = mwl8k_cmd_set_aid(hw, vif);
2902 * Finalize the join. Tell rx handler to process
2903 * next beacon from our BSSID.
2905 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
2906 priv->capture_beacon = true;
2908 rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
2909 memset(&mwl8k_vif->bss_info, 0,
2910 sizeof(struct ieee80211_bss_conf));
2911 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
2915 mwl8k_fw_unlock(hw);
2918 static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
2919 int mc_count, struct dev_addr_list *mclist)
2921 struct mwl8k_cmd_pkt *cmd;
2924 * Synthesize and return a command packet that programs the
2925 * hardware multicast address filter. At this point we don't
2926 * know whether FIF_ALLMULTI is being requested, but if it is,
2927 * we'll end up throwing this packet away and creating a new
2928 * one in mwl8k_configure_filter().
2930 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
2932 return (unsigned long)cmd;
2936 mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
2937 unsigned int changed_flags,
2938 unsigned int *total_flags)
2940 struct mwl8k_priv *priv = hw->priv;
2943 * Hardware sniffer mode is mutually exclusive with STA
2944 * operation, so refuse to enable sniffer mode if a STA
2945 * interface is active.
2947 if (priv->vif != NULL) {
2948 if (net_ratelimit())
2949 printk(KERN_INFO "%s: not enabling sniffer "
2950 "mode because STA interface is active\n",
2951 wiphy_name(hw->wiphy));
2955 if (!priv->sniffer_enabled) {
2956 if (mwl8k_enable_sniffer(hw, 1))
2958 priv->sniffer_enabled = true;
2961 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
2962 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
2968 static void mwl8k_configure_filter(struct ieee80211_hw *hw,
2969 unsigned int changed_flags,
2970 unsigned int *total_flags,
2973 struct mwl8k_priv *priv = hw->priv;
2974 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
2977 * Enable hardware sniffer mode if FIF_CONTROL or
2978 * FIF_OTHER_BSS is requested.
2980 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
2981 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
2986 /* Clear unsupported feature flags */
2987 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
2989 if (mwl8k_fw_lock(hw))
2992 if (priv->sniffer_enabled) {
2993 mwl8k_enable_sniffer(hw, 0);
2994 priv->sniffer_enabled = false;
2997 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
2998 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3000 * Disable the BSS filter.
3002 mwl8k_cmd_set_pre_scan(hw);
3007 * Enable the BSS filter.
3009 * If there is an active STA interface, use that
3010 * interface's BSSID, otherwise use a dummy one
3011 * (where the OUI part needs to be nonzero for
3012 * the BSSID to be accepted by POST_SCAN).
3014 bssid = "\x01\x00\x00\x00\x00\x00";
3015 if (priv->vif != NULL)
3016 bssid = MWL8K_VIF(priv->vif)->bssid;
3018 mwl8k_cmd_set_post_scan(hw, bssid);
3023 * If FIF_ALLMULTI is being requested, throw away the command
3024 * packet that ->prepare_multicast() built and replace it with
3025 * a command packet that enables reception of all multicast
3028 if (*total_flags & FIF_ALLMULTI) {
3030 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3034 mwl8k_post_cmd(hw, cmd);
3038 mwl8k_fw_unlock(hw);
3041 static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3043 return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value);
3046 static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3047 const struct ieee80211_tx_queue_params *params)
3049 struct mwl8k_priv *priv = hw->priv;
3052 rc = mwl8k_fw_lock(hw);
3054 if (!priv->wmm_enabled)
3055 rc = mwl8k_set_wmm(hw, 1);
3058 rc = mwl8k_set_edca_params(hw, queue,
3064 mwl8k_fw_unlock(hw);
3070 static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3071 struct ieee80211_tx_queue_stats *stats)
3073 struct mwl8k_priv *priv = hw->priv;
3074 struct mwl8k_tx_queue *txq;
3077 spin_lock_bh(&priv->tx_lock);
3078 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3079 txq = priv->txq + index;
3080 memcpy(&stats[index], &txq->stats,
3081 sizeof(struct ieee80211_tx_queue_stats));
3083 spin_unlock_bh(&priv->tx_lock);
3088 static int mwl8k_get_stats(struct ieee80211_hw *hw,
3089 struct ieee80211_low_level_stats *stats)
3091 return mwl8k_cmd_802_11_get_stat(hw, stats);
3094 static const struct ieee80211_ops mwl8k_ops = {
3096 .start = mwl8k_start,
3098 .add_interface = mwl8k_add_interface,
3099 .remove_interface = mwl8k_remove_interface,
3100 .config = mwl8k_config,
3101 .bss_info_changed = mwl8k_bss_info_changed,
3102 .prepare_multicast = mwl8k_prepare_multicast,
3103 .configure_filter = mwl8k_configure_filter,
3104 .set_rts_threshold = mwl8k_set_rts_threshold,
3105 .conf_tx = mwl8k_conf_tx,
3106 .get_tx_stats = mwl8k_get_tx_stats,
3107 .get_stats = mwl8k_get_stats,
3110 static void mwl8k_tx_reclaim_handler(unsigned long data)
3113 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3114 struct mwl8k_priv *priv = hw->priv;
3116 spin_lock_bh(&priv->tx_lock);
3117 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3118 mwl8k_txq_reclaim(hw, i, 0);
3120 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
3121 complete(priv->tx_wait);
3122 priv->tx_wait = NULL;
3124 spin_unlock_bh(&priv->tx_lock);
3127 static void mwl8k_finalize_join_worker(struct work_struct *work)
3129 struct mwl8k_priv *priv =
3130 container_of(work, struct mwl8k_priv, finalize_join_worker);
3131 struct sk_buff *skb = priv->beacon_skb;
3132 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
3134 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3137 priv->beacon_skb = NULL;
3140 static struct mwl8k_device_info di_8687 = {
3141 .part_name = "88w8687",
3142 .helper_image = "mwl8k/helper_8687.fw",
3143 .fw_image = "mwl8k/fmimage_8687.fw",
3144 .rxd_ops = &rxd_8687_ops,
3145 .modes = BIT(NL80211_IFTYPE_STATION),
3148 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
3150 PCI_VDEVICE(MARVELL, 0x2a2b),
3151 .driver_data = (unsigned long)&di_8687,
3153 PCI_VDEVICE(MARVELL, 0x2a30),
3154 .driver_data = (unsigned long)&di_8687,
3158 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3160 static int __devinit mwl8k_probe(struct pci_dev *pdev,
3161 const struct pci_device_id *id)
3163 static int printed_version = 0;
3164 struct ieee80211_hw *hw;
3165 struct mwl8k_priv *priv;
3169 if (!printed_version) {
3170 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3171 printed_version = 1;
3174 rc = pci_enable_device(pdev);
3176 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3181 rc = pci_request_regions(pdev, MWL8K_NAME);
3183 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3188 pci_set_master(pdev);
3190 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3192 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3200 priv->device_info = (void *)id->driver_data;
3201 priv->rxd_ops = priv->device_info->rxd_ops;
3202 priv->sniffer_enabled = false;
3203 priv->wmm_enabled = false;
3204 priv->pending_tx_pkts = 0;
3206 SET_IEEE80211_DEV(hw, &pdev->dev);
3207 pci_set_drvdata(pdev, hw);
3209 priv->sram = pci_iomap(pdev, 0, 0x10000);
3210 if (priv->sram == NULL) {
3211 printk(KERN_ERR "%s: Cannot map device SRAM\n",
3212 wiphy_name(hw->wiphy));
3217 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3218 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3220 priv->regs = pci_iomap(pdev, 1, 0x10000);
3221 if (priv->regs == NULL) {
3222 priv->regs = pci_iomap(pdev, 2, 0x10000);
3223 if (priv->regs == NULL) {
3224 printk(KERN_ERR "%s: Cannot map device registers\n",
3225 wiphy_name(hw->wiphy));
3230 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3231 priv->band.band = IEEE80211_BAND_2GHZ;
3232 priv->band.channels = priv->channels;
3233 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3234 priv->band.bitrates = priv->rates;
3235 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3236 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3238 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3239 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3242 * Extra headroom is the size of the required DMA header
3243 * minus the size of the smallest 802.11 frame (CTS frame).
3245 hw->extra_tx_headroom =
3246 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3248 hw->channel_change_time = 10;
3250 hw->queues = MWL8K_TX_QUEUES;
3252 hw->wiphy->interface_modes = priv->device_info->modes;
3254 /* Set rssi and noise values to dBm */
3255 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
3256 hw->vif_data_size = sizeof(struct mwl8k_vif);
3259 /* Set default radio state and preamble */
3261 priv->radio_short_preamble = 0;
3263 /* Finalize join worker */
3264 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3266 /* TX reclaim tasklet */
3267 tasklet_init(&priv->tx_reclaim_task,
3268 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3269 tasklet_disable(&priv->tx_reclaim_task);
3271 /* Power management cookie */
3272 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3273 if (priv->cookie == NULL)
3276 rc = mwl8k_rxq_init(hw, 0);
3279 rxq_refill(hw, 0, INT_MAX);
3281 mutex_init(&priv->fw_mutex);
3282 priv->fw_mutex_owner = NULL;
3283 priv->fw_mutex_depth = 0;
3284 priv->hostcmd_wait = NULL;
3286 spin_lock_init(&priv->tx_lock);
3288 priv->tx_wait = NULL;
3290 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3291 rc = mwl8k_txq_init(hw, i);
3293 goto err_free_queues;
3296 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3297 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3298 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3299 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3301 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
3302 IRQF_SHARED, MWL8K_NAME, hw);
3304 printk(KERN_ERR "%s: failed to register IRQ handler\n",
3305 wiphy_name(hw->wiphy));
3306 goto err_free_queues;
3309 /* Reset firmware and hardware */
3310 mwl8k_hw_reset(priv);
3312 /* Ask userland hotplug daemon for the device firmware */
3313 rc = mwl8k_request_firmware(priv);
3315 printk(KERN_ERR "%s: Firmware files not found\n",
3316 wiphy_name(hw->wiphy));
3320 /* Load firmware into hardware */
3321 rc = mwl8k_load_firmware(hw);
3323 printk(KERN_ERR "%s: Cannot start firmware\n",
3324 wiphy_name(hw->wiphy));
3325 goto err_stop_firmware;
3328 /* Reclaim memory once firmware is successfully loaded */
3329 mwl8k_release_firmware(priv);
3332 * Temporarily enable interrupts. Initial firmware host
3333 * commands use interrupts and avoids polling. Disable
3334 * interrupts when done.
3336 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3338 /* Get config data, mac addrs etc */
3340 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3342 rc = mwl8k_cmd_set_hw_spec(hw);
3344 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3347 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3348 wiphy_name(hw->wiphy));
3349 goto err_stop_firmware;
3352 /* Turn radio off */
3353 rc = mwl8k_cmd_802_11_radio_disable(hw);
3355 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
3356 goto err_stop_firmware;
3359 /* Clear MAC address */
3360 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3362 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3363 wiphy_name(hw->wiphy));
3364 goto err_stop_firmware;
3367 /* Disable interrupts */
3368 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3369 free_irq(priv->pdev->irq, hw);
3371 rc = ieee80211_register_hw(hw);
3373 printk(KERN_ERR "%s: Cannot register device\n",
3374 wiphy_name(hw->wiphy));
3375 goto err_stop_firmware;
3378 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
3379 wiphy_name(hw->wiphy), priv->device_info->part_name,
3380 priv->hw_rev, hw->wiphy->perm_addr,
3381 priv->ap_fw ? "AP" : "STA",
3382 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3383 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
3388 mwl8k_hw_reset(priv);
3389 mwl8k_release_firmware(priv);
3392 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3393 free_irq(priv->pdev->irq, hw);
3396 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3397 mwl8k_txq_deinit(hw, i);
3398 mwl8k_rxq_deinit(hw, 0);
3401 if (priv->cookie != NULL)
3402 pci_free_consistent(priv->pdev, 4,
3403 priv->cookie, priv->cookie_dma);
3405 if (priv->regs != NULL)
3406 pci_iounmap(pdev, priv->regs);
3408 if (priv->sram != NULL)
3409 pci_iounmap(pdev, priv->sram);
3411 pci_set_drvdata(pdev, NULL);
3412 ieee80211_free_hw(hw);
3415 pci_release_regions(pdev);
3416 pci_disable_device(pdev);
3421 static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
3423 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3426 static void __devexit mwl8k_remove(struct pci_dev *pdev)
3428 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3429 struct mwl8k_priv *priv;
3436 ieee80211_stop_queues(hw);
3438 ieee80211_unregister_hw(hw);
3440 /* Remove tx reclaim tasklet */
3441 tasklet_kill(&priv->tx_reclaim_task);
3444 mwl8k_hw_reset(priv);
3446 /* Return all skbs to mac80211 */
3447 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3448 mwl8k_txq_reclaim(hw, i, 1);
3450 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3451 mwl8k_txq_deinit(hw, i);
3453 mwl8k_rxq_deinit(hw, 0);
3455 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
3457 pci_iounmap(pdev, priv->regs);
3458 pci_iounmap(pdev, priv->sram);
3459 pci_set_drvdata(pdev, NULL);
3460 ieee80211_free_hw(hw);
3461 pci_release_regions(pdev);
3462 pci_disable_device(pdev);
3465 static struct pci_driver mwl8k_driver = {
3467 .id_table = mwl8k_pci_id_table,
3468 .probe = mwl8k_probe,
3469 .remove = __devexit_p(mwl8k_remove),
3470 .shutdown = __devexit_p(mwl8k_shutdown),
3473 static int __init mwl8k_init(void)
3475 return pci_register_driver(&mwl8k_driver);
3478 static void __exit mwl8k_exit(void)
3480 pci_unregister_driver(&mwl8k_driver);
3483 module_init(mwl8k_init);
3484 module_exit(mwl8k_exit);
3486 MODULE_DESCRIPTION(MWL8K_DESC);
3487 MODULE_VERSION(MWL8K_VERSION);
3488 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3489 MODULE_LICENSE("GPL");