blob: 6c002f3d91cdce6dd48e4f6e6aad20aefab37fe9 [file] [log] [blame]
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004 *
Lennert Buytenheka5fb2972010-01-12 13:51:38 +01005 * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006 *
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.
10 */
11
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000012#include <linux/interrupt.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010013#include <linux/module.h>
14#include <linux/kernel.h>
Lennert Buytenhek3d76e822009-10-22 20:20:16 +020015#include <linux/sched.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010016#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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010023#include <net/mac80211.h>
24#include <linux/moduleparam.h>
25#include <linux/firmware.h>
26#include <linux/workqueue.h>
27
28#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
29#define MWL8K_NAME KBUILD_MODNAME
Yogesh Ashok Powar00e8e692011-12-20 11:39:29 +053030#define MWL8K_VERSION "0.13"
Lennert Buytenheka66098d2009-03-10 10:13:33 +010031
Brian Cavagnolo0863ade2010-11-12 17:23:50 -080032/* Module parameters */
Rusty Russelleb939922011-12-19 14:08:01 +000033static bool ap_mode_default;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -080034module_param(ap_mode_default, bool, 0);
35MODULE_PARM_DESC(ap_mode_default,
36 "Set to 1 to make ap mode the default instead of sta mode");
37
Lennert Buytenheka66098d2009-03-10 10:13:33 +010038/* Register definitions */
39#define MWL8K_HIU_GEN_PTR 0x00000c10
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020040#define MWL8K_MODE_STA 0x0000005a
41#define MWL8K_MODE_AP 0x000000a5
Lennert Buytenheka66098d2009-03-10 10:13:33 +010042#define MWL8K_HIU_INT_CODE 0x00000c14
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020043#define MWL8K_FWSTA_READY 0xf0f1f2f4
44#define MWL8K_FWAP_READY 0xf1f2f4a5
45#define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
Lennert Buytenheka66098d2009-03-10 10:13:33 +010046#define MWL8K_HIU_SCRATCH 0x00000c40
47
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
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020054#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)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010058
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
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020065#define MWL8K_A2H_INT_DUMMY (1 << 20)
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -070066#define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020067#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)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010076
Pradeep Nemavat566875d2011-04-21 16:34:57 +053077/* HW micro second timer register
78 * located at offset 0xA600. This
79 * will be used to timestamp tx
80 * packets.
81 */
82
83#define MWL8K_HW_TIMER_REGISTER 0x0000a600
84
Lennert Buytenheka66098d2009-03-10 10:13:33 +010085#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 | \
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -070094 MWL8K_A2H_INT_TX_DONE | \
95 MWL8K_A2H_INT_BA_WATCHDOG)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010096
Lennert Buytenheka66098d2009-03-10 10:13:33 +010097#define MWL8K_RX_QUEUES 1
Brian Cavagnoloe6007072011-03-17 11:58:44 -070098#define MWL8K_TX_WMM_QUEUES 4
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -070099#define MWL8K_MAX_AMPDU_QUEUES 8
Brian Cavagnoloe6007072011-03-17 11:58:44 -0700100#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)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100102
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +0530103/* txpriorities are mapped with hw queues.
104 * Each hw queue has a txpriority.
105 */
106#define TOTAL_HW_TX_QUEUES 8
107
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.
112 */
113#define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1)
114
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200115struct rxd_ops {
116 int rxd_size;
117 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
118 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100119 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -0400120 __le16 *qos, s8 *noise);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200121};
122
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200123struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200124 char *part_name;
125 char *helper_image;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800126 char *fw_image_sta;
127 char *fw_image_ap;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100128 struct rxd_ops *ap_rxd_ops;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -0800129 u32 fw_api_ap;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200130};
131
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100132struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200133 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100134
135 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200136 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100137
138 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200139 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100140
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200141 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200142 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200143 struct {
144 struct sk_buff *skb;
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +0900145 DEFINE_DMA_UNMAP_ADDR(dma);
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200146 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100147};
148
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100149struct mwl8k_tx_queue {
150 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200151 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100152
153 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200154 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100155
Kalle Valo8ccbc3b2010-02-07 10:20:52 +0200156 unsigned int len;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200157 struct mwl8k_tx_desc *txd;
158 dma_addr_t txd_dma;
159 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100160};
161
Brian Cavagnoloac109fd2011-03-17 11:58:45 -0700162enum {
163 AMPDU_NO_STREAM,
164 AMPDU_STREAM_NEW,
165 AMPDU_STREAM_IN_PROGRESS,
166 AMPDU_STREAM_ACTIVE,
167};
168
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700169struct mwl8k_ampdu_stream {
170 struct ieee80211_sta *sta;
171 u8 tid;
172 u8 state;
173 u8 idx;
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700174};
175
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100176struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100177 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100178 struct pci_dev *pdev;
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +0530179 int irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100180
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200181 struct mwl8k_device_info *device_info;
182
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100183 void __iomem *sram;
184 void __iomem *regs;
185
186 /* firmware */
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800187 const struct firmware *fw_helper;
188 const struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100189
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100190 /* hardware/firmware parameters */
191 bool ap_fw;
192 struct rxd_ops *rxd_ops;
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100193 struct ieee80211_supported_band band_24;
194 struct ieee80211_channel channels_24[14];
Jonas Gorski3f524552013-04-14 14:11:58 +0200195 struct ieee80211_rate rates_24[13];
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100196 struct ieee80211_supported_band band_50;
197 struct ieee80211_channel channels_50[4];
Jonas Gorski3f524552013-04-14 14:11:58 +0200198 struct ieee80211_rate rates_50[8];
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100199 u32 ap_macids_supported;
200 u32 sta_macids_supported;
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100201
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -0700202 /* Ampdu stream information */
203 u8 num_ampdu_queues;
Brian Cavagnoloac109fd2011-03-17 11:58:45 -0700204 spinlock_t stream_lock;
205 struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -0700206 struct work_struct watchdog_ba_handle;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -0700207
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200208 /* firmware access */
209 struct mutex fw_mutex;
210 struct task_struct *fw_mutex_owner;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +0530211 struct task_struct *hw_restart_owner;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200212 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200213 struct completion *hostcmd_wait;
214
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +0530215 atomic_t watchdog_event_pending;
216
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100217 /* lock held over TX and TX reap */
218 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100219
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200220 /* TX quiesce completion, protected by fw_mutex and tx_lock */
221 struct completion *tx_wait;
222
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100223 /* List of interfaces. */
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100224 u32 macids_used;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100225 struct list_head vif_list;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100226
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100227 /* power management status cookie from firmware */
228 u32 *cookie;
229 dma_addr_t cookie_dma;
230
231 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100232 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200233 u32 fw_rev;
Jonas Gorskic3f251a2013-03-11 17:44:21 +0100234 u32 caps;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100235
236 /*
237 * Running count of TX packets in flight, to avoid
238 * iterating over the transmit rings each time.
239 */
240 int pending_tx_pkts;
241
242 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
Brian Cavagnoloe6007072011-03-17 11:58:44 -0700243 struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
244 u32 txq_offset[MWL8K_MAX_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100245
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200246 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200247 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200248 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200249 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100250
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100251 /* XXX need to convert this to handle multiple interfaces */
252 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200253 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100254 struct sk_buff *beacon_skb;
255
256 /*
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
260 * is checked.
261 */
262 struct work_struct finalize_join_worker;
263
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100264 /* Tasklet to perform TX reclaim. */
265 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100266
267 /* Tasklet to perform RX. */
268 struct tasklet_struct poll_rx_task;
John W. Linville0d462bb2010-07-28 14:04:24 -0400269
270 /* Most recently reported noise in dBm */
271 s8 noise;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800272
273 /*
274 * preserve the queue configurations so they can be restored if/when
275 * the firmware image is swapped.
276 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -0700277 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
Brian Cavagnolo99020472010-11-12 17:23:52 -0800278
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +0530279 /* To perform the task of reloading the firmware */
280 struct work_struct fw_reload;
281 bool hw_restart_in_progress;
282
Brian Cavagnolo99020472010-11-12 17:23:52 -0800283 /* async firmware loading state */
284 unsigned fw_state;
285 char *fw_pref;
286 char *fw_alt;
Nishant Sarmukadam98929822013-03-01 17:13:01 +0530287 bool is_8764;
Brian Cavagnolo99020472010-11-12 17:23:52 -0800288 struct completion firmware_loading_complete;
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +0530289
290 /* bitmap of running BSSes */
291 u32 running_bsses;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100292};
293
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800294#define MAX_WEP_KEY_LEN 13
295#define NUM_WEP_KEYS 4
296
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100297/* Per interface specific private data */
298struct mwl8k_vif {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100299 struct list_head list;
300 struct ieee80211_vif *vif;
301
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100302 /* Firmware macid for this vif. */
303 int macid;
304
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100305 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100306 u16 seqno;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800307
308 /* Saved WEP keys */
309 struct {
310 u8 enabled;
311 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
312 } wep_key_conf[NUM_WEP_KEYS];
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800313
314 /* BSSID */
315 u8 bssid[ETH_ALEN];
316
317 /* A flag to indicate is HW crypto is enabled for this bssid */
318 bool is_hw_crypto_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100319};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200320#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800321#define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100322
Brian Cavagnolod0805c12011-04-12 11:06:28 -0700323struct tx_traffic_info {
324 u32 start_time;
325 u32 pkts;
326};
327
328#define MWL8K_MAX_TID 8
Lennert Buytenheka6804002010-01-04 21:55:42 +0100329struct mwl8k_sta {
330 /* Index into station database. Returned by UPDATE_STADB. */
331 u8 peer_id;
Nishant Sarmukadam170335432011-03-17 11:58:48 -0700332 u8 is_ampdu_allowed;
Brian Cavagnolod0805c12011-04-12 11:06:28 -0700333 struct tx_traffic_info tx_stats[MWL8K_MAX_TID];
Lennert Buytenheka6804002010-01-04 21:55:42 +0100334};
335#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
336
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100337static const struct ieee80211_channel mwl8k_channels_24[] = {
Jonas Gorskid786f672013-02-08 16:07:25 +0100338 { .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, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100352};
353
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100354static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100355 { .bitrate = 10, .hw_value = 2, },
356 { .bitrate = 20, .hw_value = 4, },
357 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200358 { .bitrate = 110, .hw_value = 22, },
359 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100360 { .bitrate = 60, .hw_value = 12, },
361 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100362 { .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, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100368};
369
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100370static const struct ieee80211_channel mwl8k_channels_50[] = {
Jonas Gorskid786f672013-02-08 16:07:25 +0100371 { .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, },
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100375};
376
377static 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, },
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100386};
387
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100388/* Set or get info from Firmware */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100389#define MWL8K_CMD_GET 0x0000
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800390#define MWL8K_CMD_SET 0x0001
391#define MWL8K_CMD_SET_LIST 0x0002
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100392
393/* Firmware command codes */
394#define MWL8K_CMD_CODE_DNLD 0x0001
395#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200396#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100397#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
398#define MWL8K_CMD_GET_STAT 0x0014
Yogesh Ashok Powarc3015312014-02-25 17:41:58 +0530399#define MWL8K_CMD_BBP_REG_ACCESS 0x001a
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200400#define MWL8K_CMD_RADIO_CONTROL 0x001c
401#define MWL8K_CMD_RF_TX_POWER 0x001e
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800402#define MWL8K_CMD_TX_POWER 0x001f
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200403#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100404#define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100405#define MWL8K_CMD_SET_PRE_SCAN 0x0107
406#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200407#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100408#define MWL8K_CMD_SET_AID 0x010d
409#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200410#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100411#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200412#define MWL8K_CMD_SET_SLOT 0x0114
413#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
414#define MWL8K_CMD_SET_WMM_MODE 0x0123
415#define MWL8K_CMD_MIMO_CONFIG 0x0125
416#define MWL8K_CMD_USE_FIXED_RATE 0x0126
417#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100418#define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200419#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -0700420#define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +0530421#define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100422#define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
423#define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800424#define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200425#define MWL8K_CMD_UPDATE_STADB 0x1123
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700426#define MWL8K_CMD_BASTREAM 0x1125
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100427
John W. Linvilleb6037422010-07-20 13:55:00 -0400428static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100429{
John W. Linvilleb6037422010-07-20 13:55:00 -0400430 u16 command = le16_to_cpu(cmd);
431
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100432#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
433 snprintf(buf, bufsize, "%s", #x);\
434 return buf;\
435 } while (0)
John W. Linvilleb6037422010-07-20 13:55:00 -0400436 switch (command & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100437 MWL8K_CMDNAME(CODE_DNLD);
438 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200439 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100440 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
441 MWL8K_CMDNAME(GET_STAT);
442 MWL8K_CMDNAME(RADIO_CONTROL);
443 MWL8K_CMDNAME(RF_TX_POWER);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800444 MWL8K_CMDNAME(TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200445 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100446 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100447 MWL8K_CMDNAME(SET_PRE_SCAN);
448 MWL8K_CMDNAME(SET_POST_SCAN);
449 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100450 MWL8K_CMDNAME(SET_AID);
451 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200452 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100453 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200454 MWL8K_CMDNAME(SET_SLOT);
455 MWL8K_CMDNAME(SET_EDCA_PARAMS);
456 MWL8K_CMDNAME(SET_WMM_MODE);
457 MWL8K_CMDNAME(MIMO_CONFIG);
458 MWL8K_CMDNAME(USE_FIXED_RATE);
459 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200460 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200461 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100462 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100463 MWL8K_CMDNAME(SET_NEW_STN);
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800464 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200465 MWL8K_CMDNAME(UPDATE_STADB);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700466 MWL8K_CMDNAME(BASTREAM);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -0700467 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100468 default:
469 snprintf(buf, bufsize, "0x%x", cmd);
470 }
471#undef MWL8K_CMDNAME
472
473 return buf;
474}
475
476/* Hardware and firmware reset */
477static void mwl8k_hw_reset(struct mwl8k_priv *priv)
478{
479 iowrite32(MWL8K_H2A_INT_RESET,
480 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
481 iowrite32(MWL8K_H2A_INT_RESET,
482 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
483 msleep(20);
484}
485
486/* Release fw image */
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800487static void mwl8k_release_fw(const struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100488{
489 if (*fw == NULL)
490 return;
491 release_firmware(*fw);
492 *fw = NULL;
493}
494
495static void mwl8k_release_firmware(struct mwl8k_priv *priv)
496{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100497 mwl8k_release_fw(&priv->fw_ucode);
498 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100499}
500
Brian Cavagnolo99020472010-11-12 17:23:52 -0800501/* states for asynchronous f/w loading */
502static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
503enum {
504 FW_STATE_INIT = 0,
505 FW_STATE_LOADING_PREF,
506 FW_STATE_LOADING_ALT,
507 FW_STATE_ERROR,
508};
509
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100510/* Request fw image */
511static int mwl8k_request_fw(struct mwl8k_priv *priv,
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800512 const char *fname, const struct firmware **fw,
Brian Cavagnolo99020472010-11-12 17:23:52 -0800513 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100514{
515 /* release current image */
516 if (*fw != NULL)
517 mwl8k_release_fw(fw);
518
Brian Cavagnolo99020472010-11-12 17:23:52 -0800519 if (nowait)
520 return request_firmware_nowait(THIS_MODULE, 1, fname,
521 &priv->pdev->dev, GFP_KERNEL,
522 priv, mwl8k_fw_state_machine);
523 else
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800524 return request_firmware(fw, fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100525}
526
Brian Cavagnolo99020472010-11-12 17:23:52 -0800527static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
528 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100529{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200530 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100531 int rc;
532
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200533 if (di->helper_image != NULL) {
Brian Cavagnolo99020472010-11-12 17:23:52 -0800534 if (nowait)
535 rc = mwl8k_request_fw(priv, di->helper_image,
536 &priv->fw_helper, true);
537 else
538 rc = mwl8k_request_fw(priv, di->helper_image,
539 &priv->fw_helper, false);
540 if (rc)
541 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
542 pci_name(priv->pdev), di->helper_image);
543
544 if (rc || nowait)
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200545 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100546 }
547
Brian Cavagnolo99020472010-11-12 17:23:52 -0800548 if (nowait) {
549 /*
550 * if we get here, no helper image is needed. Skip the
551 * FW_STATE_INIT state.
552 */
553 priv->fw_state = FW_STATE_LOADING_PREF;
554 rc = mwl8k_request_fw(priv, fw_image,
555 &priv->fw_ucode,
556 true);
557 } else
558 rc = mwl8k_request_fw(priv, fw_image,
559 &priv->fw_ucode, false);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100560 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200561 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800562 pci_name(priv->pdev), fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100563 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100564 return rc;
565 }
566
567 return 0;
568}
569
570struct mwl8k_cmd_pkt {
571 __le16 code;
572 __le16 length;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100573 __u8 seq_num;
574 __u8 macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100575 __le16 result;
576 char payload[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000577} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100578
579/*
580 * Firmware loading.
581 */
582static int
583mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
584{
585 void __iomem *regs = priv->regs;
586 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100587 int loops;
588
589 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
590 if (pci_dma_mapping_error(priv->pdev, dma_addr))
591 return -ENOMEM;
592
593 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
594 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
595 iowrite32(MWL8K_H2A_INT_DOORBELL,
596 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
597 iowrite32(MWL8K_H2A_INT_DUMMY,
598 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
599
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100600 loops = 1000;
601 do {
602 u32 int_code;
Nishant Sarmukadam98929822013-03-01 17:13:01 +0530603 if (priv->is_8764) {
604 int_code = ioread32(regs +
605 MWL8K_HIU_H2A_INTERRUPT_STATUS);
606 if (int_code == 0)
607 break;
608 } else {
609 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
610 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
611 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
612 break;
613 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100614 }
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200615 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100616 udelay(1);
617 } while (--loops);
618
619 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
620
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200621 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100622}
623
624static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
625 const u8 *data, size_t length)
626{
627 struct mwl8k_cmd_pkt *cmd;
628 int done;
629 int rc = 0;
630
631 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
632 if (cmd == NULL)
633 return -ENOMEM;
634
635 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
636 cmd->seq_num = 0;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100637 cmd->macid = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100638 cmd->result = 0;
639
640 done = 0;
641 while (length) {
642 int block_size = length > 256 ? 256 : length;
643
644 memcpy(cmd->payload, data + done, block_size);
645 cmd->length = cpu_to_le16(block_size);
646
647 rc = mwl8k_send_fw_load_cmd(priv, cmd,
648 sizeof(*cmd) + block_size);
649 if (rc)
650 break;
651
652 done += block_size;
653 length -= block_size;
654 }
655
656 if (!rc) {
657 cmd->length = 0;
658 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
659 }
660
661 kfree(cmd);
662
663 return rc;
664}
665
666static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
667 const u8 *data, size_t length)
668{
669 unsigned char *buffer;
670 int may_continue, rc = 0;
671 u32 done, prev_block_size;
672
673 buffer = kmalloc(1024, GFP_KERNEL);
674 if (buffer == NULL)
675 return -ENOMEM;
676
677 done = 0;
678 prev_block_size = 0;
679 may_continue = 1000;
680 while (may_continue > 0) {
681 u32 block_size;
682
683 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
684 if (block_size & 1) {
685 block_size &= ~1;
686 may_continue--;
687 } else {
688 done += prev_block_size;
689 length -= prev_block_size;
690 }
691
692 if (block_size > 1024 || block_size > length) {
693 rc = -EOVERFLOW;
694 break;
695 }
696
697 if (length == 0) {
698 rc = 0;
699 break;
700 }
701
702 if (block_size == 0) {
703 rc = -EPROTO;
704 may_continue--;
705 udelay(1);
706 continue;
707 }
708
709 prev_block_size = block_size;
710 memcpy(buffer, data + done, block_size);
711
712 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
713 if (rc)
714 break;
715 }
716
717 if (!rc && length != 0)
718 rc = -EREMOTEIO;
719
720 kfree(buffer);
721
722 return rc;
723}
724
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200725static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100726{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200727 struct mwl8k_priv *priv = hw->priv;
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800728 const struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200729 int rc;
730 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100731
Nishant Sarmukadam98929822013-03-01 17:13:01 +0530732 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4) && !priv->is_8764) {
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800733 const struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100734
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200735 if (helper == NULL) {
736 printk(KERN_ERR "%s: helper image needed but none "
737 "given\n", pci_name(priv->pdev));
738 return -EINVAL;
739 }
740
741 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100742 if (rc) {
743 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200744 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100745 return rc;
746 }
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +0530747 msleep(20);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100748
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200749 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100750 } else {
Nishant Sarmukadam98929822013-03-01 17:13:01 +0530751 if (priv->is_8764)
752 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
753 else
754 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100755 }
756
757 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200758 printk(KERN_ERR "%s: unable to load firmware image\n",
759 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100760 return rc;
761 }
762
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100763 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100764
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100765 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100766 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200767 u32 ready_code;
768
769 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
770 if (ready_code == MWL8K_FWAP_READY) {
Rusty Russell3db1cd52011-12-19 13:56:45 +0000771 priv->ap_fw = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100772 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200773 } else if (ready_code == MWL8K_FWSTA_READY) {
Rusty Russell3db1cd52011-12-19 13:56:45 +0000774 priv->ap_fw = false;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200775 break;
776 }
777
778 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100779 udelay(1);
780 } while (--loops);
781
782 return loops ? 0 : -ETIMEDOUT;
783}
784
785
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100786/* DMA header used by firmware and hardware. */
787struct mwl8k_dma_data {
788 __le16 fwlen;
789 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100790 char data[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000791} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100792
793/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100794static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100795{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100796 struct mwl8k_dma_data *tr;
797 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100798
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100799 tr = (struct mwl8k_dma_data *)skb->data;
800 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
801
802 if (hdrlen != sizeof(tr->wh)) {
803 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
804 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
805 *((__le16 *)(tr->data - 2)) = qos;
806 } else {
807 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
808 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100809 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100810
811 if (hdrlen != sizeof(*tr))
812 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100813}
814
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530815#define REDUCED_TX_HEADROOM 8
816
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800817static void
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530818mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb,
819 int head_pad, int tail_pad)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100820{
821 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100822 int hdrlen;
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800823 int reqd_hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100824 struct mwl8k_dma_data *tr;
825
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100826 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100827 * Add a firmware DMA header; the firmware requires that we
828 * present a 2-byte payload length followed by a 4-address
829 * header (without QoS field), followed (optionally) by any
830 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100831 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100832 wh = (struct ieee80211_hdr *)skb->data;
833
834 hdrlen = ieee80211_hdrlen(wh->frame_control);
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530835
836 /*
837 * Check if skb_resize is required because of
838 * tx_headroom adjustment.
839 */
840 if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts)
841 + REDUCED_TX_HEADROOM))) {
842 if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) {
843
844 wiphy_err(priv->hw->wiphy,
845 "Failed to reallocate TX buffer\n");
846 return;
847 }
848 skb->truesize += REDUCED_TX_HEADROOM;
849 }
850
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530851 reqd_hdrlen = sizeof(*tr) + head_pad;
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800852
853 if (hdrlen != reqd_hdrlen)
854 skb_push(skb, reqd_hdrlen - hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100855
856 if (ieee80211_is_data_qos(wh->frame_control))
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800857 hdrlen -= IEEE80211_QOS_CTL_LEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100858
859 tr = (struct mwl8k_dma_data *)skb->data;
860 if (wh != &tr->wh)
861 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100862 if (hdrlen != sizeof(tr->wh))
863 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100864
865 /*
866 * Firmware length is the length of the fully formed "802.11
867 * payload". That is, everything except for the 802.11 header.
868 * This includes all crypto material including the MIC.
869 */
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800870 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100871}
872
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530873static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv,
874 struct sk_buff *skb)
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800875{
876 struct ieee80211_hdr *wh;
877 struct ieee80211_tx_info *tx_info;
878 struct ieee80211_key_conf *key_conf;
879 int data_pad;
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530880 int head_pad = 0;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800881
882 wh = (struct ieee80211_hdr *)skb->data;
883
884 tx_info = IEEE80211_SKB_CB(skb);
885
886 key_conf = NULL;
887 if (ieee80211_is_data(wh->frame_control))
888 key_conf = tx_info->control.hw_key;
889
890 /*
891 * Make sure the packet header is in the DMA header format (4-address
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530892 * without QoS), and add head & tail padding when HW crypto is enabled.
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800893 *
894 * We have the following trailer padding requirements:
895 * - WEP: 4 trailer bytes (ICV)
896 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
897 * - CCMP: 8 trailer bytes (MIC)
898 */
899 data_pad = 0;
900 if (key_conf != NULL) {
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530901 head_pad = key_conf->iv_len;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800902 switch (key_conf->cipher) {
903 case WLAN_CIPHER_SUITE_WEP40:
904 case WLAN_CIPHER_SUITE_WEP104:
905 data_pad = 4;
906 break;
907 case WLAN_CIPHER_SUITE_TKIP:
908 data_pad = 12;
909 break;
910 case WLAN_CIPHER_SUITE_CCMP:
911 data_pad = 8;
912 break;
913 }
914 }
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530915 mwl8k_add_dma_header(priv, skb, head_pad, data_pad);
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800916}
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100917
918/*
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530919 * Packet reception for 88w8366/88w8764 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200920 */
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530921struct mwl8k_rxd_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200922 __le16 pkt_len;
923 __u8 sq2;
924 __u8 rate;
925 __le32 pkt_phys_addr;
926 __le32 next_rxd_phys_addr;
927 __le16 qos_control;
928 __le16 htsig2;
929 __le32 hw_rssi_info;
930 __le32 hw_noise_floor_info;
931 __u8 noise_floor;
932 __u8 pad0[3];
933 __u8 rssi;
934 __u8 rx_status;
935 __u8 channel;
936 __u8 rx_ctrl;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000937} __packed;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200938
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530939#define MWL8K_AP_RATE_INFO_MCS_FORMAT 0x80
940#define MWL8K_AP_RATE_INFO_40MHZ 0x40
941#define MWL8K_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100942
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530943#define MWL8K_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200944
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530945/* 8366/8764 AP rx_status bits */
946#define MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
947#define MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
948#define MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
949#define MWL8K_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
950#define MWL8K_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800951
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530952static void mwl8k_rxd_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200953{
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530954 struct mwl8k_rxd_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200955
956 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530957 rxd->rx_ctrl = MWL8K_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200958}
959
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530960static void mwl8k_rxd_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200961{
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530962 struct mwl8k_rxd_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200963
964 rxd->pkt_len = cpu_to_le16(len);
965 rxd->pkt_phys_addr = cpu_to_le32(addr);
966 wmb();
967 rxd->rx_ctrl = 0;
968}
969
970static int
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530971mwl8k_rxd_ap_process(void *_rxd, struct ieee80211_rx_status *status,
972 __le16 *qos, s8 *noise)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200973{
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530974 struct mwl8k_rxd_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200975
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530976 if (!(rxd->rx_ctrl & MWL8K_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200977 return -1;
978 rmb();
979
980 memset(status, 0, sizeof(*status));
981
982 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -0400983 *noise = -rxd->noise_floor;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200984
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530985 if (rxd->rate & MWL8K_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200986 status->flag |= RX_FLAG_HT;
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530987 if (rxd->rate & MWL8K_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100988 status->flag |= RX_FLAG_40MHZ;
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +0530989 status->rate_idx = MWL8K_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200990 } else {
991 int i;
992
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100993 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
994 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200995 status->rate_idx = i;
996 break;
997 }
998 }
999 }
1000
Lennert Buytenhek85478342010-01-12 13:48:56 +01001001 if (rxd->channel > 14) {
1002 status->band = IEEE80211_BAND_5GHZ;
1003 if (!(status->flag & RX_FLAG_HT))
1004 status->rate_idx -= 5;
1005 } else {
1006 status->band = IEEE80211_BAND_2GHZ;
1007 }
Bruno Randolf59eb21a2011-01-17 13:37:28 +09001008 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1009 status->band);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02001010
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001011 *qos = rxd->qos_control;
1012
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +05301013 if ((rxd->rx_status != MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
1014 (rxd->rx_status & MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK) &&
1015 (rxd->rx_status & MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001016 status->flag |= RX_FLAG_MMIC_ERROR;
1017
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02001018 return le16_to_cpu(rxd->pkt_len);
1019}
1020
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +05301021static struct rxd_ops rxd_ap_ops = {
1022 .rxd_size = sizeof(struct mwl8k_rxd_ap),
1023 .rxd_init = mwl8k_rxd_ap_init,
1024 .rxd_refill = mwl8k_rxd_ap_refill,
1025 .rxd_process = mwl8k_rxd_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02001026};
1027
1028/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001029 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001030 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001031struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001032 __le16 pkt_len;
1033 __u8 link_quality;
1034 __u8 noise_level;
1035 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001036 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001037 __le16 qos_control;
1038 __le16 rate_info;
1039 __le32 pad0[4];
1040 __u8 rssi;
1041 __u8 channel;
1042 __le16 pad1;
1043 __u8 rx_ctrl;
1044 __u8 rx_status;
1045 __u8 pad2[2];
Eric Dumazetba2d3582010-06-02 18:10:09 +00001046} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001047
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001048#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
1049#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
1050#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
1051#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
1052#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
1053#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001054
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001055#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001056#define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
1057/* ICV=0 or MIC=1 */
1058#define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
1059/* Key is uploaded only in failure case */
1060#define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001061
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001062static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001063{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001064 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001065
1066 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001067 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001068}
1069
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001070static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001071{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001072 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001073
1074 rxd->pkt_len = cpu_to_le16(len);
1075 rxd->pkt_phys_addr = cpu_to_le32(addr);
1076 wmb();
1077 rxd->rx_ctrl = 0;
1078}
1079
1080static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001081mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -04001082 __le16 *qos, s8 *noise)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001083{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001084 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001085 u16 rate_info;
1086
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001087 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001088 return -1;
1089 rmb();
1090
1091 rate_info = le16_to_cpu(rxd->rate_info);
1092
1093 memset(status, 0, sizeof(*status));
1094
1095 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -04001096 *noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001097 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
1098 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001099
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001100 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001101 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001102 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001103 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001104 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001105 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001106 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001107 status->flag |= RX_FLAG_HT;
1108
Lennert Buytenhek85478342010-01-12 13:48:56 +01001109 if (rxd->channel > 14) {
1110 status->band = IEEE80211_BAND_5GHZ;
1111 if (!(status->flag & RX_FLAG_HT))
1112 status->rate_idx -= 5;
1113 } else {
1114 status->band = IEEE80211_BAND_2GHZ;
1115 }
Bruno Randolf59eb21a2011-01-17 13:37:28 +09001116 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1117 status->band);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001118
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001119 *qos = rxd->qos_control;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001120 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1121 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1122 status->flag |= RX_FLAG_MMIC_ERROR;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001123
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001124 return le16_to_cpu(rxd->pkt_len);
1125}
1126
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001127static struct rxd_ops rxd_sta_ops = {
1128 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1129 .rxd_init = mwl8k_rxd_sta_init,
1130 .rxd_refill = mwl8k_rxd_sta_refill,
1131 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001132};
1133
1134
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001135#define MWL8K_RX_DESCS 256
1136#define MWL8K_RX_MAXSZ 3800
1137
1138static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1139{
1140 struct mwl8k_priv *priv = hw->priv;
1141 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1142 int size;
1143 int i;
1144
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001145 rxq->rxd_count = 0;
1146 rxq->head = 0;
1147 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001148
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001149 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001150
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001151 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1152 if (rxq->rxd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001153 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001154 return -ENOMEM;
1155 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001156 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001157
Shan Weib9ede5f2011-03-08 11:02:03 +08001158 rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001159 if (rxq->buf == NULL) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001160 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001161 return -ENOMEM;
1162 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001163
1164 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001165 int desc_size;
1166 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001167 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001168 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001169
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001170 desc_size = priv->rxd_ops->rxd_size;
1171 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001172
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001173 nexti = i + 1;
1174 if (nexti == MWL8K_RX_DESCS)
1175 nexti = 0;
1176 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1177
1178 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001179 }
1180
1181 return 0;
1182}
1183
1184static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1185{
1186 struct mwl8k_priv *priv = hw->priv;
1187 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1188 int refilled;
1189
1190 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001191 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001192 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001193 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001194 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001195 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001196
1197 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1198 if (skb == NULL)
1199 break;
1200
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001201 addr = pci_map_single(priv->pdev, skb->data,
1202 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001204 rxq->rxd_count++;
1205 rx = rxq->tail++;
1206 if (rxq->tail == MWL8K_RX_DESCS)
1207 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001208 rxq->buf[rx].skb = skb;
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001209 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001210
1211 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1212 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001213
1214 refilled++;
1215 }
1216
1217 return refilled;
1218}
1219
1220/* Must be called only when the card's reception is completely halted */
1221static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1222{
1223 struct mwl8k_priv *priv = hw->priv;
1224 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1225 int i;
1226
Brian Cavagnolo73b46322011-03-17 11:58:41 -07001227 if (rxq->rxd == NULL)
1228 return;
1229
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001230 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001231 if (rxq->buf[i].skb != NULL) {
1232 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001233 dma_unmap_addr(&rxq->buf[i], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001234 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001235 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001236
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001237 kfree_skb(rxq->buf[i].skb);
1238 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001239 }
1240 }
1241
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001242 kfree(rxq->buf);
1243 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001244
1245 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001246 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001247 rxq->rxd, rxq->rxd_dma);
1248 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001249}
1250
1251
1252/*
1253 * Scan a list of BSSIDs to process for finalize join.
1254 * Allows for extension to process multiple BSSIDs.
1255 */
1256static inline int
1257mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1258{
1259 return priv->capture_beacon &&
1260 ieee80211_is_beacon(wh->frame_control) &&
Julia Lawall3f9a79b2013-12-30 19:15:01 +01001261 ether_addr_equal_64bits(wh->addr3, priv->capture_bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001262}
1263
Lennert Buytenhek37797522009-10-22 20:19:45 +02001264static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1265 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001266{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001267 struct mwl8k_priv *priv = hw->priv;
1268
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001269 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001270 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001271
1272 /*
1273 * Use GFP_ATOMIC as rxq_process is called from
1274 * the primary interrupt handler, memory allocation call
1275 * must not sleep.
1276 */
1277 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1278 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001279 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001280}
1281
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001282static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1283 u8 *bssid)
1284{
1285 struct mwl8k_vif *mwl8k_vif;
1286
1287 list_for_each_entry(mwl8k_vif,
1288 vif_list, list) {
1289 if (memcmp(bssid, mwl8k_vif->bssid,
1290 ETH_ALEN) == 0)
1291 return mwl8k_vif;
1292 }
1293
1294 return NULL;
1295}
1296
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001297static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1298{
1299 struct mwl8k_priv *priv = hw->priv;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001300 struct mwl8k_vif *mwl8k_vif = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001301 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1302 int processed;
1303
1304 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001305 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001306 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001307 void *rxd;
1308 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001309 struct ieee80211_rx_status status;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001310 struct ieee80211_hdr *wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001311 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001312
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001313 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001314 if (skb == NULL)
1315 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001316
1317 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1318
John W. Linville0d462bb2010-07-28 14:04:24 -04001319 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1320 &priv->noise);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001321 if (pkt_len < 0)
1322 break;
1323
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001324 rxq->buf[rxq->head].skb = NULL;
1325
1326 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001327 dma_unmap_addr(&rxq->buf[rxq->head], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001328 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001329 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001330
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001331 rxq->head++;
1332 if (rxq->head == MWL8K_RX_DESCS)
1333 rxq->head = 0;
1334
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001335 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001336
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001337 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001338
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001339 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001340 * Check for a pending join operation. Save a
1341 * copy of the beacon and schedule a tasklet to
1342 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001343 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001344 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001345 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001346
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001347 if (ieee80211_has_protected(wh->frame_control)) {
1348
1349 /* Check if hw crypto has been enabled for
1350 * this bss. If yes, set the status flags
1351 * accordingly
1352 */
1353 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1354 wh->addr1);
1355
1356 if (mwl8k_vif != NULL &&
Joe Perches23677ce2012-02-09 11:17:23 +00001357 mwl8k_vif->is_hw_crypto_enabled) {
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001358 /*
1359 * When MMIC ERROR is encountered
1360 * by the firmware, payload is
1361 * dropped and only 32 bytes of
1362 * mwl8k Firmware header is sent
1363 * to the host.
1364 *
1365 * We need to add four bytes of
1366 * key information. In it
1367 * MAC80211 expects keyidx set to
1368 * 0 for triggering Counter
1369 * Measure of MMIC failure.
1370 */
1371 if (status.flag & RX_FLAG_MMIC_ERROR) {
1372 struct mwl8k_dma_data *tr;
1373 tr = (struct mwl8k_dma_data *)skb->data;
1374 memset((void *)&(tr->data), 0, 4);
1375 pkt_len += 4;
1376 }
1377
1378 if (!ieee80211_is_auth(wh->frame_control))
1379 status.flag |= RX_FLAG_IV_STRIPPED |
1380 RX_FLAG_DECRYPTED |
1381 RX_FLAG_MMIC_STRIPPED;
1382 }
1383 }
1384
1385 skb_put(skb, pkt_len);
1386 mwl8k_remove_dma_header(skb, qos);
Johannes Bergf1d58c22009-06-17 13:13:00 +02001387 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1388 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001389
1390 processed++;
1391 }
1392
1393 return processed;
1394}
1395
1396
1397/*
1398 * Packet transmission.
1399 */
1400
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001401#define MWL8K_TXD_STATUS_OK 0x00000001
1402#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1403#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1404#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001405#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001406
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001407#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1408#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1409#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1410#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1411#define MWL8K_QOS_EOSP 0x0010
1412
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001413struct mwl8k_tx_desc {
1414 __le32 status;
1415 __u8 data_rate;
1416 __u8 tx_priority;
1417 __le16 qos_control;
1418 __le32 pkt_phys_addr;
1419 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001420 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001421 __le32 next_txd_phys_addr;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07001422 __le32 timestamp;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001423 __le16 rate_info;
1424 __u8 peer_id;
Brian Cavagnoloa1fe24b2010-11-12 17:23:47 -08001425 __u8 tx_frag_cnt;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001426} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001427
1428#define MWL8K_TX_DESCS 128
1429
1430static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1431{
1432 struct mwl8k_priv *priv = hw->priv;
1433 struct mwl8k_tx_queue *txq = priv->txq + index;
1434 int size;
1435 int i;
1436
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001437 txq->len = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001438 txq->head = 0;
1439 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001440
1441 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1442
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001443 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1444 if (txq->txd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001445 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001446 return -ENOMEM;
1447 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001448 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001449
Shan Weib9ede5f2011-03-08 11:02:03 +08001450 txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001451 if (txq->skb == NULL) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001452 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001453 return -ENOMEM;
1454 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001455
1456 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1457 struct mwl8k_tx_desc *tx_desc;
1458 int nexti;
1459
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001460 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001461 nexti = (i + 1) % MWL8K_TX_DESCS;
1462
1463 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001464 tx_desc->next_txd_phys_addr =
1465 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001466 }
1467
1468 return 0;
1469}
1470
1471static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1472{
1473 iowrite32(MWL8K_H2A_INT_PPA_READY,
1474 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1475 iowrite32(MWL8K_H2A_INT_DUMMY,
1476 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1477 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1478}
1479
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001480static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001481{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001482 struct mwl8k_priv *priv = hw->priv;
1483 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001484
Brian Cavagnoloe6007072011-03-17 11:58:44 -07001485 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001486 struct mwl8k_tx_queue *txq = priv->txq + i;
1487 int fw_owned = 0;
1488 int drv_owned = 0;
1489 int unused = 0;
1490 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001491
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001492 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001493 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1494 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001495
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001496 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001497 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001498 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001499 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001500 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001501
1502 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001503 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001504 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001505
Joe Perchesc96c31e2010-07-26 14:39:58 -07001506 wiphy_err(hw->wiphy,
1507 "txq[%d] len=%d head=%d tail=%d "
1508 "fw_owned=%d drv_owned=%d unused=%d\n",
1509 i,
1510 txq->len, txq->head, txq->tail,
1511 fw_owned, drv_owned, unused);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001512 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001513}
1514
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001515/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001516 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001517 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001518#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001519
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001520static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001521{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001522 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001523 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001524 int retry;
1525 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001526
1527 might_sleep();
1528
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05301529 /* Since fw restart is in progress, allow only the firmware
1530 * commands from the restart code and block the other
1531 * commands since they are going to fail in any case since
1532 * the firmware has crashed
1533 */
1534 if (priv->hw_restart_in_progress) {
1535 if (priv->hw_restart_owner == current)
1536 return 0;
1537 else
1538 return -EBUSY;
1539 }
1540
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05301541 if (atomic_read(&priv->watchdog_event_pending))
1542 return 0;
1543
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001544 /*
1545 * The TX queues are stopped at this point, so this test
1546 * doesn't need to take ->tx_lock.
1547 */
1548 if (!priv->pending_tx_pkts)
1549 return 0;
1550
Nishant Sarmukadambbf71a82013-05-24 14:42:25 +05301551 retry = 1;
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001552 rc = 0;
1553
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001554 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001555 priv->tx_wait = &tx_wait;
1556 while (!rc) {
1557 int oldcount;
1558 unsigned long timeout;
1559
1560 oldcount = priv->pending_tx_pkts;
1561
1562 spin_unlock_bh(&priv->tx_lock);
1563 timeout = wait_for_completion_timeout(&tx_wait,
1564 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05301565
1566 if (atomic_read(&priv->watchdog_event_pending)) {
1567 spin_lock_bh(&priv->tx_lock);
1568 priv->tx_wait = NULL;
1569 spin_unlock_bh(&priv->tx_lock);
1570 return 0;
1571 }
1572
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001573 spin_lock_bh(&priv->tx_lock);
1574
Nishant Sarmukadambbf71a82013-05-24 14:42:25 +05301575 if (timeout || !priv->pending_tx_pkts) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001576 WARN_ON(priv->pending_tx_pkts);
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301577 if (retry)
Joe Perchesc96c31e2010-07-26 14:39:58 -07001578 wiphy_notice(hw->wiphy, "tx rings drained\n");
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001579 break;
1580 }
1581
Nishant Sarmukadambbf71a82013-05-24 14:42:25 +05301582 if (retry) {
1583 mwl8k_tx_start(priv);
1584 retry = 0;
1585 continue;
1586 }
1587
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001588 if (priv->pending_tx_pkts < oldcount) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001589 wiphy_notice(hw->wiphy,
1590 "waiting for tx rings to drain (%d -> %d pkts)\n",
1591 oldcount, priv->pending_tx_pkts);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001592 retry = 1;
1593 continue;
1594 }
1595
1596 priv->tx_wait = NULL;
1597
Joe Perchesc96c31e2010-07-26 14:39:58 -07001598 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1599 MWL8K_TX_WAIT_TIMEOUT_MS);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001600 mwl8k_dump_tx_rings(hw);
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05301601 priv->hw_restart_in_progress = true;
1602 ieee80211_queue_work(hw, &priv->fw_reload);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001603
1604 rc = -ETIMEDOUT;
1605 }
Nishant Sarmukadam9b0b11f2013-01-08 10:16:05 +05301606 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001607 spin_unlock_bh(&priv->tx_lock);
1608
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001609 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001610}
1611
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001612#define MWL8K_TXD_SUCCESS(status) \
1613 ((status) & (MWL8K_TXD_STATUS_OK | \
1614 MWL8K_TXD_STATUS_OK_RETRY | \
1615 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001616
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001617static int mwl8k_tid_queue_mapping(u8 tid)
1618{
1619 BUG_ON(tid > 7);
1620
1621 switch (tid) {
1622 case 0:
1623 case 3:
1624 return IEEE80211_AC_BE;
1625 break;
1626 case 1:
1627 case 2:
1628 return IEEE80211_AC_BK;
1629 break;
1630 case 4:
1631 case 5:
1632 return IEEE80211_AC_VI;
1633 break;
1634 case 6:
1635 case 7:
1636 return IEEE80211_AC_VO;
1637 break;
1638 default:
1639 return -1;
1640 break;
1641 }
1642}
1643
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001644/* The firmware will fill in the rate information
1645 * for each packet that gets queued in the hardware
John W. Linville49adc5c2011-04-27 15:04:28 -04001646 * and these macros will interpret that info.
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001647 */
1648
John W. Linville49adc5c2011-04-27 15:04:28 -04001649#define RI_FORMAT(a) (a & 0x0001)
1650#define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001651
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001652static int
1653mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001654{
1655 struct mwl8k_priv *priv = hw->priv;
1656 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001657 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001658
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001659 processed = 0;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001660 while (txq->len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001661 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001662 struct mwl8k_tx_desc *tx_desc;
1663 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001664 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001665 struct sk_buff *skb;
1666 struct ieee80211_tx_info *info;
1667 u32 status;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001668 struct ieee80211_sta *sta;
1669 struct mwl8k_sta *sta_info = NULL;
1670 u16 rate_info;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001671 struct ieee80211_hdr *wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001672
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001673 tx = txq->head;
1674 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001675
1676 status = le32_to_cpu(tx_desc->status);
1677
1678 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1679 if (!force)
1680 break;
1681 tx_desc->status &=
1682 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1683 }
1684
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001685 txq->head = (tx + 1) % MWL8K_TX_DESCS;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001686 BUG_ON(txq->len == 0);
1687 txq->len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001688 priv->pending_tx_pkts--;
1689
1690 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001691 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001692 skb = txq->skb[tx];
1693 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001694
1695 BUG_ON(skb == NULL);
1696 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1697
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001698 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001699
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001700 wh = (struct ieee80211_hdr *) skb->data;
1701
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001702 /* Mark descriptor as unused */
1703 tx_desc->pkt_phys_addr = 0;
1704 tx_desc->pkt_len = 0;
1705
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001706 info = IEEE80211_SKB_CB(skb);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001707 if (ieee80211_is_data(wh->frame_control)) {
Thomas Huehn89e11802012-07-11 13:21:41 +02001708 rcu_read_lock();
1709 sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
1710 wh->addr2);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001711 if (sta) {
1712 sta_info = MWL8K_STA(sta);
1713 BUG_ON(sta_info == NULL);
1714 rate_info = le16_to_cpu(tx_desc->rate_info);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001715 /* If rate is < 6.5 Mpbs for an ht station
1716 * do not form an ampdu. If the station is a
1717 * legacy station (format = 0), do not form an
1718 * ampdu
1719 */
John W. Linville49adc5c2011-04-27 15:04:28 -04001720 if (RI_RATE_ID_MCS(rate_info) < 1 ||
1721 RI_FORMAT(rate_info) == 0) {
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001722 sta_info->is_ampdu_allowed = false;
1723 } else {
1724 sta_info->is_ampdu_allowed = true;
1725 }
1726 }
Thomas Huehn89e11802012-07-11 13:21:41 +02001727 rcu_read_unlock();
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001728 }
1729
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001730 ieee80211_tx_info_clear_status(info);
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08001731
1732 /* Rate control is happening in the firmware.
1733 * Ensure no tx rate is being reported.
1734 */
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301735 info->status.rates[0].idx = -1;
1736 info->status.rates[0].count = 1;
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08001737
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001738 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001739 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001740
1741 ieee80211_tx_status_irqsafe(hw, skb);
1742
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001743 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001744 }
1745
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001746 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001747}
1748
1749/* must be called only when the card's transmit is completely halted */
1750static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1751{
1752 struct mwl8k_priv *priv = hw->priv;
1753 struct mwl8k_tx_queue *txq = priv->txq + index;
1754
Brian Cavagnolo73b46322011-03-17 11:58:41 -07001755 if (txq->txd == NULL)
1756 return;
1757
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001758 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001759
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001760 kfree(txq->skb);
1761 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001762
1763 pci_free_consistent(priv->pdev,
1764 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001765 txq->txd, txq->txd_dma);
1766 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001767}
1768
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001769/* caller must hold priv->stream_lock when calling the stream functions */
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301770static struct mwl8k_ampdu_stream *
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001771mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
1772{
1773 struct mwl8k_ampdu_stream *stream;
1774 struct mwl8k_priv *priv = hw->priv;
1775 int i;
1776
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301777 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001778 stream = &priv->ampdu[i];
1779 if (stream->state == AMPDU_NO_STREAM) {
1780 stream->sta = sta;
1781 stream->state = AMPDU_STREAM_NEW;
1782 stream->tid = tid;
1783 stream->idx = i;
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001784 wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
1785 sta->addr, tid);
1786 return stream;
1787 }
1788 }
1789 return NULL;
1790}
1791
1792static int
1793mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1794{
1795 int ret;
1796
1797 /* if the stream has already been started, don't start it again */
1798 if (stream->state != AMPDU_STREAM_NEW)
1799 return 0;
1800 ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
1801 if (ret)
1802 wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
1803 "%d\n", stream->sta->addr, stream->tid, ret);
1804 else
1805 wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
1806 stream->sta->addr, stream->tid);
1807 return ret;
1808}
1809
1810static void
1811mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1812{
1813 wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
1814 stream->tid);
1815 memset(stream, 0, sizeof(*stream));
1816}
1817
1818static struct mwl8k_ampdu_stream *
1819mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
1820{
1821 struct mwl8k_priv *priv = hw->priv;
1822 int i;
1823
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301824 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001825 struct mwl8k_ampdu_stream *stream;
1826 stream = &priv->ampdu[i];
1827 if (stream->state == AMPDU_NO_STREAM)
1828 continue;
1829 if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
1830 stream->tid == tid)
1831 return stream;
1832 }
1833 return NULL;
1834}
1835
Brian Cavagnolod0805c12011-04-12 11:06:28 -07001836#define MWL8K_AMPDU_PACKET_THRESHOLD 64
1837static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
1838{
1839 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1840 struct tx_traffic_info *tx_stats;
1841
1842 BUG_ON(tid >= MWL8K_MAX_TID);
1843 tx_stats = &sta_info->tx_stats[tid];
1844
1845 return sta_info->is_ampdu_allowed &&
1846 tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
1847}
1848
1849static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
1850{
1851 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1852 struct tx_traffic_info *tx_stats;
1853
1854 BUG_ON(tid >= MWL8K_MAX_TID);
1855 tx_stats = &sta_info->tx_stats[tid];
1856
1857 if (tx_stats->start_time == 0)
1858 tx_stats->start_time = jiffies;
1859
1860 /* reset the packet count after each second elapses. If the number of
1861 * packets ever exceeds the ampdu_min_traffic threshold, we will allow
1862 * an ampdu stream to be started.
1863 */
1864 if (jiffies - tx_stats->start_time > HZ) {
1865 tx_stats->pkts = 0;
1866 tx_stats->start_time = 0;
1867 } else
1868 tx_stats->pkts++;
1869}
1870
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301871/* The hardware ampdu queues start from 5.
1872 * txpriorities for ampdu queues are
1873 * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
1874 * and queue 3 is lowest (queue 4 is reserved)
1875 */
1876#define BA_QUEUE 5
1877
Johannes Berg7bb45682011-02-24 14:42:06 +01001878static void
Thomas Huehn36323f82012-07-23 21:33:42 +02001879mwl8k_txq_xmit(struct ieee80211_hw *hw,
1880 int index,
1881 struct ieee80211_sta *sta,
1882 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001883{
1884 struct mwl8k_priv *priv = hw->priv;
1885 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001886 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001887 struct ieee80211_hdr *wh;
1888 struct mwl8k_tx_queue *txq;
1889 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001890 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001891 u32 txstatus;
1892 u8 txdatarate;
1893 u16 qos;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001894 int txpriority;
1895 u8 tid = 0;
1896 struct mwl8k_ampdu_stream *stream = NULL;
1897 bool start_ba_session = false;
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05301898 bool mgmtframe = false;
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001899 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301900 bool eapol_frame = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001901
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001902 wh = (struct ieee80211_hdr *)skb->data;
1903 if (ieee80211_is_data_qos(wh->frame_control))
1904 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1905 else
1906 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001907
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301908 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
1909 eapol_frame = true;
1910
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05301911 if (ieee80211_is_mgmt(wh->frame_control))
1912 mgmtframe = true;
1913
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001914 if (priv->ap_fw)
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +05301915 mwl8k_encapsulate_tx_frame(priv, skb);
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001916 else
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +05301917 mwl8k_add_dma_header(priv, skb, 0, 0);
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001918
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001919 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001920
1921 tx_info = IEEE80211_SKB_CB(skb);
1922 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001923
1924 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001925 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001926 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1927 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001928 }
1929
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001930 /* Setup firmware control bit fields for each frame type. */
1931 txstatus = 0;
1932 txdatarate = 0;
1933 if (ieee80211_is_mgmt(wh->frame_control) ||
1934 ieee80211_is_ctl(wh->frame_control)) {
1935 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001936 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001937 } else if (ieee80211_is_data(wh->frame_control)) {
1938 txdatarate = 1;
1939 if (is_multicast_ether_addr(wh->addr1))
1940 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1941
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001942 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001943 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001944 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001945 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001946 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001947 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001948
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001949 /* Queue ADDBA request in the respective data queue. While setting up
1950 * the ampdu stream, mac80211 queues further packets for that
1951 * particular ra/tid pair. However, packets piled up in the hardware
1952 * for that ra/tid pair will still go out. ADDBA request and the
1953 * related data packets going out from different queues asynchronously
1954 * will cause a shift in the receiver window which might result in
1955 * ampdu packets getting dropped at the receiver after the stream has
1956 * been setup.
1957 */
1958 if (unlikely(ieee80211_is_action(wh->frame_control) &&
1959 mgmt->u.action.category == WLAN_CATEGORY_BACK &&
1960 mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
1961 priv->ap_fw)) {
1962 u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1963 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1964 index = mwl8k_tid_queue_mapping(tid);
1965 }
1966
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001967 txpriority = index;
1968
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301969 if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame &&
1970 ieee80211_is_data_qos(wh->frame_control)) {
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001971 tid = qos & 0xf;
Brian Cavagnolod0805c12011-04-12 11:06:28 -07001972 mwl8k_tx_count_packet(sta, tid);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001973 spin_lock(&priv->stream_lock);
1974 stream = mwl8k_lookup_stream(hw, sta->addr, tid);
1975 if (stream != NULL) {
1976 if (stream->state == AMPDU_STREAM_ACTIVE) {
Yogesh Ashok Powar5f2a1492013-01-03 13:21:25 +05301977 WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK));
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301978 txpriority = (BA_QUEUE + stream->idx) %
1979 TOTAL_HW_TX_QUEUES;
1980 if (stream->idx <= 1)
1981 index = stream->idx +
1982 MWL8K_TX_WMM_QUEUES;
1983
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001984 } else if (stream->state == AMPDU_STREAM_NEW) {
1985 /* We get here if the driver sends us packets
1986 * after we've initiated a stream, but before
1987 * our ampdu_action routine has been called
1988 * with IEEE80211_AMPDU_TX_START to get the SSN
1989 * for the ADDBA request. So this packet can
1990 * go out with no risk of sequence number
1991 * mismatch. No special handling is required.
1992 */
1993 } else {
1994 /* Drop packets that would go out after the
1995 * ADDBA request was sent but before the ADDBA
1996 * response is received. If we don't do this,
1997 * the recipient would probably receive it
1998 * after the ADDBA request with SSN 0. This
1999 * will cause the recipient's BA receive window
2000 * to shift, which would cause the subsequent
2001 * packets in the BA stream to be discarded.
2002 * mac80211 queues our packets for us in this
2003 * case, so this is really just a safety check.
2004 */
2005 wiphy_warn(hw->wiphy,
2006 "Cannot send packet while ADDBA "
2007 "dialog is underway.\n");
2008 spin_unlock(&priv->stream_lock);
2009 dev_kfree_skb(skb);
2010 return;
2011 }
2012 } else {
2013 /* Defer calling mwl8k_start_stream so that the current
2014 * skb can go out before the ADDBA request. This
2015 * prevents sequence number mismatch at the recepient
2016 * as described above.
2017 */
Brian Cavagnolod0805c12011-04-12 11:06:28 -07002018 if (mwl8k_ampdu_allowed(sta, tid)) {
Nishant Sarmukadam170335432011-03-17 11:58:48 -07002019 stream = mwl8k_add_stream(hw, sta, tid);
2020 if (stream != NULL)
2021 start_ba_session = true;
2022 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002023 }
2024 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar5f2a1492013-01-03 13:21:25 +05302025 } else {
2026 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
2027 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002028 }
2029
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002030 dma = pci_map_single(priv->pdev, skb->data,
2031 skb->len, PCI_DMA_TODEVICE);
2032
2033 if (pci_dma_mapping_error(priv->pdev, dma)) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07002034 wiphy_debug(hw->wiphy,
2035 "failed to dma map skb, dropping TX frame.\n");
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002036 if (start_ba_session) {
2037 spin_lock(&priv->stream_lock);
2038 mwl8k_remove_stream(hw, stream);
2039 spin_unlock(&priv->stream_lock);
2040 }
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002041 dev_kfree_skb(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +01002042 return;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002043 }
2044
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002045 spin_lock_bh(&priv->tx_lock);
2046
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002047 txq = priv->txq + index;
2048
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302049 /* Mgmt frames that go out frequently are probe
2050 * responses. Other mgmt frames got out relatively
2051 * infrequently. Hence reserve 2 buffers so that
2052 * other mgmt frames do not get dropped due to an
2053 * already queued probe response in one of the
2054 * reserved buffers.
2055 */
2056
2057 if (txq->len >= MWL8K_TX_DESCS - 2) {
Joe Perches23677ce2012-02-09 11:17:23 +00002058 if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302059 if (start_ba_session) {
2060 spin_lock(&priv->stream_lock);
2061 mwl8k_remove_stream(hw, stream);
2062 spin_unlock(&priv->stream_lock);
2063 }
Nishant Sarmukadambbf71a82013-05-24 14:42:25 +05302064 mwl8k_tx_start(priv);
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302065 spin_unlock_bh(&priv->tx_lock);
Nishant Sarmukadamff7aa962012-11-06 19:22:48 +05302066 pci_unmap_single(priv->pdev, dma, skb->len,
2067 PCI_DMA_TODEVICE);
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302068 dev_kfree_skb(skb);
2069 return;
Pradeep Nemavat3a7dbc32011-04-21 16:34:56 +05302070 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002071 }
2072
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002073 BUG_ON(txq->skb[txq->tail] != NULL);
2074 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002075
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002076 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002077 tx->data_rate = txdatarate;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002078 tx->tx_priority = txpriority;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002079 tx->qos_control = cpu_to_le16(qos);
2080 tx->pkt_phys_addr = cpu_to_le32(dma);
2081 tx->pkt_len = cpu_to_le16(skb->len);
2082 tx->rate_info = 0;
Thomas Huehn36323f82012-07-23 21:33:42 +02002083 if (!priv->ap_fw && sta != NULL)
2084 tx->peer_id = MWL8K_STA(sta)->peer_id;
Lennert Buytenheka6804002010-01-04 21:55:42 +01002085 else
2086 tx->peer_id = 0;
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302087
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05302088 if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame)
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302089 tx->timestamp = cpu_to_le32(ioread32(priv->regs +
2090 MWL8K_HW_TIMER_REGISTER));
Nishant Sarmukadamb8d9e572012-11-06 19:23:15 +05302091 else
2092 tx->timestamp = 0;
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302093
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002094 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002095 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
2096
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02002097 txq->len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002098 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002099
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002100 txq->tail++;
2101 if (txq->tail == MWL8K_TX_DESCS)
2102 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002103
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002104 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002105
2106 spin_unlock_bh(&priv->tx_lock);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002107
2108 /* Initiate the ampdu session here */
2109 if (start_ba_session) {
2110 spin_lock(&priv->stream_lock);
2111 if (mwl8k_start_stream(hw, stream))
2112 mwl8k_remove_stream(hw, stream);
2113 spin_unlock(&priv->stream_lock);
2114 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002115}
2116
2117
2118/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002119 * Firmware access.
2120 *
2121 * We have the following requirements for issuing firmware commands:
2122 * - Some commands require that the packet transmit path is idle when
2123 * the command is issued. (For simplicity, we'll just quiesce the
2124 * transmit path for every command.)
2125 * - There are certain sequences of commands that need to be issued to
2126 * the hardware sequentially, with no other intervening commands.
2127 *
2128 * This leads to an implementation of a "firmware lock" as a mutex that
2129 * can be taken recursively, and which is taken by both the low-level
2130 * command submission function (mwl8k_post_cmd) as well as any users of
2131 * that function that require issuing of an atomic sequence of commands,
2132 * and quiesces the transmit path whenever it's taken.
2133 */
2134static int mwl8k_fw_lock(struct ieee80211_hw *hw)
2135{
2136 struct mwl8k_priv *priv = hw->priv;
2137
2138 if (priv->fw_mutex_owner != current) {
2139 int rc;
2140
2141 mutex_lock(&priv->fw_mutex);
2142 ieee80211_stop_queues(hw);
2143
2144 rc = mwl8k_tx_wait_empty(hw);
2145 if (rc) {
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05302146 if (!priv->hw_restart_in_progress)
2147 ieee80211_wake_queues(hw);
2148
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002149 mutex_unlock(&priv->fw_mutex);
2150
2151 return rc;
2152 }
2153
2154 priv->fw_mutex_owner = current;
2155 }
2156
2157 priv->fw_mutex_depth++;
2158
2159 return 0;
2160}
2161
2162static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
2163{
2164 struct mwl8k_priv *priv = hw->priv;
2165
2166 if (!--priv->fw_mutex_depth) {
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05302167 if (!priv->hw_restart_in_progress)
2168 ieee80211_wake_queues(hw);
2169
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002170 priv->fw_mutex_owner = NULL;
2171 mutex_unlock(&priv->fw_mutex);
2172 }
2173}
2174
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +05302175static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable,
2176 u32 bitmap);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002177
2178/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002179 * Command processing.
2180 */
2181
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01002182/* Timeout firmware commands after 10s */
2183#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002184
2185static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
2186{
2187 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2188 struct mwl8k_priv *priv = hw->priv;
2189 void __iomem *regs = priv->regs;
2190 dma_addr_t dma_addr;
2191 unsigned int dma_size;
2192 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002193 unsigned long timeout = 0;
2194 u8 buf[32];
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +05302195 u32 bitmap = 0;
2196
2197 wiphy_dbg(hw->wiphy, "Posting %s [%d]\n",
2198 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), cmd->macid);
2199
2200 /* Before posting firmware commands that could change the hardware
2201 * characteristics, make sure that all BSSes are stopped temporary.
2202 * Enable these stopped BSSes after completion of the commands
2203 */
2204
2205 rc = mwl8k_fw_lock(hw);
2206 if (rc)
2207 return rc;
2208
2209 if (priv->ap_fw && priv->running_bsses) {
2210 switch (le16_to_cpu(cmd->code)) {
2211 case MWL8K_CMD_SET_RF_CHANNEL:
2212 case MWL8K_CMD_RADIO_CONTROL:
2213 case MWL8K_CMD_RF_TX_POWER:
2214 case MWL8K_CMD_TX_POWER:
2215 case MWL8K_CMD_RF_ANTENNA:
2216 case MWL8K_CMD_RTS_THRESHOLD:
2217 case MWL8K_CMD_MIMO_CONFIG:
2218 bitmap = priv->running_bsses;
2219 mwl8k_enable_bsses(hw, false, bitmap);
2220 break;
2221 }
2222 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002223
John W. Linvilleb6037422010-07-20 13:55:00 -04002224 cmd->result = (__force __le16) 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002225 dma_size = le16_to_cpu(cmd->length);
2226 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
2227 PCI_DMA_BIDIRECTIONAL);
2228 if (pci_dma_mapping_error(priv->pdev, dma_addr))
2229 return -ENOMEM;
2230
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002231 priv->hostcmd_wait = &cmd_wait;
2232 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
2233 iowrite32(MWL8K_H2A_INT_DOORBELL,
2234 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2235 iowrite32(MWL8K_H2A_INT_DUMMY,
2236 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002237
2238 timeout = wait_for_completion_timeout(&cmd_wait,
2239 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
2240
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002241 priv->hostcmd_wait = NULL;
2242
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002243
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02002244 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2245 PCI_DMA_BIDIRECTIONAL);
2246
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002247 if (!timeout) {
Joe Perches5db55842010-08-11 19:11:19 -07002248 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002249 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2250 MWL8K_CMD_TIMEOUT_MS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002251 rc = -ETIMEDOUT;
2252 } else {
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01002253 int ms;
2254
2255 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
2256
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002257 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002258 if (rc)
Joe Perches5db55842010-08-11 19:11:19 -07002259 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002260 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2261 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01002262 else if (ms > 2000)
Joe Perches5db55842010-08-11 19:11:19 -07002263 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002264 mwl8k_cmd_name(cmd->code,
2265 buf, sizeof(buf)),
2266 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002267 }
2268
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +05302269 if (bitmap)
2270 mwl8k_enable_bsses(hw, true, bitmap);
2271
2272 mwl8k_fw_unlock(hw);
2273
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002274 return rc;
2275}
2276
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +01002277static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
2278 struct ieee80211_vif *vif,
2279 struct mwl8k_cmd_pkt *cmd)
2280{
2281 if (vif != NULL)
2282 cmd->macid = MWL8K_VIF(vif)->macid;
2283 return mwl8k_post_cmd(hw, cmd);
2284}
2285
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002286/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01002287 * Setup code shared between STA and AP firmware images.
2288 */
2289static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
2290{
2291 struct mwl8k_priv *priv = hw->priv;
2292
2293 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
2294 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
2295
2296 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
2297 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
2298
2299 priv->band_24.band = IEEE80211_BAND_2GHZ;
2300 priv->band_24.channels = priv->channels_24;
2301 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
2302 priv->band_24.bitrates = priv->rates_24;
2303 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
2304
2305 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
2306}
2307
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01002308static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
2309{
2310 struct mwl8k_priv *priv = hw->priv;
2311
2312 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
2313 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
2314
2315 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
2316 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
2317
2318 priv->band_50.band = IEEE80211_BAND_5GHZ;
2319 priv->band_50.channels = priv->channels_50;
2320 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
2321 priv->band_50.bitrates = priv->rates_50;
2322 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
2323
2324 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
2325}
2326
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01002327/*
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02002328 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002329 */
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02002330struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002331 struct mwl8k_cmd_pkt header;
2332 __u8 hw_rev;
2333 __u8 host_interface;
2334 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002335 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002336 __le16 region_code;
2337 __le32 fw_rev;
2338 __le32 ps_cookie;
2339 __le32 caps;
2340 __u8 mcs_bitmap[16];
2341 __le32 rx_queue_ptr;
2342 __le32 num_tx_queues;
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002343 __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002344 __le32 caps2;
2345 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002346 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002347} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002348
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002349#define MWL8K_CAP_MAX_AMSDU 0x20000000
2350#define MWL8K_CAP_GREENFIELD 0x08000000
2351#define MWL8K_CAP_AMPDU 0x04000000
2352#define MWL8K_CAP_RX_STBC 0x01000000
2353#define MWL8K_CAP_TX_STBC 0x00800000
2354#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2355#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2356#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2357#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2358#define MWL8K_CAP_DELAY_BA 0x00003000
2359#define MWL8K_CAP_MIMO 0x00000200
2360#define MWL8K_CAP_40MHZ 0x00000100
Lennert Buytenhek06953232010-01-12 13:49:41 +01002361#define MWL8K_CAP_BAND_MASK 0x00000007
2362#define MWL8K_CAP_5GHZ 0x00000004
2363#define MWL8K_CAP_2GHZ4 0x00000001
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002364
Lennert Buytenhek06953232010-01-12 13:49:41 +01002365static void
2366mwl8k_set_ht_caps(struct ieee80211_hw *hw,
2367 struct ieee80211_supported_band *band, u32 cap)
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002368{
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002369 int rx_streams;
2370 int tx_streams;
2371
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002372 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002373
2374 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002375 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002376 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002377 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002378 if (cap & MWL8K_CAP_AMPDU) {
2379 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002380 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2381 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002382 }
2383 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002384 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002385 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002386 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002387 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002388 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002389 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002390 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002391 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002392 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002393 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002394 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002395
2396 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
2397 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
2398
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002399 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002400 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002401 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002402 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002403 band->ht_cap.mcs.rx_mask[2] = 0xff;
2404 band->ht_cap.mcs.rx_mask[4] = 0x01;
2405 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002406
2407 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002408 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
2409 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002410 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2411 }
2412}
2413
Lennert Buytenhek06953232010-01-12 13:49:41 +01002414static void
2415mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
2416{
2417 struct mwl8k_priv *priv = hw->priv;
2418
Jonas Gorskic3f251a2013-03-11 17:44:21 +01002419 if (priv->caps)
2420 return;
2421
Lennert Buytenhek06953232010-01-12 13:49:41 +01002422 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
2423 mwl8k_setup_2ghz_band(hw);
2424 if (caps & MWL8K_CAP_MIMO)
2425 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
2426 }
2427
2428 if (caps & MWL8K_CAP_5GHZ) {
2429 mwl8k_setup_5ghz_band(hw);
2430 if (caps & MWL8K_CAP_MIMO)
2431 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
2432 }
Jonas Gorskic3f251a2013-03-11 17:44:21 +01002433
2434 priv->caps = caps;
Lennert Buytenhek06953232010-01-12 13:49:41 +01002435}
2436
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02002437static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002438{
2439 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02002440 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002441 int rc;
2442 int i;
2443
2444 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2445 if (cmd == NULL)
2446 return -ENOMEM;
2447
2448 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2449 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2450
2451 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2452 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002453 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002454 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2455 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002456 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02002457 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002458 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002459
2460 rc = mwl8k_post_cmd(hw, &cmd->header);
2461
2462 if (!rc) {
2463 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2464 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02002465 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002466 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek06953232010-01-12 13:49:41 +01002467 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002468 priv->ap_macids_supported = 0x00000000;
2469 priv->sta_macids_supported = 0x00000001;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002470 }
2471
2472 kfree(cmd);
2473 return rc;
2474}
2475
2476/*
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002477 * CMD_GET_HW_SPEC (AP version).
2478 */
2479struct mwl8k_cmd_get_hw_spec_ap {
2480 struct mwl8k_cmd_pkt header;
2481 __u8 hw_rev;
2482 __u8 host_interface;
2483 __le16 num_wcb;
2484 __le16 num_mcaddrs;
2485 __u8 perm_addr[ETH_ALEN];
2486 __le16 region_code;
2487 __le16 num_antenna;
2488 __le32 fw_rev;
2489 __le32 wcbbase0;
2490 __le32 rxwrptr;
2491 __le32 rxrdptr;
2492 __le32 ps_cookie;
2493 __le32 wcbbase1;
2494 __le32 wcbbase2;
2495 __le32 wcbbase3;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002496 __le32 fw_api_version;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002497 __le32 caps;
2498 __le32 num_of_ampdu_queues;
2499 __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002500} __packed;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002501
2502static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2503{
2504 struct mwl8k_priv *priv = hw->priv;
2505 struct mwl8k_cmd_get_hw_spec_ap *cmd;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002506 int rc, i;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002507 u32 api_version;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002508
2509 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2510 if (cmd == NULL)
2511 return -ENOMEM;
2512
2513 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2514 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2515
2516 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2517 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2518
2519 rc = mwl8k_post_cmd(hw, &cmd->header);
2520
2521 if (!rc) {
2522 int off;
2523
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002524 api_version = le32_to_cpu(cmd->fw_api_version);
2525 if (priv->device_info->fw_api_ap != api_version) {
2526 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2527 " Expected %d got %d.\n", MWL8K_NAME,
2528 priv->device_info->part_name,
2529 priv->device_info->fw_api_ap,
2530 api_version);
2531 rc = -EINVAL;
2532 goto done;
2533 }
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002534 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2535 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2536 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2537 priv->hw_rev = cmd->hw_rev;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002538 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002539 priv->ap_macids_supported = 0x000000ff;
Yogesh Ashok Poward59c1cf2013-01-25 16:20:03 +05302540 priv->sta_macids_supported = 0x00000100;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002541 priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
2542 if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
2543 wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
2544 " but we only support %d.\n",
2545 priv->num_ampdu_queues,
2546 MWL8K_MAX_AMPDU_QUEUES);
2547 priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
2548 }
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002549 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002550 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002551
2552 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002553 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002554
Brian Cavagnolo73b46322011-03-17 11:58:41 -07002555 priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
2556 priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
2557 priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
2558 priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002559
2560 for (i = 0; i < priv->num_ampdu_queues; i++)
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002561 priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002562 le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002563 }
2564
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002565done:
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002566 kfree(cmd);
2567 return rc;
2568}
2569
2570/*
2571 * CMD_SET_HW_SPEC.
2572 */
2573struct mwl8k_cmd_set_hw_spec {
2574 struct mwl8k_cmd_pkt header;
2575 __u8 hw_rev;
2576 __u8 host_interface;
2577 __le16 num_mcaddrs;
2578 __u8 perm_addr[ETH_ALEN];
2579 __le16 region_code;
2580 __le32 fw_rev;
2581 __le32 ps_cookie;
2582 __le32 caps;
2583 __le32 rx_queue_ptr;
2584 __le32 num_tx_queues;
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002585 __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002586 __le32 flags;
2587 __le32 num_tx_desc_per_queue;
2588 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002589} __packed;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002590
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002591/* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2592 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2593 * the packets that are queued for more than 500ms, will be dropped in the
2594 * hardware. This helps minimizing the issues caused due to head-of-line
2595 * blocking where a slow client can hog the bandwidth and affect traffic to a
2596 * faster client.
2597 */
2598#define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
Nishant Sarmukadam3373b282011-06-13 16:26:15 +05302599#define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002600#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2601#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2602#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002603
2604static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2605{
2606 struct mwl8k_priv *priv = hw->priv;
2607 struct mwl8k_cmd_set_hw_spec *cmd;
2608 int rc;
2609 int i;
2610
2611 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2612 if (cmd == NULL)
2613 return -ENOMEM;
2614
2615 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2616 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2617
2618 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2619 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002620 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08002621
2622 /*
2623 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2624 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2625 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2626 * priority is interpreted the right way in firmware.
2627 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002628 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
2629 int j = mwl8k_tx_queues(priv) - 1 - i;
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08002630 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
2631 }
2632
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002633 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2634 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
Nishant Sarmukadam31d291a2011-04-21 16:34:59 +05302635 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
Nishant Sarmukadam3373b282011-06-13 16:26:15 +05302636 MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
2637 MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002638 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2639 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2640
2641 rc = mwl8k_post_cmd(hw, &cmd->header);
2642 kfree(cmd);
2643
2644 return rc;
2645}
2646
2647/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002648 * CMD_MAC_MULTICAST_ADR.
2649 */
2650struct mwl8k_cmd_mac_multicast_adr {
2651 struct mwl8k_cmd_pkt header;
2652 __le16 action;
2653 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002654 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002655};
2656
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002657#define MWL8K_ENABLE_RX_DIRECTED 0x0001
2658#define MWL8K_ENABLE_RX_MULTICAST 0x0002
2659#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2660#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002661
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002662static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002663__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Jiri Pirko22bedad32010-04-01 21:22:57 +00002664 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002665{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002666 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002667 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002668 int size;
Jiri Pirko22bedad32010-04-01 21:22:57 +00002669 int mc_count = 0;
2670
2671 if (mc_list)
2672 mc_count = netdev_hw_addr_list_count(mc_list);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002673
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002674 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002675 allmulti = 1;
2676 mc_count = 0;
2677 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002678
2679 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2680
2681 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002682 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002683 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002684
2685 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2686 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002687 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2688 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002689
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002690 if (allmulti) {
2691 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2692 } else if (mc_count) {
Jiri Pirko22bedad32010-04-01 21:22:57 +00002693 struct netdev_hw_addr *ha;
2694 int i = 0;
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002695
2696 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2697 cmd->numaddr = cpu_to_le16(mc_count);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002698 netdev_hw_addr_list_for_each(ha, mc_list) {
2699 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002700 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002701 }
2702
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002703 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002704}
2705
2706/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002707 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002708 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002709struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002710 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002711 __le32 stats[64];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002712} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002713
2714#define MWL8K_STAT_ACK_FAILURE 9
2715#define MWL8K_STAT_RTS_FAILURE 12
2716#define MWL8K_STAT_FCS_ERROR 24
2717#define MWL8K_STAT_RTS_SUCCESS 11
2718
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002719static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2720 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002721{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002722 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002723 int rc;
2724
2725 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2726 if (cmd == NULL)
2727 return -ENOMEM;
2728
2729 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2730 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002731
2732 rc = mwl8k_post_cmd(hw, &cmd->header);
2733 if (!rc) {
2734 stats->dot11ACKFailureCount =
2735 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2736 stats->dot11RTSFailureCount =
2737 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2738 stats->dot11FCSErrorCount =
2739 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2740 stats->dot11RTSSuccessCount =
2741 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2742 }
2743 kfree(cmd);
2744
2745 return rc;
2746}
2747
2748/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002749 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002750 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002751struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002752 struct mwl8k_cmd_pkt header;
2753 __le16 action;
2754 __le16 control;
2755 __le16 radio_on;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002756} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002757
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002758static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002759mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002760{
2761 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002762 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002763 int rc;
2764
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002765 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002766 return 0;
2767
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002768 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2769 if (cmd == NULL)
2770 return -ENOMEM;
2771
2772 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2773 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2774 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002775 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002776 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2777
2778 rc = mwl8k_post_cmd(hw, &cmd->header);
2779 kfree(cmd);
2780
2781 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002782 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002783
2784 return rc;
2785}
2786
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002787static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002788{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002789 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002790}
2791
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002792static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002793{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002794 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002795}
2796
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002797static int
2798mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2799{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002800 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002801
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002802 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002803
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002804 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002805}
2806
2807/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002808 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002809 */
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002810#define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002811
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002812struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002813 struct mwl8k_cmd_pkt header;
2814 __le16 action;
2815 __le16 support_level;
2816 __le16 current_level;
2817 __le16 reserved;
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002818 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002819} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002820
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002821static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002822{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002823 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002824 int rc;
2825
2826 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2827 if (cmd == NULL)
2828 return -ENOMEM;
2829
2830 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2831 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2832 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2833 cmd->support_level = cpu_to_le16(dBm);
2834
2835 rc = mwl8k_post_cmd(hw, &cmd->header);
2836 kfree(cmd);
2837
2838 return rc;
2839}
2840
2841/*
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002842 * CMD_TX_POWER.
2843 */
2844#define MWL8K_TX_POWER_LEVEL_TOTAL 12
2845
2846struct mwl8k_cmd_tx_power {
2847 struct mwl8k_cmd_pkt header;
2848 __le16 action;
2849 __le16 band;
2850 __le16 channel;
2851 __le16 bw;
2852 __le16 sub_ch;
2853 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05302854} __packed;
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002855
2856static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2857 struct ieee80211_conf *conf,
2858 unsigned short pwr)
2859{
Karl Beldan675a0b02013-03-25 16:26:57 +01002860 struct ieee80211_channel *channel = conf->chandef.chan;
2861 enum nl80211_channel_type channel_type =
2862 cfg80211_get_chandef_type(&conf->chandef);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002863 struct mwl8k_cmd_tx_power *cmd;
2864 int rc;
2865 int i;
2866
2867 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2868 if (cmd == NULL)
2869 return -ENOMEM;
2870
2871 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2872 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2873 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2874
2875 if (channel->band == IEEE80211_BAND_2GHZ)
2876 cmd->band = cpu_to_le16(0x1);
2877 else if (channel->band == IEEE80211_BAND_5GHZ)
2878 cmd->band = cpu_to_le16(0x4);
2879
Yogesh Ashok Powar604c4ef2012-01-17 15:45:15 +05302880 cmd->channel = cpu_to_le16(channel->hw_value);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002881
Karl Beldan675a0b02013-03-25 16:26:57 +01002882 if (channel_type == NL80211_CHAN_NO_HT ||
2883 channel_type == NL80211_CHAN_HT20) {
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002884 cmd->bw = cpu_to_le16(0x2);
2885 } else {
2886 cmd->bw = cpu_to_le16(0x4);
Karl Beldan675a0b02013-03-25 16:26:57 +01002887 if (channel_type == NL80211_CHAN_HT40MINUS)
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002888 cmd->sub_ch = cpu_to_le16(0x3);
Karl Beldan675a0b02013-03-25 16:26:57 +01002889 else if (channel_type == NL80211_CHAN_HT40PLUS)
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002890 cmd->sub_ch = cpu_to_le16(0x1);
2891 }
2892
2893 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2894 cmd->power_level_list[i] = cpu_to_le16(pwr);
2895
2896 rc = mwl8k_post_cmd(hw, &cmd->header);
2897 kfree(cmd);
2898
2899 return rc;
2900}
2901
2902/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002903 * CMD_RF_ANTENNA.
2904 */
2905struct mwl8k_cmd_rf_antenna {
2906 struct mwl8k_cmd_pkt header;
2907 __le16 antenna;
2908 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002909} __packed;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002910
2911#define MWL8K_RF_ANTENNA_RX 1
2912#define MWL8K_RF_ANTENNA_TX 2
2913
2914static int
2915mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2916{
2917 struct mwl8k_cmd_rf_antenna *cmd;
2918 int rc;
2919
2920 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2921 if (cmd == NULL)
2922 return -ENOMEM;
2923
2924 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2925 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2926 cmd->antenna = cpu_to_le16(antenna);
2927 cmd->mode = cpu_to_le16(mask);
2928
2929 rc = mwl8k_post_cmd(hw, &cmd->header);
2930 kfree(cmd);
2931
2932 return rc;
2933}
2934
2935/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002936 * CMD_SET_BEACON.
2937 */
2938struct mwl8k_cmd_set_beacon {
2939 struct mwl8k_cmd_pkt header;
2940 __le16 beacon_len;
2941 __u8 beacon[0];
2942};
2943
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01002944static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2945 struct ieee80211_vif *vif, u8 *beacon, int len)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002946{
2947 struct mwl8k_cmd_set_beacon *cmd;
2948 int rc;
2949
2950 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2951 if (cmd == NULL)
2952 return -ENOMEM;
2953
2954 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2955 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2956 cmd->beacon_len = cpu_to_le16(len);
2957 memcpy(cmd->beacon, beacon, len);
2958
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01002959 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002960 kfree(cmd);
2961
2962 return rc;
2963}
2964
2965/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002966 * CMD_SET_PRE_SCAN.
2967 */
2968struct mwl8k_cmd_set_pre_scan {
2969 struct mwl8k_cmd_pkt header;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002970} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002971
2972static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2973{
2974 struct mwl8k_cmd_set_pre_scan *cmd;
2975 int rc;
2976
2977 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2978 if (cmd == NULL)
2979 return -ENOMEM;
2980
2981 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2982 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2983
2984 rc = mwl8k_post_cmd(hw, &cmd->header);
2985 kfree(cmd);
2986
2987 return rc;
2988}
2989
2990/*
Yogesh Ashok Powarc3015312014-02-25 17:41:58 +05302991 * CMD_BBP_REG_ACCESS.
2992 */
2993struct mwl8k_cmd_bbp_reg_access {
2994 struct mwl8k_cmd_pkt header;
2995 __le16 action;
2996 __le16 offset;
2997 u8 value;
2998 u8 rsrv[3];
2999} __packed;
3000
3001static int
3002mwl8k_cmd_bbp_reg_access(struct ieee80211_hw *hw,
3003 u16 action,
3004 u16 offset,
3005 u8 *value)
3006{
3007 struct mwl8k_cmd_bbp_reg_access *cmd;
3008 int rc;
3009
3010 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3011 if (cmd == NULL)
3012 return -ENOMEM;
3013
3014 cmd->header.code = cpu_to_le16(MWL8K_CMD_BBP_REG_ACCESS);
3015 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3016 cmd->action = cpu_to_le16(action);
3017 cmd->offset = cpu_to_le16(offset);
3018
3019 rc = mwl8k_post_cmd(hw, &cmd->header);
3020
3021 if (!rc)
3022 *value = cmd->value;
3023 else
3024 *value = 0;
3025
3026 kfree(cmd);
3027
3028 return rc;
3029}
3030
3031/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003032 * CMD_SET_POST_SCAN.
3033 */
3034struct mwl8k_cmd_set_post_scan {
3035 struct mwl8k_cmd_pkt header;
3036 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003037 __u8 bssid[ETH_ALEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003038} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003039
3040static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003041mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003042{
3043 struct mwl8k_cmd_set_post_scan *cmd;
3044 int rc;
3045
3046 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3047 if (cmd == NULL)
3048 return -ENOMEM;
3049
3050 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
3051 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3052 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003053 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003054
3055 rc = mwl8k_post_cmd(hw, &cmd->header);
3056 kfree(cmd);
3057
3058 return rc;
3059}
3060
3061/*
3062 * CMD_SET_RF_CHANNEL.
3063 */
3064struct mwl8k_cmd_set_rf_channel {
3065 struct mwl8k_cmd_pkt header;
3066 __le16 action;
3067 __u8 current_channel;
3068 __le32 channel_flags;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003069} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003070
3071static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003072 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003073{
Karl Beldan675a0b02013-03-25 16:26:57 +01003074 struct ieee80211_channel *channel = conf->chandef.chan;
3075 enum nl80211_channel_type channel_type =
3076 cfg80211_get_chandef_type(&conf->chandef);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003077 struct mwl8k_cmd_set_rf_channel *cmd;
3078 int rc;
3079
3080 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3081 if (cmd == NULL)
3082 return -ENOMEM;
3083
3084 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
3085 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3086 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3087 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003088
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003089 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003090 cmd->channel_flags |= cpu_to_le32(0x00000001);
Lennert Buytenhek42574ea2010-01-12 13:49:18 +01003091 else if (channel->band == IEEE80211_BAND_5GHZ)
3092 cmd->channel_flags |= cpu_to_le32(0x00000004);
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003093
Karl Beldan675a0b02013-03-25 16:26:57 +01003094 if (channel_type == NL80211_CHAN_NO_HT ||
3095 channel_type == NL80211_CHAN_HT20)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003096 cmd->channel_flags |= cpu_to_le32(0x00000080);
Karl Beldan675a0b02013-03-25 16:26:57 +01003097 else if (channel_type == NL80211_CHAN_HT40MINUS)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003098 cmd->channel_flags |= cpu_to_le32(0x000001900);
Karl Beldan675a0b02013-03-25 16:26:57 +01003099 else if (channel_type == NL80211_CHAN_HT40PLUS)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003100 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003101
3102 rc = mwl8k_post_cmd(hw, &cmd->header);
3103 kfree(cmd);
3104
3105 return rc;
3106}
3107
3108/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003109 * CMD_SET_AID.
3110 */
3111#define MWL8K_FRAME_PROT_DISABLED 0x00
3112#define MWL8K_FRAME_PROT_11G 0x07
3113#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
3114#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
3115
3116struct mwl8k_cmd_update_set_aid {
3117 struct mwl8k_cmd_pkt header;
3118 __le16 aid;
3119
3120 /* AP's MAC address (BSSID) */
3121 __u8 bssid[ETH_ALEN];
3122 __le16 protection_mode;
3123 __u8 supp_rates[14];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003124} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003125
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003126static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
3127{
3128 int i;
3129 int j;
3130
3131 /*
Jonas Gorski3f524552013-04-14 14:11:58 +02003132 * Clear nonstandard rate 4.
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003133 */
3134 mask &= 0x1fef;
3135
Jonas Gorski3f524552013-04-14 14:11:58 +02003136 for (i = 0, j = 0; i < 13; i++) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003137 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01003138 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003139 }
3140}
3141
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003142static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003143mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
3144 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003145{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003146 struct mwl8k_cmd_update_set_aid *cmd;
3147 u16 prot_mode;
3148 int rc;
3149
3150 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3151 if (cmd == NULL)
3152 return -ENOMEM;
3153
3154 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
3155 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003156 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003157 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003158
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003159 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003160 prot_mode = MWL8K_FRAME_PROT_11G;
3161 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003162 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003163 IEEE80211_HT_OP_MODE_PROTECTION) {
3164 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
3165 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
3166 break;
3167 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
3168 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
3169 break;
3170 default:
3171 prot_mode = MWL8K_FRAME_PROT_DISABLED;
3172 break;
3173 }
3174 }
3175 cmd->protection_mode = cpu_to_le16(prot_mode);
3176
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003177 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003178
3179 rc = mwl8k_post_cmd(hw, &cmd->header);
3180 kfree(cmd);
3181
3182 return rc;
3183}
3184
3185/*
3186 * CMD_SET_RATE.
3187 */
3188struct mwl8k_cmd_set_rate {
3189 struct mwl8k_cmd_pkt header;
3190 __u8 legacy_rates[14];
3191
3192 /* Bitmap for supported MCS codes. */
3193 __u8 mcs_set[16];
3194 __u8 reserved[16];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003195} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003196
3197static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003198mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003199 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003200{
3201 struct mwl8k_cmd_set_rate *cmd;
3202 int rc;
3203
3204 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3205 if (cmd == NULL)
3206 return -ENOMEM;
3207
3208 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
3209 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003210 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003211 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003212
3213 rc = mwl8k_post_cmd(hw, &cmd->header);
3214 kfree(cmd);
3215
3216 return rc;
3217}
3218
3219/*
3220 * CMD_FINALIZE_JOIN.
3221 */
3222#define MWL8K_FJ_BEACON_MAXLEN 128
3223
3224struct mwl8k_cmd_finalize_join {
3225 struct mwl8k_cmd_pkt header;
3226 __le32 sleep_interval; /* Number of beacon periods to sleep */
3227 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003228} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003229
3230static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
3231 int framelen, int dtim)
3232{
3233 struct mwl8k_cmd_finalize_join *cmd;
3234 struct ieee80211_mgmt *payload = frame;
3235 int payload_len;
3236 int rc;
3237
3238 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3239 if (cmd == NULL)
3240 return -ENOMEM;
3241
3242 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
3243 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3244 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
3245
3246 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
3247 if (payload_len < 0)
3248 payload_len = 0;
3249 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
3250 payload_len = MWL8K_FJ_BEACON_MAXLEN;
3251
3252 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
3253
3254 rc = mwl8k_post_cmd(hw, &cmd->header);
3255 kfree(cmd);
3256
3257 return rc;
3258}
3259
3260/*
3261 * CMD_SET_RTS_THRESHOLD.
3262 */
3263struct mwl8k_cmd_set_rts_threshold {
3264 struct mwl8k_cmd_pkt header;
3265 __le16 action;
3266 __le16 threshold;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003267} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003268
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003269static int
3270mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003271{
3272 struct mwl8k_cmd_set_rts_threshold *cmd;
3273 int rc;
3274
3275 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3276 if (cmd == NULL)
3277 return -ENOMEM;
3278
3279 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
3280 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003281 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3282 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003283
3284 rc = mwl8k_post_cmd(hw, &cmd->header);
3285 kfree(cmd);
3286
3287 return rc;
3288}
3289
3290/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003291 * CMD_SET_SLOT.
3292 */
3293struct mwl8k_cmd_set_slot {
3294 struct mwl8k_cmd_pkt header;
3295 __le16 action;
3296 __u8 short_slot;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003297} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003298
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02003299static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003300{
3301 struct mwl8k_cmd_set_slot *cmd;
3302 int rc;
3303
3304 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3305 if (cmd == NULL)
3306 return -ENOMEM;
3307
3308 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
3309 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3310 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02003311 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003312
3313 rc = mwl8k_post_cmd(hw, &cmd->header);
3314 kfree(cmd);
3315
3316 return rc;
3317}
3318
3319/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003320 * CMD_SET_EDCA_PARAMS.
3321 */
3322struct mwl8k_cmd_set_edca_params {
3323 struct mwl8k_cmd_pkt header;
3324
3325 /* See MWL8K_SET_EDCA_XXX below */
3326 __le16 action;
3327
3328 /* TX opportunity in units of 32 us */
3329 __le16 txop;
3330
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003331 union {
3332 struct {
3333 /* Log exponent of max contention period: 0...15 */
3334 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003335
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003336 /* Log exponent of min contention period: 0...15 */
3337 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003338
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003339 /* Adaptive interframe spacing in units of 32us */
3340 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003341
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003342 /* TX queue to configure */
3343 __u8 txq;
3344 } ap;
3345 struct {
3346 /* Log exponent of max contention period: 0...15 */
3347 __u8 log_cw_max;
3348
3349 /* Log exponent of min contention period: 0...15 */
3350 __u8 log_cw_min;
3351
3352 /* Adaptive interframe spacing in units of 32us */
3353 __u8 aifs;
3354
3355 /* TX queue to configure */
3356 __u8 txq;
3357 } sta;
3358 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00003359} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003360
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003361#define MWL8K_SET_EDCA_CW 0x01
3362#define MWL8K_SET_EDCA_TXOP 0x02
3363#define MWL8K_SET_EDCA_AIFS 0x04
3364
3365#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3366 MWL8K_SET_EDCA_TXOP | \
3367 MWL8K_SET_EDCA_AIFS)
3368
3369static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003370mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
3371 __u16 cw_min, __u16 cw_max,
3372 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003373{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003374 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003375 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003376 int rc;
3377
3378 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3379 if (cmd == NULL)
3380 return -ENOMEM;
3381
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003382 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
3383 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003384 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
3385 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003386 if (priv->ap_fw) {
3387 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
3388 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
3389 cmd->ap.aifs = aifs;
3390 cmd->ap.txq = qnum;
3391 } else {
3392 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
3393 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
3394 cmd->sta.aifs = aifs;
3395 cmd->sta.txq = qnum;
3396 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003397
3398 rc = mwl8k_post_cmd(hw, &cmd->header);
3399 kfree(cmd);
3400
3401 return rc;
3402}
3403
3404/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003405 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003406 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003407struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003408 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003409 __le16 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003410} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003411
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003412static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003413{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003414 struct mwl8k_priv *priv = hw->priv;
3415 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003416 int rc;
3417
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003418 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3419 if (cmd == NULL)
3420 return -ENOMEM;
3421
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003422 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003423 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003424 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003425
3426 rc = mwl8k_post_cmd(hw, &cmd->header);
3427 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01003428
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003429 if (!rc)
3430 priv->wmm_enabled = enable;
3431
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003432 return rc;
3433}
3434
3435/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003436 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003437 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003438struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003439 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003440 __le32 action;
3441 __u8 rx_antenna_map;
3442 __u8 tx_antenna_map;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003443} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003444
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003445static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003446{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003447 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003448 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003449
3450 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3451 if (cmd == NULL)
3452 return -ENOMEM;
3453
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003454 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003455 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003456 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
3457 cmd->rx_antenna_map = rx;
3458 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003459
3460 rc = mwl8k_post_cmd(hw, &cmd->header);
3461 kfree(cmd);
3462
3463 return rc;
3464}
3465
3466/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003467 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003468 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003469struct mwl8k_cmd_use_fixed_rate_sta {
3470 struct mwl8k_cmd_pkt header;
3471 __le32 action;
3472 __le32 allow_rate_drop;
3473 __le32 num_rates;
3474 struct {
3475 __le32 is_ht_rate;
3476 __le32 enable_retry;
3477 __le32 rate;
3478 __le32 retry_count;
3479 } rate_entry[8];
3480 __le32 rate_type;
3481 __le32 reserved1;
3482 __le32 reserved2;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003483} __packed;
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003484
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003485#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003486#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003487
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003488static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003489{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003490 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003491 int rc;
3492
3493 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3494 if (cmd == NULL)
3495 return -ENOMEM;
3496
3497 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3498 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003499 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3500 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003501
3502 rc = mwl8k_post_cmd(hw, &cmd->header);
3503 kfree(cmd);
3504
3505 return rc;
3506}
3507
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003508/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01003509 * CMD_USE_FIXED_RATE (AP version).
3510 */
3511struct mwl8k_cmd_use_fixed_rate_ap {
3512 struct mwl8k_cmd_pkt header;
3513 __le32 action;
3514 __le32 allow_rate_drop;
3515 __le32 num_rates;
3516 struct mwl8k_rate_entry_ap {
3517 __le32 is_ht_rate;
3518 __le32 enable_retry;
3519 __le32 rate;
3520 __le32 retry_count;
3521 } rate_entry[4];
3522 u8 multicast_rate;
3523 u8 multicast_rate_type;
3524 u8 management_rate;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003525} __packed;
Lennert Buytenhek088aab82010-01-08 18:30:36 +01003526
3527static int
3528mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
3529{
3530 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
3531 int rc;
3532
3533 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3534 if (cmd == NULL)
3535 return -ENOMEM;
3536
3537 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3538 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3539 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3540 cmd->multicast_rate = mcast;
3541 cmd->management_rate = mgmt;
3542
3543 rc = mwl8k_post_cmd(hw, &cmd->header);
3544 kfree(cmd);
3545
3546 return rc;
3547}
3548
3549/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003550 * CMD_ENABLE_SNIFFER.
3551 */
3552struct mwl8k_cmd_enable_sniffer {
3553 struct mwl8k_cmd_pkt header;
3554 __le32 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003555} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003556
3557static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3558{
3559 struct mwl8k_cmd_enable_sniffer *cmd;
3560 int rc;
3561
3562 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3563 if (cmd == NULL)
3564 return -ENOMEM;
3565
3566 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3567 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3568 cmd->action = cpu_to_le32(!!enable);
3569
3570 rc = mwl8k_post_cmd(hw, &cmd->header);
3571 kfree(cmd);
3572
3573 return rc;
3574}
3575
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303576struct mwl8k_cmd_update_mac_addr {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003577 struct mwl8k_cmd_pkt header;
3578 union {
3579 struct {
3580 __le16 mac_type;
3581 __u8 mac_addr[ETH_ALEN];
3582 } mbss;
3583 __u8 mac_addr[ETH_ALEN];
3584 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00003585} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003586
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003587#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3588#define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3589#define MWL8K_MAC_TYPE_PRIMARY_AP 2
3590#define MWL8K_MAC_TYPE_SECONDARY_AP 3
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01003591
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303592static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
3593 struct ieee80211_vif *vif, u8 *mac, bool set)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003594{
3595 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003596 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303597 struct mwl8k_cmd_update_mac_addr *cmd;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003598 int mac_type;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003599 int rc;
3600
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003601 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3602 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3603 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
Yogesh Ashok Powaraf458832013-01-25 16:20:12 +05303604 if (priv->ap_fw)
3605 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3606 else
3607 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003608 else
3609 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3610 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3611 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3612 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3613 else
3614 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3615 }
3616
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003617 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3618 if (cmd == NULL)
3619 return -ENOMEM;
3620
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303621 if (set)
3622 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3623 else
3624 cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
3625
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003626 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3627 if (priv->ap_fw) {
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003628 cmd->mbss.mac_type = cpu_to_le16(mac_type);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003629 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3630 } else {
3631 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3632 }
3633
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003634 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003635 kfree(cmd);
3636
3637 return rc;
3638}
3639
3640/*
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303641 * MWL8K_CMD_SET_MAC_ADDR.
3642 */
3643static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3644 struct ieee80211_vif *vif, u8 *mac)
3645{
3646 return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
3647}
3648
3649/*
3650 * MWL8K_CMD_DEL_MAC_ADDR.
3651 */
3652static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
3653 struct ieee80211_vif *vif, u8 *mac)
3654{
3655 return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
3656}
3657
3658/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003659 * CMD_SET_RATEADAPT_MODE.
3660 */
3661struct mwl8k_cmd_set_rate_adapt_mode {
3662 struct mwl8k_cmd_pkt header;
3663 __le16 action;
3664 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003665} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003666
3667static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3668{
3669 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
3670 int rc;
3671
3672 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3673 if (cmd == NULL)
3674 return -ENOMEM;
3675
3676 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
3677 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3678 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3679 cmd->mode = cpu_to_le16(mode);
3680
3681 rc = mwl8k_post_cmd(hw, &cmd->header);
3682 kfree(cmd);
3683
3684 return rc;
3685}
3686
3687/*
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003688 * CMD_GET_WATCHDOG_BITMAP.
3689 */
3690struct mwl8k_cmd_get_watchdog_bitmap {
3691 struct mwl8k_cmd_pkt header;
3692 u8 bitmap;
3693} __packed;
3694
3695static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
3696{
3697 struct mwl8k_cmd_get_watchdog_bitmap *cmd;
3698 int rc;
3699
3700 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3701 if (cmd == NULL)
3702 return -ENOMEM;
3703
3704 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
3705 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3706
3707 rc = mwl8k_post_cmd(hw, &cmd->header);
3708 if (!rc)
3709 *bitmap = cmd->bitmap;
3710
3711 kfree(cmd);
3712
3713 return rc;
3714}
3715
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303716#define MWL8K_WMM_QUEUE_NUMBER 3
3717
3718static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3719 u8 idx);
3720
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003721static void mwl8k_watchdog_ba_events(struct work_struct *work)
3722{
3723 int rc;
3724 u8 bitmap = 0, stream_index;
3725 struct mwl8k_ampdu_stream *streams;
3726 struct mwl8k_priv *priv =
3727 container_of(work, struct mwl8k_priv, watchdog_ba_handle);
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303728 struct ieee80211_hw *hw = priv->hw;
3729 int i;
3730 u32 status = 0;
3731
3732 mwl8k_fw_lock(hw);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003733
3734 rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
3735 if (rc)
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303736 goto done;
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003737
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303738 spin_lock(&priv->stream_lock);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003739
3740 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303741 for (i = 0; i < TOTAL_HW_TX_QUEUES; i++) {
3742 if (bitmap & (1 << i)) {
3743 stream_index = (i + MWL8K_WMM_QUEUE_NUMBER) %
3744 TOTAL_HW_TX_QUEUES;
3745 streams = &priv->ampdu[stream_index];
3746 if (streams->state == AMPDU_STREAM_ACTIVE) {
3747 ieee80211_stop_tx_ba_session(streams->sta,
3748 streams->tid);
3749 spin_unlock(&priv->stream_lock);
3750 mwl8k_destroy_ba(hw, stream_index);
3751 spin_lock(&priv->stream_lock);
3752 }
3753 }
3754 }
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003755
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303756 spin_unlock(&priv->stream_lock);
3757done:
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05303758 atomic_dec(&priv->watchdog_event_pending);
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303759 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3760 iowrite32((status | MWL8K_A2H_INT_BA_WATCHDOG),
3761 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3762 mwl8k_fw_unlock(hw);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003763 return;
3764}
3765
3766
3767/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003768 * CMD_BSS_START.
3769 */
3770struct mwl8k_cmd_bss_start {
3771 struct mwl8k_cmd_pkt header;
3772 __le32 enable;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003773} __packed;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003774
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003775static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3776 struct ieee80211_vif *vif, int enable)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003777{
3778 struct mwl8k_cmd_bss_start *cmd;
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +05303779 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3780 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003781 int rc;
3782
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +05303783 if (enable && (priv->running_bsses & (1 << mwl8k_vif->macid)))
3784 return 0;
3785
3786 if (!enable && !(priv->running_bsses & (1 << mwl8k_vif->macid)))
3787 return 0;
3788
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003789 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3790 if (cmd == NULL)
3791 return -ENOMEM;
3792
3793 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3794 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3795 cmd->enable = cpu_to_le32(enable);
3796
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003797 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003798 kfree(cmd);
3799
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +05303800 if (!rc) {
3801 if (enable)
3802 priv->running_bsses |= (1 << mwl8k_vif->macid);
3803 else
3804 priv->running_bsses &= ~(1 << mwl8k_vif->macid);
3805 }
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003806 return rc;
3807}
3808
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +05303809static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable, u32 bitmap)
3810{
3811 struct mwl8k_priv *priv = hw->priv;
3812 struct mwl8k_vif *mwl8k_vif, *tmp_vif;
3813 struct ieee80211_vif *vif;
3814
3815 list_for_each_entry_safe(mwl8k_vif, tmp_vif, &priv->vif_list, list) {
3816 vif = mwl8k_vif->vif;
3817
3818 if (!(bitmap & (1 << mwl8k_vif->macid)))
3819 continue;
3820
3821 if (vif->type == NL80211_IFTYPE_AP)
3822 mwl8k_cmd_bss_start(hw, vif, enable);
3823 }
3824}
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003825/*
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003826 * CMD_BASTREAM.
3827 */
3828
3829/*
3830 * UPSTREAM is tx direction
3831 */
3832#define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3833#define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3834
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303835enum ba_stream_action_type {
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003836 MWL8K_BA_CREATE,
3837 MWL8K_BA_UPDATE,
3838 MWL8K_BA_DESTROY,
3839 MWL8K_BA_FLUSH,
3840 MWL8K_BA_CHECK,
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303841};
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003842
3843
3844struct mwl8k_create_ba_stream {
3845 __le32 flags;
3846 __le32 idle_thrs;
3847 __le32 bar_thrs;
3848 __le32 window_size;
3849 u8 peer_mac_addr[6];
3850 u8 dialog_token;
3851 u8 tid;
3852 u8 queue_id;
3853 u8 param_info;
3854 __le32 ba_context;
3855 u8 reset_seq_no_flag;
3856 __le16 curr_seq_no;
3857 u8 sta_src_mac_addr[6];
3858} __packed;
3859
3860struct mwl8k_destroy_ba_stream {
3861 __le32 flags;
3862 __le32 ba_context;
3863} __packed;
3864
3865struct mwl8k_cmd_bastream {
3866 struct mwl8k_cmd_pkt header;
3867 __le32 action;
3868 union {
3869 struct mwl8k_create_ba_stream create_params;
3870 struct mwl8k_destroy_ba_stream destroy_params;
3871 };
3872} __packed;
3873
3874static int
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303875mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3876 struct ieee80211_vif *vif)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003877{
3878 struct mwl8k_cmd_bastream *cmd;
3879 int rc;
3880
3881 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3882 if (cmd == NULL)
3883 return -ENOMEM;
3884
3885 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3886 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3887
3888 cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
3889
3890 cmd->create_params.queue_id = stream->idx;
3891 memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
3892 ETH_ALEN);
3893 cmd->create_params.tid = stream->tid;
3894
3895 cmd->create_params.flags =
3896 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
3897 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
3898
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303899 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003900
3901 kfree(cmd);
3902
3903 return rc;
3904}
3905
3906static int
3907mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303908 u8 buf_size, struct ieee80211_vif *vif)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003909{
3910 struct mwl8k_cmd_bastream *cmd;
3911 int rc;
3912
3913 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3914 if (cmd == NULL)
3915 return -ENOMEM;
3916
3917
3918 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3919 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3920
3921 cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
3922
3923 cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
3924 cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
3925 cmd->create_params.queue_id = stream->idx;
3926
3927 memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
3928 cmd->create_params.tid = stream->tid;
3929 cmd->create_params.curr_seq_no = cpu_to_le16(0);
3930 cmd->create_params.reset_seq_no_flag = 1;
3931
3932 cmd->create_params.param_info =
3933 (stream->sta->ht_cap.ampdu_factor &
3934 IEEE80211_HT_AMPDU_PARM_FACTOR) |
3935 ((stream->sta->ht_cap.ampdu_density << 2) &
3936 IEEE80211_HT_AMPDU_PARM_DENSITY);
3937
3938 cmd->create_params.flags =
3939 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
3940 BASTREAM_FLAG_DIRECTION_UPSTREAM);
3941
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303942 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003943
3944 wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
3945 stream->sta->addr, stream->tid);
3946 kfree(cmd);
3947
3948 return rc;
3949}
3950
3951static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303952 u8 idx)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003953{
3954 struct mwl8k_cmd_bastream *cmd;
3955
3956 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3957 if (cmd == NULL)
3958 return;
3959
3960 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3961 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3962 cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
3963
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303964 cmd->destroy_params.ba_context = cpu_to_le32(idx);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003965 mwl8k_post_cmd(hw, &cmd->header);
3966
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303967 wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", idx);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003968
3969 kfree(cmd);
3970}
3971
3972/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003973 * CMD_SET_NEW_STN.
3974 */
3975struct mwl8k_cmd_set_new_stn {
3976 struct mwl8k_cmd_pkt header;
3977 __le16 aid;
3978 __u8 mac_addr[6];
3979 __le16 stn_id;
3980 __le16 action;
3981 __le16 rsvd;
3982 __le32 legacy_rates;
3983 __u8 ht_rates[4];
3984 __le16 cap_info;
3985 __le16 ht_capabilities_info;
3986 __u8 mac_ht_param_info;
3987 __u8 rev;
3988 __u8 control_channel;
3989 __u8 add_channel;
3990 __le16 op_mode;
3991 __le16 stbc;
3992 __u8 add_qos_info;
3993 __u8 is_qos_sta;
3994 __le32 fw_sta_ptr;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003995} __packed;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003996
3997#define MWL8K_STA_ACTION_ADD 0
3998#define MWL8K_STA_ACTION_REMOVE 2
3999
4000static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
4001 struct ieee80211_vif *vif,
4002 struct ieee80211_sta *sta)
4003{
4004 struct mwl8k_cmd_set_new_stn *cmd;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004005 u32 rates;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004006 int rc;
4007
4008 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4009 if (cmd == NULL)
4010 return -ENOMEM;
4011
4012 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
4013 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4014 cmd->aid = cpu_to_le16(sta->aid);
4015 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
4016 cmd->stn_id = cpu_to_le16(sta->aid);
4017 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
Karl Beldan675a0b02013-03-25 16:26:57 +01004018 if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004019 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
4020 else
4021 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4022 cmd->legacy_rates = cpu_to_le32(rates);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004023 if (sta->ht_cap.ht_supported) {
4024 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
4025 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
4026 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
4027 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
4028 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
4029 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
4030 ((sta->ht_cap.ampdu_density & 7) << 2);
4031 cmd->is_qos_sta = 1;
4032 }
4033
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004034 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004035 kfree(cmd);
4036
4037 return rc;
4038}
4039
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004040static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
4041 struct ieee80211_vif *vif)
4042{
4043 struct mwl8k_cmd_set_new_stn *cmd;
4044 int rc;
4045
4046 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4047 if (cmd == NULL)
4048 return -ENOMEM;
4049
4050 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
4051 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4052 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
4053
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004054 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004055 kfree(cmd);
4056
4057 return rc;
4058}
4059
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004060static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
4061 struct ieee80211_vif *vif, u8 *addr)
4062{
4063 struct mwl8k_cmd_set_new_stn *cmd;
Yogesh Ashok Powar0dd13a42013-01-08 10:16:37 +05304064 struct mwl8k_priv *priv = hw->priv;
4065 int rc, i;
4066 u8 idx;
4067
4068 spin_lock(&priv->stream_lock);
4069 /* Destroy any active ampdu streams for this sta */
4070 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
4071 struct mwl8k_ampdu_stream *s;
4072 s = &priv->ampdu[i];
4073 if (s->state != AMPDU_NO_STREAM) {
4074 if (memcmp(s->sta->addr, addr, ETH_ALEN) == 0) {
4075 if (s->state == AMPDU_STREAM_ACTIVE) {
4076 idx = s->idx;
4077 spin_unlock(&priv->stream_lock);
4078 mwl8k_destroy_ba(hw, idx);
4079 spin_lock(&priv->stream_lock);
4080 } else if (s->state == AMPDU_STREAM_NEW) {
4081 mwl8k_remove_stream(hw, s);
4082 }
4083 }
4084 }
4085 }
4086
4087 spin_unlock(&priv->stream_lock);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004088
4089 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4090 if (cmd == NULL)
4091 return -ENOMEM;
4092
4093 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
4094 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4095 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4096 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
4097
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004098 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004099 kfree(cmd);
4100
4101 return rc;
4102}
4103
4104/*
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004105 * CMD_UPDATE_ENCRYPTION.
4106 */
4107
4108#define MAX_ENCR_KEY_LENGTH 16
4109#define MIC_KEY_LENGTH 8
4110
4111struct mwl8k_cmd_update_encryption {
4112 struct mwl8k_cmd_pkt header;
4113
4114 __le32 action;
4115 __le32 reserved;
4116 __u8 mac_addr[6];
4117 __u8 encr_type;
4118
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05304119} __packed;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004120
4121struct mwl8k_cmd_set_key {
4122 struct mwl8k_cmd_pkt header;
4123
4124 __le32 action;
4125 __le32 reserved;
4126 __le16 length;
4127 __le16 key_type_id;
4128 __le32 key_info;
4129 __le32 key_id;
4130 __le16 key_len;
4131 __u8 key_material[MAX_ENCR_KEY_LENGTH];
4132 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
4133 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
4134 __le16 tkip_rsc_low;
4135 __le32 tkip_rsc_high;
4136 __le16 tkip_tsc_low;
4137 __le32 tkip_tsc_high;
4138 __u8 mac_addr[6];
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05304139} __packed;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004140
4141enum {
4142 MWL8K_ENCR_ENABLE,
4143 MWL8K_ENCR_SET_KEY,
4144 MWL8K_ENCR_REMOVE_KEY,
4145 MWL8K_ENCR_SET_GROUP_KEY,
4146};
4147
4148#define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
4149#define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
4150#define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
4151#define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
4152#define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
4153
4154enum {
4155 MWL8K_ALG_WEP,
4156 MWL8K_ALG_TKIP,
4157 MWL8K_ALG_CCMP,
4158};
4159
4160#define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
4161#define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
4162#define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
4163#define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
4164#define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
4165
4166static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
4167 struct ieee80211_vif *vif,
4168 u8 *addr,
4169 u8 encr_type)
4170{
4171 struct mwl8k_cmd_update_encryption *cmd;
4172 int rc;
4173
4174 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4175 if (cmd == NULL)
4176 return -ENOMEM;
4177
4178 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4179 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4180 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
4181 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4182 cmd->encr_type = encr_type;
4183
4184 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4185 kfree(cmd);
4186
4187 return rc;
4188}
4189
4190static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
4191 u8 *addr,
4192 struct ieee80211_key_conf *key)
4193{
4194 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4195 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4196 cmd->length = cpu_to_le16(sizeof(*cmd) -
4197 offsetof(struct mwl8k_cmd_set_key, length));
4198 cmd->key_id = cpu_to_le32(key->keyidx);
4199 cmd->key_len = cpu_to_le16(key->keylen);
4200 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4201
4202 switch (key->cipher) {
4203 case WLAN_CIPHER_SUITE_WEP40:
4204 case WLAN_CIPHER_SUITE_WEP104:
4205 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
4206 if (key->keyidx == 0)
4207 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
4208
4209 break;
4210 case WLAN_CIPHER_SUITE_TKIP:
4211 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
4212 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4213 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4214 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4215 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
4216 | MWL8K_KEY_FLAG_TSC_VALID);
4217 break;
4218 case WLAN_CIPHER_SUITE_CCMP:
4219 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
4220 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4221 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4222 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4223 break;
4224 default:
4225 return -ENOTSUPP;
4226 }
4227
4228 return 0;
4229}
4230
4231static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
4232 struct ieee80211_vif *vif,
4233 u8 *addr,
4234 struct ieee80211_key_conf *key)
4235{
4236 struct mwl8k_cmd_set_key *cmd;
4237 int rc;
4238 int keymlen;
4239 u32 action;
4240 u8 idx;
4241 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4242
4243 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4244 if (cmd == NULL)
4245 return -ENOMEM;
4246
4247 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4248 if (rc < 0)
4249 goto done;
4250
4251 idx = key->keyidx;
4252
4253 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4254 action = MWL8K_ENCR_SET_KEY;
4255 else
4256 action = MWL8K_ENCR_SET_GROUP_KEY;
4257
4258 switch (key->cipher) {
4259 case WLAN_CIPHER_SUITE_WEP40:
4260 case WLAN_CIPHER_SUITE_WEP104:
4261 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
4262 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
4263 sizeof(*key) + key->keylen);
4264 mwl8k_vif->wep_key_conf[idx].enabled = 1;
4265 }
4266
Yogesh Ashok Powar9b571e22011-05-04 17:22:16 +05304267 keymlen = key->keylen;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004268 action = MWL8K_ENCR_SET_KEY;
4269 break;
4270 case WLAN_CIPHER_SUITE_TKIP:
4271 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
4272 break;
4273 case WLAN_CIPHER_SUITE_CCMP:
4274 keymlen = key->keylen;
4275 break;
4276 default:
4277 rc = -ENOTSUPP;
4278 goto done;
4279 }
4280
4281 memcpy(cmd->key_material, key->key, keymlen);
4282 cmd->action = cpu_to_le32(action);
4283
4284 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4285done:
4286 kfree(cmd);
4287
4288 return rc;
4289}
4290
4291static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
4292 struct ieee80211_vif *vif,
4293 u8 *addr,
4294 struct ieee80211_key_conf *key)
4295{
4296 struct mwl8k_cmd_set_key *cmd;
4297 int rc;
4298 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4299
4300 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4301 if (cmd == NULL)
4302 return -ENOMEM;
4303
4304 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4305 if (rc < 0)
4306 goto done;
4307
4308 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
Dan Carpenterd981e052012-01-17 10:33:31 +03004309 key->cipher == WLAN_CIPHER_SUITE_WEP104)
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004310 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
4311
4312 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
4313
4314 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4315done:
4316 kfree(cmd);
4317
4318 return rc;
4319}
4320
4321static int mwl8k_set_key(struct ieee80211_hw *hw,
4322 enum set_key_cmd cmd_param,
4323 struct ieee80211_vif *vif,
4324 struct ieee80211_sta *sta,
4325 struct ieee80211_key_conf *key)
4326{
4327 int rc = 0;
4328 u8 encr_type;
4329 u8 *addr;
4330 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Yogesh Ashok Powar751930c2013-01-25 16:20:28 +05304331 struct mwl8k_priv *priv = hw->priv;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004332
Yogesh Ashok Powar751930c2013-01-25 16:20:28 +05304333 if (vif->type == NL80211_IFTYPE_STATION && !priv->ap_fw)
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004334 return -EOPNOTSUPP;
4335
4336 if (sta == NULL)
Yogesh Ashok Powarff7e9f92012-01-27 16:08:27 +05304337 addr = vif->addr;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004338 else
4339 addr = sta->addr;
4340
4341 if (cmd_param == SET_KEY) {
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004342 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
4343 if (rc)
4344 goto out;
4345
4346 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
4347 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
4348 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
4349 else
4350 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
4351
4352 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
4353 encr_type);
4354 if (rc)
4355 goto out;
4356
4357 mwl8k_vif->is_hw_crypto_enabled = true;
4358
4359 } else {
4360 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
4361
4362 if (rc)
4363 goto out;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004364 }
4365out:
4366 return rc;
4367}
4368
4369/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004370 * CMD_UPDATE_STADB.
4371 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004372struct ewc_ht_info {
4373 __le16 control1;
4374 __le16 control2;
4375 __le16 control3;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004376} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004377
4378struct peer_capability_info {
4379 /* Peer type - AP vs. STA. */
4380 __u8 peer_type;
4381
4382 /* Basic 802.11 capabilities from assoc resp. */
4383 __le16 basic_caps;
4384
4385 /* Set if peer supports 802.11n high throughput (HT). */
4386 __u8 ht_support;
4387
4388 /* Valid if HT is supported. */
4389 __le16 ht_caps;
4390 __u8 extended_ht_caps;
4391 struct ewc_ht_info ewc_info;
4392
4393 /* Legacy rate table. Intersection of our rates and peer rates. */
4394 __u8 legacy_rates[12];
4395
4396 /* HT rate table. Intersection of our rates and peer rates. */
4397 __u8 ht_rates[16];
4398 __u8 pad[16];
4399
4400 /* If set, interoperability mode, no proprietary extensions. */
4401 __u8 interop;
4402 __u8 pad2;
4403 __u8 station_id;
4404 __le16 amsdu_enabled;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004405} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004406
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004407struct mwl8k_cmd_update_stadb {
4408 struct mwl8k_cmd_pkt header;
4409
4410 /* See STADB_ACTION_TYPE */
4411 __le32 action;
4412
4413 /* Peer MAC address */
4414 __u8 peer_addr[ETH_ALEN];
4415
4416 __le32 reserved;
4417
4418 /* Peer info - valid during add/update. */
4419 struct peer_capability_info peer_info;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004420} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004421
Lennert Buytenheka6804002010-01-04 21:55:42 +01004422#define MWL8K_STA_DB_MODIFY_ENTRY 1
4423#define MWL8K_STA_DB_DEL_ENTRY 2
4424
4425/* Peer Entry flags - used to define the type of the peer node */
4426#define MWL8K_PEER_TYPE_ACCESSPOINT 2
4427
4428static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004429 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004430 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004431{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004432 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01004433 struct peer_capability_info *p;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004434 u32 rates;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004435 int rc;
4436
4437 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4438 if (cmd == NULL)
4439 return -ENOMEM;
4440
4441 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4442 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01004443 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004444 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004445
Lennert Buytenheka6804002010-01-04 21:55:42 +01004446 p = &cmd->peer_info;
4447 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
4448 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004449 p->ht_support = sta->ht_cap.ht_supported;
John W. Linvilleb6037422010-07-20 13:55:00 -04004450 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004451 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
4452 ((sta->ht_cap.ampdu_density & 7) << 2);
Karl Beldan675a0b02013-03-25 16:26:57 +01004453 if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004454 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
4455 else
4456 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4457 legacy_rate_mask_to_array(p->legacy_rates, rates);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004458 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01004459 p->interop = 1;
4460 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004461
Lennert Buytenheka6804002010-01-04 21:55:42 +01004462 rc = mwl8k_post_cmd(hw, &cmd->header);
Nickolai Zeldovichc4f74d32013-01-06 20:27:22 -05004463 if (!rc)
4464 rc = p->station_id;
Lennert Buytenheka6804002010-01-04 21:55:42 +01004465 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004466
Nickolai Zeldovichc4f74d32013-01-06 20:27:22 -05004467 return rc;
Lennert Buytenheka6804002010-01-04 21:55:42 +01004468}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004469
Lennert Buytenheka6804002010-01-04 21:55:42 +01004470static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
4471 struct ieee80211_vif *vif, u8 *addr)
4472{
4473 struct mwl8k_cmd_update_stadb *cmd;
4474 int rc;
4475
4476 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4477 if (cmd == NULL)
4478 return -ENOMEM;
4479
4480 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4481 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4482 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
4483 memcpy(cmd->peer_addr, addr, ETH_ALEN);
4484
4485 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004486 kfree(cmd);
4487
4488 return rc;
4489}
4490
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004491
4492/*
4493 * Interrupt handling.
4494 */
4495static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
4496{
4497 struct ieee80211_hw *hw = dev_id;
4498 struct mwl8k_priv *priv = hw->priv;
4499 u32 status;
4500
4501 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004502 if (!status)
4503 return IRQ_NONE;
4504
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004505 if (status & MWL8K_A2H_INT_TX_DONE) {
4506 status &= ~MWL8K_A2H_INT_TX_DONE;
4507 tasklet_schedule(&priv->poll_tx_task);
4508 }
4509
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004510 if (status & MWL8K_A2H_INT_RX_READY) {
4511 status &= ~MWL8K_A2H_INT_RX_READY;
4512 tasklet_schedule(&priv->poll_rx_task);
4513 }
4514
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07004515 if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05304516 iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG,
4517 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4518
4519 atomic_inc(&priv->watchdog_event_pending);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07004520 status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
4521 ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
4522 }
4523
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004524 if (status)
4525 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004526
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004527 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004528 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004529 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004530 }
4531
4532 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004533 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02004534 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004535 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004536 }
4537
4538 return IRQ_HANDLED;
4539}
4540
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004541static void mwl8k_tx_poll(unsigned long data)
4542{
4543 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4544 struct mwl8k_priv *priv = hw->priv;
4545 int limit;
4546 int i;
4547
4548 limit = 32;
4549
4550 spin_lock_bh(&priv->tx_lock);
4551
Brian Cavagnoloe6007072011-03-17 11:58:44 -07004552 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004553 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
4554
4555 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
4556 complete(priv->tx_wait);
4557 priv->tx_wait = NULL;
4558 }
4559
4560 spin_unlock_bh(&priv->tx_lock);
4561
4562 if (limit) {
4563 writel(~MWL8K_A2H_INT_TX_DONE,
4564 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4565 } else {
4566 tasklet_schedule(&priv->poll_tx_task);
4567 }
4568}
4569
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004570static void mwl8k_rx_poll(unsigned long data)
4571{
4572 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4573 struct mwl8k_priv *priv = hw->priv;
4574 int limit;
4575
4576 limit = 32;
4577 limit -= rxq_process(hw, 0, limit);
4578 limit -= rxq_refill(hw, 0, limit);
4579
4580 if (limit) {
4581 writel(~MWL8K_A2H_INT_RX_READY,
4582 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4583 } else {
4584 tasklet_schedule(&priv->poll_rx_task);
4585 }
4586}
4587
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004588
4589/*
4590 * Core driver operations.
4591 */
Thomas Huehn36323f82012-07-23 21:33:42 +02004592static void mwl8k_tx(struct ieee80211_hw *hw,
4593 struct ieee80211_tx_control *control,
4594 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004595{
4596 struct mwl8k_priv *priv = hw->priv;
4597 int index = skb_get_queue_mapping(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004598
Lennert Buytenhek9189c102010-01-12 13:47:32 +01004599 if (!priv->radio_on) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004600 wiphy_debug(hw->wiphy,
4601 "dropped TX frame since radio disabled\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004602 dev_kfree_skb(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +01004603 return;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004604 }
4605
Thomas Huehn36323f82012-07-23 21:33:42 +02004606 mwl8k_txq_xmit(hw, index, control->sta, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004607}
4608
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004609static int mwl8k_start(struct ieee80211_hw *hw)
4610{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004611 struct mwl8k_priv *priv = hw->priv;
4612 int rc;
4613
Joe Perchesa0607fd2009-11-18 23:29:17 -08004614 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004615 IRQF_SHARED, MWL8K_NAME, hw);
4616 if (rc) {
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304617 priv->irq = -1;
Joe Perches5db55842010-08-11 19:11:19 -07004618 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004619 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004620 }
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304621 priv->irq = priv->pdev->irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004622
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004623 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004624 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004625 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004626
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004627 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004628 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Nishant Sarmukadam12488e02011-04-08 14:38:27 +05304629 iowrite32(MWL8K_A2H_EVENTS,
4630 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004631
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004632 rc = mwl8k_fw_lock(hw);
4633 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004634 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004635
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02004636 if (!priv->ap_fw) {
4637 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004638 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004639
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02004640 if (!rc)
4641 rc = mwl8k_cmd_set_pre_scan(hw);
4642
4643 if (!rc)
4644 rc = mwl8k_cmd_set_post_scan(hw,
4645 "\x00\x00\x00\x00\x00\x00");
4646 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004647
4648 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004649 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004650
4651 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004652 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004653
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004654 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004655 }
4656
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004657 if (rc) {
4658 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4659 free_irq(priv->pdev->irq, hw);
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304660 priv->irq = -1;
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004661 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004662 tasklet_disable(&priv->poll_rx_task);
Nishant Sarmukadam4850b6d2013-01-08 12:10:53 +05304663 } else {
4664 ieee80211_wake_queues(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004665 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004666
4667 return rc;
4668}
4669
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004670static void mwl8k_stop(struct ieee80211_hw *hw)
4671{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004672 struct mwl8k_priv *priv = hw->priv;
4673 int i;
4674
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304675 if (!priv->hw_restart_in_progress)
4676 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004677
4678 ieee80211_stop_queues(hw);
4679
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004680 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004681 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304682 if (priv->irq != -1) {
4683 free_irq(priv->pdev->irq, hw);
4684 priv->irq = -1;
4685 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004686
4687 /* Stop finalize join worker */
4688 cancel_work_sync(&priv->finalize_join_worker);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07004689 cancel_work_sync(&priv->watchdog_ba_handle);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004690 if (priv->beacon_skb != NULL)
4691 dev_kfree_skb(priv->beacon_skb);
4692
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004693 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004694 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004695 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004696
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004697 /* Return all skbs to mac80211 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07004698 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004699 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004700}
4701
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004702static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
4703
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004704static int mwl8k_add_interface(struct ieee80211_hw *hw,
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004705 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004706{
4707 struct mwl8k_priv *priv = hw->priv;
4708 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004709 u32 macids_supported;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004710 int macid, rc;
4711 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004712
4713 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004714 * Reject interface creation if sniffer mode is active, as
4715 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004716 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004717 */
4718 if (priv->sniffer_enabled) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004719 wiphy_info(hw->wiphy,
4720 "unable to create STA interface because sniffer mode is enabled\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004721 return -EINVAL;
4722 }
4723
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004724 di = priv->device_info;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004725 switch (vif->type) {
4726 case NL80211_IFTYPE_AP:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004727 if (!priv->ap_fw && di->fw_image_ap) {
4728 /* we must load the ap fw to meet this request */
4729 if (!list_empty(&priv->vif_list))
4730 return -EBUSY;
4731 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4732 if (rc)
4733 return rc;
4734 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004735 macids_supported = priv->ap_macids_supported;
4736 break;
4737 case NL80211_IFTYPE_STATION:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004738 if (priv->ap_fw && di->fw_image_sta) {
Yogesh Ashok Poward59c1cf2013-01-25 16:20:03 +05304739 if (!list_empty(&priv->vif_list)) {
4740 wiphy_warn(hw->wiphy, "AP interface is running.\n"
4741 "Adding STA interface for WDS");
4742 } else {
4743 /* we must load the sta fw to
4744 * meet this request.
4745 */
4746 rc = mwl8k_reload_firmware(hw,
4747 di->fw_image_sta);
4748 if (rc)
4749 return rc;
4750 }
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004751 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004752 macids_supported = priv->sta_macids_supported;
4753 break;
4754 default:
4755 return -EINVAL;
4756 }
4757
4758 macid = ffs(macids_supported & ~priv->macids_used);
4759 if (!macid--)
4760 return -EBUSY;
4761
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004762 /* Setup driver private area. */
Johannes Berg1ed32e42009-12-23 13:15:45 +01004763 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004764 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004765 mwl8k_vif->vif = vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004766 mwl8k_vif->macid = macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004767 mwl8k_vif->seqno = 0;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08004768 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
4769 mwl8k_vif->is_hw_crypto_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004770
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004771 /* Set the mac address. */
4772 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
4773
Yogesh Ashok Poward994a1c2013-01-25 16:20:35 +05304774 if (vif->type == NL80211_IFTYPE_AP)
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004775 mwl8k_cmd_set_new_stn_add_self(hw, vif);
4776
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004777 priv->macids_used |= 1 << mwl8k_vif->macid;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004778 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004779
4780 return 0;
4781}
4782
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304783static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
4784{
4785 /* Has ieee80211_restart_hw re-added the removed interfaces? */
4786 if (!priv->macids_used)
4787 return;
4788
4789 priv->macids_used &= ~(1 << vif->macid);
4790 list_del(&vif->list);
4791}
4792
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004793static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01004794 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004795{
4796 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004797 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004798
Yogesh Ashok Poward994a1c2013-01-25 16:20:35 +05304799 if (vif->type == NL80211_IFTYPE_AP)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004800 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
4801
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05304802 mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004803
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304804 mwl8k_remove_vif(priv, mwl8k_vif);
4805}
4806
4807static void mwl8k_hw_restart_work(struct work_struct *work)
4808{
4809 struct mwl8k_priv *priv =
4810 container_of(work, struct mwl8k_priv, fw_reload);
4811 struct ieee80211_hw *hw = priv->hw;
4812 struct mwl8k_device_info *di;
4813 int rc;
4814
4815 /* If some command is waiting for a response, clear it */
4816 if (priv->hostcmd_wait != NULL) {
4817 complete(priv->hostcmd_wait);
4818 priv->hostcmd_wait = NULL;
4819 }
4820
4821 priv->hw_restart_owner = current;
4822 di = priv->device_info;
4823 mwl8k_fw_lock(hw);
4824
4825 if (priv->ap_fw)
4826 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4827 else
4828 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4829
4830 if (rc)
4831 goto fail;
4832
4833 priv->hw_restart_owner = NULL;
4834 priv->hw_restart_in_progress = false;
4835
4836 /*
4837 * This unlock will wake up the queues and
4838 * also opens the command path for other
4839 * commands
4840 */
4841 mwl8k_fw_unlock(hw);
4842
4843 ieee80211_restart_hw(hw);
4844
4845 wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
4846
4847 return;
4848fail:
4849 mwl8k_fw_unlock(hw);
4850
4851 wiphy_err(hw->wiphy, "Firmware restart failed\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004852}
4853
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004854static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004855{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004856 struct ieee80211_conf *conf = &hw->conf;
4857 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004858 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004859
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004860 rc = mwl8k_fw_lock(hw);
4861 if (rc)
4862 return rc;
4863
Jonas Gorskife21bb02013-03-25 16:39:54 +01004864 if (conf->flags & IEEE80211_CONF_IDLE)
4865 rc = mwl8k_cmd_radio_disable(hw);
4866 else
4867 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004868 if (rc)
4869 goto out;
4870
Yogesh Ashok Powar0f4316b2013-01-25 16:17:45 +05304871 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
4872 rc = mwl8k_cmd_set_rf_channel(hw, conf);
4873 if (rc)
4874 goto out;
4875 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004876
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004877 if (conf->power_level > 18)
4878 conf->power_level = 18;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004879
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004880 if (priv->ap_fw) {
Nishant Sarmukadam03217082011-04-05 14:18:09 +05304881
4882 if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
4883 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
4884 if (rc)
4885 goto out;
4886 }
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08004887
Nishant Sarmukadamda62b762011-02-17 14:45:16 -08004888
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004889 } else {
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08004890 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
4891 if (rc)
4892 goto out;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004893 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
4894 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004895
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004896out:
4897 mwl8k_fw_unlock(hw);
4898
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004899 return rc;
4900}
4901
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004902static void
4903mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4904 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004905{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004906 struct mwl8k_priv *priv = hw->priv;
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05304907 u32 ap_legacy_rates = 0;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004908 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004909 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004910
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004911 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004912 return;
4913
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004914 /*
4915 * No need to capture a beacon if we're no longer associated.
4916 */
4917 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
4918 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004919
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004920 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004921 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004922 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004923 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004924 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01004925
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004926 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004927
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004928 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004929 if (ap == NULL) {
4930 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004931 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004932 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004933
Karl Beldan675a0b02013-03-25 16:26:57 +01004934 if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) {
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004935 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
4936 } else {
4937 ap_legacy_rates =
4938 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4939 }
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004940 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004941
4942 rcu_read_unlock();
4943 }
4944
Yogesh Ashok Powardcee7432013-01-25 16:20:50 +05304945 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
4946 !priv->ap_fw) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004947 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004948 if (rc)
4949 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004950
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01004951 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004952 if (rc)
4953 goto out;
Yogesh Ashok Powardcee7432013-01-25 16:20:50 +05304954 } else {
4955 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
4956 priv->ap_fw) {
4957 int idx;
4958 int rate;
4959
4960 /* Use AP firmware specific rate command.
4961 */
4962 idx = ffs(vif->bss_conf.basic_rates);
4963 if (idx)
4964 idx--;
4965
Karl Beldan675a0b02013-03-25 16:26:57 +01004966 if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
Yogesh Ashok Powardcee7432013-01-25 16:20:50 +05304967 rate = mwl8k_rates_24[idx].hw_value;
4968 else
4969 rate = mwl8k_rates_50[idx].hw_value;
4970
4971 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4972 }
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004973 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004974
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004975 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004976 rc = mwl8k_set_radio_preamble(hw,
4977 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004978 if (rc)
4979 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004980 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004981
Yogesh Ashok Powardcee7432013-01-25 16:20:50 +05304982 if ((changed & BSS_CHANGED_ERP_SLOT) && !priv->ap_fw) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004983 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004984 if (rc)
4985 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004986 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004987
Yogesh Ashok Powardcee7432013-01-25 16:20:50 +05304988 if (vif->bss_conf.assoc && !priv->ap_fw &&
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01004989 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4990 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004991 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004992 if (rc)
4993 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004994 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004995
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004996 if (vif->bss_conf.assoc &&
4997 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004998 /*
4999 * Finalize the join. Tell rx handler to process
5000 * next beacon from our BSSID.
5001 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01005002 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005003 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005004 }
5005
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02005006out:
5007 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005008}
5009
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01005010static void
5011mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5012 struct ieee80211_bss_conf *info, u32 changed)
5013{
5014 int rc;
5015
5016 if (mwl8k_fw_lock(hw))
5017 return;
5018
5019 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5020 rc = mwl8k_set_radio_preamble(hw,
5021 vif->bss_conf.use_short_preamble);
5022 if (rc)
5023 goto out;
5024 }
5025
5026 if (changed & BSS_CHANGED_BASIC_RATES) {
5027 int idx;
5028 int rate;
5029
5030 /*
5031 * Use lowest supported basic rate for multicasts
5032 * and management frames (such as probe responses --
5033 * beacons will always go out at 1 Mb/s).
5034 */
5035 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01005036 if (idx)
5037 idx--;
5038
Karl Beldan675a0b02013-03-25 16:26:57 +01005039 if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek8707d022010-01-12 13:49:15 +01005040 rate = mwl8k_rates_24[idx].hw_value;
5041 else
5042 rate = mwl8k_rates_50[idx].hw_value;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01005043
5044 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
5045 }
5046
5047 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
5048 struct sk_buff *skb;
5049
5050 skb = ieee80211_beacon_get(hw, vif);
5051 if (skb != NULL) {
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01005052 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01005053 kfree_skb(skb);
5054 }
5055 }
5056
5057 if (changed & BSS_CHANGED_BEACON_ENABLED)
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01005058 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01005059
5060out:
5061 mwl8k_fw_unlock(hw);
5062}
5063
5064static void
5065mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5066 struct ieee80211_bss_conf *info, u32 changed)
5067{
Yogesh Ashok Powar41bf9112013-01-25 16:20:42 +05305068 if (vif->type == NL80211_IFTYPE_STATION)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01005069 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
Yogesh Ashok Powar41bf9112013-01-25 16:20:42 +05305070 if (vif->type == NL80211_IFTYPE_AP)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01005071 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
5072}
5073
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02005074static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad32010-04-01 21:22:57 +00005075 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02005076{
5077 struct mwl8k_cmd_pkt *cmd;
5078
Lennert Buytenhek447ced02009-10-22 20:19:50 +02005079 /*
5080 * Synthesize and return a command packet that programs the
5081 * hardware multicast address filter. At this point we don't
5082 * know whether FIF_ALLMULTI is being requested, but if it is,
5083 * we'll end up throwing this packet away and creating a new
5084 * one in mwl8k_configure_filter().
5085 */
Jiri Pirko22bedad32010-04-01 21:22:57 +00005086 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02005087
5088 return (unsigned long)cmd;
5089}
5090
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02005091static int
5092mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
5093 unsigned int changed_flags,
5094 unsigned int *total_flags)
5095{
5096 struct mwl8k_priv *priv = hw->priv;
5097
5098 /*
5099 * Hardware sniffer mode is mutually exclusive with STA
5100 * operation, so refuse to enable sniffer mode if a STA
5101 * interface is active.
5102 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005103 if (!list_empty(&priv->vif_list)) {
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02005104 if (net_ratelimit())
Joe Perchesc96c31e2010-07-26 14:39:58 -07005105 wiphy_info(hw->wiphy,
5106 "not enabling sniffer mode because STA interface is active\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02005107 return 0;
5108 }
5109
5110 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005111 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02005112 return 0;
5113 priv->sniffer_enabled = true;
5114 }
5115
5116 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
5117 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
5118 FIF_OTHER_BSS;
5119
5120 return 1;
5121}
5122
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005123static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
5124{
5125 if (!list_empty(&priv->vif_list))
5126 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
5127
5128 return NULL;
5129}
5130
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005131static void mwl8k_configure_filter(struct ieee80211_hw *hw,
5132 unsigned int changed_flags,
5133 unsigned int *total_flags,
5134 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005135{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005136 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02005137 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
5138
5139 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02005140 * AP firmware doesn't allow fine-grained control over
5141 * the receive filter.
5142 */
5143 if (priv->ap_fw) {
5144 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
5145 kfree(cmd);
5146 return;
5147 }
5148
5149 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02005150 * Enable hardware sniffer mode if FIF_CONTROL or
5151 * FIF_OTHER_BSS is requested.
5152 */
5153 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
5154 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
5155 kfree(cmd);
5156 return;
5157 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005158
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005159 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02005160 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005161
Lennert Buytenhek90852f72010-01-02 10:31:42 +01005162 if (mwl8k_fw_lock(hw)) {
5163 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005164 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01005165 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005166
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02005167 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005168 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02005169 priv->sniffer_enabled = false;
5170 }
5171
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005172 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02005173 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
5174 /*
5175 * Disable the BSS filter.
5176 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005177 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02005178 } else {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005179 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01005180 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02005181
Lennert Buytenhek77165d82009-10-22 20:19:53 +02005182 /*
5183 * Enable the BSS filter.
5184 *
5185 * If there is an active STA interface, use that
5186 * interface's BSSID, otherwise use a dummy one
5187 * (where the OUI part needs to be nonzero for
5188 * the BSSID to be accepted by POST_SCAN).
5189 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005190 mwl8k_vif = mwl8k_first_vif(priv);
5191 if (mwl8k_vif != NULL)
5192 bssid = mwl8k_vif->vif->bss_conf.bssid;
5193 else
5194 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02005195
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005196 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005197 }
5198 }
5199
Lennert Buytenhek447ced02009-10-22 20:19:50 +02005200 /*
5201 * If FIF_ALLMULTI is being requested, throw away the command
5202 * packet that ->prepare_multicast() built and replace it with
5203 * a command packet that enables reception of all multicast
5204 * packets.
5205 */
5206 if (*total_flags & FIF_ALLMULTI) {
5207 kfree(cmd);
Jiri Pirko22bedad32010-04-01 21:22:57 +00005208 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
Lennert Buytenhek447ced02009-10-22 20:19:50 +02005209 }
5210
5211 if (cmd != NULL) {
5212 mwl8k_post_cmd(hw, cmd);
5213 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005214 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02005215
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005216 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005217}
5218
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005219static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5220{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01005221 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005222}
5223
Johannes Berg4a6967b2010-02-19 19:18:37 +01005224static int mwl8k_sta_remove(struct ieee80211_hw *hw,
5225 struct ieee80211_vif *vif,
5226 struct ieee80211_sta *sta)
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005227{
5228 struct mwl8k_priv *priv = hw->priv;
5229
Johannes Berg4a6967b2010-02-19 19:18:37 +01005230 if (priv->ap_fw)
5231 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
5232 else
5233 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
5234}
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005235
Johannes Berg4a6967b2010-02-19 19:18:37 +01005236static int mwl8k_sta_add(struct ieee80211_hw *hw,
5237 struct ieee80211_vif *vif,
5238 struct ieee80211_sta *sta)
5239{
5240 struct mwl8k_priv *priv = hw->priv;
5241 int ret;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005242 int i;
5243 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
5244 struct ieee80211_key_conf *key;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005245
Johannes Berg4a6967b2010-02-19 19:18:37 +01005246 if (!priv->ap_fw) {
5247 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
5248 if (ret >= 0) {
5249 MWL8K_STA(sta)->peer_id = ret;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07005250 if (sta->ht_cap.ht_supported)
5251 MWL8K_STA(sta)->is_ampdu_allowed = true;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005252 ret = 0;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005253 }
Johannes Berg4a6967b2010-02-19 19:18:37 +01005254
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08005255 } else {
5256 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005257 }
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005258
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08005259 for (i = 0; i < NUM_WEP_KEYS; i++) {
5260 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
5261 if (mwl8k_vif->wep_key_conf[i].enabled)
5262 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
5263 }
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005264 return ret;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01005265}
5266
Eliad Peller8a3a3c82011-10-02 10:15:52 +02005267static int mwl8k_conf_tx(struct ieee80211_hw *hw,
5268 struct ieee80211_vif *vif, u16 queue,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005269 const struct ieee80211_tx_queue_params *params)
5270{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005271 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005272 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005273
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005274 rc = mwl8k_fw_lock(hw);
5275 if (!rc) {
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005276 BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005277 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
5278
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005279 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005280 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005281
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005282 if (!rc) {
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005283 int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005284 rc = mwl8k_cmd_set_edca_params(hw, q,
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005285 params->cw_min,
5286 params->cw_max,
5287 params->aifs,
5288 params->txop);
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005289 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005290
5291 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005292 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005293
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005294 return rc;
5295}
5296
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005297static int mwl8k_get_stats(struct ieee80211_hw *hw,
5298 struct ieee80211_low_level_stats *stats)
5299{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005300 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005301}
5302
John W. Linville0d462bb2010-07-28 14:04:24 -04005303static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
5304 struct survey_info *survey)
5305{
5306 struct mwl8k_priv *priv = hw->priv;
5307 struct ieee80211_conf *conf = &hw->conf;
5308
5309 if (idx != 0)
5310 return -ENOENT;
5311
Karl Beldan675a0b02013-03-25 16:26:57 +01005312 survey->channel = conf->chandef.chan;
John W. Linville0d462bb2010-07-28 14:04:24 -04005313 survey->filled = SURVEY_INFO_NOISE_DBM;
5314 survey->noise = priv->noise;
5315
5316 return 0;
5317}
5318
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005319#define MAX_AMPDU_ATTEMPTS 5
5320
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005321static int
5322mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5323 enum ieee80211_ampdu_mlme_action action,
Johannes Berg0b01f032011-01-18 13:51:05 +01005324 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5325 u8 buf_size)
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005326{
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005327
5328 int i, rc = 0;
5329 struct mwl8k_priv *priv = hw->priv;
5330 struct mwl8k_ampdu_stream *stream;
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305331 u8 *addr = sta->addr, idx;
Yogesh Ashok Powarfd712f52012-11-06 19:22:35 +05305332 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005333
5334 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
5335 return -ENOTSUPP;
5336
5337 spin_lock(&priv->stream_lock);
5338 stream = mwl8k_lookup_stream(hw, addr, tid);
5339
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005340 switch (action) {
5341 case IEEE80211_AMPDU_RX_START:
5342 case IEEE80211_AMPDU_RX_STOP:
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005343 break;
5344 case IEEE80211_AMPDU_TX_START:
5345 /* By the time we get here the hw queues may contain outgoing
5346 * packets for this RA/TID that are not part of this BA
5347 * session. The hw will assign sequence numbers to these
5348 * packets as they go out. So if we query the hw for its next
5349 * sequence number and use that for the SSN here, it may end up
5350 * being wrong, which will lead to sequence number mismatch at
5351 * the recipient. To avoid this, we reset the sequence number
5352 * to O for the first MPDU in this BA stream.
5353 */
5354 *ssn = 0;
5355 if (stream == NULL) {
5356 /* This means that somebody outside this driver called
5357 * ieee80211_start_tx_ba_session. This is unexpected
5358 * because we do our own rate control. Just warn and
5359 * move on.
5360 */
5361 wiphy_warn(hw->wiphy, "Unexpected call to %s. "
5362 "Proceeding anyway.\n", __func__);
5363 stream = mwl8k_add_stream(hw, sta, tid);
5364 }
5365 if (stream == NULL) {
5366 wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
5367 rc = -EBUSY;
5368 break;
5369 }
5370 stream->state = AMPDU_STREAM_IN_PROGRESS;
5371
5372 /* Release the lock before we do the time consuming stuff */
5373 spin_unlock(&priv->stream_lock);
5374 for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
Yogesh Ashok Powarfd712f52012-11-06 19:22:35 +05305375
5376 /* Check if link is still valid */
5377 if (!sta_info->is_ampdu_allowed) {
5378 spin_lock(&priv->stream_lock);
5379 mwl8k_remove_stream(hw, stream);
5380 spin_unlock(&priv->stream_lock);
5381 return -EBUSY;
5382 }
5383
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05305384 rc = mwl8k_check_ba(hw, stream, vif);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005385
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305386 /* If HW restart is in progress mwl8k_post_cmd will
5387 * return -EBUSY. Avoid retrying mwl8k_check_ba in
5388 * such cases
5389 */
5390 if (!rc || rc == -EBUSY)
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005391 break;
5392 /*
5393 * HW queues take time to be flushed, give them
5394 * sufficient time
5395 */
5396
5397 msleep(1000);
5398 }
5399 spin_lock(&priv->stream_lock);
5400 if (rc) {
5401 wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
5402 " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
5403 mwl8k_remove_stream(hw, stream);
5404 rc = -EBUSY;
5405 break;
5406 }
5407 ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
5408 break;
Johannes Berg18b559d2012-07-18 13:51:25 +02005409 case IEEE80211_AMPDU_TX_STOP_CONT:
5410 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5411 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305412 if (stream) {
5413 if (stream->state == AMPDU_STREAM_ACTIVE) {
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305414 idx = stream->idx;
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305415 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305416 mwl8k_destroy_ba(hw, idx);
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305417 spin_lock(&priv->stream_lock);
5418 }
5419 mwl8k_remove_stream(hw, stream);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005420 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005421 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
5422 break;
5423 case IEEE80211_AMPDU_TX_OPERATIONAL:
5424 BUG_ON(stream == NULL);
5425 BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
5426 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05305427 rc = mwl8k_create_ba(hw, stream, buf_size, vif);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005428 spin_lock(&priv->stream_lock);
5429 if (!rc)
5430 stream->state = AMPDU_STREAM_ACTIVE;
5431 else {
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305432 idx = stream->idx;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005433 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305434 mwl8k_destroy_ba(hw, idx);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005435 spin_lock(&priv->stream_lock);
5436 wiphy_debug(hw->wiphy,
5437 "Failed adding stream for sta %pM tid %d\n",
5438 addr, tid);
5439 mwl8k_remove_stream(hw, stream);
5440 }
5441 break;
5442
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005443 default:
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005444 rc = -ENOTSUPP;
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005445 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005446
5447 spin_unlock(&priv->stream_lock);
5448 return rc;
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005449}
5450
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005451static const struct ieee80211_ops mwl8k_ops = {
5452 .tx = mwl8k_tx,
5453 .start = mwl8k_start,
5454 .stop = mwl8k_stop,
5455 .add_interface = mwl8k_add_interface,
5456 .remove_interface = mwl8k_remove_interface,
5457 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005458 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02005459 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005460 .configure_filter = mwl8k_configure_filter,
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005461 .set_key = mwl8k_set_key,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005462 .set_rts_threshold = mwl8k_set_rts_threshold,
Johannes Berg4a6967b2010-02-19 19:18:37 +01005463 .sta_add = mwl8k_sta_add,
5464 .sta_remove = mwl8k_sta_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005465 .conf_tx = mwl8k_conf_tx,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005466 .get_stats = mwl8k_get_stats,
John W. Linville0d462bb2010-07-28 14:04:24 -04005467 .get_survey = mwl8k_get_survey,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005468 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005469};
5470
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005471static void mwl8k_finalize_join_worker(struct work_struct *work)
5472{
5473 struct mwl8k_priv *priv =
5474 container_of(work, struct mwl8k_priv, finalize_join_worker);
5475 struct sk_buff *skb = priv->beacon_skb;
Johannes Berg56007a02010-01-26 14:19:52 +01005476 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5477 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
5478 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
5479 mgmt->u.beacon.variable, len);
5480 int dtim_period = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005481
Johannes Berg56007a02010-01-26 14:19:52 +01005482 if (tim && tim[1] >= 2)
5483 dtim_period = tim[3];
5484
5485 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005486
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005487 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005488 priv->beacon_skb = NULL;
5489}
5490
John W. Linvillebcb628d2009-11-06 16:40:16 -05005491enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005492 MWL8363 = 0,
5493 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05005494 MWL8366,
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +05305495 MWL8764,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02005496};
5497
Yogesh Ashok Powarc2f2e202013-01-03 13:24:44 +05305498#define MWL8K_8366_AP_FW_API 3
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005499#define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5500#define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5501
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +05305502#define MWL8K_8764_AP_FW_API 1
5503#define _MWL8K_8764_AP_FW(api) "mwl8k/fmimage_8764_ap-" #api ".fw"
5504#define MWL8K_8764_AP_FW(api) _MWL8K_8764_AP_FW(api)
5505
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005506static struct mwl8k_device_info mwl8k_info_tbl[] = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005507 [MWL8363] = {
5508 .part_name = "88w8363",
5509 .helper_image = "mwl8k/helper_8363.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005510 .fw_image_sta = "mwl8k/fmimage_8363.fw",
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005511 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01005512 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05005513 .part_name = "88w8687",
5514 .helper_image = "mwl8k/helper_8687.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005515 .fw_image_sta = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05005516 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01005517 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05005518 .part_name = "88w8366",
5519 .helper_image = "mwl8k/helper_8366.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005520 .fw_image_sta = "mwl8k/fmimage_8366.fw",
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005521 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
5522 .fw_api_ap = MWL8K_8366_AP_FW_API,
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +05305523 .ap_rxd_ops = &rxd_ap_ops,
5524 },
5525 [MWL8764] = {
5526 .part_name = "88w8764",
5527 .fw_image_ap = MWL8K_8764_AP_FW(MWL8K_8764_AP_FW_API),
5528 .fw_api_ap = MWL8K_8764_AP_FW_API,
5529 .ap_rxd_ops = &rxd_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05005530 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005531};
5532
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01005533MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5534MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5535MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5536MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5537MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5538MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005539MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01005540
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005541static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Benjamin Larssone5868ba12010-03-19 01:46:10 +01005542 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005543 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
5544 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05005545 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
5546 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
5547 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Jonas Gorskifc5bc162013-02-05 16:59:17 +01005548 { PCI_VDEVICE(MARVELL, 0x2a41), .driver_data = MWL8366, },
5549 { PCI_VDEVICE(MARVELL, 0x2a42), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01005550 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
Nishant Sarmukadamd926dc72013-03-01 17:12:45 +05305551 { PCI_VDEVICE(MARVELL, 0x2b36), .driver_data = MWL8764, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05005552 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005553};
5554MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
5555
Brian Cavagnolo99020472010-11-12 17:23:52 -08005556static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
5557{
5558 int rc;
5559 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
5560 "Trying alternative firmware %s\n", pci_name(priv->pdev),
5561 priv->fw_pref, priv->fw_alt);
5562 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
5563 if (rc) {
5564 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5565 pci_name(priv->pdev), priv->fw_alt);
5566 return rc;
5567 }
5568 return 0;
5569}
5570
5571static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
5572static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
5573{
5574 struct mwl8k_priv *priv = context;
5575 struct mwl8k_device_info *di = priv->device_info;
5576 int rc;
5577
5578 switch (priv->fw_state) {
5579 case FW_STATE_INIT:
5580 if (!fw) {
5581 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
5582 pci_name(priv->pdev), di->helper_image);
5583 goto fail;
5584 }
5585 priv->fw_helper = fw;
5586 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
5587 true);
5588 if (rc && priv->fw_alt) {
5589 rc = mwl8k_request_alt_fw(priv);
5590 if (rc)
5591 goto fail;
5592 priv->fw_state = FW_STATE_LOADING_ALT;
5593 } else if (rc)
5594 goto fail;
5595 else
5596 priv->fw_state = FW_STATE_LOADING_PREF;
5597 break;
5598
5599 case FW_STATE_LOADING_PREF:
5600 if (!fw) {
5601 if (priv->fw_alt) {
5602 rc = mwl8k_request_alt_fw(priv);
5603 if (rc)
5604 goto fail;
5605 priv->fw_state = FW_STATE_LOADING_ALT;
5606 } else
5607 goto fail;
5608 } else {
5609 priv->fw_ucode = fw;
5610 rc = mwl8k_firmware_load_success(priv);
5611 if (rc)
5612 goto fail;
5613 else
5614 complete(&priv->firmware_loading_complete);
5615 }
5616 break;
5617
5618 case FW_STATE_LOADING_ALT:
5619 if (!fw) {
5620 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5621 pci_name(priv->pdev), di->helper_image);
5622 goto fail;
5623 }
5624 priv->fw_ucode = fw;
5625 rc = mwl8k_firmware_load_success(priv);
5626 if (rc)
5627 goto fail;
5628 else
5629 complete(&priv->firmware_loading_complete);
5630 break;
5631
5632 default:
5633 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
5634 MWL8K_NAME, priv->fw_state);
5635 BUG_ON(1);
5636 }
5637
5638 return;
5639
5640fail:
5641 priv->fw_state = FW_STATE_ERROR;
5642 complete(&priv->firmware_loading_complete);
5643 device_release_driver(&priv->pdev->dev);
5644 mwl8k_release_firmware(priv);
5645}
5646
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305647#define MAX_RESTART_ATTEMPTS 1
Brian Cavagnolo99020472010-11-12 17:23:52 -08005648static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
5649 bool nowait)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005650{
5651 struct mwl8k_priv *priv = hw->priv;
5652 int rc;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305653 int count = MAX_RESTART_ATTEMPTS;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005654
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305655retry:
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005656 /* Reset firmware and hardware */
5657 mwl8k_hw_reset(priv);
5658
5659 /* Ask userland hotplug daemon for the device firmware */
Brian Cavagnolo99020472010-11-12 17:23:52 -08005660 rc = mwl8k_request_firmware(priv, fw_image, nowait);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005661 if (rc) {
5662 wiphy_err(hw->wiphy, "Firmware files not found\n");
5663 return rc;
5664 }
5665
Brian Cavagnolo99020472010-11-12 17:23:52 -08005666 if (nowait)
5667 return rc;
5668
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005669 /* Load firmware into hardware */
5670 rc = mwl8k_load_firmware(hw);
5671 if (rc)
5672 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5673
5674 /* Reclaim memory once firmware is successfully loaded */
5675 mwl8k_release_firmware(priv);
5676
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305677 if (rc && count) {
5678 /* FW did not start successfully;
5679 * lets try one more time
5680 */
5681 count--;
5682 wiphy_err(hw->wiphy, "Trying to reload the firmware again\n");
5683 msleep(20);
5684 goto retry;
5685 }
5686
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005687 return rc;
5688}
5689
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005690static int mwl8k_init_txqs(struct ieee80211_hw *hw)
5691{
5692 struct mwl8k_priv *priv = hw->priv;
5693 int rc = 0;
5694 int i;
5695
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005696 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005697 rc = mwl8k_txq_init(hw, i);
5698 if (rc)
5699 break;
5700 if (priv->ap_fw)
5701 iowrite32(priv->txq[i].txd_dma,
5702 priv->sram + priv->txq_offset[i]);
5703 }
5704 return rc;
5705}
5706
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005707/* initialize hw after successfully loading a firmware image */
5708static int mwl8k_probe_hw(struct ieee80211_hw *hw)
5709{
5710 struct mwl8k_priv *priv = hw->priv;
5711 int rc = 0;
5712 int i;
5713
5714 if (priv->ap_fw) {
5715 priv->rxd_ops = priv->device_info->ap_rxd_ops;
5716 if (priv->rxd_ops == NULL) {
5717 wiphy_err(hw->wiphy,
5718 "Driver does not have AP firmware image support for this hardware\n");
Alexey Khoroshilova2ca8ec2013-01-19 01:24:01 +04005719 rc = -ENOENT;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005720 goto err_stop_firmware;
5721 }
5722 } else {
5723 priv->rxd_ops = &rxd_sta_ops;
5724 }
5725
5726 priv->sniffer_enabled = false;
5727 priv->wmm_enabled = false;
5728 priv->pending_tx_pkts = 0;
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05305729 atomic_set(&priv->watchdog_event_pending, 0);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005730
5731 rc = mwl8k_rxq_init(hw, 0);
5732 if (rc)
5733 goto err_stop_firmware;
5734 rxq_refill(hw, 0, INT_MAX);
5735
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005736 /* For the sta firmware, we need to know the dma addresses of tx queues
5737 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5738 * prior to issuing this command. But for the AP case, we learn the
5739 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5740 * case we must initialize the tx queues after.
5741 */
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07005742 priv->num_ampdu_queues = 0;
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005743 if (!priv->ap_fw) {
5744 rc = mwl8k_init_txqs(hw);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005745 if (rc)
5746 goto err_free_queues;
5747 }
5748
5749 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
5750 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07005751 iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
5752 MWL8K_A2H_INT_BA_WATCHDOG,
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005753 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
Nishant Sarmukadam12488e02011-04-08 14:38:27 +05305754 iowrite32(MWL8K_A2H_INT_OPC_DONE,
5755 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005756
5757 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
5758 IRQF_SHARED, MWL8K_NAME, hw);
5759 if (rc) {
5760 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
5761 goto err_free_queues;
5762 }
5763
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305764 /*
5765 * When hw restart is requested,
5766 * mac80211 will take care of clearing
5767 * the ampdu streams, so do not clear
5768 * the ampdu state here
5769 */
5770 if (!priv->hw_restart_in_progress)
5771 memset(priv->ampdu, 0, sizeof(priv->ampdu));
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07005772
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005773 /*
5774 * Temporarily enable interrupts. Initial firmware host
5775 * commands use interrupts and avoid polling. Disable
5776 * interrupts when done.
5777 */
5778 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5779
5780 /* Get config data, mac addrs etc */
5781 if (priv->ap_fw) {
5782 rc = mwl8k_cmd_get_hw_spec_ap(hw);
5783 if (!rc)
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005784 rc = mwl8k_init_txqs(hw);
5785 if (!rc)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005786 rc = mwl8k_cmd_set_hw_spec(hw);
5787 } else {
5788 rc = mwl8k_cmd_get_hw_spec_sta(hw);
5789 }
5790 if (rc) {
5791 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
5792 goto err_free_irq;
5793 }
5794
5795 /* Turn radio off */
5796 rc = mwl8k_cmd_radio_disable(hw);
5797 if (rc) {
5798 wiphy_err(hw->wiphy, "Cannot disable\n");
5799 goto err_free_irq;
5800 }
5801
5802 /* Clear MAC address */
5803 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
5804 if (rc) {
5805 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
5806 goto err_free_irq;
5807 }
5808
Yogesh Ashok Powara246ac32013-01-25 16:17:56 +05305809 /* Configure Antennas */
5810 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
5811 if (rc)
5812 wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
5813 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
5814 if (rc)
5815 wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
5816
5817
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005818 /* Disable interrupts */
5819 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5820 free_irq(priv->pdev->irq, hw);
5821
5822 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5823 priv->device_info->part_name,
5824 priv->hw_rev, hw->wiphy->perm_addr,
5825 priv->ap_fw ? "AP" : "STA",
5826 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
5827 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
5828
5829 return 0;
5830
5831err_free_irq:
5832 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5833 free_irq(priv->pdev->irq, hw);
5834
5835err_free_queues:
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005836 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005837 mwl8k_txq_deinit(hw, i);
5838 mwl8k_rxq_deinit(hw, 0);
5839
5840err_stop_firmware:
5841 mwl8k_hw_reset(priv);
5842
5843 return rc;
5844}
5845
5846/*
5847 * invoke mwl8k_reload_firmware to change the firmware image after the device
5848 * has already been registered
5849 */
5850static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
5851{
5852 int i, rc = 0;
5853 struct mwl8k_priv *priv = hw->priv;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305854 struct mwl8k_vif *vif, *tmp_vif;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005855
5856 mwl8k_stop(hw);
5857 mwl8k_rxq_deinit(hw, 0);
5858
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305859 /*
5860 * All the existing interfaces are re-added by the ieee80211_reconfig;
5861 * which means driver should remove existing interfaces before calling
5862 * ieee80211_restart_hw
5863 */
5864 if (priv->hw_restart_in_progress)
5865 list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list)
5866 mwl8k_remove_vif(priv, vif);
5867
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005868 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005869 mwl8k_txq_deinit(hw, i);
5870
Brian Cavagnolo99020472010-11-12 17:23:52 -08005871 rc = mwl8k_init_firmware(hw, fw_image, false);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005872 if (rc)
5873 goto fail;
5874
5875 rc = mwl8k_probe_hw(hw);
5876 if (rc)
5877 goto fail;
5878
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305879 if (priv->hw_restart_in_progress)
5880 return rc;
5881
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005882 rc = mwl8k_start(hw);
5883 if (rc)
5884 goto fail;
5885
5886 rc = mwl8k_config(hw, ~0);
5887 if (rc)
5888 goto fail;
5889
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005890 for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
Eliad Peller8a3a3c82011-10-02 10:15:52 +02005891 rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005892 if (rc)
5893 goto fail;
5894 }
5895
5896 return rc;
5897
5898fail:
5899 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
5900 return rc;
5901}
5902
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305903static const struct ieee80211_iface_limit ap_if_limits[] = {
5904 { .max = 8, .types = BIT(NL80211_IFTYPE_AP) },
Yogesh Ashok Powar2acdaa72013-01-25 16:19:55 +05305905 { .max = 1, .types = BIT(NL80211_IFTYPE_STATION) },
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305906};
5907
5908static const struct ieee80211_iface_combination ap_if_comb = {
5909 .limits = ap_if_limits,
5910 .n_limits = ARRAY_SIZE(ap_if_limits),
5911 .max_interfaces = 8,
5912 .num_different_channels = 1,
5913};
5914
5915
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005916static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
5917{
5918 struct ieee80211_hw *hw = priv->hw;
5919 int i, rc;
5920
Brian Cavagnolo99020472010-11-12 17:23:52 -08005921 rc = mwl8k_load_firmware(hw);
5922 mwl8k_release_firmware(priv);
5923 if (rc) {
5924 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5925 return rc;
5926 }
5927
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005928 /*
5929 * Extra headroom is the size of the required DMA header
5930 * minus the size of the smallest 802.11 frame (CTS frame).
5931 */
5932 hw->extra_tx_headroom =
5933 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
5934
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +05305935 hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0;
5936
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005937 hw->queues = MWL8K_TX_WMM_QUEUES;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005938
5939 /* Set rssi values to dBm */
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08005940 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
Yogesh Ashok Powar2a36a0e2011-08-29 17:12:44 +05305941
5942 /*
5943 * Ask mac80211 to not to trigger PS mode
5944 * based on PM bit of incoming frames.
5945 */
5946 if (priv->ap_fw)
5947 hw->flags |= IEEE80211_HW_AP_LINK_PS;
5948
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005949 hw->vif_data_size = sizeof(struct mwl8k_vif);
5950 hw->sta_data_size = sizeof(struct mwl8k_sta);
5951
5952 priv->macids_used = 0;
5953 INIT_LIST_HEAD(&priv->vif_list);
5954
5955 /* Set default radio state and preamble */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005956 priv->radio_on = false;
5957 priv->radio_short_preamble = false;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005958
5959 /* Finalize join worker */
5960 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07005961 /* Handle watchdog ba events */
5962 INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305963 /* To reload the firmware if it crashes */
5964 INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005965
5966 /* TX reclaim and RX tasklets. */
5967 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
5968 tasklet_disable(&priv->poll_tx_task);
5969 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
5970 tasklet_disable(&priv->poll_rx_task);
5971
5972 /* Power management cookie */
5973 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
5974 if (priv->cookie == NULL)
5975 return -ENOMEM;
5976
5977 mutex_init(&priv->fw_mutex);
5978 priv->fw_mutex_owner = NULL;
5979 priv->fw_mutex_depth = 0;
5980 priv->hostcmd_wait = NULL;
5981
5982 spin_lock_init(&priv->tx_lock);
5983
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07005984 spin_lock_init(&priv->stream_lock);
5985
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005986 priv->tx_wait = NULL;
5987
5988 rc = mwl8k_probe_hw(hw);
5989 if (rc)
5990 goto err_free_cookie;
5991
5992 hw->wiphy->interface_modes = 0;
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305993
5994 if (priv->ap_macids_supported || priv->device_info->fw_image_ap) {
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005995 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
Yogesh Ashok Powar2acdaa72013-01-25 16:19:55 +05305996 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305997 hw->wiphy->iface_combinations = &ap_if_comb;
5998 hw->wiphy->n_iface_combinations = 1;
5999 }
6000
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08006001 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
6002 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
6003
6004 rc = ieee80211_register_hw(hw);
6005 if (rc) {
6006 wiphy_err(hw->wiphy, "Cannot register device\n");
6007 goto err_unprobe_hw;
6008 }
6009
6010 return 0;
6011
6012err_unprobe_hw:
Brian Cavagnoloe6007072011-03-17 11:58:44 -07006013 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08006014 mwl8k_txq_deinit(hw, i);
6015 mwl8k_rxq_deinit(hw, 0);
6016
6017err_free_cookie:
6018 if (priv->cookie != NULL)
6019 pci_free_consistent(priv->pdev, 4,
6020 priv->cookie, priv->cookie_dma);
6021
6022 return rc;
6023}
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05006024static int mwl8k_probe(struct pci_dev *pdev,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006025 const struct pci_device_id *id)
6026{
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08006027 static int printed_version;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006028 struct ieee80211_hw *hw;
6029 struct mwl8k_priv *priv;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08006030 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006031 int rc;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02006032
6033 if (!printed_version) {
6034 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
6035 printed_version = 1;
6036 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006037
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01006038
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006039 rc = pci_enable_device(pdev);
6040 if (rc) {
6041 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
6042 MWL8K_NAME);
6043 return rc;
6044 }
6045
6046 rc = pci_request_regions(pdev, MWL8K_NAME);
6047 if (rc) {
6048 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
6049 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01006050 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006051 }
6052
6053 pci_set_master(pdev);
6054
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01006055
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006056 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
6057 if (hw == NULL) {
6058 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
6059 rc = -ENOMEM;
6060 goto err_free_reg;
6061 }
6062
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01006063 SET_IEEE80211_DEV(hw, &pdev->dev);
6064 pci_set_drvdata(pdev, hw);
6065
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006066 priv = hw->priv;
6067 priv->hw = hw;
6068 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05006069 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006070
Nishant Sarmukadam98929822013-03-01 17:13:01 +05306071 if (id->driver_data == MWL8764)
6072 priv->is_8764 = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006073
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02006074 priv->sram = pci_iomap(pdev, 0, 0x10000);
6075 if (priv->sram == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07006076 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
Alexey Khoroshilova2ca8ec2013-01-19 01:24:01 +04006077 rc = -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006078 goto err_iounmap;
6079 }
6080
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02006081 /*
6082 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
6083 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
6084 */
6085 priv->regs = pci_iomap(pdev, 1, 0x10000);
6086 if (priv->regs == NULL) {
6087 priv->regs = pci_iomap(pdev, 2, 0x10000);
6088 if (priv->regs == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07006089 wiphy_err(hw->wiphy, "Cannot map device registers\n");
Alexey Khoroshilova2ca8ec2013-01-19 01:24:01 +04006090 rc = -EIO;
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02006091 goto err_iounmap;
6092 }
6093 }
6094
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08006095 /*
Brian Cavagnolo99020472010-11-12 17:23:52 -08006096 * Choose the initial fw image depending on user input. If a second
6097 * image is available, make it the alternative image that will be
6098 * loaded if the first one fails.
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08006099 */
Brian Cavagnolo99020472010-11-12 17:23:52 -08006100 init_completion(&priv->firmware_loading_complete);
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08006101 di = priv->device_info;
Brian Cavagnolo99020472010-11-12 17:23:52 -08006102 if (ap_mode_default && di->fw_image_ap) {
6103 priv->fw_pref = di->fw_image_ap;
6104 priv->fw_alt = di->fw_image_sta;
6105 } else if (!ap_mode_default && di->fw_image_sta) {
6106 priv->fw_pref = di->fw_image_sta;
6107 priv->fw_alt = di->fw_image_ap;
6108 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08006109 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08006110 priv->fw_pref = di->fw_image_sta;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08006111 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
6112 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08006113 priv->fw_pref = di->fw_image_ap;
6114 }
6115 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006116 if (rc)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08006117 goto err_stop_firmware;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05306118
6119 priv->hw_restart_in_progress = false;
6120
Yogesh Ashok Poware882efc2013-01-25 16:17:32 +05306121 priv->running_bsses = 0;
6122
Brian Cavagnolo99020472010-11-12 17:23:52 -08006123 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006124
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01006125err_stop_firmware:
6126 mwl8k_hw_reset(priv);
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01006127
6128err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006129 if (priv->regs != NULL)
6130 pci_iounmap(pdev, priv->regs);
6131
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02006132 if (priv->sram != NULL)
6133 pci_iounmap(pdev, priv->sram);
6134
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006135 ieee80211_free_hw(hw);
6136
6137err_free_reg:
6138 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01006139
6140err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006141 pci_disable_device(pdev);
6142
6143 return rc;
6144}
6145
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05006146static void mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006147{
6148 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
6149 struct mwl8k_priv *priv;
6150 int i;
6151
6152 if (hw == NULL)
6153 return;
6154 priv = hw->priv;
6155
Brian Cavagnolo99020472010-11-12 17:23:52 -08006156 wait_for_completion(&priv->firmware_loading_complete);
6157
6158 if (priv->fw_state == FW_STATE_ERROR) {
6159 mwl8k_hw_reset(priv);
6160 goto unmap;
6161 }
6162
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006163 ieee80211_stop_queues(hw);
6164
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02006165 ieee80211_unregister_hw(hw);
6166
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01006167 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01006168 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01006169 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006170
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006171 /* Stop hardware */
6172 mwl8k_hw_reset(priv);
6173
6174 /* Return all skbs to mac80211 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07006175 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01006176 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006177
Brian Cavagnoloe6007072011-03-17 11:58:44 -07006178 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006179 mwl8k_txq_deinit(hw, i);
6180
6181 mwl8k_rxq_deinit(hw, 0);
6182
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02006183 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006184
Brian Cavagnolo99020472010-11-12 17:23:52 -08006185unmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006186 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02006187 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006188 ieee80211_free_hw(hw);
6189 pci_release_regions(pdev);
6190 pci_disable_device(pdev);
6191}
6192
6193static struct pci_driver mwl8k_driver = {
6194 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02006195 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006196 .probe = mwl8k_probe,
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05006197 .remove = mwl8k_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006198};
6199
Axel Lin5b0a3b72012-04-14 10:38:36 +08006200module_pci_driver(mwl8k_driver);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02006201
6202MODULE_DESCRIPTION(MWL8K_DESC);
6203MODULE_VERSION(MWL8K_VERSION);
6204MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
6205MODULE_LICENSE("GPL");