2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
5 * Copyright (C) 2008, 2009, 2010 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 <linux/slab.h>
23 #include <net/mac80211.h>
24 #include <linux/moduleparam.h>
25 #include <linux/firmware.h>
26 #include <linux/workqueue.h>
28 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
29 #define MWL8K_NAME KBUILD_MODNAME
30 #define MWL8K_VERSION "0.12"
32 /* Register definitions */
33 #define MWL8K_HIU_GEN_PTR 0x00000c10
34 #define MWL8K_MODE_STA 0x0000005a
35 #define MWL8K_MODE_AP 0x000000a5
36 #define MWL8K_HIU_INT_CODE 0x00000c14
37 #define MWL8K_FWSTA_READY 0xf0f1f2f4
38 #define MWL8K_FWAP_READY 0xf1f2f4a5
39 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
40 #define MWL8K_HIU_SCRATCH 0x00000c40
42 /* Host->device communications */
43 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
44 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
45 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
46 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
47 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
48 #define MWL8K_H2A_INT_DUMMY (1 << 20)
49 #define MWL8K_H2A_INT_RESET (1 << 15)
50 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
51 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
53 /* Device->host communications */
54 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
55 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
56 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
57 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
58 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
59 #define MWL8K_A2H_INT_DUMMY (1 << 20)
60 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
61 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
62 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
63 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
64 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
65 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
66 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
67 #define MWL8K_A2H_INT_RX_READY (1 << 1)
68 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
70 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
71 MWL8K_A2H_INT_CHNL_SWITCHED | \
72 MWL8K_A2H_INT_QUEUE_EMPTY | \
73 MWL8K_A2H_INT_RADAR_DETECT | \
74 MWL8K_A2H_INT_RADIO_ON | \
75 MWL8K_A2H_INT_RADIO_OFF | \
76 MWL8K_A2H_INT_MAC_EVENT | \
77 MWL8K_A2H_INT_OPC_DONE | \
78 MWL8K_A2H_INT_RX_READY | \
79 MWL8K_A2H_INT_TX_DONE)
81 #define MWL8K_RX_QUEUES 1
82 #define MWL8K_TX_QUEUES 4
86 void (*rxd_init
)(void *rxd
, dma_addr_t next_dma_addr
);
87 void (*rxd_refill
)(void *rxd
, dma_addr_t addr
, int len
);
88 int (*rxd_process
)(void *rxd
, struct ieee80211_rx_status
*status
,
89 __le16
*qos
, s8
*noise
);
92 struct mwl8k_device_info
{
96 struct rxd_ops
*ap_rxd_ops
;
99 struct mwl8k_rx_queue
{
102 /* hw receives here */
105 /* refill descs here */
112 DEFINE_DMA_UNMAP_ADDR(dma
);
116 struct mwl8k_tx_queue
{
117 /* hw transmits here */
120 /* sw appends here */
124 struct mwl8k_tx_desc
*txd
;
126 struct sk_buff
**skb
;
130 struct ieee80211_hw
*hw
;
131 struct pci_dev
*pdev
;
133 struct mwl8k_device_info
*device_info
;
139 struct firmware
*fw_helper
;
140 struct firmware
*fw_ucode
;
142 /* hardware/firmware parameters */
144 struct rxd_ops
*rxd_ops
;
145 struct ieee80211_supported_band band_24
;
146 struct ieee80211_channel channels_24
[14];
147 struct ieee80211_rate rates_24
[14];
148 struct ieee80211_supported_band band_50
;
149 struct ieee80211_channel channels_50
[4];
150 struct ieee80211_rate rates_50
[9];
151 u32 ap_macids_supported
;
152 u32 sta_macids_supported
;
154 /* firmware access */
155 struct mutex fw_mutex
;
156 struct task_struct
*fw_mutex_owner
;
158 struct completion
*hostcmd_wait
;
160 /* lock held over TX and TX reap */
163 /* TX quiesce completion, protected by fw_mutex and tx_lock */
164 struct completion
*tx_wait
;
166 /* List of interfaces. */
168 struct list_head vif_list
;
170 /* power management status cookie from firmware */
172 dma_addr_t cookie_dma
;
179 * Running count of TX packets in flight, to avoid
180 * iterating over the transmit rings each time.
184 struct mwl8k_rx_queue rxq
[MWL8K_RX_QUEUES
];
185 struct mwl8k_tx_queue txq
[MWL8K_TX_QUEUES
];
188 bool radio_short_preamble
;
189 bool sniffer_enabled
;
192 /* XXX need to convert this to handle multiple interfaces */
194 u8 capture_bssid
[ETH_ALEN
];
195 struct sk_buff
*beacon_skb
;
198 * This FJ worker has to be global as it is scheduled from the
199 * RX handler. At this point we don't know which interface it
200 * belongs to until the list of bssids waiting to complete join
203 struct work_struct finalize_join_worker
;
205 /* Tasklet to perform TX reclaim. */
206 struct tasklet_struct poll_tx_task
;
208 /* Tasklet to perform RX. */
209 struct tasklet_struct poll_rx_task
;
211 /* Most recently reported noise in dBm */
215 /* Per interface specific private data */
217 struct list_head list
;
218 struct ieee80211_vif
*vif
;
220 /* Firmware macid for this vif. */
223 /* Non AMPDU sequence number assigned by driver. */
226 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
229 /* Index into station database. Returned by UPDATE_STADB. */
232 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
234 static const struct ieee80211_channel mwl8k_channels_24
[] = {
235 { .center_freq
= 2412, .hw_value
= 1, },
236 { .center_freq
= 2417, .hw_value
= 2, },
237 { .center_freq
= 2422, .hw_value
= 3, },
238 { .center_freq
= 2427, .hw_value
= 4, },
239 { .center_freq
= 2432, .hw_value
= 5, },
240 { .center_freq
= 2437, .hw_value
= 6, },
241 { .center_freq
= 2442, .hw_value
= 7, },
242 { .center_freq
= 2447, .hw_value
= 8, },
243 { .center_freq
= 2452, .hw_value
= 9, },
244 { .center_freq
= 2457, .hw_value
= 10, },
245 { .center_freq
= 2462, .hw_value
= 11, },
246 { .center_freq
= 2467, .hw_value
= 12, },
247 { .center_freq
= 2472, .hw_value
= 13, },
248 { .center_freq
= 2484, .hw_value
= 14, },
251 static const struct ieee80211_rate mwl8k_rates_24
[] = {
252 { .bitrate
= 10, .hw_value
= 2, },
253 { .bitrate
= 20, .hw_value
= 4, },
254 { .bitrate
= 55, .hw_value
= 11, },
255 { .bitrate
= 110, .hw_value
= 22, },
256 { .bitrate
= 220, .hw_value
= 44, },
257 { .bitrate
= 60, .hw_value
= 12, },
258 { .bitrate
= 90, .hw_value
= 18, },
259 { .bitrate
= 120, .hw_value
= 24, },
260 { .bitrate
= 180, .hw_value
= 36, },
261 { .bitrate
= 240, .hw_value
= 48, },
262 { .bitrate
= 360, .hw_value
= 72, },
263 { .bitrate
= 480, .hw_value
= 96, },
264 { .bitrate
= 540, .hw_value
= 108, },
265 { .bitrate
= 720, .hw_value
= 144, },
268 static const struct ieee80211_channel mwl8k_channels_50
[] = {
269 { .center_freq
= 5180, .hw_value
= 36, },
270 { .center_freq
= 5200, .hw_value
= 40, },
271 { .center_freq
= 5220, .hw_value
= 44, },
272 { .center_freq
= 5240, .hw_value
= 48, },
275 static const struct ieee80211_rate mwl8k_rates_50
[] = {
276 { .bitrate
= 60, .hw_value
= 12, },
277 { .bitrate
= 90, .hw_value
= 18, },
278 { .bitrate
= 120, .hw_value
= 24, },
279 { .bitrate
= 180, .hw_value
= 36, },
280 { .bitrate
= 240, .hw_value
= 48, },
281 { .bitrate
= 360, .hw_value
= 72, },
282 { .bitrate
= 480, .hw_value
= 96, },
283 { .bitrate
= 540, .hw_value
= 108, },
284 { .bitrate
= 720, .hw_value
= 144, },
287 /* Set or get info from Firmware */
288 #define MWL8K_CMD_GET 0x0000
289 #define MWL8K_CMD_SET 0x0001
290 #define MWL8K_CMD_SET_LIST 0x0002
292 /* Firmware command codes */
293 #define MWL8K_CMD_CODE_DNLD 0x0001
294 #define MWL8K_CMD_GET_HW_SPEC 0x0003
295 #define MWL8K_CMD_SET_HW_SPEC 0x0004
296 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
297 #define MWL8K_CMD_GET_STAT 0x0014
298 #define MWL8K_CMD_RADIO_CONTROL 0x001c
299 #define MWL8K_CMD_RF_TX_POWER 0x001e
300 #define MWL8K_CMD_TX_POWER 0x001f
301 #define MWL8K_CMD_RF_ANTENNA 0x0020
302 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
303 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
304 #define MWL8K_CMD_SET_POST_SCAN 0x0108
305 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
306 #define MWL8K_CMD_SET_AID 0x010d
307 #define MWL8K_CMD_SET_RATE 0x0110
308 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
309 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
310 #define MWL8K_CMD_SET_SLOT 0x0114
311 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
312 #define MWL8K_CMD_SET_WMM_MODE 0x0123
313 #define MWL8K_CMD_MIMO_CONFIG 0x0125
314 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
315 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
316 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
317 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
318 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
319 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
320 #define MWL8K_CMD_UPDATE_STADB 0x1123
322 static const char *mwl8k_cmd_name(__le16 cmd
, char *buf
, int bufsize
)
324 u16 command
= le16_to_cpu(cmd
);
326 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
327 snprintf(buf, bufsize, "%s", #x);\
330 switch (command
& ~0x8000) {
331 MWL8K_CMDNAME(CODE_DNLD
);
332 MWL8K_CMDNAME(GET_HW_SPEC
);
333 MWL8K_CMDNAME(SET_HW_SPEC
);
334 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
335 MWL8K_CMDNAME(GET_STAT
);
336 MWL8K_CMDNAME(RADIO_CONTROL
);
337 MWL8K_CMDNAME(RF_TX_POWER
);
338 MWL8K_CMDNAME(TX_POWER
);
339 MWL8K_CMDNAME(RF_ANTENNA
);
340 MWL8K_CMDNAME(SET_BEACON
);
341 MWL8K_CMDNAME(SET_PRE_SCAN
);
342 MWL8K_CMDNAME(SET_POST_SCAN
);
343 MWL8K_CMDNAME(SET_RF_CHANNEL
);
344 MWL8K_CMDNAME(SET_AID
);
345 MWL8K_CMDNAME(SET_RATE
);
346 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
347 MWL8K_CMDNAME(RTS_THRESHOLD
);
348 MWL8K_CMDNAME(SET_SLOT
);
349 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
350 MWL8K_CMDNAME(SET_WMM_MODE
);
351 MWL8K_CMDNAME(MIMO_CONFIG
);
352 MWL8K_CMDNAME(USE_FIXED_RATE
);
353 MWL8K_CMDNAME(ENABLE_SNIFFER
);
354 MWL8K_CMDNAME(SET_MAC_ADDR
);
355 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
356 MWL8K_CMDNAME(BSS_START
);
357 MWL8K_CMDNAME(SET_NEW_STN
);
358 MWL8K_CMDNAME(UPDATE_STADB
);
360 snprintf(buf
, bufsize
, "0x%x", cmd
);
367 /* Hardware and firmware reset */
368 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
370 iowrite32(MWL8K_H2A_INT_RESET
,
371 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
372 iowrite32(MWL8K_H2A_INT_RESET
,
373 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
377 /* Release fw image */
378 static void mwl8k_release_fw(struct firmware
**fw
)
382 release_firmware(*fw
);
386 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
388 mwl8k_release_fw(&priv
->fw_ucode
);
389 mwl8k_release_fw(&priv
->fw_helper
);
392 /* Request fw image */
393 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
394 const char *fname
, struct firmware
**fw
)
396 /* release current image */
398 mwl8k_release_fw(fw
);
400 return request_firmware((const struct firmware
**)fw
,
401 fname
, &priv
->pdev
->dev
);
404 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
)
406 struct mwl8k_device_info
*di
= priv
->device_info
;
409 if (di
->helper_image
!= NULL
) {
410 rc
= mwl8k_request_fw(priv
, di
->helper_image
, &priv
->fw_helper
);
412 printk(KERN_ERR
"%s: Error requesting helper "
413 "firmware file %s\n", pci_name(priv
->pdev
),
419 rc
= mwl8k_request_fw(priv
, di
->fw_image
, &priv
->fw_ucode
);
421 printk(KERN_ERR
"%s: Error requesting firmware file %s\n",
422 pci_name(priv
->pdev
), di
->fw_image
);
423 mwl8k_release_fw(&priv
->fw_helper
);
430 struct mwl8k_cmd_pkt
{
443 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
445 void __iomem
*regs
= priv
->regs
;
449 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
450 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
453 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
454 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
455 iowrite32(MWL8K_H2A_INT_DOORBELL
,
456 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
457 iowrite32(MWL8K_H2A_INT_DUMMY
,
458 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
464 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
465 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
466 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
474 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
476 return loops
? 0 : -ETIMEDOUT
;
479 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
480 const u8
*data
, size_t length
)
482 struct mwl8k_cmd_pkt
*cmd
;
486 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
490 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
497 int block_size
= length
> 256 ? 256 : length
;
499 memcpy(cmd
->payload
, data
+ done
, block_size
);
500 cmd
->length
= cpu_to_le16(block_size
);
502 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
503 sizeof(*cmd
) + block_size
);
508 length
-= block_size
;
513 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
521 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
522 const u8
*data
, size_t length
)
524 unsigned char *buffer
;
525 int may_continue
, rc
= 0;
526 u32 done
, prev_block_size
;
528 buffer
= kmalloc(1024, GFP_KERNEL
);
535 while (may_continue
> 0) {
538 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
539 if (block_size
& 1) {
543 done
+= prev_block_size
;
544 length
-= prev_block_size
;
547 if (block_size
> 1024 || block_size
> length
) {
557 if (block_size
== 0) {
564 prev_block_size
= block_size
;
565 memcpy(buffer
, data
+ done
, block_size
);
567 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
572 if (!rc
&& length
!= 0)
580 static int mwl8k_load_firmware(struct ieee80211_hw
*hw
)
582 struct mwl8k_priv
*priv
= hw
->priv
;
583 struct firmware
*fw
= priv
->fw_ucode
;
587 if (!memcmp(fw
->data
, "\x01\x00\x00\x00", 4)) {
588 struct firmware
*helper
= priv
->fw_helper
;
590 if (helper
== NULL
) {
591 printk(KERN_ERR
"%s: helper image needed but none "
592 "given\n", pci_name(priv
->pdev
));
596 rc
= mwl8k_load_fw_image(priv
, helper
->data
, helper
->size
);
598 printk(KERN_ERR
"%s: unable to load firmware "
599 "helper image\n", pci_name(priv
->pdev
));
604 rc
= mwl8k_feed_fw_image(priv
, fw
->data
, fw
->size
);
606 rc
= mwl8k_load_fw_image(priv
, fw
->data
, fw
->size
);
610 printk(KERN_ERR
"%s: unable to load firmware image\n",
611 pci_name(priv
->pdev
));
615 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
621 ready_code
= ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
622 if (ready_code
== MWL8K_FWAP_READY
) {
625 } else if (ready_code
== MWL8K_FWSTA_READY
) {
634 return loops
? 0 : -ETIMEDOUT
;
638 /* DMA header used by firmware and hardware. */
639 struct mwl8k_dma_data
{
641 struct ieee80211_hdr wh
;
645 /* Routines to add/remove DMA header from skb. */
646 static inline void mwl8k_remove_dma_header(struct sk_buff
*skb
, __le16 qos
)
648 struct mwl8k_dma_data
*tr
;
651 tr
= (struct mwl8k_dma_data
*)skb
->data
;
652 hdrlen
= ieee80211_hdrlen(tr
->wh
.frame_control
);
654 if (hdrlen
!= sizeof(tr
->wh
)) {
655 if (ieee80211_is_data_qos(tr
->wh
.frame_control
)) {
656 memmove(tr
->data
- hdrlen
, &tr
->wh
, hdrlen
- 2);
657 *((__le16
*)(tr
->data
- 2)) = qos
;
659 memmove(tr
->data
- hdrlen
, &tr
->wh
, hdrlen
);
663 if (hdrlen
!= sizeof(*tr
))
664 skb_pull(skb
, sizeof(*tr
) - hdrlen
);
667 static inline void mwl8k_add_dma_header(struct sk_buff
*skb
)
669 struct ieee80211_hdr
*wh
;
671 struct mwl8k_dma_data
*tr
;
674 * Add a firmware DMA header; the firmware requires that we
675 * present a 2-byte payload length followed by a 4-address
676 * header (without QoS field), followed (optionally) by any
677 * WEP/ExtIV header (but only filled in for CCMP).
679 wh
= (struct ieee80211_hdr
*)skb
->data
;
681 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
682 if (hdrlen
!= sizeof(*tr
))
683 skb_push(skb
, sizeof(*tr
) - hdrlen
);
685 if (ieee80211_is_data_qos(wh
->frame_control
))
688 tr
= (struct mwl8k_dma_data
*)skb
->data
;
690 memmove(&tr
->wh
, wh
, hdrlen
);
691 if (hdrlen
!= sizeof(tr
->wh
))
692 memset(((void *)&tr
->wh
) + hdrlen
, 0, sizeof(tr
->wh
) - hdrlen
);
695 * Firmware length is the length of the fully formed "802.11
696 * payload". That is, everything except for the 802.11 header.
697 * This includes all crypto material including the MIC.
699 tr
->fwlen
= cpu_to_le16(skb
->len
- sizeof(*tr
));
704 * Packet reception for 88w8366 AP firmware.
706 struct mwl8k_rxd_8366_ap
{
710 __le32 pkt_phys_addr
;
711 __le32 next_rxd_phys_addr
;
715 __le32 hw_noise_floor_info
;
724 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
725 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
726 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
728 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
730 static void mwl8k_rxd_8366_ap_init(void *_rxd
, dma_addr_t next_dma_addr
)
732 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
734 rxd
->next_rxd_phys_addr
= cpu_to_le32(next_dma_addr
);
735 rxd
->rx_ctrl
= MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST
;
738 static void mwl8k_rxd_8366_ap_refill(void *_rxd
, dma_addr_t addr
, int len
)
740 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
742 rxd
->pkt_len
= cpu_to_le16(len
);
743 rxd
->pkt_phys_addr
= cpu_to_le32(addr
);
749 mwl8k_rxd_8366_ap_process(void *_rxd
, struct ieee80211_rx_status
*status
,
750 __le16
*qos
, s8
*noise
)
752 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
754 if (!(rxd
->rx_ctrl
& MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST
))
758 memset(status
, 0, sizeof(*status
));
760 status
->signal
= -rxd
->rssi
;
761 *noise
= -rxd
->noise_floor
;
763 if (rxd
->rate
& MWL8K_8366_AP_RATE_INFO_MCS_FORMAT
) {
764 status
->flag
|= RX_FLAG_HT
;
765 if (rxd
->rate
& MWL8K_8366_AP_RATE_INFO_40MHZ
)
766 status
->flag
|= RX_FLAG_40MHZ
;
767 status
->rate_idx
= MWL8K_8366_AP_RATE_INFO_RATEID(rxd
->rate
);
771 for (i
= 0; i
< ARRAY_SIZE(mwl8k_rates_24
); i
++) {
772 if (mwl8k_rates_24
[i
].hw_value
== rxd
->rate
) {
773 status
->rate_idx
= i
;
779 if (rxd
->channel
> 14) {
780 status
->band
= IEEE80211_BAND_5GHZ
;
781 if (!(status
->flag
& RX_FLAG_HT
))
782 status
->rate_idx
-= 5;
784 status
->band
= IEEE80211_BAND_2GHZ
;
786 status
->freq
= ieee80211_channel_to_frequency(rxd
->channel
);
788 *qos
= rxd
->qos_control
;
790 return le16_to_cpu(rxd
->pkt_len
);
793 static struct rxd_ops rxd_8366_ap_ops
= {
794 .rxd_size
= sizeof(struct mwl8k_rxd_8366_ap
),
795 .rxd_init
= mwl8k_rxd_8366_ap_init
,
796 .rxd_refill
= mwl8k_rxd_8366_ap_refill
,
797 .rxd_process
= mwl8k_rxd_8366_ap_process
,
801 * Packet reception for STA firmware.
803 struct mwl8k_rxd_sta
{
807 __le32 pkt_phys_addr
;
808 __le32 next_rxd_phys_addr
;
820 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
821 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
822 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
823 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
824 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
825 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
827 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
829 static void mwl8k_rxd_sta_init(void *_rxd
, dma_addr_t next_dma_addr
)
831 struct mwl8k_rxd_sta
*rxd
= _rxd
;
833 rxd
->next_rxd_phys_addr
= cpu_to_le32(next_dma_addr
);
834 rxd
->rx_ctrl
= MWL8K_STA_RX_CTRL_OWNED_BY_HOST
;
837 static void mwl8k_rxd_sta_refill(void *_rxd
, dma_addr_t addr
, int len
)
839 struct mwl8k_rxd_sta
*rxd
= _rxd
;
841 rxd
->pkt_len
= cpu_to_le16(len
);
842 rxd
->pkt_phys_addr
= cpu_to_le32(addr
);
848 mwl8k_rxd_sta_process(void *_rxd
, struct ieee80211_rx_status
*status
,
849 __le16
*qos
, s8
*noise
)
851 struct mwl8k_rxd_sta
*rxd
= _rxd
;
854 if (!(rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_OWNED_BY_HOST
))
858 rate_info
= le16_to_cpu(rxd
->rate_info
);
860 memset(status
, 0, sizeof(*status
));
862 status
->signal
= -rxd
->rssi
;
863 *noise
= -rxd
->noise_level
;
864 status
->antenna
= MWL8K_STA_RATE_INFO_ANTSELECT(rate_info
);
865 status
->rate_idx
= MWL8K_STA_RATE_INFO_RATEID(rate_info
);
867 if (rate_info
& MWL8K_STA_RATE_INFO_SHORTPRE
)
868 status
->flag
|= RX_FLAG_SHORTPRE
;
869 if (rate_info
& MWL8K_STA_RATE_INFO_40MHZ
)
870 status
->flag
|= RX_FLAG_40MHZ
;
871 if (rate_info
& MWL8K_STA_RATE_INFO_SHORTGI
)
872 status
->flag
|= RX_FLAG_SHORT_GI
;
873 if (rate_info
& MWL8K_STA_RATE_INFO_MCS_FORMAT
)
874 status
->flag
|= RX_FLAG_HT
;
876 if (rxd
->channel
> 14) {
877 status
->band
= IEEE80211_BAND_5GHZ
;
878 if (!(status
->flag
& RX_FLAG_HT
))
879 status
->rate_idx
-= 5;
881 status
->band
= IEEE80211_BAND_2GHZ
;
883 status
->freq
= ieee80211_channel_to_frequency(rxd
->channel
);
885 *qos
= rxd
->qos_control
;
887 return le16_to_cpu(rxd
->pkt_len
);
890 static struct rxd_ops rxd_sta_ops
= {
891 .rxd_size
= sizeof(struct mwl8k_rxd_sta
),
892 .rxd_init
= mwl8k_rxd_sta_init
,
893 .rxd_refill
= mwl8k_rxd_sta_refill
,
894 .rxd_process
= mwl8k_rxd_sta_process
,
898 #define MWL8K_RX_DESCS 256
899 #define MWL8K_RX_MAXSZ 3800
901 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
903 struct mwl8k_priv
*priv
= hw
->priv
;
904 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
912 size
= MWL8K_RX_DESCS
* priv
->rxd_ops
->rxd_size
;
914 rxq
->rxd
= pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rxd_dma
);
915 if (rxq
->rxd
== NULL
) {
916 wiphy_err(hw
->wiphy
, "failed to alloc RX descriptors\n");
919 memset(rxq
->rxd
, 0, size
);
921 rxq
->buf
= kmalloc(MWL8K_RX_DESCS
* sizeof(*rxq
->buf
), GFP_KERNEL
);
922 if (rxq
->buf
== NULL
) {
923 wiphy_err(hw
->wiphy
, "failed to alloc RX skbuff list\n");
924 pci_free_consistent(priv
->pdev
, size
, rxq
->rxd
, rxq
->rxd_dma
);
927 memset(rxq
->buf
, 0, MWL8K_RX_DESCS
* sizeof(*rxq
->buf
));
929 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
933 dma_addr_t next_dma_addr
;
935 desc_size
= priv
->rxd_ops
->rxd_size
;
936 rxd
= rxq
->rxd
+ (i
* priv
->rxd_ops
->rxd_size
);
939 if (nexti
== MWL8K_RX_DESCS
)
941 next_dma_addr
= rxq
->rxd_dma
+ (nexti
* desc_size
);
943 priv
->rxd_ops
->rxd_init(rxd
, next_dma_addr
);
949 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
951 struct mwl8k_priv
*priv
= hw
->priv
;
952 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
956 while (rxq
->rxd_count
< MWL8K_RX_DESCS
&& limit
--) {
962 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
966 addr
= pci_map_single(priv
->pdev
, skb
->data
,
967 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
);
971 if (rxq
->tail
== MWL8K_RX_DESCS
)
973 rxq
->buf
[rx
].skb
= skb
;
974 dma_unmap_addr_set(&rxq
->buf
[rx
], dma
, addr
);
976 rxd
= rxq
->rxd
+ (rx
* priv
->rxd_ops
->rxd_size
);
977 priv
->rxd_ops
->rxd_refill(rxd
, addr
, MWL8K_RX_MAXSZ
);
985 /* Must be called only when the card's reception is completely halted */
986 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
988 struct mwl8k_priv
*priv
= hw
->priv
;
989 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
992 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
993 if (rxq
->buf
[i
].skb
!= NULL
) {
994 pci_unmap_single(priv
->pdev
,
995 dma_unmap_addr(&rxq
->buf
[i
], dma
),
996 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
997 dma_unmap_addr_set(&rxq
->buf
[i
], dma
, 0);
999 kfree_skb(rxq
->buf
[i
].skb
);
1000 rxq
->buf
[i
].skb
= NULL
;
1007 pci_free_consistent(priv
->pdev
,
1008 MWL8K_RX_DESCS
* priv
->rxd_ops
->rxd_size
,
1009 rxq
->rxd
, rxq
->rxd_dma
);
1015 * Scan a list of BSSIDs to process for finalize join.
1016 * Allows for extension to process multiple BSSIDs.
1019 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
1021 return priv
->capture_beacon
&&
1022 ieee80211_is_beacon(wh
->frame_control
) &&
1023 !compare_ether_addr(wh
->addr3
, priv
->capture_bssid
);
1026 static inline void mwl8k_save_beacon(struct ieee80211_hw
*hw
,
1027 struct sk_buff
*skb
)
1029 struct mwl8k_priv
*priv
= hw
->priv
;
1031 priv
->capture_beacon
= false;
1032 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
1035 * Use GFP_ATOMIC as rxq_process is called from
1036 * the primary interrupt handler, memory allocation call
1039 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
1040 if (priv
->beacon_skb
!= NULL
)
1041 ieee80211_queue_work(hw
, &priv
->finalize_join_worker
);
1044 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
1046 struct mwl8k_priv
*priv
= hw
->priv
;
1047 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1051 while (rxq
->rxd_count
&& limit
--) {
1052 struct sk_buff
*skb
;
1055 struct ieee80211_rx_status status
;
1058 skb
= rxq
->buf
[rxq
->head
].skb
;
1062 rxd
= rxq
->rxd
+ (rxq
->head
* priv
->rxd_ops
->rxd_size
);
1064 pkt_len
= priv
->rxd_ops
->rxd_process(rxd
, &status
, &qos
,
1069 rxq
->buf
[rxq
->head
].skb
= NULL
;
1071 pci_unmap_single(priv
->pdev
,
1072 dma_unmap_addr(&rxq
->buf
[rxq
->head
], dma
),
1073 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
1074 dma_unmap_addr_set(&rxq
->buf
[rxq
->head
], dma
, 0);
1077 if (rxq
->head
== MWL8K_RX_DESCS
)
1082 skb_put(skb
, pkt_len
);
1083 mwl8k_remove_dma_header(skb
, qos
);
1086 * Check for a pending join operation. Save a
1087 * copy of the beacon and schedule a tasklet to
1088 * send a FINALIZE_JOIN command to the firmware.
1090 if (mwl8k_capture_bssid(priv
, (void *)skb
->data
))
1091 mwl8k_save_beacon(hw
, skb
);
1093 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
1094 ieee80211_rx_irqsafe(hw
, skb
);
1104 * Packet transmission.
1107 #define MWL8K_TXD_STATUS_OK 0x00000001
1108 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1109 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1110 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1111 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1113 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1114 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1115 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1116 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1117 #define MWL8K_QOS_EOSP 0x0010
1119 struct mwl8k_tx_desc
{
1124 __le32 pkt_phys_addr
;
1126 __u8 dest_MAC_addr
[ETH_ALEN
];
1127 __le32 next_txd_phys_addr
;
1134 #define MWL8K_TX_DESCS 128
1136 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1138 struct mwl8k_priv
*priv
= hw
->priv
;
1139 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1147 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1149 txq
->txd
= pci_alloc_consistent(priv
->pdev
, size
, &txq
->txd_dma
);
1150 if (txq
->txd
== NULL
) {
1151 wiphy_err(hw
->wiphy
, "failed to alloc TX descriptors\n");
1154 memset(txq
->txd
, 0, size
);
1156 txq
->skb
= kmalloc(MWL8K_TX_DESCS
* sizeof(*txq
->skb
), GFP_KERNEL
);
1157 if (txq
->skb
== NULL
) {
1158 wiphy_err(hw
->wiphy
, "failed to alloc TX skbuff list\n");
1159 pci_free_consistent(priv
->pdev
, size
, txq
->txd
, txq
->txd_dma
);
1162 memset(txq
->skb
, 0, MWL8K_TX_DESCS
* sizeof(*txq
->skb
));
1164 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1165 struct mwl8k_tx_desc
*tx_desc
;
1168 tx_desc
= txq
->txd
+ i
;
1169 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1171 tx_desc
->status
= 0;
1172 tx_desc
->next_txd_phys_addr
=
1173 cpu_to_le32(txq
->txd_dma
+ nexti
* sizeof(*tx_desc
));
1179 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1181 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1182 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1183 iowrite32(MWL8K_H2A_INT_DUMMY
,
1184 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1185 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1188 static void mwl8k_dump_tx_rings(struct ieee80211_hw
*hw
)
1190 struct mwl8k_priv
*priv
= hw
->priv
;
1193 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
1194 struct mwl8k_tx_queue
*txq
= priv
->txq
+ i
;
1200 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1201 struct mwl8k_tx_desc
*tx_desc
= txq
->txd
+ desc
;
1204 status
= le32_to_cpu(tx_desc
->status
);
1205 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1210 if (tx_desc
->pkt_len
== 0)
1214 wiphy_err(hw
->wiphy
,
1215 "txq[%d] len=%d head=%d tail=%d "
1216 "fw_owned=%d drv_owned=%d unused=%d\n",
1218 txq
->len
, txq
->head
, txq
->tail
,
1219 fw_owned
, drv_owned
, unused
);
1224 * Must be called with priv->fw_mutex held and tx queues stopped.
1226 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1228 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
)
1230 struct mwl8k_priv
*priv
= hw
->priv
;
1231 DECLARE_COMPLETION_ONSTACK(tx_wait
);
1238 * The TX queues are stopped at this point, so this test
1239 * doesn't need to take ->tx_lock.
1241 if (!priv
->pending_tx_pkts
)
1247 spin_lock_bh(&priv
->tx_lock
);
1248 priv
->tx_wait
= &tx_wait
;
1251 unsigned long timeout
;
1253 oldcount
= priv
->pending_tx_pkts
;
1255 spin_unlock_bh(&priv
->tx_lock
);
1256 timeout
= wait_for_completion_timeout(&tx_wait
,
1257 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS
));
1258 spin_lock_bh(&priv
->tx_lock
);
1261 WARN_ON(priv
->pending_tx_pkts
);
1263 wiphy_notice(hw
->wiphy
, "tx rings drained\n");
1268 if (priv
->pending_tx_pkts
< oldcount
) {
1269 wiphy_notice(hw
->wiphy
,
1270 "waiting for tx rings to drain (%d -> %d pkts)\n",
1271 oldcount
, priv
->pending_tx_pkts
);
1276 priv
->tx_wait
= NULL
;
1278 wiphy_err(hw
->wiphy
, "tx rings stuck for %d ms\n",
1279 MWL8K_TX_WAIT_TIMEOUT_MS
);
1280 mwl8k_dump_tx_rings(hw
);
1284 spin_unlock_bh(&priv
->tx_lock
);
1289 #define MWL8K_TXD_SUCCESS(status) \
1290 ((status) & (MWL8K_TXD_STATUS_OK | \
1291 MWL8K_TXD_STATUS_OK_RETRY | \
1292 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1295 mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int limit
, int force
)
1297 struct mwl8k_priv
*priv
= hw
->priv
;
1298 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1302 while (txq
->len
> 0 && limit
--) {
1304 struct mwl8k_tx_desc
*tx_desc
;
1307 struct sk_buff
*skb
;
1308 struct ieee80211_tx_info
*info
;
1312 tx_desc
= txq
->txd
+ tx
;
1314 status
= le32_to_cpu(tx_desc
->status
);
1316 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1320 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1323 txq
->head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1324 BUG_ON(txq
->len
== 0);
1326 priv
->pending_tx_pkts
--;
1328 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1329 size
= le16_to_cpu(tx_desc
->pkt_len
);
1331 txq
->skb
[tx
] = NULL
;
1333 BUG_ON(skb
== NULL
);
1334 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1336 mwl8k_remove_dma_header(skb
, tx_desc
->qos_control
);
1338 /* Mark descriptor as unused */
1339 tx_desc
->pkt_phys_addr
= 0;
1340 tx_desc
->pkt_len
= 0;
1342 info
= IEEE80211_SKB_CB(skb
);
1343 ieee80211_tx_info_clear_status(info
);
1344 if (MWL8K_TXD_SUCCESS(status
))
1345 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1347 ieee80211_tx_status_irqsafe(hw
, skb
);
1352 if (processed
&& priv
->radio_on
&& !mutex_is_locked(&priv
->fw_mutex
))
1353 ieee80211_wake_queue(hw
, index
);
1358 /* must be called only when the card's transmit is completely halted */
1359 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1361 struct mwl8k_priv
*priv
= hw
->priv
;
1362 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1364 mwl8k_txq_reclaim(hw
, index
, INT_MAX
, 1);
1369 pci_free_consistent(priv
->pdev
,
1370 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1371 txq
->txd
, txq
->txd_dma
);
1376 mwl8k_txq_xmit(struct ieee80211_hw
*hw
, int index
, struct sk_buff
*skb
)
1378 struct mwl8k_priv
*priv
= hw
->priv
;
1379 struct ieee80211_tx_info
*tx_info
;
1380 struct mwl8k_vif
*mwl8k_vif
;
1381 struct ieee80211_hdr
*wh
;
1382 struct mwl8k_tx_queue
*txq
;
1383 struct mwl8k_tx_desc
*tx
;
1389 wh
= (struct ieee80211_hdr
*)skb
->data
;
1390 if (ieee80211_is_data_qos(wh
->frame_control
))
1391 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1395 mwl8k_add_dma_header(skb
);
1396 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1398 tx_info
= IEEE80211_SKB_CB(skb
);
1399 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1401 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1402 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1403 wh
->seq_ctrl
|= cpu_to_le16(mwl8k_vif
->seqno
);
1404 mwl8k_vif
->seqno
+= 0x10;
1407 /* Setup firmware control bit fields for each frame type. */
1410 if (ieee80211_is_mgmt(wh
->frame_control
) ||
1411 ieee80211_is_ctl(wh
->frame_control
)) {
1413 qos
|= MWL8K_QOS_QLEN_UNSPEC
| MWL8K_QOS_EOSP
;
1414 } else if (ieee80211_is_data(wh
->frame_control
)) {
1416 if (is_multicast_ether_addr(wh
->addr1
))
1417 txstatus
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1419 qos
&= ~MWL8K_QOS_ACK_POLICY_MASK
;
1420 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1421 qos
|= MWL8K_QOS_ACK_POLICY_BLOCKACK
;
1423 qos
|= MWL8K_QOS_ACK_POLICY_NORMAL
;
1426 dma
= pci_map_single(priv
->pdev
, skb
->data
,
1427 skb
->len
, PCI_DMA_TODEVICE
);
1429 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
1430 wiphy_debug(hw
->wiphy
,
1431 "failed to dma map skb, dropping TX frame.\n");
1433 return NETDEV_TX_OK
;
1436 spin_lock_bh(&priv
->tx_lock
);
1438 txq
= priv
->txq
+ index
;
1440 BUG_ON(txq
->skb
[txq
->tail
] != NULL
);
1441 txq
->skb
[txq
->tail
] = skb
;
1443 tx
= txq
->txd
+ txq
->tail
;
1444 tx
->data_rate
= txdatarate
;
1445 tx
->tx_priority
= index
;
1446 tx
->qos_control
= cpu_to_le16(qos
);
1447 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
1448 tx
->pkt_len
= cpu_to_le16(skb
->len
);
1450 if (!priv
->ap_fw
&& tx_info
->control
.sta
!= NULL
)
1451 tx
->peer_id
= MWL8K_STA(tx_info
->control
.sta
)->peer_id
;
1455 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
| txstatus
);
1458 priv
->pending_tx_pkts
++;
1461 if (txq
->tail
== MWL8K_TX_DESCS
)
1464 if (txq
->head
== txq
->tail
)
1465 ieee80211_stop_queue(hw
, index
);
1467 mwl8k_tx_start(priv
);
1469 spin_unlock_bh(&priv
->tx_lock
);
1471 return NETDEV_TX_OK
;
1478 * We have the following requirements for issuing firmware commands:
1479 * - Some commands require that the packet transmit path is idle when
1480 * the command is issued. (For simplicity, we'll just quiesce the
1481 * transmit path for every command.)
1482 * - There are certain sequences of commands that need to be issued to
1483 * the hardware sequentially, with no other intervening commands.
1485 * This leads to an implementation of a "firmware lock" as a mutex that
1486 * can be taken recursively, and which is taken by both the low-level
1487 * command submission function (mwl8k_post_cmd) as well as any users of
1488 * that function that require issuing of an atomic sequence of commands,
1489 * and quiesces the transmit path whenever it's taken.
1491 static int mwl8k_fw_lock(struct ieee80211_hw
*hw
)
1493 struct mwl8k_priv
*priv
= hw
->priv
;
1495 if (priv
->fw_mutex_owner
!= current
) {
1498 mutex_lock(&priv
->fw_mutex
);
1499 ieee80211_stop_queues(hw
);
1501 rc
= mwl8k_tx_wait_empty(hw
);
1503 ieee80211_wake_queues(hw
);
1504 mutex_unlock(&priv
->fw_mutex
);
1509 priv
->fw_mutex_owner
= current
;
1512 priv
->fw_mutex_depth
++;
1517 static void mwl8k_fw_unlock(struct ieee80211_hw
*hw
)
1519 struct mwl8k_priv
*priv
= hw
->priv
;
1521 if (!--priv
->fw_mutex_depth
) {
1522 ieee80211_wake_queues(hw
);
1523 priv
->fw_mutex_owner
= NULL
;
1524 mutex_unlock(&priv
->fw_mutex
);
1530 * Command processing.
1533 /* Timeout firmware commands after 10s */
1534 #define MWL8K_CMD_TIMEOUT_MS 10000
1536 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
1538 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
1539 struct mwl8k_priv
*priv
= hw
->priv
;
1540 void __iomem
*regs
= priv
->regs
;
1541 dma_addr_t dma_addr
;
1542 unsigned int dma_size
;
1544 unsigned long timeout
= 0;
1547 cmd
->result
= (__force __le16
) 0xffff;
1548 dma_size
= le16_to_cpu(cmd
->length
);
1549 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
1550 PCI_DMA_BIDIRECTIONAL
);
1551 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
1554 rc
= mwl8k_fw_lock(hw
);
1556 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1557 PCI_DMA_BIDIRECTIONAL
);
1561 priv
->hostcmd_wait
= &cmd_wait
;
1562 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
1563 iowrite32(MWL8K_H2A_INT_DOORBELL
,
1564 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1565 iowrite32(MWL8K_H2A_INT_DUMMY
,
1566 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1568 timeout
= wait_for_completion_timeout(&cmd_wait
,
1569 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
1571 priv
->hostcmd_wait
= NULL
;
1573 mwl8k_fw_unlock(hw
);
1575 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
1576 PCI_DMA_BIDIRECTIONAL
);
1579 wiphy_err(hw
->wiphy
, "Command %s timeout after %u ms\n",
1580 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1581 MWL8K_CMD_TIMEOUT_MS
);
1586 ms
= MWL8K_CMD_TIMEOUT_MS
- jiffies_to_msecs(timeout
);
1588 rc
= cmd
->result
? -EINVAL
: 0;
1590 wiphy_err(hw
->wiphy
, "Command %s error 0x%x\n",
1591 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
1592 le16_to_cpu(cmd
->result
));
1594 wiphy_notice(hw
->wiphy
, "Command %s took %d ms\n",
1595 mwl8k_cmd_name(cmd
->code
,
1603 static int mwl8k_post_pervif_cmd(struct ieee80211_hw
*hw
,
1604 struct ieee80211_vif
*vif
,
1605 struct mwl8k_cmd_pkt
*cmd
)
1608 cmd
->macid
= MWL8K_VIF(vif
)->macid
;
1609 return mwl8k_post_cmd(hw
, cmd
);
1613 * Setup code shared between STA and AP firmware images.
1615 static void mwl8k_setup_2ghz_band(struct ieee80211_hw
*hw
)
1617 struct mwl8k_priv
*priv
= hw
->priv
;
1619 BUILD_BUG_ON(sizeof(priv
->channels_24
) != sizeof(mwl8k_channels_24
));
1620 memcpy(priv
->channels_24
, mwl8k_channels_24
, sizeof(mwl8k_channels_24
));
1622 BUILD_BUG_ON(sizeof(priv
->rates_24
) != sizeof(mwl8k_rates_24
));
1623 memcpy(priv
->rates_24
, mwl8k_rates_24
, sizeof(mwl8k_rates_24
));
1625 priv
->band_24
.band
= IEEE80211_BAND_2GHZ
;
1626 priv
->band_24
.channels
= priv
->channels_24
;
1627 priv
->band_24
.n_channels
= ARRAY_SIZE(mwl8k_channels_24
);
1628 priv
->band_24
.bitrates
= priv
->rates_24
;
1629 priv
->band_24
.n_bitrates
= ARRAY_SIZE(mwl8k_rates_24
);
1631 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band_24
;
1634 static void mwl8k_setup_5ghz_band(struct ieee80211_hw
*hw
)
1636 struct mwl8k_priv
*priv
= hw
->priv
;
1638 BUILD_BUG_ON(sizeof(priv
->channels_50
) != sizeof(mwl8k_channels_50
));
1639 memcpy(priv
->channels_50
, mwl8k_channels_50
, sizeof(mwl8k_channels_50
));
1641 BUILD_BUG_ON(sizeof(priv
->rates_50
) != sizeof(mwl8k_rates_50
));
1642 memcpy(priv
->rates_50
, mwl8k_rates_50
, sizeof(mwl8k_rates_50
));
1644 priv
->band_50
.band
= IEEE80211_BAND_5GHZ
;
1645 priv
->band_50
.channels
= priv
->channels_50
;
1646 priv
->band_50
.n_channels
= ARRAY_SIZE(mwl8k_channels_50
);
1647 priv
->band_50
.bitrates
= priv
->rates_50
;
1648 priv
->band_50
.n_bitrates
= ARRAY_SIZE(mwl8k_rates_50
);
1650 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &priv
->band_50
;
1654 * CMD_GET_HW_SPEC (STA version).
1656 struct mwl8k_cmd_get_hw_spec_sta
{
1657 struct mwl8k_cmd_pkt header
;
1659 __u8 host_interface
;
1661 __u8 perm_addr
[ETH_ALEN
];
1666 __u8 mcs_bitmap
[16];
1667 __le32 rx_queue_ptr
;
1668 __le32 num_tx_queues
;
1669 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1671 __le32 num_tx_desc_per_queue
;
1675 #define MWL8K_CAP_MAX_AMSDU 0x20000000
1676 #define MWL8K_CAP_GREENFIELD 0x08000000
1677 #define MWL8K_CAP_AMPDU 0x04000000
1678 #define MWL8K_CAP_RX_STBC 0x01000000
1679 #define MWL8K_CAP_TX_STBC 0x00800000
1680 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1681 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1682 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1683 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1684 #define MWL8K_CAP_DELAY_BA 0x00003000
1685 #define MWL8K_CAP_MIMO 0x00000200
1686 #define MWL8K_CAP_40MHZ 0x00000100
1687 #define MWL8K_CAP_BAND_MASK 0x00000007
1688 #define MWL8K_CAP_5GHZ 0x00000004
1689 #define MWL8K_CAP_2GHZ4 0x00000001
1692 mwl8k_set_ht_caps(struct ieee80211_hw
*hw
,
1693 struct ieee80211_supported_band
*band
, u32 cap
)
1698 band
->ht_cap
.ht_supported
= 1;
1700 if (cap
& MWL8K_CAP_MAX_AMSDU
)
1701 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
1702 if (cap
& MWL8K_CAP_GREENFIELD
)
1703 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_GRN_FLD
;
1704 if (cap
& MWL8K_CAP_AMPDU
) {
1705 hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
1706 band
->ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
1707 band
->ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_NONE
;
1709 if (cap
& MWL8K_CAP_RX_STBC
)
1710 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_RX_STBC
;
1711 if (cap
& MWL8K_CAP_TX_STBC
)
1712 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
1713 if (cap
& MWL8K_CAP_SHORTGI_40MHZ
)
1714 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
1715 if (cap
& MWL8K_CAP_SHORTGI_20MHZ
)
1716 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
1717 if (cap
& MWL8K_CAP_DELAY_BA
)
1718 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_DELAY_BA
;
1719 if (cap
& MWL8K_CAP_40MHZ
)
1720 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
1722 rx_streams
= hweight32(cap
& MWL8K_CAP_RX_ANTENNA_MASK
);
1723 tx_streams
= hweight32(cap
& MWL8K_CAP_TX_ANTENNA_MASK
);
1725 band
->ht_cap
.mcs
.rx_mask
[0] = 0xff;
1726 if (rx_streams
>= 2)
1727 band
->ht_cap
.mcs
.rx_mask
[1] = 0xff;
1728 if (rx_streams
>= 3)
1729 band
->ht_cap
.mcs
.rx_mask
[2] = 0xff;
1730 band
->ht_cap
.mcs
.rx_mask
[4] = 0x01;
1731 band
->ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
1733 if (rx_streams
!= tx_streams
) {
1734 band
->ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_RX_DIFF
;
1735 band
->ht_cap
.mcs
.tx_params
|= (tx_streams
- 1) <<
1736 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
1741 mwl8k_set_caps(struct ieee80211_hw
*hw
, u32 caps
)
1743 struct mwl8k_priv
*priv
= hw
->priv
;
1745 if ((caps
& MWL8K_CAP_2GHZ4
) || !(caps
& MWL8K_CAP_BAND_MASK
)) {
1746 mwl8k_setup_2ghz_band(hw
);
1747 if (caps
& MWL8K_CAP_MIMO
)
1748 mwl8k_set_ht_caps(hw
, &priv
->band_24
, caps
);
1751 if (caps
& MWL8K_CAP_5GHZ
) {
1752 mwl8k_setup_5ghz_band(hw
);
1753 if (caps
& MWL8K_CAP_MIMO
)
1754 mwl8k_set_ht_caps(hw
, &priv
->band_50
, caps
);
1758 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw
*hw
)
1760 struct mwl8k_priv
*priv
= hw
->priv
;
1761 struct mwl8k_cmd_get_hw_spec_sta
*cmd
;
1765 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1769 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1770 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1772 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1773 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1774 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rxd_dma
);
1775 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1776 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1777 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].txd_dma
);
1778 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1779 cmd
->total_rxd
= cpu_to_le32(MWL8K_RX_DESCS
);
1781 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1784 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1785 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1786 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1787 priv
->hw_rev
= cmd
->hw_rev
;
1788 mwl8k_set_caps(hw
, le32_to_cpu(cmd
->caps
));
1789 priv
->ap_macids_supported
= 0x00000000;
1790 priv
->sta_macids_supported
= 0x00000001;
1798 * CMD_GET_HW_SPEC (AP version).
1800 struct mwl8k_cmd_get_hw_spec_ap
{
1801 struct mwl8k_cmd_pkt header
;
1803 __u8 host_interface
;
1806 __u8 perm_addr
[ETH_ALEN
];
1819 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw
*hw
)
1821 struct mwl8k_priv
*priv
= hw
->priv
;
1822 struct mwl8k_cmd_get_hw_spec_ap
*cmd
;
1825 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1829 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
1830 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1832 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
1833 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1835 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1840 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
1841 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
1842 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
1843 priv
->hw_rev
= cmd
->hw_rev
;
1844 mwl8k_setup_2ghz_band(hw
);
1845 priv
->ap_macids_supported
= 0x000000ff;
1846 priv
->sta_macids_supported
= 0x00000000;
1848 off
= le32_to_cpu(cmd
->wcbbase0
) & 0xffff;
1849 iowrite32(priv
->txq
[0].txd_dma
, priv
->sram
+ off
);
1851 off
= le32_to_cpu(cmd
->rxwrptr
) & 0xffff;
1852 iowrite32(priv
->rxq
[0].rxd_dma
, priv
->sram
+ off
);
1854 off
= le32_to_cpu(cmd
->rxrdptr
) & 0xffff;
1855 iowrite32(priv
->rxq
[0].rxd_dma
, priv
->sram
+ off
);
1857 off
= le32_to_cpu(cmd
->wcbbase1
) & 0xffff;
1858 iowrite32(priv
->txq
[1].txd_dma
, priv
->sram
+ off
);
1860 off
= le32_to_cpu(cmd
->wcbbase2
) & 0xffff;
1861 iowrite32(priv
->txq
[2].txd_dma
, priv
->sram
+ off
);
1863 off
= le32_to_cpu(cmd
->wcbbase3
) & 0xffff;
1864 iowrite32(priv
->txq
[3].txd_dma
, priv
->sram
+ off
);
1874 struct mwl8k_cmd_set_hw_spec
{
1875 struct mwl8k_cmd_pkt header
;
1877 __u8 host_interface
;
1879 __u8 perm_addr
[ETH_ALEN
];
1884 __le32 rx_queue_ptr
;
1885 __le32 num_tx_queues
;
1886 __le32 tx_queue_ptrs
[MWL8K_TX_QUEUES
];
1888 __le32 num_tx_desc_per_queue
;
1892 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1893 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1894 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
1896 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw
*hw
)
1898 struct mwl8k_priv
*priv
= hw
->priv
;
1899 struct mwl8k_cmd_set_hw_spec
*cmd
;
1903 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1907 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_HW_SPEC
);
1908 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
1910 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
1911 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rxd_dma
);
1912 cmd
->num_tx_queues
= cpu_to_le32(MWL8K_TX_QUEUES
);
1913 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
1914 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].txd_dma
);
1915 cmd
->flags
= cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT
|
1916 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP
|
1917 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON
);
1918 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
1919 cmd
->total_rxd
= cpu_to_le32(MWL8K_RX_DESCS
);
1921 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
1928 * CMD_MAC_MULTICAST_ADR.
1930 struct mwl8k_cmd_mac_multicast_adr
{
1931 struct mwl8k_cmd_pkt header
;
1934 __u8 addr
[0][ETH_ALEN
];
1937 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
1938 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
1939 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1940 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
1942 static struct mwl8k_cmd_pkt
*
1943 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
, int allmulti
,
1944 struct netdev_hw_addr_list
*mc_list
)
1946 struct mwl8k_priv
*priv
= hw
->priv
;
1947 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
1952 mc_count
= netdev_hw_addr_list_count(mc_list
);
1954 if (allmulti
|| mc_count
> priv
->num_mcaddrs
) {
1959 size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
1961 cmd
= kzalloc(size
, GFP_ATOMIC
);
1965 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
1966 cmd
->header
.length
= cpu_to_le16(size
);
1967 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED
|
1968 MWL8K_ENABLE_RX_BROADCAST
);
1971 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST
);
1972 } else if (mc_count
) {
1973 struct netdev_hw_addr
*ha
;
1976 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
1977 cmd
->numaddr
= cpu_to_le16(mc_count
);
1978 netdev_hw_addr_list_for_each(ha
, mc_list
) {
1979 memcpy(cmd
->addr
[i
], ha
->addr
, ETH_ALEN
);
1983 return &cmd
->header
;
1989 struct mwl8k_cmd_get_stat
{
1990 struct mwl8k_cmd_pkt header
;
1994 #define MWL8K_STAT_ACK_FAILURE 9
1995 #define MWL8K_STAT_RTS_FAILURE 12
1996 #define MWL8K_STAT_FCS_ERROR 24
1997 #define MWL8K_STAT_RTS_SUCCESS 11
1999 static int mwl8k_cmd_get_stat(struct ieee80211_hw
*hw
,
2000 struct ieee80211_low_level_stats
*stats
)
2002 struct mwl8k_cmd_get_stat
*cmd
;
2005 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2009 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
2010 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2012 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2014 stats
->dot11ACKFailureCount
=
2015 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
2016 stats
->dot11RTSFailureCount
=
2017 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
2018 stats
->dot11FCSErrorCount
=
2019 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
2020 stats
->dot11RTSSuccessCount
=
2021 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
2029 * CMD_RADIO_CONTROL.
2031 struct mwl8k_cmd_radio_control
{
2032 struct mwl8k_cmd_pkt header
;
2039 mwl8k_cmd_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
2041 struct mwl8k_priv
*priv
= hw
->priv
;
2042 struct mwl8k_cmd_radio_control
*cmd
;
2045 if (enable
== priv
->radio_on
&& !force
)
2048 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2052 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
2053 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2054 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2055 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
2056 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
2058 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2062 priv
->radio_on
= enable
;
2067 static int mwl8k_cmd_radio_disable(struct ieee80211_hw
*hw
)
2069 return mwl8k_cmd_radio_control(hw
, 0, 0);
2072 static int mwl8k_cmd_radio_enable(struct ieee80211_hw
*hw
)
2074 return mwl8k_cmd_radio_control(hw
, 1, 0);
2078 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
2080 struct mwl8k_priv
*priv
= hw
->priv
;
2082 priv
->radio_short_preamble
= short_preamble
;
2084 return mwl8k_cmd_radio_control(hw
, 1, 1);
2090 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2092 struct mwl8k_cmd_rf_tx_power
{
2093 struct mwl8k_cmd_pkt header
;
2095 __le16 support_level
;
2096 __le16 current_level
;
2098 __le16 power_level_list
[MWL8K_RF_TX_POWER_LEVEL_TOTAL
];
2101 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
2103 struct mwl8k_cmd_rf_tx_power
*cmd
;
2106 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2110 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
2111 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2112 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2113 cmd
->support_level
= cpu_to_le16(dBm
);
2115 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2124 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2126 struct mwl8k_cmd_tx_power
{
2127 struct mwl8k_cmd_pkt header
;
2133 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
2134 } __attribute__((packed
));
2136 static int mwl8k_cmd_tx_power(struct ieee80211_hw
*hw
,
2137 struct ieee80211_conf
*conf
,
2140 struct ieee80211_channel
*channel
= conf
->channel
;
2141 struct mwl8k_cmd_tx_power
*cmd
;
2145 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2149 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_TX_POWER
);
2150 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2151 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET_LIST
);
2153 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2154 cmd
->band
= cpu_to_le16(0x1);
2155 else if (channel
->band
== IEEE80211_BAND_5GHZ
)
2156 cmd
->band
= cpu_to_le16(0x4);
2158 cmd
->channel
= channel
->hw_value
;
2160 if (conf
->channel_type
== NL80211_CHAN_NO_HT
||
2161 conf
->channel_type
== NL80211_CHAN_HT20
) {
2162 cmd
->bw
= cpu_to_le16(0x2);
2164 cmd
->bw
= cpu_to_le16(0x4);
2165 if (conf
->channel_type
== NL80211_CHAN_HT40MINUS
)
2166 cmd
->sub_ch
= cpu_to_le16(0x3);
2167 else if (conf
->channel_type
== NL80211_CHAN_HT40PLUS
)
2168 cmd
->sub_ch
= cpu_to_le16(0x1);
2171 for (i
= 0; i
< MWL8K_TX_POWER_LEVEL_TOTAL
; i
++)
2172 cmd
->power_level_list
[i
] = cpu_to_le16(pwr
);
2174 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2183 struct mwl8k_cmd_rf_antenna
{
2184 struct mwl8k_cmd_pkt header
;
2189 #define MWL8K_RF_ANTENNA_RX 1
2190 #define MWL8K_RF_ANTENNA_TX 2
2193 mwl8k_cmd_rf_antenna(struct ieee80211_hw
*hw
, int antenna
, int mask
)
2195 struct mwl8k_cmd_rf_antenna
*cmd
;
2198 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2202 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_ANTENNA
);
2203 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2204 cmd
->antenna
= cpu_to_le16(antenna
);
2205 cmd
->mode
= cpu_to_le16(mask
);
2207 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2216 struct mwl8k_cmd_set_beacon
{
2217 struct mwl8k_cmd_pkt header
;
2222 static int mwl8k_cmd_set_beacon(struct ieee80211_hw
*hw
,
2223 struct ieee80211_vif
*vif
, u8
*beacon
, int len
)
2225 struct mwl8k_cmd_set_beacon
*cmd
;
2228 cmd
= kzalloc(sizeof(*cmd
) + len
, GFP_KERNEL
);
2232 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_BEACON
);
2233 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
) + len
);
2234 cmd
->beacon_len
= cpu_to_le16(len
);
2235 memcpy(cmd
->beacon
, beacon
, len
);
2237 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
2246 struct mwl8k_cmd_set_pre_scan
{
2247 struct mwl8k_cmd_pkt header
;
2250 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
2252 struct mwl8k_cmd_set_pre_scan
*cmd
;
2255 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2259 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
2260 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2262 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2269 * CMD_SET_POST_SCAN.
2271 struct mwl8k_cmd_set_post_scan
{
2272 struct mwl8k_cmd_pkt header
;
2274 __u8 bssid
[ETH_ALEN
];
2278 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, const __u8
*mac
)
2280 struct mwl8k_cmd_set_post_scan
*cmd
;
2283 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2287 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
2288 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2290 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
2292 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2299 * CMD_SET_RF_CHANNEL.
2301 struct mwl8k_cmd_set_rf_channel
{
2302 struct mwl8k_cmd_pkt header
;
2304 __u8 current_channel
;
2305 __le32 channel_flags
;
2308 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
2309 struct ieee80211_conf
*conf
)
2311 struct ieee80211_channel
*channel
= conf
->channel
;
2312 struct mwl8k_cmd_set_rf_channel
*cmd
;
2315 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2319 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
2320 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2321 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2322 cmd
->current_channel
= channel
->hw_value
;
2324 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2325 cmd
->channel_flags
|= cpu_to_le32(0x00000001);
2326 else if (channel
->band
== IEEE80211_BAND_5GHZ
)
2327 cmd
->channel_flags
|= cpu_to_le32(0x00000004);
2329 if (conf
->channel_type
== NL80211_CHAN_NO_HT
||
2330 conf
->channel_type
== NL80211_CHAN_HT20
)
2331 cmd
->channel_flags
|= cpu_to_le32(0x00000080);
2332 else if (conf
->channel_type
== NL80211_CHAN_HT40MINUS
)
2333 cmd
->channel_flags
|= cpu_to_le32(0x000001900);
2334 else if (conf
->channel_type
== NL80211_CHAN_HT40PLUS
)
2335 cmd
->channel_flags
|= cpu_to_le32(0x000000900);
2337 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2346 #define MWL8K_FRAME_PROT_DISABLED 0x00
2347 #define MWL8K_FRAME_PROT_11G 0x07
2348 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2349 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2351 struct mwl8k_cmd_update_set_aid
{
2352 struct mwl8k_cmd_pkt header
;
2355 /* AP's MAC address (BSSID) */
2356 __u8 bssid
[ETH_ALEN
];
2357 __le16 protection_mode
;
2358 __u8 supp_rates
[14];
2361 static void legacy_rate_mask_to_array(u8
*rates
, u32 mask
)
2367 * Clear nonstandard rates 4 and 13.
2371 for (i
= 0, j
= 0; i
< 14; i
++) {
2372 if (mask
& (1 << i
))
2373 rates
[j
++] = mwl8k_rates_24
[i
].hw_value
;
2378 mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
2379 struct ieee80211_vif
*vif
, u32 legacy_rate_mask
)
2381 struct mwl8k_cmd_update_set_aid
*cmd
;
2385 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2389 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
2390 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2391 cmd
->aid
= cpu_to_le16(vif
->bss_conf
.aid
);
2392 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
2394 if (vif
->bss_conf
.use_cts_prot
) {
2395 prot_mode
= MWL8K_FRAME_PROT_11G
;
2397 switch (vif
->bss_conf
.ht_operation_mode
&
2398 IEEE80211_HT_OP_MODE_PROTECTION
) {
2399 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
2400 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
2402 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
2403 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
2406 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
2410 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
2412 legacy_rate_mask_to_array(cmd
->supp_rates
, legacy_rate_mask
);
2414 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2423 struct mwl8k_cmd_set_rate
{
2424 struct mwl8k_cmd_pkt header
;
2425 __u8 legacy_rates
[14];
2427 /* Bitmap for supported MCS codes. */
2433 mwl8k_cmd_set_rate(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
2434 u32 legacy_rate_mask
, u8
*mcs_rates
)
2436 struct mwl8k_cmd_set_rate
*cmd
;
2439 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2443 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
2444 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2445 legacy_rate_mask_to_array(cmd
->legacy_rates
, legacy_rate_mask
);
2446 memcpy(cmd
->mcs_set
, mcs_rates
, 16);
2448 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2455 * CMD_FINALIZE_JOIN.
2457 #define MWL8K_FJ_BEACON_MAXLEN 128
2459 struct mwl8k_cmd_finalize_join
{
2460 struct mwl8k_cmd_pkt header
;
2461 __le32 sleep_interval
; /* Number of beacon periods to sleep */
2462 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
2465 static int mwl8k_cmd_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
2466 int framelen
, int dtim
)
2468 struct mwl8k_cmd_finalize_join
*cmd
;
2469 struct ieee80211_mgmt
*payload
= frame
;
2473 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2477 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
2478 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2479 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
2481 payload_len
= framelen
- ieee80211_hdrlen(payload
->frame_control
);
2482 if (payload_len
< 0)
2484 else if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
2485 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
2487 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
2489 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2496 * CMD_SET_RTS_THRESHOLD.
2498 struct mwl8k_cmd_set_rts_threshold
{
2499 struct mwl8k_cmd_pkt header
;
2505 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw
*hw
, int rts_thresh
)
2507 struct mwl8k_cmd_set_rts_threshold
*cmd
;
2510 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2514 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
2515 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2516 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2517 cmd
->threshold
= cpu_to_le16(rts_thresh
);
2519 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2528 struct mwl8k_cmd_set_slot
{
2529 struct mwl8k_cmd_pkt header
;
2534 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, bool short_slot_time
)
2536 struct mwl8k_cmd_set_slot
*cmd
;
2539 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2543 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
2544 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2545 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2546 cmd
->short_slot
= short_slot_time
;
2548 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2555 * CMD_SET_EDCA_PARAMS.
2557 struct mwl8k_cmd_set_edca_params
{
2558 struct mwl8k_cmd_pkt header
;
2560 /* See MWL8K_SET_EDCA_XXX below */
2563 /* TX opportunity in units of 32 us */
2568 /* Log exponent of max contention period: 0...15 */
2571 /* Log exponent of min contention period: 0...15 */
2574 /* Adaptive interframe spacing in units of 32us */
2577 /* TX queue to configure */
2581 /* Log exponent of max contention period: 0...15 */
2584 /* Log exponent of min contention period: 0...15 */
2587 /* Adaptive interframe spacing in units of 32us */
2590 /* TX queue to configure */
2596 #define MWL8K_SET_EDCA_CW 0x01
2597 #define MWL8K_SET_EDCA_TXOP 0x02
2598 #define MWL8K_SET_EDCA_AIFS 0x04
2600 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2601 MWL8K_SET_EDCA_TXOP | \
2602 MWL8K_SET_EDCA_AIFS)
2605 mwl8k_cmd_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
2606 __u16 cw_min
, __u16 cw_max
,
2607 __u8 aifs
, __u16 txop
)
2609 struct mwl8k_priv
*priv
= hw
->priv
;
2610 struct mwl8k_cmd_set_edca_params
*cmd
;
2613 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2617 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
2618 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2619 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
2620 cmd
->txop
= cpu_to_le16(txop
);
2622 cmd
->ap
.log_cw_max
= cpu_to_le32(ilog2(cw_max
+ 1));
2623 cmd
->ap
.log_cw_min
= cpu_to_le32(ilog2(cw_min
+ 1));
2624 cmd
->ap
.aifs
= aifs
;
2627 cmd
->sta
.log_cw_max
= (u8
)ilog2(cw_max
+ 1);
2628 cmd
->sta
.log_cw_min
= (u8
)ilog2(cw_min
+ 1);
2629 cmd
->sta
.aifs
= aifs
;
2630 cmd
->sta
.txq
= qnum
;
2633 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2642 struct mwl8k_cmd_set_wmm_mode
{
2643 struct mwl8k_cmd_pkt header
;
2647 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw
*hw
, bool enable
)
2649 struct mwl8k_priv
*priv
= hw
->priv
;
2650 struct mwl8k_cmd_set_wmm_mode
*cmd
;
2653 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2657 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
2658 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2659 cmd
->action
= cpu_to_le16(!!enable
);
2661 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2665 priv
->wmm_enabled
= enable
;
2673 struct mwl8k_cmd_mimo_config
{
2674 struct mwl8k_cmd_pkt header
;
2676 __u8 rx_antenna_map
;
2677 __u8 tx_antenna_map
;
2680 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
2682 struct mwl8k_cmd_mimo_config
*cmd
;
2685 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2689 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
2690 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2691 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
2692 cmd
->rx_antenna_map
= rx
;
2693 cmd
->tx_antenna_map
= tx
;
2695 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2702 * CMD_USE_FIXED_RATE (STA version).
2704 struct mwl8k_cmd_use_fixed_rate_sta
{
2705 struct mwl8k_cmd_pkt header
;
2707 __le32 allow_rate_drop
;
2711 __le32 enable_retry
;
2720 #define MWL8K_USE_AUTO_RATE 0x0002
2721 #define MWL8K_UCAST_RATE 0
2723 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw
*hw
)
2725 struct mwl8k_cmd_use_fixed_rate_sta
*cmd
;
2728 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2732 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2733 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2734 cmd
->action
= cpu_to_le32(MWL8K_USE_AUTO_RATE
);
2735 cmd
->rate_type
= cpu_to_le32(MWL8K_UCAST_RATE
);
2737 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2744 * CMD_USE_FIXED_RATE (AP version).
2746 struct mwl8k_cmd_use_fixed_rate_ap
{
2747 struct mwl8k_cmd_pkt header
;
2749 __le32 allow_rate_drop
;
2751 struct mwl8k_rate_entry_ap
{
2753 __le32 enable_retry
;
2758 u8 multicast_rate_type
;
2763 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw
*hw
, int mcast
, int mgmt
)
2765 struct mwl8k_cmd_use_fixed_rate_ap
*cmd
;
2768 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2772 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
2773 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2774 cmd
->action
= cpu_to_le32(MWL8K_USE_AUTO_RATE
);
2775 cmd
->multicast_rate
= mcast
;
2776 cmd
->management_rate
= mgmt
;
2778 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2785 * CMD_ENABLE_SNIFFER.
2787 struct mwl8k_cmd_enable_sniffer
{
2788 struct mwl8k_cmd_pkt header
;
2792 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
2794 struct mwl8k_cmd_enable_sniffer
*cmd
;
2797 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2801 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
2802 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2803 cmd
->action
= cpu_to_le32(!!enable
);
2805 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2814 struct mwl8k_cmd_set_mac_addr
{
2815 struct mwl8k_cmd_pkt header
;
2819 __u8 mac_addr
[ETH_ALEN
];
2821 __u8 mac_addr
[ETH_ALEN
];
2825 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2826 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
2827 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
2828 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
2830 static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw
*hw
,
2831 struct ieee80211_vif
*vif
, u8
*mac
)
2833 struct mwl8k_priv
*priv
= hw
->priv
;
2834 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
2835 struct mwl8k_cmd_set_mac_addr
*cmd
;
2839 mac_type
= MWL8K_MAC_TYPE_PRIMARY_AP
;
2840 if (vif
!= NULL
&& vif
->type
== NL80211_IFTYPE_STATION
) {
2841 if (mwl8k_vif
->macid
+ 1 == ffs(priv
->sta_macids_supported
))
2842 mac_type
= MWL8K_MAC_TYPE_PRIMARY_CLIENT
;
2844 mac_type
= MWL8K_MAC_TYPE_SECONDARY_CLIENT
;
2845 } else if (vif
!= NULL
&& vif
->type
== NL80211_IFTYPE_AP
) {
2846 if (mwl8k_vif
->macid
+ 1 == ffs(priv
->ap_macids_supported
))
2847 mac_type
= MWL8K_MAC_TYPE_PRIMARY_AP
;
2849 mac_type
= MWL8K_MAC_TYPE_SECONDARY_AP
;
2852 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2856 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR
);
2857 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2859 cmd
->mbss
.mac_type
= cpu_to_le16(mac_type
);
2860 memcpy(cmd
->mbss
.mac_addr
, mac
, ETH_ALEN
);
2862 memcpy(cmd
->mac_addr
, mac
, ETH_ALEN
);
2865 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
2872 * CMD_SET_RATEADAPT_MODE.
2874 struct mwl8k_cmd_set_rate_adapt_mode
{
2875 struct mwl8k_cmd_pkt header
;
2880 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw
*hw
, __u16 mode
)
2882 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
2885 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2889 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
2890 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2891 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2892 cmd
->mode
= cpu_to_le16(mode
);
2894 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2903 struct mwl8k_cmd_bss_start
{
2904 struct mwl8k_cmd_pkt header
;
2908 static int mwl8k_cmd_bss_start(struct ieee80211_hw
*hw
,
2909 struct ieee80211_vif
*vif
, int enable
)
2911 struct mwl8k_cmd_bss_start
*cmd
;
2914 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2918 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BSS_START
);
2919 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2920 cmd
->enable
= cpu_to_le32(enable
);
2922 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
2931 struct mwl8k_cmd_set_new_stn
{
2932 struct mwl8k_cmd_pkt header
;
2938 __le32 legacy_rates
;
2941 __le16 ht_capabilities_info
;
2942 __u8 mac_ht_param_info
;
2944 __u8 control_channel
;
2953 #define MWL8K_STA_ACTION_ADD 0
2954 #define MWL8K_STA_ACTION_REMOVE 2
2956 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw
*hw
,
2957 struct ieee80211_vif
*vif
,
2958 struct ieee80211_sta
*sta
)
2960 struct mwl8k_cmd_set_new_stn
*cmd
;
2964 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2968 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
2969 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2970 cmd
->aid
= cpu_to_le16(sta
->aid
);
2971 memcpy(cmd
->mac_addr
, sta
->addr
, ETH_ALEN
);
2972 cmd
->stn_id
= cpu_to_le16(sta
->aid
);
2973 cmd
->action
= cpu_to_le16(MWL8K_STA_ACTION_ADD
);
2974 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
2975 rates
= sta
->supp_rates
[IEEE80211_BAND_2GHZ
];
2977 rates
= sta
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
2978 cmd
->legacy_rates
= cpu_to_le32(rates
);
2979 if (sta
->ht_cap
.ht_supported
) {
2980 cmd
->ht_rates
[0] = sta
->ht_cap
.mcs
.rx_mask
[0];
2981 cmd
->ht_rates
[1] = sta
->ht_cap
.mcs
.rx_mask
[1];
2982 cmd
->ht_rates
[2] = sta
->ht_cap
.mcs
.rx_mask
[2];
2983 cmd
->ht_rates
[3] = sta
->ht_cap
.mcs
.rx_mask
[3];
2984 cmd
->ht_capabilities_info
= cpu_to_le16(sta
->ht_cap
.cap
);
2985 cmd
->mac_ht_param_info
= (sta
->ht_cap
.ampdu_factor
& 3) |
2986 ((sta
->ht_cap
.ampdu_density
& 7) << 2);
2987 cmd
->is_qos_sta
= 1;
2990 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
2996 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw
*hw
,
2997 struct ieee80211_vif
*vif
)
2999 struct mwl8k_cmd_set_new_stn
*cmd
;
3002 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3006 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3007 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3008 memcpy(cmd
->mac_addr
, vif
->addr
, ETH_ALEN
);
3010 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3016 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw
*hw
,
3017 struct ieee80211_vif
*vif
, u8
*addr
)
3019 struct mwl8k_cmd_set_new_stn
*cmd
;
3022 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3026 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3027 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3028 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
3029 cmd
->action
= cpu_to_le16(MWL8K_STA_ACTION_REMOVE
);
3031 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3040 struct ewc_ht_info
{
3046 struct peer_capability_info
{
3047 /* Peer type - AP vs. STA. */
3050 /* Basic 802.11 capabilities from assoc resp. */
3053 /* Set if peer supports 802.11n high throughput (HT). */
3056 /* Valid if HT is supported. */
3058 __u8 extended_ht_caps
;
3059 struct ewc_ht_info ewc_info
;
3061 /* Legacy rate table. Intersection of our rates and peer rates. */
3062 __u8 legacy_rates
[12];
3064 /* HT rate table. Intersection of our rates and peer rates. */
3068 /* If set, interoperability mode, no proprietary extensions. */
3072 __le16 amsdu_enabled
;
3075 struct mwl8k_cmd_update_stadb
{
3076 struct mwl8k_cmd_pkt header
;
3078 /* See STADB_ACTION_TYPE */
3081 /* Peer MAC address */
3082 __u8 peer_addr
[ETH_ALEN
];
3086 /* Peer info - valid during add/update. */
3087 struct peer_capability_info peer_info
;
3090 #define MWL8K_STA_DB_MODIFY_ENTRY 1
3091 #define MWL8K_STA_DB_DEL_ENTRY 2
3093 /* Peer Entry flags - used to define the type of the peer node */
3094 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
3096 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw
*hw
,
3097 struct ieee80211_vif
*vif
,
3098 struct ieee80211_sta
*sta
)
3100 struct mwl8k_cmd_update_stadb
*cmd
;
3101 struct peer_capability_info
*p
;
3105 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3109 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
3110 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3111 cmd
->action
= cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY
);
3112 memcpy(cmd
->peer_addr
, sta
->addr
, ETH_ALEN
);
3114 p
= &cmd
->peer_info
;
3115 p
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
3116 p
->basic_caps
= cpu_to_le16(vif
->bss_conf
.assoc_capability
);
3117 p
->ht_support
= sta
->ht_cap
.ht_supported
;
3118 p
->ht_caps
= cpu_to_le16(sta
->ht_cap
.cap
);
3119 p
->extended_ht_caps
= (sta
->ht_cap
.ampdu_factor
& 3) |
3120 ((sta
->ht_cap
.ampdu_density
& 7) << 2);
3121 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
3122 rates
= sta
->supp_rates
[IEEE80211_BAND_2GHZ
];
3124 rates
= sta
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
3125 legacy_rate_mask_to_array(p
->legacy_rates
, rates
);
3126 memcpy(p
->ht_rates
, sta
->ht_cap
.mcs
.rx_mask
, 16);
3128 p
->amsdu_enabled
= 0;
3130 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3133 return rc
? rc
: p
->station_id
;
3136 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw
*hw
,
3137 struct ieee80211_vif
*vif
, u8
*addr
)
3139 struct mwl8k_cmd_update_stadb
*cmd
;
3142 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3146 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
3147 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3148 cmd
->action
= cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY
);
3149 memcpy(cmd
->peer_addr
, addr
, ETH_ALEN
);
3151 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3159 * Interrupt handling.
3161 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
3163 struct ieee80211_hw
*hw
= dev_id
;
3164 struct mwl8k_priv
*priv
= hw
->priv
;
3167 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3171 if (status
& MWL8K_A2H_INT_TX_DONE
) {
3172 status
&= ~MWL8K_A2H_INT_TX_DONE
;
3173 tasklet_schedule(&priv
->poll_tx_task
);
3176 if (status
& MWL8K_A2H_INT_RX_READY
) {
3177 status
&= ~MWL8K_A2H_INT_RX_READY
;
3178 tasklet_schedule(&priv
->poll_rx_task
);
3182 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3184 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
3185 if (priv
->hostcmd_wait
!= NULL
)
3186 complete(priv
->hostcmd_wait
);
3189 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
3190 if (!mutex_is_locked(&priv
->fw_mutex
) &&
3191 priv
->radio_on
&& priv
->pending_tx_pkts
)
3192 mwl8k_tx_start(priv
);
3198 static void mwl8k_tx_poll(unsigned long data
)
3200 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
3201 struct mwl8k_priv
*priv
= hw
->priv
;
3207 spin_lock_bh(&priv
->tx_lock
);
3209 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3210 limit
-= mwl8k_txq_reclaim(hw
, i
, limit
, 0);
3212 if (!priv
->pending_tx_pkts
&& priv
->tx_wait
!= NULL
) {
3213 complete(priv
->tx_wait
);
3214 priv
->tx_wait
= NULL
;
3217 spin_unlock_bh(&priv
->tx_lock
);
3220 writel(~MWL8K_A2H_INT_TX_DONE
,
3221 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3223 tasklet_schedule(&priv
->poll_tx_task
);
3227 static void mwl8k_rx_poll(unsigned long data
)
3229 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
3230 struct mwl8k_priv
*priv
= hw
->priv
;
3234 limit
-= rxq_process(hw
, 0, limit
);
3235 limit
-= rxq_refill(hw
, 0, limit
);
3238 writel(~MWL8K_A2H_INT_RX_READY
,
3239 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
3241 tasklet_schedule(&priv
->poll_rx_task
);
3247 * Core driver operations.
3249 static int mwl8k_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3251 struct mwl8k_priv
*priv
= hw
->priv
;
3252 int index
= skb_get_queue_mapping(skb
);
3255 if (!priv
->radio_on
) {
3256 wiphy_debug(hw
->wiphy
,
3257 "dropped TX frame since radio disabled\n");
3259 return NETDEV_TX_OK
;
3262 rc
= mwl8k_txq_xmit(hw
, index
, skb
);
3267 static int mwl8k_start(struct ieee80211_hw
*hw
)
3269 struct mwl8k_priv
*priv
= hw
->priv
;
3272 rc
= request_irq(priv
->pdev
->irq
, mwl8k_interrupt
,
3273 IRQF_SHARED
, MWL8K_NAME
, hw
);
3275 wiphy_err(hw
->wiphy
, "failed to register IRQ handler\n");
3279 /* Enable TX reclaim and RX tasklets. */
3280 tasklet_enable(&priv
->poll_tx_task
);
3281 tasklet_enable(&priv
->poll_rx_task
);
3283 /* Enable interrupts */
3284 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3286 rc
= mwl8k_fw_lock(hw
);
3288 rc
= mwl8k_cmd_radio_enable(hw
);
3292 rc
= mwl8k_cmd_enable_sniffer(hw
, 0);
3295 rc
= mwl8k_cmd_set_pre_scan(hw
);
3298 rc
= mwl8k_cmd_set_post_scan(hw
,
3299 "\x00\x00\x00\x00\x00\x00");
3303 rc
= mwl8k_cmd_set_rateadapt_mode(hw
, 0);
3306 rc
= mwl8k_cmd_set_wmm_mode(hw
, 0);
3308 mwl8k_fw_unlock(hw
);
3312 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3313 free_irq(priv
->pdev
->irq
, hw
);
3314 tasklet_disable(&priv
->poll_tx_task
);
3315 tasklet_disable(&priv
->poll_rx_task
);
3321 static void mwl8k_stop(struct ieee80211_hw
*hw
)
3323 struct mwl8k_priv
*priv
= hw
->priv
;
3326 mwl8k_cmd_radio_disable(hw
);
3328 ieee80211_stop_queues(hw
);
3330 /* Disable interrupts */
3331 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
3332 free_irq(priv
->pdev
->irq
, hw
);
3334 /* Stop finalize join worker */
3335 cancel_work_sync(&priv
->finalize_join_worker
);
3336 if (priv
->beacon_skb
!= NULL
)
3337 dev_kfree_skb(priv
->beacon_skb
);
3339 /* Stop TX reclaim and RX tasklets. */
3340 tasklet_disable(&priv
->poll_tx_task
);
3341 tasklet_disable(&priv
->poll_rx_task
);
3343 /* Return all skbs to mac80211 */
3344 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
3345 mwl8k_txq_reclaim(hw
, i
, INT_MAX
, 1);
3348 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
3349 struct ieee80211_vif
*vif
)
3351 struct mwl8k_priv
*priv
= hw
->priv
;
3352 struct mwl8k_vif
*mwl8k_vif
;
3353 u32 macids_supported
;
3357 * Reject interface creation if sniffer mode is active, as
3358 * STA operation is mutually exclusive with hardware sniffer
3359 * mode. (Sniffer mode is only used on STA firmware.)
3361 if (priv
->sniffer_enabled
) {
3362 wiphy_info(hw
->wiphy
,
3363 "unable to create STA interface because sniffer mode is enabled\n");
3368 switch (vif
->type
) {
3369 case NL80211_IFTYPE_AP
:
3370 macids_supported
= priv
->ap_macids_supported
;
3372 case NL80211_IFTYPE_STATION
:
3373 macids_supported
= priv
->sta_macids_supported
;
3379 macid
= ffs(macids_supported
& ~priv
->macids_used
);
3383 /* Setup driver private area. */
3384 mwl8k_vif
= MWL8K_VIF(vif
);
3385 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
3386 mwl8k_vif
->vif
= vif
;
3387 mwl8k_vif
->macid
= macid
;
3388 mwl8k_vif
->seqno
= 0;
3390 /* Set the mac address. */
3391 mwl8k_cmd_set_mac_addr(hw
, vif
, vif
->addr
);
3394 mwl8k_cmd_set_new_stn_add_self(hw
, vif
);
3396 priv
->macids_used
|= 1 << mwl8k_vif
->macid
;
3397 list_add_tail(&mwl8k_vif
->list
, &priv
->vif_list
);
3402 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
3403 struct ieee80211_vif
*vif
)
3405 struct mwl8k_priv
*priv
= hw
->priv
;
3406 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3409 mwl8k_cmd_set_new_stn_del(hw
, vif
, vif
->addr
);
3411 mwl8k_cmd_set_mac_addr(hw
, vif
, "\x00\x00\x00\x00\x00\x00");
3413 priv
->macids_used
&= ~(1 << mwl8k_vif
->macid
);
3414 list_del(&mwl8k_vif
->list
);
3417 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
3419 struct ieee80211_conf
*conf
= &hw
->conf
;
3420 struct mwl8k_priv
*priv
= hw
->priv
;
3423 if (conf
->flags
& IEEE80211_CONF_IDLE
) {
3424 mwl8k_cmd_radio_disable(hw
);
3428 rc
= mwl8k_fw_lock(hw
);
3432 rc
= mwl8k_cmd_radio_enable(hw
);
3436 rc
= mwl8k_cmd_set_rf_channel(hw
, conf
);
3440 if (conf
->power_level
> 18)
3441 conf
->power_level
= 18;
3444 rc
= mwl8k_cmd_tx_power(hw
, conf
, conf
->power_level
);
3448 rc
= mwl8k_cmd_rf_antenna(hw
, MWL8K_RF_ANTENNA_RX
, 0x7);
3450 rc
= mwl8k_cmd_rf_antenna(hw
, MWL8K_RF_ANTENNA_TX
, 0x7);
3452 rc
= mwl8k_cmd_rf_tx_power(hw
, conf
->power_level
);
3455 rc
= mwl8k_cmd_mimo_config(hw
, 0x7, 0x7);
3459 mwl8k_fw_unlock(hw
);
3465 mwl8k_bss_info_changed_sta(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
3466 struct ieee80211_bss_conf
*info
, u32 changed
)
3468 struct mwl8k_priv
*priv
= hw
->priv
;
3469 u32 ap_legacy_rates
;
3470 u8 ap_mcs_rates
[16];
3473 if (mwl8k_fw_lock(hw
))
3477 * No need to capture a beacon if we're no longer associated.
3479 if ((changed
& BSS_CHANGED_ASSOC
) && !vif
->bss_conf
.assoc
)
3480 priv
->capture_beacon
= false;
3483 * Get the AP's legacy and MCS rates.
3485 if (vif
->bss_conf
.assoc
) {
3486 struct ieee80211_sta
*ap
;
3490 ap
= ieee80211_find_sta(vif
, vif
->bss_conf
.bssid
);
3496 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
3497 ap_legacy_rates
= ap
->supp_rates
[IEEE80211_BAND_2GHZ
];
3500 ap
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
3502 memcpy(ap_mcs_rates
, ap
->ht_cap
.mcs
.rx_mask
, 16);
3507 if ((changed
& BSS_CHANGED_ASSOC
) && vif
->bss_conf
.assoc
) {
3508 rc
= mwl8k_cmd_set_rate(hw
, vif
, ap_legacy_rates
, ap_mcs_rates
);
3512 rc
= mwl8k_cmd_use_fixed_rate_sta(hw
);
3517 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3518 rc
= mwl8k_set_radio_preamble(hw
,
3519 vif
->bss_conf
.use_short_preamble
);
3524 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3525 rc
= mwl8k_cmd_set_slot(hw
, vif
->bss_conf
.use_short_slot
);
3530 if (vif
->bss_conf
.assoc
&&
3531 (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_ERP_CTS_PROT
|
3533 rc
= mwl8k_cmd_set_aid(hw
, vif
, ap_legacy_rates
);
3538 if (vif
->bss_conf
.assoc
&&
3539 (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_BEACON_INT
))) {
3541 * Finalize the join. Tell rx handler to process
3542 * next beacon from our BSSID.
3544 memcpy(priv
->capture_bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
3545 priv
->capture_beacon
= true;
3549 mwl8k_fw_unlock(hw
);
3553 mwl8k_bss_info_changed_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
3554 struct ieee80211_bss_conf
*info
, u32 changed
)
3558 if (mwl8k_fw_lock(hw
))
3561 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3562 rc
= mwl8k_set_radio_preamble(hw
,
3563 vif
->bss_conf
.use_short_preamble
);
3568 if (changed
& BSS_CHANGED_BASIC_RATES
) {
3573 * Use lowest supported basic rate for multicasts
3574 * and management frames (such as probe responses --
3575 * beacons will always go out at 1 Mb/s).
3577 idx
= ffs(vif
->bss_conf
.basic_rates
);
3581 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
3582 rate
= mwl8k_rates_24
[idx
].hw_value
;
3584 rate
= mwl8k_rates_50
[idx
].hw_value
;
3586 mwl8k_cmd_use_fixed_rate_ap(hw
, rate
, rate
);
3589 if (changed
& (BSS_CHANGED_BEACON_INT
| BSS_CHANGED_BEACON
)) {
3590 struct sk_buff
*skb
;
3592 skb
= ieee80211_beacon_get(hw
, vif
);
3594 mwl8k_cmd_set_beacon(hw
, vif
, skb
->data
, skb
->len
);
3599 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
3600 mwl8k_cmd_bss_start(hw
, vif
, info
->enable_beacon
);
3603 mwl8k_fw_unlock(hw
);
3607 mwl8k_bss_info_changed(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
3608 struct ieee80211_bss_conf
*info
, u32 changed
)
3610 struct mwl8k_priv
*priv
= hw
->priv
;
3613 mwl8k_bss_info_changed_sta(hw
, vif
, info
, changed
);
3615 mwl8k_bss_info_changed_ap(hw
, vif
, info
, changed
);
3618 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
3619 struct netdev_hw_addr_list
*mc_list
)
3621 struct mwl8k_cmd_pkt
*cmd
;
3624 * Synthesize and return a command packet that programs the
3625 * hardware multicast address filter. At this point we don't
3626 * know whether FIF_ALLMULTI is being requested, but if it is,
3627 * we'll end up throwing this packet away and creating a new
3628 * one in mwl8k_configure_filter().
3630 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 0, mc_list
);
3632 return (unsigned long)cmd
;
3636 mwl8k_configure_filter_sniffer(struct ieee80211_hw
*hw
,
3637 unsigned int changed_flags
,
3638 unsigned int *total_flags
)
3640 struct mwl8k_priv
*priv
= hw
->priv
;
3643 * Hardware sniffer mode is mutually exclusive with STA
3644 * operation, so refuse to enable sniffer mode if a STA
3645 * interface is active.
3647 if (!list_empty(&priv
->vif_list
)) {
3648 if (net_ratelimit())
3649 wiphy_info(hw
->wiphy
,
3650 "not enabling sniffer mode because STA interface is active\n");
3654 if (!priv
->sniffer_enabled
) {
3655 if (mwl8k_cmd_enable_sniffer(hw
, 1))
3657 priv
->sniffer_enabled
= true;
3660 *total_flags
&= FIF_PROMISC_IN_BSS
| FIF_ALLMULTI
|
3661 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
|
3667 static struct mwl8k_vif
*mwl8k_first_vif(struct mwl8k_priv
*priv
)
3669 if (!list_empty(&priv
->vif_list
))
3670 return list_entry(priv
->vif_list
.next
, struct mwl8k_vif
, list
);
3675 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
3676 unsigned int changed_flags
,
3677 unsigned int *total_flags
,
3680 struct mwl8k_priv
*priv
= hw
->priv
;
3681 struct mwl8k_cmd_pkt
*cmd
= (void *)(unsigned long)multicast
;
3684 * AP firmware doesn't allow fine-grained control over
3685 * the receive filter.
3688 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
3694 * Enable hardware sniffer mode if FIF_CONTROL or
3695 * FIF_OTHER_BSS is requested.
3697 if (*total_flags
& (FIF_CONTROL
| FIF_OTHER_BSS
) &&
3698 mwl8k_configure_filter_sniffer(hw
, changed_flags
, total_flags
)) {
3703 /* Clear unsupported feature flags */
3704 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
3706 if (mwl8k_fw_lock(hw
)) {
3711 if (priv
->sniffer_enabled
) {
3712 mwl8k_cmd_enable_sniffer(hw
, 0);
3713 priv
->sniffer_enabled
= false;
3716 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
3717 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
) {
3719 * Disable the BSS filter.
3721 mwl8k_cmd_set_pre_scan(hw
);
3723 struct mwl8k_vif
*mwl8k_vif
;
3727 * Enable the BSS filter.
3729 * If there is an active STA interface, use that
3730 * interface's BSSID, otherwise use a dummy one
3731 * (where the OUI part needs to be nonzero for
3732 * the BSSID to be accepted by POST_SCAN).
3734 mwl8k_vif
= mwl8k_first_vif(priv
);
3735 if (mwl8k_vif
!= NULL
)
3736 bssid
= mwl8k_vif
->vif
->bss_conf
.bssid
;
3738 bssid
= "\x01\x00\x00\x00\x00\x00";
3740 mwl8k_cmd_set_post_scan(hw
, bssid
);
3745 * If FIF_ALLMULTI is being requested, throw away the command
3746 * packet that ->prepare_multicast() built and replace it with
3747 * a command packet that enables reception of all multicast
3750 if (*total_flags
& FIF_ALLMULTI
) {
3752 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 1, NULL
);
3756 mwl8k_post_cmd(hw
, cmd
);
3760 mwl8k_fw_unlock(hw
);
3763 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3765 return mwl8k_cmd_set_rts_threshold(hw
, value
);
3768 static int mwl8k_sta_remove(struct ieee80211_hw
*hw
,
3769 struct ieee80211_vif
*vif
,
3770 struct ieee80211_sta
*sta
)
3772 struct mwl8k_priv
*priv
= hw
->priv
;
3775 return mwl8k_cmd_set_new_stn_del(hw
, vif
, sta
->addr
);
3777 return mwl8k_cmd_update_stadb_del(hw
, vif
, sta
->addr
);
3780 static int mwl8k_sta_add(struct ieee80211_hw
*hw
,
3781 struct ieee80211_vif
*vif
,
3782 struct ieee80211_sta
*sta
)
3784 struct mwl8k_priv
*priv
= hw
->priv
;
3788 ret
= mwl8k_cmd_update_stadb_add(hw
, vif
, sta
);
3790 MWL8K_STA(sta
)->peer_id
= ret
;
3797 return mwl8k_cmd_set_new_stn_add(hw
, vif
, sta
);
3800 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
3801 const struct ieee80211_tx_queue_params
*params
)
3803 struct mwl8k_priv
*priv
= hw
->priv
;
3806 rc
= mwl8k_fw_lock(hw
);
3808 if (!priv
->wmm_enabled
)
3809 rc
= mwl8k_cmd_set_wmm_mode(hw
, 1);
3812 rc
= mwl8k_cmd_set_edca_params(hw
, queue
,
3818 mwl8k_fw_unlock(hw
);
3824 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
3825 struct ieee80211_low_level_stats
*stats
)
3827 return mwl8k_cmd_get_stat(hw
, stats
);
3830 static int mwl8k_get_survey(struct ieee80211_hw
*hw
, int idx
,
3831 struct survey_info
*survey
)
3833 struct mwl8k_priv
*priv
= hw
->priv
;
3834 struct ieee80211_conf
*conf
= &hw
->conf
;
3839 survey
->channel
= conf
->channel
;
3840 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
3841 survey
->noise
= priv
->noise
;
3847 mwl8k_ampdu_action(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
3848 enum ieee80211_ampdu_mlme_action action
,
3849 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
3852 case IEEE80211_AMPDU_RX_START
:
3853 case IEEE80211_AMPDU_RX_STOP
:
3854 if (!(hw
->flags
& IEEE80211_HW_AMPDU_AGGREGATION
))
3862 static const struct ieee80211_ops mwl8k_ops
= {
3864 .start
= mwl8k_start
,
3866 .add_interface
= mwl8k_add_interface
,
3867 .remove_interface
= mwl8k_remove_interface
,
3868 .config
= mwl8k_config
,
3869 .bss_info_changed
= mwl8k_bss_info_changed
,
3870 .prepare_multicast
= mwl8k_prepare_multicast
,
3871 .configure_filter
= mwl8k_configure_filter
,
3872 .set_rts_threshold
= mwl8k_set_rts_threshold
,
3873 .sta_add
= mwl8k_sta_add
,
3874 .sta_remove
= mwl8k_sta_remove
,
3875 .conf_tx
= mwl8k_conf_tx
,
3876 .get_stats
= mwl8k_get_stats
,
3877 .get_survey
= mwl8k_get_survey
,
3878 .ampdu_action
= mwl8k_ampdu_action
,
3881 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
3883 struct mwl8k_priv
*priv
=
3884 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
3885 struct sk_buff
*skb
= priv
->beacon_skb
;
3886 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
3887 int len
= skb
->len
- offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
3888 const u8
*tim
= cfg80211_find_ie(WLAN_EID_TIM
,
3889 mgmt
->u
.beacon
.variable
, len
);
3890 int dtim_period
= 1;
3892 if (tim
&& tim
[1] >= 2)
3893 dtim_period
= tim
[3];
3895 mwl8k_cmd_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim_period
);
3898 priv
->beacon_skb
= NULL
;
3907 static struct mwl8k_device_info mwl8k_info_tbl
[] __devinitdata
= {
3909 .part_name
= "88w8363",
3910 .helper_image
= "mwl8k/helper_8363.fw",
3911 .fw_image
= "mwl8k/fmimage_8363.fw",
3914 .part_name
= "88w8687",
3915 .helper_image
= "mwl8k/helper_8687.fw",
3916 .fw_image
= "mwl8k/fmimage_8687.fw",
3919 .part_name
= "88w8366",
3920 .helper_image
= "mwl8k/helper_8366.fw",
3921 .fw_image
= "mwl8k/fmimage_8366.fw",
3922 .ap_rxd_ops
= &rxd_8366_ap_ops
,
3926 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3927 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3928 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3929 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3930 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3931 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3933 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table
) = {
3934 { PCI_VDEVICE(MARVELL
, 0x2a0a), .driver_data
= MWL8363
, },
3935 { PCI_VDEVICE(MARVELL
, 0x2a0c), .driver_data
= MWL8363
, },
3936 { PCI_VDEVICE(MARVELL
, 0x2a24), .driver_data
= MWL8363
, },
3937 { PCI_VDEVICE(MARVELL
, 0x2a2b), .driver_data
= MWL8687
, },
3938 { PCI_VDEVICE(MARVELL
, 0x2a30), .driver_data
= MWL8687
, },
3939 { PCI_VDEVICE(MARVELL
, 0x2a40), .driver_data
= MWL8366
, },
3940 { PCI_VDEVICE(MARVELL
, 0x2a43), .driver_data
= MWL8366
, },
3943 MODULE_DEVICE_TABLE(pci
, mwl8k_pci_id_table
);
3945 static int mwl8k_init_firmware(struct ieee80211_hw
*hw
)
3947 struct mwl8k_priv
*priv
= hw
->priv
;
3950 /* Reset firmware and hardware */
3951 mwl8k_hw_reset(priv
);
3953 /* Ask userland hotplug daemon for the device firmware */
3954 rc
= mwl8k_request_firmware(priv
);
3956 wiphy_err(hw
->wiphy
, "Firmware files not found\n");
3960 /* Load firmware into hardware */
3961 rc
= mwl8k_load_firmware(hw
);
3963 wiphy_err(hw
->wiphy
, "Cannot start firmware\n");
3965 /* Reclaim memory once firmware is successfully loaded */
3966 mwl8k_release_firmware(priv
);
3971 /* initialize hw after successfully loading a firmware image */
3972 static int mwl8k_probe_hw(struct ieee80211_hw
*hw
)
3974 struct mwl8k_priv
*priv
= hw
->priv
;
3979 priv
->rxd_ops
= priv
->device_info
->ap_rxd_ops
;
3980 if (priv
->rxd_ops
== NULL
) {
3981 wiphy_err(hw
->wiphy
,
3982 "Driver does not have AP firmware image support for this hardware\n");
3983 goto err_stop_firmware
;
3986 priv
->rxd_ops
= &rxd_sta_ops
;
3989 priv
->sniffer_enabled
= false;
3990 priv
->wmm_enabled
= false;
3991 priv
->pending_tx_pkts
= 0;
3993 rc
= mwl8k_rxq_init(hw
, 0);
3995 goto err_stop_firmware
;
3996 rxq_refill(hw
, 0, INT_MAX
);
3998 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
3999 rc
= mwl8k_txq_init(hw
, i
);
4001 goto err_free_queues
;
4004 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4005 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4006 iowrite32(MWL8K_A2H_INT_TX_DONE
| MWL8K_A2H_INT_RX_READY
,
4007 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
4008 iowrite32(0xffffffff, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
4010 rc
= request_irq(priv
->pdev
->irq
, mwl8k_interrupt
,
4011 IRQF_SHARED
, MWL8K_NAME
, hw
);
4013 wiphy_err(hw
->wiphy
, "failed to register IRQ handler\n");
4014 goto err_free_queues
;
4018 * Temporarily enable interrupts. Initial firmware host
4019 * commands use interrupts and avoid polling. Disable
4020 * interrupts when done.
4022 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4024 /* Get config data, mac addrs etc */
4026 rc
= mwl8k_cmd_get_hw_spec_ap(hw
);
4028 rc
= mwl8k_cmd_set_hw_spec(hw
);
4030 rc
= mwl8k_cmd_get_hw_spec_sta(hw
);
4033 wiphy_err(hw
->wiphy
, "Cannot initialise firmware\n");
4037 /* Turn radio off */
4038 rc
= mwl8k_cmd_radio_disable(hw
);
4040 wiphy_err(hw
->wiphy
, "Cannot disable\n");
4044 /* Clear MAC address */
4045 rc
= mwl8k_cmd_set_mac_addr(hw
, NULL
, "\x00\x00\x00\x00\x00\x00");
4047 wiphy_err(hw
->wiphy
, "Cannot clear MAC address\n");
4051 /* Disable interrupts */
4052 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4053 free_irq(priv
->pdev
->irq
, hw
);
4055 wiphy_info(hw
->wiphy
, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
4056 priv
->device_info
->part_name
,
4057 priv
->hw_rev
, hw
->wiphy
->perm_addr
,
4058 priv
->ap_fw
? "AP" : "STA",
4059 (priv
->fw_rev
>> 24) & 0xff, (priv
->fw_rev
>> 16) & 0xff,
4060 (priv
->fw_rev
>> 8) & 0xff, priv
->fw_rev
& 0xff);
4065 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4066 free_irq(priv
->pdev
->irq
, hw
);
4069 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4070 mwl8k_txq_deinit(hw
, i
);
4071 mwl8k_rxq_deinit(hw
, 0);
4074 mwl8k_hw_reset(priv
);
4080 * invoke mwl8k_reload_firmware to change the firmware image after the device
4081 * has already been registered
4083 static int mwl8k_reload_firmware(struct ieee80211_hw
*hw
, char *fw_image
)
4086 struct mwl8k_priv
*priv
= hw
->priv
;
4089 mwl8k_rxq_deinit(hw
, 0);
4091 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4092 mwl8k_txq_deinit(hw
, i
);
4094 rc
= mwl8k_init_firmware(hw
, fw_image
);
4098 rc
= mwl8k_probe_hw(hw
);
4102 rc
= mwl8k_start(hw
);
4106 rc
= mwl8k_config(hw
, ~0);
4110 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++) {
4111 rc
= mwl8k_conf_tx(hw
, i
, &priv
->wmm_params
[i
]);
4119 printk(KERN_WARNING
"mwl8k: Failed to reload firmware image.\n");
4123 static int mwl8k_firmware_load_success(struct mwl8k_priv
*priv
)
4125 struct ieee80211_hw
*hw
= priv
->hw
;
4129 * Extra headroom is the size of the required DMA header
4130 * minus the size of the smallest 802.11 frame (CTS frame).
4132 hw
->extra_tx_headroom
=
4133 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
4135 hw
->channel_change_time
= 10;
4137 hw
->queues
= MWL8K_TX_QUEUES
;
4139 /* Set rssi values to dBm */
4140 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
;
4141 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
4142 hw
->sta_data_size
= sizeof(struct mwl8k_sta
);
4144 priv
->macids_used
= 0;
4145 INIT_LIST_HEAD(&priv
->vif_list
);
4147 /* Set default radio state and preamble */
4149 priv
->radio_short_preamble
= 0;
4151 /* Finalize join worker */
4152 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
4154 /* TX reclaim and RX tasklets. */
4155 tasklet_init(&priv
->poll_tx_task
, mwl8k_tx_poll
, (unsigned long)hw
);
4156 tasklet_disable(&priv
->poll_tx_task
);
4157 tasklet_init(&priv
->poll_rx_task
, mwl8k_rx_poll
, (unsigned long)hw
);
4158 tasklet_disable(&priv
->poll_rx_task
);
4160 /* Power management cookie */
4161 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
4162 if (priv
->cookie
== NULL
)
4165 mutex_init(&priv
->fw_mutex
);
4166 priv
->fw_mutex_owner
= NULL
;
4167 priv
->fw_mutex_depth
= 0;
4168 priv
->hostcmd_wait
= NULL
;
4170 spin_lock_init(&priv
->tx_lock
);
4172 priv
->tx_wait
= NULL
;
4174 rc
= mwl8k_probe_hw(hw
);
4176 goto err_free_cookie
;
4178 hw
->wiphy
->interface_modes
= 0;
4179 if (priv
->ap_macids_supported
|| priv
->device_info
->fw_image_ap
)
4180 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_AP
);
4181 if (priv
->sta_macids_supported
|| priv
->device_info
->fw_image_sta
)
4182 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_STATION
);
4184 rc
= ieee80211_register_hw(hw
);
4186 wiphy_err(hw
->wiphy
, "Cannot register device\n");
4187 goto err_unprobe_hw
;
4193 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4194 mwl8k_txq_deinit(hw
, i
);
4195 mwl8k_rxq_deinit(hw
, 0);
4198 if (priv
->cookie
!= NULL
)
4199 pci_free_consistent(priv
->pdev
, 4,
4200 priv
->cookie
, priv
->cookie_dma
);
4204 static int __devinit
mwl8k_probe(struct pci_dev
*pdev
,
4205 const struct pci_device_id
*id
)
4207 static int printed_version
;
4208 struct ieee80211_hw
*hw
;
4209 struct mwl8k_priv
*priv
;
4212 if (!printed_version
) {
4213 printk(KERN_INFO
"%s version %s\n", MWL8K_DESC
, MWL8K_VERSION
);
4214 printed_version
= 1;
4218 rc
= pci_enable_device(pdev
);
4220 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
4225 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
4227 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
4229 goto err_disable_device
;
4232 pci_set_master(pdev
);
4235 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
4237 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
4242 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
4243 pci_set_drvdata(pdev
, hw
);
4248 priv
->device_info
= &mwl8k_info_tbl
[id
->driver_data
];
4251 priv
->sram
= pci_iomap(pdev
, 0, 0x10000);
4252 if (priv
->sram
== NULL
) {
4253 wiphy_err(hw
->wiphy
, "Cannot map device SRAM\n");
4258 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
4259 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
4261 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
4262 if (priv
->regs
== NULL
) {
4263 priv
->regs
= pci_iomap(pdev
, 2, 0x10000);
4264 if (priv
->regs
== NULL
) {
4265 wiphy_err(hw
->wiphy
, "Cannot map device registers\n");
4270 rc
= mwl8k_init_firmware(hw
);
4272 goto err_stop_firmware
;
4274 rc
= mwl8k_firmware_load_success(priv
);
4279 mwl8k_hw_reset(priv
);
4282 if (priv
->regs
!= NULL
)
4283 pci_iounmap(pdev
, priv
->regs
);
4285 if (priv
->sram
!= NULL
)
4286 pci_iounmap(pdev
, priv
->sram
);
4288 pci_set_drvdata(pdev
, NULL
);
4289 ieee80211_free_hw(hw
);
4292 pci_release_regions(pdev
);
4295 pci_disable_device(pdev
);
4300 static void __devexit
mwl8k_shutdown(struct pci_dev
*pdev
)
4302 printk(KERN_ERR
"===>%s(%u)\n", __func__
, __LINE__
);
4305 static void __devexit
mwl8k_remove(struct pci_dev
*pdev
)
4307 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
4308 struct mwl8k_priv
*priv
;
4315 ieee80211_stop_queues(hw
);
4317 ieee80211_unregister_hw(hw
);
4319 /* Remove TX reclaim and RX tasklets. */
4320 tasklet_kill(&priv
->poll_tx_task
);
4321 tasklet_kill(&priv
->poll_rx_task
);
4324 mwl8k_hw_reset(priv
);
4326 /* Return all skbs to mac80211 */
4327 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4328 mwl8k_txq_reclaim(hw
, i
, INT_MAX
, 1);
4330 for (i
= 0; i
< MWL8K_TX_QUEUES
; i
++)
4331 mwl8k_txq_deinit(hw
, i
);
4333 mwl8k_rxq_deinit(hw
, 0);
4335 pci_free_consistent(priv
->pdev
, 4, priv
->cookie
, priv
->cookie_dma
);
4337 pci_iounmap(pdev
, priv
->regs
);
4338 pci_iounmap(pdev
, priv
->sram
);
4339 pci_set_drvdata(pdev
, NULL
);
4340 ieee80211_free_hw(hw
);
4341 pci_release_regions(pdev
);
4342 pci_disable_device(pdev
);
4345 static struct pci_driver mwl8k_driver
= {
4347 .id_table
= mwl8k_pci_id_table
,
4348 .probe
= mwl8k_probe
,
4349 .remove
= __devexit_p(mwl8k_remove
),
4350 .shutdown
= __devexit_p(mwl8k_shutdown
),
4353 static int __init
mwl8k_init(void)
4355 return pci_register_driver(&mwl8k_driver
);
4358 static void __exit
mwl8k_exit(void)
4360 pci_unregister_driver(&mwl8k_driver
);
4363 module_init(mwl8k_init
);
4364 module_exit(mwl8k_exit
);
4366 MODULE_DESCRIPTION(MWL8K_DESC
);
4367 MODULE_VERSION(MWL8K_VERSION
);
4368 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4369 MODULE_LICENSE("GPL");