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/interrupt.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/spinlock.h>
18 #include <linux/list.h>
19 #include <linux/pci.h>
20 #include <linux/delay.h>
21 #include <linux/completion.h>
22 #include <linux/etherdevice.h>
23 #include <linux/slab.h>
24 #include <net/mac80211.h>
25 #include <linux/moduleparam.h>
26 #include <linux/firmware.h>
27 #include <linux/workqueue.h>
29 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
30 #define MWL8K_NAME KBUILD_MODNAME
31 #define MWL8K_VERSION "0.13"
33 /* Module parameters */
34 static bool ap_mode_default
;
35 module_param(ap_mode_default
, bool, 0);
36 MODULE_PARM_DESC(ap_mode_default
,
37 "Set to 1 to make ap mode the default instead of sta mode");
39 /* Register definitions */
40 #define MWL8K_HIU_GEN_PTR 0x00000c10
41 #define MWL8K_MODE_STA 0x0000005a
42 #define MWL8K_MODE_AP 0x000000a5
43 #define MWL8K_HIU_INT_CODE 0x00000c14
44 #define MWL8K_FWSTA_READY 0xf0f1f2f4
45 #define MWL8K_FWAP_READY 0xf1f2f4a5
46 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
47 #define MWL8K_HIU_SCRATCH 0x00000c40
49 /* Host->device communications */
50 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
51 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
52 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
53 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
54 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
55 #define MWL8K_H2A_INT_DUMMY (1 << 20)
56 #define MWL8K_H2A_INT_RESET (1 << 15)
57 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
58 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
60 /* Device->host communications */
61 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
62 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
63 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
64 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
65 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
66 #define MWL8K_A2H_INT_DUMMY (1 << 20)
67 #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
68 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
69 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
70 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
71 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
72 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
73 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
74 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
75 #define MWL8K_A2H_INT_RX_READY (1 << 1)
76 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
78 /* HW micro second timer register
79 * located at offset 0xA600. This
80 * will be used to timestamp tx
84 #define MWL8K_HW_TIMER_REGISTER 0x0000a600
86 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
87 MWL8K_A2H_INT_CHNL_SWITCHED | \
88 MWL8K_A2H_INT_QUEUE_EMPTY | \
89 MWL8K_A2H_INT_RADAR_DETECT | \
90 MWL8K_A2H_INT_RADIO_ON | \
91 MWL8K_A2H_INT_RADIO_OFF | \
92 MWL8K_A2H_INT_MAC_EVENT | \
93 MWL8K_A2H_INT_OPC_DONE | \
94 MWL8K_A2H_INT_RX_READY | \
95 MWL8K_A2H_INT_TX_DONE | \
96 MWL8K_A2H_INT_BA_WATCHDOG)
98 #define MWL8K_RX_QUEUES 1
99 #define MWL8K_TX_WMM_QUEUES 4
100 #define MWL8K_MAX_AMPDU_QUEUES 8
101 #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
102 #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
104 /* txpriorities are mapped with hw queues.
105 * Each hw queue has a txpriority.
107 #define TOTAL_HW_TX_QUEUES 8
109 /* Each HW queue can have one AMPDU stream.
110 * But, because one of the hw queue is reserved,
111 * maximum AMPDU queues that can be created are
112 * one short of total tx queues.
114 #define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1)
118 void (*rxd_init
)(void *rxd
, dma_addr_t next_dma_addr
);
119 void (*rxd_refill
)(void *rxd
, dma_addr_t addr
, int len
);
120 int (*rxd_process
)(void *rxd
, struct ieee80211_rx_status
*status
,
121 __le16
*qos
, s8
*noise
);
124 struct mwl8k_device_info
{
129 struct rxd_ops
*ap_rxd_ops
;
133 struct mwl8k_rx_queue
{
136 /* hw receives here */
139 /* refill descs here */
146 DEFINE_DMA_UNMAP_ADDR(dma
);
150 struct mwl8k_tx_queue
{
151 /* hw transmits here */
154 /* sw appends here */
158 struct mwl8k_tx_desc
*txd
;
160 struct sk_buff
**skb
;
166 AMPDU_STREAM_IN_PROGRESS
,
170 struct mwl8k_ampdu_stream
{
171 struct ieee80211_sta
*sta
;
178 struct ieee80211_hw
*hw
;
179 struct pci_dev
*pdev
;
182 struct mwl8k_device_info
*device_info
;
188 const struct firmware
*fw_helper
;
189 const struct firmware
*fw_ucode
;
191 /* hardware/firmware parameters */
193 struct rxd_ops
*rxd_ops
;
194 struct ieee80211_supported_band band_24
;
195 struct ieee80211_channel channels_24
[14];
196 struct ieee80211_rate rates_24
[14];
197 struct ieee80211_supported_band band_50
;
198 struct ieee80211_channel channels_50
[4];
199 struct ieee80211_rate rates_50
[9];
200 u32 ap_macids_supported
;
201 u32 sta_macids_supported
;
203 /* Ampdu stream information */
205 spinlock_t stream_lock
;
206 struct mwl8k_ampdu_stream ampdu
[MWL8K_MAX_AMPDU_QUEUES
];
207 struct work_struct watchdog_ba_handle
;
209 /* firmware access */
210 struct mutex fw_mutex
;
211 struct task_struct
*fw_mutex_owner
;
212 struct task_struct
*hw_restart_owner
;
214 struct completion
*hostcmd_wait
;
216 atomic_t watchdog_event_pending
;
218 /* lock held over TX and TX reap */
221 /* TX quiesce completion, protected by fw_mutex and tx_lock */
222 struct completion
*tx_wait
;
224 /* List of interfaces. */
226 struct list_head vif_list
;
228 /* power management status cookie from firmware */
230 dma_addr_t cookie_dma
;
237 * Running count of TX packets in flight, to avoid
238 * iterating over the transmit rings each time.
242 struct mwl8k_rx_queue rxq
[MWL8K_RX_QUEUES
];
243 struct mwl8k_tx_queue txq
[MWL8K_MAX_TX_QUEUES
];
244 u32 txq_offset
[MWL8K_MAX_TX_QUEUES
];
247 bool radio_short_preamble
;
248 bool sniffer_enabled
;
251 /* XXX need to convert this to handle multiple interfaces */
253 u8 capture_bssid
[ETH_ALEN
];
254 struct sk_buff
*beacon_skb
;
257 * This FJ worker has to be global as it is scheduled from the
258 * RX handler. At this point we don't know which interface it
259 * belongs to until the list of bssids waiting to complete join
262 struct work_struct finalize_join_worker
;
264 /* Tasklet to perform TX reclaim. */
265 struct tasklet_struct poll_tx_task
;
267 /* Tasklet to perform RX. */
268 struct tasklet_struct poll_rx_task
;
270 /* Most recently reported noise in dBm */
274 * preserve the queue configurations so they can be restored if/when
275 * the firmware image is swapped.
277 struct ieee80211_tx_queue_params wmm_params
[MWL8K_TX_WMM_QUEUES
];
279 /* To perform the task of reloading the firmware */
280 struct work_struct fw_reload
;
281 bool hw_restart_in_progress
;
283 /* async firmware loading state */
287 struct completion firmware_loading_complete
;
290 #define MAX_WEP_KEY_LEN 13
291 #define NUM_WEP_KEYS 4
293 /* Per interface specific private data */
295 struct list_head list
;
296 struct ieee80211_vif
*vif
;
298 /* Firmware macid for this vif. */
301 /* Non AMPDU sequence number assigned by driver. */
307 u8 key
[sizeof(struct ieee80211_key_conf
) + MAX_WEP_KEY_LEN
];
308 } wep_key_conf
[NUM_WEP_KEYS
];
313 /* A flag to indicate is HW crypto is enabled for this bssid */
314 bool is_hw_crypto_enabled
;
316 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
317 #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
319 struct tx_traffic_info
{
324 #define MWL8K_MAX_TID 8
326 /* Index into station database. Returned by UPDATE_STADB. */
329 struct tx_traffic_info tx_stats
[MWL8K_MAX_TID
];
331 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
333 static const struct ieee80211_channel mwl8k_channels_24
[] = {
334 { .center_freq
= 2412, .hw_value
= 1, },
335 { .center_freq
= 2417, .hw_value
= 2, },
336 { .center_freq
= 2422, .hw_value
= 3, },
337 { .center_freq
= 2427, .hw_value
= 4, },
338 { .center_freq
= 2432, .hw_value
= 5, },
339 { .center_freq
= 2437, .hw_value
= 6, },
340 { .center_freq
= 2442, .hw_value
= 7, },
341 { .center_freq
= 2447, .hw_value
= 8, },
342 { .center_freq
= 2452, .hw_value
= 9, },
343 { .center_freq
= 2457, .hw_value
= 10, },
344 { .center_freq
= 2462, .hw_value
= 11, },
345 { .center_freq
= 2467, .hw_value
= 12, },
346 { .center_freq
= 2472, .hw_value
= 13, },
347 { .center_freq
= 2484, .hw_value
= 14, },
350 static const struct ieee80211_rate mwl8k_rates_24
[] = {
351 { .bitrate
= 10, .hw_value
= 2, },
352 { .bitrate
= 20, .hw_value
= 4, },
353 { .bitrate
= 55, .hw_value
= 11, },
354 { .bitrate
= 110, .hw_value
= 22, },
355 { .bitrate
= 220, .hw_value
= 44, },
356 { .bitrate
= 60, .hw_value
= 12, },
357 { .bitrate
= 90, .hw_value
= 18, },
358 { .bitrate
= 120, .hw_value
= 24, },
359 { .bitrate
= 180, .hw_value
= 36, },
360 { .bitrate
= 240, .hw_value
= 48, },
361 { .bitrate
= 360, .hw_value
= 72, },
362 { .bitrate
= 480, .hw_value
= 96, },
363 { .bitrate
= 540, .hw_value
= 108, },
364 { .bitrate
= 720, .hw_value
= 144, },
367 static const struct ieee80211_channel mwl8k_channels_50
[] = {
368 { .center_freq
= 5180, .hw_value
= 36, },
369 { .center_freq
= 5200, .hw_value
= 40, },
370 { .center_freq
= 5220, .hw_value
= 44, },
371 { .center_freq
= 5240, .hw_value
= 48, },
374 static const struct ieee80211_rate mwl8k_rates_50
[] = {
375 { .bitrate
= 60, .hw_value
= 12, },
376 { .bitrate
= 90, .hw_value
= 18, },
377 { .bitrate
= 120, .hw_value
= 24, },
378 { .bitrate
= 180, .hw_value
= 36, },
379 { .bitrate
= 240, .hw_value
= 48, },
380 { .bitrate
= 360, .hw_value
= 72, },
381 { .bitrate
= 480, .hw_value
= 96, },
382 { .bitrate
= 540, .hw_value
= 108, },
383 { .bitrate
= 720, .hw_value
= 144, },
386 /* Set or get info from Firmware */
387 #define MWL8K_CMD_GET 0x0000
388 #define MWL8K_CMD_SET 0x0001
389 #define MWL8K_CMD_SET_LIST 0x0002
391 /* Firmware command codes */
392 #define MWL8K_CMD_CODE_DNLD 0x0001
393 #define MWL8K_CMD_GET_HW_SPEC 0x0003
394 #define MWL8K_CMD_SET_HW_SPEC 0x0004
395 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
396 #define MWL8K_CMD_GET_STAT 0x0014
397 #define MWL8K_CMD_RADIO_CONTROL 0x001c
398 #define MWL8K_CMD_RF_TX_POWER 0x001e
399 #define MWL8K_CMD_TX_POWER 0x001f
400 #define MWL8K_CMD_RF_ANTENNA 0x0020
401 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
402 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
403 #define MWL8K_CMD_SET_POST_SCAN 0x0108
404 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
405 #define MWL8K_CMD_SET_AID 0x010d
406 #define MWL8K_CMD_SET_RATE 0x0110
407 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
408 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
409 #define MWL8K_CMD_SET_SLOT 0x0114
410 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
411 #define MWL8K_CMD_SET_WMM_MODE 0x0123
412 #define MWL8K_CMD_MIMO_CONFIG 0x0125
413 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
414 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
415 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
416 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
417 #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
418 #define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
419 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
420 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
421 #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
422 #define MWL8K_CMD_UPDATE_STADB 0x1123
423 #define MWL8K_CMD_BASTREAM 0x1125
425 static const char *mwl8k_cmd_name(__le16 cmd
, char *buf
, int bufsize
)
427 u16 command
= le16_to_cpu(cmd
);
429 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
430 snprintf(buf, bufsize, "%s", #x);\
433 switch (command
& ~0x8000) {
434 MWL8K_CMDNAME(CODE_DNLD
);
435 MWL8K_CMDNAME(GET_HW_SPEC
);
436 MWL8K_CMDNAME(SET_HW_SPEC
);
437 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
438 MWL8K_CMDNAME(GET_STAT
);
439 MWL8K_CMDNAME(RADIO_CONTROL
);
440 MWL8K_CMDNAME(RF_TX_POWER
);
441 MWL8K_CMDNAME(TX_POWER
);
442 MWL8K_CMDNAME(RF_ANTENNA
);
443 MWL8K_CMDNAME(SET_BEACON
);
444 MWL8K_CMDNAME(SET_PRE_SCAN
);
445 MWL8K_CMDNAME(SET_POST_SCAN
);
446 MWL8K_CMDNAME(SET_RF_CHANNEL
);
447 MWL8K_CMDNAME(SET_AID
);
448 MWL8K_CMDNAME(SET_RATE
);
449 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
450 MWL8K_CMDNAME(RTS_THRESHOLD
);
451 MWL8K_CMDNAME(SET_SLOT
);
452 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
453 MWL8K_CMDNAME(SET_WMM_MODE
);
454 MWL8K_CMDNAME(MIMO_CONFIG
);
455 MWL8K_CMDNAME(USE_FIXED_RATE
);
456 MWL8K_CMDNAME(ENABLE_SNIFFER
);
457 MWL8K_CMDNAME(SET_MAC_ADDR
);
458 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
459 MWL8K_CMDNAME(BSS_START
);
460 MWL8K_CMDNAME(SET_NEW_STN
);
461 MWL8K_CMDNAME(UPDATE_ENCRYPTION
);
462 MWL8K_CMDNAME(UPDATE_STADB
);
463 MWL8K_CMDNAME(BASTREAM
);
464 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP
);
466 snprintf(buf
, bufsize
, "0x%x", cmd
);
473 /* Hardware and firmware reset */
474 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
476 iowrite32(MWL8K_H2A_INT_RESET
,
477 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
478 iowrite32(MWL8K_H2A_INT_RESET
,
479 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
483 /* Release fw image */
484 static void mwl8k_release_fw(const struct firmware
**fw
)
488 release_firmware(*fw
);
492 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
494 mwl8k_release_fw(&priv
->fw_ucode
);
495 mwl8k_release_fw(&priv
->fw_helper
);
498 /* states for asynchronous f/w loading */
499 static void mwl8k_fw_state_machine(const struct firmware
*fw
, void *context
);
502 FW_STATE_LOADING_PREF
,
503 FW_STATE_LOADING_ALT
,
507 /* Request fw image */
508 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
509 const char *fname
, const struct firmware
**fw
,
512 /* release current image */
514 mwl8k_release_fw(fw
);
517 return request_firmware_nowait(THIS_MODULE
, 1, fname
,
518 &priv
->pdev
->dev
, GFP_KERNEL
,
519 priv
, mwl8k_fw_state_machine
);
521 return request_firmware(fw
, fname
, &priv
->pdev
->dev
);
524 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, char *fw_image
,
527 struct mwl8k_device_info
*di
= priv
->device_info
;
530 if (di
->helper_image
!= NULL
) {
532 rc
= mwl8k_request_fw(priv
, di
->helper_image
,
533 &priv
->fw_helper
, true);
535 rc
= mwl8k_request_fw(priv
, di
->helper_image
,
536 &priv
->fw_helper
, false);
538 printk(KERN_ERR
"%s: Error requesting helper fw %s\n",
539 pci_name(priv
->pdev
), di
->helper_image
);
547 * if we get here, no helper image is needed. Skip the
548 * FW_STATE_INIT state.
550 priv
->fw_state
= FW_STATE_LOADING_PREF
;
551 rc
= mwl8k_request_fw(priv
, fw_image
,
555 rc
= mwl8k_request_fw(priv
, fw_image
,
556 &priv
->fw_ucode
, false);
558 printk(KERN_ERR
"%s: Error requesting firmware file %s\n",
559 pci_name(priv
->pdev
), fw_image
);
560 mwl8k_release_fw(&priv
->fw_helper
);
567 struct mwl8k_cmd_pkt
{
580 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
582 void __iomem
*regs
= priv
->regs
;
586 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
587 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
590 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
591 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
592 iowrite32(MWL8K_H2A_INT_DOORBELL
,
593 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
594 iowrite32(MWL8K_H2A_INT_DUMMY
,
595 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
601 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
602 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
603 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
611 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
613 return loops
? 0 : -ETIMEDOUT
;
616 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
617 const u8
*data
, size_t length
)
619 struct mwl8k_cmd_pkt
*cmd
;
623 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
627 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
634 int block_size
= length
> 256 ? 256 : length
;
636 memcpy(cmd
->payload
, data
+ done
, block_size
);
637 cmd
->length
= cpu_to_le16(block_size
);
639 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
640 sizeof(*cmd
) + block_size
);
645 length
-= block_size
;
650 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
658 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
659 const u8
*data
, size_t length
)
661 unsigned char *buffer
;
662 int may_continue
, rc
= 0;
663 u32 done
, prev_block_size
;
665 buffer
= kmalloc(1024, GFP_KERNEL
);
672 while (may_continue
> 0) {
675 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
676 if (block_size
& 1) {
680 done
+= prev_block_size
;
681 length
-= prev_block_size
;
684 if (block_size
> 1024 || block_size
> length
) {
694 if (block_size
== 0) {
701 prev_block_size
= block_size
;
702 memcpy(buffer
, data
+ done
, block_size
);
704 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
709 if (!rc
&& length
!= 0)
717 static int mwl8k_load_firmware(struct ieee80211_hw
*hw
)
719 struct mwl8k_priv
*priv
= hw
->priv
;
720 const struct firmware
*fw
= priv
->fw_ucode
;
724 if (!memcmp(fw
->data
, "\x01\x00\x00\x00", 4)) {
725 const struct firmware
*helper
= priv
->fw_helper
;
727 if (helper
== NULL
) {
728 printk(KERN_ERR
"%s: helper image needed but none "
729 "given\n", pci_name(priv
->pdev
));
733 rc
= mwl8k_load_fw_image(priv
, helper
->data
, helper
->size
);
735 printk(KERN_ERR
"%s: unable to load firmware "
736 "helper image\n", pci_name(priv
->pdev
));
741 rc
= mwl8k_feed_fw_image(priv
, fw
->data
, fw
->size
);
743 rc
= mwl8k_load_fw_image(priv
, fw
->data
, fw
->size
);
747 printk(KERN_ERR
"%s: unable to load firmware image\n",
748 pci_name(priv
->pdev
));
752 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
758 ready_code
= ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
759 if (ready_code
== MWL8K_FWAP_READY
) {
762 } else if (ready_code
== MWL8K_FWSTA_READY
) {
771 return loops
? 0 : -ETIMEDOUT
;
775 /* DMA header used by firmware and hardware. */
776 struct mwl8k_dma_data
{
778 struct ieee80211_hdr wh
;
782 /* Routines to add/remove DMA header from skb. */
783 static inline void mwl8k_remove_dma_header(struct sk_buff
*skb
, __le16 qos
)
785 struct mwl8k_dma_data
*tr
;
788 tr
= (struct mwl8k_dma_data
*)skb
->data
;
789 hdrlen
= ieee80211_hdrlen(tr
->wh
.frame_control
);
791 if (hdrlen
!= sizeof(tr
->wh
)) {
792 if (ieee80211_is_data_qos(tr
->wh
.frame_control
)) {
793 memmove(tr
->data
- hdrlen
, &tr
->wh
, hdrlen
- 2);
794 *((__le16
*)(tr
->data
- 2)) = qos
;
796 memmove(tr
->data
- hdrlen
, &tr
->wh
, hdrlen
);
800 if (hdrlen
!= sizeof(*tr
))
801 skb_pull(skb
, sizeof(*tr
) - hdrlen
);
804 #define REDUCED_TX_HEADROOM 8
807 mwl8k_add_dma_header(struct mwl8k_priv
*priv
, struct sk_buff
*skb
,
808 int head_pad
, int tail_pad
)
810 struct ieee80211_hdr
*wh
;
813 struct mwl8k_dma_data
*tr
;
816 * Add a firmware DMA header; the firmware requires that we
817 * present a 2-byte payload length followed by a 4-address
818 * header (without QoS field), followed (optionally) by any
819 * WEP/ExtIV header (but only filled in for CCMP).
821 wh
= (struct ieee80211_hdr
*)skb
->data
;
823 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
826 * Check if skb_resize is required because of
827 * tx_headroom adjustment.
829 if (priv
->ap_fw
&& (hdrlen
< (sizeof(struct ieee80211_cts
)
830 + REDUCED_TX_HEADROOM
))) {
831 if (pskb_expand_head(skb
, REDUCED_TX_HEADROOM
, 0, GFP_ATOMIC
)) {
833 wiphy_err(priv
->hw
->wiphy
,
834 "Failed to reallocate TX buffer\n");
837 skb
->truesize
+= REDUCED_TX_HEADROOM
;
840 reqd_hdrlen
= sizeof(*tr
) + head_pad
;
842 if (hdrlen
!= reqd_hdrlen
)
843 skb_push(skb
, reqd_hdrlen
- hdrlen
);
845 if (ieee80211_is_data_qos(wh
->frame_control
))
846 hdrlen
-= IEEE80211_QOS_CTL_LEN
;
848 tr
= (struct mwl8k_dma_data
*)skb
->data
;
850 memmove(&tr
->wh
, wh
, hdrlen
);
851 if (hdrlen
!= sizeof(tr
->wh
))
852 memset(((void *)&tr
->wh
) + hdrlen
, 0, sizeof(tr
->wh
) - hdrlen
);
855 * Firmware length is the length of the fully formed "802.11
856 * payload". That is, everything except for the 802.11 header.
857 * This includes all crypto material including the MIC.
859 tr
->fwlen
= cpu_to_le16(skb
->len
- sizeof(*tr
) + tail_pad
);
862 static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv
*priv
,
865 struct ieee80211_hdr
*wh
;
866 struct ieee80211_tx_info
*tx_info
;
867 struct ieee80211_key_conf
*key_conf
;
871 wh
= (struct ieee80211_hdr
*)skb
->data
;
873 tx_info
= IEEE80211_SKB_CB(skb
);
876 if (ieee80211_is_data(wh
->frame_control
))
877 key_conf
= tx_info
->control
.hw_key
;
880 * Make sure the packet header is in the DMA header format (4-address
881 * without QoS), and add head & tail padding when HW crypto is enabled.
883 * We have the following trailer padding requirements:
884 * - WEP: 4 trailer bytes (ICV)
885 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
886 * - CCMP: 8 trailer bytes (MIC)
889 if (key_conf
!= NULL
) {
890 head_pad
= key_conf
->iv_len
;
891 switch (key_conf
->cipher
) {
892 case WLAN_CIPHER_SUITE_WEP40
:
893 case WLAN_CIPHER_SUITE_WEP104
:
896 case WLAN_CIPHER_SUITE_TKIP
:
899 case WLAN_CIPHER_SUITE_CCMP
:
904 mwl8k_add_dma_header(priv
, skb
, head_pad
, data_pad
);
908 * Packet reception for 88w8366 AP firmware.
910 struct mwl8k_rxd_8366_ap
{
914 __le32 pkt_phys_addr
;
915 __le32 next_rxd_phys_addr
;
919 __le32 hw_noise_floor_info
;
928 #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
929 #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
930 #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
932 #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
934 /* 8366 AP rx_status bits */
935 #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
936 #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
937 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
938 #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
939 #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
941 static void mwl8k_rxd_8366_ap_init(void *_rxd
, dma_addr_t next_dma_addr
)
943 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
945 rxd
->next_rxd_phys_addr
= cpu_to_le32(next_dma_addr
);
946 rxd
->rx_ctrl
= MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST
;
949 static void mwl8k_rxd_8366_ap_refill(void *_rxd
, dma_addr_t addr
, int len
)
951 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
953 rxd
->pkt_len
= cpu_to_le16(len
);
954 rxd
->pkt_phys_addr
= cpu_to_le32(addr
);
960 mwl8k_rxd_8366_ap_process(void *_rxd
, struct ieee80211_rx_status
*status
,
961 __le16
*qos
, s8
*noise
)
963 struct mwl8k_rxd_8366_ap
*rxd
= _rxd
;
965 if (!(rxd
->rx_ctrl
& MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST
))
969 memset(status
, 0, sizeof(*status
));
971 status
->signal
= -rxd
->rssi
;
972 *noise
= -rxd
->noise_floor
;
974 if (rxd
->rate
& MWL8K_8366_AP_RATE_INFO_MCS_FORMAT
) {
975 status
->flag
|= RX_FLAG_HT
;
976 if (rxd
->rate
& MWL8K_8366_AP_RATE_INFO_40MHZ
)
977 status
->flag
|= RX_FLAG_40MHZ
;
978 status
->rate_idx
= MWL8K_8366_AP_RATE_INFO_RATEID(rxd
->rate
);
982 for (i
= 0; i
< ARRAY_SIZE(mwl8k_rates_24
); i
++) {
983 if (mwl8k_rates_24
[i
].hw_value
== rxd
->rate
) {
984 status
->rate_idx
= i
;
990 if (rxd
->channel
> 14) {
991 status
->band
= IEEE80211_BAND_5GHZ
;
992 if (!(status
->flag
& RX_FLAG_HT
))
993 status
->rate_idx
-= 5;
995 status
->band
= IEEE80211_BAND_2GHZ
;
997 status
->freq
= ieee80211_channel_to_frequency(rxd
->channel
,
1000 *qos
= rxd
->qos_control
;
1002 if ((rxd
->rx_status
!= MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR
) &&
1003 (rxd
->rx_status
& MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK
) &&
1004 (rxd
->rx_status
& MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR
))
1005 status
->flag
|= RX_FLAG_MMIC_ERROR
;
1007 return le16_to_cpu(rxd
->pkt_len
);
1010 static struct rxd_ops rxd_8366_ap_ops
= {
1011 .rxd_size
= sizeof(struct mwl8k_rxd_8366_ap
),
1012 .rxd_init
= mwl8k_rxd_8366_ap_init
,
1013 .rxd_refill
= mwl8k_rxd_8366_ap_refill
,
1014 .rxd_process
= mwl8k_rxd_8366_ap_process
,
1018 * Packet reception for STA firmware.
1020 struct mwl8k_rxd_sta
{
1024 __le32 pkt_phys_addr
;
1025 __le32 next_rxd_phys_addr
;
1037 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
1038 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
1039 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
1040 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
1041 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
1042 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
1044 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
1045 #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
1046 /* ICV=0 or MIC=1 */
1047 #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
1048 /* Key is uploaded only in failure case */
1049 #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
1051 static void mwl8k_rxd_sta_init(void *_rxd
, dma_addr_t next_dma_addr
)
1053 struct mwl8k_rxd_sta
*rxd
= _rxd
;
1055 rxd
->next_rxd_phys_addr
= cpu_to_le32(next_dma_addr
);
1056 rxd
->rx_ctrl
= MWL8K_STA_RX_CTRL_OWNED_BY_HOST
;
1059 static void mwl8k_rxd_sta_refill(void *_rxd
, dma_addr_t addr
, int len
)
1061 struct mwl8k_rxd_sta
*rxd
= _rxd
;
1063 rxd
->pkt_len
= cpu_to_le16(len
);
1064 rxd
->pkt_phys_addr
= cpu_to_le32(addr
);
1070 mwl8k_rxd_sta_process(void *_rxd
, struct ieee80211_rx_status
*status
,
1071 __le16
*qos
, s8
*noise
)
1073 struct mwl8k_rxd_sta
*rxd
= _rxd
;
1076 if (!(rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_OWNED_BY_HOST
))
1080 rate_info
= le16_to_cpu(rxd
->rate_info
);
1082 memset(status
, 0, sizeof(*status
));
1084 status
->signal
= -rxd
->rssi
;
1085 *noise
= -rxd
->noise_level
;
1086 status
->antenna
= MWL8K_STA_RATE_INFO_ANTSELECT(rate_info
);
1087 status
->rate_idx
= MWL8K_STA_RATE_INFO_RATEID(rate_info
);
1089 if (rate_info
& MWL8K_STA_RATE_INFO_SHORTPRE
)
1090 status
->flag
|= RX_FLAG_SHORTPRE
;
1091 if (rate_info
& MWL8K_STA_RATE_INFO_40MHZ
)
1092 status
->flag
|= RX_FLAG_40MHZ
;
1093 if (rate_info
& MWL8K_STA_RATE_INFO_SHORTGI
)
1094 status
->flag
|= RX_FLAG_SHORT_GI
;
1095 if (rate_info
& MWL8K_STA_RATE_INFO_MCS_FORMAT
)
1096 status
->flag
|= RX_FLAG_HT
;
1098 if (rxd
->channel
> 14) {
1099 status
->band
= IEEE80211_BAND_5GHZ
;
1100 if (!(status
->flag
& RX_FLAG_HT
))
1101 status
->rate_idx
-= 5;
1103 status
->band
= IEEE80211_BAND_2GHZ
;
1105 status
->freq
= ieee80211_channel_to_frequency(rxd
->channel
,
1108 *qos
= rxd
->qos_control
;
1109 if ((rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_DECRYPT_ERROR
) &&
1110 (rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_DEC_ERR_TYPE
))
1111 status
->flag
|= RX_FLAG_MMIC_ERROR
;
1113 return le16_to_cpu(rxd
->pkt_len
);
1116 static struct rxd_ops rxd_sta_ops
= {
1117 .rxd_size
= sizeof(struct mwl8k_rxd_sta
),
1118 .rxd_init
= mwl8k_rxd_sta_init
,
1119 .rxd_refill
= mwl8k_rxd_sta_refill
,
1120 .rxd_process
= mwl8k_rxd_sta_process
,
1124 #define MWL8K_RX_DESCS 256
1125 #define MWL8K_RX_MAXSZ 3800
1127 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
1129 struct mwl8k_priv
*priv
= hw
->priv
;
1130 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1138 size
= MWL8K_RX_DESCS
* priv
->rxd_ops
->rxd_size
;
1140 rxq
->rxd
= pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rxd_dma
);
1141 if (rxq
->rxd
== NULL
) {
1142 wiphy_err(hw
->wiphy
, "failed to alloc RX descriptors\n");
1145 memset(rxq
->rxd
, 0, size
);
1147 rxq
->buf
= kcalloc(MWL8K_RX_DESCS
, sizeof(*rxq
->buf
), GFP_KERNEL
);
1148 if (rxq
->buf
== NULL
) {
1149 wiphy_err(hw
->wiphy
, "failed to alloc RX skbuff list\n");
1150 pci_free_consistent(priv
->pdev
, size
, rxq
->rxd
, rxq
->rxd_dma
);
1154 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
1158 dma_addr_t next_dma_addr
;
1160 desc_size
= priv
->rxd_ops
->rxd_size
;
1161 rxd
= rxq
->rxd
+ (i
* priv
->rxd_ops
->rxd_size
);
1164 if (nexti
== MWL8K_RX_DESCS
)
1166 next_dma_addr
= rxq
->rxd_dma
+ (nexti
* desc_size
);
1168 priv
->rxd_ops
->rxd_init(rxd
, next_dma_addr
);
1174 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
1176 struct mwl8k_priv
*priv
= hw
->priv
;
1177 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1181 while (rxq
->rxd_count
< MWL8K_RX_DESCS
&& limit
--) {
1182 struct sk_buff
*skb
;
1187 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
1191 addr
= pci_map_single(priv
->pdev
, skb
->data
,
1192 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
);
1196 if (rxq
->tail
== MWL8K_RX_DESCS
)
1198 rxq
->buf
[rx
].skb
= skb
;
1199 dma_unmap_addr_set(&rxq
->buf
[rx
], dma
, addr
);
1201 rxd
= rxq
->rxd
+ (rx
* priv
->rxd_ops
->rxd_size
);
1202 priv
->rxd_ops
->rxd_refill(rxd
, addr
, MWL8K_RX_MAXSZ
);
1210 /* Must be called only when the card's reception is completely halted */
1211 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
1213 struct mwl8k_priv
*priv
= hw
->priv
;
1214 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1217 if (rxq
->rxd
== NULL
)
1220 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
1221 if (rxq
->buf
[i
].skb
!= NULL
) {
1222 pci_unmap_single(priv
->pdev
,
1223 dma_unmap_addr(&rxq
->buf
[i
], dma
),
1224 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
1225 dma_unmap_addr_set(&rxq
->buf
[i
], dma
, 0);
1227 kfree_skb(rxq
->buf
[i
].skb
);
1228 rxq
->buf
[i
].skb
= NULL
;
1235 pci_free_consistent(priv
->pdev
,
1236 MWL8K_RX_DESCS
* priv
->rxd_ops
->rxd_size
,
1237 rxq
->rxd
, rxq
->rxd_dma
);
1243 * Scan a list of BSSIDs to process for finalize join.
1244 * Allows for extension to process multiple BSSIDs.
1247 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
1249 return priv
->capture_beacon
&&
1250 ieee80211_is_beacon(wh
->frame_control
) &&
1251 ether_addr_equal(wh
->addr3
, priv
->capture_bssid
);
1254 static inline void mwl8k_save_beacon(struct ieee80211_hw
*hw
,
1255 struct sk_buff
*skb
)
1257 struct mwl8k_priv
*priv
= hw
->priv
;
1259 priv
->capture_beacon
= false;
1260 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
1263 * Use GFP_ATOMIC as rxq_process is called from
1264 * the primary interrupt handler, memory allocation call
1267 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
1268 if (priv
->beacon_skb
!= NULL
)
1269 ieee80211_queue_work(hw
, &priv
->finalize_join_worker
);
1272 static inline struct mwl8k_vif
*mwl8k_find_vif_bss(struct list_head
*vif_list
,
1275 struct mwl8k_vif
*mwl8k_vif
;
1277 list_for_each_entry(mwl8k_vif
,
1279 if (memcmp(bssid
, mwl8k_vif
->bssid
,
1287 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
1289 struct mwl8k_priv
*priv
= hw
->priv
;
1290 struct mwl8k_vif
*mwl8k_vif
= NULL
;
1291 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1295 while (rxq
->rxd_count
&& limit
--) {
1296 struct sk_buff
*skb
;
1299 struct ieee80211_rx_status status
;
1300 struct ieee80211_hdr
*wh
;
1303 skb
= rxq
->buf
[rxq
->head
].skb
;
1307 rxd
= rxq
->rxd
+ (rxq
->head
* priv
->rxd_ops
->rxd_size
);
1309 pkt_len
= priv
->rxd_ops
->rxd_process(rxd
, &status
, &qos
,
1314 rxq
->buf
[rxq
->head
].skb
= NULL
;
1316 pci_unmap_single(priv
->pdev
,
1317 dma_unmap_addr(&rxq
->buf
[rxq
->head
], dma
),
1318 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
1319 dma_unmap_addr_set(&rxq
->buf
[rxq
->head
], dma
, 0);
1322 if (rxq
->head
== MWL8K_RX_DESCS
)
1327 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1330 * Check for a pending join operation. Save a
1331 * copy of the beacon and schedule a tasklet to
1332 * send a FINALIZE_JOIN command to the firmware.
1334 if (mwl8k_capture_bssid(priv
, (void *)skb
->data
))
1335 mwl8k_save_beacon(hw
, skb
);
1337 if (ieee80211_has_protected(wh
->frame_control
)) {
1339 /* Check if hw crypto has been enabled for
1340 * this bss. If yes, set the status flags
1343 mwl8k_vif
= mwl8k_find_vif_bss(&priv
->vif_list
,
1346 if (mwl8k_vif
!= NULL
&&
1347 mwl8k_vif
->is_hw_crypto_enabled
) {
1349 * When MMIC ERROR is encountered
1350 * by the firmware, payload is
1351 * dropped and only 32 bytes of
1352 * mwl8k Firmware header is sent
1355 * We need to add four bytes of
1356 * key information. In it
1357 * MAC80211 expects keyidx set to
1358 * 0 for triggering Counter
1359 * Measure of MMIC failure.
1361 if (status
.flag
& RX_FLAG_MMIC_ERROR
) {
1362 struct mwl8k_dma_data
*tr
;
1363 tr
= (struct mwl8k_dma_data
*)skb
->data
;
1364 memset((void *)&(tr
->data
), 0, 4);
1368 if (!ieee80211_is_auth(wh
->frame_control
))
1369 status
.flag
|= RX_FLAG_IV_STRIPPED
|
1371 RX_FLAG_MMIC_STRIPPED
;
1375 skb_put(skb
, pkt_len
);
1376 mwl8k_remove_dma_header(skb
, qos
);
1377 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
1378 ieee80211_rx_irqsafe(hw
, skb
);
1388 * Packet transmission.
1391 #define MWL8K_TXD_STATUS_OK 0x00000001
1392 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1393 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1394 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1395 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1397 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1398 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1399 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1400 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1401 #define MWL8K_QOS_EOSP 0x0010
1403 struct mwl8k_tx_desc
{
1408 __le32 pkt_phys_addr
;
1410 __u8 dest_MAC_addr
[ETH_ALEN
];
1411 __le32 next_txd_phys_addr
;
1418 #define MWL8K_TX_DESCS 128
1420 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1422 struct mwl8k_priv
*priv
= hw
->priv
;
1423 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1431 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1433 txq
->txd
= pci_alloc_consistent(priv
->pdev
, size
, &txq
->txd_dma
);
1434 if (txq
->txd
== NULL
) {
1435 wiphy_err(hw
->wiphy
, "failed to alloc TX descriptors\n");
1438 memset(txq
->txd
, 0, size
);
1440 txq
->skb
= kcalloc(MWL8K_TX_DESCS
, sizeof(*txq
->skb
), GFP_KERNEL
);
1441 if (txq
->skb
== NULL
) {
1442 wiphy_err(hw
->wiphy
, "failed to alloc TX skbuff list\n");
1443 pci_free_consistent(priv
->pdev
, size
, txq
->txd
, txq
->txd_dma
);
1447 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1448 struct mwl8k_tx_desc
*tx_desc
;
1451 tx_desc
= txq
->txd
+ i
;
1452 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1454 tx_desc
->status
= 0;
1455 tx_desc
->next_txd_phys_addr
=
1456 cpu_to_le32(txq
->txd_dma
+ nexti
* sizeof(*tx_desc
));
1462 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1464 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1465 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1466 iowrite32(MWL8K_H2A_INT_DUMMY
,
1467 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1468 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1471 static void mwl8k_dump_tx_rings(struct ieee80211_hw
*hw
)
1473 struct mwl8k_priv
*priv
= hw
->priv
;
1476 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++) {
1477 struct mwl8k_tx_queue
*txq
= priv
->txq
+ i
;
1483 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1484 struct mwl8k_tx_desc
*tx_desc
= txq
->txd
+ desc
;
1487 status
= le32_to_cpu(tx_desc
->status
);
1488 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1493 if (tx_desc
->pkt_len
== 0)
1497 wiphy_err(hw
->wiphy
,
1498 "txq[%d] len=%d head=%d tail=%d "
1499 "fw_owned=%d drv_owned=%d unused=%d\n",
1501 txq
->len
, txq
->head
, txq
->tail
,
1502 fw_owned
, drv_owned
, unused
);
1507 * Must be called with priv->fw_mutex held and tx queues stopped.
1509 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1511 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
)
1513 struct mwl8k_priv
*priv
= hw
->priv
;
1514 DECLARE_COMPLETION_ONSTACK(tx_wait
);
1520 /* Since fw restart is in progress, allow only the firmware
1521 * commands from the restart code and block the other
1522 * commands since they are going to fail in any case since
1523 * the firmware has crashed
1525 if (priv
->hw_restart_in_progress
) {
1526 if (priv
->hw_restart_owner
== current
)
1532 if (atomic_read(&priv
->watchdog_event_pending
))
1536 * The TX queues are stopped at this point, so this test
1537 * doesn't need to take ->tx_lock.
1539 if (!priv
->pending_tx_pkts
)
1545 spin_lock_bh(&priv
->tx_lock
);
1546 priv
->tx_wait
= &tx_wait
;
1549 unsigned long timeout
;
1551 oldcount
= priv
->pending_tx_pkts
;
1553 spin_unlock_bh(&priv
->tx_lock
);
1554 timeout
= wait_for_completion_timeout(&tx_wait
,
1555 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS
));
1557 if (atomic_read(&priv
->watchdog_event_pending
)) {
1558 spin_lock_bh(&priv
->tx_lock
);
1559 priv
->tx_wait
= NULL
;
1560 spin_unlock_bh(&priv
->tx_lock
);
1564 spin_lock_bh(&priv
->tx_lock
);
1567 WARN_ON(priv
->pending_tx_pkts
);
1569 wiphy_notice(hw
->wiphy
, "tx rings drained\n");
1573 if (priv
->pending_tx_pkts
< oldcount
) {
1574 wiphy_notice(hw
->wiphy
,
1575 "waiting for tx rings to drain (%d -> %d pkts)\n",
1576 oldcount
, priv
->pending_tx_pkts
);
1581 priv
->tx_wait
= NULL
;
1583 wiphy_err(hw
->wiphy
, "tx rings stuck for %d ms\n",
1584 MWL8K_TX_WAIT_TIMEOUT_MS
);
1585 mwl8k_dump_tx_rings(hw
);
1586 priv
->hw_restart_in_progress
= true;
1587 ieee80211_queue_work(hw
, &priv
->fw_reload
);
1591 priv
->tx_wait
= NULL
;
1592 spin_unlock_bh(&priv
->tx_lock
);
1597 #define MWL8K_TXD_SUCCESS(status) \
1598 ((status) & (MWL8K_TXD_STATUS_OK | \
1599 MWL8K_TXD_STATUS_OK_RETRY | \
1600 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1602 static int mwl8k_tid_queue_mapping(u8 tid
)
1609 return IEEE80211_AC_BE
;
1613 return IEEE80211_AC_BK
;
1617 return IEEE80211_AC_VI
;
1621 return IEEE80211_AC_VO
;
1629 /* The firmware will fill in the rate information
1630 * for each packet that gets queued in the hardware
1631 * and these macros will interpret that info.
1634 #define RI_FORMAT(a) (a & 0x0001)
1635 #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
1638 mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int limit
, int force
)
1640 struct mwl8k_priv
*priv
= hw
->priv
;
1641 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1645 while (txq
->len
> 0 && limit
--) {
1647 struct mwl8k_tx_desc
*tx_desc
;
1650 struct sk_buff
*skb
;
1651 struct ieee80211_tx_info
*info
;
1653 struct ieee80211_sta
*sta
;
1654 struct mwl8k_sta
*sta_info
= NULL
;
1656 struct ieee80211_hdr
*wh
;
1659 tx_desc
= txq
->txd
+ tx
;
1661 status
= le32_to_cpu(tx_desc
->status
);
1663 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1667 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1670 txq
->head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1671 BUG_ON(txq
->len
== 0);
1673 priv
->pending_tx_pkts
--;
1675 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1676 size
= le16_to_cpu(tx_desc
->pkt_len
);
1678 txq
->skb
[tx
] = NULL
;
1680 BUG_ON(skb
== NULL
);
1681 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1683 mwl8k_remove_dma_header(skb
, tx_desc
->qos_control
);
1685 wh
= (struct ieee80211_hdr
*) skb
->data
;
1687 /* Mark descriptor as unused */
1688 tx_desc
->pkt_phys_addr
= 0;
1689 tx_desc
->pkt_len
= 0;
1691 info
= IEEE80211_SKB_CB(skb
);
1692 if (ieee80211_is_data(wh
->frame_control
)) {
1694 sta
= ieee80211_find_sta_by_ifaddr(hw
, wh
->addr1
,
1697 sta_info
= MWL8K_STA(sta
);
1698 BUG_ON(sta_info
== NULL
);
1699 rate_info
= le16_to_cpu(tx_desc
->rate_info
);
1700 /* If rate is < 6.5 Mpbs for an ht station
1701 * do not form an ampdu. If the station is a
1702 * legacy station (format = 0), do not form an
1705 if (RI_RATE_ID_MCS(rate_info
) < 1 ||
1706 RI_FORMAT(rate_info
) == 0) {
1707 sta_info
->is_ampdu_allowed
= false;
1709 sta_info
->is_ampdu_allowed
= true;
1715 ieee80211_tx_info_clear_status(info
);
1717 /* Rate control is happening in the firmware.
1718 * Ensure no tx rate is being reported.
1720 info
->status
.rates
[0].idx
= -1;
1721 info
->status
.rates
[0].count
= 1;
1723 if (MWL8K_TXD_SUCCESS(status
))
1724 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1726 ieee80211_tx_status_irqsafe(hw
, skb
);
1734 /* must be called only when the card's transmit is completely halted */
1735 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1737 struct mwl8k_priv
*priv
= hw
->priv
;
1738 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1740 if (txq
->txd
== NULL
)
1743 mwl8k_txq_reclaim(hw
, index
, INT_MAX
, 1);
1748 pci_free_consistent(priv
->pdev
,
1749 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1750 txq
->txd
, txq
->txd_dma
);
1754 /* caller must hold priv->stream_lock when calling the stream functions */
1755 static struct mwl8k_ampdu_stream
*
1756 mwl8k_add_stream(struct ieee80211_hw
*hw
, struct ieee80211_sta
*sta
, u8 tid
)
1758 struct mwl8k_ampdu_stream
*stream
;
1759 struct mwl8k_priv
*priv
= hw
->priv
;
1762 for (i
= 0; i
< MWL8K_NUM_AMPDU_STREAMS
; i
++) {
1763 stream
= &priv
->ampdu
[i
];
1764 if (stream
->state
== AMPDU_NO_STREAM
) {
1766 stream
->state
= AMPDU_STREAM_NEW
;
1769 wiphy_debug(hw
->wiphy
, "Added a new stream for %pM %d",
1778 mwl8k_start_stream(struct ieee80211_hw
*hw
, struct mwl8k_ampdu_stream
*stream
)
1782 /* if the stream has already been started, don't start it again */
1783 if (stream
->state
!= AMPDU_STREAM_NEW
)
1785 ret
= ieee80211_start_tx_ba_session(stream
->sta
, stream
->tid
, 0);
1787 wiphy_debug(hw
->wiphy
, "Failed to start stream for %pM %d: "
1788 "%d\n", stream
->sta
->addr
, stream
->tid
, ret
);
1790 wiphy_debug(hw
->wiphy
, "Started stream for %pM %d\n",
1791 stream
->sta
->addr
, stream
->tid
);
1796 mwl8k_remove_stream(struct ieee80211_hw
*hw
, struct mwl8k_ampdu_stream
*stream
)
1798 wiphy_debug(hw
->wiphy
, "Remove stream for %pM %d\n", stream
->sta
->addr
,
1800 memset(stream
, 0, sizeof(*stream
));
1803 static struct mwl8k_ampdu_stream
*
1804 mwl8k_lookup_stream(struct ieee80211_hw
*hw
, u8
*addr
, u8 tid
)
1806 struct mwl8k_priv
*priv
= hw
->priv
;
1809 for (i
= 0; i
< MWL8K_NUM_AMPDU_STREAMS
; i
++) {
1810 struct mwl8k_ampdu_stream
*stream
;
1811 stream
= &priv
->ampdu
[i
];
1812 if (stream
->state
== AMPDU_NO_STREAM
)
1814 if (!memcmp(stream
->sta
->addr
, addr
, ETH_ALEN
) &&
1821 #define MWL8K_AMPDU_PACKET_THRESHOLD 64
1822 static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta
*sta
, u8 tid
)
1824 struct mwl8k_sta
*sta_info
= MWL8K_STA(sta
);
1825 struct tx_traffic_info
*tx_stats
;
1827 BUG_ON(tid
>= MWL8K_MAX_TID
);
1828 tx_stats
= &sta_info
->tx_stats
[tid
];
1830 return sta_info
->is_ampdu_allowed
&&
1831 tx_stats
->pkts
> MWL8K_AMPDU_PACKET_THRESHOLD
;
1834 static inline void mwl8k_tx_count_packet(struct ieee80211_sta
*sta
, u8 tid
)
1836 struct mwl8k_sta
*sta_info
= MWL8K_STA(sta
);
1837 struct tx_traffic_info
*tx_stats
;
1839 BUG_ON(tid
>= MWL8K_MAX_TID
);
1840 tx_stats
= &sta_info
->tx_stats
[tid
];
1842 if (tx_stats
->start_time
== 0)
1843 tx_stats
->start_time
= jiffies
;
1845 /* reset the packet count after each second elapses. If the number of
1846 * packets ever exceeds the ampdu_min_traffic threshold, we will allow
1847 * an ampdu stream to be started.
1849 if (jiffies
- tx_stats
->start_time
> HZ
) {
1851 tx_stats
->start_time
= 0;
1856 /* The hardware ampdu queues start from 5.
1857 * txpriorities for ampdu queues are
1858 * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
1859 * and queue 3 is lowest (queue 4 is reserved)
1864 mwl8k_txq_xmit(struct ieee80211_hw
*hw
,
1866 struct ieee80211_sta
*sta
,
1867 struct sk_buff
*skb
)
1869 struct mwl8k_priv
*priv
= hw
->priv
;
1870 struct ieee80211_tx_info
*tx_info
;
1871 struct mwl8k_vif
*mwl8k_vif
;
1872 struct ieee80211_hdr
*wh
;
1873 struct mwl8k_tx_queue
*txq
;
1874 struct mwl8k_tx_desc
*tx
;
1881 struct mwl8k_ampdu_stream
*stream
= NULL
;
1882 bool start_ba_session
= false;
1883 bool mgmtframe
= false;
1884 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)skb
->data
;
1885 bool eapol_frame
= false;
1887 wh
= (struct ieee80211_hdr
*)skb
->data
;
1888 if (ieee80211_is_data_qos(wh
->frame_control
))
1889 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1893 if (skb
->protocol
== cpu_to_be16(ETH_P_PAE
))
1896 if (ieee80211_is_mgmt(wh
->frame_control
))
1900 mwl8k_encapsulate_tx_frame(priv
, skb
);
1902 mwl8k_add_dma_header(priv
, skb
, 0, 0);
1904 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1906 tx_info
= IEEE80211_SKB_CB(skb
);
1907 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1909 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1910 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1911 wh
->seq_ctrl
|= cpu_to_le16(mwl8k_vif
->seqno
);
1912 mwl8k_vif
->seqno
+= 0x10;
1915 /* Setup firmware control bit fields for each frame type. */
1918 if (ieee80211_is_mgmt(wh
->frame_control
) ||
1919 ieee80211_is_ctl(wh
->frame_control
)) {
1921 qos
|= MWL8K_QOS_QLEN_UNSPEC
| MWL8K_QOS_EOSP
;
1922 } else if (ieee80211_is_data(wh
->frame_control
)) {
1924 if (is_multicast_ether_addr(wh
->addr1
))
1925 txstatus
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1927 qos
&= ~MWL8K_QOS_ACK_POLICY_MASK
;
1928 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1929 qos
|= MWL8K_QOS_ACK_POLICY_BLOCKACK
;
1931 qos
|= MWL8K_QOS_ACK_POLICY_NORMAL
;
1934 /* Queue ADDBA request in the respective data queue. While setting up
1935 * the ampdu stream, mac80211 queues further packets for that
1936 * particular ra/tid pair. However, packets piled up in the hardware
1937 * for that ra/tid pair will still go out. ADDBA request and the
1938 * related data packets going out from different queues asynchronously
1939 * will cause a shift in the receiver window which might result in
1940 * ampdu packets getting dropped at the receiver after the stream has
1943 if (unlikely(ieee80211_is_action(wh
->frame_control
) &&
1944 mgmt
->u
.action
.category
== WLAN_CATEGORY_BACK
&&
1945 mgmt
->u
.action
.u
.addba_req
.action_code
== WLAN_ACTION_ADDBA_REQ
&&
1947 u16 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1948 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1949 index
= mwl8k_tid_queue_mapping(tid
);
1954 if (priv
->ap_fw
&& sta
&& sta
->ht_cap
.ht_supported
&& !eapol_frame
&&
1955 ieee80211_is_data_qos(wh
->frame_control
)) {
1957 mwl8k_tx_count_packet(sta
, tid
);
1958 spin_lock(&priv
->stream_lock
);
1959 stream
= mwl8k_lookup_stream(hw
, sta
->addr
, tid
);
1960 if (stream
!= NULL
) {
1961 if (stream
->state
== AMPDU_STREAM_ACTIVE
) {
1962 WARN_ON(!(qos
& MWL8K_QOS_ACK_POLICY_BLOCKACK
));
1963 txpriority
= (BA_QUEUE
+ stream
->idx
) %
1965 if (stream
->idx
<= 1)
1966 index
= stream
->idx
+
1967 MWL8K_TX_WMM_QUEUES
;
1969 } else if (stream
->state
== AMPDU_STREAM_NEW
) {
1970 /* We get here if the driver sends us packets
1971 * after we've initiated a stream, but before
1972 * our ampdu_action routine has been called
1973 * with IEEE80211_AMPDU_TX_START to get the SSN
1974 * for the ADDBA request. So this packet can
1975 * go out with no risk of sequence number
1976 * mismatch. No special handling is required.
1979 /* Drop packets that would go out after the
1980 * ADDBA request was sent but before the ADDBA
1981 * response is received. If we don't do this,
1982 * the recipient would probably receive it
1983 * after the ADDBA request with SSN 0. This
1984 * will cause the recipient's BA receive window
1985 * to shift, which would cause the subsequent
1986 * packets in the BA stream to be discarded.
1987 * mac80211 queues our packets for us in this
1988 * case, so this is really just a safety check.
1990 wiphy_warn(hw
->wiphy
,
1991 "Cannot send packet while ADDBA "
1992 "dialog is underway.\n");
1993 spin_unlock(&priv
->stream_lock
);
1998 /* Defer calling mwl8k_start_stream so that the current
1999 * skb can go out before the ADDBA request. This
2000 * prevents sequence number mismatch at the recepient
2001 * as described above.
2003 if (mwl8k_ampdu_allowed(sta
, tid
)) {
2004 stream
= mwl8k_add_stream(hw
, sta
, tid
);
2006 start_ba_session
= true;
2009 spin_unlock(&priv
->stream_lock
);
2011 qos
&= ~MWL8K_QOS_ACK_POLICY_MASK
;
2012 qos
|= MWL8K_QOS_ACK_POLICY_NORMAL
;
2015 dma
= pci_map_single(priv
->pdev
, skb
->data
,
2016 skb
->len
, PCI_DMA_TODEVICE
);
2018 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
2019 wiphy_debug(hw
->wiphy
,
2020 "failed to dma map skb, dropping TX frame.\n");
2021 if (start_ba_session
) {
2022 spin_lock(&priv
->stream_lock
);
2023 mwl8k_remove_stream(hw
, stream
);
2024 spin_unlock(&priv
->stream_lock
);
2030 spin_lock_bh(&priv
->tx_lock
);
2032 txq
= priv
->txq
+ index
;
2034 /* Mgmt frames that go out frequently are probe
2035 * responses. Other mgmt frames got out relatively
2036 * infrequently. Hence reserve 2 buffers so that
2037 * other mgmt frames do not get dropped due to an
2038 * already queued probe response in one of the
2042 if (txq
->len
>= MWL8K_TX_DESCS
- 2) {
2043 if (!mgmtframe
|| txq
->len
== MWL8K_TX_DESCS
) {
2044 if (start_ba_session
) {
2045 spin_lock(&priv
->stream_lock
);
2046 mwl8k_remove_stream(hw
, stream
);
2047 spin_unlock(&priv
->stream_lock
);
2049 spin_unlock_bh(&priv
->tx_lock
);
2050 pci_unmap_single(priv
->pdev
, dma
, skb
->len
,
2057 BUG_ON(txq
->skb
[txq
->tail
] != NULL
);
2058 txq
->skb
[txq
->tail
] = skb
;
2060 tx
= txq
->txd
+ txq
->tail
;
2061 tx
->data_rate
= txdatarate
;
2062 tx
->tx_priority
= txpriority
;
2063 tx
->qos_control
= cpu_to_le16(qos
);
2064 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
2065 tx
->pkt_len
= cpu_to_le16(skb
->len
);
2067 if (!priv
->ap_fw
&& sta
!= NULL
)
2068 tx
->peer_id
= MWL8K_STA(sta
)->peer_id
;
2072 if (priv
->ap_fw
&& ieee80211_is_data(wh
->frame_control
) && !eapol_frame
)
2073 tx
->timestamp
= cpu_to_le32(ioread32(priv
->regs
+
2074 MWL8K_HW_TIMER_REGISTER
));
2079 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
| txstatus
);
2082 priv
->pending_tx_pkts
++;
2085 if (txq
->tail
== MWL8K_TX_DESCS
)
2088 mwl8k_tx_start(priv
);
2090 spin_unlock_bh(&priv
->tx_lock
);
2092 /* Initiate the ampdu session here */
2093 if (start_ba_session
) {
2094 spin_lock(&priv
->stream_lock
);
2095 if (mwl8k_start_stream(hw
, stream
))
2096 mwl8k_remove_stream(hw
, stream
);
2097 spin_unlock(&priv
->stream_lock
);
2105 * We have the following requirements for issuing firmware commands:
2106 * - Some commands require that the packet transmit path is idle when
2107 * the command is issued. (For simplicity, we'll just quiesce the
2108 * transmit path for every command.)
2109 * - There are certain sequences of commands that need to be issued to
2110 * the hardware sequentially, with no other intervening commands.
2112 * This leads to an implementation of a "firmware lock" as a mutex that
2113 * can be taken recursively, and which is taken by both the low-level
2114 * command submission function (mwl8k_post_cmd) as well as any users of
2115 * that function that require issuing of an atomic sequence of commands,
2116 * and quiesces the transmit path whenever it's taken.
2118 static int mwl8k_fw_lock(struct ieee80211_hw
*hw
)
2120 struct mwl8k_priv
*priv
= hw
->priv
;
2122 if (priv
->fw_mutex_owner
!= current
) {
2125 mutex_lock(&priv
->fw_mutex
);
2126 ieee80211_stop_queues(hw
);
2128 rc
= mwl8k_tx_wait_empty(hw
);
2130 if (!priv
->hw_restart_in_progress
)
2131 ieee80211_wake_queues(hw
);
2133 mutex_unlock(&priv
->fw_mutex
);
2138 priv
->fw_mutex_owner
= current
;
2141 priv
->fw_mutex_depth
++;
2146 static void mwl8k_fw_unlock(struct ieee80211_hw
*hw
)
2148 struct mwl8k_priv
*priv
= hw
->priv
;
2150 if (!--priv
->fw_mutex_depth
) {
2151 if (!priv
->hw_restart_in_progress
)
2152 ieee80211_wake_queues(hw
);
2154 priv
->fw_mutex_owner
= NULL
;
2155 mutex_unlock(&priv
->fw_mutex
);
2161 * Command processing.
2164 /* Timeout firmware commands after 10s */
2165 #define MWL8K_CMD_TIMEOUT_MS 10000
2167 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
2169 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
2170 struct mwl8k_priv
*priv
= hw
->priv
;
2171 void __iomem
*regs
= priv
->regs
;
2172 dma_addr_t dma_addr
;
2173 unsigned int dma_size
;
2175 unsigned long timeout
= 0;
2178 cmd
->result
= (__force __le16
) 0xffff;
2179 dma_size
= le16_to_cpu(cmd
->length
);
2180 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
2181 PCI_DMA_BIDIRECTIONAL
);
2182 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
2185 rc
= mwl8k_fw_lock(hw
);
2187 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
2188 PCI_DMA_BIDIRECTIONAL
);
2192 priv
->hostcmd_wait
= &cmd_wait
;
2193 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
2194 iowrite32(MWL8K_H2A_INT_DOORBELL
,
2195 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
2196 iowrite32(MWL8K_H2A_INT_DUMMY
,
2197 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
2199 timeout
= wait_for_completion_timeout(&cmd_wait
,
2200 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
2202 priv
->hostcmd_wait
= NULL
;
2204 mwl8k_fw_unlock(hw
);
2206 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
2207 PCI_DMA_BIDIRECTIONAL
);
2210 wiphy_err(hw
->wiphy
, "Command %s timeout after %u ms\n",
2211 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
2212 MWL8K_CMD_TIMEOUT_MS
);
2217 ms
= MWL8K_CMD_TIMEOUT_MS
- jiffies_to_msecs(timeout
);
2219 rc
= cmd
->result
? -EINVAL
: 0;
2221 wiphy_err(hw
->wiphy
, "Command %s error 0x%x\n",
2222 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
2223 le16_to_cpu(cmd
->result
));
2225 wiphy_notice(hw
->wiphy
, "Command %s took %d ms\n",
2226 mwl8k_cmd_name(cmd
->code
,
2234 static int mwl8k_post_pervif_cmd(struct ieee80211_hw
*hw
,
2235 struct ieee80211_vif
*vif
,
2236 struct mwl8k_cmd_pkt
*cmd
)
2239 cmd
->macid
= MWL8K_VIF(vif
)->macid
;
2240 return mwl8k_post_cmd(hw
, cmd
);
2244 * Setup code shared between STA and AP firmware images.
2246 static void mwl8k_setup_2ghz_band(struct ieee80211_hw
*hw
)
2248 struct mwl8k_priv
*priv
= hw
->priv
;
2250 BUILD_BUG_ON(sizeof(priv
->channels_24
) != sizeof(mwl8k_channels_24
));
2251 memcpy(priv
->channels_24
, mwl8k_channels_24
, sizeof(mwl8k_channels_24
));
2253 BUILD_BUG_ON(sizeof(priv
->rates_24
) != sizeof(mwl8k_rates_24
));
2254 memcpy(priv
->rates_24
, mwl8k_rates_24
, sizeof(mwl8k_rates_24
));
2256 priv
->band_24
.band
= IEEE80211_BAND_2GHZ
;
2257 priv
->band_24
.channels
= priv
->channels_24
;
2258 priv
->band_24
.n_channels
= ARRAY_SIZE(mwl8k_channels_24
);
2259 priv
->band_24
.bitrates
= priv
->rates_24
;
2260 priv
->band_24
.n_bitrates
= ARRAY_SIZE(mwl8k_rates_24
);
2262 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band_24
;
2265 static void mwl8k_setup_5ghz_band(struct ieee80211_hw
*hw
)
2267 struct mwl8k_priv
*priv
= hw
->priv
;
2269 BUILD_BUG_ON(sizeof(priv
->channels_50
) != sizeof(mwl8k_channels_50
));
2270 memcpy(priv
->channels_50
, mwl8k_channels_50
, sizeof(mwl8k_channels_50
));
2272 BUILD_BUG_ON(sizeof(priv
->rates_50
) != sizeof(mwl8k_rates_50
));
2273 memcpy(priv
->rates_50
, mwl8k_rates_50
, sizeof(mwl8k_rates_50
));
2275 priv
->band_50
.band
= IEEE80211_BAND_5GHZ
;
2276 priv
->band_50
.channels
= priv
->channels_50
;
2277 priv
->band_50
.n_channels
= ARRAY_SIZE(mwl8k_channels_50
);
2278 priv
->band_50
.bitrates
= priv
->rates_50
;
2279 priv
->band_50
.n_bitrates
= ARRAY_SIZE(mwl8k_rates_50
);
2281 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &priv
->band_50
;
2285 * CMD_GET_HW_SPEC (STA version).
2287 struct mwl8k_cmd_get_hw_spec_sta
{
2288 struct mwl8k_cmd_pkt header
;
2290 __u8 host_interface
;
2292 __u8 perm_addr
[ETH_ALEN
];
2297 __u8 mcs_bitmap
[16];
2298 __le32 rx_queue_ptr
;
2299 __le32 num_tx_queues
;
2300 __le32 tx_queue_ptrs
[MWL8K_TX_WMM_QUEUES
];
2302 __le32 num_tx_desc_per_queue
;
2306 #define MWL8K_CAP_MAX_AMSDU 0x20000000
2307 #define MWL8K_CAP_GREENFIELD 0x08000000
2308 #define MWL8K_CAP_AMPDU 0x04000000
2309 #define MWL8K_CAP_RX_STBC 0x01000000
2310 #define MWL8K_CAP_TX_STBC 0x00800000
2311 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2312 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2313 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2314 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2315 #define MWL8K_CAP_DELAY_BA 0x00003000
2316 #define MWL8K_CAP_MIMO 0x00000200
2317 #define MWL8K_CAP_40MHZ 0x00000100
2318 #define MWL8K_CAP_BAND_MASK 0x00000007
2319 #define MWL8K_CAP_5GHZ 0x00000004
2320 #define MWL8K_CAP_2GHZ4 0x00000001
2323 mwl8k_set_ht_caps(struct ieee80211_hw
*hw
,
2324 struct ieee80211_supported_band
*band
, u32 cap
)
2329 band
->ht_cap
.ht_supported
= 1;
2331 if (cap
& MWL8K_CAP_MAX_AMSDU
)
2332 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
2333 if (cap
& MWL8K_CAP_GREENFIELD
)
2334 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_GRN_FLD
;
2335 if (cap
& MWL8K_CAP_AMPDU
) {
2336 hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
2337 band
->ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
2338 band
->ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_NONE
;
2340 if (cap
& MWL8K_CAP_RX_STBC
)
2341 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_RX_STBC
;
2342 if (cap
& MWL8K_CAP_TX_STBC
)
2343 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
2344 if (cap
& MWL8K_CAP_SHORTGI_40MHZ
)
2345 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
2346 if (cap
& MWL8K_CAP_SHORTGI_20MHZ
)
2347 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
2348 if (cap
& MWL8K_CAP_DELAY_BA
)
2349 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_DELAY_BA
;
2350 if (cap
& MWL8K_CAP_40MHZ
)
2351 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
2353 rx_streams
= hweight32(cap
& MWL8K_CAP_RX_ANTENNA_MASK
);
2354 tx_streams
= hweight32(cap
& MWL8K_CAP_TX_ANTENNA_MASK
);
2356 band
->ht_cap
.mcs
.rx_mask
[0] = 0xff;
2357 if (rx_streams
>= 2)
2358 band
->ht_cap
.mcs
.rx_mask
[1] = 0xff;
2359 if (rx_streams
>= 3)
2360 band
->ht_cap
.mcs
.rx_mask
[2] = 0xff;
2361 band
->ht_cap
.mcs
.rx_mask
[4] = 0x01;
2362 band
->ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
2364 if (rx_streams
!= tx_streams
) {
2365 band
->ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_RX_DIFF
;
2366 band
->ht_cap
.mcs
.tx_params
|= (tx_streams
- 1) <<
2367 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
2372 mwl8k_set_caps(struct ieee80211_hw
*hw
, u32 caps
)
2374 struct mwl8k_priv
*priv
= hw
->priv
;
2376 if ((caps
& MWL8K_CAP_2GHZ4
) || !(caps
& MWL8K_CAP_BAND_MASK
)) {
2377 mwl8k_setup_2ghz_band(hw
);
2378 if (caps
& MWL8K_CAP_MIMO
)
2379 mwl8k_set_ht_caps(hw
, &priv
->band_24
, caps
);
2382 if (caps
& MWL8K_CAP_5GHZ
) {
2383 mwl8k_setup_5ghz_band(hw
);
2384 if (caps
& MWL8K_CAP_MIMO
)
2385 mwl8k_set_ht_caps(hw
, &priv
->band_50
, caps
);
2389 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw
*hw
)
2391 struct mwl8k_priv
*priv
= hw
->priv
;
2392 struct mwl8k_cmd_get_hw_spec_sta
*cmd
;
2396 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2400 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
2401 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2403 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
2404 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
2405 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rxd_dma
);
2406 cmd
->num_tx_queues
= cpu_to_le32(mwl8k_tx_queues(priv
));
2407 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
2408 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].txd_dma
);
2409 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
2410 cmd
->total_rxd
= cpu_to_le32(MWL8K_RX_DESCS
);
2412 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2415 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
2416 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
2417 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
2418 priv
->hw_rev
= cmd
->hw_rev
;
2419 mwl8k_set_caps(hw
, le32_to_cpu(cmd
->caps
));
2420 priv
->ap_macids_supported
= 0x00000000;
2421 priv
->sta_macids_supported
= 0x00000001;
2429 * CMD_GET_HW_SPEC (AP version).
2431 struct mwl8k_cmd_get_hw_spec_ap
{
2432 struct mwl8k_cmd_pkt header
;
2434 __u8 host_interface
;
2437 __u8 perm_addr
[ETH_ALEN
];
2448 __le32 fw_api_version
;
2450 __le32 num_of_ampdu_queues
;
2451 __le32 wcbbase_ampdu
[MWL8K_MAX_AMPDU_QUEUES
];
2454 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw
*hw
)
2456 struct mwl8k_priv
*priv
= hw
->priv
;
2457 struct mwl8k_cmd_get_hw_spec_ap
*cmd
;
2461 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2465 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
2466 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2468 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
2469 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
2471 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2476 api_version
= le32_to_cpu(cmd
->fw_api_version
);
2477 if (priv
->device_info
->fw_api_ap
!= api_version
) {
2478 printk(KERN_ERR
"%s: Unsupported fw API version for %s."
2479 " Expected %d got %d.\n", MWL8K_NAME
,
2480 priv
->device_info
->part_name
,
2481 priv
->device_info
->fw_api_ap
,
2486 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
2487 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
2488 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
2489 priv
->hw_rev
= cmd
->hw_rev
;
2490 mwl8k_set_caps(hw
, le32_to_cpu(cmd
->caps
));
2491 priv
->ap_macids_supported
= 0x000000ff;
2492 priv
->sta_macids_supported
= 0x00000000;
2493 priv
->num_ampdu_queues
= le32_to_cpu(cmd
->num_of_ampdu_queues
);
2494 if (priv
->num_ampdu_queues
> MWL8K_MAX_AMPDU_QUEUES
) {
2495 wiphy_warn(hw
->wiphy
, "fw reported %d ampdu queues"
2496 " but we only support %d.\n",
2497 priv
->num_ampdu_queues
,
2498 MWL8K_MAX_AMPDU_QUEUES
);
2499 priv
->num_ampdu_queues
= MWL8K_MAX_AMPDU_QUEUES
;
2501 off
= le32_to_cpu(cmd
->rxwrptr
) & 0xffff;
2502 iowrite32(priv
->rxq
[0].rxd_dma
, priv
->sram
+ off
);
2504 off
= le32_to_cpu(cmd
->rxrdptr
) & 0xffff;
2505 iowrite32(priv
->rxq
[0].rxd_dma
, priv
->sram
+ off
);
2507 priv
->txq_offset
[0] = le32_to_cpu(cmd
->wcbbase0
) & 0xffff;
2508 priv
->txq_offset
[1] = le32_to_cpu(cmd
->wcbbase1
) & 0xffff;
2509 priv
->txq_offset
[2] = le32_to_cpu(cmd
->wcbbase2
) & 0xffff;
2510 priv
->txq_offset
[3] = le32_to_cpu(cmd
->wcbbase3
) & 0xffff;
2512 for (i
= 0; i
< priv
->num_ampdu_queues
; i
++)
2513 priv
->txq_offset
[i
+ MWL8K_TX_WMM_QUEUES
] =
2514 le32_to_cpu(cmd
->wcbbase_ampdu
[i
]) & 0xffff;
2525 struct mwl8k_cmd_set_hw_spec
{
2526 struct mwl8k_cmd_pkt header
;
2528 __u8 host_interface
;
2530 __u8 perm_addr
[ETH_ALEN
];
2535 __le32 rx_queue_ptr
;
2536 __le32 num_tx_queues
;
2537 __le32 tx_queue_ptrs
[MWL8K_MAX_TX_QUEUES
];
2539 __le32 num_tx_desc_per_queue
;
2543 /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2544 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2545 * the packets that are queued for more than 500ms, will be dropped in the
2546 * hardware. This helps minimizing the issues caused due to head-of-line
2547 * blocking where a slow client can hog the bandwidth and affect traffic to a
2550 #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
2551 #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
2552 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2553 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2554 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
2556 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw
*hw
)
2558 struct mwl8k_priv
*priv
= hw
->priv
;
2559 struct mwl8k_cmd_set_hw_spec
*cmd
;
2563 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2567 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_HW_SPEC
);
2568 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2570 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
2571 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rxd_dma
);
2572 cmd
->num_tx_queues
= cpu_to_le32(mwl8k_tx_queues(priv
));
2575 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2576 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2577 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2578 * priority is interpreted the right way in firmware.
2580 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++) {
2581 int j
= mwl8k_tx_queues(priv
) - 1 - i
;
2582 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[j
].txd_dma
);
2585 cmd
->flags
= cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT
|
2586 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP
|
2587 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON
|
2588 MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY
|
2589 MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR
);
2590 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
2591 cmd
->total_rxd
= cpu_to_le32(MWL8K_RX_DESCS
);
2593 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2600 * CMD_MAC_MULTICAST_ADR.
2602 struct mwl8k_cmd_mac_multicast_adr
{
2603 struct mwl8k_cmd_pkt header
;
2606 __u8 addr
[0][ETH_ALEN
];
2609 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
2610 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
2611 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2612 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
2614 static struct mwl8k_cmd_pkt
*
2615 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
, int allmulti
,
2616 struct netdev_hw_addr_list
*mc_list
)
2618 struct mwl8k_priv
*priv
= hw
->priv
;
2619 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
2624 mc_count
= netdev_hw_addr_list_count(mc_list
);
2626 if (allmulti
|| mc_count
> priv
->num_mcaddrs
) {
2631 size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
2633 cmd
= kzalloc(size
, GFP_ATOMIC
);
2637 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
2638 cmd
->header
.length
= cpu_to_le16(size
);
2639 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED
|
2640 MWL8K_ENABLE_RX_BROADCAST
);
2643 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST
);
2644 } else if (mc_count
) {
2645 struct netdev_hw_addr
*ha
;
2648 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
2649 cmd
->numaddr
= cpu_to_le16(mc_count
);
2650 netdev_hw_addr_list_for_each(ha
, mc_list
) {
2651 memcpy(cmd
->addr
[i
], ha
->addr
, ETH_ALEN
);
2655 return &cmd
->header
;
2661 struct mwl8k_cmd_get_stat
{
2662 struct mwl8k_cmd_pkt header
;
2666 #define MWL8K_STAT_ACK_FAILURE 9
2667 #define MWL8K_STAT_RTS_FAILURE 12
2668 #define MWL8K_STAT_FCS_ERROR 24
2669 #define MWL8K_STAT_RTS_SUCCESS 11
2671 static int mwl8k_cmd_get_stat(struct ieee80211_hw
*hw
,
2672 struct ieee80211_low_level_stats
*stats
)
2674 struct mwl8k_cmd_get_stat
*cmd
;
2677 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2681 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
2682 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2684 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2686 stats
->dot11ACKFailureCount
=
2687 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
2688 stats
->dot11RTSFailureCount
=
2689 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
2690 stats
->dot11FCSErrorCount
=
2691 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
2692 stats
->dot11RTSSuccessCount
=
2693 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
2701 * CMD_RADIO_CONTROL.
2703 struct mwl8k_cmd_radio_control
{
2704 struct mwl8k_cmd_pkt header
;
2711 mwl8k_cmd_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
2713 struct mwl8k_priv
*priv
= hw
->priv
;
2714 struct mwl8k_cmd_radio_control
*cmd
;
2717 if (enable
== priv
->radio_on
&& !force
)
2720 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2724 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
2725 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2726 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2727 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
2728 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
2730 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2734 priv
->radio_on
= enable
;
2739 static int mwl8k_cmd_radio_disable(struct ieee80211_hw
*hw
)
2741 return mwl8k_cmd_radio_control(hw
, 0, 0);
2744 static int mwl8k_cmd_radio_enable(struct ieee80211_hw
*hw
)
2746 return mwl8k_cmd_radio_control(hw
, 1, 0);
2750 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
2752 struct mwl8k_priv
*priv
= hw
->priv
;
2754 priv
->radio_short_preamble
= short_preamble
;
2756 return mwl8k_cmd_radio_control(hw
, 1, 1);
2762 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2764 struct mwl8k_cmd_rf_tx_power
{
2765 struct mwl8k_cmd_pkt header
;
2767 __le16 support_level
;
2768 __le16 current_level
;
2770 __le16 power_level_list
[MWL8K_RF_TX_POWER_LEVEL_TOTAL
];
2773 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
2775 struct mwl8k_cmd_rf_tx_power
*cmd
;
2778 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2782 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
2783 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2784 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2785 cmd
->support_level
= cpu_to_le16(dBm
);
2787 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2796 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2798 struct mwl8k_cmd_tx_power
{
2799 struct mwl8k_cmd_pkt header
;
2805 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
2808 static int mwl8k_cmd_tx_power(struct ieee80211_hw
*hw
,
2809 struct ieee80211_conf
*conf
,
2812 struct ieee80211_channel
*channel
= conf
->channel
;
2813 struct mwl8k_cmd_tx_power
*cmd
;
2817 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2821 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_TX_POWER
);
2822 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2823 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET_LIST
);
2825 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2826 cmd
->band
= cpu_to_le16(0x1);
2827 else if (channel
->band
== IEEE80211_BAND_5GHZ
)
2828 cmd
->band
= cpu_to_le16(0x4);
2830 cmd
->channel
= cpu_to_le16(channel
->hw_value
);
2832 if (conf
->channel_type
== NL80211_CHAN_NO_HT
||
2833 conf
->channel_type
== NL80211_CHAN_HT20
) {
2834 cmd
->bw
= cpu_to_le16(0x2);
2836 cmd
->bw
= cpu_to_le16(0x4);
2837 if (conf
->channel_type
== NL80211_CHAN_HT40MINUS
)
2838 cmd
->sub_ch
= cpu_to_le16(0x3);
2839 else if (conf
->channel_type
== NL80211_CHAN_HT40PLUS
)
2840 cmd
->sub_ch
= cpu_to_le16(0x1);
2843 for (i
= 0; i
< MWL8K_TX_POWER_LEVEL_TOTAL
; i
++)
2844 cmd
->power_level_list
[i
] = cpu_to_le16(pwr
);
2846 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2855 struct mwl8k_cmd_rf_antenna
{
2856 struct mwl8k_cmd_pkt header
;
2861 #define MWL8K_RF_ANTENNA_RX 1
2862 #define MWL8K_RF_ANTENNA_TX 2
2865 mwl8k_cmd_rf_antenna(struct ieee80211_hw
*hw
, int antenna
, int mask
)
2867 struct mwl8k_cmd_rf_antenna
*cmd
;
2870 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2874 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_ANTENNA
);
2875 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2876 cmd
->antenna
= cpu_to_le16(antenna
);
2877 cmd
->mode
= cpu_to_le16(mask
);
2879 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2888 struct mwl8k_cmd_set_beacon
{
2889 struct mwl8k_cmd_pkt header
;
2894 static int mwl8k_cmd_set_beacon(struct ieee80211_hw
*hw
,
2895 struct ieee80211_vif
*vif
, u8
*beacon
, int len
)
2897 struct mwl8k_cmd_set_beacon
*cmd
;
2900 cmd
= kzalloc(sizeof(*cmd
) + len
, GFP_KERNEL
);
2904 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_BEACON
);
2905 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
) + len
);
2906 cmd
->beacon_len
= cpu_to_le16(len
);
2907 memcpy(cmd
->beacon
, beacon
, len
);
2909 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
2918 struct mwl8k_cmd_set_pre_scan
{
2919 struct mwl8k_cmd_pkt header
;
2922 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
2924 struct mwl8k_cmd_set_pre_scan
*cmd
;
2927 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2931 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
2932 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2934 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2941 * CMD_SET_POST_SCAN.
2943 struct mwl8k_cmd_set_post_scan
{
2944 struct mwl8k_cmd_pkt header
;
2946 __u8 bssid
[ETH_ALEN
];
2950 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, const __u8
*mac
)
2952 struct mwl8k_cmd_set_post_scan
*cmd
;
2955 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2959 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
2960 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2962 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
2964 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2971 * CMD_SET_RF_CHANNEL.
2973 struct mwl8k_cmd_set_rf_channel
{
2974 struct mwl8k_cmd_pkt header
;
2976 __u8 current_channel
;
2977 __le32 channel_flags
;
2980 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
2981 struct ieee80211_conf
*conf
)
2983 struct ieee80211_channel
*channel
= conf
->channel
;
2984 struct mwl8k_cmd_set_rf_channel
*cmd
;
2987 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2991 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
2992 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2993 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2994 cmd
->current_channel
= channel
->hw_value
;
2996 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2997 cmd
->channel_flags
|= cpu_to_le32(0x00000001);
2998 else if (channel
->band
== IEEE80211_BAND_5GHZ
)
2999 cmd
->channel_flags
|= cpu_to_le32(0x00000004);
3001 if (conf
->channel_type
== NL80211_CHAN_NO_HT
||
3002 conf
->channel_type
== NL80211_CHAN_HT20
)
3003 cmd
->channel_flags
|= cpu_to_le32(0x00000080);
3004 else if (conf
->channel_type
== NL80211_CHAN_HT40MINUS
)
3005 cmd
->channel_flags
|= cpu_to_le32(0x000001900);
3006 else if (conf
->channel_type
== NL80211_CHAN_HT40PLUS
)
3007 cmd
->channel_flags
|= cpu_to_le32(0x000000900);
3009 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3018 #define MWL8K_FRAME_PROT_DISABLED 0x00
3019 #define MWL8K_FRAME_PROT_11G 0x07
3020 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
3021 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
3023 struct mwl8k_cmd_update_set_aid
{
3024 struct mwl8k_cmd_pkt header
;
3027 /* AP's MAC address (BSSID) */
3028 __u8 bssid
[ETH_ALEN
];
3029 __le16 protection_mode
;
3030 __u8 supp_rates
[14];
3033 static void legacy_rate_mask_to_array(u8
*rates
, u32 mask
)
3039 * Clear nonstandard rates 4 and 13.
3043 for (i
= 0, j
= 0; i
< 14; i
++) {
3044 if (mask
& (1 << i
))
3045 rates
[j
++] = mwl8k_rates_24
[i
].hw_value
;
3050 mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
3051 struct ieee80211_vif
*vif
, u32 legacy_rate_mask
)
3053 struct mwl8k_cmd_update_set_aid
*cmd
;
3057 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3061 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
3062 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3063 cmd
->aid
= cpu_to_le16(vif
->bss_conf
.aid
);
3064 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
3066 if (vif
->bss_conf
.use_cts_prot
) {
3067 prot_mode
= MWL8K_FRAME_PROT_11G
;
3069 switch (vif
->bss_conf
.ht_operation_mode
&
3070 IEEE80211_HT_OP_MODE_PROTECTION
) {
3071 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
3072 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
3074 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
3075 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
3078 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
3082 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
3084 legacy_rate_mask_to_array(cmd
->supp_rates
, legacy_rate_mask
);
3086 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3095 struct mwl8k_cmd_set_rate
{
3096 struct mwl8k_cmd_pkt header
;
3097 __u8 legacy_rates
[14];
3099 /* Bitmap for supported MCS codes. */
3105 mwl8k_cmd_set_rate(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
3106 u32 legacy_rate_mask
, u8
*mcs_rates
)
3108 struct mwl8k_cmd_set_rate
*cmd
;
3111 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3115 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
3116 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3117 legacy_rate_mask_to_array(cmd
->legacy_rates
, legacy_rate_mask
);
3118 memcpy(cmd
->mcs_set
, mcs_rates
, 16);
3120 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3127 * CMD_FINALIZE_JOIN.
3129 #define MWL8K_FJ_BEACON_MAXLEN 128
3131 struct mwl8k_cmd_finalize_join
{
3132 struct mwl8k_cmd_pkt header
;
3133 __le32 sleep_interval
; /* Number of beacon periods to sleep */
3134 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
3137 static int mwl8k_cmd_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
3138 int framelen
, int dtim
)
3140 struct mwl8k_cmd_finalize_join
*cmd
;
3141 struct ieee80211_mgmt
*payload
= frame
;
3145 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3149 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
3150 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3151 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
3153 payload_len
= framelen
- ieee80211_hdrlen(payload
->frame_control
);
3154 if (payload_len
< 0)
3156 else if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
3157 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
3159 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
3161 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3168 * CMD_SET_RTS_THRESHOLD.
3170 struct mwl8k_cmd_set_rts_threshold
{
3171 struct mwl8k_cmd_pkt header
;
3177 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw
*hw
, int rts_thresh
)
3179 struct mwl8k_cmd_set_rts_threshold
*cmd
;
3182 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3186 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
3187 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3188 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
3189 cmd
->threshold
= cpu_to_le16(rts_thresh
);
3191 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3200 struct mwl8k_cmd_set_slot
{
3201 struct mwl8k_cmd_pkt header
;
3206 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, bool short_slot_time
)
3208 struct mwl8k_cmd_set_slot
*cmd
;
3211 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3215 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
3216 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3217 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
3218 cmd
->short_slot
= short_slot_time
;
3220 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3227 * CMD_SET_EDCA_PARAMS.
3229 struct mwl8k_cmd_set_edca_params
{
3230 struct mwl8k_cmd_pkt header
;
3232 /* See MWL8K_SET_EDCA_XXX below */
3235 /* TX opportunity in units of 32 us */
3240 /* Log exponent of max contention period: 0...15 */
3243 /* Log exponent of min contention period: 0...15 */
3246 /* Adaptive interframe spacing in units of 32us */
3249 /* TX queue to configure */
3253 /* Log exponent of max contention period: 0...15 */
3256 /* Log exponent of min contention period: 0...15 */
3259 /* Adaptive interframe spacing in units of 32us */
3262 /* TX queue to configure */
3268 #define MWL8K_SET_EDCA_CW 0x01
3269 #define MWL8K_SET_EDCA_TXOP 0x02
3270 #define MWL8K_SET_EDCA_AIFS 0x04
3272 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3273 MWL8K_SET_EDCA_TXOP | \
3274 MWL8K_SET_EDCA_AIFS)
3277 mwl8k_cmd_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
3278 __u16 cw_min
, __u16 cw_max
,
3279 __u8 aifs
, __u16 txop
)
3281 struct mwl8k_priv
*priv
= hw
->priv
;
3282 struct mwl8k_cmd_set_edca_params
*cmd
;
3285 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3289 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
3290 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3291 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
3292 cmd
->txop
= cpu_to_le16(txop
);
3294 cmd
->ap
.log_cw_max
= cpu_to_le32(ilog2(cw_max
+ 1));
3295 cmd
->ap
.log_cw_min
= cpu_to_le32(ilog2(cw_min
+ 1));
3296 cmd
->ap
.aifs
= aifs
;
3299 cmd
->sta
.log_cw_max
= (u8
)ilog2(cw_max
+ 1);
3300 cmd
->sta
.log_cw_min
= (u8
)ilog2(cw_min
+ 1);
3301 cmd
->sta
.aifs
= aifs
;
3302 cmd
->sta
.txq
= qnum
;
3305 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3314 struct mwl8k_cmd_set_wmm_mode
{
3315 struct mwl8k_cmd_pkt header
;
3319 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw
*hw
, bool enable
)
3321 struct mwl8k_priv
*priv
= hw
->priv
;
3322 struct mwl8k_cmd_set_wmm_mode
*cmd
;
3325 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3329 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
3330 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3331 cmd
->action
= cpu_to_le16(!!enable
);
3333 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3337 priv
->wmm_enabled
= enable
;
3345 struct mwl8k_cmd_mimo_config
{
3346 struct mwl8k_cmd_pkt header
;
3348 __u8 rx_antenna_map
;
3349 __u8 tx_antenna_map
;
3352 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
3354 struct mwl8k_cmd_mimo_config
*cmd
;
3357 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3361 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
3362 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3363 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
3364 cmd
->rx_antenna_map
= rx
;
3365 cmd
->tx_antenna_map
= tx
;
3367 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3374 * CMD_USE_FIXED_RATE (STA version).
3376 struct mwl8k_cmd_use_fixed_rate_sta
{
3377 struct mwl8k_cmd_pkt header
;
3379 __le32 allow_rate_drop
;
3383 __le32 enable_retry
;
3392 #define MWL8K_USE_AUTO_RATE 0x0002
3393 #define MWL8K_UCAST_RATE 0
3395 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw
*hw
)
3397 struct mwl8k_cmd_use_fixed_rate_sta
*cmd
;
3400 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3404 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
3405 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3406 cmd
->action
= cpu_to_le32(MWL8K_USE_AUTO_RATE
);
3407 cmd
->rate_type
= cpu_to_le32(MWL8K_UCAST_RATE
);
3409 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3416 * CMD_USE_FIXED_RATE (AP version).
3418 struct mwl8k_cmd_use_fixed_rate_ap
{
3419 struct mwl8k_cmd_pkt header
;
3421 __le32 allow_rate_drop
;
3423 struct mwl8k_rate_entry_ap
{
3425 __le32 enable_retry
;
3430 u8 multicast_rate_type
;
3435 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw
*hw
, int mcast
, int mgmt
)
3437 struct mwl8k_cmd_use_fixed_rate_ap
*cmd
;
3440 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3444 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
3445 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3446 cmd
->action
= cpu_to_le32(MWL8K_USE_AUTO_RATE
);
3447 cmd
->multicast_rate
= mcast
;
3448 cmd
->management_rate
= mgmt
;
3450 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3457 * CMD_ENABLE_SNIFFER.
3459 struct mwl8k_cmd_enable_sniffer
{
3460 struct mwl8k_cmd_pkt header
;
3464 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
3466 struct mwl8k_cmd_enable_sniffer
*cmd
;
3469 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3473 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
3474 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3475 cmd
->action
= cpu_to_le32(!!enable
);
3477 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3483 struct mwl8k_cmd_update_mac_addr
{
3484 struct mwl8k_cmd_pkt header
;
3488 __u8 mac_addr
[ETH_ALEN
];
3490 __u8 mac_addr
[ETH_ALEN
];
3494 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3495 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3496 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
3497 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
3499 static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw
*hw
,
3500 struct ieee80211_vif
*vif
, u8
*mac
, bool set
)
3502 struct mwl8k_priv
*priv
= hw
->priv
;
3503 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3504 struct mwl8k_cmd_update_mac_addr
*cmd
;
3508 mac_type
= MWL8K_MAC_TYPE_PRIMARY_AP
;
3509 if (vif
!= NULL
&& vif
->type
== NL80211_IFTYPE_STATION
) {
3510 if (mwl8k_vif
->macid
+ 1 == ffs(priv
->sta_macids_supported
))
3511 mac_type
= MWL8K_MAC_TYPE_PRIMARY_CLIENT
;
3513 mac_type
= MWL8K_MAC_TYPE_SECONDARY_CLIENT
;
3514 } else if (vif
!= NULL
&& vif
->type
== NL80211_IFTYPE_AP
) {
3515 if (mwl8k_vif
->macid
+ 1 == ffs(priv
->ap_macids_supported
))
3516 mac_type
= MWL8K_MAC_TYPE_PRIMARY_AP
;
3518 mac_type
= MWL8K_MAC_TYPE_SECONDARY_AP
;
3521 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3526 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR
);
3528 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR
);
3530 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3532 cmd
->mbss
.mac_type
= cpu_to_le16(mac_type
);
3533 memcpy(cmd
->mbss
.mac_addr
, mac
, ETH_ALEN
);
3535 memcpy(cmd
->mac_addr
, mac
, ETH_ALEN
);
3538 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3545 * MWL8K_CMD_SET_MAC_ADDR.
3547 static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw
*hw
,
3548 struct ieee80211_vif
*vif
, u8
*mac
)
3550 return mwl8k_cmd_update_mac_addr(hw
, vif
, mac
, true);
3554 * MWL8K_CMD_DEL_MAC_ADDR.
3556 static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw
*hw
,
3557 struct ieee80211_vif
*vif
, u8
*mac
)
3559 return mwl8k_cmd_update_mac_addr(hw
, vif
, mac
, false);
3563 * CMD_SET_RATEADAPT_MODE.
3565 struct mwl8k_cmd_set_rate_adapt_mode
{
3566 struct mwl8k_cmd_pkt header
;
3571 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw
*hw
, __u16 mode
)
3573 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
3576 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3580 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
3581 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3582 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
3583 cmd
->mode
= cpu_to_le16(mode
);
3585 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3592 * CMD_GET_WATCHDOG_BITMAP.
3594 struct mwl8k_cmd_get_watchdog_bitmap
{
3595 struct mwl8k_cmd_pkt header
;
3599 static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw
*hw
, u8
*bitmap
)
3601 struct mwl8k_cmd_get_watchdog_bitmap
*cmd
;
3604 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3608 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP
);
3609 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3611 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3613 *bitmap
= cmd
->bitmap
;
3620 #define MWL8K_WMM_QUEUE_NUMBER 3
3622 static void mwl8k_destroy_ba(struct ieee80211_hw
*hw
,
3625 static void mwl8k_watchdog_ba_events(struct work_struct
*work
)
3628 u8 bitmap
= 0, stream_index
;
3629 struct mwl8k_ampdu_stream
*streams
;
3630 struct mwl8k_priv
*priv
=
3631 container_of(work
, struct mwl8k_priv
, watchdog_ba_handle
);
3632 struct ieee80211_hw
*hw
= priv
->hw
;
3638 rc
= mwl8k_cmd_get_watchdog_bitmap(priv
->hw
, &bitmap
);
3642 spin_lock(&priv
->stream_lock
);
3644 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
3645 for (i
= 0; i
< TOTAL_HW_TX_QUEUES
; i
++) {
3646 if (bitmap
& (1 << i
)) {
3647 stream_index
= (i
+ MWL8K_WMM_QUEUE_NUMBER
) %
3649 streams
= &priv
->ampdu
[stream_index
];
3650 if (streams
->state
== AMPDU_STREAM_ACTIVE
) {
3651 ieee80211_stop_tx_ba_session(streams
->sta
,
3653 spin_unlock(&priv
->stream_lock
);
3654 mwl8k_destroy_ba(hw
, stream_index
);
3655 spin_lock(&priv
->stream_lock
);
3660 spin_unlock(&priv
->stream_lock
);
3662 atomic_dec(&priv
->watchdog_event_pending
);
3663 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3664 iowrite32((status
| MWL8K_A2H_INT_BA_WATCHDOG
),
3665 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3666 mwl8k_fw_unlock(hw
);
3674 struct mwl8k_cmd_bss_start
{
3675 struct mwl8k_cmd_pkt header
;
3679 static int mwl8k_cmd_bss_start(struct ieee80211_hw
*hw
,
3680 struct ieee80211_vif
*vif
, int enable
)
3682 struct mwl8k_cmd_bss_start
*cmd
;
3685 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3689 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BSS_START
);
3690 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3691 cmd
->enable
= cpu_to_le32(enable
);
3693 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3704 * UPSTREAM is tx direction
3706 #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3707 #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3709 enum ba_stream_action_type
{
3718 struct mwl8k_create_ba_stream
{
3723 u8 peer_mac_addr
[6];
3729 u8 reset_seq_no_flag
;
3731 u8 sta_src_mac_addr
[6];
3734 struct mwl8k_destroy_ba_stream
{
3739 struct mwl8k_cmd_bastream
{
3740 struct mwl8k_cmd_pkt header
;
3743 struct mwl8k_create_ba_stream create_params
;
3744 struct mwl8k_destroy_ba_stream destroy_params
;
3749 mwl8k_check_ba(struct ieee80211_hw
*hw
, struct mwl8k_ampdu_stream
*stream
,
3750 struct ieee80211_vif
*vif
)
3752 struct mwl8k_cmd_bastream
*cmd
;
3755 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3759 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BASTREAM
);
3760 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3762 cmd
->action
= cpu_to_le32(MWL8K_BA_CHECK
);
3764 cmd
->create_params
.queue_id
= stream
->idx
;
3765 memcpy(&cmd
->create_params
.peer_mac_addr
[0], stream
->sta
->addr
,
3767 cmd
->create_params
.tid
= stream
->tid
;
3769 cmd
->create_params
.flags
=
3770 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE
) |
3771 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM
);
3773 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3781 mwl8k_create_ba(struct ieee80211_hw
*hw
, struct mwl8k_ampdu_stream
*stream
,
3782 u8 buf_size
, struct ieee80211_vif
*vif
)
3784 struct mwl8k_cmd_bastream
*cmd
;
3787 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3792 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BASTREAM
);
3793 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3795 cmd
->action
= cpu_to_le32(MWL8K_BA_CREATE
);
3797 cmd
->create_params
.bar_thrs
= cpu_to_le32((u32
)buf_size
);
3798 cmd
->create_params
.window_size
= cpu_to_le32((u32
)buf_size
);
3799 cmd
->create_params
.queue_id
= stream
->idx
;
3801 memcpy(cmd
->create_params
.peer_mac_addr
, stream
->sta
->addr
, ETH_ALEN
);
3802 cmd
->create_params
.tid
= stream
->tid
;
3803 cmd
->create_params
.curr_seq_no
= cpu_to_le16(0);
3804 cmd
->create_params
.reset_seq_no_flag
= 1;
3806 cmd
->create_params
.param_info
=
3807 (stream
->sta
->ht_cap
.ampdu_factor
&
3808 IEEE80211_HT_AMPDU_PARM_FACTOR
) |
3809 ((stream
->sta
->ht_cap
.ampdu_density
<< 2) &
3810 IEEE80211_HT_AMPDU_PARM_DENSITY
);
3812 cmd
->create_params
.flags
=
3813 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE
|
3814 BASTREAM_FLAG_DIRECTION_UPSTREAM
);
3816 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3818 wiphy_debug(hw
->wiphy
, "Created a BA stream for %pM : tid %d\n",
3819 stream
->sta
->addr
, stream
->tid
);
3825 static void mwl8k_destroy_ba(struct ieee80211_hw
*hw
,
3828 struct mwl8k_cmd_bastream
*cmd
;
3830 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3834 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BASTREAM
);
3835 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3836 cmd
->action
= cpu_to_le32(MWL8K_BA_DESTROY
);
3838 cmd
->destroy_params
.ba_context
= cpu_to_le32(idx
);
3839 mwl8k_post_cmd(hw
, &cmd
->header
);
3841 wiphy_debug(hw
->wiphy
, "Deleted BA stream index %d\n", idx
);
3849 struct mwl8k_cmd_set_new_stn
{
3850 struct mwl8k_cmd_pkt header
;
3856 __le32 legacy_rates
;
3859 __le16 ht_capabilities_info
;
3860 __u8 mac_ht_param_info
;
3862 __u8 control_channel
;
3871 #define MWL8K_STA_ACTION_ADD 0
3872 #define MWL8K_STA_ACTION_REMOVE 2
3874 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw
*hw
,
3875 struct ieee80211_vif
*vif
,
3876 struct ieee80211_sta
*sta
)
3878 struct mwl8k_cmd_set_new_stn
*cmd
;
3882 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3886 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3887 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3888 cmd
->aid
= cpu_to_le16(sta
->aid
);
3889 memcpy(cmd
->mac_addr
, sta
->addr
, ETH_ALEN
);
3890 cmd
->stn_id
= cpu_to_le16(sta
->aid
);
3891 cmd
->action
= cpu_to_le16(MWL8K_STA_ACTION_ADD
);
3892 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
3893 rates
= sta
->supp_rates
[IEEE80211_BAND_2GHZ
];
3895 rates
= sta
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
3896 cmd
->legacy_rates
= cpu_to_le32(rates
);
3897 if (sta
->ht_cap
.ht_supported
) {
3898 cmd
->ht_rates
[0] = sta
->ht_cap
.mcs
.rx_mask
[0];
3899 cmd
->ht_rates
[1] = sta
->ht_cap
.mcs
.rx_mask
[1];
3900 cmd
->ht_rates
[2] = sta
->ht_cap
.mcs
.rx_mask
[2];
3901 cmd
->ht_rates
[3] = sta
->ht_cap
.mcs
.rx_mask
[3];
3902 cmd
->ht_capabilities_info
= cpu_to_le16(sta
->ht_cap
.cap
);
3903 cmd
->mac_ht_param_info
= (sta
->ht_cap
.ampdu_factor
& 3) |
3904 ((sta
->ht_cap
.ampdu_density
& 7) << 2);
3905 cmd
->is_qos_sta
= 1;
3908 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3914 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw
*hw
,
3915 struct ieee80211_vif
*vif
)
3917 struct mwl8k_cmd_set_new_stn
*cmd
;
3920 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3924 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3925 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3926 memcpy(cmd
->mac_addr
, vif
->addr
, ETH_ALEN
);
3928 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3934 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw
*hw
,
3935 struct ieee80211_vif
*vif
, u8
*addr
)
3937 struct mwl8k_cmd_set_new_stn
*cmd
;
3938 struct mwl8k_priv
*priv
= hw
->priv
;
3942 spin_lock(&priv
->stream_lock
);
3943 /* Destroy any active ampdu streams for this sta */
3944 for (i
= 0; i
< MWL8K_NUM_AMPDU_STREAMS
; i
++) {
3945 struct mwl8k_ampdu_stream
*s
;
3946 s
= &priv
->ampdu
[i
];
3947 if (s
->state
!= AMPDU_NO_STREAM
) {
3948 if (memcmp(s
->sta
->addr
, addr
, ETH_ALEN
) == 0) {
3949 if (s
->state
== AMPDU_STREAM_ACTIVE
) {
3951 spin_unlock(&priv
->stream_lock
);
3952 mwl8k_destroy_ba(hw
, idx
);
3953 spin_lock(&priv
->stream_lock
);
3954 } else if (s
->state
== AMPDU_STREAM_NEW
) {
3955 mwl8k_remove_stream(hw
, s
);
3961 spin_unlock(&priv
->stream_lock
);
3963 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3967 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3968 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3969 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
3970 cmd
->action
= cpu_to_le16(MWL8K_STA_ACTION_REMOVE
);
3972 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3979 * CMD_UPDATE_ENCRYPTION.
3982 #define MAX_ENCR_KEY_LENGTH 16
3983 #define MIC_KEY_LENGTH 8
3985 struct mwl8k_cmd_update_encryption
{
3986 struct mwl8k_cmd_pkt header
;
3995 struct mwl8k_cmd_set_key
{
3996 struct mwl8k_cmd_pkt header
;
4005 __u8 key_material
[MAX_ENCR_KEY_LENGTH
];
4006 __u8 tkip_tx_mic_key
[MIC_KEY_LENGTH
];
4007 __u8 tkip_rx_mic_key
[MIC_KEY_LENGTH
];
4008 __le16 tkip_rsc_low
;
4009 __le32 tkip_rsc_high
;
4010 __le16 tkip_tsc_low
;
4011 __le32 tkip_tsc_high
;
4018 MWL8K_ENCR_REMOVE_KEY
,
4019 MWL8K_ENCR_SET_GROUP_KEY
,
4022 #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
4023 #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
4024 #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
4025 #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
4026 #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
4034 #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
4035 #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
4036 #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
4037 #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
4038 #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
4040 static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw
*hw
,
4041 struct ieee80211_vif
*vif
,
4045 struct mwl8k_cmd_update_encryption
*cmd
;
4048 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4052 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION
);
4053 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4054 cmd
->action
= cpu_to_le32(MWL8K_ENCR_ENABLE
);
4055 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
4056 cmd
->encr_type
= encr_type
;
4058 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
4064 static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key
*cmd
,
4066 struct ieee80211_key_conf
*key
)
4068 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION
);
4069 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4070 cmd
->length
= cpu_to_le16(sizeof(*cmd
) -
4071 offsetof(struct mwl8k_cmd_set_key
, length
));
4072 cmd
->key_id
= cpu_to_le32(key
->keyidx
);
4073 cmd
->key_len
= cpu_to_le16(key
->keylen
);
4074 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
4076 switch (key
->cipher
) {
4077 case WLAN_CIPHER_SUITE_WEP40
:
4078 case WLAN_CIPHER_SUITE_WEP104
:
4079 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_WEP
);
4080 if (key
->keyidx
== 0)
4081 cmd
->key_info
= cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY
);
4084 case WLAN_CIPHER_SUITE_TKIP
:
4085 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_TKIP
);
4086 cmd
->key_info
= (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4087 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE
)
4088 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY
);
4089 cmd
->key_info
|= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
4090 | MWL8K_KEY_FLAG_TSC_VALID
);
4092 case WLAN_CIPHER_SUITE_CCMP
:
4093 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_CCMP
);
4094 cmd
->key_info
= (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4095 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE
)
4096 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY
);
4105 static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw
*hw
,
4106 struct ieee80211_vif
*vif
,
4108 struct ieee80211_key_conf
*key
)
4110 struct mwl8k_cmd_set_key
*cmd
;
4115 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4117 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4121 rc
= mwl8k_encryption_set_cmd_info(cmd
, addr
, key
);
4127 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4128 action
= MWL8K_ENCR_SET_KEY
;
4130 action
= MWL8K_ENCR_SET_GROUP_KEY
;
4132 switch (key
->cipher
) {
4133 case WLAN_CIPHER_SUITE_WEP40
:
4134 case WLAN_CIPHER_SUITE_WEP104
:
4135 if (!mwl8k_vif
->wep_key_conf
[idx
].enabled
) {
4136 memcpy(mwl8k_vif
->wep_key_conf
[idx
].key
, key
,
4137 sizeof(*key
) + key
->keylen
);
4138 mwl8k_vif
->wep_key_conf
[idx
].enabled
= 1;
4141 keymlen
= key
->keylen
;
4142 action
= MWL8K_ENCR_SET_KEY
;
4144 case WLAN_CIPHER_SUITE_TKIP
:
4145 keymlen
= MAX_ENCR_KEY_LENGTH
+ 2 * MIC_KEY_LENGTH
;
4147 case WLAN_CIPHER_SUITE_CCMP
:
4148 keymlen
= key
->keylen
;
4155 memcpy(cmd
->key_material
, key
->key
, keymlen
);
4156 cmd
->action
= cpu_to_le32(action
);
4158 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
4165 static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw
*hw
,
4166 struct ieee80211_vif
*vif
,
4168 struct ieee80211_key_conf
*key
)
4170 struct mwl8k_cmd_set_key
*cmd
;
4172 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4174 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4178 rc
= mwl8k_encryption_set_cmd_info(cmd
, addr
, key
);
4182 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
4183 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
4184 mwl8k_vif
->wep_key_conf
[key
->keyidx
].enabled
= 0;
4186 cmd
->action
= cpu_to_le32(MWL8K_ENCR_REMOVE_KEY
);
4188 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
4195 static int mwl8k_set_key(struct ieee80211_hw
*hw
,
4196 enum set_key_cmd cmd_param
,
4197 struct ieee80211_vif
*vif
,
4198 struct ieee80211_sta
*sta
,
4199 struct ieee80211_key_conf
*key
)
4204 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4206 if (vif
->type
== NL80211_IFTYPE_STATION
)
4214 if (cmd_param
== SET_KEY
) {
4215 rc
= mwl8k_cmd_encryption_set_key(hw
, vif
, addr
, key
);
4219 if ((key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
4220 || (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
))
4221 encr_type
= MWL8K_UPDATE_ENCRYPTION_TYPE_WEP
;
4223 encr_type
= MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED
;
4225 rc
= mwl8k_cmd_update_encryption_enable(hw
, vif
, addr
,
4230 mwl8k_vif
->is_hw_crypto_enabled
= true;
4233 rc
= mwl8k_cmd_encryption_remove_key(hw
, vif
, addr
, key
);
4245 struct ewc_ht_info
{
4251 struct peer_capability_info
{
4252 /* Peer type - AP vs. STA. */
4255 /* Basic 802.11 capabilities from assoc resp. */
4258 /* Set if peer supports 802.11n high throughput (HT). */
4261 /* Valid if HT is supported. */
4263 __u8 extended_ht_caps
;
4264 struct ewc_ht_info ewc_info
;
4266 /* Legacy rate table. Intersection of our rates and peer rates. */
4267 __u8 legacy_rates
[12];
4269 /* HT rate table. Intersection of our rates and peer rates. */
4273 /* If set, interoperability mode, no proprietary extensions. */
4277 __le16 amsdu_enabled
;
4280 struct mwl8k_cmd_update_stadb
{
4281 struct mwl8k_cmd_pkt header
;
4283 /* See STADB_ACTION_TYPE */
4286 /* Peer MAC address */
4287 __u8 peer_addr
[ETH_ALEN
];
4291 /* Peer info - valid during add/update. */
4292 struct peer_capability_info peer_info
;
4295 #define MWL8K_STA_DB_MODIFY_ENTRY 1
4296 #define MWL8K_STA_DB_DEL_ENTRY 2
4298 /* Peer Entry flags - used to define the type of the peer node */
4299 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
4301 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw
*hw
,
4302 struct ieee80211_vif
*vif
,
4303 struct ieee80211_sta
*sta
)
4305 struct mwl8k_cmd_update_stadb
*cmd
;
4306 struct peer_capability_info
*p
;
4310 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4314 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
4315 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4316 cmd
->action
= cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY
);
4317 memcpy(cmd
->peer_addr
, sta
->addr
, ETH_ALEN
);
4319 p
= &cmd
->peer_info
;
4320 p
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
4321 p
->basic_caps
= cpu_to_le16(vif
->bss_conf
.assoc_capability
);
4322 p
->ht_support
= sta
->ht_cap
.ht_supported
;
4323 p
->ht_caps
= cpu_to_le16(sta
->ht_cap
.cap
);
4324 p
->extended_ht_caps
= (sta
->ht_cap
.ampdu_factor
& 3) |
4325 ((sta
->ht_cap
.ampdu_density
& 7) << 2);
4326 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
4327 rates
= sta
->supp_rates
[IEEE80211_BAND_2GHZ
];
4329 rates
= sta
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
4330 legacy_rate_mask_to_array(p
->legacy_rates
, rates
);
4331 memcpy(p
->ht_rates
, sta
->ht_cap
.mcs
.rx_mask
, 16);
4333 p
->amsdu_enabled
= 0;
4335 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
4338 return rc
? rc
: p
->station_id
;
4341 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw
*hw
,
4342 struct ieee80211_vif
*vif
, u8
*addr
)
4344 struct mwl8k_cmd_update_stadb
*cmd
;
4347 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4351 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
4352 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4353 cmd
->action
= cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY
);
4354 memcpy(cmd
->peer_addr
, addr
, ETH_ALEN
);
4356 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
4364 * Interrupt handling.
4366 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
4368 struct ieee80211_hw
*hw
= dev_id
;
4369 struct mwl8k_priv
*priv
= hw
->priv
;
4372 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4376 if (status
& MWL8K_A2H_INT_TX_DONE
) {
4377 status
&= ~MWL8K_A2H_INT_TX_DONE
;
4378 tasklet_schedule(&priv
->poll_tx_task
);
4381 if (status
& MWL8K_A2H_INT_RX_READY
) {
4382 status
&= ~MWL8K_A2H_INT_RX_READY
;
4383 tasklet_schedule(&priv
->poll_rx_task
);
4386 if (status
& MWL8K_A2H_INT_BA_WATCHDOG
) {
4387 iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG
,
4388 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
4390 atomic_inc(&priv
->watchdog_event_pending
);
4391 status
&= ~MWL8K_A2H_INT_BA_WATCHDOG
;
4392 ieee80211_queue_work(hw
, &priv
->watchdog_ba_handle
);
4396 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4398 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
4399 if (priv
->hostcmd_wait
!= NULL
)
4400 complete(priv
->hostcmd_wait
);
4403 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
4404 if (!mutex_is_locked(&priv
->fw_mutex
) &&
4405 priv
->radio_on
&& priv
->pending_tx_pkts
)
4406 mwl8k_tx_start(priv
);
4412 static void mwl8k_tx_poll(unsigned long data
)
4414 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
4415 struct mwl8k_priv
*priv
= hw
->priv
;
4421 spin_lock_bh(&priv
->tx_lock
);
4423 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
4424 limit
-= mwl8k_txq_reclaim(hw
, i
, limit
, 0);
4426 if (!priv
->pending_tx_pkts
&& priv
->tx_wait
!= NULL
) {
4427 complete(priv
->tx_wait
);
4428 priv
->tx_wait
= NULL
;
4431 spin_unlock_bh(&priv
->tx_lock
);
4434 writel(~MWL8K_A2H_INT_TX_DONE
,
4435 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4437 tasklet_schedule(&priv
->poll_tx_task
);
4441 static void mwl8k_rx_poll(unsigned long data
)
4443 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
4444 struct mwl8k_priv
*priv
= hw
->priv
;
4448 limit
-= rxq_process(hw
, 0, limit
);
4449 limit
-= rxq_refill(hw
, 0, limit
);
4452 writel(~MWL8K_A2H_INT_RX_READY
,
4453 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4455 tasklet_schedule(&priv
->poll_rx_task
);
4461 * Core driver operations.
4463 static void mwl8k_tx(struct ieee80211_hw
*hw
,
4464 struct ieee80211_tx_control
*control
,
4465 struct sk_buff
*skb
)
4467 struct mwl8k_priv
*priv
= hw
->priv
;
4468 int index
= skb_get_queue_mapping(skb
);
4470 if (!priv
->radio_on
) {
4471 wiphy_debug(hw
->wiphy
,
4472 "dropped TX frame since radio disabled\n");
4477 mwl8k_txq_xmit(hw
, index
, control
->sta
, skb
);
4480 static int mwl8k_start(struct ieee80211_hw
*hw
)
4482 struct mwl8k_priv
*priv
= hw
->priv
;
4485 rc
= request_irq(priv
->pdev
->irq
, mwl8k_interrupt
,
4486 IRQF_SHARED
, MWL8K_NAME
, hw
);
4489 wiphy_err(hw
->wiphy
, "failed to register IRQ handler\n");
4492 priv
->irq
= priv
->pdev
->irq
;
4494 /* Enable TX reclaim and RX tasklets. */
4495 tasklet_enable(&priv
->poll_tx_task
);
4496 tasklet_enable(&priv
->poll_rx_task
);
4498 /* Enable interrupts */
4499 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4500 iowrite32(MWL8K_A2H_EVENTS
,
4501 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
4503 rc
= mwl8k_fw_lock(hw
);
4505 rc
= mwl8k_cmd_radio_enable(hw
);
4509 rc
= mwl8k_cmd_enable_sniffer(hw
, 0);
4512 rc
= mwl8k_cmd_set_pre_scan(hw
);
4515 rc
= mwl8k_cmd_set_post_scan(hw
,
4516 "\x00\x00\x00\x00\x00\x00");
4520 rc
= mwl8k_cmd_set_rateadapt_mode(hw
, 0);
4523 rc
= mwl8k_cmd_set_wmm_mode(hw
, 0);
4525 mwl8k_fw_unlock(hw
);
4529 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4530 free_irq(priv
->pdev
->irq
, hw
);
4532 tasklet_disable(&priv
->poll_tx_task
);
4533 tasklet_disable(&priv
->poll_rx_task
);
4535 ieee80211_wake_queues(hw
);
4541 static void mwl8k_stop(struct ieee80211_hw
*hw
)
4543 struct mwl8k_priv
*priv
= hw
->priv
;
4546 if (!priv
->hw_restart_in_progress
)
4547 mwl8k_cmd_radio_disable(hw
);
4549 ieee80211_stop_queues(hw
);
4551 /* Disable interrupts */
4552 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4553 if (priv
->irq
!= -1) {
4554 free_irq(priv
->pdev
->irq
, hw
);
4558 /* Stop finalize join worker */
4559 cancel_work_sync(&priv
->finalize_join_worker
);
4560 cancel_work_sync(&priv
->watchdog_ba_handle
);
4561 if (priv
->beacon_skb
!= NULL
)
4562 dev_kfree_skb(priv
->beacon_skb
);
4564 /* Stop TX reclaim and RX tasklets. */
4565 tasklet_disable(&priv
->poll_tx_task
);
4566 tasklet_disable(&priv
->poll_rx_task
);
4568 /* Return all skbs to mac80211 */
4569 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
4570 mwl8k_txq_reclaim(hw
, i
, INT_MAX
, 1);
4573 static int mwl8k_reload_firmware(struct ieee80211_hw
*hw
, char *fw_image
);
4575 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
4576 struct ieee80211_vif
*vif
)
4578 struct mwl8k_priv
*priv
= hw
->priv
;
4579 struct mwl8k_vif
*mwl8k_vif
;
4580 u32 macids_supported
;
4582 struct mwl8k_device_info
*di
;
4585 * Reject interface creation if sniffer mode is active, as
4586 * STA operation is mutually exclusive with hardware sniffer
4587 * mode. (Sniffer mode is only used on STA firmware.)
4589 if (priv
->sniffer_enabled
) {
4590 wiphy_info(hw
->wiphy
,
4591 "unable to create STA interface because sniffer mode is enabled\n");
4595 di
= priv
->device_info
;
4596 switch (vif
->type
) {
4597 case NL80211_IFTYPE_AP
:
4598 if (!priv
->ap_fw
&& di
->fw_image_ap
) {
4599 /* we must load the ap fw to meet this request */
4600 if (!list_empty(&priv
->vif_list
))
4602 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_ap
);
4606 macids_supported
= priv
->ap_macids_supported
;
4608 case NL80211_IFTYPE_STATION
:
4609 if (priv
->ap_fw
&& di
->fw_image_sta
) {
4610 /* we must load the sta fw to meet this request */
4611 if (!list_empty(&priv
->vif_list
))
4613 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_sta
);
4617 macids_supported
= priv
->sta_macids_supported
;
4623 macid
= ffs(macids_supported
& ~priv
->macids_used
);
4627 /* Setup driver private area. */
4628 mwl8k_vif
= MWL8K_VIF(vif
);
4629 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
4630 mwl8k_vif
->vif
= vif
;
4631 mwl8k_vif
->macid
= macid
;
4632 mwl8k_vif
->seqno
= 0;
4633 memcpy(mwl8k_vif
->bssid
, vif
->addr
, ETH_ALEN
);
4634 mwl8k_vif
->is_hw_crypto_enabled
= false;
4636 /* Set the mac address. */
4637 mwl8k_cmd_set_mac_addr(hw
, vif
, vif
->addr
);
4640 mwl8k_cmd_set_new_stn_add_self(hw
, vif
);
4642 priv
->macids_used
|= 1 << mwl8k_vif
->macid
;
4643 list_add_tail(&mwl8k_vif
->list
, &priv
->vif_list
);
4648 static void mwl8k_remove_vif(struct mwl8k_priv
*priv
, struct mwl8k_vif
*vif
)
4650 /* Has ieee80211_restart_hw re-added the removed interfaces? */
4651 if (!priv
->macids_used
)
4654 priv
->macids_used
&= ~(1 << vif
->macid
);
4655 list_del(&vif
->list
);
4658 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
4659 struct ieee80211_vif
*vif
)
4661 struct mwl8k_priv
*priv
= hw
->priv
;
4662 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4665 mwl8k_cmd_set_new_stn_del(hw
, vif
, vif
->addr
);
4667 mwl8k_cmd_del_mac_addr(hw
, vif
, vif
->addr
);
4669 mwl8k_remove_vif(priv
, mwl8k_vif
);
4672 static void mwl8k_hw_restart_work(struct work_struct
*work
)
4674 struct mwl8k_priv
*priv
=
4675 container_of(work
, struct mwl8k_priv
, fw_reload
);
4676 struct ieee80211_hw
*hw
= priv
->hw
;
4677 struct mwl8k_device_info
*di
;
4680 /* If some command is waiting for a response, clear it */
4681 if (priv
->hostcmd_wait
!= NULL
) {
4682 complete(priv
->hostcmd_wait
);
4683 priv
->hostcmd_wait
= NULL
;
4686 priv
->hw_restart_owner
= current
;
4687 di
= priv
->device_info
;
4691 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_ap
);
4693 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_sta
);
4698 priv
->hw_restart_owner
= NULL
;
4699 priv
->hw_restart_in_progress
= false;
4702 * This unlock will wake up the queues and
4703 * also opens the command path for other
4706 mwl8k_fw_unlock(hw
);
4708 ieee80211_restart_hw(hw
);
4710 wiphy_err(hw
->wiphy
, "Firmware restarted successfully\n");
4714 mwl8k_fw_unlock(hw
);
4716 wiphy_err(hw
->wiphy
, "Firmware restart failed\n");
4719 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
4721 struct ieee80211_conf
*conf
= &hw
->conf
;
4722 struct mwl8k_priv
*priv
= hw
->priv
;
4725 if (conf
->flags
& IEEE80211_CONF_IDLE
) {
4726 mwl8k_cmd_radio_disable(hw
);
4730 rc
= mwl8k_fw_lock(hw
);
4734 rc
= mwl8k_cmd_radio_enable(hw
);
4738 rc
= mwl8k_cmd_set_rf_channel(hw
, conf
);
4742 if (conf
->power_level
> 18)
4743 conf
->power_level
= 18;
4747 if (conf
->flags
& IEEE80211_CONF_CHANGE_POWER
) {
4748 rc
= mwl8k_cmd_tx_power(hw
, conf
, conf
->power_level
);
4753 rc
= mwl8k_cmd_rf_antenna(hw
, MWL8K_RF_ANTENNA_RX
, 0x3);
4755 wiphy_warn(hw
->wiphy
, "failed to set # of RX antennas");
4756 rc
= mwl8k_cmd_rf_antenna(hw
, MWL8K_RF_ANTENNA_TX
, 0x7);
4758 wiphy_warn(hw
->wiphy
, "failed to set # of TX antennas");
4761 rc
= mwl8k_cmd_rf_tx_power(hw
, conf
->power_level
);
4764 rc
= mwl8k_cmd_mimo_config(hw
, 0x7, 0x7);
4768 mwl8k_fw_unlock(hw
);
4774 mwl8k_bss_info_changed_sta(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4775 struct ieee80211_bss_conf
*info
, u32 changed
)
4777 struct mwl8k_priv
*priv
= hw
->priv
;
4778 u32 ap_legacy_rates
= 0;
4779 u8 ap_mcs_rates
[16];
4782 if (mwl8k_fw_lock(hw
))
4786 * No need to capture a beacon if we're no longer associated.
4788 if ((changed
& BSS_CHANGED_ASSOC
) && !vif
->bss_conf
.assoc
)
4789 priv
->capture_beacon
= false;
4792 * Get the AP's legacy and MCS rates.
4794 if (vif
->bss_conf
.assoc
) {
4795 struct ieee80211_sta
*ap
;
4799 ap
= ieee80211_find_sta(vif
, vif
->bss_conf
.bssid
);
4805 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
4806 ap_legacy_rates
= ap
->supp_rates
[IEEE80211_BAND_2GHZ
];
4809 ap
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
4811 memcpy(ap_mcs_rates
, ap
->ht_cap
.mcs
.rx_mask
, 16);
4816 if ((changed
& BSS_CHANGED_ASSOC
) && vif
->bss_conf
.assoc
) {
4817 rc
= mwl8k_cmd_set_rate(hw
, vif
, ap_legacy_rates
, ap_mcs_rates
);
4821 rc
= mwl8k_cmd_use_fixed_rate_sta(hw
);
4826 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4827 rc
= mwl8k_set_radio_preamble(hw
,
4828 vif
->bss_conf
.use_short_preamble
);
4833 if (changed
& BSS_CHANGED_ERP_SLOT
) {
4834 rc
= mwl8k_cmd_set_slot(hw
, vif
->bss_conf
.use_short_slot
);
4839 if (vif
->bss_conf
.assoc
&&
4840 (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_ERP_CTS_PROT
|
4842 rc
= mwl8k_cmd_set_aid(hw
, vif
, ap_legacy_rates
);
4847 if (vif
->bss_conf
.assoc
&&
4848 (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_BEACON_INT
))) {
4850 * Finalize the join. Tell rx handler to process
4851 * next beacon from our BSSID.
4853 memcpy(priv
->capture_bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
4854 priv
->capture_beacon
= true;
4858 mwl8k_fw_unlock(hw
);
4862 mwl8k_bss_info_changed_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4863 struct ieee80211_bss_conf
*info
, u32 changed
)
4867 if (mwl8k_fw_lock(hw
))
4870 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4871 rc
= mwl8k_set_radio_preamble(hw
,
4872 vif
->bss_conf
.use_short_preamble
);
4877 if (changed
& BSS_CHANGED_BASIC_RATES
) {
4882 * Use lowest supported basic rate for multicasts
4883 * and management frames (such as probe responses --
4884 * beacons will always go out at 1 Mb/s).
4886 idx
= ffs(vif
->bss_conf
.basic_rates
);
4890 if (hw
->conf
.channel
->band
== IEEE80211_BAND_2GHZ
)
4891 rate
= mwl8k_rates_24
[idx
].hw_value
;
4893 rate
= mwl8k_rates_50
[idx
].hw_value
;
4895 mwl8k_cmd_use_fixed_rate_ap(hw
, rate
, rate
);
4898 if (changed
& (BSS_CHANGED_BEACON_INT
| BSS_CHANGED_BEACON
)) {
4899 struct sk_buff
*skb
;
4901 skb
= ieee80211_beacon_get(hw
, vif
);
4903 mwl8k_cmd_set_beacon(hw
, vif
, skb
->data
, skb
->len
);
4908 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
4909 mwl8k_cmd_bss_start(hw
, vif
, info
->enable_beacon
);
4912 mwl8k_fw_unlock(hw
);
4916 mwl8k_bss_info_changed(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4917 struct ieee80211_bss_conf
*info
, u32 changed
)
4919 struct mwl8k_priv
*priv
= hw
->priv
;
4922 mwl8k_bss_info_changed_sta(hw
, vif
, info
, changed
);
4924 mwl8k_bss_info_changed_ap(hw
, vif
, info
, changed
);
4927 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
4928 struct netdev_hw_addr_list
*mc_list
)
4930 struct mwl8k_cmd_pkt
*cmd
;
4933 * Synthesize and return a command packet that programs the
4934 * hardware multicast address filter. At this point we don't
4935 * know whether FIF_ALLMULTI is being requested, but if it is,
4936 * we'll end up throwing this packet away and creating a new
4937 * one in mwl8k_configure_filter().
4939 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 0, mc_list
);
4941 return (unsigned long)cmd
;
4945 mwl8k_configure_filter_sniffer(struct ieee80211_hw
*hw
,
4946 unsigned int changed_flags
,
4947 unsigned int *total_flags
)
4949 struct mwl8k_priv
*priv
= hw
->priv
;
4952 * Hardware sniffer mode is mutually exclusive with STA
4953 * operation, so refuse to enable sniffer mode if a STA
4954 * interface is active.
4956 if (!list_empty(&priv
->vif_list
)) {
4957 if (net_ratelimit())
4958 wiphy_info(hw
->wiphy
,
4959 "not enabling sniffer mode because STA interface is active\n");
4963 if (!priv
->sniffer_enabled
) {
4964 if (mwl8k_cmd_enable_sniffer(hw
, 1))
4966 priv
->sniffer_enabled
= true;
4969 *total_flags
&= FIF_PROMISC_IN_BSS
| FIF_ALLMULTI
|
4970 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
|
4976 static struct mwl8k_vif
*mwl8k_first_vif(struct mwl8k_priv
*priv
)
4978 if (!list_empty(&priv
->vif_list
))
4979 return list_entry(priv
->vif_list
.next
, struct mwl8k_vif
, list
);
4984 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
4985 unsigned int changed_flags
,
4986 unsigned int *total_flags
,
4989 struct mwl8k_priv
*priv
= hw
->priv
;
4990 struct mwl8k_cmd_pkt
*cmd
= (void *)(unsigned long)multicast
;
4993 * AP firmware doesn't allow fine-grained control over
4994 * the receive filter.
4997 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
5003 * Enable hardware sniffer mode if FIF_CONTROL or
5004 * FIF_OTHER_BSS is requested.
5006 if (*total_flags
& (FIF_CONTROL
| FIF_OTHER_BSS
) &&
5007 mwl8k_configure_filter_sniffer(hw
, changed_flags
, total_flags
)) {
5012 /* Clear unsupported feature flags */
5013 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
5015 if (mwl8k_fw_lock(hw
)) {
5020 if (priv
->sniffer_enabled
) {
5021 mwl8k_cmd_enable_sniffer(hw
, 0);
5022 priv
->sniffer_enabled
= false;
5025 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
5026 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
) {
5028 * Disable the BSS filter.
5030 mwl8k_cmd_set_pre_scan(hw
);
5032 struct mwl8k_vif
*mwl8k_vif
;
5036 * Enable the BSS filter.
5038 * If there is an active STA interface, use that
5039 * interface's BSSID, otherwise use a dummy one
5040 * (where the OUI part needs to be nonzero for
5041 * the BSSID to be accepted by POST_SCAN).
5043 mwl8k_vif
= mwl8k_first_vif(priv
);
5044 if (mwl8k_vif
!= NULL
)
5045 bssid
= mwl8k_vif
->vif
->bss_conf
.bssid
;
5047 bssid
= "\x01\x00\x00\x00\x00\x00";
5049 mwl8k_cmd_set_post_scan(hw
, bssid
);
5054 * If FIF_ALLMULTI is being requested, throw away the command
5055 * packet that ->prepare_multicast() built and replace it with
5056 * a command packet that enables reception of all multicast
5059 if (*total_flags
& FIF_ALLMULTI
) {
5061 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 1, NULL
);
5065 mwl8k_post_cmd(hw
, cmd
);
5069 mwl8k_fw_unlock(hw
);
5072 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
5074 return mwl8k_cmd_set_rts_threshold(hw
, value
);
5077 static int mwl8k_sta_remove(struct ieee80211_hw
*hw
,
5078 struct ieee80211_vif
*vif
,
5079 struct ieee80211_sta
*sta
)
5081 struct mwl8k_priv
*priv
= hw
->priv
;
5084 return mwl8k_cmd_set_new_stn_del(hw
, vif
, sta
->addr
);
5086 return mwl8k_cmd_update_stadb_del(hw
, vif
, sta
->addr
);
5089 static int mwl8k_sta_add(struct ieee80211_hw
*hw
,
5090 struct ieee80211_vif
*vif
,
5091 struct ieee80211_sta
*sta
)
5093 struct mwl8k_priv
*priv
= hw
->priv
;
5096 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
5097 struct ieee80211_key_conf
*key
;
5100 ret
= mwl8k_cmd_update_stadb_add(hw
, vif
, sta
);
5102 MWL8K_STA(sta
)->peer_id
= ret
;
5103 if (sta
->ht_cap
.ht_supported
)
5104 MWL8K_STA(sta
)->is_ampdu_allowed
= true;
5109 ret
= mwl8k_cmd_set_new_stn_add(hw
, vif
, sta
);
5112 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
5113 key
= IEEE80211_KEY_CONF(mwl8k_vif
->wep_key_conf
[i
].key
);
5114 if (mwl8k_vif
->wep_key_conf
[i
].enabled
)
5115 mwl8k_set_key(hw
, SET_KEY
, vif
, sta
, key
);
5120 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
,
5121 struct ieee80211_vif
*vif
, u16 queue
,
5122 const struct ieee80211_tx_queue_params
*params
)
5124 struct mwl8k_priv
*priv
= hw
->priv
;
5127 rc
= mwl8k_fw_lock(hw
);
5129 BUG_ON(queue
> MWL8K_TX_WMM_QUEUES
- 1);
5130 memcpy(&priv
->wmm_params
[queue
], params
, sizeof(*params
));
5132 if (!priv
->wmm_enabled
)
5133 rc
= mwl8k_cmd_set_wmm_mode(hw
, 1);
5136 int q
= MWL8K_TX_WMM_QUEUES
- 1 - queue
;
5137 rc
= mwl8k_cmd_set_edca_params(hw
, q
,
5144 mwl8k_fw_unlock(hw
);
5150 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
5151 struct ieee80211_low_level_stats
*stats
)
5153 return mwl8k_cmd_get_stat(hw
, stats
);
5156 static int mwl8k_get_survey(struct ieee80211_hw
*hw
, int idx
,
5157 struct survey_info
*survey
)
5159 struct mwl8k_priv
*priv
= hw
->priv
;
5160 struct ieee80211_conf
*conf
= &hw
->conf
;
5165 survey
->channel
= conf
->channel
;
5166 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
5167 survey
->noise
= priv
->noise
;
5172 #define MAX_AMPDU_ATTEMPTS 5
5175 mwl8k_ampdu_action(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
5176 enum ieee80211_ampdu_mlme_action action
,
5177 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
5182 struct mwl8k_priv
*priv
= hw
->priv
;
5183 struct mwl8k_ampdu_stream
*stream
;
5184 u8
*addr
= sta
->addr
, idx
;
5185 struct mwl8k_sta
*sta_info
= MWL8K_STA(sta
);
5187 if (!(hw
->flags
& IEEE80211_HW_AMPDU_AGGREGATION
))
5190 spin_lock(&priv
->stream_lock
);
5191 stream
= mwl8k_lookup_stream(hw
, addr
, tid
);
5194 case IEEE80211_AMPDU_RX_START
:
5195 case IEEE80211_AMPDU_RX_STOP
:
5197 case IEEE80211_AMPDU_TX_START
:
5198 /* By the time we get here the hw queues may contain outgoing
5199 * packets for this RA/TID that are not part of this BA
5200 * session. The hw will assign sequence numbers to these
5201 * packets as they go out. So if we query the hw for its next
5202 * sequence number and use that for the SSN here, it may end up
5203 * being wrong, which will lead to sequence number mismatch at
5204 * the recipient. To avoid this, we reset the sequence number
5205 * to O for the first MPDU in this BA stream.
5208 if (stream
== NULL
) {
5209 /* This means that somebody outside this driver called
5210 * ieee80211_start_tx_ba_session. This is unexpected
5211 * because we do our own rate control. Just warn and
5214 wiphy_warn(hw
->wiphy
, "Unexpected call to %s. "
5215 "Proceeding anyway.\n", __func__
);
5216 stream
= mwl8k_add_stream(hw
, sta
, tid
);
5218 if (stream
== NULL
) {
5219 wiphy_debug(hw
->wiphy
, "no free AMPDU streams\n");
5223 stream
->state
= AMPDU_STREAM_IN_PROGRESS
;
5225 /* Release the lock before we do the time consuming stuff */
5226 spin_unlock(&priv
->stream_lock
);
5227 for (i
= 0; i
< MAX_AMPDU_ATTEMPTS
; i
++) {
5229 /* Check if link is still valid */
5230 if (!sta_info
->is_ampdu_allowed
) {
5231 spin_lock(&priv
->stream_lock
);
5232 mwl8k_remove_stream(hw
, stream
);
5233 spin_unlock(&priv
->stream_lock
);
5237 rc
= mwl8k_check_ba(hw
, stream
, vif
);
5239 /* If HW restart is in progress mwl8k_post_cmd will
5240 * return -EBUSY. Avoid retrying mwl8k_check_ba in
5243 if (!rc
|| rc
== -EBUSY
)
5246 * HW queues take time to be flushed, give them
5252 spin_lock(&priv
->stream_lock
);
5254 wiphy_err(hw
->wiphy
, "Stream for tid %d busy after %d"
5255 " attempts\n", tid
, MAX_AMPDU_ATTEMPTS
);
5256 mwl8k_remove_stream(hw
, stream
);
5260 ieee80211_start_tx_ba_cb_irqsafe(vif
, addr
, tid
);
5262 case IEEE80211_AMPDU_TX_STOP_CONT
:
5263 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
5264 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
5266 if (stream
->state
== AMPDU_STREAM_ACTIVE
) {
5268 spin_unlock(&priv
->stream_lock
);
5269 mwl8k_destroy_ba(hw
, idx
);
5270 spin_lock(&priv
->stream_lock
);
5272 mwl8k_remove_stream(hw
, stream
);
5274 ieee80211_stop_tx_ba_cb_irqsafe(vif
, addr
, tid
);
5276 case IEEE80211_AMPDU_TX_OPERATIONAL
:
5277 BUG_ON(stream
== NULL
);
5278 BUG_ON(stream
->state
!= AMPDU_STREAM_IN_PROGRESS
);
5279 spin_unlock(&priv
->stream_lock
);
5280 rc
= mwl8k_create_ba(hw
, stream
, buf_size
, vif
);
5281 spin_lock(&priv
->stream_lock
);
5283 stream
->state
= AMPDU_STREAM_ACTIVE
;
5286 spin_unlock(&priv
->stream_lock
);
5287 mwl8k_destroy_ba(hw
, idx
);
5288 spin_lock(&priv
->stream_lock
);
5289 wiphy_debug(hw
->wiphy
,
5290 "Failed adding stream for sta %pM tid %d\n",
5292 mwl8k_remove_stream(hw
, stream
);
5300 spin_unlock(&priv
->stream_lock
);
5304 static const struct ieee80211_ops mwl8k_ops
= {
5306 .start
= mwl8k_start
,
5308 .add_interface
= mwl8k_add_interface
,
5309 .remove_interface
= mwl8k_remove_interface
,
5310 .config
= mwl8k_config
,
5311 .bss_info_changed
= mwl8k_bss_info_changed
,
5312 .prepare_multicast
= mwl8k_prepare_multicast
,
5313 .configure_filter
= mwl8k_configure_filter
,
5314 .set_key
= mwl8k_set_key
,
5315 .set_rts_threshold
= mwl8k_set_rts_threshold
,
5316 .sta_add
= mwl8k_sta_add
,
5317 .sta_remove
= mwl8k_sta_remove
,
5318 .conf_tx
= mwl8k_conf_tx
,
5319 .get_stats
= mwl8k_get_stats
,
5320 .get_survey
= mwl8k_get_survey
,
5321 .ampdu_action
= mwl8k_ampdu_action
,
5324 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
5326 struct mwl8k_priv
*priv
=
5327 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
5328 struct sk_buff
*skb
= priv
->beacon_skb
;
5329 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
5330 int len
= skb
->len
- offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
5331 const u8
*tim
= cfg80211_find_ie(WLAN_EID_TIM
,
5332 mgmt
->u
.beacon
.variable
, len
);
5333 int dtim_period
= 1;
5335 if (tim
&& tim
[1] >= 2)
5336 dtim_period
= tim
[3];
5338 mwl8k_cmd_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim_period
);
5341 priv
->beacon_skb
= NULL
;
5350 #define MWL8K_8366_AP_FW_API 3
5351 #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5352 #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5354 static struct mwl8k_device_info mwl8k_info_tbl
[] = {
5356 .part_name
= "88w8363",
5357 .helper_image
= "mwl8k/helper_8363.fw",
5358 .fw_image_sta
= "mwl8k/fmimage_8363.fw",
5361 .part_name
= "88w8687",
5362 .helper_image
= "mwl8k/helper_8687.fw",
5363 .fw_image_sta
= "mwl8k/fmimage_8687.fw",
5366 .part_name
= "88w8366",
5367 .helper_image
= "mwl8k/helper_8366.fw",
5368 .fw_image_sta
= "mwl8k/fmimage_8366.fw",
5369 .fw_image_ap
= MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API
),
5370 .fw_api_ap
= MWL8K_8366_AP_FW_API
,
5371 .ap_rxd_ops
= &rxd_8366_ap_ops
,
5375 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5376 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5377 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5378 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5379 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5380 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
5381 MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API
));
5383 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table
) = {
5384 { PCI_VDEVICE(MARVELL
, 0x2a0a), .driver_data
= MWL8363
, },
5385 { PCI_VDEVICE(MARVELL
, 0x2a0c), .driver_data
= MWL8363
, },
5386 { PCI_VDEVICE(MARVELL
, 0x2a24), .driver_data
= MWL8363
, },
5387 { PCI_VDEVICE(MARVELL
, 0x2a2b), .driver_data
= MWL8687
, },
5388 { PCI_VDEVICE(MARVELL
, 0x2a30), .driver_data
= MWL8687
, },
5389 { PCI_VDEVICE(MARVELL
, 0x2a40), .driver_data
= MWL8366
, },
5390 { PCI_VDEVICE(MARVELL
, 0x2a43), .driver_data
= MWL8366
, },
5393 MODULE_DEVICE_TABLE(pci
, mwl8k_pci_id_table
);
5395 static int mwl8k_request_alt_fw(struct mwl8k_priv
*priv
)
5398 printk(KERN_ERR
"%s: Error requesting preferred fw %s.\n"
5399 "Trying alternative firmware %s\n", pci_name(priv
->pdev
),
5400 priv
->fw_pref
, priv
->fw_alt
);
5401 rc
= mwl8k_request_fw(priv
, priv
->fw_alt
, &priv
->fw_ucode
, true);
5403 printk(KERN_ERR
"%s: Error requesting alt fw %s\n",
5404 pci_name(priv
->pdev
), priv
->fw_alt
);
5410 static int mwl8k_firmware_load_success(struct mwl8k_priv
*priv
);
5411 static void mwl8k_fw_state_machine(const struct firmware
*fw
, void *context
)
5413 struct mwl8k_priv
*priv
= context
;
5414 struct mwl8k_device_info
*di
= priv
->device_info
;
5417 switch (priv
->fw_state
) {
5420 printk(KERN_ERR
"%s: Error requesting helper fw %s\n",
5421 pci_name(priv
->pdev
), di
->helper_image
);
5424 priv
->fw_helper
= fw
;
5425 rc
= mwl8k_request_fw(priv
, priv
->fw_pref
, &priv
->fw_ucode
,
5427 if (rc
&& priv
->fw_alt
) {
5428 rc
= mwl8k_request_alt_fw(priv
);
5431 priv
->fw_state
= FW_STATE_LOADING_ALT
;
5435 priv
->fw_state
= FW_STATE_LOADING_PREF
;
5438 case FW_STATE_LOADING_PREF
:
5441 rc
= mwl8k_request_alt_fw(priv
);
5444 priv
->fw_state
= FW_STATE_LOADING_ALT
;
5448 priv
->fw_ucode
= fw
;
5449 rc
= mwl8k_firmware_load_success(priv
);
5453 complete(&priv
->firmware_loading_complete
);
5457 case FW_STATE_LOADING_ALT
:
5459 printk(KERN_ERR
"%s: Error requesting alt fw %s\n",
5460 pci_name(priv
->pdev
), di
->helper_image
);
5463 priv
->fw_ucode
= fw
;
5464 rc
= mwl8k_firmware_load_success(priv
);
5468 complete(&priv
->firmware_loading_complete
);
5472 printk(KERN_ERR
"%s: Unexpected firmware loading state: %d\n",
5473 MWL8K_NAME
, priv
->fw_state
);
5480 priv
->fw_state
= FW_STATE_ERROR
;
5481 complete(&priv
->firmware_loading_complete
);
5482 device_release_driver(&priv
->pdev
->dev
);
5483 mwl8k_release_firmware(priv
);
5486 #define MAX_RESTART_ATTEMPTS 1
5487 static int mwl8k_init_firmware(struct ieee80211_hw
*hw
, char *fw_image
,
5490 struct mwl8k_priv
*priv
= hw
->priv
;
5492 int count
= MAX_RESTART_ATTEMPTS
;
5495 /* Reset firmware and hardware */
5496 mwl8k_hw_reset(priv
);
5498 /* Ask userland hotplug daemon for the device firmware */
5499 rc
= mwl8k_request_firmware(priv
, fw_image
, nowait
);
5501 wiphy_err(hw
->wiphy
, "Firmware files not found\n");
5508 /* Load firmware into hardware */
5509 rc
= mwl8k_load_firmware(hw
);
5511 wiphy_err(hw
->wiphy
, "Cannot start firmware\n");
5513 /* Reclaim memory once firmware is successfully loaded */
5514 mwl8k_release_firmware(priv
);
5517 /* FW did not start successfully;
5518 * lets try one more time
5521 wiphy_err(hw
->wiphy
, "Trying to reload the firmware again\n");
5529 static int mwl8k_init_txqs(struct ieee80211_hw
*hw
)
5531 struct mwl8k_priv
*priv
= hw
->priv
;
5535 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++) {
5536 rc
= mwl8k_txq_init(hw
, i
);
5540 iowrite32(priv
->txq
[i
].txd_dma
,
5541 priv
->sram
+ priv
->txq_offset
[i
]);
5546 /* initialize hw after successfully loading a firmware image */
5547 static int mwl8k_probe_hw(struct ieee80211_hw
*hw
)
5549 struct mwl8k_priv
*priv
= hw
->priv
;
5554 priv
->rxd_ops
= priv
->device_info
->ap_rxd_ops
;
5555 if (priv
->rxd_ops
== NULL
) {
5556 wiphy_err(hw
->wiphy
,
5557 "Driver does not have AP firmware image support for this hardware\n");
5559 goto err_stop_firmware
;
5562 priv
->rxd_ops
= &rxd_sta_ops
;
5565 priv
->sniffer_enabled
= false;
5566 priv
->wmm_enabled
= false;
5567 priv
->pending_tx_pkts
= 0;
5568 atomic_set(&priv
->watchdog_event_pending
, 0);
5570 rc
= mwl8k_rxq_init(hw
, 0);
5572 goto err_stop_firmware
;
5573 rxq_refill(hw
, 0, INT_MAX
);
5575 /* For the sta firmware, we need to know the dma addresses of tx queues
5576 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5577 * prior to issuing this command. But for the AP case, we learn the
5578 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5579 * case we must initialize the tx queues after.
5581 priv
->num_ampdu_queues
= 0;
5583 rc
= mwl8k_init_txqs(hw
);
5585 goto err_free_queues
;
5588 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
5589 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
5590 iowrite32(MWL8K_A2H_INT_TX_DONE
|MWL8K_A2H_INT_RX_READY
|
5591 MWL8K_A2H_INT_BA_WATCHDOG
,
5592 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
5593 iowrite32(MWL8K_A2H_INT_OPC_DONE
,
5594 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
5596 rc
= request_irq(priv
->pdev
->irq
, mwl8k_interrupt
,
5597 IRQF_SHARED
, MWL8K_NAME
, hw
);
5599 wiphy_err(hw
->wiphy
, "failed to register IRQ handler\n");
5600 goto err_free_queues
;
5604 * When hw restart is requested,
5605 * mac80211 will take care of clearing
5606 * the ampdu streams, so do not clear
5607 * the ampdu state here
5609 if (!priv
->hw_restart_in_progress
)
5610 memset(priv
->ampdu
, 0, sizeof(priv
->ampdu
));
5613 * Temporarily enable interrupts. Initial firmware host
5614 * commands use interrupts and avoid polling. Disable
5615 * interrupts when done.
5617 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
5619 /* Get config data, mac addrs etc */
5621 rc
= mwl8k_cmd_get_hw_spec_ap(hw
);
5623 rc
= mwl8k_init_txqs(hw
);
5625 rc
= mwl8k_cmd_set_hw_spec(hw
);
5627 rc
= mwl8k_cmd_get_hw_spec_sta(hw
);
5630 wiphy_err(hw
->wiphy
, "Cannot initialise firmware\n");
5634 /* Turn radio off */
5635 rc
= mwl8k_cmd_radio_disable(hw
);
5637 wiphy_err(hw
->wiphy
, "Cannot disable\n");
5641 /* Clear MAC address */
5642 rc
= mwl8k_cmd_set_mac_addr(hw
, NULL
, "\x00\x00\x00\x00\x00\x00");
5644 wiphy_err(hw
->wiphy
, "Cannot clear MAC address\n");
5648 /* Disable interrupts */
5649 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
5650 free_irq(priv
->pdev
->irq
, hw
);
5652 wiphy_info(hw
->wiphy
, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5653 priv
->device_info
->part_name
,
5654 priv
->hw_rev
, hw
->wiphy
->perm_addr
,
5655 priv
->ap_fw
? "AP" : "STA",
5656 (priv
->fw_rev
>> 24) & 0xff, (priv
->fw_rev
>> 16) & 0xff,
5657 (priv
->fw_rev
>> 8) & 0xff, priv
->fw_rev
& 0xff);
5662 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
5663 free_irq(priv
->pdev
->irq
, hw
);
5666 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
5667 mwl8k_txq_deinit(hw
, i
);
5668 mwl8k_rxq_deinit(hw
, 0);
5671 mwl8k_hw_reset(priv
);
5677 * invoke mwl8k_reload_firmware to change the firmware image after the device
5678 * has already been registered
5680 static int mwl8k_reload_firmware(struct ieee80211_hw
*hw
, char *fw_image
)
5683 struct mwl8k_priv
*priv
= hw
->priv
;
5684 struct mwl8k_vif
*vif
, *tmp_vif
;
5687 mwl8k_rxq_deinit(hw
, 0);
5690 * All the existing interfaces are re-added by the ieee80211_reconfig;
5691 * which means driver should remove existing interfaces before calling
5692 * ieee80211_restart_hw
5694 if (priv
->hw_restart_in_progress
)
5695 list_for_each_entry_safe(vif
, tmp_vif
, &priv
->vif_list
, list
)
5696 mwl8k_remove_vif(priv
, vif
);
5698 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
5699 mwl8k_txq_deinit(hw
, i
);
5701 rc
= mwl8k_init_firmware(hw
, fw_image
, false);
5705 rc
= mwl8k_probe_hw(hw
);
5709 if (priv
->hw_restart_in_progress
)
5712 rc
= mwl8k_start(hw
);
5716 rc
= mwl8k_config(hw
, ~0);
5720 for (i
= 0; i
< MWL8K_TX_WMM_QUEUES
; i
++) {
5721 rc
= mwl8k_conf_tx(hw
, NULL
, i
, &priv
->wmm_params
[i
]);
5729 printk(KERN_WARNING
"mwl8k: Failed to reload firmware image.\n");
5733 static const struct ieee80211_iface_limit ap_if_limits
[] = {
5734 { .max
= 8, .types
= BIT(NL80211_IFTYPE_AP
) },
5737 static const struct ieee80211_iface_combination ap_if_comb
= {
5738 .limits
= ap_if_limits
,
5739 .n_limits
= ARRAY_SIZE(ap_if_limits
),
5740 .max_interfaces
= 8,
5741 .num_different_channels
= 1,
5745 static int mwl8k_firmware_load_success(struct mwl8k_priv
*priv
)
5747 struct ieee80211_hw
*hw
= priv
->hw
;
5750 rc
= mwl8k_load_firmware(hw
);
5751 mwl8k_release_firmware(priv
);
5753 wiphy_err(hw
->wiphy
, "Cannot start firmware\n");
5758 * Extra headroom is the size of the required DMA header
5759 * minus the size of the smallest 802.11 frame (CTS frame).
5761 hw
->extra_tx_headroom
=
5762 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
5764 hw
->extra_tx_headroom
-= priv
->ap_fw
? REDUCED_TX_HEADROOM
: 0;
5766 hw
->channel_change_time
= 10;
5768 hw
->queues
= MWL8K_TX_WMM_QUEUES
;
5770 /* Set rssi values to dBm */
5771 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
| IEEE80211_HW_HAS_RATE_CONTROL
;
5774 * Ask mac80211 to not to trigger PS mode
5775 * based on PM bit of incoming frames.
5778 hw
->flags
|= IEEE80211_HW_AP_LINK_PS
;
5780 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
5781 hw
->sta_data_size
= sizeof(struct mwl8k_sta
);
5783 priv
->macids_used
= 0;
5784 INIT_LIST_HEAD(&priv
->vif_list
);
5786 /* Set default radio state and preamble */
5787 priv
->radio_on
= false;
5788 priv
->radio_short_preamble
= false;
5790 /* Finalize join worker */
5791 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
5792 /* Handle watchdog ba events */
5793 INIT_WORK(&priv
->watchdog_ba_handle
, mwl8k_watchdog_ba_events
);
5794 /* To reload the firmware if it crashes */
5795 INIT_WORK(&priv
->fw_reload
, mwl8k_hw_restart_work
);
5797 /* TX reclaim and RX tasklets. */
5798 tasklet_init(&priv
->poll_tx_task
, mwl8k_tx_poll
, (unsigned long)hw
);
5799 tasklet_disable(&priv
->poll_tx_task
);
5800 tasklet_init(&priv
->poll_rx_task
, mwl8k_rx_poll
, (unsigned long)hw
);
5801 tasklet_disable(&priv
->poll_rx_task
);
5803 /* Power management cookie */
5804 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
5805 if (priv
->cookie
== NULL
)
5808 mutex_init(&priv
->fw_mutex
);
5809 priv
->fw_mutex_owner
= NULL
;
5810 priv
->fw_mutex_depth
= 0;
5811 priv
->hostcmd_wait
= NULL
;
5813 spin_lock_init(&priv
->tx_lock
);
5815 spin_lock_init(&priv
->stream_lock
);
5817 priv
->tx_wait
= NULL
;
5819 rc
= mwl8k_probe_hw(hw
);
5821 goto err_free_cookie
;
5823 hw
->wiphy
->interface_modes
= 0;
5825 if (priv
->ap_macids_supported
|| priv
->device_info
->fw_image_ap
) {
5826 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_AP
);
5827 hw
->wiphy
->iface_combinations
= &ap_if_comb
;
5828 hw
->wiphy
->n_iface_combinations
= 1;
5831 if (priv
->sta_macids_supported
|| priv
->device_info
->fw_image_sta
)
5832 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_STATION
);
5834 rc
= ieee80211_register_hw(hw
);
5836 wiphy_err(hw
->wiphy
, "Cannot register device\n");
5837 goto err_unprobe_hw
;
5843 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
5844 mwl8k_txq_deinit(hw
, i
);
5845 mwl8k_rxq_deinit(hw
, 0);
5848 if (priv
->cookie
!= NULL
)
5849 pci_free_consistent(priv
->pdev
, 4,
5850 priv
->cookie
, priv
->cookie_dma
);
5854 static int mwl8k_probe(struct pci_dev
*pdev
,
5855 const struct pci_device_id
*id
)
5857 static int printed_version
;
5858 struct ieee80211_hw
*hw
;
5859 struct mwl8k_priv
*priv
;
5860 struct mwl8k_device_info
*di
;
5863 if (!printed_version
) {
5864 printk(KERN_INFO
"%s version %s\n", MWL8K_DESC
, MWL8K_VERSION
);
5865 printed_version
= 1;
5869 rc
= pci_enable_device(pdev
);
5871 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
5876 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
5878 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
5880 goto err_disable_device
;
5883 pci_set_master(pdev
);
5886 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
5888 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
5893 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
5894 pci_set_drvdata(pdev
, hw
);
5899 priv
->device_info
= &mwl8k_info_tbl
[id
->driver_data
];
5902 priv
->sram
= pci_iomap(pdev
, 0, 0x10000);
5903 if (priv
->sram
== NULL
) {
5904 wiphy_err(hw
->wiphy
, "Cannot map device SRAM\n");
5910 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
5911 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
5913 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
5914 if (priv
->regs
== NULL
) {
5915 priv
->regs
= pci_iomap(pdev
, 2, 0x10000);
5916 if (priv
->regs
== NULL
) {
5917 wiphy_err(hw
->wiphy
, "Cannot map device registers\n");
5924 * Choose the initial fw image depending on user input. If a second
5925 * image is available, make it the alternative image that will be
5926 * loaded if the first one fails.
5928 init_completion(&priv
->firmware_loading_complete
);
5929 di
= priv
->device_info
;
5930 if (ap_mode_default
&& di
->fw_image_ap
) {
5931 priv
->fw_pref
= di
->fw_image_ap
;
5932 priv
->fw_alt
= di
->fw_image_sta
;
5933 } else if (!ap_mode_default
&& di
->fw_image_sta
) {
5934 priv
->fw_pref
= di
->fw_image_sta
;
5935 priv
->fw_alt
= di
->fw_image_ap
;
5936 } else if (ap_mode_default
&& !di
->fw_image_ap
&& di
->fw_image_sta
) {
5937 printk(KERN_WARNING
"AP fw is unavailable. Using STA fw.");
5938 priv
->fw_pref
= di
->fw_image_sta
;
5939 } else if (!ap_mode_default
&& !di
->fw_image_sta
&& di
->fw_image_ap
) {
5940 printk(KERN_WARNING
"STA fw is unavailable. Using AP fw.");
5941 priv
->fw_pref
= di
->fw_image_ap
;
5943 rc
= mwl8k_init_firmware(hw
, priv
->fw_pref
, true);
5945 goto err_stop_firmware
;
5947 priv
->hw_restart_in_progress
= false;
5952 mwl8k_hw_reset(priv
);
5955 if (priv
->regs
!= NULL
)
5956 pci_iounmap(pdev
, priv
->regs
);
5958 if (priv
->sram
!= NULL
)
5959 pci_iounmap(pdev
, priv
->sram
);
5961 pci_set_drvdata(pdev
, NULL
);
5962 ieee80211_free_hw(hw
);
5965 pci_release_regions(pdev
);
5968 pci_disable_device(pdev
);
5973 static void mwl8k_remove(struct pci_dev
*pdev
)
5975 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
5976 struct mwl8k_priv
*priv
;
5983 wait_for_completion(&priv
->firmware_loading_complete
);
5985 if (priv
->fw_state
== FW_STATE_ERROR
) {
5986 mwl8k_hw_reset(priv
);
5990 ieee80211_stop_queues(hw
);
5992 ieee80211_unregister_hw(hw
);
5994 /* Remove TX reclaim and RX tasklets. */
5995 tasklet_kill(&priv
->poll_tx_task
);
5996 tasklet_kill(&priv
->poll_rx_task
);
5999 mwl8k_hw_reset(priv
);
6001 /* Return all skbs to mac80211 */
6002 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
6003 mwl8k_txq_reclaim(hw
, i
, INT_MAX
, 1);
6005 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
6006 mwl8k_txq_deinit(hw
, i
);
6008 mwl8k_rxq_deinit(hw
, 0);
6010 pci_free_consistent(priv
->pdev
, 4, priv
->cookie
, priv
->cookie_dma
);
6013 pci_iounmap(pdev
, priv
->regs
);
6014 pci_iounmap(pdev
, priv
->sram
);
6015 pci_set_drvdata(pdev
, NULL
);
6016 ieee80211_free_hw(hw
);
6017 pci_release_regions(pdev
);
6018 pci_disable_device(pdev
);
6021 static struct pci_driver mwl8k_driver
= {
6023 .id_table
= mwl8k_pci_id_table
,
6024 .probe
= mwl8k_probe
,
6025 .remove
= mwl8k_remove
,
6028 module_pci_driver(mwl8k_driver
);
6030 MODULE_DESCRIPTION(MWL8K_DESC
);
6031 MODULE_VERSION(MWL8K_VERSION
);
6032 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
6033 MODULE_LICENSE("GPL");