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/interrupt.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/spinlock.h>
17 #include <linux/list.h>
18 #include <linux/pci.h>
19 #include <linux/delay.h>
20 #include <linux/completion.h>
21 #include <linux/etherdevice.h>
22 #include <linux/slab.h>
23 #include <net/mac80211.h>
24 #include <linux/moduleparam.h>
25 #include <linux/firmware.h>
26 #include <linux/workqueue.h>
28 #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
29 #define MWL8K_NAME KBUILD_MODNAME
30 #define MWL8K_VERSION "0.13"
32 /* Module parameters */
33 static bool ap_mode_default
;
34 module_param(ap_mode_default
, bool, 0);
35 MODULE_PARM_DESC(ap_mode_default
,
36 "Set to 1 to make ap mode the default instead of sta mode");
38 /* Register definitions */
39 #define MWL8K_HIU_GEN_PTR 0x00000c10
40 #define MWL8K_MODE_STA 0x0000005a
41 #define MWL8K_MODE_AP 0x000000a5
42 #define MWL8K_HIU_INT_CODE 0x00000c14
43 #define MWL8K_FWSTA_READY 0xf0f1f2f4
44 #define MWL8K_FWAP_READY 0xf1f2f4a5
45 #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
46 #define MWL8K_HIU_SCRATCH 0x00000c40
48 /* Host->device communications */
49 #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
50 #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
51 #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
52 #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
53 #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
54 #define MWL8K_H2A_INT_DUMMY (1 << 20)
55 #define MWL8K_H2A_INT_RESET (1 << 15)
56 #define MWL8K_H2A_INT_DOORBELL (1 << 1)
57 #define MWL8K_H2A_INT_PPA_READY (1 << 0)
59 /* Device->host communications */
60 #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
61 #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
62 #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
63 #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
64 #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
65 #define MWL8K_A2H_INT_DUMMY (1 << 20)
66 #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
67 #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
68 #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
69 #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
70 #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
71 #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
72 #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
73 #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
74 #define MWL8K_A2H_INT_RX_READY (1 << 1)
75 #define MWL8K_A2H_INT_TX_DONE (1 << 0)
77 /* HW micro second timer register
78 * located at offset 0xA600. This
79 * will be used to timestamp tx
83 #define MWL8K_HW_TIMER_REGISTER 0x0000a600
85 #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
86 MWL8K_A2H_INT_CHNL_SWITCHED | \
87 MWL8K_A2H_INT_QUEUE_EMPTY | \
88 MWL8K_A2H_INT_RADAR_DETECT | \
89 MWL8K_A2H_INT_RADIO_ON | \
90 MWL8K_A2H_INT_RADIO_OFF | \
91 MWL8K_A2H_INT_MAC_EVENT | \
92 MWL8K_A2H_INT_OPC_DONE | \
93 MWL8K_A2H_INT_RX_READY | \
94 MWL8K_A2H_INT_TX_DONE | \
95 MWL8K_A2H_INT_BA_WATCHDOG)
97 #define MWL8K_RX_QUEUES 1
98 #define MWL8K_TX_WMM_QUEUES 4
99 #define MWL8K_MAX_AMPDU_QUEUES 8
100 #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
101 #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
103 /* txpriorities are mapped with hw queues.
104 * Each hw queue has a txpriority.
106 #define TOTAL_HW_TX_QUEUES 8
108 /* Each HW queue can have one AMPDU stream.
109 * But, because one of the hw queue is reserved,
110 * maximum AMPDU queues that can be created are
111 * one short of total tx queues.
113 #define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1)
117 void (*rxd_init
)(void *rxd
, dma_addr_t next_dma_addr
);
118 void (*rxd_refill
)(void *rxd
, dma_addr_t addr
, int len
);
119 int (*rxd_process
)(void *rxd
, struct ieee80211_rx_status
*status
,
120 __le16
*qos
, s8
*noise
);
123 struct mwl8k_device_info
{
128 struct rxd_ops
*ap_rxd_ops
;
132 struct mwl8k_rx_queue
{
135 /* hw receives here */
138 /* refill descs here */
145 DEFINE_DMA_UNMAP_ADDR(dma
);
149 struct mwl8k_tx_queue
{
150 /* hw transmits here */
153 /* sw appends here */
157 struct mwl8k_tx_desc
*txd
;
159 struct sk_buff
**skb
;
165 AMPDU_STREAM_IN_PROGRESS
,
169 struct mwl8k_ampdu_stream
{
170 struct ieee80211_sta
*sta
;
177 struct ieee80211_hw
*hw
;
178 struct pci_dev
*pdev
;
181 struct mwl8k_device_info
*device_info
;
187 const struct firmware
*fw_helper
;
188 const struct firmware
*fw_ucode
;
190 /* hardware/firmware parameters */
192 struct rxd_ops
*rxd_ops
;
193 struct ieee80211_supported_band band_24
;
194 struct ieee80211_channel channels_24
[14];
195 struct ieee80211_rate rates_24
[13];
196 struct ieee80211_supported_band band_50
;
197 struct ieee80211_channel channels_50
[4];
198 struct ieee80211_rate rates_50
[8];
199 u32 ap_macids_supported
;
200 u32 sta_macids_supported
;
202 /* Ampdu stream information */
204 spinlock_t stream_lock
;
205 struct mwl8k_ampdu_stream ampdu
[MWL8K_MAX_AMPDU_QUEUES
];
206 struct work_struct watchdog_ba_handle
;
208 /* firmware access */
209 struct mutex fw_mutex
;
210 struct task_struct
*fw_mutex_owner
;
211 struct task_struct
*hw_restart_owner
;
213 struct completion
*hostcmd_wait
;
215 atomic_t watchdog_event_pending
;
217 /* lock held over TX and TX reap */
220 /* TX quiesce completion, protected by fw_mutex and tx_lock */
221 struct completion
*tx_wait
;
223 /* List of interfaces. */
225 struct list_head vif_list
;
227 /* power management status cookie from firmware */
229 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 */
288 struct completion firmware_loading_complete
;
290 /* bitmap of running BSSes */
294 #define MAX_WEP_KEY_LEN 13
295 #define NUM_WEP_KEYS 4
297 /* Per interface specific private data */
299 struct list_head list
;
300 struct ieee80211_vif
*vif
;
302 /* Firmware macid for this vif. */
305 /* Non AMPDU sequence number assigned by driver. */
311 u8 key
[sizeof(struct ieee80211_key_conf
) + MAX_WEP_KEY_LEN
];
312 } wep_key_conf
[NUM_WEP_KEYS
];
317 /* A flag to indicate is HW crypto is enabled for this bssid */
318 bool is_hw_crypto_enabled
;
320 #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
321 #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
323 struct tx_traffic_info
{
328 #define MWL8K_MAX_TID 8
330 /* Index into station database. Returned by UPDATE_STADB. */
333 struct tx_traffic_info tx_stats
[MWL8K_MAX_TID
];
335 #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
337 static const struct ieee80211_channel mwl8k_channels_24
[] = {
338 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2412, .hw_value
= 1, },
339 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2417, .hw_value
= 2, },
340 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2422, .hw_value
= 3, },
341 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2427, .hw_value
= 4, },
342 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2432, .hw_value
= 5, },
343 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2437, .hw_value
= 6, },
344 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2442, .hw_value
= 7, },
345 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2447, .hw_value
= 8, },
346 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2452, .hw_value
= 9, },
347 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2457, .hw_value
= 10, },
348 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2462, .hw_value
= 11, },
349 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2467, .hw_value
= 12, },
350 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2472, .hw_value
= 13, },
351 { .band
= IEEE80211_BAND_2GHZ
, .center_freq
= 2484, .hw_value
= 14, },
354 static const struct ieee80211_rate mwl8k_rates_24
[] = {
355 { .bitrate
= 10, .hw_value
= 2, },
356 { .bitrate
= 20, .hw_value
= 4, },
357 { .bitrate
= 55, .hw_value
= 11, },
358 { .bitrate
= 110, .hw_value
= 22, },
359 { .bitrate
= 220, .hw_value
= 44, },
360 { .bitrate
= 60, .hw_value
= 12, },
361 { .bitrate
= 90, .hw_value
= 18, },
362 { .bitrate
= 120, .hw_value
= 24, },
363 { .bitrate
= 180, .hw_value
= 36, },
364 { .bitrate
= 240, .hw_value
= 48, },
365 { .bitrate
= 360, .hw_value
= 72, },
366 { .bitrate
= 480, .hw_value
= 96, },
367 { .bitrate
= 540, .hw_value
= 108, },
370 static const struct ieee80211_channel mwl8k_channels_50
[] = {
371 { .band
= IEEE80211_BAND_5GHZ
, .center_freq
= 5180, .hw_value
= 36, },
372 { .band
= IEEE80211_BAND_5GHZ
, .center_freq
= 5200, .hw_value
= 40, },
373 { .band
= IEEE80211_BAND_5GHZ
, .center_freq
= 5220, .hw_value
= 44, },
374 { .band
= IEEE80211_BAND_5GHZ
, .center_freq
= 5240, .hw_value
= 48, },
377 static const struct ieee80211_rate mwl8k_rates_50
[] = {
378 { .bitrate
= 60, .hw_value
= 12, },
379 { .bitrate
= 90, .hw_value
= 18, },
380 { .bitrate
= 120, .hw_value
= 24, },
381 { .bitrate
= 180, .hw_value
= 36, },
382 { .bitrate
= 240, .hw_value
= 48, },
383 { .bitrate
= 360, .hw_value
= 72, },
384 { .bitrate
= 480, .hw_value
= 96, },
385 { .bitrate
= 540, .hw_value
= 108, },
388 /* Set or get info from Firmware */
389 #define MWL8K_CMD_GET 0x0000
390 #define MWL8K_CMD_SET 0x0001
391 #define MWL8K_CMD_SET_LIST 0x0002
393 /* Firmware command codes */
394 #define MWL8K_CMD_CODE_DNLD 0x0001
395 #define MWL8K_CMD_GET_HW_SPEC 0x0003
396 #define MWL8K_CMD_SET_HW_SPEC 0x0004
397 #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
398 #define MWL8K_CMD_GET_STAT 0x0014
399 #define MWL8K_CMD_RADIO_CONTROL 0x001c
400 #define MWL8K_CMD_RF_TX_POWER 0x001e
401 #define MWL8K_CMD_TX_POWER 0x001f
402 #define MWL8K_CMD_RF_ANTENNA 0x0020
403 #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
404 #define MWL8K_CMD_SET_PRE_SCAN 0x0107
405 #define MWL8K_CMD_SET_POST_SCAN 0x0108
406 #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
407 #define MWL8K_CMD_SET_AID 0x010d
408 #define MWL8K_CMD_SET_RATE 0x0110
409 #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
410 #define MWL8K_CMD_RTS_THRESHOLD 0x0113
411 #define MWL8K_CMD_SET_SLOT 0x0114
412 #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
413 #define MWL8K_CMD_SET_WMM_MODE 0x0123
414 #define MWL8K_CMD_MIMO_CONFIG 0x0125
415 #define MWL8K_CMD_USE_FIXED_RATE 0x0126
416 #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
417 #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
418 #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
419 #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
420 #define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
421 #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
422 #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
423 #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
424 #define MWL8K_CMD_UPDATE_STADB 0x1123
425 #define MWL8K_CMD_BASTREAM 0x1125
427 static const char *mwl8k_cmd_name(__le16 cmd
, char *buf
, int bufsize
)
429 u16 command
= le16_to_cpu(cmd
);
431 #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
432 snprintf(buf, bufsize, "%s", #x);\
435 switch (command
& ~0x8000) {
436 MWL8K_CMDNAME(CODE_DNLD
);
437 MWL8K_CMDNAME(GET_HW_SPEC
);
438 MWL8K_CMDNAME(SET_HW_SPEC
);
439 MWL8K_CMDNAME(MAC_MULTICAST_ADR
);
440 MWL8K_CMDNAME(GET_STAT
);
441 MWL8K_CMDNAME(RADIO_CONTROL
);
442 MWL8K_CMDNAME(RF_TX_POWER
);
443 MWL8K_CMDNAME(TX_POWER
);
444 MWL8K_CMDNAME(RF_ANTENNA
);
445 MWL8K_CMDNAME(SET_BEACON
);
446 MWL8K_CMDNAME(SET_PRE_SCAN
);
447 MWL8K_CMDNAME(SET_POST_SCAN
);
448 MWL8K_CMDNAME(SET_RF_CHANNEL
);
449 MWL8K_CMDNAME(SET_AID
);
450 MWL8K_CMDNAME(SET_RATE
);
451 MWL8K_CMDNAME(SET_FINALIZE_JOIN
);
452 MWL8K_CMDNAME(RTS_THRESHOLD
);
453 MWL8K_CMDNAME(SET_SLOT
);
454 MWL8K_CMDNAME(SET_EDCA_PARAMS
);
455 MWL8K_CMDNAME(SET_WMM_MODE
);
456 MWL8K_CMDNAME(MIMO_CONFIG
);
457 MWL8K_CMDNAME(USE_FIXED_RATE
);
458 MWL8K_CMDNAME(ENABLE_SNIFFER
);
459 MWL8K_CMDNAME(SET_MAC_ADDR
);
460 MWL8K_CMDNAME(SET_RATEADAPT_MODE
);
461 MWL8K_CMDNAME(BSS_START
);
462 MWL8K_CMDNAME(SET_NEW_STN
);
463 MWL8K_CMDNAME(UPDATE_ENCRYPTION
);
464 MWL8K_CMDNAME(UPDATE_STADB
);
465 MWL8K_CMDNAME(BASTREAM
);
466 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP
);
468 snprintf(buf
, bufsize
, "0x%x", cmd
);
475 /* Hardware and firmware reset */
476 static void mwl8k_hw_reset(struct mwl8k_priv
*priv
)
478 iowrite32(MWL8K_H2A_INT_RESET
,
479 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
480 iowrite32(MWL8K_H2A_INT_RESET
,
481 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
485 /* Release fw image */
486 static void mwl8k_release_fw(const struct firmware
**fw
)
490 release_firmware(*fw
);
494 static void mwl8k_release_firmware(struct mwl8k_priv
*priv
)
496 mwl8k_release_fw(&priv
->fw_ucode
);
497 mwl8k_release_fw(&priv
->fw_helper
);
500 /* states for asynchronous f/w loading */
501 static void mwl8k_fw_state_machine(const struct firmware
*fw
, void *context
);
504 FW_STATE_LOADING_PREF
,
505 FW_STATE_LOADING_ALT
,
509 /* Request fw image */
510 static int mwl8k_request_fw(struct mwl8k_priv
*priv
,
511 const char *fname
, const struct firmware
**fw
,
514 /* release current image */
516 mwl8k_release_fw(fw
);
519 return request_firmware_nowait(THIS_MODULE
, 1, fname
,
520 &priv
->pdev
->dev
, GFP_KERNEL
,
521 priv
, mwl8k_fw_state_machine
);
523 return request_firmware(fw
, fname
, &priv
->pdev
->dev
);
526 static int mwl8k_request_firmware(struct mwl8k_priv
*priv
, char *fw_image
,
529 struct mwl8k_device_info
*di
= priv
->device_info
;
532 if (di
->helper_image
!= NULL
) {
534 rc
= mwl8k_request_fw(priv
, di
->helper_image
,
535 &priv
->fw_helper
, true);
537 rc
= mwl8k_request_fw(priv
, di
->helper_image
,
538 &priv
->fw_helper
, false);
540 printk(KERN_ERR
"%s: Error requesting helper fw %s\n",
541 pci_name(priv
->pdev
), di
->helper_image
);
549 * if we get here, no helper image is needed. Skip the
550 * FW_STATE_INIT state.
552 priv
->fw_state
= FW_STATE_LOADING_PREF
;
553 rc
= mwl8k_request_fw(priv
, fw_image
,
557 rc
= mwl8k_request_fw(priv
, fw_image
,
558 &priv
->fw_ucode
, false);
560 printk(KERN_ERR
"%s: Error requesting firmware file %s\n",
561 pci_name(priv
->pdev
), fw_image
);
562 mwl8k_release_fw(&priv
->fw_helper
);
569 struct mwl8k_cmd_pkt
{
582 mwl8k_send_fw_load_cmd(struct mwl8k_priv
*priv
, void *data
, int length
)
584 void __iomem
*regs
= priv
->regs
;
588 dma_addr
= pci_map_single(priv
->pdev
, data
, length
, PCI_DMA_TODEVICE
);
589 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
592 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
593 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
594 iowrite32(MWL8K_H2A_INT_DOORBELL
,
595 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
596 iowrite32(MWL8K_H2A_INT_DUMMY
,
597 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
603 int_code
= ioread32(regs
+
604 MWL8K_HIU_H2A_INTERRUPT_STATUS
);
608 int_code
= ioread32(regs
+ MWL8K_HIU_INT_CODE
);
609 if (int_code
== MWL8K_INT_CODE_CMD_FINISHED
) {
610 iowrite32(0, regs
+ MWL8K_HIU_INT_CODE
);
618 pci_unmap_single(priv
->pdev
, dma_addr
, length
, PCI_DMA_TODEVICE
);
620 return loops
? 0 : -ETIMEDOUT
;
623 static int mwl8k_load_fw_image(struct mwl8k_priv
*priv
,
624 const u8
*data
, size_t length
)
626 struct mwl8k_cmd_pkt
*cmd
;
630 cmd
= kmalloc(sizeof(*cmd
) + 256, GFP_KERNEL
);
634 cmd
->code
= cpu_to_le16(MWL8K_CMD_CODE_DNLD
);
641 int block_size
= length
> 256 ? 256 : length
;
643 memcpy(cmd
->payload
, data
+ done
, block_size
);
644 cmd
->length
= cpu_to_le16(block_size
);
646 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
,
647 sizeof(*cmd
) + block_size
);
652 length
-= block_size
;
657 rc
= mwl8k_send_fw_load_cmd(priv
, cmd
, sizeof(*cmd
));
665 static int mwl8k_feed_fw_image(struct mwl8k_priv
*priv
,
666 const u8
*data
, size_t length
)
668 unsigned char *buffer
;
669 int may_continue
, rc
= 0;
670 u32 done
, prev_block_size
;
672 buffer
= kmalloc(1024, GFP_KERNEL
);
679 while (may_continue
> 0) {
682 block_size
= ioread32(priv
->regs
+ MWL8K_HIU_SCRATCH
);
683 if (block_size
& 1) {
687 done
+= prev_block_size
;
688 length
-= prev_block_size
;
691 if (block_size
> 1024 || block_size
> length
) {
701 if (block_size
== 0) {
708 prev_block_size
= block_size
;
709 memcpy(buffer
, data
+ done
, block_size
);
711 rc
= mwl8k_send_fw_load_cmd(priv
, buffer
, block_size
);
716 if (!rc
&& length
!= 0)
724 static int mwl8k_load_firmware(struct ieee80211_hw
*hw
)
726 struct mwl8k_priv
*priv
= hw
->priv
;
727 const struct firmware
*fw
= priv
->fw_ucode
;
731 if (!memcmp(fw
->data
, "\x01\x00\x00\x00", 4) && !priv
->is_8764
) {
732 const struct firmware
*helper
= priv
->fw_helper
;
734 if (helper
== NULL
) {
735 printk(KERN_ERR
"%s: helper image needed but none "
736 "given\n", pci_name(priv
->pdev
));
740 rc
= mwl8k_load_fw_image(priv
, helper
->data
, helper
->size
);
742 printk(KERN_ERR
"%s: unable to load firmware "
743 "helper image\n", pci_name(priv
->pdev
));
748 rc
= mwl8k_feed_fw_image(priv
, fw
->data
, fw
->size
);
751 rc
= mwl8k_feed_fw_image(priv
, fw
->data
, fw
->size
);
753 rc
= mwl8k_load_fw_image(priv
, fw
->data
, fw
->size
);
757 printk(KERN_ERR
"%s: unable to load firmware image\n",
758 pci_name(priv
->pdev
));
762 iowrite32(MWL8K_MODE_STA
, priv
->regs
+ MWL8K_HIU_GEN_PTR
);
768 ready_code
= ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
769 if (ready_code
== MWL8K_FWAP_READY
) {
772 } else if (ready_code
== MWL8K_FWSTA_READY
) {
781 return loops
? 0 : -ETIMEDOUT
;
785 /* DMA header used by firmware and hardware. */
786 struct mwl8k_dma_data
{
788 struct ieee80211_hdr wh
;
792 /* Routines to add/remove DMA header from skb. */
793 static inline void mwl8k_remove_dma_header(struct sk_buff
*skb
, __le16 qos
)
795 struct mwl8k_dma_data
*tr
;
798 tr
= (struct mwl8k_dma_data
*)skb
->data
;
799 hdrlen
= ieee80211_hdrlen(tr
->wh
.frame_control
);
801 if (hdrlen
!= sizeof(tr
->wh
)) {
802 if (ieee80211_is_data_qos(tr
->wh
.frame_control
)) {
803 memmove(tr
->data
- hdrlen
, &tr
->wh
, hdrlen
- 2);
804 *((__le16
*)(tr
->data
- 2)) = qos
;
806 memmove(tr
->data
- hdrlen
, &tr
->wh
, hdrlen
);
810 if (hdrlen
!= sizeof(*tr
))
811 skb_pull(skb
, sizeof(*tr
) - hdrlen
);
814 #define REDUCED_TX_HEADROOM 8
817 mwl8k_add_dma_header(struct mwl8k_priv
*priv
, struct sk_buff
*skb
,
818 int head_pad
, int tail_pad
)
820 struct ieee80211_hdr
*wh
;
823 struct mwl8k_dma_data
*tr
;
826 * Add a firmware DMA header; the firmware requires that we
827 * present a 2-byte payload length followed by a 4-address
828 * header (without QoS field), followed (optionally) by any
829 * WEP/ExtIV header (but only filled in for CCMP).
831 wh
= (struct ieee80211_hdr
*)skb
->data
;
833 hdrlen
= ieee80211_hdrlen(wh
->frame_control
);
836 * Check if skb_resize is required because of
837 * tx_headroom adjustment.
839 if (priv
->ap_fw
&& (hdrlen
< (sizeof(struct ieee80211_cts
)
840 + REDUCED_TX_HEADROOM
))) {
841 if (pskb_expand_head(skb
, REDUCED_TX_HEADROOM
, 0, GFP_ATOMIC
)) {
843 wiphy_err(priv
->hw
->wiphy
,
844 "Failed to reallocate TX buffer\n");
847 skb
->truesize
+= REDUCED_TX_HEADROOM
;
850 reqd_hdrlen
= sizeof(*tr
) + head_pad
;
852 if (hdrlen
!= reqd_hdrlen
)
853 skb_push(skb
, reqd_hdrlen
- hdrlen
);
855 if (ieee80211_is_data_qos(wh
->frame_control
))
856 hdrlen
-= IEEE80211_QOS_CTL_LEN
;
858 tr
= (struct mwl8k_dma_data
*)skb
->data
;
860 memmove(&tr
->wh
, wh
, hdrlen
);
861 if (hdrlen
!= sizeof(tr
->wh
))
862 memset(((void *)&tr
->wh
) + hdrlen
, 0, sizeof(tr
->wh
) - hdrlen
);
865 * Firmware length is the length of the fully formed "802.11
866 * payload". That is, everything except for the 802.11 header.
867 * This includes all crypto material including the MIC.
869 tr
->fwlen
= cpu_to_le16(skb
->len
- sizeof(*tr
) + tail_pad
);
872 static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv
*priv
,
875 struct ieee80211_hdr
*wh
;
876 struct ieee80211_tx_info
*tx_info
;
877 struct ieee80211_key_conf
*key_conf
;
881 wh
= (struct ieee80211_hdr
*)skb
->data
;
883 tx_info
= IEEE80211_SKB_CB(skb
);
886 if (ieee80211_is_data(wh
->frame_control
))
887 key_conf
= tx_info
->control
.hw_key
;
890 * Make sure the packet header is in the DMA header format (4-address
891 * without QoS), and add head & tail padding when HW crypto is enabled.
893 * We have the following trailer padding requirements:
894 * - WEP: 4 trailer bytes (ICV)
895 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
896 * - CCMP: 8 trailer bytes (MIC)
899 if (key_conf
!= NULL
) {
900 head_pad
= key_conf
->iv_len
;
901 switch (key_conf
->cipher
) {
902 case WLAN_CIPHER_SUITE_WEP40
:
903 case WLAN_CIPHER_SUITE_WEP104
:
906 case WLAN_CIPHER_SUITE_TKIP
:
909 case WLAN_CIPHER_SUITE_CCMP
:
914 mwl8k_add_dma_header(priv
, skb
, head_pad
, data_pad
);
918 * Packet reception for 88w8366/88w8764 AP firmware.
920 struct mwl8k_rxd_ap
{
924 __le32 pkt_phys_addr
;
925 __le32 next_rxd_phys_addr
;
929 __le32 hw_noise_floor_info
;
938 #define MWL8K_AP_RATE_INFO_MCS_FORMAT 0x80
939 #define MWL8K_AP_RATE_INFO_40MHZ 0x40
940 #define MWL8K_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
942 #define MWL8K_AP_RX_CTRL_OWNED_BY_HOST 0x80
944 /* 8366/8764 AP rx_status bits */
945 #define MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
946 #define MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
947 #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
948 #define MWL8K_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
949 #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
951 static void mwl8k_rxd_ap_init(void *_rxd
, dma_addr_t next_dma_addr
)
953 struct mwl8k_rxd_ap
*rxd
= _rxd
;
955 rxd
->next_rxd_phys_addr
= cpu_to_le32(next_dma_addr
);
956 rxd
->rx_ctrl
= MWL8K_AP_RX_CTRL_OWNED_BY_HOST
;
959 static void mwl8k_rxd_ap_refill(void *_rxd
, dma_addr_t addr
, int len
)
961 struct mwl8k_rxd_ap
*rxd
= _rxd
;
963 rxd
->pkt_len
= cpu_to_le16(len
);
964 rxd
->pkt_phys_addr
= cpu_to_le32(addr
);
970 mwl8k_rxd_ap_process(void *_rxd
, struct ieee80211_rx_status
*status
,
971 __le16
*qos
, s8
*noise
)
973 struct mwl8k_rxd_ap
*rxd
= _rxd
;
975 if (!(rxd
->rx_ctrl
& MWL8K_AP_RX_CTRL_OWNED_BY_HOST
))
979 memset(status
, 0, sizeof(*status
));
981 status
->signal
= -rxd
->rssi
;
982 *noise
= -rxd
->noise_floor
;
984 if (rxd
->rate
& MWL8K_AP_RATE_INFO_MCS_FORMAT
) {
985 status
->flag
|= RX_FLAG_HT
;
986 if (rxd
->rate
& MWL8K_AP_RATE_INFO_40MHZ
)
987 status
->flag
|= RX_FLAG_40MHZ
;
988 status
->rate_idx
= MWL8K_AP_RATE_INFO_RATEID(rxd
->rate
);
992 for (i
= 0; i
< ARRAY_SIZE(mwl8k_rates_24
); i
++) {
993 if (mwl8k_rates_24
[i
].hw_value
== rxd
->rate
) {
994 status
->rate_idx
= i
;
1000 if (rxd
->channel
> 14) {
1001 status
->band
= IEEE80211_BAND_5GHZ
;
1002 if (!(status
->flag
& RX_FLAG_HT
))
1003 status
->rate_idx
-= 5;
1005 status
->band
= IEEE80211_BAND_2GHZ
;
1007 status
->freq
= ieee80211_channel_to_frequency(rxd
->channel
,
1010 *qos
= rxd
->qos_control
;
1012 if ((rxd
->rx_status
!= MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR
) &&
1013 (rxd
->rx_status
& MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK
) &&
1014 (rxd
->rx_status
& MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR
))
1015 status
->flag
|= RX_FLAG_MMIC_ERROR
;
1017 return le16_to_cpu(rxd
->pkt_len
);
1020 static struct rxd_ops rxd_ap_ops
= {
1021 .rxd_size
= sizeof(struct mwl8k_rxd_ap
),
1022 .rxd_init
= mwl8k_rxd_ap_init
,
1023 .rxd_refill
= mwl8k_rxd_ap_refill
,
1024 .rxd_process
= mwl8k_rxd_ap_process
,
1028 * Packet reception for STA firmware.
1030 struct mwl8k_rxd_sta
{
1034 __le32 pkt_phys_addr
;
1035 __le32 next_rxd_phys_addr
;
1047 #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
1048 #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
1049 #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
1050 #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
1051 #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
1052 #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
1054 #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
1055 #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
1056 /* ICV=0 or MIC=1 */
1057 #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
1058 /* Key is uploaded only in failure case */
1059 #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
1061 static void mwl8k_rxd_sta_init(void *_rxd
, dma_addr_t next_dma_addr
)
1063 struct mwl8k_rxd_sta
*rxd
= _rxd
;
1065 rxd
->next_rxd_phys_addr
= cpu_to_le32(next_dma_addr
);
1066 rxd
->rx_ctrl
= MWL8K_STA_RX_CTRL_OWNED_BY_HOST
;
1069 static void mwl8k_rxd_sta_refill(void *_rxd
, dma_addr_t addr
, int len
)
1071 struct mwl8k_rxd_sta
*rxd
= _rxd
;
1073 rxd
->pkt_len
= cpu_to_le16(len
);
1074 rxd
->pkt_phys_addr
= cpu_to_le32(addr
);
1080 mwl8k_rxd_sta_process(void *_rxd
, struct ieee80211_rx_status
*status
,
1081 __le16
*qos
, s8
*noise
)
1083 struct mwl8k_rxd_sta
*rxd
= _rxd
;
1086 if (!(rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_OWNED_BY_HOST
))
1090 rate_info
= le16_to_cpu(rxd
->rate_info
);
1092 memset(status
, 0, sizeof(*status
));
1094 status
->signal
= -rxd
->rssi
;
1095 *noise
= -rxd
->noise_level
;
1096 status
->antenna
= MWL8K_STA_RATE_INFO_ANTSELECT(rate_info
);
1097 status
->rate_idx
= MWL8K_STA_RATE_INFO_RATEID(rate_info
);
1099 if (rate_info
& MWL8K_STA_RATE_INFO_SHORTPRE
)
1100 status
->flag
|= RX_FLAG_SHORTPRE
;
1101 if (rate_info
& MWL8K_STA_RATE_INFO_40MHZ
)
1102 status
->flag
|= RX_FLAG_40MHZ
;
1103 if (rate_info
& MWL8K_STA_RATE_INFO_SHORTGI
)
1104 status
->flag
|= RX_FLAG_SHORT_GI
;
1105 if (rate_info
& MWL8K_STA_RATE_INFO_MCS_FORMAT
)
1106 status
->flag
|= RX_FLAG_HT
;
1108 if (rxd
->channel
> 14) {
1109 status
->band
= IEEE80211_BAND_5GHZ
;
1110 if (!(status
->flag
& RX_FLAG_HT
))
1111 status
->rate_idx
-= 5;
1113 status
->band
= IEEE80211_BAND_2GHZ
;
1115 status
->freq
= ieee80211_channel_to_frequency(rxd
->channel
,
1118 *qos
= rxd
->qos_control
;
1119 if ((rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_DECRYPT_ERROR
) &&
1120 (rxd
->rx_ctrl
& MWL8K_STA_RX_CTRL_DEC_ERR_TYPE
))
1121 status
->flag
|= RX_FLAG_MMIC_ERROR
;
1123 return le16_to_cpu(rxd
->pkt_len
);
1126 static struct rxd_ops rxd_sta_ops
= {
1127 .rxd_size
= sizeof(struct mwl8k_rxd_sta
),
1128 .rxd_init
= mwl8k_rxd_sta_init
,
1129 .rxd_refill
= mwl8k_rxd_sta_refill
,
1130 .rxd_process
= mwl8k_rxd_sta_process
,
1134 #define MWL8K_RX_DESCS 256
1135 #define MWL8K_RX_MAXSZ 3800
1137 static int mwl8k_rxq_init(struct ieee80211_hw
*hw
, int index
)
1139 struct mwl8k_priv
*priv
= hw
->priv
;
1140 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1148 size
= MWL8K_RX_DESCS
* priv
->rxd_ops
->rxd_size
;
1150 rxq
->rxd
= pci_alloc_consistent(priv
->pdev
, size
, &rxq
->rxd_dma
);
1151 if (rxq
->rxd
== NULL
) {
1152 wiphy_err(hw
->wiphy
, "failed to alloc RX descriptors\n");
1155 memset(rxq
->rxd
, 0, size
);
1157 rxq
->buf
= kcalloc(MWL8K_RX_DESCS
, sizeof(*rxq
->buf
), GFP_KERNEL
);
1158 if (rxq
->buf
== NULL
) {
1159 pci_free_consistent(priv
->pdev
, size
, rxq
->rxd
, rxq
->rxd_dma
);
1163 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
1167 dma_addr_t next_dma_addr
;
1169 desc_size
= priv
->rxd_ops
->rxd_size
;
1170 rxd
= rxq
->rxd
+ (i
* priv
->rxd_ops
->rxd_size
);
1173 if (nexti
== MWL8K_RX_DESCS
)
1175 next_dma_addr
= rxq
->rxd_dma
+ (nexti
* desc_size
);
1177 priv
->rxd_ops
->rxd_init(rxd
, next_dma_addr
);
1183 static int rxq_refill(struct ieee80211_hw
*hw
, int index
, int limit
)
1185 struct mwl8k_priv
*priv
= hw
->priv
;
1186 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1190 while (rxq
->rxd_count
< MWL8K_RX_DESCS
&& limit
--) {
1191 struct sk_buff
*skb
;
1196 skb
= dev_alloc_skb(MWL8K_RX_MAXSZ
);
1200 addr
= pci_map_single(priv
->pdev
, skb
->data
,
1201 MWL8K_RX_MAXSZ
, DMA_FROM_DEVICE
);
1205 if (rxq
->tail
== MWL8K_RX_DESCS
)
1207 rxq
->buf
[rx
].skb
= skb
;
1208 dma_unmap_addr_set(&rxq
->buf
[rx
], dma
, addr
);
1210 rxd
= rxq
->rxd
+ (rx
* priv
->rxd_ops
->rxd_size
);
1211 priv
->rxd_ops
->rxd_refill(rxd
, addr
, MWL8K_RX_MAXSZ
);
1219 /* Must be called only when the card's reception is completely halted */
1220 static void mwl8k_rxq_deinit(struct ieee80211_hw
*hw
, int index
)
1222 struct mwl8k_priv
*priv
= hw
->priv
;
1223 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1226 if (rxq
->rxd
== NULL
)
1229 for (i
= 0; i
< MWL8K_RX_DESCS
; i
++) {
1230 if (rxq
->buf
[i
].skb
!= NULL
) {
1231 pci_unmap_single(priv
->pdev
,
1232 dma_unmap_addr(&rxq
->buf
[i
], dma
),
1233 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
1234 dma_unmap_addr_set(&rxq
->buf
[i
], dma
, 0);
1236 kfree_skb(rxq
->buf
[i
].skb
);
1237 rxq
->buf
[i
].skb
= NULL
;
1244 pci_free_consistent(priv
->pdev
,
1245 MWL8K_RX_DESCS
* priv
->rxd_ops
->rxd_size
,
1246 rxq
->rxd
, rxq
->rxd_dma
);
1252 * Scan a list of BSSIDs to process for finalize join.
1253 * Allows for extension to process multiple BSSIDs.
1256 mwl8k_capture_bssid(struct mwl8k_priv
*priv
, struct ieee80211_hdr
*wh
)
1258 return priv
->capture_beacon
&&
1259 ieee80211_is_beacon(wh
->frame_control
) &&
1260 ether_addr_equal_64bits(wh
->addr3
, priv
->capture_bssid
);
1263 static inline void mwl8k_save_beacon(struct ieee80211_hw
*hw
,
1264 struct sk_buff
*skb
)
1266 struct mwl8k_priv
*priv
= hw
->priv
;
1268 priv
->capture_beacon
= false;
1269 memset(priv
->capture_bssid
, 0, ETH_ALEN
);
1272 * Use GFP_ATOMIC as rxq_process is called from
1273 * the primary interrupt handler, memory allocation call
1276 priv
->beacon_skb
= skb_copy(skb
, GFP_ATOMIC
);
1277 if (priv
->beacon_skb
!= NULL
)
1278 ieee80211_queue_work(hw
, &priv
->finalize_join_worker
);
1281 static inline struct mwl8k_vif
*mwl8k_find_vif_bss(struct list_head
*vif_list
,
1284 struct mwl8k_vif
*mwl8k_vif
;
1286 list_for_each_entry(mwl8k_vif
,
1288 if (memcmp(bssid
, mwl8k_vif
->bssid
,
1296 static int rxq_process(struct ieee80211_hw
*hw
, int index
, int limit
)
1298 struct mwl8k_priv
*priv
= hw
->priv
;
1299 struct mwl8k_vif
*mwl8k_vif
= NULL
;
1300 struct mwl8k_rx_queue
*rxq
= priv
->rxq
+ index
;
1304 while (rxq
->rxd_count
&& limit
--) {
1305 struct sk_buff
*skb
;
1308 struct ieee80211_rx_status status
;
1309 struct ieee80211_hdr
*wh
;
1312 skb
= rxq
->buf
[rxq
->head
].skb
;
1316 rxd
= rxq
->rxd
+ (rxq
->head
* priv
->rxd_ops
->rxd_size
);
1318 pkt_len
= priv
->rxd_ops
->rxd_process(rxd
, &status
, &qos
,
1323 rxq
->buf
[rxq
->head
].skb
= NULL
;
1325 pci_unmap_single(priv
->pdev
,
1326 dma_unmap_addr(&rxq
->buf
[rxq
->head
], dma
),
1327 MWL8K_RX_MAXSZ
, PCI_DMA_FROMDEVICE
);
1328 dma_unmap_addr_set(&rxq
->buf
[rxq
->head
], dma
, 0);
1331 if (rxq
->head
== MWL8K_RX_DESCS
)
1336 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1339 * Check for a pending join operation. Save a
1340 * copy of the beacon and schedule a tasklet to
1341 * send a FINALIZE_JOIN command to the firmware.
1343 if (mwl8k_capture_bssid(priv
, (void *)skb
->data
))
1344 mwl8k_save_beacon(hw
, skb
);
1346 if (ieee80211_has_protected(wh
->frame_control
)) {
1348 /* Check if hw crypto has been enabled for
1349 * this bss. If yes, set the status flags
1352 mwl8k_vif
= mwl8k_find_vif_bss(&priv
->vif_list
,
1355 if (mwl8k_vif
!= NULL
&&
1356 mwl8k_vif
->is_hw_crypto_enabled
) {
1358 * When MMIC ERROR is encountered
1359 * by the firmware, payload is
1360 * dropped and only 32 bytes of
1361 * mwl8k Firmware header is sent
1364 * We need to add four bytes of
1365 * key information. In it
1366 * MAC80211 expects keyidx set to
1367 * 0 for triggering Counter
1368 * Measure of MMIC failure.
1370 if (status
.flag
& RX_FLAG_MMIC_ERROR
) {
1371 struct mwl8k_dma_data
*tr
;
1372 tr
= (struct mwl8k_dma_data
*)skb
->data
;
1373 memset((void *)&(tr
->data
), 0, 4);
1377 if (!ieee80211_is_auth(wh
->frame_control
))
1378 status
.flag
|= RX_FLAG_IV_STRIPPED
|
1380 RX_FLAG_MMIC_STRIPPED
;
1384 skb_put(skb
, pkt_len
);
1385 mwl8k_remove_dma_header(skb
, qos
);
1386 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
1387 ieee80211_rx_irqsafe(hw
, skb
);
1397 * Packet transmission.
1400 #define MWL8K_TXD_STATUS_OK 0x00000001
1401 #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1402 #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1403 #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1404 #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1406 #define MWL8K_QOS_QLEN_UNSPEC 0xff00
1407 #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1408 #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1409 #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1410 #define MWL8K_QOS_EOSP 0x0010
1412 struct mwl8k_tx_desc
{
1417 __le32 pkt_phys_addr
;
1419 __u8 dest_MAC_addr
[ETH_ALEN
];
1420 __le32 next_txd_phys_addr
;
1427 #define MWL8K_TX_DESCS 128
1429 static int mwl8k_txq_init(struct ieee80211_hw
*hw
, int index
)
1431 struct mwl8k_priv
*priv
= hw
->priv
;
1432 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1440 size
= MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
);
1442 txq
->txd
= pci_alloc_consistent(priv
->pdev
, size
, &txq
->txd_dma
);
1443 if (txq
->txd
== NULL
) {
1444 wiphy_err(hw
->wiphy
, "failed to alloc TX descriptors\n");
1447 memset(txq
->txd
, 0, size
);
1449 txq
->skb
= kcalloc(MWL8K_TX_DESCS
, sizeof(*txq
->skb
), GFP_KERNEL
);
1450 if (txq
->skb
== NULL
) {
1451 pci_free_consistent(priv
->pdev
, size
, txq
->txd
, txq
->txd_dma
);
1455 for (i
= 0; i
< MWL8K_TX_DESCS
; i
++) {
1456 struct mwl8k_tx_desc
*tx_desc
;
1459 tx_desc
= txq
->txd
+ i
;
1460 nexti
= (i
+ 1) % MWL8K_TX_DESCS
;
1462 tx_desc
->status
= 0;
1463 tx_desc
->next_txd_phys_addr
=
1464 cpu_to_le32(txq
->txd_dma
+ nexti
* sizeof(*tx_desc
));
1470 static inline void mwl8k_tx_start(struct mwl8k_priv
*priv
)
1472 iowrite32(MWL8K_H2A_INT_PPA_READY
,
1473 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1474 iowrite32(MWL8K_H2A_INT_DUMMY
,
1475 priv
->regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
1476 ioread32(priv
->regs
+ MWL8K_HIU_INT_CODE
);
1479 static void mwl8k_dump_tx_rings(struct ieee80211_hw
*hw
)
1481 struct mwl8k_priv
*priv
= hw
->priv
;
1484 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++) {
1485 struct mwl8k_tx_queue
*txq
= priv
->txq
+ i
;
1491 for (desc
= 0; desc
< MWL8K_TX_DESCS
; desc
++) {
1492 struct mwl8k_tx_desc
*tx_desc
= txq
->txd
+ desc
;
1495 status
= le32_to_cpu(tx_desc
->status
);
1496 if (status
& MWL8K_TXD_STATUS_FW_OWNED
)
1501 if (tx_desc
->pkt_len
== 0)
1505 wiphy_err(hw
->wiphy
,
1506 "txq[%d] len=%d head=%d tail=%d "
1507 "fw_owned=%d drv_owned=%d unused=%d\n",
1509 txq
->len
, txq
->head
, txq
->tail
,
1510 fw_owned
, drv_owned
, unused
);
1515 * Must be called with priv->fw_mutex held and tx queues stopped.
1517 #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1519 static int mwl8k_tx_wait_empty(struct ieee80211_hw
*hw
)
1521 struct mwl8k_priv
*priv
= hw
->priv
;
1522 DECLARE_COMPLETION_ONSTACK(tx_wait
);
1528 /* Since fw restart is in progress, allow only the firmware
1529 * commands from the restart code and block the other
1530 * commands since they are going to fail in any case since
1531 * the firmware has crashed
1533 if (priv
->hw_restart_in_progress
) {
1534 if (priv
->hw_restart_owner
== current
)
1540 if (atomic_read(&priv
->watchdog_event_pending
))
1544 * The TX queues are stopped at this point, so this test
1545 * doesn't need to take ->tx_lock.
1547 if (!priv
->pending_tx_pkts
)
1553 spin_lock_bh(&priv
->tx_lock
);
1554 priv
->tx_wait
= &tx_wait
;
1557 unsigned long timeout
;
1559 oldcount
= priv
->pending_tx_pkts
;
1561 spin_unlock_bh(&priv
->tx_lock
);
1562 timeout
= wait_for_completion_timeout(&tx_wait
,
1563 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS
));
1565 if (atomic_read(&priv
->watchdog_event_pending
)) {
1566 spin_lock_bh(&priv
->tx_lock
);
1567 priv
->tx_wait
= NULL
;
1568 spin_unlock_bh(&priv
->tx_lock
);
1572 spin_lock_bh(&priv
->tx_lock
);
1574 if (timeout
|| !priv
->pending_tx_pkts
) {
1575 WARN_ON(priv
->pending_tx_pkts
);
1577 wiphy_notice(hw
->wiphy
, "tx rings drained\n");
1582 mwl8k_tx_start(priv
);
1587 if (priv
->pending_tx_pkts
< oldcount
) {
1588 wiphy_notice(hw
->wiphy
,
1589 "waiting for tx rings to drain (%d -> %d pkts)\n",
1590 oldcount
, priv
->pending_tx_pkts
);
1595 priv
->tx_wait
= NULL
;
1597 wiphy_err(hw
->wiphy
, "tx rings stuck for %d ms\n",
1598 MWL8K_TX_WAIT_TIMEOUT_MS
);
1599 mwl8k_dump_tx_rings(hw
);
1600 priv
->hw_restart_in_progress
= true;
1601 ieee80211_queue_work(hw
, &priv
->fw_reload
);
1605 priv
->tx_wait
= NULL
;
1606 spin_unlock_bh(&priv
->tx_lock
);
1611 #define MWL8K_TXD_SUCCESS(status) \
1612 ((status) & (MWL8K_TXD_STATUS_OK | \
1613 MWL8K_TXD_STATUS_OK_RETRY | \
1614 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1616 static int mwl8k_tid_queue_mapping(u8 tid
)
1623 return IEEE80211_AC_BE
;
1627 return IEEE80211_AC_BK
;
1631 return IEEE80211_AC_VI
;
1635 return IEEE80211_AC_VO
;
1643 /* The firmware will fill in the rate information
1644 * for each packet that gets queued in the hardware
1645 * and these macros will interpret that info.
1648 #define RI_FORMAT(a) (a & 0x0001)
1649 #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
1652 mwl8k_txq_reclaim(struct ieee80211_hw
*hw
, int index
, int limit
, int force
)
1654 struct mwl8k_priv
*priv
= hw
->priv
;
1655 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1659 while (txq
->len
> 0 && limit
--) {
1661 struct mwl8k_tx_desc
*tx_desc
;
1664 struct sk_buff
*skb
;
1665 struct ieee80211_tx_info
*info
;
1667 struct ieee80211_sta
*sta
;
1668 struct mwl8k_sta
*sta_info
= NULL
;
1670 struct ieee80211_hdr
*wh
;
1673 tx_desc
= txq
->txd
+ tx
;
1675 status
= le32_to_cpu(tx_desc
->status
);
1677 if (status
& MWL8K_TXD_STATUS_FW_OWNED
) {
1681 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
);
1684 txq
->head
= (tx
+ 1) % MWL8K_TX_DESCS
;
1685 BUG_ON(txq
->len
== 0);
1687 priv
->pending_tx_pkts
--;
1689 addr
= le32_to_cpu(tx_desc
->pkt_phys_addr
);
1690 size
= le16_to_cpu(tx_desc
->pkt_len
);
1692 txq
->skb
[tx
] = NULL
;
1694 BUG_ON(skb
== NULL
);
1695 pci_unmap_single(priv
->pdev
, addr
, size
, PCI_DMA_TODEVICE
);
1697 mwl8k_remove_dma_header(skb
, tx_desc
->qos_control
);
1699 wh
= (struct ieee80211_hdr
*) skb
->data
;
1701 /* Mark descriptor as unused */
1702 tx_desc
->pkt_phys_addr
= 0;
1703 tx_desc
->pkt_len
= 0;
1705 info
= IEEE80211_SKB_CB(skb
);
1706 if (ieee80211_is_data(wh
->frame_control
)) {
1708 sta
= ieee80211_find_sta_by_ifaddr(hw
, wh
->addr1
,
1711 sta_info
= MWL8K_STA(sta
);
1712 BUG_ON(sta_info
== NULL
);
1713 rate_info
= le16_to_cpu(tx_desc
->rate_info
);
1714 /* If rate is < 6.5 Mpbs for an ht station
1715 * do not form an ampdu. If the station is a
1716 * legacy station (format = 0), do not form an
1719 if (RI_RATE_ID_MCS(rate_info
) < 1 ||
1720 RI_FORMAT(rate_info
) == 0) {
1721 sta_info
->is_ampdu_allowed
= false;
1723 sta_info
->is_ampdu_allowed
= true;
1729 ieee80211_tx_info_clear_status(info
);
1731 /* Rate control is happening in the firmware.
1732 * Ensure no tx rate is being reported.
1734 info
->status
.rates
[0].idx
= -1;
1735 info
->status
.rates
[0].count
= 1;
1737 if (MWL8K_TXD_SUCCESS(status
))
1738 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1740 ieee80211_tx_status_irqsafe(hw
, skb
);
1748 /* must be called only when the card's transmit is completely halted */
1749 static void mwl8k_txq_deinit(struct ieee80211_hw
*hw
, int index
)
1751 struct mwl8k_priv
*priv
= hw
->priv
;
1752 struct mwl8k_tx_queue
*txq
= priv
->txq
+ index
;
1754 if (txq
->txd
== NULL
)
1757 mwl8k_txq_reclaim(hw
, index
, INT_MAX
, 1);
1762 pci_free_consistent(priv
->pdev
,
1763 MWL8K_TX_DESCS
* sizeof(struct mwl8k_tx_desc
),
1764 txq
->txd
, txq
->txd_dma
);
1768 /* caller must hold priv->stream_lock when calling the stream functions */
1769 static struct mwl8k_ampdu_stream
*
1770 mwl8k_add_stream(struct ieee80211_hw
*hw
, struct ieee80211_sta
*sta
, u8 tid
)
1772 struct mwl8k_ampdu_stream
*stream
;
1773 struct mwl8k_priv
*priv
= hw
->priv
;
1776 for (i
= 0; i
< MWL8K_NUM_AMPDU_STREAMS
; i
++) {
1777 stream
= &priv
->ampdu
[i
];
1778 if (stream
->state
== AMPDU_NO_STREAM
) {
1780 stream
->state
= AMPDU_STREAM_NEW
;
1783 wiphy_debug(hw
->wiphy
, "Added a new stream for %pM %d",
1792 mwl8k_start_stream(struct ieee80211_hw
*hw
, struct mwl8k_ampdu_stream
*stream
)
1796 /* if the stream has already been started, don't start it again */
1797 if (stream
->state
!= AMPDU_STREAM_NEW
)
1799 ret
= ieee80211_start_tx_ba_session(stream
->sta
, stream
->tid
, 0);
1801 wiphy_debug(hw
->wiphy
, "Failed to start stream for %pM %d: "
1802 "%d\n", stream
->sta
->addr
, stream
->tid
, ret
);
1804 wiphy_debug(hw
->wiphy
, "Started stream for %pM %d\n",
1805 stream
->sta
->addr
, stream
->tid
);
1810 mwl8k_remove_stream(struct ieee80211_hw
*hw
, struct mwl8k_ampdu_stream
*stream
)
1812 wiphy_debug(hw
->wiphy
, "Remove stream for %pM %d\n", stream
->sta
->addr
,
1814 memset(stream
, 0, sizeof(*stream
));
1817 static struct mwl8k_ampdu_stream
*
1818 mwl8k_lookup_stream(struct ieee80211_hw
*hw
, u8
*addr
, u8 tid
)
1820 struct mwl8k_priv
*priv
= hw
->priv
;
1823 for (i
= 0; i
< MWL8K_NUM_AMPDU_STREAMS
; i
++) {
1824 struct mwl8k_ampdu_stream
*stream
;
1825 stream
= &priv
->ampdu
[i
];
1826 if (stream
->state
== AMPDU_NO_STREAM
)
1828 if (!memcmp(stream
->sta
->addr
, addr
, ETH_ALEN
) &&
1835 #define MWL8K_AMPDU_PACKET_THRESHOLD 64
1836 static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta
*sta
, u8 tid
)
1838 struct mwl8k_sta
*sta_info
= MWL8K_STA(sta
);
1839 struct tx_traffic_info
*tx_stats
;
1841 BUG_ON(tid
>= MWL8K_MAX_TID
);
1842 tx_stats
= &sta_info
->tx_stats
[tid
];
1844 return sta_info
->is_ampdu_allowed
&&
1845 tx_stats
->pkts
> MWL8K_AMPDU_PACKET_THRESHOLD
;
1848 static inline void mwl8k_tx_count_packet(struct ieee80211_sta
*sta
, u8 tid
)
1850 struct mwl8k_sta
*sta_info
= MWL8K_STA(sta
);
1851 struct tx_traffic_info
*tx_stats
;
1853 BUG_ON(tid
>= MWL8K_MAX_TID
);
1854 tx_stats
= &sta_info
->tx_stats
[tid
];
1856 if (tx_stats
->start_time
== 0)
1857 tx_stats
->start_time
= jiffies
;
1859 /* reset the packet count after each second elapses. If the number of
1860 * packets ever exceeds the ampdu_min_traffic threshold, we will allow
1861 * an ampdu stream to be started.
1863 if (jiffies
- tx_stats
->start_time
> HZ
) {
1865 tx_stats
->start_time
= 0;
1870 /* The hardware ampdu queues start from 5.
1871 * txpriorities for ampdu queues are
1872 * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
1873 * and queue 3 is lowest (queue 4 is reserved)
1878 mwl8k_txq_xmit(struct ieee80211_hw
*hw
,
1880 struct ieee80211_sta
*sta
,
1881 struct sk_buff
*skb
)
1883 struct mwl8k_priv
*priv
= hw
->priv
;
1884 struct ieee80211_tx_info
*tx_info
;
1885 struct mwl8k_vif
*mwl8k_vif
;
1886 struct ieee80211_hdr
*wh
;
1887 struct mwl8k_tx_queue
*txq
;
1888 struct mwl8k_tx_desc
*tx
;
1895 struct mwl8k_ampdu_stream
*stream
= NULL
;
1896 bool start_ba_session
= false;
1897 bool mgmtframe
= false;
1898 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)skb
->data
;
1899 bool eapol_frame
= false;
1901 wh
= (struct ieee80211_hdr
*)skb
->data
;
1902 if (ieee80211_is_data_qos(wh
->frame_control
))
1903 qos
= le16_to_cpu(*((__le16
*)ieee80211_get_qos_ctl(wh
)));
1907 if (skb
->protocol
== cpu_to_be16(ETH_P_PAE
))
1910 if (ieee80211_is_mgmt(wh
->frame_control
))
1914 mwl8k_encapsulate_tx_frame(priv
, skb
);
1916 mwl8k_add_dma_header(priv
, skb
, 0, 0);
1918 wh
= &((struct mwl8k_dma_data
*)skb
->data
)->wh
;
1920 tx_info
= IEEE80211_SKB_CB(skb
);
1921 mwl8k_vif
= MWL8K_VIF(tx_info
->control
.vif
);
1923 if (tx_info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1924 wh
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1925 wh
->seq_ctrl
|= cpu_to_le16(mwl8k_vif
->seqno
);
1926 mwl8k_vif
->seqno
+= 0x10;
1929 /* Setup firmware control bit fields for each frame type. */
1932 if (ieee80211_is_mgmt(wh
->frame_control
) ||
1933 ieee80211_is_ctl(wh
->frame_control
)) {
1935 qos
|= MWL8K_QOS_QLEN_UNSPEC
| MWL8K_QOS_EOSP
;
1936 } else if (ieee80211_is_data(wh
->frame_control
)) {
1938 if (is_multicast_ether_addr(wh
->addr1
))
1939 txstatus
|= MWL8K_TXD_STATUS_MULTICAST_TX
;
1941 qos
&= ~MWL8K_QOS_ACK_POLICY_MASK
;
1942 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1943 qos
|= MWL8K_QOS_ACK_POLICY_BLOCKACK
;
1945 qos
|= MWL8K_QOS_ACK_POLICY_NORMAL
;
1948 /* Queue ADDBA request in the respective data queue. While setting up
1949 * the ampdu stream, mac80211 queues further packets for that
1950 * particular ra/tid pair. However, packets piled up in the hardware
1951 * for that ra/tid pair will still go out. ADDBA request and the
1952 * related data packets going out from different queues asynchronously
1953 * will cause a shift in the receiver window which might result in
1954 * ampdu packets getting dropped at the receiver after the stream has
1957 if (unlikely(ieee80211_is_action(wh
->frame_control
) &&
1958 mgmt
->u
.action
.category
== WLAN_CATEGORY_BACK
&&
1959 mgmt
->u
.action
.u
.addba_req
.action_code
== WLAN_ACTION_ADDBA_REQ
&&
1961 u16 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1962 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1963 index
= mwl8k_tid_queue_mapping(tid
);
1968 if (priv
->ap_fw
&& sta
&& sta
->ht_cap
.ht_supported
&& !eapol_frame
&&
1969 ieee80211_is_data_qos(wh
->frame_control
)) {
1971 mwl8k_tx_count_packet(sta
, tid
);
1972 spin_lock(&priv
->stream_lock
);
1973 stream
= mwl8k_lookup_stream(hw
, sta
->addr
, tid
);
1974 if (stream
!= NULL
) {
1975 if (stream
->state
== AMPDU_STREAM_ACTIVE
) {
1976 WARN_ON(!(qos
& MWL8K_QOS_ACK_POLICY_BLOCKACK
));
1977 txpriority
= (BA_QUEUE
+ stream
->idx
) %
1979 if (stream
->idx
<= 1)
1980 index
= stream
->idx
+
1981 MWL8K_TX_WMM_QUEUES
;
1983 } else if (stream
->state
== AMPDU_STREAM_NEW
) {
1984 /* We get here if the driver sends us packets
1985 * after we've initiated a stream, but before
1986 * our ampdu_action routine has been called
1987 * with IEEE80211_AMPDU_TX_START to get the SSN
1988 * for the ADDBA request. So this packet can
1989 * go out with no risk of sequence number
1990 * mismatch. No special handling is required.
1993 /* Drop packets that would go out after the
1994 * ADDBA request was sent but before the ADDBA
1995 * response is received. If we don't do this,
1996 * the recipient would probably receive it
1997 * after the ADDBA request with SSN 0. This
1998 * will cause the recipient's BA receive window
1999 * to shift, which would cause the subsequent
2000 * packets in the BA stream to be discarded.
2001 * mac80211 queues our packets for us in this
2002 * case, so this is really just a safety check.
2004 wiphy_warn(hw
->wiphy
,
2005 "Cannot send packet while ADDBA "
2006 "dialog is underway.\n");
2007 spin_unlock(&priv
->stream_lock
);
2012 /* Defer calling mwl8k_start_stream so that the current
2013 * skb can go out before the ADDBA request. This
2014 * prevents sequence number mismatch at the recepient
2015 * as described above.
2017 if (mwl8k_ampdu_allowed(sta
, tid
)) {
2018 stream
= mwl8k_add_stream(hw
, sta
, tid
);
2020 start_ba_session
= true;
2023 spin_unlock(&priv
->stream_lock
);
2025 qos
&= ~MWL8K_QOS_ACK_POLICY_MASK
;
2026 qos
|= MWL8K_QOS_ACK_POLICY_NORMAL
;
2029 dma
= pci_map_single(priv
->pdev
, skb
->data
,
2030 skb
->len
, PCI_DMA_TODEVICE
);
2032 if (pci_dma_mapping_error(priv
->pdev
, dma
)) {
2033 wiphy_debug(hw
->wiphy
,
2034 "failed to dma map skb, dropping TX frame.\n");
2035 if (start_ba_session
) {
2036 spin_lock(&priv
->stream_lock
);
2037 mwl8k_remove_stream(hw
, stream
);
2038 spin_unlock(&priv
->stream_lock
);
2044 spin_lock_bh(&priv
->tx_lock
);
2046 txq
= priv
->txq
+ index
;
2048 /* Mgmt frames that go out frequently are probe
2049 * responses. Other mgmt frames got out relatively
2050 * infrequently. Hence reserve 2 buffers so that
2051 * other mgmt frames do not get dropped due to an
2052 * already queued probe response in one of the
2056 if (txq
->len
>= MWL8K_TX_DESCS
- 2) {
2057 if (!mgmtframe
|| txq
->len
== MWL8K_TX_DESCS
) {
2058 if (start_ba_session
) {
2059 spin_lock(&priv
->stream_lock
);
2060 mwl8k_remove_stream(hw
, stream
);
2061 spin_unlock(&priv
->stream_lock
);
2063 mwl8k_tx_start(priv
);
2064 spin_unlock_bh(&priv
->tx_lock
);
2065 pci_unmap_single(priv
->pdev
, dma
, skb
->len
,
2072 BUG_ON(txq
->skb
[txq
->tail
] != NULL
);
2073 txq
->skb
[txq
->tail
] = skb
;
2075 tx
= txq
->txd
+ txq
->tail
;
2076 tx
->data_rate
= txdatarate
;
2077 tx
->tx_priority
= txpriority
;
2078 tx
->qos_control
= cpu_to_le16(qos
);
2079 tx
->pkt_phys_addr
= cpu_to_le32(dma
);
2080 tx
->pkt_len
= cpu_to_le16(skb
->len
);
2082 if (!priv
->ap_fw
&& sta
!= NULL
)
2083 tx
->peer_id
= MWL8K_STA(sta
)->peer_id
;
2087 if (priv
->ap_fw
&& ieee80211_is_data(wh
->frame_control
) && !eapol_frame
)
2088 tx
->timestamp
= cpu_to_le32(ioread32(priv
->regs
+
2089 MWL8K_HW_TIMER_REGISTER
));
2094 tx
->status
= cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED
| txstatus
);
2097 priv
->pending_tx_pkts
++;
2100 if (txq
->tail
== MWL8K_TX_DESCS
)
2103 mwl8k_tx_start(priv
);
2105 spin_unlock_bh(&priv
->tx_lock
);
2107 /* Initiate the ampdu session here */
2108 if (start_ba_session
) {
2109 spin_lock(&priv
->stream_lock
);
2110 if (mwl8k_start_stream(hw
, stream
))
2111 mwl8k_remove_stream(hw
, stream
);
2112 spin_unlock(&priv
->stream_lock
);
2120 * We have the following requirements for issuing firmware commands:
2121 * - Some commands require that the packet transmit path is idle when
2122 * the command is issued. (For simplicity, we'll just quiesce the
2123 * transmit path for every command.)
2124 * - There are certain sequences of commands that need to be issued to
2125 * the hardware sequentially, with no other intervening commands.
2127 * This leads to an implementation of a "firmware lock" as a mutex that
2128 * can be taken recursively, and which is taken by both the low-level
2129 * command submission function (mwl8k_post_cmd) as well as any users of
2130 * that function that require issuing of an atomic sequence of commands,
2131 * and quiesces the transmit path whenever it's taken.
2133 static int mwl8k_fw_lock(struct ieee80211_hw
*hw
)
2135 struct mwl8k_priv
*priv
= hw
->priv
;
2137 if (priv
->fw_mutex_owner
!= current
) {
2140 mutex_lock(&priv
->fw_mutex
);
2141 ieee80211_stop_queues(hw
);
2143 rc
= mwl8k_tx_wait_empty(hw
);
2145 if (!priv
->hw_restart_in_progress
)
2146 ieee80211_wake_queues(hw
);
2148 mutex_unlock(&priv
->fw_mutex
);
2153 priv
->fw_mutex_owner
= current
;
2156 priv
->fw_mutex_depth
++;
2161 static void mwl8k_fw_unlock(struct ieee80211_hw
*hw
)
2163 struct mwl8k_priv
*priv
= hw
->priv
;
2165 if (!--priv
->fw_mutex_depth
) {
2166 if (!priv
->hw_restart_in_progress
)
2167 ieee80211_wake_queues(hw
);
2169 priv
->fw_mutex_owner
= NULL
;
2170 mutex_unlock(&priv
->fw_mutex
);
2174 static void mwl8k_enable_bsses(struct ieee80211_hw
*hw
, bool enable
,
2178 * Command processing.
2181 /* Timeout firmware commands after 10s */
2182 #define MWL8K_CMD_TIMEOUT_MS 10000
2184 static int mwl8k_post_cmd(struct ieee80211_hw
*hw
, struct mwl8k_cmd_pkt
*cmd
)
2186 DECLARE_COMPLETION_ONSTACK(cmd_wait
);
2187 struct mwl8k_priv
*priv
= hw
->priv
;
2188 void __iomem
*regs
= priv
->regs
;
2189 dma_addr_t dma_addr
;
2190 unsigned int dma_size
;
2192 unsigned long timeout
= 0;
2196 wiphy_dbg(hw
->wiphy
, "Posting %s [%d]\n",
2197 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)), cmd
->macid
);
2199 /* Before posting firmware commands that could change the hardware
2200 * characteristics, make sure that all BSSes are stopped temporary.
2201 * Enable these stopped BSSes after completion of the commands
2204 rc
= mwl8k_fw_lock(hw
);
2208 if (priv
->ap_fw
&& priv
->running_bsses
) {
2209 switch (le16_to_cpu(cmd
->code
)) {
2210 case MWL8K_CMD_SET_RF_CHANNEL
:
2211 case MWL8K_CMD_RADIO_CONTROL
:
2212 case MWL8K_CMD_RF_TX_POWER
:
2213 case MWL8K_CMD_TX_POWER
:
2214 case MWL8K_CMD_RF_ANTENNA
:
2215 case MWL8K_CMD_RTS_THRESHOLD
:
2216 case MWL8K_CMD_MIMO_CONFIG
:
2217 bitmap
= priv
->running_bsses
;
2218 mwl8k_enable_bsses(hw
, false, bitmap
);
2223 cmd
->result
= (__force __le16
) 0xffff;
2224 dma_size
= le16_to_cpu(cmd
->length
);
2225 dma_addr
= pci_map_single(priv
->pdev
, cmd
, dma_size
,
2226 PCI_DMA_BIDIRECTIONAL
);
2227 if (pci_dma_mapping_error(priv
->pdev
, dma_addr
))
2230 priv
->hostcmd_wait
= &cmd_wait
;
2231 iowrite32(dma_addr
, regs
+ MWL8K_HIU_GEN_PTR
);
2232 iowrite32(MWL8K_H2A_INT_DOORBELL
,
2233 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
2234 iowrite32(MWL8K_H2A_INT_DUMMY
,
2235 regs
+ MWL8K_HIU_H2A_INTERRUPT_EVENTS
);
2237 timeout
= wait_for_completion_timeout(&cmd_wait
,
2238 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS
));
2240 priv
->hostcmd_wait
= NULL
;
2243 pci_unmap_single(priv
->pdev
, dma_addr
, dma_size
,
2244 PCI_DMA_BIDIRECTIONAL
);
2247 wiphy_err(hw
->wiphy
, "Command %s timeout after %u ms\n",
2248 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
2249 MWL8K_CMD_TIMEOUT_MS
);
2254 ms
= MWL8K_CMD_TIMEOUT_MS
- jiffies_to_msecs(timeout
);
2256 rc
= cmd
->result
? -EINVAL
: 0;
2258 wiphy_err(hw
->wiphy
, "Command %s error 0x%x\n",
2259 mwl8k_cmd_name(cmd
->code
, buf
, sizeof(buf
)),
2260 le16_to_cpu(cmd
->result
));
2262 wiphy_notice(hw
->wiphy
, "Command %s took %d ms\n",
2263 mwl8k_cmd_name(cmd
->code
,
2269 mwl8k_enable_bsses(hw
, true, bitmap
);
2271 mwl8k_fw_unlock(hw
);
2276 static int mwl8k_post_pervif_cmd(struct ieee80211_hw
*hw
,
2277 struct ieee80211_vif
*vif
,
2278 struct mwl8k_cmd_pkt
*cmd
)
2281 cmd
->macid
= MWL8K_VIF(vif
)->macid
;
2282 return mwl8k_post_cmd(hw
, cmd
);
2286 * Setup code shared between STA and AP firmware images.
2288 static void mwl8k_setup_2ghz_band(struct ieee80211_hw
*hw
)
2290 struct mwl8k_priv
*priv
= hw
->priv
;
2292 BUILD_BUG_ON(sizeof(priv
->channels_24
) != sizeof(mwl8k_channels_24
));
2293 memcpy(priv
->channels_24
, mwl8k_channels_24
, sizeof(mwl8k_channels_24
));
2295 BUILD_BUG_ON(sizeof(priv
->rates_24
) != sizeof(mwl8k_rates_24
));
2296 memcpy(priv
->rates_24
, mwl8k_rates_24
, sizeof(mwl8k_rates_24
));
2298 priv
->band_24
.band
= IEEE80211_BAND_2GHZ
;
2299 priv
->band_24
.channels
= priv
->channels_24
;
2300 priv
->band_24
.n_channels
= ARRAY_SIZE(mwl8k_channels_24
);
2301 priv
->band_24
.bitrates
= priv
->rates_24
;
2302 priv
->band_24
.n_bitrates
= ARRAY_SIZE(mwl8k_rates_24
);
2304 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band_24
;
2307 static void mwl8k_setup_5ghz_band(struct ieee80211_hw
*hw
)
2309 struct mwl8k_priv
*priv
= hw
->priv
;
2311 BUILD_BUG_ON(sizeof(priv
->channels_50
) != sizeof(mwl8k_channels_50
));
2312 memcpy(priv
->channels_50
, mwl8k_channels_50
, sizeof(mwl8k_channels_50
));
2314 BUILD_BUG_ON(sizeof(priv
->rates_50
) != sizeof(mwl8k_rates_50
));
2315 memcpy(priv
->rates_50
, mwl8k_rates_50
, sizeof(mwl8k_rates_50
));
2317 priv
->band_50
.band
= IEEE80211_BAND_5GHZ
;
2318 priv
->band_50
.channels
= priv
->channels_50
;
2319 priv
->band_50
.n_channels
= ARRAY_SIZE(mwl8k_channels_50
);
2320 priv
->band_50
.bitrates
= priv
->rates_50
;
2321 priv
->band_50
.n_bitrates
= ARRAY_SIZE(mwl8k_rates_50
);
2323 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &priv
->band_50
;
2327 * CMD_GET_HW_SPEC (STA version).
2329 struct mwl8k_cmd_get_hw_spec_sta
{
2330 struct mwl8k_cmd_pkt header
;
2332 __u8 host_interface
;
2334 __u8 perm_addr
[ETH_ALEN
];
2339 __u8 mcs_bitmap
[16];
2340 __le32 rx_queue_ptr
;
2341 __le32 num_tx_queues
;
2342 __le32 tx_queue_ptrs
[MWL8K_TX_WMM_QUEUES
];
2344 __le32 num_tx_desc_per_queue
;
2348 #define MWL8K_CAP_MAX_AMSDU 0x20000000
2349 #define MWL8K_CAP_GREENFIELD 0x08000000
2350 #define MWL8K_CAP_AMPDU 0x04000000
2351 #define MWL8K_CAP_RX_STBC 0x01000000
2352 #define MWL8K_CAP_TX_STBC 0x00800000
2353 #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2354 #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2355 #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2356 #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2357 #define MWL8K_CAP_DELAY_BA 0x00003000
2358 #define MWL8K_CAP_MIMO 0x00000200
2359 #define MWL8K_CAP_40MHZ 0x00000100
2360 #define MWL8K_CAP_BAND_MASK 0x00000007
2361 #define MWL8K_CAP_5GHZ 0x00000004
2362 #define MWL8K_CAP_2GHZ4 0x00000001
2365 mwl8k_set_ht_caps(struct ieee80211_hw
*hw
,
2366 struct ieee80211_supported_band
*band
, u32 cap
)
2371 band
->ht_cap
.ht_supported
= 1;
2373 if (cap
& MWL8K_CAP_MAX_AMSDU
)
2374 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
2375 if (cap
& MWL8K_CAP_GREENFIELD
)
2376 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_GRN_FLD
;
2377 if (cap
& MWL8K_CAP_AMPDU
) {
2378 hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
2379 band
->ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
2380 band
->ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_NONE
;
2382 if (cap
& MWL8K_CAP_RX_STBC
)
2383 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_RX_STBC
;
2384 if (cap
& MWL8K_CAP_TX_STBC
)
2385 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
2386 if (cap
& MWL8K_CAP_SHORTGI_40MHZ
)
2387 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
2388 if (cap
& MWL8K_CAP_SHORTGI_20MHZ
)
2389 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
2390 if (cap
& MWL8K_CAP_DELAY_BA
)
2391 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_DELAY_BA
;
2392 if (cap
& MWL8K_CAP_40MHZ
)
2393 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
2395 rx_streams
= hweight32(cap
& MWL8K_CAP_RX_ANTENNA_MASK
);
2396 tx_streams
= hweight32(cap
& MWL8K_CAP_TX_ANTENNA_MASK
);
2398 band
->ht_cap
.mcs
.rx_mask
[0] = 0xff;
2399 if (rx_streams
>= 2)
2400 band
->ht_cap
.mcs
.rx_mask
[1] = 0xff;
2401 if (rx_streams
>= 3)
2402 band
->ht_cap
.mcs
.rx_mask
[2] = 0xff;
2403 band
->ht_cap
.mcs
.rx_mask
[4] = 0x01;
2404 band
->ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
2406 if (rx_streams
!= tx_streams
) {
2407 band
->ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_RX_DIFF
;
2408 band
->ht_cap
.mcs
.tx_params
|= (tx_streams
- 1) <<
2409 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
2414 mwl8k_set_caps(struct ieee80211_hw
*hw
, u32 caps
)
2416 struct mwl8k_priv
*priv
= hw
->priv
;
2421 if ((caps
& MWL8K_CAP_2GHZ4
) || !(caps
& MWL8K_CAP_BAND_MASK
)) {
2422 mwl8k_setup_2ghz_band(hw
);
2423 if (caps
& MWL8K_CAP_MIMO
)
2424 mwl8k_set_ht_caps(hw
, &priv
->band_24
, caps
);
2427 if (caps
& MWL8K_CAP_5GHZ
) {
2428 mwl8k_setup_5ghz_band(hw
);
2429 if (caps
& MWL8K_CAP_MIMO
)
2430 mwl8k_set_ht_caps(hw
, &priv
->band_50
, caps
);
2436 static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw
*hw
)
2438 struct mwl8k_priv
*priv
= hw
->priv
;
2439 struct mwl8k_cmd_get_hw_spec_sta
*cmd
;
2443 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2447 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
2448 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2450 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
2451 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
2452 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rxd_dma
);
2453 cmd
->num_tx_queues
= cpu_to_le32(mwl8k_tx_queues(priv
));
2454 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
2455 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[i
].txd_dma
);
2456 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
2457 cmd
->total_rxd
= cpu_to_le32(MWL8K_RX_DESCS
);
2459 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2462 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
2463 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
2464 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
2465 priv
->hw_rev
= cmd
->hw_rev
;
2466 mwl8k_set_caps(hw
, le32_to_cpu(cmd
->caps
));
2467 priv
->ap_macids_supported
= 0x00000000;
2468 priv
->sta_macids_supported
= 0x00000001;
2476 * CMD_GET_HW_SPEC (AP version).
2478 struct mwl8k_cmd_get_hw_spec_ap
{
2479 struct mwl8k_cmd_pkt header
;
2481 __u8 host_interface
;
2484 __u8 perm_addr
[ETH_ALEN
];
2495 __le32 fw_api_version
;
2497 __le32 num_of_ampdu_queues
;
2498 __le32 wcbbase_ampdu
[MWL8K_MAX_AMPDU_QUEUES
];
2501 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw
*hw
)
2503 struct mwl8k_priv
*priv
= hw
->priv
;
2504 struct mwl8k_cmd_get_hw_spec_ap
*cmd
;
2508 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2512 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_HW_SPEC
);
2513 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2515 memset(cmd
->perm_addr
, 0xff, sizeof(cmd
->perm_addr
));
2516 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
2518 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2523 api_version
= le32_to_cpu(cmd
->fw_api_version
);
2524 if (priv
->device_info
->fw_api_ap
!= api_version
) {
2525 printk(KERN_ERR
"%s: Unsupported fw API version for %s."
2526 " Expected %d got %d.\n", MWL8K_NAME
,
2527 priv
->device_info
->part_name
,
2528 priv
->device_info
->fw_api_ap
,
2533 SET_IEEE80211_PERM_ADDR(hw
, cmd
->perm_addr
);
2534 priv
->num_mcaddrs
= le16_to_cpu(cmd
->num_mcaddrs
);
2535 priv
->fw_rev
= le32_to_cpu(cmd
->fw_rev
);
2536 priv
->hw_rev
= cmd
->hw_rev
;
2537 mwl8k_set_caps(hw
, le32_to_cpu(cmd
->caps
));
2538 priv
->ap_macids_supported
= 0x000000ff;
2539 priv
->sta_macids_supported
= 0x00000100;
2540 priv
->num_ampdu_queues
= le32_to_cpu(cmd
->num_of_ampdu_queues
);
2541 if (priv
->num_ampdu_queues
> MWL8K_MAX_AMPDU_QUEUES
) {
2542 wiphy_warn(hw
->wiphy
, "fw reported %d ampdu queues"
2543 " but we only support %d.\n",
2544 priv
->num_ampdu_queues
,
2545 MWL8K_MAX_AMPDU_QUEUES
);
2546 priv
->num_ampdu_queues
= MWL8K_MAX_AMPDU_QUEUES
;
2548 off
= le32_to_cpu(cmd
->rxwrptr
) & 0xffff;
2549 iowrite32(priv
->rxq
[0].rxd_dma
, priv
->sram
+ off
);
2551 off
= le32_to_cpu(cmd
->rxrdptr
) & 0xffff;
2552 iowrite32(priv
->rxq
[0].rxd_dma
, priv
->sram
+ off
);
2554 priv
->txq_offset
[0] = le32_to_cpu(cmd
->wcbbase0
) & 0xffff;
2555 priv
->txq_offset
[1] = le32_to_cpu(cmd
->wcbbase1
) & 0xffff;
2556 priv
->txq_offset
[2] = le32_to_cpu(cmd
->wcbbase2
) & 0xffff;
2557 priv
->txq_offset
[3] = le32_to_cpu(cmd
->wcbbase3
) & 0xffff;
2559 for (i
= 0; i
< priv
->num_ampdu_queues
; i
++)
2560 priv
->txq_offset
[i
+ MWL8K_TX_WMM_QUEUES
] =
2561 le32_to_cpu(cmd
->wcbbase_ampdu
[i
]) & 0xffff;
2572 struct mwl8k_cmd_set_hw_spec
{
2573 struct mwl8k_cmd_pkt header
;
2575 __u8 host_interface
;
2577 __u8 perm_addr
[ETH_ALEN
];
2582 __le32 rx_queue_ptr
;
2583 __le32 num_tx_queues
;
2584 __le32 tx_queue_ptrs
[MWL8K_MAX_TX_QUEUES
];
2586 __le32 num_tx_desc_per_queue
;
2590 /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2591 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2592 * the packets that are queued for more than 500ms, will be dropped in the
2593 * hardware. This helps minimizing the issues caused due to head-of-line
2594 * blocking where a slow client can hog the bandwidth and affect traffic to a
2597 #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
2598 #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
2599 #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2600 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2601 #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
2603 static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw
*hw
)
2605 struct mwl8k_priv
*priv
= hw
->priv
;
2606 struct mwl8k_cmd_set_hw_spec
*cmd
;
2610 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2614 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_HW_SPEC
);
2615 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2617 cmd
->ps_cookie
= cpu_to_le32(priv
->cookie_dma
);
2618 cmd
->rx_queue_ptr
= cpu_to_le32(priv
->rxq
[0].rxd_dma
);
2619 cmd
->num_tx_queues
= cpu_to_le32(mwl8k_tx_queues(priv
));
2622 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2623 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2624 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2625 * priority is interpreted the right way in firmware.
2627 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++) {
2628 int j
= mwl8k_tx_queues(priv
) - 1 - i
;
2629 cmd
->tx_queue_ptrs
[i
] = cpu_to_le32(priv
->txq
[j
].txd_dma
);
2632 cmd
->flags
= cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT
|
2633 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP
|
2634 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON
|
2635 MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY
|
2636 MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR
);
2637 cmd
->num_tx_desc_per_queue
= cpu_to_le32(MWL8K_TX_DESCS
);
2638 cmd
->total_rxd
= cpu_to_le32(MWL8K_RX_DESCS
);
2640 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2647 * CMD_MAC_MULTICAST_ADR.
2649 struct mwl8k_cmd_mac_multicast_adr
{
2650 struct mwl8k_cmd_pkt header
;
2653 __u8 addr
[0][ETH_ALEN
];
2656 #define MWL8K_ENABLE_RX_DIRECTED 0x0001
2657 #define MWL8K_ENABLE_RX_MULTICAST 0x0002
2658 #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2659 #define MWL8K_ENABLE_RX_BROADCAST 0x0008
2661 static struct mwl8k_cmd_pkt
*
2662 __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw
*hw
, int allmulti
,
2663 struct netdev_hw_addr_list
*mc_list
)
2665 struct mwl8k_priv
*priv
= hw
->priv
;
2666 struct mwl8k_cmd_mac_multicast_adr
*cmd
;
2671 mc_count
= netdev_hw_addr_list_count(mc_list
);
2673 if (allmulti
|| mc_count
> priv
->num_mcaddrs
) {
2678 size
= sizeof(*cmd
) + mc_count
* ETH_ALEN
;
2680 cmd
= kzalloc(size
, GFP_ATOMIC
);
2684 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR
);
2685 cmd
->header
.length
= cpu_to_le16(size
);
2686 cmd
->action
= cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED
|
2687 MWL8K_ENABLE_RX_BROADCAST
);
2690 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST
);
2691 } else if (mc_count
) {
2692 struct netdev_hw_addr
*ha
;
2695 cmd
->action
|= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST
);
2696 cmd
->numaddr
= cpu_to_le16(mc_count
);
2697 netdev_hw_addr_list_for_each(ha
, mc_list
) {
2698 memcpy(cmd
->addr
[i
], ha
->addr
, ETH_ALEN
);
2702 return &cmd
->header
;
2708 struct mwl8k_cmd_get_stat
{
2709 struct mwl8k_cmd_pkt header
;
2713 #define MWL8K_STAT_ACK_FAILURE 9
2714 #define MWL8K_STAT_RTS_FAILURE 12
2715 #define MWL8K_STAT_FCS_ERROR 24
2716 #define MWL8K_STAT_RTS_SUCCESS 11
2718 static int mwl8k_cmd_get_stat(struct ieee80211_hw
*hw
,
2719 struct ieee80211_low_level_stats
*stats
)
2721 struct mwl8k_cmd_get_stat
*cmd
;
2724 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2728 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_STAT
);
2729 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2731 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2733 stats
->dot11ACKFailureCount
=
2734 le32_to_cpu(cmd
->stats
[MWL8K_STAT_ACK_FAILURE
]);
2735 stats
->dot11RTSFailureCount
=
2736 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_FAILURE
]);
2737 stats
->dot11FCSErrorCount
=
2738 le32_to_cpu(cmd
->stats
[MWL8K_STAT_FCS_ERROR
]);
2739 stats
->dot11RTSSuccessCount
=
2740 le32_to_cpu(cmd
->stats
[MWL8K_STAT_RTS_SUCCESS
]);
2748 * CMD_RADIO_CONTROL.
2750 struct mwl8k_cmd_radio_control
{
2751 struct mwl8k_cmd_pkt header
;
2758 mwl8k_cmd_radio_control(struct ieee80211_hw
*hw
, bool enable
, bool force
)
2760 struct mwl8k_priv
*priv
= hw
->priv
;
2761 struct mwl8k_cmd_radio_control
*cmd
;
2764 if (enable
== priv
->radio_on
&& !force
)
2767 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2771 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RADIO_CONTROL
);
2772 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2773 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2774 cmd
->control
= cpu_to_le16(priv
->radio_short_preamble
? 3 : 1);
2775 cmd
->radio_on
= cpu_to_le16(enable
? 0x0001 : 0x0000);
2777 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2781 priv
->radio_on
= enable
;
2786 static int mwl8k_cmd_radio_disable(struct ieee80211_hw
*hw
)
2788 return mwl8k_cmd_radio_control(hw
, 0, 0);
2791 static int mwl8k_cmd_radio_enable(struct ieee80211_hw
*hw
)
2793 return mwl8k_cmd_radio_control(hw
, 1, 0);
2797 mwl8k_set_radio_preamble(struct ieee80211_hw
*hw
, bool short_preamble
)
2799 struct mwl8k_priv
*priv
= hw
->priv
;
2801 priv
->radio_short_preamble
= short_preamble
;
2803 return mwl8k_cmd_radio_control(hw
, 1, 1);
2809 #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
2811 struct mwl8k_cmd_rf_tx_power
{
2812 struct mwl8k_cmd_pkt header
;
2814 __le16 support_level
;
2815 __le16 current_level
;
2817 __le16 power_level_list
[MWL8K_RF_TX_POWER_LEVEL_TOTAL
];
2820 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw
*hw
, int dBm
)
2822 struct mwl8k_cmd_rf_tx_power
*cmd
;
2825 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2829 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_TX_POWER
);
2830 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2831 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
2832 cmd
->support_level
= cpu_to_le16(dBm
);
2834 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2843 #define MWL8K_TX_POWER_LEVEL_TOTAL 12
2845 struct mwl8k_cmd_tx_power
{
2846 struct mwl8k_cmd_pkt header
;
2852 __le16 power_level_list
[MWL8K_TX_POWER_LEVEL_TOTAL
];
2855 static int mwl8k_cmd_tx_power(struct ieee80211_hw
*hw
,
2856 struct ieee80211_conf
*conf
,
2859 struct ieee80211_channel
*channel
= conf
->chandef
.chan
;
2860 enum nl80211_channel_type channel_type
=
2861 cfg80211_get_chandef_type(&conf
->chandef
);
2862 struct mwl8k_cmd_tx_power
*cmd
;
2866 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2870 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_TX_POWER
);
2871 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2872 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET_LIST
);
2874 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2875 cmd
->band
= cpu_to_le16(0x1);
2876 else if (channel
->band
== IEEE80211_BAND_5GHZ
)
2877 cmd
->band
= cpu_to_le16(0x4);
2879 cmd
->channel
= cpu_to_le16(channel
->hw_value
);
2881 if (channel_type
== NL80211_CHAN_NO_HT
||
2882 channel_type
== NL80211_CHAN_HT20
) {
2883 cmd
->bw
= cpu_to_le16(0x2);
2885 cmd
->bw
= cpu_to_le16(0x4);
2886 if (channel_type
== NL80211_CHAN_HT40MINUS
)
2887 cmd
->sub_ch
= cpu_to_le16(0x3);
2888 else if (channel_type
== NL80211_CHAN_HT40PLUS
)
2889 cmd
->sub_ch
= cpu_to_le16(0x1);
2892 for (i
= 0; i
< MWL8K_TX_POWER_LEVEL_TOTAL
; i
++)
2893 cmd
->power_level_list
[i
] = cpu_to_le16(pwr
);
2895 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2904 struct mwl8k_cmd_rf_antenna
{
2905 struct mwl8k_cmd_pkt header
;
2910 #define MWL8K_RF_ANTENNA_RX 1
2911 #define MWL8K_RF_ANTENNA_TX 2
2914 mwl8k_cmd_rf_antenna(struct ieee80211_hw
*hw
, int antenna
, int mask
)
2916 struct mwl8k_cmd_rf_antenna
*cmd
;
2919 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2923 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RF_ANTENNA
);
2924 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2925 cmd
->antenna
= cpu_to_le16(antenna
);
2926 cmd
->mode
= cpu_to_le16(mask
);
2928 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2937 struct mwl8k_cmd_set_beacon
{
2938 struct mwl8k_cmd_pkt header
;
2943 static int mwl8k_cmd_set_beacon(struct ieee80211_hw
*hw
,
2944 struct ieee80211_vif
*vif
, u8
*beacon
, int len
)
2946 struct mwl8k_cmd_set_beacon
*cmd
;
2949 cmd
= kzalloc(sizeof(*cmd
) + len
, GFP_KERNEL
);
2953 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_BEACON
);
2954 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
) + len
);
2955 cmd
->beacon_len
= cpu_to_le16(len
);
2956 memcpy(cmd
->beacon
, beacon
, len
);
2958 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
2967 struct mwl8k_cmd_set_pre_scan
{
2968 struct mwl8k_cmd_pkt header
;
2971 static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw
*hw
)
2973 struct mwl8k_cmd_set_pre_scan
*cmd
;
2976 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2980 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN
);
2981 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
2983 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
2990 * CMD_SET_POST_SCAN.
2992 struct mwl8k_cmd_set_post_scan
{
2993 struct mwl8k_cmd_pkt header
;
2995 __u8 bssid
[ETH_ALEN
];
2999 mwl8k_cmd_set_post_scan(struct ieee80211_hw
*hw
, const __u8
*mac
)
3001 struct mwl8k_cmd_set_post_scan
*cmd
;
3004 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3008 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_POST_SCAN
);
3009 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3011 memcpy(cmd
->bssid
, mac
, ETH_ALEN
);
3013 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3020 * CMD_SET_RF_CHANNEL.
3022 struct mwl8k_cmd_set_rf_channel
{
3023 struct mwl8k_cmd_pkt header
;
3025 __u8 current_channel
;
3026 __le32 channel_flags
;
3029 static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw
*hw
,
3030 struct ieee80211_conf
*conf
)
3032 struct ieee80211_channel
*channel
= conf
->chandef
.chan
;
3033 enum nl80211_channel_type channel_type
=
3034 cfg80211_get_chandef_type(&conf
->chandef
);
3035 struct mwl8k_cmd_set_rf_channel
*cmd
;
3038 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3042 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL
);
3043 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3044 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
3045 cmd
->current_channel
= channel
->hw_value
;
3047 if (channel
->band
== IEEE80211_BAND_2GHZ
)
3048 cmd
->channel_flags
|= cpu_to_le32(0x00000001);
3049 else if (channel
->band
== IEEE80211_BAND_5GHZ
)
3050 cmd
->channel_flags
|= cpu_to_le32(0x00000004);
3052 if (channel_type
== NL80211_CHAN_NO_HT
||
3053 channel_type
== NL80211_CHAN_HT20
)
3054 cmd
->channel_flags
|= cpu_to_le32(0x00000080);
3055 else if (channel_type
== NL80211_CHAN_HT40MINUS
)
3056 cmd
->channel_flags
|= cpu_to_le32(0x000001900);
3057 else if (channel_type
== NL80211_CHAN_HT40PLUS
)
3058 cmd
->channel_flags
|= cpu_to_le32(0x000000900);
3060 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3069 #define MWL8K_FRAME_PROT_DISABLED 0x00
3070 #define MWL8K_FRAME_PROT_11G 0x07
3071 #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
3072 #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
3074 struct mwl8k_cmd_update_set_aid
{
3075 struct mwl8k_cmd_pkt header
;
3078 /* AP's MAC address (BSSID) */
3079 __u8 bssid
[ETH_ALEN
];
3080 __le16 protection_mode
;
3081 __u8 supp_rates
[14];
3084 static void legacy_rate_mask_to_array(u8
*rates
, u32 mask
)
3090 * Clear nonstandard rate 4.
3094 for (i
= 0, j
= 0; i
< 13; i
++) {
3095 if (mask
& (1 << i
))
3096 rates
[j
++] = mwl8k_rates_24
[i
].hw_value
;
3101 mwl8k_cmd_set_aid(struct ieee80211_hw
*hw
,
3102 struct ieee80211_vif
*vif
, u32 legacy_rate_mask
)
3104 struct mwl8k_cmd_update_set_aid
*cmd
;
3108 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3112 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_AID
);
3113 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3114 cmd
->aid
= cpu_to_le16(vif
->bss_conf
.aid
);
3115 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
3117 if (vif
->bss_conf
.use_cts_prot
) {
3118 prot_mode
= MWL8K_FRAME_PROT_11G
;
3120 switch (vif
->bss_conf
.ht_operation_mode
&
3121 IEEE80211_HT_OP_MODE_PROTECTION
) {
3122 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
3123 prot_mode
= MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY
;
3125 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
3126 prot_mode
= MWL8K_FRAME_PROT_11N_HT_ALL
;
3129 prot_mode
= MWL8K_FRAME_PROT_DISABLED
;
3133 cmd
->protection_mode
= cpu_to_le16(prot_mode
);
3135 legacy_rate_mask_to_array(cmd
->supp_rates
, legacy_rate_mask
);
3137 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3146 struct mwl8k_cmd_set_rate
{
3147 struct mwl8k_cmd_pkt header
;
3148 __u8 legacy_rates
[14];
3150 /* Bitmap for supported MCS codes. */
3156 mwl8k_cmd_set_rate(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
3157 u32 legacy_rate_mask
, u8
*mcs_rates
)
3159 struct mwl8k_cmd_set_rate
*cmd
;
3162 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3166 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATE
);
3167 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3168 legacy_rate_mask_to_array(cmd
->legacy_rates
, legacy_rate_mask
);
3169 memcpy(cmd
->mcs_set
, mcs_rates
, 16);
3171 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3178 * CMD_FINALIZE_JOIN.
3180 #define MWL8K_FJ_BEACON_MAXLEN 128
3182 struct mwl8k_cmd_finalize_join
{
3183 struct mwl8k_cmd_pkt header
;
3184 __le32 sleep_interval
; /* Number of beacon periods to sleep */
3185 __u8 beacon_data
[MWL8K_FJ_BEACON_MAXLEN
];
3188 static int mwl8k_cmd_finalize_join(struct ieee80211_hw
*hw
, void *frame
,
3189 int framelen
, int dtim
)
3191 struct mwl8k_cmd_finalize_join
*cmd
;
3192 struct ieee80211_mgmt
*payload
= frame
;
3196 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3200 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN
);
3201 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3202 cmd
->sleep_interval
= cpu_to_le32(dtim
? dtim
: 1);
3204 payload_len
= framelen
- ieee80211_hdrlen(payload
->frame_control
);
3205 if (payload_len
< 0)
3207 else if (payload_len
> MWL8K_FJ_BEACON_MAXLEN
)
3208 payload_len
= MWL8K_FJ_BEACON_MAXLEN
;
3210 memcpy(cmd
->beacon_data
, &payload
->u
.beacon
, payload_len
);
3212 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3219 * CMD_SET_RTS_THRESHOLD.
3221 struct mwl8k_cmd_set_rts_threshold
{
3222 struct mwl8k_cmd_pkt header
;
3228 mwl8k_cmd_set_rts_threshold(struct ieee80211_hw
*hw
, int rts_thresh
)
3230 struct mwl8k_cmd_set_rts_threshold
*cmd
;
3233 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3237 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD
);
3238 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3239 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
3240 cmd
->threshold
= cpu_to_le16(rts_thresh
);
3242 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3251 struct mwl8k_cmd_set_slot
{
3252 struct mwl8k_cmd_pkt header
;
3257 static int mwl8k_cmd_set_slot(struct ieee80211_hw
*hw
, bool short_slot_time
)
3259 struct mwl8k_cmd_set_slot
*cmd
;
3262 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3266 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_SLOT
);
3267 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3268 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
3269 cmd
->short_slot
= short_slot_time
;
3271 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3278 * CMD_SET_EDCA_PARAMS.
3280 struct mwl8k_cmd_set_edca_params
{
3281 struct mwl8k_cmd_pkt header
;
3283 /* See MWL8K_SET_EDCA_XXX below */
3286 /* TX opportunity in units of 32 us */
3291 /* Log exponent of max contention period: 0...15 */
3294 /* Log exponent of min contention period: 0...15 */
3297 /* Adaptive interframe spacing in units of 32us */
3300 /* TX queue to configure */
3304 /* Log exponent of max contention period: 0...15 */
3307 /* Log exponent of min contention period: 0...15 */
3310 /* Adaptive interframe spacing in units of 32us */
3313 /* TX queue to configure */
3319 #define MWL8K_SET_EDCA_CW 0x01
3320 #define MWL8K_SET_EDCA_TXOP 0x02
3321 #define MWL8K_SET_EDCA_AIFS 0x04
3323 #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3324 MWL8K_SET_EDCA_TXOP | \
3325 MWL8K_SET_EDCA_AIFS)
3328 mwl8k_cmd_set_edca_params(struct ieee80211_hw
*hw
, __u8 qnum
,
3329 __u16 cw_min
, __u16 cw_max
,
3330 __u8 aifs
, __u16 txop
)
3332 struct mwl8k_priv
*priv
= hw
->priv
;
3333 struct mwl8k_cmd_set_edca_params
*cmd
;
3336 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3340 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS
);
3341 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3342 cmd
->action
= cpu_to_le16(MWL8K_SET_EDCA_ALL
);
3343 cmd
->txop
= cpu_to_le16(txop
);
3345 cmd
->ap
.log_cw_max
= cpu_to_le32(ilog2(cw_max
+ 1));
3346 cmd
->ap
.log_cw_min
= cpu_to_le32(ilog2(cw_min
+ 1));
3347 cmd
->ap
.aifs
= aifs
;
3350 cmd
->sta
.log_cw_max
= (u8
)ilog2(cw_max
+ 1);
3351 cmd
->sta
.log_cw_min
= (u8
)ilog2(cw_min
+ 1);
3352 cmd
->sta
.aifs
= aifs
;
3353 cmd
->sta
.txq
= qnum
;
3356 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3365 struct mwl8k_cmd_set_wmm_mode
{
3366 struct mwl8k_cmd_pkt header
;
3370 static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw
*hw
, bool enable
)
3372 struct mwl8k_priv
*priv
= hw
->priv
;
3373 struct mwl8k_cmd_set_wmm_mode
*cmd
;
3376 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3380 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_WMM_MODE
);
3381 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3382 cmd
->action
= cpu_to_le16(!!enable
);
3384 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3388 priv
->wmm_enabled
= enable
;
3396 struct mwl8k_cmd_mimo_config
{
3397 struct mwl8k_cmd_pkt header
;
3399 __u8 rx_antenna_map
;
3400 __u8 tx_antenna_map
;
3403 static int mwl8k_cmd_mimo_config(struct ieee80211_hw
*hw
, __u8 rx
, __u8 tx
)
3405 struct mwl8k_cmd_mimo_config
*cmd
;
3408 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3412 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_MIMO_CONFIG
);
3413 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3414 cmd
->action
= cpu_to_le32((u32
)MWL8K_CMD_SET
);
3415 cmd
->rx_antenna_map
= rx
;
3416 cmd
->tx_antenna_map
= tx
;
3418 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3425 * CMD_USE_FIXED_RATE (STA version).
3427 struct mwl8k_cmd_use_fixed_rate_sta
{
3428 struct mwl8k_cmd_pkt header
;
3430 __le32 allow_rate_drop
;
3434 __le32 enable_retry
;
3443 #define MWL8K_USE_AUTO_RATE 0x0002
3444 #define MWL8K_UCAST_RATE 0
3446 static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw
*hw
)
3448 struct mwl8k_cmd_use_fixed_rate_sta
*cmd
;
3451 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3455 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
3456 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3457 cmd
->action
= cpu_to_le32(MWL8K_USE_AUTO_RATE
);
3458 cmd
->rate_type
= cpu_to_le32(MWL8K_UCAST_RATE
);
3460 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3467 * CMD_USE_FIXED_RATE (AP version).
3469 struct mwl8k_cmd_use_fixed_rate_ap
{
3470 struct mwl8k_cmd_pkt header
;
3472 __le32 allow_rate_drop
;
3474 struct mwl8k_rate_entry_ap
{
3476 __le32 enable_retry
;
3481 u8 multicast_rate_type
;
3486 mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw
*hw
, int mcast
, int mgmt
)
3488 struct mwl8k_cmd_use_fixed_rate_ap
*cmd
;
3491 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3495 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE
);
3496 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3497 cmd
->action
= cpu_to_le32(MWL8K_USE_AUTO_RATE
);
3498 cmd
->multicast_rate
= mcast
;
3499 cmd
->management_rate
= mgmt
;
3501 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3508 * CMD_ENABLE_SNIFFER.
3510 struct mwl8k_cmd_enable_sniffer
{
3511 struct mwl8k_cmd_pkt header
;
3515 static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw
*hw
, bool enable
)
3517 struct mwl8k_cmd_enable_sniffer
*cmd
;
3520 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3524 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER
);
3525 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3526 cmd
->action
= cpu_to_le32(!!enable
);
3528 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3534 struct mwl8k_cmd_update_mac_addr
{
3535 struct mwl8k_cmd_pkt header
;
3539 __u8 mac_addr
[ETH_ALEN
];
3541 __u8 mac_addr
[ETH_ALEN
];
3545 #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3546 #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3547 #define MWL8K_MAC_TYPE_PRIMARY_AP 2
3548 #define MWL8K_MAC_TYPE_SECONDARY_AP 3
3550 static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw
*hw
,
3551 struct ieee80211_vif
*vif
, u8
*mac
, bool set
)
3553 struct mwl8k_priv
*priv
= hw
->priv
;
3554 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3555 struct mwl8k_cmd_update_mac_addr
*cmd
;
3559 mac_type
= MWL8K_MAC_TYPE_PRIMARY_AP
;
3560 if (vif
!= NULL
&& vif
->type
== NL80211_IFTYPE_STATION
) {
3561 if (mwl8k_vif
->macid
+ 1 == ffs(priv
->sta_macids_supported
))
3563 mac_type
= MWL8K_MAC_TYPE_SECONDARY_CLIENT
;
3565 mac_type
= MWL8K_MAC_TYPE_PRIMARY_CLIENT
;
3567 mac_type
= MWL8K_MAC_TYPE_SECONDARY_CLIENT
;
3568 } else if (vif
!= NULL
&& vif
->type
== NL80211_IFTYPE_AP
) {
3569 if (mwl8k_vif
->macid
+ 1 == ffs(priv
->ap_macids_supported
))
3570 mac_type
= MWL8K_MAC_TYPE_PRIMARY_AP
;
3572 mac_type
= MWL8K_MAC_TYPE_SECONDARY_AP
;
3575 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3580 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR
);
3582 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR
);
3584 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3586 cmd
->mbss
.mac_type
= cpu_to_le16(mac_type
);
3587 memcpy(cmd
->mbss
.mac_addr
, mac
, ETH_ALEN
);
3589 memcpy(cmd
->mac_addr
, mac
, ETH_ALEN
);
3592 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3599 * MWL8K_CMD_SET_MAC_ADDR.
3601 static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw
*hw
,
3602 struct ieee80211_vif
*vif
, u8
*mac
)
3604 return mwl8k_cmd_update_mac_addr(hw
, vif
, mac
, true);
3608 * MWL8K_CMD_DEL_MAC_ADDR.
3610 static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw
*hw
,
3611 struct ieee80211_vif
*vif
, u8
*mac
)
3613 return mwl8k_cmd_update_mac_addr(hw
, vif
, mac
, false);
3617 * CMD_SET_RATEADAPT_MODE.
3619 struct mwl8k_cmd_set_rate_adapt_mode
{
3620 struct mwl8k_cmd_pkt header
;
3625 static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw
*hw
, __u16 mode
)
3627 struct mwl8k_cmd_set_rate_adapt_mode
*cmd
;
3630 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3634 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE
);
3635 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3636 cmd
->action
= cpu_to_le16(MWL8K_CMD_SET
);
3637 cmd
->mode
= cpu_to_le16(mode
);
3639 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3646 * CMD_GET_WATCHDOG_BITMAP.
3648 struct mwl8k_cmd_get_watchdog_bitmap
{
3649 struct mwl8k_cmd_pkt header
;
3653 static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw
*hw
, u8
*bitmap
)
3655 struct mwl8k_cmd_get_watchdog_bitmap
*cmd
;
3658 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3662 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP
);
3663 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3665 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
3667 *bitmap
= cmd
->bitmap
;
3674 #define MWL8K_WMM_QUEUE_NUMBER 3
3676 static void mwl8k_destroy_ba(struct ieee80211_hw
*hw
,
3679 static void mwl8k_watchdog_ba_events(struct work_struct
*work
)
3682 u8 bitmap
= 0, stream_index
;
3683 struct mwl8k_ampdu_stream
*streams
;
3684 struct mwl8k_priv
*priv
=
3685 container_of(work
, struct mwl8k_priv
, watchdog_ba_handle
);
3686 struct ieee80211_hw
*hw
= priv
->hw
;
3692 rc
= mwl8k_cmd_get_watchdog_bitmap(priv
->hw
, &bitmap
);
3696 spin_lock(&priv
->stream_lock
);
3698 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
3699 for (i
= 0; i
< TOTAL_HW_TX_QUEUES
; i
++) {
3700 if (bitmap
& (1 << i
)) {
3701 stream_index
= (i
+ MWL8K_WMM_QUEUE_NUMBER
) %
3703 streams
= &priv
->ampdu
[stream_index
];
3704 if (streams
->state
== AMPDU_STREAM_ACTIVE
) {
3705 ieee80211_stop_tx_ba_session(streams
->sta
,
3707 spin_unlock(&priv
->stream_lock
);
3708 mwl8k_destroy_ba(hw
, stream_index
);
3709 spin_lock(&priv
->stream_lock
);
3714 spin_unlock(&priv
->stream_lock
);
3716 atomic_dec(&priv
->watchdog_event_pending
);
3717 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3718 iowrite32((status
| MWL8K_A2H_INT_BA_WATCHDOG
),
3719 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
3720 mwl8k_fw_unlock(hw
);
3728 struct mwl8k_cmd_bss_start
{
3729 struct mwl8k_cmd_pkt header
;
3733 static int mwl8k_cmd_bss_start(struct ieee80211_hw
*hw
,
3734 struct ieee80211_vif
*vif
, int enable
)
3736 struct mwl8k_cmd_bss_start
*cmd
;
3737 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
3738 struct mwl8k_priv
*priv
= hw
->priv
;
3741 if (enable
&& (priv
->running_bsses
& (1 << mwl8k_vif
->macid
)))
3744 if (!enable
&& !(priv
->running_bsses
& (1 << mwl8k_vif
->macid
)))
3747 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3751 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BSS_START
);
3752 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3753 cmd
->enable
= cpu_to_le32(enable
);
3755 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3760 priv
->running_bsses
|= (1 << mwl8k_vif
->macid
);
3762 priv
->running_bsses
&= ~(1 << mwl8k_vif
->macid
);
3767 static void mwl8k_enable_bsses(struct ieee80211_hw
*hw
, bool enable
, u32 bitmap
)
3769 struct mwl8k_priv
*priv
= hw
->priv
;
3770 struct mwl8k_vif
*mwl8k_vif
, *tmp_vif
;
3771 struct ieee80211_vif
*vif
;
3773 list_for_each_entry_safe(mwl8k_vif
, tmp_vif
, &priv
->vif_list
, list
) {
3774 vif
= mwl8k_vif
->vif
;
3776 if (!(bitmap
& (1 << mwl8k_vif
->macid
)))
3779 if (vif
->type
== NL80211_IFTYPE_AP
)
3780 mwl8k_cmd_bss_start(hw
, vif
, enable
);
3788 * UPSTREAM is tx direction
3790 #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3791 #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3793 enum ba_stream_action_type
{
3802 struct mwl8k_create_ba_stream
{
3807 u8 peer_mac_addr
[6];
3813 u8 reset_seq_no_flag
;
3815 u8 sta_src_mac_addr
[6];
3818 struct mwl8k_destroy_ba_stream
{
3823 struct mwl8k_cmd_bastream
{
3824 struct mwl8k_cmd_pkt header
;
3827 struct mwl8k_create_ba_stream create_params
;
3828 struct mwl8k_destroy_ba_stream destroy_params
;
3833 mwl8k_check_ba(struct ieee80211_hw
*hw
, struct mwl8k_ampdu_stream
*stream
,
3834 struct ieee80211_vif
*vif
)
3836 struct mwl8k_cmd_bastream
*cmd
;
3839 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3843 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BASTREAM
);
3844 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3846 cmd
->action
= cpu_to_le32(MWL8K_BA_CHECK
);
3848 cmd
->create_params
.queue_id
= stream
->idx
;
3849 memcpy(&cmd
->create_params
.peer_mac_addr
[0], stream
->sta
->addr
,
3851 cmd
->create_params
.tid
= stream
->tid
;
3853 cmd
->create_params
.flags
=
3854 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE
) |
3855 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM
);
3857 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3865 mwl8k_create_ba(struct ieee80211_hw
*hw
, struct mwl8k_ampdu_stream
*stream
,
3866 u8 buf_size
, struct ieee80211_vif
*vif
)
3868 struct mwl8k_cmd_bastream
*cmd
;
3871 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3876 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BASTREAM
);
3877 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3879 cmd
->action
= cpu_to_le32(MWL8K_BA_CREATE
);
3881 cmd
->create_params
.bar_thrs
= cpu_to_le32((u32
)buf_size
);
3882 cmd
->create_params
.window_size
= cpu_to_le32((u32
)buf_size
);
3883 cmd
->create_params
.queue_id
= stream
->idx
;
3885 memcpy(cmd
->create_params
.peer_mac_addr
, stream
->sta
->addr
, ETH_ALEN
);
3886 cmd
->create_params
.tid
= stream
->tid
;
3887 cmd
->create_params
.curr_seq_no
= cpu_to_le16(0);
3888 cmd
->create_params
.reset_seq_no_flag
= 1;
3890 cmd
->create_params
.param_info
=
3891 (stream
->sta
->ht_cap
.ampdu_factor
&
3892 IEEE80211_HT_AMPDU_PARM_FACTOR
) |
3893 ((stream
->sta
->ht_cap
.ampdu_density
<< 2) &
3894 IEEE80211_HT_AMPDU_PARM_DENSITY
);
3896 cmd
->create_params
.flags
=
3897 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE
|
3898 BASTREAM_FLAG_DIRECTION_UPSTREAM
);
3900 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3902 wiphy_debug(hw
->wiphy
, "Created a BA stream for %pM : tid %d\n",
3903 stream
->sta
->addr
, stream
->tid
);
3909 static void mwl8k_destroy_ba(struct ieee80211_hw
*hw
,
3912 struct mwl8k_cmd_bastream
*cmd
;
3914 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3918 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_BASTREAM
);
3919 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3920 cmd
->action
= cpu_to_le32(MWL8K_BA_DESTROY
);
3922 cmd
->destroy_params
.ba_context
= cpu_to_le32(idx
);
3923 mwl8k_post_cmd(hw
, &cmd
->header
);
3925 wiphy_debug(hw
->wiphy
, "Deleted BA stream index %d\n", idx
);
3933 struct mwl8k_cmd_set_new_stn
{
3934 struct mwl8k_cmd_pkt header
;
3940 __le32 legacy_rates
;
3943 __le16 ht_capabilities_info
;
3944 __u8 mac_ht_param_info
;
3946 __u8 control_channel
;
3955 #define MWL8K_STA_ACTION_ADD 0
3956 #define MWL8K_STA_ACTION_REMOVE 2
3958 static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw
*hw
,
3959 struct ieee80211_vif
*vif
,
3960 struct ieee80211_sta
*sta
)
3962 struct mwl8k_cmd_set_new_stn
*cmd
;
3966 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
3970 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
3971 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
3972 cmd
->aid
= cpu_to_le16(sta
->aid
);
3973 memcpy(cmd
->mac_addr
, sta
->addr
, ETH_ALEN
);
3974 cmd
->stn_id
= cpu_to_le16(sta
->aid
);
3975 cmd
->action
= cpu_to_le16(MWL8K_STA_ACTION_ADD
);
3976 if (hw
->conf
.chandef
.chan
->band
== IEEE80211_BAND_2GHZ
)
3977 rates
= sta
->supp_rates
[IEEE80211_BAND_2GHZ
];
3979 rates
= sta
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
3980 cmd
->legacy_rates
= cpu_to_le32(rates
);
3981 if (sta
->ht_cap
.ht_supported
) {
3982 cmd
->ht_rates
[0] = sta
->ht_cap
.mcs
.rx_mask
[0];
3983 cmd
->ht_rates
[1] = sta
->ht_cap
.mcs
.rx_mask
[1];
3984 cmd
->ht_rates
[2] = sta
->ht_cap
.mcs
.rx_mask
[2];
3985 cmd
->ht_rates
[3] = sta
->ht_cap
.mcs
.rx_mask
[3];
3986 cmd
->ht_capabilities_info
= cpu_to_le16(sta
->ht_cap
.cap
);
3987 cmd
->mac_ht_param_info
= (sta
->ht_cap
.ampdu_factor
& 3) |
3988 ((sta
->ht_cap
.ampdu_density
& 7) << 2);
3989 cmd
->is_qos_sta
= 1;
3992 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
3998 static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw
*hw
,
3999 struct ieee80211_vif
*vif
)
4001 struct mwl8k_cmd_set_new_stn
*cmd
;
4004 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4008 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
4009 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4010 memcpy(cmd
->mac_addr
, vif
->addr
, ETH_ALEN
);
4012 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
4018 static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw
*hw
,
4019 struct ieee80211_vif
*vif
, u8
*addr
)
4021 struct mwl8k_cmd_set_new_stn
*cmd
;
4022 struct mwl8k_priv
*priv
= hw
->priv
;
4026 spin_lock(&priv
->stream_lock
);
4027 /* Destroy any active ampdu streams for this sta */
4028 for (i
= 0; i
< MWL8K_NUM_AMPDU_STREAMS
; i
++) {
4029 struct mwl8k_ampdu_stream
*s
;
4030 s
= &priv
->ampdu
[i
];
4031 if (s
->state
!= AMPDU_NO_STREAM
) {
4032 if (memcmp(s
->sta
->addr
, addr
, ETH_ALEN
) == 0) {
4033 if (s
->state
== AMPDU_STREAM_ACTIVE
) {
4035 spin_unlock(&priv
->stream_lock
);
4036 mwl8k_destroy_ba(hw
, idx
);
4037 spin_lock(&priv
->stream_lock
);
4038 } else if (s
->state
== AMPDU_STREAM_NEW
) {
4039 mwl8k_remove_stream(hw
, s
);
4045 spin_unlock(&priv
->stream_lock
);
4047 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4051 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_SET_NEW_STN
);
4052 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4053 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
4054 cmd
->action
= cpu_to_le16(MWL8K_STA_ACTION_REMOVE
);
4056 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
4063 * CMD_UPDATE_ENCRYPTION.
4066 #define MAX_ENCR_KEY_LENGTH 16
4067 #define MIC_KEY_LENGTH 8
4069 struct mwl8k_cmd_update_encryption
{
4070 struct mwl8k_cmd_pkt header
;
4079 struct mwl8k_cmd_set_key
{
4080 struct mwl8k_cmd_pkt header
;
4089 __u8 key_material
[MAX_ENCR_KEY_LENGTH
];
4090 __u8 tkip_tx_mic_key
[MIC_KEY_LENGTH
];
4091 __u8 tkip_rx_mic_key
[MIC_KEY_LENGTH
];
4092 __le16 tkip_rsc_low
;
4093 __le32 tkip_rsc_high
;
4094 __le16 tkip_tsc_low
;
4095 __le32 tkip_tsc_high
;
4102 MWL8K_ENCR_REMOVE_KEY
,
4103 MWL8K_ENCR_SET_GROUP_KEY
,
4106 #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
4107 #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
4108 #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
4109 #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
4110 #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
4118 #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
4119 #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
4120 #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
4121 #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
4122 #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
4124 static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw
*hw
,
4125 struct ieee80211_vif
*vif
,
4129 struct mwl8k_cmd_update_encryption
*cmd
;
4132 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4136 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION
);
4137 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4138 cmd
->action
= cpu_to_le32(MWL8K_ENCR_ENABLE
);
4139 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
4140 cmd
->encr_type
= encr_type
;
4142 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
4148 static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key
*cmd
,
4150 struct ieee80211_key_conf
*key
)
4152 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION
);
4153 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4154 cmd
->length
= cpu_to_le16(sizeof(*cmd
) -
4155 offsetof(struct mwl8k_cmd_set_key
, length
));
4156 cmd
->key_id
= cpu_to_le32(key
->keyidx
);
4157 cmd
->key_len
= cpu_to_le16(key
->keylen
);
4158 memcpy(cmd
->mac_addr
, addr
, ETH_ALEN
);
4160 switch (key
->cipher
) {
4161 case WLAN_CIPHER_SUITE_WEP40
:
4162 case WLAN_CIPHER_SUITE_WEP104
:
4163 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_WEP
);
4164 if (key
->keyidx
== 0)
4165 cmd
->key_info
= cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY
);
4168 case WLAN_CIPHER_SUITE_TKIP
:
4169 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_TKIP
);
4170 cmd
->key_info
= (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4171 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE
)
4172 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY
);
4173 cmd
->key_info
|= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
4174 | MWL8K_KEY_FLAG_TSC_VALID
);
4176 case WLAN_CIPHER_SUITE_CCMP
:
4177 cmd
->key_type_id
= cpu_to_le16(MWL8K_ALG_CCMP
);
4178 cmd
->key_info
= (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4179 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE
)
4180 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY
);
4189 static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw
*hw
,
4190 struct ieee80211_vif
*vif
,
4192 struct ieee80211_key_conf
*key
)
4194 struct mwl8k_cmd_set_key
*cmd
;
4199 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4201 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4205 rc
= mwl8k_encryption_set_cmd_info(cmd
, addr
, key
);
4211 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4212 action
= MWL8K_ENCR_SET_KEY
;
4214 action
= MWL8K_ENCR_SET_GROUP_KEY
;
4216 switch (key
->cipher
) {
4217 case WLAN_CIPHER_SUITE_WEP40
:
4218 case WLAN_CIPHER_SUITE_WEP104
:
4219 if (!mwl8k_vif
->wep_key_conf
[idx
].enabled
) {
4220 memcpy(mwl8k_vif
->wep_key_conf
[idx
].key
, key
,
4221 sizeof(*key
) + key
->keylen
);
4222 mwl8k_vif
->wep_key_conf
[idx
].enabled
= 1;
4225 keymlen
= key
->keylen
;
4226 action
= MWL8K_ENCR_SET_KEY
;
4228 case WLAN_CIPHER_SUITE_TKIP
:
4229 keymlen
= MAX_ENCR_KEY_LENGTH
+ 2 * MIC_KEY_LENGTH
;
4231 case WLAN_CIPHER_SUITE_CCMP
:
4232 keymlen
= key
->keylen
;
4239 memcpy(cmd
->key_material
, key
->key
, keymlen
);
4240 cmd
->action
= cpu_to_le32(action
);
4242 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
4249 static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw
*hw
,
4250 struct ieee80211_vif
*vif
,
4252 struct ieee80211_key_conf
*key
)
4254 struct mwl8k_cmd_set_key
*cmd
;
4256 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4258 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4262 rc
= mwl8k_encryption_set_cmd_info(cmd
, addr
, key
);
4266 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
4267 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
4268 mwl8k_vif
->wep_key_conf
[key
->keyidx
].enabled
= 0;
4270 cmd
->action
= cpu_to_le32(MWL8K_ENCR_REMOVE_KEY
);
4272 rc
= mwl8k_post_pervif_cmd(hw
, vif
, &cmd
->header
);
4279 static int mwl8k_set_key(struct ieee80211_hw
*hw
,
4280 enum set_key_cmd cmd_param
,
4281 struct ieee80211_vif
*vif
,
4282 struct ieee80211_sta
*sta
,
4283 struct ieee80211_key_conf
*key
)
4288 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4289 struct mwl8k_priv
*priv
= hw
->priv
;
4291 if (vif
->type
== NL80211_IFTYPE_STATION
&& !priv
->ap_fw
)
4299 if (cmd_param
== SET_KEY
) {
4300 rc
= mwl8k_cmd_encryption_set_key(hw
, vif
, addr
, key
);
4304 if ((key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
4305 || (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
))
4306 encr_type
= MWL8K_UPDATE_ENCRYPTION_TYPE_WEP
;
4308 encr_type
= MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED
;
4310 rc
= mwl8k_cmd_update_encryption_enable(hw
, vif
, addr
,
4315 mwl8k_vif
->is_hw_crypto_enabled
= true;
4318 rc
= mwl8k_cmd_encryption_remove_key(hw
, vif
, addr
, key
);
4330 struct ewc_ht_info
{
4336 struct peer_capability_info
{
4337 /* Peer type - AP vs. STA. */
4340 /* Basic 802.11 capabilities from assoc resp. */
4343 /* Set if peer supports 802.11n high throughput (HT). */
4346 /* Valid if HT is supported. */
4348 __u8 extended_ht_caps
;
4349 struct ewc_ht_info ewc_info
;
4351 /* Legacy rate table. Intersection of our rates and peer rates. */
4352 __u8 legacy_rates
[12];
4354 /* HT rate table. Intersection of our rates and peer rates. */
4358 /* If set, interoperability mode, no proprietary extensions. */
4362 __le16 amsdu_enabled
;
4365 struct mwl8k_cmd_update_stadb
{
4366 struct mwl8k_cmd_pkt header
;
4368 /* See STADB_ACTION_TYPE */
4371 /* Peer MAC address */
4372 __u8 peer_addr
[ETH_ALEN
];
4376 /* Peer info - valid during add/update. */
4377 struct peer_capability_info peer_info
;
4380 #define MWL8K_STA_DB_MODIFY_ENTRY 1
4381 #define MWL8K_STA_DB_DEL_ENTRY 2
4383 /* Peer Entry flags - used to define the type of the peer node */
4384 #define MWL8K_PEER_TYPE_ACCESSPOINT 2
4386 static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw
*hw
,
4387 struct ieee80211_vif
*vif
,
4388 struct ieee80211_sta
*sta
)
4390 struct mwl8k_cmd_update_stadb
*cmd
;
4391 struct peer_capability_info
*p
;
4395 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4399 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
4400 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4401 cmd
->action
= cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY
);
4402 memcpy(cmd
->peer_addr
, sta
->addr
, ETH_ALEN
);
4404 p
= &cmd
->peer_info
;
4405 p
->peer_type
= MWL8K_PEER_TYPE_ACCESSPOINT
;
4406 p
->basic_caps
= cpu_to_le16(vif
->bss_conf
.assoc_capability
);
4407 p
->ht_support
= sta
->ht_cap
.ht_supported
;
4408 p
->ht_caps
= cpu_to_le16(sta
->ht_cap
.cap
);
4409 p
->extended_ht_caps
= (sta
->ht_cap
.ampdu_factor
& 3) |
4410 ((sta
->ht_cap
.ampdu_density
& 7) << 2);
4411 if (hw
->conf
.chandef
.chan
->band
== IEEE80211_BAND_2GHZ
)
4412 rates
= sta
->supp_rates
[IEEE80211_BAND_2GHZ
];
4414 rates
= sta
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
4415 legacy_rate_mask_to_array(p
->legacy_rates
, rates
);
4416 memcpy(p
->ht_rates
, sta
->ht_cap
.mcs
.rx_mask
, 16);
4418 p
->amsdu_enabled
= 0;
4420 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
4428 static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw
*hw
,
4429 struct ieee80211_vif
*vif
, u8
*addr
)
4431 struct mwl8k_cmd_update_stadb
*cmd
;
4434 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
4438 cmd
->header
.code
= cpu_to_le16(MWL8K_CMD_UPDATE_STADB
);
4439 cmd
->header
.length
= cpu_to_le16(sizeof(*cmd
));
4440 cmd
->action
= cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY
);
4441 memcpy(cmd
->peer_addr
, addr
, ETH_ALEN
);
4443 rc
= mwl8k_post_cmd(hw
, &cmd
->header
);
4451 * Interrupt handling.
4453 static irqreturn_t
mwl8k_interrupt(int irq
, void *dev_id
)
4455 struct ieee80211_hw
*hw
= dev_id
;
4456 struct mwl8k_priv
*priv
= hw
->priv
;
4459 status
= ioread32(priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4463 if (status
& MWL8K_A2H_INT_TX_DONE
) {
4464 status
&= ~MWL8K_A2H_INT_TX_DONE
;
4465 tasklet_schedule(&priv
->poll_tx_task
);
4468 if (status
& MWL8K_A2H_INT_RX_READY
) {
4469 status
&= ~MWL8K_A2H_INT_RX_READY
;
4470 tasklet_schedule(&priv
->poll_rx_task
);
4473 if (status
& MWL8K_A2H_INT_BA_WATCHDOG
) {
4474 iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG
,
4475 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
4477 atomic_inc(&priv
->watchdog_event_pending
);
4478 status
&= ~MWL8K_A2H_INT_BA_WATCHDOG
;
4479 ieee80211_queue_work(hw
, &priv
->watchdog_ba_handle
);
4483 iowrite32(~status
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4485 if (status
& MWL8K_A2H_INT_OPC_DONE
) {
4486 if (priv
->hostcmd_wait
!= NULL
)
4487 complete(priv
->hostcmd_wait
);
4490 if (status
& MWL8K_A2H_INT_QUEUE_EMPTY
) {
4491 if (!mutex_is_locked(&priv
->fw_mutex
) &&
4492 priv
->radio_on
&& priv
->pending_tx_pkts
)
4493 mwl8k_tx_start(priv
);
4499 static void mwl8k_tx_poll(unsigned long data
)
4501 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
4502 struct mwl8k_priv
*priv
= hw
->priv
;
4508 spin_lock_bh(&priv
->tx_lock
);
4510 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
4511 limit
-= mwl8k_txq_reclaim(hw
, i
, limit
, 0);
4513 if (!priv
->pending_tx_pkts
&& priv
->tx_wait
!= NULL
) {
4514 complete(priv
->tx_wait
);
4515 priv
->tx_wait
= NULL
;
4518 spin_unlock_bh(&priv
->tx_lock
);
4521 writel(~MWL8K_A2H_INT_TX_DONE
,
4522 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4524 tasklet_schedule(&priv
->poll_tx_task
);
4528 static void mwl8k_rx_poll(unsigned long data
)
4530 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
4531 struct mwl8k_priv
*priv
= hw
->priv
;
4535 limit
-= rxq_process(hw
, 0, limit
);
4536 limit
-= rxq_refill(hw
, 0, limit
);
4539 writel(~MWL8K_A2H_INT_RX_READY
,
4540 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
4542 tasklet_schedule(&priv
->poll_rx_task
);
4548 * Core driver operations.
4550 static void mwl8k_tx(struct ieee80211_hw
*hw
,
4551 struct ieee80211_tx_control
*control
,
4552 struct sk_buff
*skb
)
4554 struct mwl8k_priv
*priv
= hw
->priv
;
4555 int index
= skb_get_queue_mapping(skb
);
4557 if (!priv
->radio_on
) {
4558 wiphy_debug(hw
->wiphy
,
4559 "dropped TX frame since radio disabled\n");
4564 mwl8k_txq_xmit(hw
, index
, control
->sta
, skb
);
4567 static int mwl8k_start(struct ieee80211_hw
*hw
)
4569 struct mwl8k_priv
*priv
= hw
->priv
;
4572 rc
= request_irq(priv
->pdev
->irq
, mwl8k_interrupt
,
4573 IRQF_SHARED
, MWL8K_NAME
, hw
);
4576 wiphy_err(hw
->wiphy
, "failed to register IRQ handler\n");
4579 priv
->irq
= priv
->pdev
->irq
;
4581 /* Enable TX reclaim and RX tasklets. */
4582 tasklet_enable(&priv
->poll_tx_task
);
4583 tasklet_enable(&priv
->poll_rx_task
);
4585 /* Enable interrupts */
4586 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4587 iowrite32(MWL8K_A2H_EVENTS
,
4588 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
4590 rc
= mwl8k_fw_lock(hw
);
4592 rc
= mwl8k_cmd_radio_enable(hw
);
4596 rc
= mwl8k_cmd_enable_sniffer(hw
, 0);
4599 rc
= mwl8k_cmd_set_pre_scan(hw
);
4602 rc
= mwl8k_cmd_set_post_scan(hw
,
4603 "\x00\x00\x00\x00\x00\x00");
4607 rc
= mwl8k_cmd_set_rateadapt_mode(hw
, 0);
4610 rc
= mwl8k_cmd_set_wmm_mode(hw
, 0);
4612 mwl8k_fw_unlock(hw
);
4616 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4617 free_irq(priv
->pdev
->irq
, hw
);
4619 tasklet_disable(&priv
->poll_tx_task
);
4620 tasklet_disable(&priv
->poll_rx_task
);
4622 ieee80211_wake_queues(hw
);
4628 static void mwl8k_stop(struct ieee80211_hw
*hw
)
4630 struct mwl8k_priv
*priv
= hw
->priv
;
4633 if (!priv
->hw_restart_in_progress
)
4634 mwl8k_cmd_radio_disable(hw
);
4636 ieee80211_stop_queues(hw
);
4638 /* Disable interrupts */
4639 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
4640 if (priv
->irq
!= -1) {
4641 free_irq(priv
->pdev
->irq
, hw
);
4645 /* Stop finalize join worker */
4646 cancel_work_sync(&priv
->finalize_join_worker
);
4647 cancel_work_sync(&priv
->watchdog_ba_handle
);
4648 if (priv
->beacon_skb
!= NULL
)
4649 dev_kfree_skb(priv
->beacon_skb
);
4651 /* Stop TX reclaim and RX tasklets. */
4652 tasklet_disable(&priv
->poll_tx_task
);
4653 tasklet_disable(&priv
->poll_rx_task
);
4655 /* Return all skbs to mac80211 */
4656 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
4657 mwl8k_txq_reclaim(hw
, i
, INT_MAX
, 1);
4660 static int mwl8k_reload_firmware(struct ieee80211_hw
*hw
, char *fw_image
);
4662 static int mwl8k_add_interface(struct ieee80211_hw
*hw
,
4663 struct ieee80211_vif
*vif
)
4665 struct mwl8k_priv
*priv
= hw
->priv
;
4666 struct mwl8k_vif
*mwl8k_vif
;
4667 u32 macids_supported
;
4669 struct mwl8k_device_info
*di
;
4672 * Reject interface creation if sniffer mode is active, as
4673 * STA operation is mutually exclusive with hardware sniffer
4674 * mode. (Sniffer mode is only used on STA firmware.)
4676 if (priv
->sniffer_enabled
) {
4677 wiphy_info(hw
->wiphy
,
4678 "unable to create STA interface because sniffer mode is enabled\n");
4682 di
= priv
->device_info
;
4683 switch (vif
->type
) {
4684 case NL80211_IFTYPE_AP
:
4685 if (!priv
->ap_fw
&& di
->fw_image_ap
) {
4686 /* we must load the ap fw to meet this request */
4687 if (!list_empty(&priv
->vif_list
))
4689 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_ap
);
4693 macids_supported
= priv
->ap_macids_supported
;
4695 case NL80211_IFTYPE_STATION
:
4696 if (priv
->ap_fw
&& di
->fw_image_sta
) {
4697 if (!list_empty(&priv
->vif_list
)) {
4698 wiphy_warn(hw
->wiphy
, "AP interface is running.\n"
4699 "Adding STA interface for WDS");
4701 /* we must load the sta fw to
4702 * meet this request.
4704 rc
= mwl8k_reload_firmware(hw
,
4710 macids_supported
= priv
->sta_macids_supported
;
4716 macid
= ffs(macids_supported
& ~priv
->macids_used
);
4720 /* Setup driver private area. */
4721 mwl8k_vif
= MWL8K_VIF(vif
);
4722 memset(mwl8k_vif
, 0, sizeof(*mwl8k_vif
));
4723 mwl8k_vif
->vif
= vif
;
4724 mwl8k_vif
->macid
= macid
;
4725 mwl8k_vif
->seqno
= 0;
4726 memcpy(mwl8k_vif
->bssid
, vif
->addr
, ETH_ALEN
);
4727 mwl8k_vif
->is_hw_crypto_enabled
= false;
4729 /* Set the mac address. */
4730 mwl8k_cmd_set_mac_addr(hw
, vif
, vif
->addr
);
4732 if (vif
->type
== NL80211_IFTYPE_AP
)
4733 mwl8k_cmd_set_new_stn_add_self(hw
, vif
);
4735 priv
->macids_used
|= 1 << mwl8k_vif
->macid
;
4736 list_add_tail(&mwl8k_vif
->list
, &priv
->vif_list
);
4741 static void mwl8k_remove_vif(struct mwl8k_priv
*priv
, struct mwl8k_vif
*vif
)
4743 /* Has ieee80211_restart_hw re-added the removed interfaces? */
4744 if (!priv
->macids_used
)
4747 priv
->macids_used
&= ~(1 << vif
->macid
);
4748 list_del(&vif
->list
);
4751 static void mwl8k_remove_interface(struct ieee80211_hw
*hw
,
4752 struct ieee80211_vif
*vif
)
4754 struct mwl8k_priv
*priv
= hw
->priv
;
4755 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
4757 if (vif
->type
== NL80211_IFTYPE_AP
)
4758 mwl8k_cmd_set_new_stn_del(hw
, vif
, vif
->addr
);
4760 mwl8k_cmd_del_mac_addr(hw
, vif
, vif
->addr
);
4762 mwl8k_remove_vif(priv
, mwl8k_vif
);
4765 static void mwl8k_hw_restart_work(struct work_struct
*work
)
4767 struct mwl8k_priv
*priv
=
4768 container_of(work
, struct mwl8k_priv
, fw_reload
);
4769 struct ieee80211_hw
*hw
= priv
->hw
;
4770 struct mwl8k_device_info
*di
;
4773 /* If some command is waiting for a response, clear it */
4774 if (priv
->hostcmd_wait
!= NULL
) {
4775 complete(priv
->hostcmd_wait
);
4776 priv
->hostcmd_wait
= NULL
;
4779 priv
->hw_restart_owner
= current
;
4780 di
= priv
->device_info
;
4784 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_ap
);
4786 rc
= mwl8k_reload_firmware(hw
, di
->fw_image_sta
);
4791 priv
->hw_restart_owner
= NULL
;
4792 priv
->hw_restart_in_progress
= false;
4795 * This unlock will wake up the queues and
4796 * also opens the command path for other
4799 mwl8k_fw_unlock(hw
);
4801 ieee80211_restart_hw(hw
);
4803 wiphy_err(hw
->wiphy
, "Firmware restarted successfully\n");
4807 mwl8k_fw_unlock(hw
);
4809 wiphy_err(hw
->wiphy
, "Firmware restart failed\n");
4812 static int mwl8k_config(struct ieee80211_hw
*hw
, u32 changed
)
4814 struct ieee80211_conf
*conf
= &hw
->conf
;
4815 struct mwl8k_priv
*priv
= hw
->priv
;
4818 rc
= mwl8k_fw_lock(hw
);
4822 if (conf
->flags
& IEEE80211_CONF_IDLE
)
4823 rc
= mwl8k_cmd_radio_disable(hw
);
4825 rc
= mwl8k_cmd_radio_enable(hw
);
4829 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
4830 rc
= mwl8k_cmd_set_rf_channel(hw
, conf
);
4835 if (conf
->power_level
> 18)
4836 conf
->power_level
= 18;
4840 if (conf
->flags
& IEEE80211_CONF_CHANGE_POWER
) {
4841 rc
= mwl8k_cmd_tx_power(hw
, conf
, conf
->power_level
);
4848 rc
= mwl8k_cmd_rf_tx_power(hw
, conf
->power_level
);
4851 rc
= mwl8k_cmd_mimo_config(hw
, 0x7, 0x7);
4855 mwl8k_fw_unlock(hw
);
4861 mwl8k_bss_info_changed_sta(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4862 struct ieee80211_bss_conf
*info
, u32 changed
)
4864 struct mwl8k_priv
*priv
= hw
->priv
;
4865 u32 ap_legacy_rates
= 0;
4866 u8 ap_mcs_rates
[16];
4869 if (mwl8k_fw_lock(hw
))
4873 * No need to capture a beacon if we're no longer associated.
4875 if ((changed
& BSS_CHANGED_ASSOC
) && !vif
->bss_conf
.assoc
)
4876 priv
->capture_beacon
= false;
4879 * Get the AP's legacy and MCS rates.
4881 if (vif
->bss_conf
.assoc
) {
4882 struct ieee80211_sta
*ap
;
4886 ap
= ieee80211_find_sta(vif
, vif
->bss_conf
.bssid
);
4892 if (hw
->conf
.chandef
.chan
->band
== IEEE80211_BAND_2GHZ
) {
4893 ap_legacy_rates
= ap
->supp_rates
[IEEE80211_BAND_2GHZ
];
4896 ap
->supp_rates
[IEEE80211_BAND_5GHZ
] << 5;
4898 memcpy(ap_mcs_rates
, ap
->ht_cap
.mcs
.rx_mask
, 16);
4903 if ((changed
& BSS_CHANGED_ASSOC
) && vif
->bss_conf
.assoc
&&
4905 rc
= mwl8k_cmd_set_rate(hw
, vif
, ap_legacy_rates
, ap_mcs_rates
);
4909 rc
= mwl8k_cmd_use_fixed_rate_sta(hw
);
4913 if ((changed
& BSS_CHANGED_ASSOC
) && vif
->bss_conf
.assoc
&&
4918 /* Use AP firmware specific rate command.
4920 idx
= ffs(vif
->bss_conf
.basic_rates
);
4924 if (hw
->conf
.chandef
.chan
->band
== IEEE80211_BAND_2GHZ
)
4925 rate
= mwl8k_rates_24
[idx
].hw_value
;
4927 rate
= mwl8k_rates_50
[idx
].hw_value
;
4929 mwl8k_cmd_use_fixed_rate_ap(hw
, rate
, rate
);
4933 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4934 rc
= mwl8k_set_radio_preamble(hw
,
4935 vif
->bss_conf
.use_short_preamble
);
4940 if ((changed
& BSS_CHANGED_ERP_SLOT
) && !priv
->ap_fw
) {
4941 rc
= mwl8k_cmd_set_slot(hw
, vif
->bss_conf
.use_short_slot
);
4946 if (vif
->bss_conf
.assoc
&& !priv
->ap_fw
&&
4947 (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_ERP_CTS_PROT
|
4949 rc
= mwl8k_cmd_set_aid(hw
, vif
, ap_legacy_rates
);
4954 if (vif
->bss_conf
.assoc
&&
4955 (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_BEACON_INT
))) {
4957 * Finalize the join. Tell rx handler to process
4958 * next beacon from our BSSID.
4960 memcpy(priv
->capture_bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
4961 priv
->capture_beacon
= true;
4965 mwl8k_fw_unlock(hw
);
4969 mwl8k_bss_info_changed_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4970 struct ieee80211_bss_conf
*info
, u32 changed
)
4974 if (mwl8k_fw_lock(hw
))
4977 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4978 rc
= mwl8k_set_radio_preamble(hw
,
4979 vif
->bss_conf
.use_short_preamble
);
4984 if (changed
& BSS_CHANGED_BASIC_RATES
) {
4989 * Use lowest supported basic rate for multicasts
4990 * and management frames (such as probe responses --
4991 * beacons will always go out at 1 Mb/s).
4993 idx
= ffs(vif
->bss_conf
.basic_rates
);
4997 if (hw
->conf
.chandef
.chan
->band
== IEEE80211_BAND_2GHZ
)
4998 rate
= mwl8k_rates_24
[idx
].hw_value
;
5000 rate
= mwl8k_rates_50
[idx
].hw_value
;
5002 mwl8k_cmd_use_fixed_rate_ap(hw
, rate
, rate
);
5005 if (changed
& (BSS_CHANGED_BEACON_INT
| BSS_CHANGED_BEACON
)) {
5006 struct sk_buff
*skb
;
5008 skb
= ieee80211_beacon_get(hw
, vif
);
5010 mwl8k_cmd_set_beacon(hw
, vif
, skb
->data
, skb
->len
);
5015 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
5016 mwl8k_cmd_bss_start(hw
, vif
, info
->enable_beacon
);
5019 mwl8k_fw_unlock(hw
);
5023 mwl8k_bss_info_changed(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
5024 struct ieee80211_bss_conf
*info
, u32 changed
)
5026 if (vif
->type
== NL80211_IFTYPE_STATION
)
5027 mwl8k_bss_info_changed_sta(hw
, vif
, info
, changed
);
5028 if (vif
->type
== NL80211_IFTYPE_AP
)
5029 mwl8k_bss_info_changed_ap(hw
, vif
, info
, changed
);
5032 static u64
mwl8k_prepare_multicast(struct ieee80211_hw
*hw
,
5033 struct netdev_hw_addr_list
*mc_list
)
5035 struct mwl8k_cmd_pkt
*cmd
;
5038 * Synthesize and return a command packet that programs the
5039 * hardware multicast address filter. At this point we don't
5040 * know whether FIF_ALLMULTI is being requested, but if it is,
5041 * we'll end up throwing this packet away and creating a new
5042 * one in mwl8k_configure_filter().
5044 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 0, mc_list
);
5046 return (unsigned long)cmd
;
5050 mwl8k_configure_filter_sniffer(struct ieee80211_hw
*hw
,
5051 unsigned int changed_flags
,
5052 unsigned int *total_flags
)
5054 struct mwl8k_priv
*priv
= hw
->priv
;
5057 * Hardware sniffer mode is mutually exclusive with STA
5058 * operation, so refuse to enable sniffer mode if a STA
5059 * interface is active.
5061 if (!list_empty(&priv
->vif_list
)) {
5062 if (net_ratelimit())
5063 wiphy_info(hw
->wiphy
,
5064 "not enabling sniffer mode because STA interface is active\n");
5068 if (!priv
->sniffer_enabled
) {
5069 if (mwl8k_cmd_enable_sniffer(hw
, 1))
5071 priv
->sniffer_enabled
= true;
5074 *total_flags
&= FIF_PROMISC_IN_BSS
| FIF_ALLMULTI
|
5075 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
|
5081 static struct mwl8k_vif
*mwl8k_first_vif(struct mwl8k_priv
*priv
)
5083 if (!list_empty(&priv
->vif_list
))
5084 return list_entry(priv
->vif_list
.next
, struct mwl8k_vif
, list
);
5089 static void mwl8k_configure_filter(struct ieee80211_hw
*hw
,
5090 unsigned int changed_flags
,
5091 unsigned int *total_flags
,
5094 struct mwl8k_priv
*priv
= hw
->priv
;
5095 struct mwl8k_cmd_pkt
*cmd
= (void *)(unsigned long)multicast
;
5098 * AP firmware doesn't allow fine-grained control over
5099 * the receive filter.
5102 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
5108 * Enable hardware sniffer mode if FIF_CONTROL or
5109 * FIF_OTHER_BSS is requested.
5111 if (*total_flags
& (FIF_CONTROL
| FIF_OTHER_BSS
) &&
5112 mwl8k_configure_filter_sniffer(hw
, changed_flags
, total_flags
)) {
5117 /* Clear unsupported feature flags */
5118 *total_flags
&= FIF_ALLMULTI
| FIF_BCN_PRBRESP_PROMISC
;
5120 if (mwl8k_fw_lock(hw
)) {
5125 if (priv
->sniffer_enabled
) {
5126 mwl8k_cmd_enable_sniffer(hw
, 0);
5127 priv
->sniffer_enabled
= false;
5130 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
5131 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
) {
5133 * Disable the BSS filter.
5135 mwl8k_cmd_set_pre_scan(hw
);
5137 struct mwl8k_vif
*mwl8k_vif
;
5141 * Enable the BSS filter.
5143 * If there is an active STA interface, use that
5144 * interface's BSSID, otherwise use a dummy one
5145 * (where the OUI part needs to be nonzero for
5146 * the BSSID to be accepted by POST_SCAN).
5148 mwl8k_vif
= mwl8k_first_vif(priv
);
5149 if (mwl8k_vif
!= NULL
)
5150 bssid
= mwl8k_vif
->vif
->bss_conf
.bssid
;
5152 bssid
= "\x01\x00\x00\x00\x00\x00";
5154 mwl8k_cmd_set_post_scan(hw
, bssid
);
5159 * If FIF_ALLMULTI is being requested, throw away the command
5160 * packet that ->prepare_multicast() built and replace it with
5161 * a command packet that enables reception of all multicast
5164 if (*total_flags
& FIF_ALLMULTI
) {
5166 cmd
= __mwl8k_cmd_mac_multicast_adr(hw
, 1, NULL
);
5170 mwl8k_post_cmd(hw
, cmd
);
5174 mwl8k_fw_unlock(hw
);
5177 static int mwl8k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
5179 return mwl8k_cmd_set_rts_threshold(hw
, value
);
5182 static int mwl8k_sta_remove(struct ieee80211_hw
*hw
,
5183 struct ieee80211_vif
*vif
,
5184 struct ieee80211_sta
*sta
)
5186 struct mwl8k_priv
*priv
= hw
->priv
;
5189 return mwl8k_cmd_set_new_stn_del(hw
, vif
, sta
->addr
);
5191 return mwl8k_cmd_update_stadb_del(hw
, vif
, sta
->addr
);
5194 static int mwl8k_sta_add(struct ieee80211_hw
*hw
,
5195 struct ieee80211_vif
*vif
,
5196 struct ieee80211_sta
*sta
)
5198 struct mwl8k_priv
*priv
= hw
->priv
;
5201 struct mwl8k_vif
*mwl8k_vif
= MWL8K_VIF(vif
);
5202 struct ieee80211_key_conf
*key
;
5205 ret
= mwl8k_cmd_update_stadb_add(hw
, vif
, sta
);
5207 MWL8K_STA(sta
)->peer_id
= ret
;
5208 if (sta
->ht_cap
.ht_supported
)
5209 MWL8K_STA(sta
)->is_ampdu_allowed
= true;
5214 ret
= mwl8k_cmd_set_new_stn_add(hw
, vif
, sta
);
5217 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
5218 key
= IEEE80211_KEY_CONF(mwl8k_vif
->wep_key_conf
[i
].key
);
5219 if (mwl8k_vif
->wep_key_conf
[i
].enabled
)
5220 mwl8k_set_key(hw
, SET_KEY
, vif
, sta
, key
);
5225 static int mwl8k_conf_tx(struct ieee80211_hw
*hw
,
5226 struct ieee80211_vif
*vif
, u16 queue
,
5227 const struct ieee80211_tx_queue_params
*params
)
5229 struct mwl8k_priv
*priv
= hw
->priv
;
5232 rc
= mwl8k_fw_lock(hw
);
5234 BUG_ON(queue
> MWL8K_TX_WMM_QUEUES
- 1);
5235 memcpy(&priv
->wmm_params
[queue
], params
, sizeof(*params
));
5237 if (!priv
->wmm_enabled
)
5238 rc
= mwl8k_cmd_set_wmm_mode(hw
, 1);
5241 int q
= MWL8K_TX_WMM_QUEUES
- 1 - queue
;
5242 rc
= mwl8k_cmd_set_edca_params(hw
, q
,
5249 mwl8k_fw_unlock(hw
);
5255 static int mwl8k_get_stats(struct ieee80211_hw
*hw
,
5256 struct ieee80211_low_level_stats
*stats
)
5258 return mwl8k_cmd_get_stat(hw
, stats
);
5261 static int mwl8k_get_survey(struct ieee80211_hw
*hw
, int idx
,
5262 struct survey_info
*survey
)
5264 struct mwl8k_priv
*priv
= hw
->priv
;
5265 struct ieee80211_conf
*conf
= &hw
->conf
;
5270 survey
->channel
= conf
->chandef
.chan
;
5271 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
5272 survey
->noise
= priv
->noise
;
5277 #define MAX_AMPDU_ATTEMPTS 5
5280 mwl8k_ampdu_action(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
5281 enum ieee80211_ampdu_mlme_action action
,
5282 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
5287 struct mwl8k_priv
*priv
= hw
->priv
;
5288 struct mwl8k_ampdu_stream
*stream
;
5289 u8
*addr
= sta
->addr
, idx
;
5290 struct mwl8k_sta
*sta_info
= MWL8K_STA(sta
);
5292 if (!(hw
->flags
& IEEE80211_HW_AMPDU_AGGREGATION
))
5295 spin_lock(&priv
->stream_lock
);
5296 stream
= mwl8k_lookup_stream(hw
, addr
, tid
);
5299 case IEEE80211_AMPDU_RX_START
:
5300 case IEEE80211_AMPDU_RX_STOP
:
5302 case IEEE80211_AMPDU_TX_START
:
5303 /* By the time we get here the hw queues may contain outgoing
5304 * packets for this RA/TID that are not part of this BA
5305 * session. The hw will assign sequence numbers to these
5306 * packets as they go out. So if we query the hw for its next
5307 * sequence number and use that for the SSN here, it may end up
5308 * being wrong, which will lead to sequence number mismatch at
5309 * the recipient. To avoid this, we reset the sequence number
5310 * to O for the first MPDU in this BA stream.
5313 if (stream
== NULL
) {
5314 /* This means that somebody outside this driver called
5315 * ieee80211_start_tx_ba_session. This is unexpected
5316 * because we do our own rate control. Just warn and
5319 wiphy_warn(hw
->wiphy
, "Unexpected call to %s. "
5320 "Proceeding anyway.\n", __func__
);
5321 stream
= mwl8k_add_stream(hw
, sta
, tid
);
5323 if (stream
== NULL
) {
5324 wiphy_debug(hw
->wiphy
, "no free AMPDU streams\n");
5328 stream
->state
= AMPDU_STREAM_IN_PROGRESS
;
5330 /* Release the lock before we do the time consuming stuff */
5331 spin_unlock(&priv
->stream_lock
);
5332 for (i
= 0; i
< MAX_AMPDU_ATTEMPTS
; i
++) {
5334 /* Check if link is still valid */
5335 if (!sta_info
->is_ampdu_allowed
) {
5336 spin_lock(&priv
->stream_lock
);
5337 mwl8k_remove_stream(hw
, stream
);
5338 spin_unlock(&priv
->stream_lock
);
5342 rc
= mwl8k_check_ba(hw
, stream
, vif
);
5344 /* If HW restart is in progress mwl8k_post_cmd will
5345 * return -EBUSY. Avoid retrying mwl8k_check_ba in
5348 if (!rc
|| rc
== -EBUSY
)
5351 * HW queues take time to be flushed, give them
5357 spin_lock(&priv
->stream_lock
);
5359 wiphy_err(hw
->wiphy
, "Stream for tid %d busy after %d"
5360 " attempts\n", tid
, MAX_AMPDU_ATTEMPTS
);
5361 mwl8k_remove_stream(hw
, stream
);
5365 ieee80211_start_tx_ba_cb_irqsafe(vif
, addr
, tid
);
5367 case IEEE80211_AMPDU_TX_STOP_CONT
:
5368 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
5369 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
5371 if (stream
->state
== AMPDU_STREAM_ACTIVE
) {
5373 spin_unlock(&priv
->stream_lock
);
5374 mwl8k_destroy_ba(hw
, idx
);
5375 spin_lock(&priv
->stream_lock
);
5377 mwl8k_remove_stream(hw
, stream
);
5379 ieee80211_stop_tx_ba_cb_irqsafe(vif
, addr
, tid
);
5381 case IEEE80211_AMPDU_TX_OPERATIONAL
:
5382 BUG_ON(stream
== NULL
);
5383 BUG_ON(stream
->state
!= AMPDU_STREAM_IN_PROGRESS
);
5384 spin_unlock(&priv
->stream_lock
);
5385 rc
= mwl8k_create_ba(hw
, stream
, buf_size
, vif
);
5386 spin_lock(&priv
->stream_lock
);
5388 stream
->state
= AMPDU_STREAM_ACTIVE
;
5391 spin_unlock(&priv
->stream_lock
);
5392 mwl8k_destroy_ba(hw
, idx
);
5393 spin_lock(&priv
->stream_lock
);
5394 wiphy_debug(hw
->wiphy
,
5395 "Failed adding stream for sta %pM tid %d\n",
5397 mwl8k_remove_stream(hw
, stream
);
5405 spin_unlock(&priv
->stream_lock
);
5409 static const struct ieee80211_ops mwl8k_ops
= {
5411 .start
= mwl8k_start
,
5413 .add_interface
= mwl8k_add_interface
,
5414 .remove_interface
= mwl8k_remove_interface
,
5415 .config
= mwl8k_config
,
5416 .bss_info_changed
= mwl8k_bss_info_changed
,
5417 .prepare_multicast
= mwl8k_prepare_multicast
,
5418 .configure_filter
= mwl8k_configure_filter
,
5419 .set_key
= mwl8k_set_key
,
5420 .set_rts_threshold
= mwl8k_set_rts_threshold
,
5421 .sta_add
= mwl8k_sta_add
,
5422 .sta_remove
= mwl8k_sta_remove
,
5423 .conf_tx
= mwl8k_conf_tx
,
5424 .get_stats
= mwl8k_get_stats
,
5425 .get_survey
= mwl8k_get_survey
,
5426 .ampdu_action
= mwl8k_ampdu_action
,
5429 static void mwl8k_finalize_join_worker(struct work_struct
*work
)
5431 struct mwl8k_priv
*priv
=
5432 container_of(work
, struct mwl8k_priv
, finalize_join_worker
);
5433 struct sk_buff
*skb
= priv
->beacon_skb
;
5434 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
5435 int len
= skb
->len
- offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
5436 const u8
*tim
= cfg80211_find_ie(WLAN_EID_TIM
,
5437 mgmt
->u
.beacon
.variable
, len
);
5438 int dtim_period
= 1;
5440 if (tim
&& tim
[1] >= 2)
5441 dtim_period
= tim
[3];
5443 mwl8k_cmd_finalize_join(priv
->hw
, skb
->data
, skb
->len
, dtim_period
);
5446 priv
->beacon_skb
= NULL
;
5456 #define MWL8K_8366_AP_FW_API 3
5457 #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5458 #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5460 #define MWL8K_8764_AP_FW_API 1
5461 #define _MWL8K_8764_AP_FW(api) "mwl8k/fmimage_8764_ap-" #api ".fw"
5462 #define MWL8K_8764_AP_FW(api) _MWL8K_8764_AP_FW(api)
5464 static struct mwl8k_device_info mwl8k_info_tbl
[] = {
5466 .part_name
= "88w8363",
5467 .helper_image
= "mwl8k/helper_8363.fw",
5468 .fw_image_sta
= "mwl8k/fmimage_8363.fw",
5471 .part_name
= "88w8687",
5472 .helper_image
= "mwl8k/helper_8687.fw",
5473 .fw_image_sta
= "mwl8k/fmimage_8687.fw",
5476 .part_name
= "88w8366",
5477 .helper_image
= "mwl8k/helper_8366.fw",
5478 .fw_image_sta
= "mwl8k/fmimage_8366.fw",
5479 .fw_image_ap
= MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API
),
5480 .fw_api_ap
= MWL8K_8366_AP_FW_API
,
5481 .ap_rxd_ops
= &rxd_ap_ops
,
5484 .part_name
= "88w8764",
5485 .fw_image_ap
= MWL8K_8764_AP_FW(MWL8K_8764_AP_FW_API
),
5486 .fw_api_ap
= MWL8K_8764_AP_FW_API
,
5487 .ap_rxd_ops
= &rxd_ap_ops
,
5491 MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5492 MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5493 MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5494 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5495 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5496 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
5497 MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API
));
5499 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table
) = {
5500 { PCI_VDEVICE(MARVELL
, 0x2a0a), .driver_data
= MWL8363
, },
5501 { PCI_VDEVICE(MARVELL
, 0x2a0c), .driver_data
= MWL8363
, },
5502 { PCI_VDEVICE(MARVELL
, 0x2a24), .driver_data
= MWL8363
, },
5503 { PCI_VDEVICE(MARVELL
, 0x2a2b), .driver_data
= MWL8687
, },
5504 { PCI_VDEVICE(MARVELL
, 0x2a30), .driver_data
= MWL8687
, },
5505 { PCI_VDEVICE(MARVELL
, 0x2a40), .driver_data
= MWL8366
, },
5506 { PCI_VDEVICE(MARVELL
, 0x2a41), .driver_data
= MWL8366
, },
5507 { PCI_VDEVICE(MARVELL
, 0x2a42), .driver_data
= MWL8366
, },
5508 { PCI_VDEVICE(MARVELL
, 0x2a43), .driver_data
= MWL8366
, },
5509 { PCI_VDEVICE(MARVELL
, 0x2b36), .driver_data
= MWL8764
, },
5512 MODULE_DEVICE_TABLE(pci
, mwl8k_pci_id_table
);
5514 static int mwl8k_request_alt_fw(struct mwl8k_priv
*priv
)
5517 printk(KERN_ERR
"%s: Error requesting preferred fw %s.\n"
5518 "Trying alternative firmware %s\n", pci_name(priv
->pdev
),
5519 priv
->fw_pref
, priv
->fw_alt
);
5520 rc
= mwl8k_request_fw(priv
, priv
->fw_alt
, &priv
->fw_ucode
, true);
5522 printk(KERN_ERR
"%s: Error requesting alt fw %s\n",
5523 pci_name(priv
->pdev
), priv
->fw_alt
);
5529 static int mwl8k_firmware_load_success(struct mwl8k_priv
*priv
);
5530 static void mwl8k_fw_state_machine(const struct firmware
*fw
, void *context
)
5532 struct mwl8k_priv
*priv
= context
;
5533 struct mwl8k_device_info
*di
= priv
->device_info
;
5536 switch (priv
->fw_state
) {
5539 printk(KERN_ERR
"%s: Error requesting helper fw %s\n",
5540 pci_name(priv
->pdev
), di
->helper_image
);
5543 priv
->fw_helper
= fw
;
5544 rc
= mwl8k_request_fw(priv
, priv
->fw_pref
, &priv
->fw_ucode
,
5546 if (rc
&& priv
->fw_alt
) {
5547 rc
= mwl8k_request_alt_fw(priv
);
5550 priv
->fw_state
= FW_STATE_LOADING_ALT
;
5554 priv
->fw_state
= FW_STATE_LOADING_PREF
;
5557 case FW_STATE_LOADING_PREF
:
5560 rc
= mwl8k_request_alt_fw(priv
);
5563 priv
->fw_state
= FW_STATE_LOADING_ALT
;
5567 priv
->fw_ucode
= fw
;
5568 rc
= mwl8k_firmware_load_success(priv
);
5572 complete(&priv
->firmware_loading_complete
);
5576 case FW_STATE_LOADING_ALT
:
5578 printk(KERN_ERR
"%s: Error requesting alt fw %s\n",
5579 pci_name(priv
->pdev
), di
->helper_image
);
5582 priv
->fw_ucode
= fw
;
5583 rc
= mwl8k_firmware_load_success(priv
);
5587 complete(&priv
->firmware_loading_complete
);
5591 printk(KERN_ERR
"%s: Unexpected firmware loading state: %d\n",
5592 MWL8K_NAME
, priv
->fw_state
);
5599 priv
->fw_state
= FW_STATE_ERROR
;
5600 complete(&priv
->firmware_loading_complete
);
5601 device_release_driver(&priv
->pdev
->dev
);
5602 mwl8k_release_firmware(priv
);
5605 #define MAX_RESTART_ATTEMPTS 1
5606 static int mwl8k_init_firmware(struct ieee80211_hw
*hw
, char *fw_image
,
5609 struct mwl8k_priv
*priv
= hw
->priv
;
5611 int count
= MAX_RESTART_ATTEMPTS
;
5614 /* Reset firmware and hardware */
5615 mwl8k_hw_reset(priv
);
5617 /* Ask userland hotplug daemon for the device firmware */
5618 rc
= mwl8k_request_firmware(priv
, fw_image
, nowait
);
5620 wiphy_err(hw
->wiphy
, "Firmware files not found\n");
5627 /* Load firmware into hardware */
5628 rc
= mwl8k_load_firmware(hw
);
5630 wiphy_err(hw
->wiphy
, "Cannot start firmware\n");
5632 /* Reclaim memory once firmware is successfully loaded */
5633 mwl8k_release_firmware(priv
);
5636 /* FW did not start successfully;
5637 * lets try one more time
5640 wiphy_err(hw
->wiphy
, "Trying to reload the firmware again\n");
5648 static int mwl8k_init_txqs(struct ieee80211_hw
*hw
)
5650 struct mwl8k_priv
*priv
= hw
->priv
;
5654 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++) {
5655 rc
= mwl8k_txq_init(hw
, i
);
5659 iowrite32(priv
->txq
[i
].txd_dma
,
5660 priv
->sram
+ priv
->txq_offset
[i
]);
5665 /* initialize hw after successfully loading a firmware image */
5666 static int mwl8k_probe_hw(struct ieee80211_hw
*hw
)
5668 struct mwl8k_priv
*priv
= hw
->priv
;
5673 priv
->rxd_ops
= priv
->device_info
->ap_rxd_ops
;
5674 if (priv
->rxd_ops
== NULL
) {
5675 wiphy_err(hw
->wiphy
,
5676 "Driver does not have AP firmware image support for this hardware\n");
5678 goto err_stop_firmware
;
5681 priv
->rxd_ops
= &rxd_sta_ops
;
5684 priv
->sniffer_enabled
= false;
5685 priv
->wmm_enabled
= false;
5686 priv
->pending_tx_pkts
= 0;
5687 atomic_set(&priv
->watchdog_event_pending
, 0);
5689 rc
= mwl8k_rxq_init(hw
, 0);
5691 goto err_stop_firmware
;
5692 rxq_refill(hw
, 0, INT_MAX
);
5694 /* For the sta firmware, we need to know the dma addresses of tx queues
5695 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5696 * prior to issuing this command. But for the AP case, we learn the
5697 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5698 * case we must initialize the tx queues after.
5700 priv
->num_ampdu_queues
= 0;
5702 rc
= mwl8k_init_txqs(hw
);
5704 goto err_free_queues
;
5707 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS
);
5708 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
5709 iowrite32(MWL8K_A2H_INT_TX_DONE
|MWL8K_A2H_INT_RX_READY
|
5710 MWL8K_A2H_INT_BA_WATCHDOG
,
5711 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL
);
5712 iowrite32(MWL8K_A2H_INT_OPC_DONE
,
5713 priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK
);
5715 rc
= request_irq(priv
->pdev
->irq
, mwl8k_interrupt
,
5716 IRQF_SHARED
, MWL8K_NAME
, hw
);
5718 wiphy_err(hw
->wiphy
, "failed to register IRQ handler\n");
5719 goto err_free_queues
;
5723 * When hw restart is requested,
5724 * mac80211 will take care of clearing
5725 * the ampdu streams, so do not clear
5726 * the ampdu state here
5728 if (!priv
->hw_restart_in_progress
)
5729 memset(priv
->ampdu
, 0, sizeof(priv
->ampdu
));
5732 * Temporarily enable interrupts. Initial firmware host
5733 * commands use interrupts and avoid polling. Disable
5734 * interrupts when done.
5736 iowrite32(MWL8K_A2H_EVENTS
, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
5738 /* Get config data, mac addrs etc */
5740 rc
= mwl8k_cmd_get_hw_spec_ap(hw
);
5742 rc
= mwl8k_init_txqs(hw
);
5744 rc
= mwl8k_cmd_set_hw_spec(hw
);
5746 rc
= mwl8k_cmd_get_hw_spec_sta(hw
);
5749 wiphy_err(hw
->wiphy
, "Cannot initialise firmware\n");
5753 /* Turn radio off */
5754 rc
= mwl8k_cmd_radio_disable(hw
);
5756 wiphy_err(hw
->wiphy
, "Cannot disable\n");
5760 /* Clear MAC address */
5761 rc
= mwl8k_cmd_set_mac_addr(hw
, NULL
, "\x00\x00\x00\x00\x00\x00");
5763 wiphy_err(hw
->wiphy
, "Cannot clear MAC address\n");
5767 /* Configure Antennas */
5768 rc
= mwl8k_cmd_rf_antenna(hw
, MWL8K_RF_ANTENNA_RX
, 0x3);
5770 wiphy_warn(hw
->wiphy
, "failed to set # of RX antennas");
5771 rc
= mwl8k_cmd_rf_antenna(hw
, MWL8K_RF_ANTENNA_TX
, 0x7);
5773 wiphy_warn(hw
->wiphy
, "failed to set # of TX antennas");
5776 /* Disable interrupts */
5777 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
5778 free_irq(priv
->pdev
->irq
, hw
);
5780 wiphy_info(hw
->wiphy
, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5781 priv
->device_info
->part_name
,
5782 priv
->hw_rev
, hw
->wiphy
->perm_addr
,
5783 priv
->ap_fw
? "AP" : "STA",
5784 (priv
->fw_rev
>> 24) & 0xff, (priv
->fw_rev
>> 16) & 0xff,
5785 (priv
->fw_rev
>> 8) & 0xff, priv
->fw_rev
& 0xff);
5790 iowrite32(0, priv
->regs
+ MWL8K_HIU_A2H_INTERRUPT_MASK
);
5791 free_irq(priv
->pdev
->irq
, hw
);
5794 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
5795 mwl8k_txq_deinit(hw
, i
);
5796 mwl8k_rxq_deinit(hw
, 0);
5799 mwl8k_hw_reset(priv
);
5805 * invoke mwl8k_reload_firmware to change the firmware image after the device
5806 * has already been registered
5808 static int mwl8k_reload_firmware(struct ieee80211_hw
*hw
, char *fw_image
)
5811 struct mwl8k_priv
*priv
= hw
->priv
;
5812 struct mwl8k_vif
*vif
, *tmp_vif
;
5815 mwl8k_rxq_deinit(hw
, 0);
5818 * All the existing interfaces are re-added by the ieee80211_reconfig;
5819 * which means driver should remove existing interfaces before calling
5820 * ieee80211_restart_hw
5822 if (priv
->hw_restart_in_progress
)
5823 list_for_each_entry_safe(vif
, tmp_vif
, &priv
->vif_list
, list
)
5824 mwl8k_remove_vif(priv
, vif
);
5826 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
5827 mwl8k_txq_deinit(hw
, i
);
5829 rc
= mwl8k_init_firmware(hw
, fw_image
, false);
5833 rc
= mwl8k_probe_hw(hw
);
5837 if (priv
->hw_restart_in_progress
)
5840 rc
= mwl8k_start(hw
);
5844 rc
= mwl8k_config(hw
, ~0);
5848 for (i
= 0; i
< MWL8K_TX_WMM_QUEUES
; i
++) {
5849 rc
= mwl8k_conf_tx(hw
, NULL
, i
, &priv
->wmm_params
[i
]);
5857 printk(KERN_WARNING
"mwl8k: Failed to reload firmware image.\n");
5861 static const struct ieee80211_iface_limit ap_if_limits
[] = {
5862 { .max
= 8, .types
= BIT(NL80211_IFTYPE_AP
) },
5863 { .max
= 1, .types
= BIT(NL80211_IFTYPE_STATION
) },
5866 static const struct ieee80211_iface_combination ap_if_comb
= {
5867 .limits
= ap_if_limits
,
5868 .n_limits
= ARRAY_SIZE(ap_if_limits
),
5869 .max_interfaces
= 8,
5870 .num_different_channels
= 1,
5874 static int mwl8k_firmware_load_success(struct mwl8k_priv
*priv
)
5876 struct ieee80211_hw
*hw
= priv
->hw
;
5879 rc
= mwl8k_load_firmware(hw
);
5880 mwl8k_release_firmware(priv
);
5882 wiphy_err(hw
->wiphy
, "Cannot start firmware\n");
5887 * Extra headroom is the size of the required DMA header
5888 * minus the size of the smallest 802.11 frame (CTS frame).
5890 hw
->extra_tx_headroom
=
5891 sizeof(struct mwl8k_dma_data
) - sizeof(struct ieee80211_cts
);
5893 hw
->extra_tx_headroom
-= priv
->ap_fw
? REDUCED_TX_HEADROOM
: 0;
5895 hw
->queues
= MWL8K_TX_WMM_QUEUES
;
5897 /* Set rssi values to dBm */
5898 hw
->flags
|= IEEE80211_HW_SIGNAL_DBM
| IEEE80211_HW_HAS_RATE_CONTROL
;
5901 * Ask mac80211 to not to trigger PS mode
5902 * based on PM bit of incoming frames.
5905 hw
->flags
|= IEEE80211_HW_AP_LINK_PS
;
5907 hw
->vif_data_size
= sizeof(struct mwl8k_vif
);
5908 hw
->sta_data_size
= sizeof(struct mwl8k_sta
);
5910 priv
->macids_used
= 0;
5911 INIT_LIST_HEAD(&priv
->vif_list
);
5913 /* Set default radio state and preamble */
5914 priv
->radio_on
= false;
5915 priv
->radio_short_preamble
= false;
5917 /* Finalize join worker */
5918 INIT_WORK(&priv
->finalize_join_worker
, mwl8k_finalize_join_worker
);
5919 /* Handle watchdog ba events */
5920 INIT_WORK(&priv
->watchdog_ba_handle
, mwl8k_watchdog_ba_events
);
5921 /* To reload the firmware if it crashes */
5922 INIT_WORK(&priv
->fw_reload
, mwl8k_hw_restart_work
);
5924 /* TX reclaim and RX tasklets. */
5925 tasklet_init(&priv
->poll_tx_task
, mwl8k_tx_poll
, (unsigned long)hw
);
5926 tasklet_disable(&priv
->poll_tx_task
);
5927 tasklet_init(&priv
->poll_rx_task
, mwl8k_rx_poll
, (unsigned long)hw
);
5928 tasklet_disable(&priv
->poll_rx_task
);
5930 /* Power management cookie */
5931 priv
->cookie
= pci_alloc_consistent(priv
->pdev
, 4, &priv
->cookie_dma
);
5932 if (priv
->cookie
== NULL
)
5935 mutex_init(&priv
->fw_mutex
);
5936 priv
->fw_mutex_owner
= NULL
;
5937 priv
->fw_mutex_depth
= 0;
5938 priv
->hostcmd_wait
= NULL
;
5940 spin_lock_init(&priv
->tx_lock
);
5942 spin_lock_init(&priv
->stream_lock
);
5944 priv
->tx_wait
= NULL
;
5946 rc
= mwl8k_probe_hw(hw
);
5948 goto err_free_cookie
;
5950 hw
->wiphy
->interface_modes
= 0;
5952 if (priv
->ap_macids_supported
|| priv
->device_info
->fw_image_ap
) {
5953 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_AP
);
5954 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_STATION
);
5955 hw
->wiphy
->iface_combinations
= &ap_if_comb
;
5956 hw
->wiphy
->n_iface_combinations
= 1;
5959 if (priv
->sta_macids_supported
|| priv
->device_info
->fw_image_sta
)
5960 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_STATION
);
5962 rc
= ieee80211_register_hw(hw
);
5964 wiphy_err(hw
->wiphy
, "Cannot register device\n");
5965 goto err_unprobe_hw
;
5971 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
5972 mwl8k_txq_deinit(hw
, i
);
5973 mwl8k_rxq_deinit(hw
, 0);
5976 if (priv
->cookie
!= NULL
)
5977 pci_free_consistent(priv
->pdev
, 4,
5978 priv
->cookie
, priv
->cookie_dma
);
5982 static int mwl8k_probe(struct pci_dev
*pdev
,
5983 const struct pci_device_id
*id
)
5985 static int printed_version
;
5986 struct ieee80211_hw
*hw
;
5987 struct mwl8k_priv
*priv
;
5988 struct mwl8k_device_info
*di
;
5991 if (!printed_version
) {
5992 printk(KERN_INFO
"%s version %s\n", MWL8K_DESC
, MWL8K_VERSION
);
5993 printed_version
= 1;
5997 rc
= pci_enable_device(pdev
);
5999 printk(KERN_ERR
"%s: Cannot enable new PCI device\n",
6004 rc
= pci_request_regions(pdev
, MWL8K_NAME
);
6006 printk(KERN_ERR
"%s: Cannot obtain PCI resources\n",
6008 goto err_disable_device
;
6011 pci_set_master(pdev
);
6014 hw
= ieee80211_alloc_hw(sizeof(*priv
), &mwl8k_ops
);
6016 printk(KERN_ERR
"%s: ieee80211 alloc failed\n", MWL8K_NAME
);
6021 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
6022 pci_set_drvdata(pdev
, hw
);
6027 priv
->device_info
= &mwl8k_info_tbl
[id
->driver_data
];
6029 if (id
->driver_data
== MWL8764
)
6030 priv
->is_8764
= true;
6032 priv
->sram
= pci_iomap(pdev
, 0, 0x10000);
6033 if (priv
->sram
== NULL
) {
6034 wiphy_err(hw
->wiphy
, "Cannot map device SRAM\n");
6040 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
6041 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
6043 priv
->regs
= pci_iomap(pdev
, 1, 0x10000);
6044 if (priv
->regs
== NULL
) {
6045 priv
->regs
= pci_iomap(pdev
, 2, 0x10000);
6046 if (priv
->regs
== NULL
) {
6047 wiphy_err(hw
->wiphy
, "Cannot map device registers\n");
6054 * Choose the initial fw image depending on user input. If a second
6055 * image is available, make it the alternative image that will be
6056 * loaded if the first one fails.
6058 init_completion(&priv
->firmware_loading_complete
);
6059 di
= priv
->device_info
;
6060 if (ap_mode_default
&& di
->fw_image_ap
) {
6061 priv
->fw_pref
= di
->fw_image_ap
;
6062 priv
->fw_alt
= di
->fw_image_sta
;
6063 } else if (!ap_mode_default
&& di
->fw_image_sta
) {
6064 priv
->fw_pref
= di
->fw_image_sta
;
6065 priv
->fw_alt
= di
->fw_image_ap
;
6066 } else if (ap_mode_default
&& !di
->fw_image_ap
&& di
->fw_image_sta
) {
6067 printk(KERN_WARNING
"AP fw is unavailable. Using STA fw.");
6068 priv
->fw_pref
= di
->fw_image_sta
;
6069 } else if (!ap_mode_default
&& !di
->fw_image_sta
&& di
->fw_image_ap
) {
6070 printk(KERN_WARNING
"STA fw is unavailable. Using AP fw.");
6071 priv
->fw_pref
= di
->fw_image_ap
;
6073 rc
= mwl8k_init_firmware(hw
, priv
->fw_pref
, true);
6075 goto err_stop_firmware
;
6077 priv
->hw_restart_in_progress
= false;
6079 priv
->running_bsses
= 0;
6084 mwl8k_hw_reset(priv
);
6087 if (priv
->regs
!= NULL
)
6088 pci_iounmap(pdev
, priv
->regs
);
6090 if (priv
->sram
!= NULL
)
6091 pci_iounmap(pdev
, priv
->sram
);
6093 ieee80211_free_hw(hw
);
6096 pci_release_regions(pdev
);
6099 pci_disable_device(pdev
);
6104 static void mwl8k_remove(struct pci_dev
*pdev
)
6106 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
6107 struct mwl8k_priv
*priv
;
6114 wait_for_completion(&priv
->firmware_loading_complete
);
6116 if (priv
->fw_state
== FW_STATE_ERROR
) {
6117 mwl8k_hw_reset(priv
);
6121 ieee80211_stop_queues(hw
);
6123 ieee80211_unregister_hw(hw
);
6125 /* Remove TX reclaim and RX tasklets. */
6126 tasklet_kill(&priv
->poll_tx_task
);
6127 tasklet_kill(&priv
->poll_rx_task
);
6130 mwl8k_hw_reset(priv
);
6132 /* Return all skbs to mac80211 */
6133 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
6134 mwl8k_txq_reclaim(hw
, i
, INT_MAX
, 1);
6136 for (i
= 0; i
< mwl8k_tx_queues(priv
); i
++)
6137 mwl8k_txq_deinit(hw
, i
);
6139 mwl8k_rxq_deinit(hw
, 0);
6141 pci_free_consistent(priv
->pdev
, 4, priv
->cookie
, priv
->cookie_dma
);
6144 pci_iounmap(pdev
, priv
->regs
);
6145 pci_iounmap(pdev
, priv
->sram
);
6146 ieee80211_free_hw(hw
);
6147 pci_release_regions(pdev
);
6148 pci_disable_device(pdev
);
6151 static struct pci_driver mwl8k_driver
= {
6153 .id_table
= mwl8k_pci_id_table
,
6154 .probe
= mwl8k_probe
,
6155 .remove
= mwl8k_remove
,
6158 module_pci_driver(mwl8k_driver
);
6160 MODULE_DESCRIPTION(MWL8K_DESC
);
6161 MODULE_VERSION(MWL8K_VERSION
);
6162 MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
6163 MODULE_LICENSE("GPL");