blob: 19afd2cdacedb5378b717dd809233abc644012fc [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
12#include <linux/init.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000013#include <linux/interrupt.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010014#include <linux/module.h>
15#include <linux/kernel.h>
Lennert Buytenhek3d76e822009-10-22 20:20:16 +020016#include <linux/sched.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010017#include <linux/spinlock.h>
18#include <linux/list.h>
19#include <linux/pci.h>
20#include <linux/delay.h>
21#include <linux/completion.h>
22#include <linux/etherdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010024#include <net/mac80211.h>
25#include <linux/moduleparam.h>
26#include <linux/firmware.h>
27#include <linux/workqueue.h>
28
29#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
30#define MWL8K_NAME KBUILD_MODNAME
Yogesh Ashok Powar00e8e692011-12-20 11:39:29 +053031#define MWL8K_VERSION "0.13"
Lennert Buytenheka66098d2009-03-10 10:13:33 +010032
Brian Cavagnolo0863ade2010-11-12 17:23:50 -080033/* Module parameters */
Rusty Russelleb939922011-12-19 14:08:01 +000034static bool ap_mode_default;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -080035module_param(ap_mode_default, bool, 0);
36MODULE_PARM_DESC(ap_mode_default,
37 "Set to 1 to make ap mode the default instead of sta mode");
38
Lennert Buytenheka66098d2009-03-10 10:13:33 +010039/* Register definitions */
40#define MWL8K_HIU_GEN_PTR 0x00000c10
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020041#define MWL8K_MODE_STA 0x0000005a
42#define MWL8K_MODE_AP 0x000000a5
Lennert Buytenheka66098d2009-03-10 10:13:33 +010043#define MWL8K_HIU_INT_CODE 0x00000c14
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020044#define MWL8K_FWSTA_READY 0xf0f1f2f4
45#define MWL8K_FWAP_READY 0xf1f2f4a5
46#define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
Lennert Buytenheka66098d2009-03-10 10:13:33 +010047#define MWL8K_HIU_SCRATCH 0x00000c40
48
49/* Host->device communications */
50#define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
51#define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
52#define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
53#define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
54#define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020055#define MWL8K_H2A_INT_DUMMY (1 << 20)
56#define MWL8K_H2A_INT_RESET (1 << 15)
57#define MWL8K_H2A_INT_DOORBELL (1 << 1)
58#define MWL8K_H2A_INT_PPA_READY (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010059
60/* Device->host communications */
61#define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
62#define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
63#define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
64#define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
65#define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020066#define MWL8K_A2H_INT_DUMMY (1 << 20)
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -070067#define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020068#define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
69#define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
70#define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
71#define MWL8K_A2H_INT_RADIO_ON (1 << 6)
72#define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
73#define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
74#define MWL8K_A2H_INT_OPC_DONE (1 << 2)
75#define MWL8K_A2H_INT_RX_READY (1 << 1)
76#define MWL8K_A2H_INT_TX_DONE (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010077
Pradeep Nemavat566875d2011-04-21 16:34:57 +053078/* HW micro second timer register
79 * located at offset 0xA600. This
80 * will be used to timestamp tx
81 * packets.
82 */
83
84#define MWL8K_HW_TIMER_REGISTER 0x0000a600
85
Lennert Buytenheka66098d2009-03-10 10:13:33 +010086#define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
87 MWL8K_A2H_INT_CHNL_SWITCHED | \
88 MWL8K_A2H_INT_QUEUE_EMPTY | \
89 MWL8K_A2H_INT_RADAR_DETECT | \
90 MWL8K_A2H_INT_RADIO_ON | \
91 MWL8K_A2H_INT_RADIO_OFF | \
92 MWL8K_A2H_INT_MAC_EVENT | \
93 MWL8K_A2H_INT_OPC_DONE | \
94 MWL8K_A2H_INT_RX_READY | \
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -070095 MWL8K_A2H_INT_TX_DONE | \
96 MWL8K_A2H_INT_BA_WATCHDOG)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010097
Lennert Buytenheka66098d2009-03-10 10:13:33 +010098#define MWL8K_RX_QUEUES 1
Brian Cavagnoloe6007072011-03-17 11:58:44 -070099#define MWL8K_TX_WMM_QUEUES 4
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -0700100#define MWL8K_MAX_AMPDU_QUEUES 8
Brian Cavagnoloe6007072011-03-17 11:58:44 -0700101#define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
102#define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100103
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +0530104/* txpriorities are mapped with hw queues.
105 * Each hw queue has a txpriority.
106 */
107#define TOTAL_HW_TX_QUEUES 8
108
109/* Each HW queue can have one AMPDU stream.
110 * But, because one of the hw queue is reserved,
111 * maximum AMPDU queues that can be created are
112 * one short of total tx queues.
113 */
114#define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1)
115
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200116struct rxd_ops {
117 int rxd_size;
118 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
119 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100120 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -0400121 __le16 *qos, s8 *noise);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200122};
123
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200124struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200125 char *part_name;
126 char *helper_image;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800127 char *fw_image_sta;
128 char *fw_image_ap;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100129 struct rxd_ops *ap_rxd_ops;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -0800130 u32 fw_api_ap;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200131};
132
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100133struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200134 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100135
136 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200137 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100138
139 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200140 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100141
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200142 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200143 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200144 struct {
145 struct sk_buff *skb;
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +0900146 DEFINE_DMA_UNMAP_ADDR(dma);
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200147 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100148};
149
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100150struct mwl8k_tx_queue {
151 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200152 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100153
154 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200155 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100156
Kalle Valo8ccbc3b2010-02-07 10:20:52 +0200157 unsigned int len;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200158 struct mwl8k_tx_desc *txd;
159 dma_addr_t txd_dma;
160 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100161};
162
Brian Cavagnoloac109fd2011-03-17 11:58:45 -0700163enum {
164 AMPDU_NO_STREAM,
165 AMPDU_STREAM_NEW,
166 AMPDU_STREAM_IN_PROGRESS,
167 AMPDU_STREAM_ACTIVE,
168};
169
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700170struct mwl8k_ampdu_stream {
171 struct ieee80211_sta *sta;
172 u8 tid;
173 u8 state;
174 u8 idx;
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700175};
176
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100177struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100178 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100179 struct pci_dev *pdev;
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +0530180 int irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100181
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200182 struct mwl8k_device_info *device_info;
183
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100184 void __iomem *sram;
185 void __iomem *regs;
186
187 /* firmware */
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800188 const struct firmware *fw_helper;
189 const struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100190
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100191 /* hardware/firmware parameters */
192 bool ap_fw;
193 struct rxd_ops *rxd_ops;
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100194 struct ieee80211_supported_band band_24;
195 struct ieee80211_channel channels_24[14];
196 struct ieee80211_rate rates_24[14];
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100197 struct ieee80211_supported_band band_50;
198 struct ieee80211_channel channels_50[4];
199 struct ieee80211_rate rates_50[9];
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100200 u32 ap_macids_supported;
201 u32 sta_macids_supported;
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100202
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -0700203 /* Ampdu stream information */
204 u8 num_ampdu_queues;
Brian Cavagnoloac109fd2011-03-17 11:58:45 -0700205 spinlock_t stream_lock;
206 struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -0700207 struct work_struct watchdog_ba_handle;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -0700208
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200209 /* firmware access */
210 struct mutex fw_mutex;
211 struct task_struct *fw_mutex_owner;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +0530212 struct task_struct *hw_restart_owner;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200213 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200214 struct completion *hostcmd_wait;
215
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100216 /* lock held over TX and TX reap */
217 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100218
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200219 /* TX quiesce completion, protected by fw_mutex and tx_lock */
220 struct completion *tx_wait;
221
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100222 /* List of interfaces. */
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100223 u32 macids_used;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100224 struct list_head vif_list;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100225
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100226 /* power management status cookie from firmware */
227 u32 *cookie;
228 dma_addr_t cookie_dma;
229
230 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100231 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200232 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100233
234 /*
235 * Running count of TX packets in flight, to avoid
236 * iterating over the transmit rings each time.
237 */
238 int pending_tx_pkts;
239
240 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
Brian Cavagnoloe6007072011-03-17 11:58:44 -0700241 struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
242 u32 txq_offset[MWL8K_MAX_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100243
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200244 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200245 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200246 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200247 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100248
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100249 /* XXX need to convert this to handle multiple interfaces */
250 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200251 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100252 struct sk_buff *beacon_skb;
253
254 /*
255 * This FJ worker has to be global as it is scheduled from the
256 * RX handler. At this point we don't know which interface it
257 * belongs to until the list of bssids waiting to complete join
258 * is checked.
259 */
260 struct work_struct finalize_join_worker;
261
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100262 /* Tasklet to perform TX reclaim. */
263 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100264
265 /* Tasklet to perform RX. */
266 struct tasklet_struct poll_rx_task;
John W. Linville0d462bb2010-07-28 14:04:24 -0400267
268 /* Most recently reported noise in dBm */
269 s8 noise;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800270
271 /*
272 * preserve the queue configurations so they can be restored if/when
273 * the firmware image is swapped.
274 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -0700275 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
Brian Cavagnolo99020472010-11-12 17:23:52 -0800276
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +0530277 /* To perform the task of reloading the firmware */
278 struct work_struct fw_reload;
279 bool hw_restart_in_progress;
280
Brian Cavagnolo99020472010-11-12 17:23:52 -0800281 /* async firmware loading state */
282 unsigned fw_state;
283 char *fw_pref;
284 char *fw_alt;
285 struct completion firmware_loading_complete;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100286};
287
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800288#define MAX_WEP_KEY_LEN 13
289#define NUM_WEP_KEYS 4
290
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100291/* Per interface specific private data */
292struct mwl8k_vif {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100293 struct list_head list;
294 struct ieee80211_vif *vif;
295
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100296 /* Firmware macid for this vif. */
297 int macid;
298
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100299 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100300 u16 seqno;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800301
302 /* Saved WEP keys */
303 struct {
304 u8 enabled;
305 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
306 } wep_key_conf[NUM_WEP_KEYS];
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800307
308 /* BSSID */
309 u8 bssid[ETH_ALEN];
310
311 /* A flag to indicate is HW crypto is enabled for this bssid */
312 bool is_hw_crypto_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100313};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200314#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800315#define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100316
Brian Cavagnolod0805c12011-04-12 11:06:28 -0700317struct tx_traffic_info {
318 u32 start_time;
319 u32 pkts;
320};
321
322#define MWL8K_MAX_TID 8
Lennert Buytenheka6804002010-01-04 21:55:42 +0100323struct mwl8k_sta {
324 /* Index into station database. Returned by UPDATE_STADB. */
325 u8 peer_id;
Nishant Sarmukadam170335432011-03-17 11:58:48 -0700326 u8 is_ampdu_allowed;
Brian Cavagnolod0805c12011-04-12 11:06:28 -0700327 struct tx_traffic_info tx_stats[MWL8K_MAX_TID];
Lennert Buytenheka6804002010-01-04 21:55:42 +0100328};
329#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
330
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100331static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100332 { .center_freq = 2412, .hw_value = 1, },
333 { .center_freq = 2417, .hw_value = 2, },
334 { .center_freq = 2422, .hw_value = 3, },
335 { .center_freq = 2427, .hw_value = 4, },
336 { .center_freq = 2432, .hw_value = 5, },
337 { .center_freq = 2437, .hw_value = 6, },
338 { .center_freq = 2442, .hw_value = 7, },
339 { .center_freq = 2447, .hw_value = 8, },
340 { .center_freq = 2452, .hw_value = 9, },
341 { .center_freq = 2457, .hw_value = 10, },
342 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100343 { .center_freq = 2467, .hw_value = 12, },
344 { .center_freq = 2472, .hw_value = 13, },
345 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100346};
347
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100348static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100349 { .bitrate = 10, .hw_value = 2, },
350 { .bitrate = 20, .hw_value = 4, },
351 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200352 { .bitrate = 110, .hw_value = 22, },
353 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100354 { .bitrate = 60, .hw_value = 12, },
355 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100356 { .bitrate = 120, .hw_value = 24, },
357 { .bitrate = 180, .hw_value = 36, },
358 { .bitrate = 240, .hw_value = 48, },
359 { .bitrate = 360, .hw_value = 72, },
360 { .bitrate = 480, .hw_value = 96, },
361 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100362 { .bitrate = 720, .hw_value = 144, },
363};
364
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100365static const struct ieee80211_channel mwl8k_channels_50[] = {
366 { .center_freq = 5180, .hw_value = 36, },
367 { .center_freq = 5200, .hw_value = 40, },
368 { .center_freq = 5220, .hw_value = 44, },
369 { .center_freq = 5240, .hw_value = 48, },
370};
371
372static const struct ieee80211_rate mwl8k_rates_50[] = {
373 { .bitrate = 60, .hw_value = 12, },
374 { .bitrate = 90, .hw_value = 18, },
375 { .bitrate = 120, .hw_value = 24, },
376 { .bitrate = 180, .hw_value = 36, },
377 { .bitrate = 240, .hw_value = 48, },
378 { .bitrate = 360, .hw_value = 72, },
379 { .bitrate = 480, .hw_value = 96, },
380 { .bitrate = 540, .hw_value = 108, },
381 { .bitrate = 720, .hw_value = 144, },
382};
383
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100384/* Set or get info from Firmware */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100385#define MWL8K_CMD_GET 0x0000
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800386#define MWL8K_CMD_SET 0x0001
387#define MWL8K_CMD_SET_LIST 0x0002
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100388
389/* Firmware command codes */
390#define MWL8K_CMD_CODE_DNLD 0x0001
391#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200392#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100393#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
394#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200395#define MWL8K_CMD_RADIO_CONTROL 0x001c
396#define MWL8K_CMD_RF_TX_POWER 0x001e
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800397#define MWL8K_CMD_TX_POWER 0x001f
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200398#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100399#define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100400#define MWL8K_CMD_SET_PRE_SCAN 0x0107
401#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200402#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100403#define MWL8K_CMD_SET_AID 0x010d
404#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200405#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100406#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200407#define MWL8K_CMD_SET_SLOT 0x0114
408#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
409#define MWL8K_CMD_SET_WMM_MODE 0x0123
410#define MWL8K_CMD_MIMO_CONFIG 0x0125
411#define MWL8K_CMD_USE_FIXED_RATE 0x0126
412#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100413#define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200414#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -0700415#define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +0530416#define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100417#define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
418#define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800419#define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200420#define MWL8K_CMD_UPDATE_STADB 0x1123
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700421#define MWL8K_CMD_BASTREAM 0x1125
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100422
John W. Linvilleb6037422010-07-20 13:55:00 -0400423static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100424{
John W. Linvilleb6037422010-07-20 13:55:00 -0400425 u16 command = le16_to_cpu(cmd);
426
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100427#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
428 snprintf(buf, bufsize, "%s", #x);\
429 return buf;\
430 } while (0)
John W. Linvilleb6037422010-07-20 13:55:00 -0400431 switch (command & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100432 MWL8K_CMDNAME(CODE_DNLD);
433 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200434 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100435 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
436 MWL8K_CMDNAME(GET_STAT);
437 MWL8K_CMDNAME(RADIO_CONTROL);
438 MWL8K_CMDNAME(RF_TX_POWER);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800439 MWL8K_CMDNAME(TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200440 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100441 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100442 MWL8K_CMDNAME(SET_PRE_SCAN);
443 MWL8K_CMDNAME(SET_POST_SCAN);
444 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100445 MWL8K_CMDNAME(SET_AID);
446 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200447 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100448 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200449 MWL8K_CMDNAME(SET_SLOT);
450 MWL8K_CMDNAME(SET_EDCA_PARAMS);
451 MWL8K_CMDNAME(SET_WMM_MODE);
452 MWL8K_CMDNAME(MIMO_CONFIG);
453 MWL8K_CMDNAME(USE_FIXED_RATE);
454 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200455 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200456 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100457 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100458 MWL8K_CMDNAME(SET_NEW_STN);
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800459 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200460 MWL8K_CMDNAME(UPDATE_STADB);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700461 MWL8K_CMDNAME(BASTREAM);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -0700462 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100463 default:
464 snprintf(buf, bufsize, "0x%x", cmd);
465 }
466#undef MWL8K_CMDNAME
467
468 return buf;
469}
470
471/* Hardware and firmware reset */
472static void mwl8k_hw_reset(struct mwl8k_priv *priv)
473{
474 iowrite32(MWL8K_H2A_INT_RESET,
475 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
476 iowrite32(MWL8K_H2A_INT_RESET,
477 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
478 msleep(20);
479}
480
481/* Release fw image */
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800482static void mwl8k_release_fw(const struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100483{
484 if (*fw == NULL)
485 return;
486 release_firmware(*fw);
487 *fw = NULL;
488}
489
490static void mwl8k_release_firmware(struct mwl8k_priv *priv)
491{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100492 mwl8k_release_fw(&priv->fw_ucode);
493 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100494}
495
Brian Cavagnolo99020472010-11-12 17:23:52 -0800496/* states for asynchronous f/w loading */
497static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
498enum {
499 FW_STATE_INIT = 0,
500 FW_STATE_LOADING_PREF,
501 FW_STATE_LOADING_ALT,
502 FW_STATE_ERROR,
503};
504
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100505/* Request fw image */
506static int mwl8k_request_fw(struct mwl8k_priv *priv,
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800507 const char *fname, const struct firmware **fw,
Brian Cavagnolo99020472010-11-12 17:23:52 -0800508 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100509{
510 /* release current image */
511 if (*fw != NULL)
512 mwl8k_release_fw(fw);
513
Brian Cavagnolo99020472010-11-12 17:23:52 -0800514 if (nowait)
515 return request_firmware_nowait(THIS_MODULE, 1, fname,
516 &priv->pdev->dev, GFP_KERNEL,
517 priv, mwl8k_fw_state_machine);
518 else
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800519 return request_firmware(fw, fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100520}
521
Brian Cavagnolo99020472010-11-12 17:23:52 -0800522static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
523 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100524{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200525 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100526 int rc;
527
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200528 if (di->helper_image != NULL) {
Brian Cavagnolo99020472010-11-12 17:23:52 -0800529 if (nowait)
530 rc = mwl8k_request_fw(priv, di->helper_image,
531 &priv->fw_helper, true);
532 else
533 rc = mwl8k_request_fw(priv, di->helper_image,
534 &priv->fw_helper, false);
535 if (rc)
536 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
537 pci_name(priv->pdev), di->helper_image);
538
539 if (rc || nowait)
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200540 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100541 }
542
Brian Cavagnolo99020472010-11-12 17:23:52 -0800543 if (nowait) {
544 /*
545 * if we get here, no helper image is needed. Skip the
546 * FW_STATE_INIT state.
547 */
548 priv->fw_state = FW_STATE_LOADING_PREF;
549 rc = mwl8k_request_fw(priv, fw_image,
550 &priv->fw_ucode,
551 true);
552 } else
553 rc = mwl8k_request_fw(priv, fw_image,
554 &priv->fw_ucode, false);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100555 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200556 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800557 pci_name(priv->pdev), fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100558 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100559 return rc;
560 }
561
562 return 0;
563}
564
565struct mwl8k_cmd_pkt {
566 __le16 code;
567 __le16 length;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100568 __u8 seq_num;
569 __u8 macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100570 __le16 result;
571 char payload[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000572} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100573
574/*
575 * Firmware loading.
576 */
577static int
578mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
579{
580 void __iomem *regs = priv->regs;
581 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100582 int loops;
583
584 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
585 if (pci_dma_mapping_error(priv->pdev, dma_addr))
586 return -ENOMEM;
587
588 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
589 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
590 iowrite32(MWL8K_H2A_INT_DOORBELL,
591 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
592 iowrite32(MWL8K_H2A_INT_DUMMY,
593 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
594
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100595 loops = 1000;
596 do {
597 u32 int_code;
598
599 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
600 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
601 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100602 break;
603 }
604
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200605 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100606 udelay(1);
607 } while (--loops);
608
609 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
610
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200611 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100612}
613
614static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
615 const u8 *data, size_t length)
616{
617 struct mwl8k_cmd_pkt *cmd;
618 int done;
619 int rc = 0;
620
621 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
622 if (cmd == NULL)
623 return -ENOMEM;
624
625 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
626 cmd->seq_num = 0;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100627 cmd->macid = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100628 cmd->result = 0;
629
630 done = 0;
631 while (length) {
632 int block_size = length > 256 ? 256 : length;
633
634 memcpy(cmd->payload, data + done, block_size);
635 cmd->length = cpu_to_le16(block_size);
636
637 rc = mwl8k_send_fw_load_cmd(priv, cmd,
638 sizeof(*cmd) + block_size);
639 if (rc)
640 break;
641
642 done += block_size;
643 length -= block_size;
644 }
645
646 if (!rc) {
647 cmd->length = 0;
648 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
649 }
650
651 kfree(cmd);
652
653 return rc;
654}
655
656static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
657 const u8 *data, size_t length)
658{
659 unsigned char *buffer;
660 int may_continue, rc = 0;
661 u32 done, prev_block_size;
662
663 buffer = kmalloc(1024, GFP_KERNEL);
664 if (buffer == NULL)
665 return -ENOMEM;
666
667 done = 0;
668 prev_block_size = 0;
669 may_continue = 1000;
670 while (may_continue > 0) {
671 u32 block_size;
672
673 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
674 if (block_size & 1) {
675 block_size &= ~1;
676 may_continue--;
677 } else {
678 done += prev_block_size;
679 length -= prev_block_size;
680 }
681
682 if (block_size > 1024 || block_size > length) {
683 rc = -EOVERFLOW;
684 break;
685 }
686
687 if (length == 0) {
688 rc = 0;
689 break;
690 }
691
692 if (block_size == 0) {
693 rc = -EPROTO;
694 may_continue--;
695 udelay(1);
696 continue;
697 }
698
699 prev_block_size = block_size;
700 memcpy(buffer, data + done, block_size);
701
702 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
703 if (rc)
704 break;
705 }
706
707 if (!rc && length != 0)
708 rc = -EREMOTEIO;
709
710 kfree(buffer);
711
712 return rc;
713}
714
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200715static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100716{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200717 struct mwl8k_priv *priv = hw->priv;
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800718 const struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200719 int rc;
720 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100721
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200722 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800723 const struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100724
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200725 if (helper == NULL) {
726 printk(KERN_ERR "%s: helper image needed but none "
727 "given\n", pci_name(priv->pdev));
728 return -EINVAL;
729 }
730
731 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100732 if (rc) {
733 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200734 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100735 return rc;
736 }
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +0530737 msleep(20);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100738
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200739 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100740 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200741 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100742 }
743
744 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200745 printk(KERN_ERR "%s: unable to load firmware image\n",
746 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100747 return rc;
748 }
749
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100750 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100751
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100752 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100753 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200754 u32 ready_code;
755
756 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
757 if (ready_code == MWL8K_FWAP_READY) {
Rusty Russell3db1cd52011-12-19 13:56:45 +0000758 priv->ap_fw = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100759 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200760 } else if (ready_code == MWL8K_FWSTA_READY) {
Rusty Russell3db1cd52011-12-19 13:56:45 +0000761 priv->ap_fw = false;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200762 break;
763 }
764
765 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100766 udelay(1);
767 } while (--loops);
768
769 return loops ? 0 : -ETIMEDOUT;
770}
771
772
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100773/* DMA header used by firmware and hardware. */
774struct mwl8k_dma_data {
775 __le16 fwlen;
776 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100777 char data[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000778} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100779
780/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100781static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100782{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100783 struct mwl8k_dma_data *tr;
784 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100785
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100786 tr = (struct mwl8k_dma_data *)skb->data;
787 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
788
789 if (hdrlen != sizeof(tr->wh)) {
790 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
791 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
792 *((__le16 *)(tr->data - 2)) = qos;
793 } else {
794 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
795 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100796 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100797
798 if (hdrlen != sizeof(*tr))
799 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100800}
801
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530802#define REDUCED_TX_HEADROOM 8
803
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800804static void
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530805mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb,
806 int head_pad, int tail_pad)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100807{
808 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100809 int hdrlen;
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800810 int reqd_hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100811 struct mwl8k_dma_data *tr;
812
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100813 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100814 * Add a firmware DMA header; the firmware requires that we
815 * present a 2-byte payload length followed by a 4-address
816 * header (without QoS field), followed (optionally) by any
817 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100818 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100819 wh = (struct ieee80211_hdr *)skb->data;
820
821 hdrlen = ieee80211_hdrlen(wh->frame_control);
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530822
823 /*
824 * Check if skb_resize is required because of
825 * tx_headroom adjustment.
826 */
827 if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts)
828 + REDUCED_TX_HEADROOM))) {
829 if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) {
830
831 wiphy_err(priv->hw->wiphy,
832 "Failed to reallocate TX buffer\n");
833 return;
834 }
835 skb->truesize += REDUCED_TX_HEADROOM;
836 }
837
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530838 reqd_hdrlen = sizeof(*tr) + head_pad;
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800839
840 if (hdrlen != reqd_hdrlen)
841 skb_push(skb, reqd_hdrlen - hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100842
843 if (ieee80211_is_data_qos(wh->frame_control))
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800844 hdrlen -= IEEE80211_QOS_CTL_LEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100845
846 tr = (struct mwl8k_dma_data *)skb->data;
847 if (wh != &tr->wh)
848 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100849 if (hdrlen != sizeof(tr->wh))
850 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100851
852 /*
853 * Firmware length is the length of the fully formed "802.11
854 * payload". That is, everything except for the 802.11 header.
855 * This includes all crypto material including the MIC.
856 */
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800857 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100858}
859
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530860static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv,
861 struct sk_buff *skb)
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800862{
863 struct ieee80211_hdr *wh;
864 struct ieee80211_tx_info *tx_info;
865 struct ieee80211_key_conf *key_conf;
866 int data_pad;
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530867 int head_pad = 0;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800868
869 wh = (struct ieee80211_hdr *)skb->data;
870
871 tx_info = IEEE80211_SKB_CB(skb);
872
873 key_conf = NULL;
874 if (ieee80211_is_data(wh->frame_control))
875 key_conf = tx_info->control.hw_key;
876
877 /*
878 * Make sure the packet header is in the DMA header format (4-address
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530879 * without QoS), and add head & tail padding when HW crypto is enabled.
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800880 *
881 * We have the following trailer padding requirements:
882 * - WEP: 4 trailer bytes (ICV)
883 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
884 * - CCMP: 8 trailer bytes (MIC)
885 */
886 data_pad = 0;
887 if (key_conf != NULL) {
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530888 head_pad = key_conf->iv_len;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800889 switch (key_conf->cipher) {
890 case WLAN_CIPHER_SUITE_WEP40:
891 case WLAN_CIPHER_SUITE_WEP104:
892 data_pad = 4;
893 break;
894 case WLAN_CIPHER_SUITE_TKIP:
895 data_pad = 12;
896 break;
897 case WLAN_CIPHER_SUITE_CCMP:
898 data_pad = 8;
899 break;
900 }
901 }
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530902 mwl8k_add_dma_header(priv, skb, head_pad, data_pad);
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800903}
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100904
905/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100906 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200907 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100908struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200909 __le16 pkt_len;
910 __u8 sq2;
911 __u8 rate;
912 __le32 pkt_phys_addr;
913 __le32 next_rxd_phys_addr;
914 __le16 qos_control;
915 __le16 htsig2;
916 __le32 hw_rssi_info;
917 __le32 hw_noise_floor_info;
918 __u8 noise_floor;
919 __u8 pad0[3];
920 __u8 rssi;
921 __u8 rx_status;
922 __u8 channel;
923 __u8 rx_ctrl;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000924} __packed;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200925
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100926#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
927#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
928#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100929
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100930#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200931
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800932/* 8366 AP rx_status bits */
933#define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
934#define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
935#define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
936#define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
937#define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
938
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100939static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200940{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100941 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200942
943 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100944 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200945}
946
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100947static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200948{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100949 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200950
951 rxd->pkt_len = cpu_to_le16(len);
952 rxd->pkt_phys_addr = cpu_to_le32(addr);
953 wmb();
954 rxd->rx_ctrl = 0;
955}
956
957static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100958mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -0400959 __le16 *qos, s8 *noise)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200960{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100961 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200962
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100963 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200964 return -1;
965 rmb();
966
967 memset(status, 0, sizeof(*status));
968
969 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -0400970 *noise = -rxd->noise_floor;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200971
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100972 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200973 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100974 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100975 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100976 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200977 } else {
978 int i;
979
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100980 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
981 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200982 status->rate_idx = i;
983 break;
984 }
985 }
986 }
987
Lennert Buytenhek85478342010-01-12 13:48:56 +0100988 if (rxd->channel > 14) {
989 status->band = IEEE80211_BAND_5GHZ;
990 if (!(status->flag & RX_FLAG_HT))
991 status->rate_idx -= 5;
992 } else {
993 status->band = IEEE80211_BAND_2GHZ;
994 }
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900995 status->freq = ieee80211_channel_to_frequency(rxd->channel,
996 status->band);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200997
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100998 *qos = rxd->qos_control;
999
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001000 if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
1001 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) &&
1002 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
1003 status->flag |= RX_FLAG_MMIC_ERROR;
1004
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02001005 return le16_to_cpu(rxd->pkt_len);
1006}
1007
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001008static struct rxd_ops rxd_8366_ap_ops = {
1009 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
1010 .rxd_init = mwl8k_rxd_8366_ap_init,
1011 .rxd_refill = mwl8k_rxd_8366_ap_refill,
1012 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02001013};
1014
1015/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001016 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001017 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001018struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001019 __le16 pkt_len;
1020 __u8 link_quality;
1021 __u8 noise_level;
1022 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001023 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001024 __le16 qos_control;
1025 __le16 rate_info;
1026 __le32 pad0[4];
1027 __u8 rssi;
1028 __u8 channel;
1029 __le16 pad1;
1030 __u8 rx_ctrl;
1031 __u8 rx_status;
1032 __u8 pad2[2];
Eric Dumazetba2d3582010-06-02 18:10:09 +00001033} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001034
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001035#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
1036#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
1037#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
1038#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
1039#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
1040#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001041
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001042#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001043#define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
1044/* ICV=0 or MIC=1 */
1045#define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
1046/* Key is uploaded only in failure case */
1047#define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001048
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001049static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001050{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001051 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001052
1053 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001054 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001055}
1056
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001057static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001058{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001059 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001060
1061 rxd->pkt_len = cpu_to_le16(len);
1062 rxd->pkt_phys_addr = cpu_to_le32(addr);
1063 wmb();
1064 rxd->rx_ctrl = 0;
1065}
1066
1067static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001068mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -04001069 __le16 *qos, s8 *noise)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001070{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001071 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001072 u16 rate_info;
1073
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001074 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001075 return -1;
1076 rmb();
1077
1078 rate_info = le16_to_cpu(rxd->rate_info);
1079
1080 memset(status, 0, sizeof(*status));
1081
1082 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -04001083 *noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001084 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
1085 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001086
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001087 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001088 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001089 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001090 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001091 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001092 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001093 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001094 status->flag |= RX_FLAG_HT;
1095
Lennert Buytenhek85478342010-01-12 13:48:56 +01001096 if (rxd->channel > 14) {
1097 status->band = IEEE80211_BAND_5GHZ;
1098 if (!(status->flag & RX_FLAG_HT))
1099 status->rate_idx -= 5;
1100 } else {
1101 status->band = IEEE80211_BAND_2GHZ;
1102 }
Bruno Randolf59eb21a2011-01-17 13:37:28 +09001103 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1104 status->band);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001105
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001106 *qos = rxd->qos_control;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001107 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1108 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1109 status->flag |= RX_FLAG_MMIC_ERROR;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001110
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001111 return le16_to_cpu(rxd->pkt_len);
1112}
1113
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001114static struct rxd_ops rxd_sta_ops = {
1115 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1116 .rxd_init = mwl8k_rxd_sta_init,
1117 .rxd_refill = mwl8k_rxd_sta_refill,
1118 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001119};
1120
1121
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001122#define MWL8K_RX_DESCS 256
1123#define MWL8K_RX_MAXSZ 3800
1124
1125static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1126{
1127 struct mwl8k_priv *priv = hw->priv;
1128 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1129 int size;
1130 int i;
1131
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001132 rxq->rxd_count = 0;
1133 rxq->head = 0;
1134 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001135
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001136 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001137
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001138 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1139 if (rxq->rxd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001140 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001141 return -ENOMEM;
1142 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001143 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001144
Shan Weib9ede5f2011-03-08 11:02:03 +08001145 rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001146 if (rxq->buf == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001147 wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001148 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001149 return -ENOMEM;
1150 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001151
1152 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001153 int desc_size;
1154 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001155 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001156 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001157
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001158 desc_size = priv->rxd_ops->rxd_size;
1159 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001160
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001161 nexti = i + 1;
1162 if (nexti == MWL8K_RX_DESCS)
1163 nexti = 0;
1164 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1165
1166 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001167 }
1168
1169 return 0;
1170}
1171
1172static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1173{
1174 struct mwl8k_priv *priv = hw->priv;
1175 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1176 int refilled;
1177
1178 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001179 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001180 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001181 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001182 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001183 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001184
1185 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1186 if (skb == NULL)
1187 break;
1188
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001189 addr = pci_map_single(priv->pdev, skb->data,
1190 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001191
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001192 rxq->rxd_count++;
1193 rx = rxq->tail++;
1194 if (rxq->tail == MWL8K_RX_DESCS)
1195 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001196 rxq->buf[rx].skb = skb;
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001197 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001198
1199 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1200 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001201
1202 refilled++;
1203 }
1204
1205 return refilled;
1206}
1207
1208/* Must be called only when the card's reception is completely halted */
1209static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1210{
1211 struct mwl8k_priv *priv = hw->priv;
1212 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1213 int i;
1214
Brian Cavagnolo73b46322011-03-17 11:58:41 -07001215 if (rxq->rxd == NULL)
1216 return;
1217
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001218 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001219 if (rxq->buf[i].skb != NULL) {
1220 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001221 dma_unmap_addr(&rxq->buf[i], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001222 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001223 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001224
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001225 kfree_skb(rxq->buf[i].skb);
1226 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001227 }
1228 }
1229
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001230 kfree(rxq->buf);
1231 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001232
1233 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001234 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001235 rxq->rxd, rxq->rxd_dma);
1236 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001237}
1238
1239
1240/*
1241 * Scan a list of BSSIDs to process for finalize join.
1242 * Allows for extension to process multiple BSSIDs.
1243 */
1244static inline int
1245mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1246{
1247 return priv->capture_beacon &&
1248 ieee80211_is_beacon(wh->frame_control) &&
Joe Perches2e42e472012-05-09 17:17:46 +00001249 ether_addr_equal(wh->addr3, priv->capture_bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001250}
1251
Lennert Buytenhek37797522009-10-22 20:19:45 +02001252static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1253 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001254{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001255 struct mwl8k_priv *priv = hw->priv;
1256
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001257 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001258 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001259
1260 /*
1261 * Use GFP_ATOMIC as rxq_process is called from
1262 * the primary interrupt handler, memory allocation call
1263 * must not sleep.
1264 */
1265 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1266 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001267 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001268}
1269
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001270static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1271 u8 *bssid)
1272{
1273 struct mwl8k_vif *mwl8k_vif;
1274
1275 list_for_each_entry(mwl8k_vif,
1276 vif_list, list) {
1277 if (memcmp(bssid, mwl8k_vif->bssid,
1278 ETH_ALEN) == 0)
1279 return mwl8k_vif;
1280 }
1281
1282 return NULL;
1283}
1284
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001285static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1286{
1287 struct mwl8k_priv *priv = hw->priv;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001288 struct mwl8k_vif *mwl8k_vif = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001289 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1290 int processed;
1291
1292 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001293 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001294 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001295 void *rxd;
1296 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001297 struct ieee80211_rx_status status;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001298 struct ieee80211_hdr *wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001299 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001300
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001301 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001302 if (skb == NULL)
1303 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001304
1305 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1306
John W. Linville0d462bb2010-07-28 14:04:24 -04001307 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1308 &priv->noise);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001309 if (pkt_len < 0)
1310 break;
1311
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001312 rxq->buf[rxq->head].skb = NULL;
1313
1314 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001315 dma_unmap_addr(&rxq->buf[rxq->head], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001316 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001317 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001318
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001319 rxq->head++;
1320 if (rxq->head == MWL8K_RX_DESCS)
1321 rxq->head = 0;
1322
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001323 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001324
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001325 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001326
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001327 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001328 * Check for a pending join operation. Save a
1329 * copy of the beacon and schedule a tasklet to
1330 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001331 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001332 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001333 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001334
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001335 if (ieee80211_has_protected(wh->frame_control)) {
1336
1337 /* Check if hw crypto has been enabled for
1338 * this bss. If yes, set the status flags
1339 * accordingly
1340 */
1341 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1342 wh->addr1);
1343
1344 if (mwl8k_vif != NULL &&
Joe Perches23677ce2012-02-09 11:17:23 +00001345 mwl8k_vif->is_hw_crypto_enabled) {
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001346 /*
1347 * When MMIC ERROR is encountered
1348 * by the firmware, payload is
1349 * dropped and only 32 bytes of
1350 * mwl8k Firmware header is sent
1351 * to the host.
1352 *
1353 * We need to add four bytes of
1354 * key information. In it
1355 * MAC80211 expects keyidx set to
1356 * 0 for triggering Counter
1357 * Measure of MMIC failure.
1358 */
1359 if (status.flag & RX_FLAG_MMIC_ERROR) {
1360 struct mwl8k_dma_data *tr;
1361 tr = (struct mwl8k_dma_data *)skb->data;
1362 memset((void *)&(tr->data), 0, 4);
1363 pkt_len += 4;
1364 }
1365
1366 if (!ieee80211_is_auth(wh->frame_control))
1367 status.flag |= RX_FLAG_IV_STRIPPED |
1368 RX_FLAG_DECRYPTED |
1369 RX_FLAG_MMIC_STRIPPED;
1370 }
1371 }
1372
1373 skb_put(skb, pkt_len);
1374 mwl8k_remove_dma_header(skb, qos);
Johannes Bergf1d58c22009-06-17 13:13:00 +02001375 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1376 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001377
1378 processed++;
1379 }
1380
1381 return processed;
1382}
1383
1384
1385/*
1386 * Packet transmission.
1387 */
1388
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001389#define MWL8K_TXD_STATUS_OK 0x00000001
1390#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1391#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1392#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001393#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001394
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001395#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1396#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1397#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1398#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1399#define MWL8K_QOS_EOSP 0x0010
1400
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001401struct mwl8k_tx_desc {
1402 __le32 status;
1403 __u8 data_rate;
1404 __u8 tx_priority;
1405 __le16 qos_control;
1406 __le32 pkt_phys_addr;
1407 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001408 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001409 __le32 next_txd_phys_addr;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07001410 __le32 timestamp;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001411 __le16 rate_info;
1412 __u8 peer_id;
Brian Cavagnoloa1fe24b2010-11-12 17:23:47 -08001413 __u8 tx_frag_cnt;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001414} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001415
1416#define MWL8K_TX_DESCS 128
1417
1418static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1419{
1420 struct mwl8k_priv *priv = hw->priv;
1421 struct mwl8k_tx_queue *txq = priv->txq + index;
1422 int size;
1423 int i;
1424
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001425 txq->len = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001426 txq->head = 0;
1427 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001428
1429 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1430
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001431 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1432 if (txq->txd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001433 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001434 return -ENOMEM;
1435 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001436 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001437
Shan Weib9ede5f2011-03-08 11:02:03 +08001438 txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001439 if (txq->skb == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001440 wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001441 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001442 return -ENOMEM;
1443 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001444
1445 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1446 struct mwl8k_tx_desc *tx_desc;
1447 int nexti;
1448
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001449 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001450 nexti = (i + 1) % MWL8K_TX_DESCS;
1451
1452 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001453 tx_desc->next_txd_phys_addr =
1454 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001455 }
1456
1457 return 0;
1458}
1459
1460static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1461{
1462 iowrite32(MWL8K_H2A_INT_PPA_READY,
1463 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1464 iowrite32(MWL8K_H2A_INT_DUMMY,
1465 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1466 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1467}
1468
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001469static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001470{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001471 struct mwl8k_priv *priv = hw->priv;
1472 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001473
Brian Cavagnoloe6007072011-03-17 11:58:44 -07001474 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001475 struct mwl8k_tx_queue *txq = priv->txq + i;
1476 int fw_owned = 0;
1477 int drv_owned = 0;
1478 int unused = 0;
1479 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001480
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001481 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001482 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1483 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001484
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001485 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001486 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001487 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001488 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001489 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001490
1491 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001492 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001493 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001494
Joe Perchesc96c31e2010-07-26 14:39:58 -07001495 wiphy_err(hw->wiphy,
1496 "txq[%d] len=%d head=%d tail=%d "
1497 "fw_owned=%d drv_owned=%d unused=%d\n",
1498 i,
1499 txq->len, txq->head, txq->tail,
1500 fw_owned, drv_owned, unused);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001501 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001502}
1503
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001504/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001505 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001506 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001507#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001508
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001509static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001510{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001511 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001512 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001513 int retry;
1514 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001515
1516 might_sleep();
1517
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05301518 /* Since fw restart is in progress, allow only the firmware
1519 * commands from the restart code and block the other
1520 * commands since they are going to fail in any case since
1521 * the firmware has crashed
1522 */
1523 if (priv->hw_restart_in_progress) {
1524 if (priv->hw_restart_owner == current)
1525 return 0;
1526 else
1527 return -EBUSY;
1528 }
1529
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001530 /*
1531 * The TX queues are stopped at this point, so this test
1532 * doesn't need to take ->tx_lock.
1533 */
1534 if (!priv->pending_tx_pkts)
1535 return 0;
1536
1537 retry = 0;
1538 rc = 0;
1539
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001540 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001541 priv->tx_wait = &tx_wait;
1542 while (!rc) {
1543 int oldcount;
1544 unsigned long timeout;
1545
1546 oldcount = priv->pending_tx_pkts;
1547
1548 spin_unlock_bh(&priv->tx_lock);
1549 timeout = wait_for_completion_timeout(&tx_wait,
1550 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1551 spin_lock_bh(&priv->tx_lock);
1552
1553 if (timeout) {
1554 WARN_ON(priv->pending_tx_pkts);
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301555 if (retry)
Joe Perchesc96c31e2010-07-26 14:39:58 -07001556 wiphy_notice(hw->wiphy, "tx rings drained\n");
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001557 break;
1558 }
1559
1560 if (priv->pending_tx_pkts < oldcount) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001561 wiphy_notice(hw->wiphy,
1562 "waiting for tx rings to drain (%d -> %d pkts)\n",
1563 oldcount, priv->pending_tx_pkts);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001564 retry = 1;
1565 continue;
1566 }
1567
1568 priv->tx_wait = NULL;
1569
Joe Perchesc96c31e2010-07-26 14:39:58 -07001570 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1571 MWL8K_TX_WAIT_TIMEOUT_MS);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001572 mwl8k_dump_tx_rings(hw);
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05301573 priv->hw_restart_in_progress = true;
1574 ieee80211_queue_work(hw, &priv->fw_reload);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001575
1576 rc = -ETIMEDOUT;
1577 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001578 spin_unlock_bh(&priv->tx_lock);
1579
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001580 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001581}
1582
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001583#define MWL8K_TXD_SUCCESS(status) \
1584 ((status) & (MWL8K_TXD_STATUS_OK | \
1585 MWL8K_TXD_STATUS_OK_RETRY | \
1586 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001587
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001588static int mwl8k_tid_queue_mapping(u8 tid)
1589{
1590 BUG_ON(tid > 7);
1591
1592 switch (tid) {
1593 case 0:
1594 case 3:
1595 return IEEE80211_AC_BE;
1596 break;
1597 case 1:
1598 case 2:
1599 return IEEE80211_AC_BK;
1600 break;
1601 case 4:
1602 case 5:
1603 return IEEE80211_AC_VI;
1604 break;
1605 case 6:
1606 case 7:
1607 return IEEE80211_AC_VO;
1608 break;
1609 default:
1610 return -1;
1611 break;
1612 }
1613}
1614
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001615/* The firmware will fill in the rate information
1616 * for each packet that gets queued in the hardware
John W. Linville49adc5c2011-04-27 15:04:28 -04001617 * and these macros will interpret that info.
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001618 */
1619
John W. Linville49adc5c2011-04-27 15:04:28 -04001620#define RI_FORMAT(a) (a & 0x0001)
1621#define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001622
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001623static int
1624mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001625{
1626 struct mwl8k_priv *priv = hw->priv;
1627 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001628 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001629
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001630 processed = 0;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001631 while (txq->len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001632 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001633 struct mwl8k_tx_desc *tx_desc;
1634 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001635 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001636 struct sk_buff *skb;
1637 struct ieee80211_tx_info *info;
1638 u32 status;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001639 struct ieee80211_sta *sta;
1640 struct mwl8k_sta *sta_info = NULL;
1641 u16 rate_info;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001642 struct ieee80211_hdr *wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001643
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001644 tx = txq->head;
1645 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001646
1647 status = le32_to_cpu(tx_desc->status);
1648
1649 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1650 if (!force)
1651 break;
1652 tx_desc->status &=
1653 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1654 }
1655
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001656 txq->head = (tx + 1) % MWL8K_TX_DESCS;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001657 BUG_ON(txq->len == 0);
1658 txq->len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001659 priv->pending_tx_pkts--;
1660
1661 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001662 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001663 skb = txq->skb[tx];
1664 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001665
1666 BUG_ON(skb == NULL);
1667 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1668
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001669 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001670
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001671 wh = (struct ieee80211_hdr *) skb->data;
1672
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001673 /* Mark descriptor as unused */
1674 tx_desc->pkt_phys_addr = 0;
1675 tx_desc->pkt_len = 0;
1676
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001677 info = IEEE80211_SKB_CB(skb);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001678 if (ieee80211_is_data(wh->frame_control)) {
Thomas Huehn89e11802012-07-11 13:21:41 +02001679 rcu_read_lock();
1680 sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
1681 wh->addr2);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001682 if (sta) {
1683 sta_info = MWL8K_STA(sta);
1684 BUG_ON(sta_info == NULL);
1685 rate_info = le16_to_cpu(tx_desc->rate_info);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001686 /* If rate is < 6.5 Mpbs for an ht station
1687 * do not form an ampdu. If the station is a
1688 * legacy station (format = 0), do not form an
1689 * ampdu
1690 */
John W. Linville49adc5c2011-04-27 15:04:28 -04001691 if (RI_RATE_ID_MCS(rate_info) < 1 ||
1692 RI_FORMAT(rate_info) == 0) {
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001693 sta_info->is_ampdu_allowed = false;
1694 } else {
1695 sta_info->is_ampdu_allowed = true;
1696 }
1697 }
Thomas Huehn89e11802012-07-11 13:21:41 +02001698 rcu_read_unlock();
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001699 }
1700
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001701 ieee80211_tx_info_clear_status(info);
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08001702
1703 /* Rate control is happening in the firmware.
1704 * Ensure no tx rate is being reported.
1705 */
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301706 info->status.rates[0].idx = -1;
1707 info->status.rates[0].count = 1;
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08001708
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001709 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001710 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001711
1712 ieee80211_tx_status_irqsafe(hw, skb);
1713
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001714 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001715 }
1716
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001717 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001718}
1719
1720/* must be called only when the card's transmit is completely halted */
1721static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1722{
1723 struct mwl8k_priv *priv = hw->priv;
1724 struct mwl8k_tx_queue *txq = priv->txq + index;
1725
Brian Cavagnolo73b46322011-03-17 11:58:41 -07001726 if (txq->txd == NULL)
1727 return;
1728
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001729 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001730
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001731 kfree(txq->skb);
1732 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001733
1734 pci_free_consistent(priv->pdev,
1735 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001736 txq->txd, txq->txd_dma);
1737 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001738}
1739
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001740/* caller must hold priv->stream_lock when calling the stream functions */
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301741static struct mwl8k_ampdu_stream *
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001742mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
1743{
1744 struct mwl8k_ampdu_stream *stream;
1745 struct mwl8k_priv *priv = hw->priv;
1746 int i;
1747
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301748 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001749 stream = &priv->ampdu[i];
1750 if (stream->state == AMPDU_NO_STREAM) {
1751 stream->sta = sta;
1752 stream->state = AMPDU_STREAM_NEW;
1753 stream->tid = tid;
1754 stream->idx = i;
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001755 wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
1756 sta->addr, tid);
1757 return stream;
1758 }
1759 }
1760 return NULL;
1761}
1762
1763static int
1764mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1765{
1766 int ret;
1767
1768 /* if the stream has already been started, don't start it again */
1769 if (stream->state != AMPDU_STREAM_NEW)
1770 return 0;
1771 ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
1772 if (ret)
1773 wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
1774 "%d\n", stream->sta->addr, stream->tid, ret);
1775 else
1776 wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
1777 stream->sta->addr, stream->tid);
1778 return ret;
1779}
1780
1781static void
1782mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1783{
1784 wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
1785 stream->tid);
1786 memset(stream, 0, sizeof(*stream));
1787}
1788
1789static struct mwl8k_ampdu_stream *
1790mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
1791{
1792 struct mwl8k_priv *priv = hw->priv;
1793 int i;
1794
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301795 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001796 struct mwl8k_ampdu_stream *stream;
1797 stream = &priv->ampdu[i];
1798 if (stream->state == AMPDU_NO_STREAM)
1799 continue;
1800 if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
1801 stream->tid == tid)
1802 return stream;
1803 }
1804 return NULL;
1805}
1806
Brian Cavagnolod0805c12011-04-12 11:06:28 -07001807#define MWL8K_AMPDU_PACKET_THRESHOLD 64
1808static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
1809{
1810 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1811 struct tx_traffic_info *tx_stats;
1812
1813 BUG_ON(tid >= MWL8K_MAX_TID);
1814 tx_stats = &sta_info->tx_stats[tid];
1815
1816 return sta_info->is_ampdu_allowed &&
1817 tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
1818}
1819
1820static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
1821{
1822 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1823 struct tx_traffic_info *tx_stats;
1824
1825 BUG_ON(tid >= MWL8K_MAX_TID);
1826 tx_stats = &sta_info->tx_stats[tid];
1827
1828 if (tx_stats->start_time == 0)
1829 tx_stats->start_time = jiffies;
1830
1831 /* reset the packet count after each second elapses. If the number of
1832 * packets ever exceeds the ampdu_min_traffic threshold, we will allow
1833 * an ampdu stream to be started.
1834 */
1835 if (jiffies - tx_stats->start_time > HZ) {
1836 tx_stats->pkts = 0;
1837 tx_stats->start_time = 0;
1838 } else
1839 tx_stats->pkts++;
1840}
1841
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301842/* The hardware ampdu queues start from 5.
1843 * txpriorities for ampdu queues are
1844 * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
1845 * and queue 3 is lowest (queue 4 is reserved)
1846 */
1847#define BA_QUEUE 5
1848
Johannes Berg7bb45682011-02-24 14:42:06 +01001849static void
Thomas Huehn36323f82012-07-23 21:33:42 +02001850mwl8k_txq_xmit(struct ieee80211_hw *hw,
1851 int index,
1852 struct ieee80211_sta *sta,
1853 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001854{
1855 struct mwl8k_priv *priv = hw->priv;
1856 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001857 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001858 struct ieee80211_hdr *wh;
1859 struct mwl8k_tx_queue *txq;
1860 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001861 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001862 u32 txstatus;
1863 u8 txdatarate;
1864 u16 qos;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001865 int txpriority;
1866 u8 tid = 0;
1867 struct mwl8k_ampdu_stream *stream = NULL;
1868 bool start_ba_session = false;
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05301869 bool mgmtframe = false;
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001870 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301871 bool eapol_frame = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001872
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001873 wh = (struct ieee80211_hdr *)skb->data;
1874 if (ieee80211_is_data_qos(wh->frame_control))
1875 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1876 else
1877 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001878
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301879 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
1880 eapol_frame = true;
1881
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05301882 if (ieee80211_is_mgmt(wh->frame_control))
1883 mgmtframe = true;
1884
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001885 if (priv->ap_fw)
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +05301886 mwl8k_encapsulate_tx_frame(priv, skb);
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001887 else
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +05301888 mwl8k_add_dma_header(priv, skb, 0, 0);
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001889
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001890 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001891
1892 tx_info = IEEE80211_SKB_CB(skb);
1893 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001894
1895 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001896 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001897 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1898 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001899 }
1900
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001901 /* Setup firmware control bit fields for each frame type. */
1902 txstatus = 0;
1903 txdatarate = 0;
1904 if (ieee80211_is_mgmt(wh->frame_control) ||
1905 ieee80211_is_ctl(wh->frame_control)) {
1906 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001907 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001908 } else if (ieee80211_is_data(wh->frame_control)) {
1909 txdatarate = 1;
1910 if (is_multicast_ether_addr(wh->addr1))
1911 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1912
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001913 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001914 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001915 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001916 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001917 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001918 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001919
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001920 /* Queue ADDBA request in the respective data queue. While setting up
1921 * the ampdu stream, mac80211 queues further packets for that
1922 * particular ra/tid pair. However, packets piled up in the hardware
1923 * for that ra/tid pair will still go out. ADDBA request and the
1924 * related data packets going out from different queues asynchronously
1925 * will cause a shift in the receiver window which might result in
1926 * ampdu packets getting dropped at the receiver after the stream has
1927 * been setup.
1928 */
1929 if (unlikely(ieee80211_is_action(wh->frame_control) &&
1930 mgmt->u.action.category == WLAN_CATEGORY_BACK &&
1931 mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
1932 priv->ap_fw)) {
1933 u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1934 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1935 index = mwl8k_tid_queue_mapping(tid);
1936 }
1937
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001938 txpriority = index;
1939
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301940 if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame &&
1941 ieee80211_is_data_qos(wh->frame_control)) {
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001942 tid = qos & 0xf;
Brian Cavagnolod0805c12011-04-12 11:06:28 -07001943 mwl8k_tx_count_packet(sta, tid);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001944 spin_lock(&priv->stream_lock);
1945 stream = mwl8k_lookup_stream(hw, sta->addr, tid);
1946 if (stream != NULL) {
1947 if (stream->state == AMPDU_STREAM_ACTIVE) {
Yogesh Ashok Powar5f2a1492013-01-03 13:21:25 +05301948 WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK));
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301949 txpriority = (BA_QUEUE + stream->idx) %
1950 TOTAL_HW_TX_QUEUES;
1951 if (stream->idx <= 1)
1952 index = stream->idx +
1953 MWL8K_TX_WMM_QUEUES;
1954
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001955 } else if (stream->state == AMPDU_STREAM_NEW) {
1956 /* We get here if the driver sends us packets
1957 * after we've initiated a stream, but before
1958 * our ampdu_action routine has been called
1959 * with IEEE80211_AMPDU_TX_START to get the SSN
1960 * for the ADDBA request. So this packet can
1961 * go out with no risk of sequence number
1962 * mismatch. No special handling is required.
1963 */
1964 } else {
1965 /* Drop packets that would go out after the
1966 * ADDBA request was sent but before the ADDBA
1967 * response is received. If we don't do this,
1968 * the recipient would probably receive it
1969 * after the ADDBA request with SSN 0. This
1970 * will cause the recipient's BA receive window
1971 * to shift, which would cause the subsequent
1972 * packets in the BA stream to be discarded.
1973 * mac80211 queues our packets for us in this
1974 * case, so this is really just a safety check.
1975 */
1976 wiphy_warn(hw->wiphy,
1977 "Cannot send packet while ADDBA "
1978 "dialog is underway.\n");
1979 spin_unlock(&priv->stream_lock);
1980 dev_kfree_skb(skb);
1981 return;
1982 }
1983 } else {
1984 /* Defer calling mwl8k_start_stream so that the current
1985 * skb can go out before the ADDBA request. This
1986 * prevents sequence number mismatch at the recepient
1987 * as described above.
1988 */
Brian Cavagnolod0805c12011-04-12 11:06:28 -07001989 if (mwl8k_ampdu_allowed(sta, tid)) {
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001990 stream = mwl8k_add_stream(hw, sta, tid);
1991 if (stream != NULL)
1992 start_ba_session = true;
1993 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001994 }
1995 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar5f2a1492013-01-03 13:21:25 +05301996 } else {
1997 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1998 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001999 }
2000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002001 dma = pci_map_single(priv->pdev, skb->data,
2002 skb->len, PCI_DMA_TODEVICE);
2003
2004 if (pci_dma_mapping_error(priv->pdev, dma)) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07002005 wiphy_debug(hw->wiphy,
2006 "failed to dma map skb, dropping TX frame.\n");
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002007 if (start_ba_session) {
2008 spin_lock(&priv->stream_lock);
2009 mwl8k_remove_stream(hw, stream);
2010 spin_unlock(&priv->stream_lock);
2011 }
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002012 dev_kfree_skb(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +01002013 return;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002014 }
2015
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002016 spin_lock_bh(&priv->tx_lock);
2017
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002018 txq = priv->txq + index;
2019
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302020 /* Mgmt frames that go out frequently are probe
2021 * responses. Other mgmt frames got out relatively
2022 * infrequently. Hence reserve 2 buffers so that
2023 * other mgmt frames do not get dropped due to an
2024 * already queued probe response in one of the
2025 * reserved buffers.
2026 */
2027
2028 if (txq->len >= MWL8K_TX_DESCS - 2) {
Joe Perches23677ce2012-02-09 11:17:23 +00002029 if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302030 if (start_ba_session) {
2031 spin_lock(&priv->stream_lock);
2032 mwl8k_remove_stream(hw, stream);
2033 spin_unlock(&priv->stream_lock);
2034 }
2035 spin_unlock_bh(&priv->tx_lock);
Nishant Sarmukadamff7aa962012-11-06 19:22:48 +05302036 pci_unmap_single(priv->pdev, dma, skb->len,
2037 PCI_DMA_TODEVICE);
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302038 dev_kfree_skb(skb);
2039 return;
Pradeep Nemavat3a7dbc32011-04-21 16:34:56 +05302040 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002041 }
2042
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002043 BUG_ON(txq->skb[txq->tail] != NULL);
2044 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002045
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002046 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002047 tx->data_rate = txdatarate;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002048 tx->tx_priority = txpriority;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002049 tx->qos_control = cpu_to_le16(qos);
2050 tx->pkt_phys_addr = cpu_to_le32(dma);
2051 tx->pkt_len = cpu_to_le16(skb->len);
2052 tx->rate_info = 0;
Thomas Huehn36323f82012-07-23 21:33:42 +02002053 if (!priv->ap_fw && sta != NULL)
2054 tx->peer_id = MWL8K_STA(sta)->peer_id;
Lennert Buytenheka6804002010-01-04 21:55:42 +01002055 else
2056 tx->peer_id = 0;
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302057
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05302058 if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame)
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302059 tx->timestamp = cpu_to_le32(ioread32(priv->regs +
2060 MWL8K_HW_TIMER_REGISTER));
Nishant Sarmukadamb8d9e572012-11-06 19:23:15 +05302061 else
2062 tx->timestamp = 0;
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302063
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002064 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002065 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
2066
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02002067 txq->len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002068 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002069
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002070 txq->tail++;
2071 if (txq->tail == MWL8K_TX_DESCS)
2072 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002073
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002074 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002075
2076 spin_unlock_bh(&priv->tx_lock);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002077
2078 /* Initiate the ampdu session here */
2079 if (start_ba_session) {
2080 spin_lock(&priv->stream_lock);
2081 if (mwl8k_start_stream(hw, stream))
2082 mwl8k_remove_stream(hw, stream);
2083 spin_unlock(&priv->stream_lock);
2084 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002085}
2086
2087
2088/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002089 * Firmware access.
2090 *
2091 * We have the following requirements for issuing firmware commands:
2092 * - Some commands require that the packet transmit path is idle when
2093 * the command is issued. (For simplicity, we'll just quiesce the
2094 * transmit path for every command.)
2095 * - There are certain sequences of commands that need to be issued to
2096 * the hardware sequentially, with no other intervening commands.
2097 *
2098 * This leads to an implementation of a "firmware lock" as a mutex that
2099 * can be taken recursively, and which is taken by both the low-level
2100 * command submission function (mwl8k_post_cmd) as well as any users of
2101 * that function that require issuing of an atomic sequence of commands,
2102 * and quiesces the transmit path whenever it's taken.
2103 */
2104static int mwl8k_fw_lock(struct ieee80211_hw *hw)
2105{
2106 struct mwl8k_priv *priv = hw->priv;
2107
2108 if (priv->fw_mutex_owner != current) {
2109 int rc;
2110
2111 mutex_lock(&priv->fw_mutex);
2112 ieee80211_stop_queues(hw);
2113
2114 rc = mwl8k_tx_wait_empty(hw);
2115 if (rc) {
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05302116 if (!priv->hw_restart_in_progress)
2117 ieee80211_wake_queues(hw);
2118
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002119 mutex_unlock(&priv->fw_mutex);
2120
2121 return rc;
2122 }
2123
2124 priv->fw_mutex_owner = current;
2125 }
2126
2127 priv->fw_mutex_depth++;
2128
2129 return 0;
2130}
2131
2132static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
2133{
2134 struct mwl8k_priv *priv = hw->priv;
2135
2136 if (!--priv->fw_mutex_depth) {
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05302137 if (!priv->hw_restart_in_progress)
2138 ieee80211_wake_queues(hw);
2139
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002140 priv->fw_mutex_owner = NULL;
2141 mutex_unlock(&priv->fw_mutex);
2142 }
2143}
2144
2145
2146/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002147 * Command processing.
2148 */
2149
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01002150/* Timeout firmware commands after 10s */
2151#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002152
2153static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
2154{
2155 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2156 struct mwl8k_priv *priv = hw->priv;
2157 void __iomem *regs = priv->regs;
2158 dma_addr_t dma_addr;
2159 unsigned int dma_size;
2160 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002161 unsigned long timeout = 0;
2162 u8 buf[32];
2163
John W. Linvilleb6037422010-07-20 13:55:00 -04002164 cmd->result = (__force __le16) 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002165 dma_size = le16_to_cpu(cmd->length);
2166 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
2167 PCI_DMA_BIDIRECTIONAL);
2168 if (pci_dma_mapping_error(priv->pdev, dma_addr))
2169 return -ENOMEM;
2170
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002171 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02002172 if (rc) {
2173 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2174 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002175 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02002176 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002177
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002178 priv->hostcmd_wait = &cmd_wait;
2179 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
2180 iowrite32(MWL8K_H2A_INT_DOORBELL,
2181 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2182 iowrite32(MWL8K_H2A_INT_DUMMY,
2183 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002184
2185 timeout = wait_for_completion_timeout(&cmd_wait,
2186 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
2187
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002188 priv->hostcmd_wait = NULL;
2189
2190 mwl8k_fw_unlock(hw);
2191
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02002192 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2193 PCI_DMA_BIDIRECTIONAL);
2194
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002195 if (!timeout) {
Joe Perches5db55842010-08-11 19:11:19 -07002196 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002197 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2198 MWL8K_CMD_TIMEOUT_MS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002199 rc = -ETIMEDOUT;
2200 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01002201 int ms;
2202
2203 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
2204
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002205 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002206 if (rc)
Joe Perches5db55842010-08-11 19:11:19 -07002207 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002208 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2209 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01002210 else if (ms > 2000)
Joe Perches5db55842010-08-11 19:11:19 -07002211 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002212 mwl8k_cmd_name(cmd->code,
2213 buf, sizeof(buf)),
2214 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002215 }
2216
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002217 return rc;
2218}
2219
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +01002220static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
2221 struct ieee80211_vif *vif,
2222 struct mwl8k_cmd_pkt *cmd)
2223{
2224 if (vif != NULL)
2225 cmd->macid = MWL8K_VIF(vif)->macid;
2226 return mwl8k_post_cmd(hw, cmd);
2227}
2228
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002229/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01002230 * Setup code shared between STA and AP firmware images.
2231 */
2232static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
2233{
2234 struct mwl8k_priv *priv = hw->priv;
2235
2236 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
2237 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
2238
2239 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
2240 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
2241
2242 priv->band_24.band = IEEE80211_BAND_2GHZ;
2243 priv->band_24.channels = priv->channels_24;
2244 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
2245 priv->band_24.bitrates = priv->rates_24;
2246 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
2247
2248 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
2249}
2250
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01002251static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
2252{
2253 struct mwl8k_priv *priv = hw->priv;
2254
2255 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
2256 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
2257
2258 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
2259 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
2260
2261 priv->band_50.band = IEEE80211_BAND_5GHZ;
2262 priv->band_50.channels = priv->channels_50;
2263 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
2264 priv->band_50.bitrates = priv->rates_50;
2265 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
2266
2267 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
2268}
2269
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01002270/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02002271 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002272 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02002273struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002274 struct mwl8k_cmd_pkt header;
2275 __u8 hw_rev;
2276 __u8 host_interface;
2277 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002278 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002279 __le16 region_code;
2280 __le32 fw_rev;
2281 __le32 ps_cookie;
2282 __le32 caps;
2283 __u8 mcs_bitmap[16];
2284 __le32 rx_queue_ptr;
2285 __le32 num_tx_queues;
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002286 __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002287 __le32 caps2;
2288 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002289 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002290} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002291
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002292#define MWL8K_CAP_MAX_AMSDU 0x20000000
2293#define MWL8K_CAP_GREENFIELD 0x08000000
2294#define MWL8K_CAP_AMPDU 0x04000000
2295#define MWL8K_CAP_RX_STBC 0x01000000
2296#define MWL8K_CAP_TX_STBC 0x00800000
2297#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2298#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2299#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2300#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2301#define MWL8K_CAP_DELAY_BA 0x00003000
2302#define MWL8K_CAP_MIMO 0x00000200
2303#define MWL8K_CAP_40MHZ 0x00000100
Lennert Buytenhek06953232010-01-12 13:49:41 +01002304#define MWL8K_CAP_BAND_MASK 0x00000007
2305#define MWL8K_CAP_5GHZ 0x00000004
2306#define MWL8K_CAP_2GHZ4 0x00000001
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002307
Lennert Buytenhek06953232010-01-12 13:49:41 +01002308static void
2309mwl8k_set_ht_caps(struct ieee80211_hw *hw,
2310 struct ieee80211_supported_band *band, u32 cap)
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002311{
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002312 int rx_streams;
2313 int tx_streams;
2314
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002315 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002316
2317 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002318 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002319 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002320 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002321 if (cap & MWL8K_CAP_AMPDU) {
2322 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002323 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2324 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002325 }
2326 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002327 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002328 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002329 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002330 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002331 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002332 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002333 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002334 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002335 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002336 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002337 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002338
2339 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
2340 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
2341
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002342 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002343 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002344 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002345 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002346 band->ht_cap.mcs.rx_mask[2] = 0xff;
2347 band->ht_cap.mcs.rx_mask[4] = 0x01;
2348 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002349
2350 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002351 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
2352 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002353 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2354 }
2355}
2356
Lennert Buytenhek06953232010-01-12 13:49:41 +01002357static void
2358mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
2359{
2360 struct mwl8k_priv *priv = hw->priv;
2361
2362 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
2363 mwl8k_setup_2ghz_band(hw);
2364 if (caps & MWL8K_CAP_MIMO)
2365 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
2366 }
2367
2368 if (caps & MWL8K_CAP_5GHZ) {
2369 mwl8k_setup_5ghz_band(hw);
2370 if (caps & MWL8K_CAP_MIMO)
2371 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
2372 }
2373}
2374
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02002375static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002376{
2377 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02002378 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002379 int rc;
2380 int i;
2381
2382 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2383 if (cmd == NULL)
2384 return -ENOMEM;
2385
2386 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2387 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2388
2389 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2390 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002391 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002392 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2393 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002394 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02002395 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002396 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002397
2398 rc = mwl8k_post_cmd(hw, &cmd->header);
2399
2400 if (!rc) {
2401 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2402 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02002403 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002404 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek06953232010-01-12 13:49:41 +01002405 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002406 priv->ap_macids_supported = 0x00000000;
2407 priv->sta_macids_supported = 0x00000001;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002408 }
2409
2410 kfree(cmd);
2411 return rc;
2412}
2413
2414/*
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002415 * CMD_GET_HW_SPEC (AP version).
2416 */
2417struct mwl8k_cmd_get_hw_spec_ap {
2418 struct mwl8k_cmd_pkt header;
2419 __u8 hw_rev;
2420 __u8 host_interface;
2421 __le16 num_wcb;
2422 __le16 num_mcaddrs;
2423 __u8 perm_addr[ETH_ALEN];
2424 __le16 region_code;
2425 __le16 num_antenna;
2426 __le32 fw_rev;
2427 __le32 wcbbase0;
2428 __le32 rxwrptr;
2429 __le32 rxrdptr;
2430 __le32 ps_cookie;
2431 __le32 wcbbase1;
2432 __le32 wcbbase2;
2433 __le32 wcbbase3;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002434 __le32 fw_api_version;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002435 __le32 caps;
2436 __le32 num_of_ampdu_queues;
2437 __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002438} __packed;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002439
2440static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2441{
2442 struct mwl8k_priv *priv = hw->priv;
2443 struct mwl8k_cmd_get_hw_spec_ap *cmd;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002444 int rc, i;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002445 u32 api_version;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002446
2447 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2448 if (cmd == NULL)
2449 return -ENOMEM;
2450
2451 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2452 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2453
2454 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2455 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2456
2457 rc = mwl8k_post_cmd(hw, &cmd->header);
2458
2459 if (!rc) {
2460 int off;
2461
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002462 api_version = le32_to_cpu(cmd->fw_api_version);
2463 if (priv->device_info->fw_api_ap != api_version) {
2464 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2465 " Expected %d got %d.\n", MWL8K_NAME,
2466 priv->device_info->part_name,
2467 priv->device_info->fw_api_ap,
2468 api_version);
2469 rc = -EINVAL;
2470 goto done;
2471 }
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002472 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2473 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2474 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2475 priv->hw_rev = cmd->hw_rev;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002476 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002477 priv->ap_macids_supported = 0x000000ff;
2478 priv->sta_macids_supported = 0x00000000;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002479 priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
2480 if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
2481 wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
2482 " but we only support %d.\n",
2483 priv->num_ampdu_queues,
2484 MWL8K_MAX_AMPDU_QUEUES);
2485 priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
2486 }
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002487 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002488 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002489
2490 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002491 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002492
Brian Cavagnolo73b46322011-03-17 11:58:41 -07002493 priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
2494 priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
2495 priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
2496 priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002497
2498 for (i = 0; i < priv->num_ampdu_queues; i++)
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002499 priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002500 le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002501 }
2502
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002503done:
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002504 kfree(cmd);
2505 return rc;
2506}
2507
2508/*
2509 * CMD_SET_HW_SPEC.
2510 */
2511struct mwl8k_cmd_set_hw_spec {
2512 struct mwl8k_cmd_pkt header;
2513 __u8 hw_rev;
2514 __u8 host_interface;
2515 __le16 num_mcaddrs;
2516 __u8 perm_addr[ETH_ALEN];
2517 __le16 region_code;
2518 __le32 fw_rev;
2519 __le32 ps_cookie;
2520 __le32 caps;
2521 __le32 rx_queue_ptr;
2522 __le32 num_tx_queues;
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002523 __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002524 __le32 flags;
2525 __le32 num_tx_desc_per_queue;
2526 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002527} __packed;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002528
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002529/* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2530 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2531 * the packets that are queued for more than 500ms, will be dropped in the
2532 * hardware. This helps minimizing the issues caused due to head-of-line
2533 * blocking where a slow client can hog the bandwidth and affect traffic to a
2534 * faster client.
2535 */
2536#define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
Nishant Sarmukadam3373b282011-06-13 16:26:15 +05302537#define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002538#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2539#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2540#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002541
2542static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2543{
2544 struct mwl8k_priv *priv = hw->priv;
2545 struct mwl8k_cmd_set_hw_spec *cmd;
2546 int rc;
2547 int i;
2548
2549 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2550 if (cmd == NULL)
2551 return -ENOMEM;
2552
2553 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2554 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2555
2556 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2557 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002558 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08002559
2560 /*
2561 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2562 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2563 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2564 * priority is interpreted the right way in firmware.
2565 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002566 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
2567 int j = mwl8k_tx_queues(priv) - 1 - i;
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08002568 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
2569 }
2570
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002571 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2572 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
Nishant Sarmukadam31d291a2011-04-21 16:34:59 +05302573 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
Nishant Sarmukadam3373b282011-06-13 16:26:15 +05302574 MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
2575 MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002576 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2577 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2578
2579 rc = mwl8k_post_cmd(hw, &cmd->header);
2580 kfree(cmd);
2581
2582 return rc;
2583}
2584
2585/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002586 * CMD_MAC_MULTICAST_ADR.
2587 */
2588struct mwl8k_cmd_mac_multicast_adr {
2589 struct mwl8k_cmd_pkt header;
2590 __le16 action;
2591 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002592 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002593};
2594
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002595#define MWL8K_ENABLE_RX_DIRECTED 0x0001
2596#define MWL8K_ENABLE_RX_MULTICAST 0x0002
2597#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2598#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002599
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002600static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002601__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Jiri Pirko22bedad2010-04-01 21:22:57 +00002602 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002603{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002604 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002605 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002606 int size;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002607 int mc_count = 0;
2608
2609 if (mc_list)
2610 mc_count = netdev_hw_addr_list_count(mc_list);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002611
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002612 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002613 allmulti = 1;
2614 mc_count = 0;
2615 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002616
2617 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2618
2619 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002620 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002621 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002622
2623 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2624 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002625 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2626 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002627
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002628 if (allmulti) {
2629 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2630 } else if (mc_count) {
Jiri Pirko22bedad2010-04-01 21:22:57 +00002631 struct netdev_hw_addr *ha;
2632 int i = 0;
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002633
2634 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2635 cmd->numaddr = cpu_to_le16(mc_count);
Jiri Pirko22bedad2010-04-01 21:22:57 +00002636 netdev_hw_addr_list_for_each(ha, mc_list) {
2637 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002638 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002639 }
2640
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002641 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002642}
2643
2644/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002645 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002646 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002647struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002648 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002649 __le32 stats[64];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002650} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002651
2652#define MWL8K_STAT_ACK_FAILURE 9
2653#define MWL8K_STAT_RTS_FAILURE 12
2654#define MWL8K_STAT_FCS_ERROR 24
2655#define MWL8K_STAT_RTS_SUCCESS 11
2656
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002657static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2658 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002659{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002660 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002661 int rc;
2662
2663 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2664 if (cmd == NULL)
2665 return -ENOMEM;
2666
2667 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2668 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002669
2670 rc = mwl8k_post_cmd(hw, &cmd->header);
2671 if (!rc) {
2672 stats->dot11ACKFailureCount =
2673 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2674 stats->dot11RTSFailureCount =
2675 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2676 stats->dot11FCSErrorCount =
2677 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2678 stats->dot11RTSSuccessCount =
2679 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2680 }
2681 kfree(cmd);
2682
2683 return rc;
2684}
2685
2686/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002687 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002688 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002689struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002690 struct mwl8k_cmd_pkt header;
2691 __le16 action;
2692 __le16 control;
2693 __le16 radio_on;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002694} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002695
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002696static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002697mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002698{
2699 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002700 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002701 int rc;
2702
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002703 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002704 return 0;
2705
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002706 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2707 if (cmd == NULL)
2708 return -ENOMEM;
2709
2710 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2711 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2712 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002713 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002714 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2715
2716 rc = mwl8k_post_cmd(hw, &cmd->header);
2717 kfree(cmd);
2718
2719 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002720 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002721
2722 return rc;
2723}
2724
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002725static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002726{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002727 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002728}
2729
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002730static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002731{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002732 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002733}
2734
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002735static int
2736mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2737{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002738 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002739
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002740 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002741
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002742 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002743}
2744
2745/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002746 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002747 */
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002748#define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002749
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002750struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002751 struct mwl8k_cmd_pkt header;
2752 __le16 action;
2753 __le16 support_level;
2754 __le16 current_level;
2755 __le16 reserved;
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002756 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002757} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002758
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002759static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002760{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002761 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002762 int rc;
2763
2764 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2765 if (cmd == NULL)
2766 return -ENOMEM;
2767
2768 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2769 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2770 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2771 cmd->support_level = cpu_to_le16(dBm);
2772
2773 rc = mwl8k_post_cmd(hw, &cmd->header);
2774 kfree(cmd);
2775
2776 return rc;
2777}
2778
2779/*
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002780 * CMD_TX_POWER.
2781 */
2782#define MWL8K_TX_POWER_LEVEL_TOTAL 12
2783
2784struct mwl8k_cmd_tx_power {
2785 struct mwl8k_cmd_pkt header;
2786 __le16 action;
2787 __le16 band;
2788 __le16 channel;
2789 __le16 bw;
2790 __le16 sub_ch;
2791 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05302792} __packed;
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002793
2794static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2795 struct ieee80211_conf *conf,
2796 unsigned short pwr)
2797{
2798 struct ieee80211_channel *channel = conf->channel;
2799 struct mwl8k_cmd_tx_power *cmd;
2800 int rc;
2801 int i;
2802
2803 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2804 if (cmd == NULL)
2805 return -ENOMEM;
2806
2807 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2808 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2809 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2810
2811 if (channel->band == IEEE80211_BAND_2GHZ)
2812 cmd->band = cpu_to_le16(0x1);
2813 else if (channel->band == IEEE80211_BAND_5GHZ)
2814 cmd->band = cpu_to_le16(0x4);
2815
Yogesh Ashok Powar604c4ef2012-01-17 15:45:15 +05302816 cmd->channel = cpu_to_le16(channel->hw_value);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002817
2818 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2819 conf->channel_type == NL80211_CHAN_HT20) {
2820 cmd->bw = cpu_to_le16(0x2);
2821 } else {
2822 cmd->bw = cpu_to_le16(0x4);
2823 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2824 cmd->sub_ch = cpu_to_le16(0x3);
2825 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2826 cmd->sub_ch = cpu_to_le16(0x1);
2827 }
2828
2829 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2830 cmd->power_level_list[i] = cpu_to_le16(pwr);
2831
2832 rc = mwl8k_post_cmd(hw, &cmd->header);
2833 kfree(cmd);
2834
2835 return rc;
2836}
2837
2838/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002839 * CMD_RF_ANTENNA.
2840 */
2841struct mwl8k_cmd_rf_antenna {
2842 struct mwl8k_cmd_pkt header;
2843 __le16 antenna;
2844 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002845} __packed;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002846
2847#define MWL8K_RF_ANTENNA_RX 1
2848#define MWL8K_RF_ANTENNA_TX 2
2849
2850static int
2851mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2852{
2853 struct mwl8k_cmd_rf_antenna *cmd;
2854 int rc;
2855
2856 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2857 if (cmd == NULL)
2858 return -ENOMEM;
2859
2860 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2861 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2862 cmd->antenna = cpu_to_le16(antenna);
2863 cmd->mode = cpu_to_le16(mask);
2864
2865 rc = mwl8k_post_cmd(hw, &cmd->header);
2866 kfree(cmd);
2867
2868 return rc;
2869}
2870
2871/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002872 * CMD_SET_BEACON.
2873 */
2874struct mwl8k_cmd_set_beacon {
2875 struct mwl8k_cmd_pkt header;
2876 __le16 beacon_len;
2877 __u8 beacon[0];
2878};
2879
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01002880static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2881 struct ieee80211_vif *vif, u8 *beacon, int len)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002882{
2883 struct mwl8k_cmd_set_beacon *cmd;
2884 int rc;
2885
2886 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2887 if (cmd == NULL)
2888 return -ENOMEM;
2889
2890 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2891 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2892 cmd->beacon_len = cpu_to_le16(len);
2893 memcpy(cmd->beacon, beacon, len);
2894
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01002895 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002896 kfree(cmd);
2897
2898 return rc;
2899}
2900
2901/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002902 * CMD_SET_PRE_SCAN.
2903 */
2904struct mwl8k_cmd_set_pre_scan {
2905 struct mwl8k_cmd_pkt header;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002906} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002907
2908static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2909{
2910 struct mwl8k_cmd_set_pre_scan *cmd;
2911 int rc;
2912
2913 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2914 if (cmd == NULL)
2915 return -ENOMEM;
2916
2917 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2918 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2919
2920 rc = mwl8k_post_cmd(hw, &cmd->header);
2921 kfree(cmd);
2922
2923 return rc;
2924}
2925
2926/*
2927 * CMD_SET_POST_SCAN.
2928 */
2929struct mwl8k_cmd_set_post_scan {
2930 struct mwl8k_cmd_pkt header;
2931 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002932 __u8 bssid[ETH_ALEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002933} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002934
2935static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002936mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002937{
2938 struct mwl8k_cmd_set_post_scan *cmd;
2939 int rc;
2940
2941 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2942 if (cmd == NULL)
2943 return -ENOMEM;
2944
2945 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2946 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2947 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002948 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002949
2950 rc = mwl8k_post_cmd(hw, &cmd->header);
2951 kfree(cmd);
2952
2953 return rc;
2954}
2955
2956/*
2957 * CMD_SET_RF_CHANNEL.
2958 */
2959struct mwl8k_cmd_set_rf_channel {
2960 struct mwl8k_cmd_pkt header;
2961 __le16 action;
2962 __u8 current_channel;
2963 __le32 channel_flags;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002964} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002965
2966static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002967 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002968{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002969 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002970 struct mwl8k_cmd_set_rf_channel *cmd;
2971 int rc;
2972
2973 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2974 if (cmd == NULL)
2975 return -ENOMEM;
2976
2977 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2978 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2979 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2980 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002981
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002982 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002983 cmd->channel_flags |= cpu_to_le32(0x00000001);
Lennert Buytenhek42574ea2010-01-12 13:49:18 +01002984 else if (channel->band == IEEE80211_BAND_5GHZ)
2985 cmd->channel_flags |= cpu_to_le32(0x00000004);
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002986
2987 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2988 conf->channel_type == NL80211_CHAN_HT20)
2989 cmd->channel_flags |= cpu_to_le32(0x00000080);
2990 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2991 cmd->channel_flags |= cpu_to_le32(0x000001900);
2992 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2993 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002994
2995 rc = mwl8k_post_cmd(hw, &cmd->header);
2996 kfree(cmd);
2997
2998 return rc;
2999}
3000
3001/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003002 * CMD_SET_AID.
3003 */
3004#define MWL8K_FRAME_PROT_DISABLED 0x00
3005#define MWL8K_FRAME_PROT_11G 0x07
3006#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
3007#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
3008
3009struct mwl8k_cmd_update_set_aid {
3010 struct mwl8k_cmd_pkt header;
3011 __le16 aid;
3012
3013 /* AP's MAC address (BSSID) */
3014 __u8 bssid[ETH_ALEN];
3015 __le16 protection_mode;
3016 __u8 supp_rates[14];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003017} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003018
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003019static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
3020{
3021 int i;
3022 int j;
3023
3024 /*
3025 * Clear nonstandard rates 4 and 13.
3026 */
3027 mask &= 0x1fef;
3028
3029 for (i = 0, j = 0; i < 14; i++) {
3030 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01003031 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003032 }
3033}
3034
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003035static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003036mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
3037 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003038{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003039 struct mwl8k_cmd_update_set_aid *cmd;
3040 u16 prot_mode;
3041 int rc;
3042
3043 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3044 if (cmd == NULL)
3045 return -ENOMEM;
3046
3047 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
3048 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003049 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003050 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003051
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003052 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003053 prot_mode = MWL8K_FRAME_PROT_11G;
3054 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003055 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003056 IEEE80211_HT_OP_MODE_PROTECTION) {
3057 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
3058 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
3059 break;
3060 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
3061 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
3062 break;
3063 default:
3064 prot_mode = MWL8K_FRAME_PROT_DISABLED;
3065 break;
3066 }
3067 }
3068 cmd->protection_mode = cpu_to_le16(prot_mode);
3069
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003070 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003071
3072 rc = mwl8k_post_cmd(hw, &cmd->header);
3073 kfree(cmd);
3074
3075 return rc;
3076}
3077
3078/*
3079 * CMD_SET_RATE.
3080 */
3081struct mwl8k_cmd_set_rate {
3082 struct mwl8k_cmd_pkt header;
3083 __u8 legacy_rates[14];
3084
3085 /* Bitmap for supported MCS codes. */
3086 __u8 mcs_set[16];
3087 __u8 reserved[16];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003088} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003089
3090static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003091mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003092 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003093{
3094 struct mwl8k_cmd_set_rate *cmd;
3095 int rc;
3096
3097 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3098 if (cmd == NULL)
3099 return -ENOMEM;
3100
3101 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
3102 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003103 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003104 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003105
3106 rc = mwl8k_post_cmd(hw, &cmd->header);
3107 kfree(cmd);
3108
3109 return rc;
3110}
3111
3112/*
3113 * CMD_FINALIZE_JOIN.
3114 */
3115#define MWL8K_FJ_BEACON_MAXLEN 128
3116
3117struct mwl8k_cmd_finalize_join {
3118 struct mwl8k_cmd_pkt header;
3119 __le32 sleep_interval; /* Number of beacon periods to sleep */
3120 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003121} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003122
3123static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
3124 int framelen, int dtim)
3125{
3126 struct mwl8k_cmd_finalize_join *cmd;
3127 struct ieee80211_mgmt *payload = frame;
3128 int payload_len;
3129 int rc;
3130
3131 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3132 if (cmd == NULL)
3133 return -ENOMEM;
3134
3135 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
3136 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3137 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
3138
3139 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
3140 if (payload_len < 0)
3141 payload_len = 0;
3142 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
3143 payload_len = MWL8K_FJ_BEACON_MAXLEN;
3144
3145 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
3146
3147 rc = mwl8k_post_cmd(hw, &cmd->header);
3148 kfree(cmd);
3149
3150 return rc;
3151}
3152
3153/*
3154 * CMD_SET_RTS_THRESHOLD.
3155 */
3156struct mwl8k_cmd_set_rts_threshold {
3157 struct mwl8k_cmd_pkt header;
3158 __le16 action;
3159 __le16 threshold;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003160} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003161
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003162static int
3163mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003164{
3165 struct mwl8k_cmd_set_rts_threshold *cmd;
3166 int rc;
3167
3168 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3169 if (cmd == NULL)
3170 return -ENOMEM;
3171
3172 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
3173 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003174 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3175 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003176
3177 rc = mwl8k_post_cmd(hw, &cmd->header);
3178 kfree(cmd);
3179
3180 return rc;
3181}
3182
3183/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003184 * CMD_SET_SLOT.
3185 */
3186struct mwl8k_cmd_set_slot {
3187 struct mwl8k_cmd_pkt header;
3188 __le16 action;
3189 __u8 short_slot;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003190} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003191
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02003192static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003193{
3194 struct mwl8k_cmd_set_slot *cmd;
3195 int rc;
3196
3197 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3198 if (cmd == NULL)
3199 return -ENOMEM;
3200
3201 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
3202 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3203 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02003204 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003205
3206 rc = mwl8k_post_cmd(hw, &cmd->header);
3207 kfree(cmd);
3208
3209 return rc;
3210}
3211
3212/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003213 * CMD_SET_EDCA_PARAMS.
3214 */
3215struct mwl8k_cmd_set_edca_params {
3216 struct mwl8k_cmd_pkt header;
3217
3218 /* See MWL8K_SET_EDCA_XXX below */
3219 __le16 action;
3220
3221 /* TX opportunity in units of 32 us */
3222 __le16 txop;
3223
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003224 union {
3225 struct {
3226 /* Log exponent of max contention period: 0...15 */
3227 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003228
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003229 /* Log exponent of min contention period: 0...15 */
3230 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003231
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003232 /* Adaptive interframe spacing in units of 32us */
3233 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003234
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003235 /* TX queue to configure */
3236 __u8 txq;
3237 } ap;
3238 struct {
3239 /* Log exponent of max contention period: 0...15 */
3240 __u8 log_cw_max;
3241
3242 /* Log exponent of min contention period: 0...15 */
3243 __u8 log_cw_min;
3244
3245 /* Adaptive interframe spacing in units of 32us */
3246 __u8 aifs;
3247
3248 /* TX queue to configure */
3249 __u8 txq;
3250 } sta;
3251 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00003252} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003253
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003254#define MWL8K_SET_EDCA_CW 0x01
3255#define MWL8K_SET_EDCA_TXOP 0x02
3256#define MWL8K_SET_EDCA_AIFS 0x04
3257
3258#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3259 MWL8K_SET_EDCA_TXOP | \
3260 MWL8K_SET_EDCA_AIFS)
3261
3262static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003263mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
3264 __u16 cw_min, __u16 cw_max,
3265 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003266{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003267 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003268 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003269 int rc;
3270
3271 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3272 if (cmd == NULL)
3273 return -ENOMEM;
3274
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003275 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
3276 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003277 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
3278 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003279 if (priv->ap_fw) {
3280 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
3281 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
3282 cmd->ap.aifs = aifs;
3283 cmd->ap.txq = qnum;
3284 } else {
3285 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
3286 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
3287 cmd->sta.aifs = aifs;
3288 cmd->sta.txq = qnum;
3289 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003290
3291 rc = mwl8k_post_cmd(hw, &cmd->header);
3292 kfree(cmd);
3293
3294 return rc;
3295}
3296
3297/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003298 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003299 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003300struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003301 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003302 __le16 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003303} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003304
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003305static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003306{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003307 struct mwl8k_priv *priv = hw->priv;
3308 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003309 int rc;
3310
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003311 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3312 if (cmd == NULL)
3313 return -ENOMEM;
3314
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003315 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003316 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003317 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003318
3319 rc = mwl8k_post_cmd(hw, &cmd->header);
3320 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01003321
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003322 if (!rc)
3323 priv->wmm_enabled = enable;
3324
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003325 return rc;
3326}
3327
3328/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003329 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003330 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003331struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003332 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003333 __le32 action;
3334 __u8 rx_antenna_map;
3335 __u8 tx_antenna_map;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003336} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003337
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003338static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003339{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003340 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003341 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003342
3343 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3344 if (cmd == NULL)
3345 return -ENOMEM;
3346
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003347 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003348 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003349 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
3350 cmd->rx_antenna_map = rx;
3351 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003352
3353 rc = mwl8k_post_cmd(hw, &cmd->header);
3354 kfree(cmd);
3355
3356 return rc;
3357}
3358
3359/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003360 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003361 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003362struct mwl8k_cmd_use_fixed_rate_sta {
3363 struct mwl8k_cmd_pkt header;
3364 __le32 action;
3365 __le32 allow_rate_drop;
3366 __le32 num_rates;
3367 struct {
3368 __le32 is_ht_rate;
3369 __le32 enable_retry;
3370 __le32 rate;
3371 __le32 retry_count;
3372 } rate_entry[8];
3373 __le32 rate_type;
3374 __le32 reserved1;
3375 __le32 reserved2;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003376} __packed;
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003377
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003378#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003379#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003380
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003381static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003382{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003383 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003384 int rc;
3385
3386 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3387 if (cmd == NULL)
3388 return -ENOMEM;
3389
3390 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3391 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003392 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3393 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003394
3395 rc = mwl8k_post_cmd(hw, &cmd->header);
3396 kfree(cmd);
3397
3398 return rc;
3399}
3400
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003401/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01003402 * CMD_USE_FIXED_RATE (AP version).
3403 */
3404struct mwl8k_cmd_use_fixed_rate_ap {
3405 struct mwl8k_cmd_pkt header;
3406 __le32 action;
3407 __le32 allow_rate_drop;
3408 __le32 num_rates;
3409 struct mwl8k_rate_entry_ap {
3410 __le32 is_ht_rate;
3411 __le32 enable_retry;
3412 __le32 rate;
3413 __le32 retry_count;
3414 } rate_entry[4];
3415 u8 multicast_rate;
3416 u8 multicast_rate_type;
3417 u8 management_rate;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003418} __packed;
Lennert Buytenhek088aab82010-01-08 18:30:36 +01003419
3420static int
3421mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
3422{
3423 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
3424 int rc;
3425
3426 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3427 if (cmd == NULL)
3428 return -ENOMEM;
3429
3430 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3431 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3432 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3433 cmd->multicast_rate = mcast;
3434 cmd->management_rate = mgmt;
3435
3436 rc = mwl8k_post_cmd(hw, &cmd->header);
3437 kfree(cmd);
3438
3439 return rc;
3440}
3441
3442/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003443 * CMD_ENABLE_SNIFFER.
3444 */
3445struct mwl8k_cmd_enable_sniffer {
3446 struct mwl8k_cmd_pkt header;
3447 __le32 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003448} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003449
3450static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3451{
3452 struct mwl8k_cmd_enable_sniffer *cmd;
3453 int rc;
3454
3455 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3456 if (cmd == NULL)
3457 return -ENOMEM;
3458
3459 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3460 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3461 cmd->action = cpu_to_le32(!!enable);
3462
3463 rc = mwl8k_post_cmd(hw, &cmd->header);
3464 kfree(cmd);
3465
3466 return rc;
3467}
3468
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303469struct mwl8k_cmd_update_mac_addr {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003470 struct mwl8k_cmd_pkt header;
3471 union {
3472 struct {
3473 __le16 mac_type;
3474 __u8 mac_addr[ETH_ALEN];
3475 } mbss;
3476 __u8 mac_addr[ETH_ALEN];
3477 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00003478} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003479
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003480#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3481#define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3482#define MWL8K_MAC_TYPE_PRIMARY_AP 2
3483#define MWL8K_MAC_TYPE_SECONDARY_AP 3
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01003484
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303485static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
3486 struct ieee80211_vif *vif, u8 *mac, bool set)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003487{
3488 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003489 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303490 struct mwl8k_cmd_update_mac_addr *cmd;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003491 int mac_type;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003492 int rc;
3493
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003494 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3495 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3496 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
3497 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
3498 else
3499 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3500 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3501 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3502 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3503 else
3504 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3505 }
3506
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003507 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3508 if (cmd == NULL)
3509 return -ENOMEM;
3510
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303511 if (set)
3512 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3513 else
3514 cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
3515
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003516 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3517 if (priv->ap_fw) {
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003518 cmd->mbss.mac_type = cpu_to_le16(mac_type);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003519 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3520 } else {
3521 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3522 }
3523
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003524 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003525 kfree(cmd);
3526
3527 return rc;
3528}
3529
3530/*
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303531 * MWL8K_CMD_SET_MAC_ADDR.
3532 */
3533static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3534 struct ieee80211_vif *vif, u8 *mac)
3535{
3536 return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
3537}
3538
3539/*
3540 * MWL8K_CMD_DEL_MAC_ADDR.
3541 */
3542static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
3543 struct ieee80211_vif *vif, u8 *mac)
3544{
3545 return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
3546}
3547
3548/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003549 * CMD_SET_RATEADAPT_MODE.
3550 */
3551struct mwl8k_cmd_set_rate_adapt_mode {
3552 struct mwl8k_cmd_pkt header;
3553 __le16 action;
3554 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003555} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003556
3557static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3558{
3559 struct mwl8k_cmd_set_rate_adapt_mode *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_SET_RATEADAPT_MODE);
3567 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3568 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3569 cmd->mode = cpu_to_le16(mode);
3570
3571 rc = mwl8k_post_cmd(hw, &cmd->header);
3572 kfree(cmd);
3573
3574 return rc;
3575}
3576
3577/*
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003578 * CMD_GET_WATCHDOG_BITMAP.
3579 */
3580struct mwl8k_cmd_get_watchdog_bitmap {
3581 struct mwl8k_cmd_pkt header;
3582 u8 bitmap;
3583} __packed;
3584
3585static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
3586{
3587 struct mwl8k_cmd_get_watchdog_bitmap *cmd;
3588 int rc;
3589
3590 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3591 if (cmd == NULL)
3592 return -ENOMEM;
3593
3594 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
3595 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3596
3597 rc = mwl8k_post_cmd(hw, &cmd->header);
3598 if (!rc)
3599 *bitmap = cmd->bitmap;
3600
3601 kfree(cmd);
3602
3603 return rc;
3604}
3605
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303606#define MWL8K_WMM_QUEUE_NUMBER 3
3607
3608static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3609 u8 idx);
3610
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003611static void mwl8k_watchdog_ba_events(struct work_struct *work)
3612{
3613 int rc;
3614 u8 bitmap = 0, stream_index;
3615 struct mwl8k_ampdu_stream *streams;
3616 struct mwl8k_priv *priv =
3617 container_of(work, struct mwl8k_priv, watchdog_ba_handle);
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303618 struct ieee80211_hw *hw = priv->hw;
3619 int i;
3620 u32 status = 0;
3621
3622 mwl8k_fw_lock(hw);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003623
3624 rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
3625 if (rc)
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303626 goto done;
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003627
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303628 spin_lock(&priv->stream_lock);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003629
3630 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303631 for (i = 0; i < TOTAL_HW_TX_QUEUES; i++) {
3632 if (bitmap & (1 << i)) {
3633 stream_index = (i + MWL8K_WMM_QUEUE_NUMBER) %
3634 TOTAL_HW_TX_QUEUES;
3635 streams = &priv->ampdu[stream_index];
3636 if (streams->state == AMPDU_STREAM_ACTIVE) {
3637 ieee80211_stop_tx_ba_session(streams->sta,
3638 streams->tid);
3639 spin_unlock(&priv->stream_lock);
3640 mwl8k_destroy_ba(hw, stream_index);
3641 spin_lock(&priv->stream_lock);
3642 }
3643 }
3644 }
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003645
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303646 spin_unlock(&priv->stream_lock);
3647done:
3648 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3649 iowrite32((status | MWL8K_A2H_INT_BA_WATCHDOG),
3650 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3651 mwl8k_fw_unlock(hw);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003652 return;
3653}
3654
3655
3656/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003657 * CMD_BSS_START.
3658 */
3659struct mwl8k_cmd_bss_start {
3660 struct mwl8k_cmd_pkt header;
3661 __le32 enable;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003662} __packed;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003663
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003664static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3665 struct ieee80211_vif *vif, int enable)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003666{
3667 struct mwl8k_cmd_bss_start *cmd;
3668 int rc;
3669
3670 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3671 if (cmd == NULL)
3672 return -ENOMEM;
3673
3674 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3675 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3676 cmd->enable = cpu_to_le32(enable);
3677
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003678 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003679 kfree(cmd);
3680
3681 return rc;
3682}
3683
3684/*
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003685 * CMD_BASTREAM.
3686 */
3687
3688/*
3689 * UPSTREAM is tx direction
3690 */
3691#define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3692#define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3693
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303694enum ba_stream_action_type {
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003695 MWL8K_BA_CREATE,
3696 MWL8K_BA_UPDATE,
3697 MWL8K_BA_DESTROY,
3698 MWL8K_BA_FLUSH,
3699 MWL8K_BA_CHECK,
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303700};
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003701
3702
3703struct mwl8k_create_ba_stream {
3704 __le32 flags;
3705 __le32 idle_thrs;
3706 __le32 bar_thrs;
3707 __le32 window_size;
3708 u8 peer_mac_addr[6];
3709 u8 dialog_token;
3710 u8 tid;
3711 u8 queue_id;
3712 u8 param_info;
3713 __le32 ba_context;
3714 u8 reset_seq_no_flag;
3715 __le16 curr_seq_no;
3716 u8 sta_src_mac_addr[6];
3717} __packed;
3718
3719struct mwl8k_destroy_ba_stream {
3720 __le32 flags;
3721 __le32 ba_context;
3722} __packed;
3723
3724struct mwl8k_cmd_bastream {
3725 struct mwl8k_cmd_pkt header;
3726 __le32 action;
3727 union {
3728 struct mwl8k_create_ba_stream create_params;
3729 struct mwl8k_destroy_ba_stream destroy_params;
3730 };
3731} __packed;
3732
3733static int
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303734mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3735 struct ieee80211_vif *vif)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003736{
3737 struct mwl8k_cmd_bastream *cmd;
3738 int rc;
3739
3740 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3741 if (cmd == NULL)
3742 return -ENOMEM;
3743
3744 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3745 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3746
3747 cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
3748
3749 cmd->create_params.queue_id = stream->idx;
3750 memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
3751 ETH_ALEN);
3752 cmd->create_params.tid = stream->tid;
3753
3754 cmd->create_params.flags =
3755 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
3756 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
3757
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303758 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003759
3760 kfree(cmd);
3761
3762 return rc;
3763}
3764
3765static int
3766mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303767 u8 buf_size, struct ieee80211_vif *vif)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003768{
3769 struct mwl8k_cmd_bastream *cmd;
3770 int rc;
3771
3772 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3773 if (cmd == NULL)
3774 return -ENOMEM;
3775
3776
3777 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3778 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3779
3780 cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
3781
3782 cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
3783 cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
3784 cmd->create_params.queue_id = stream->idx;
3785
3786 memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
3787 cmd->create_params.tid = stream->tid;
3788 cmd->create_params.curr_seq_no = cpu_to_le16(0);
3789 cmd->create_params.reset_seq_no_flag = 1;
3790
3791 cmd->create_params.param_info =
3792 (stream->sta->ht_cap.ampdu_factor &
3793 IEEE80211_HT_AMPDU_PARM_FACTOR) |
3794 ((stream->sta->ht_cap.ampdu_density << 2) &
3795 IEEE80211_HT_AMPDU_PARM_DENSITY);
3796
3797 cmd->create_params.flags =
3798 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
3799 BASTREAM_FLAG_DIRECTION_UPSTREAM);
3800
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303801 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003802
3803 wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
3804 stream->sta->addr, stream->tid);
3805 kfree(cmd);
3806
3807 return rc;
3808}
3809
3810static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303811 u8 idx)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003812{
3813 struct mwl8k_cmd_bastream *cmd;
3814
3815 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3816 if (cmd == NULL)
3817 return;
3818
3819 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3820 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3821 cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
3822
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303823 cmd->destroy_params.ba_context = cpu_to_le32(idx);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003824 mwl8k_post_cmd(hw, &cmd->header);
3825
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303826 wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", idx);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003827
3828 kfree(cmd);
3829}
3830
3831/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003832 * CMD_SET_NEW_STN.
3833 */
3834struct mwl8k_cmd_set_new_stn {
3835 struct mwl8k_cmd_pkt header;
3836 __le16 aid;
3837 __u8 mac_addr[6];
3838 __le16 stn_id;
3839 __le16 action;
3840 __le16 rsvd;
3841 __le32 legacy_rates;
3842 __u8 ht_rates[4];
3843 __le16 cap_info;
3844 __le16 ht_capabilities_info;
3845 __u8 mac_ht_param_info;
3846 __u8 rev;
3847 __u8 control_channel;
3848 __u8 add_channel;
3849 __le16 op_mode;
3850 __le16 stbc;
3851 __u8 add_qos_info;
3852 __u8 is_qos_sta;
3853 __le32 fw_sta_ptr;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003854} __packed;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003855
3856#define MWL8K_STA_ACTION_ADD 0
3857#define MWL8K_STA_ACTION_REMOVE 2
3858
3859static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3860 struct ieee80211_vif *vif,
3861 struct ieee80211_sta *sta)
3862{
3863 struct mwl8k_cmd_set_new_stn *cmd;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003864 u32 rates;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003865 int rc;
3866
3867 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3868 if (cmd == NULL)
3869 return -ENOMEM;
3870
3871 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3872 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3873 cmd->aid = cpu_to_le16(sta->aid);
3874 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3875 cmd->stn_id = cpu_to_le16(sta->aid);
3876 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003877 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3878 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3879 else
3880 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3881 cmd->legacy_rates = cpu_to_le32(rates);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003882 if (sta->ht_cap.ht_supported) {
3883 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3884 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3885 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3886 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3887 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3888 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3889 ((sta->ht_cap.ampdu_density & 7) << 2);
3890 cmd->is_qos_sta = 1;
3891 }
3892
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003893 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003894 kfree(cmd);
3895
3896 return rc;
3897}
3898
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003899static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3900 struct ieee80211_vif *vif)
3901{
3902 struct mwl8k_cmd_set_new_stn *cmd;
3903 int rc;
3904
3905 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3906 if (cmd == NULL)
3907 return -ENOMEM;
3908
3909 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3910 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3911 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3912
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003913 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003914 kfree(cmd);
3915
3916 return rc;
3917}
3918
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003919static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
3920 struct ieee80211_vif *vif, u8 *addr)
3921{
3922 struct mwl8k_cmd_set_new_stn *cmd;
3923 int rc;
3924
3925 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3926 if (cmd == NULL)
3927 return -ENOMEM;
3928
3929 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3930 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3931 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3932 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
3933
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003934 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003935 kfree(cmd);
3936
3937 return rc;
3938}
3939
3940/*
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08003941 * CMD_UPDATE_ENCRYPTION.
3942 */
3943
3944#define MAX_ENCR_KEY_LENGTH 16
3945#define MIC_KEY_LENGTH 8
3946
3947struct mwl8k_cmd_update_encryption {
3948 struct mwl8k_cmd_pkt header;
3949
3950 __le32 action;
3951 __le32 reserved;
3952 __u8 mac_addr[6];
3953 __u8 encr_type;
3954
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303955} __packed;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08003956
3957struct mwl8k_cmd_set_key {
3958 struct mwl8k_cmd_pkt header;
3959
3960 __le32 action;
3961 __le32 reserved;
3962 __le16 length;
3963 __le16 key_type_id;
3964 __le32 key_info;
3965 __le32 key_id;
3966 __le16 key_len;
3967 __u8 key_material[MAX_ENCR_KEY_LENGTH];
3968 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
3969 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
3970 __le16 tkip_rsc_low;
3971 __le32 tkip_rsc_high;
3972 __le16 tkip_tsc_low;
3973 __le32 tkip_tsc_high;
3974 __u8 mac_addr[6];
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303975} __packed;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08003976
3977enum {
3978 MWL8K_ENCR_ENABLE,
3979 MWL8K_ENCR_SET_KEY,
3980 MWL8K_ENCR_REMOVE_KEY,
3981 MWL8K_ENCR_SET_GROUP_KEY,
3982};
3983
3984#define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
3985#define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
3986#define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
3987#define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
3988#define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
3989
3990enum {
3991 MWL8K_ALG_WEP,
3992 MWL8K_ALG_TKIP,
3993 MWL8K_ALG_CCMP,
3994};
3995
3996#define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
3997#define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
3998#define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
3999#define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
4000#define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
4001
4002static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
4003 struct ieee80211_vif *vif,
4004 u8 *addr,
4005 u8 encr_type)
4006{
4007 struct mwl8k_cmd_update_encryption *cmd;
4008 int rc;
4009
4010 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4011 if (cmd == NULL)
4012 return -ENOMEM;
4013
4014 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4015 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4016 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
4017 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4018 cmd->encr_type = encr_type;
4019
4020 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4021 kfree(cmd);
4022
4023 return rc;
4024}
4025
4026static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
4027 u8 *addr,
4028 struct ieee80211_key_conf *key)
4029{
4030 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4031 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4032 cmd->length = cpu_to_le16(sizeof(*cmd) -
4033 offsetof(struct mwl8k_cmd_set_key, length));
4034 cmd->key_id = cpu_to_le32(key->keyidx);
4035 cmd->key_len = cpu_to_le16(key->keylen);
4036 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4037
4038 switch (key->cipher) {
4039 case WLAN_CIPHER_SUITE_WEP40:
4040 case WLAN_CIPHER_SUITE_WEP104:
4041 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
4042 if (key->keyidx == 0)
4043 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
4044
4045 break;
4046 case WLAN_CIPHER_SUITE_TKIP:
4047 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
4048 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4049 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4050 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4051 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
4052 | MWL8K_KEY_FLAG_TSC_VALID);
4053 break;
4054 case WLAN_CIPHER_SUITE_CCMP:
4055 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
4056 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4057 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4058 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4059 break;
4060 default:
4061 return -ENOTSUPP;
4062 }
4063
4064 return 0;
4065}
4066
4067static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
4068 struct ieee80211_vif *vif,
4069 u8 *addr,
4070 struct ieee80211_key_conf *key)
4071{
4072 struct mwl8k_cmd_set_key *cmd;
4073 int rc;
4074 int keymlen;
4075 u32 action;
4076 u8 idx;
4077 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4078
4079 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4080 if (cmd == NULL)
4081 return -ENOMEM;
4082
4083 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4084 if (rc < 0)
4085 goto done;
4086
4087 idx = key->keyidx;
4088
4089 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4090 action = MWL8K_ENCR_SET_KEY;
4091 else
4092 action = MWL8K_ENCR_SET_GROUP_KEY;
4093
4094 switch (key->cipher) {
4095 case WLAN_CIPHER_SUITE_WEP40:
4096 case WLAN_CIPHER_SUITE_WEP104:
4097 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
4098 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
4099 sizeof(*key) + key->keylen);
4100 mwl8k_vif->wep_key_conf[idx].enabled = 1;
4101 }
4102
Yogesh Ashok Powar9b571e22011-05-04 17:22:16 +05304103 keymlen = key->keylen;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004104 action = MWL8K_ENCR_SET_KEY;
4105 break;
4106 case WLAN_CIPHER_SUITE_TKIP:
4107 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
4108 break;
4109 case WLAN_CIPHER_SUITE_CCMP:
4110 keymlen = key->keylen;
4111 break;
4112 default:
4113 rc = -ENOTSUPP;
4114 goto done;
4115 }
4116
4117 memcpy(cmd->key_material, key->key, keymlen);
4118 cmd->action = cpu_to_le32(action);
4119
4120 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4121done:
4122 kfree(cmd);
4123
4124 return rc;
4125}
4126
4127static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
4128 struct ieee80211_vif *vif,
4129 u8 *addr,
4130 struct ieee80211_key_conf *key)
4131{
4132 struct mwl8k_cmd_set_key *cmd;
4133 int rc;
4134 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4135
4136 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4137 if (cmd == NULL)
4138 return -ENOMEM;
4139
4140 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4141 if (rc < 0)
4142 goto done;
4143
4144 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
Dan Carpenterd981e052012-01-17 10:33:31 +03004145 key->cipher == WLAN_CIPHER_SUITE_WEP104)
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004146 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
4147
4148 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
4149
4150 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4151done:
4152 kfree(cmd);
4153
4154 return rc;
4155}
4156
4157static int mwl8k_set_key(struct ieee80211_hw *hw,
4158 enum set_key_cmd cmd_param,
4159 struct ieee80211_vif *vif,
4160 struct ieee80211_sta *sta,
4161 struct ieee80211_key_conf *key)
4162{
4163 int rc = 0;
4164 u8 encr_type;
4165 u8 *addr;
4166 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4167
4168 if (vif->type == NL80211_IFTYPE_STATION)
4169 return -EOPNOTSUPP;
4170
4171 if (sta == NULL)
Yogesh Ashok Powarff7e9f92012-01-27 16:08:27 +05304172 addr = vif->addr;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004173 else
4174 addr = sta->addr;
4175
4176 if (cmd_param == SET_KEY) {
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004177 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
4178 if (rc)
4179 goto out;
4180
4181 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
4182 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
4183 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
4184 else
4185 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
4186
4187 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
4188 encr_type);
4189 if (rc)
4190 goto out;
4191
4192 mwl8k_vif->is_hw_crypto_enabled = true;
4193
4194 } else {
4195 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
4196
4197 if (rc)
4198 goto out;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004199 }
4200out:
4201 return rc;
4202}
4203
4204/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004205 * CMD_UPDATE_STADB.
4206 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004207struct ewc_ht_info {
4208 __le16 control1;
4209 __le16 control2;
4210 __le16 control3;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004211} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004212
4213struct peer_capability_info {
4214 /* Peer type - AP vs. STA. */
4215 __u8 peer_type;
4216
4217 /* Basic 802.11 capabilities from assoc resp. */
4218 __le16 basic_caps;
4219
4220 /* Set if peer supports 802.11n high throughput (HT). */
4221 __u8 ht_support;
4222
4223 /* Valid if HT is supported. */
4224 __le16 ht_caps;
4225 __u8 extended_ht_caps;
4226 struct ewc_ht_info ewc_info;
4227
4228 /* Legacy rate table. Intersection of our rates and peer rates. */
4229 __u8 legacy_rates[12];
4230
4231 /* HT rate table. Intersection of our rates and peer rates. */
4232 __u8 ht_rates[16];
4233 __u8 pad[16];
4234
4235 /* If set, interoperability mode, no proprietary extensions. */
4236 __u8 interop;
4237 __u8 pad2;
4238 __u8 station_id;
4239 __le16 amsdu_enabled;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004240} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004241
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004242struct mwl8k_cmd_update_stadb {
4243 struct mwl8k_cmd_pkt header;
4244
4245 /* See STADB_ACTION_TYPE */
4246 __le32 action;
4247
4248 /* Peer MAC address */
4249 __u8 peer_addr[ETH_ALEN];
4250
4251 __le32 reserved;
4252
4253 /* Peer info - valid during add/update. */
4254 struct peer_capability_info peer_info;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004255} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004256
Lennert Buytenheka6804002010-01-04 21:55:42 +01004257#define MWL8K_STA_DB_MODIFY_ENTRY 1
4258#define MWL8K_STA_DB_DEL_ENTRY 2
4259
4260/* Peer Entry flags - used to define the type of the peer node */
4261#define MWL8K_PEER_TYPE_ACCESSPOINT 2
4262
4263static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004264 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004265 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004266{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004267 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01004268 struct peer_capability_info *p;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004269 u32 rates;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004270 int rc;
4271
4272 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4273 if (cmd == NULL)
4274 return -ENOMEM;
4275
4276 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4277 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01004278 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004279 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004280
Lennert Buytenheka6804002010-01-04 21:55:42 +01004281 p = &cmd->peer_info;
4282 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
4283 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004284 p->ht_support = sta->ht_cap.ht_supported;
John W. Linvilleb6037422010-07-20 13:55:00 -04004285 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004286 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
4287 ((sta->ht_cap.ampdu_density & 7) << 2);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004288 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4289 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
4290 else
4291 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4292 legacy_rate_mask_to_array(p->legacy_rates, rates);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004293 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01004294 p->interop = 1;
4295 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004296
Lennert Buytenheka6804002010-01-04 21:55:42 +01004297 rc = mwl8k_post_cmd(hw, &cmd->header);
4298 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004299
Lennert Buytenheka6804002010-01-04 21:55:42 +01004300 return rc ? rc : p->station_id;
4301}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004302
Lennert Buytenheka6804002010-01-04 21:55:42 +01004303static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
4304 struct ieee80211_vif *vif, u8 *addr)
4305{
4306 struct mwl8k_cmd_update_stadb *cmd;
4307 int rc;
4308
4309 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4310 if (cmd == NULL)
4311 return -ENOMEM;
4312
4313 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4314 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4315 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
4316 memcpy(cmd->peer_addr, addr, ETH_ALEN);
4317
4318 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004319 kfree(cmd);
4320
4321 return rc;
4322}
4323
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004324
4325/*
4326 * Interrupt handling.
4327 */
4328static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
4329{
4330 struct ieee80211_hw *hw = dev_id;
4331 struct mwl8k_priv *priv = hw->priv;
4332 u32 status;
4333
4334 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004335 if (!status)
4336 return IRQ_NONE;
4337
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004338 if (status & MWL8K_A2H_INT_TX_DONE) {
4339 status &= ~MWL8K_A2H_INT_TX_DONE;
4340 tasklet_schedule(&priv->poll_tx_task);
4341 }
4342
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004343 if (status & MWL8K_A2H_INT_RX_READY) {
4344 status &= ~MWL8K_A2H_INT_RX_READY;
4345 tasklet_schedule(&priv->poll_rx_task);
4346 }
4347
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07004348 if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
4349 status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
4350 ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
4351 }
4352
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004353 if (status)
4354 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004355
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004356 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004357 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004358 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004359 }
4360
4361 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004362 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02004363 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004364 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004365 }
4366
4367 return IRQ_HANDLED;
4368}
4369
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004370static void mwl8k_tx_poll(unsigned long data)
4371{
4372 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4373 struct mwl8k_priv *priv = hw->priv;
4374 int limit;
4375 int i;
4376
4377 limit = 32;
4378
4379 spin_lock_bh(&priv->tx_lock);
4380
Brian Cavagnoloe6007072011-03-17 11:58:44 -07004381 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004382 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
4383
4384 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
4385 complete(priv->tx_wait);
4386 priv->tx_wait = NULL;
4387 }
4388
4389 spin_unlock_bh(&priv->tx_lock);
4390
4391 if (limit) {
4392 writel(~MWL8K_A2H_INT_TX_DONE,
4393 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4394 } else {
4395 tasklet_schedule(&priv->poll_tx_task);
4396 }
4397}
4398
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004399static void mwl8k_rx_poll(unsigned long data)
4400{
4401 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4402 struct mwl8k_priv *priv = hw->priv;
4403 int limit;
4404
4405 limit = 32;
4406 limit -= rxq_process(hw, 0, limit);
4407 limit -= rxq_refill(hw, 0, limit);
4408
4409 if (limit) {
4410 writel(~MWL8K_A2H_INT_RX_READY,
4411 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4412 } else {
4413 tasklet_schedule(&priv->poll_rx_task);
4414 }
4415}
4416
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004417
4418/*
4419 * Core driver operations.
4420 */
Thomas Huehn36323f82012-07-23 21:33:42 +02004421static void mwl8k_tx(struct ieee80211_hw *hw,
4422 struct ieee80211_tx_control *control,
4423 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004424{
4425 struct mwl8k_priv *priv = hw->priv;
4426 int index = skb_get_queue_mapping(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004427
Lennert Buytenhek9189c102010-01-12 13:47:32 +01004428 if (!priv->radio_on) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004429 wiphy_debug(hw->wiphy,
4430 "dropped TX frame since radio disabled\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004431 dev_kfree_skb(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +01004432 return;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004433 }
4434
Thomas Huehn36323f82012-07-23 21:33:42 +02004435 mwl8k_txq_xmit(hw, index, control->sta, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004436}
4437
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004438static int mwl8k_start(struct ieee80211_hw *hw)
4439{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004440 struct mwl8k_priv *priv = hw->priv;
4441 int rc;
4442
Joe Perchesa0607fd2009-11-18 23:29:17 -08004443 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004444 IRQF_SHARED, MWL8K_NAME, hw);
4445 if (rc) {
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304446 priv->irq = -1;
Joe Perches5db55842010-08-11 19:11:19 -07004447 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004448 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004449 }
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304450 priv->irq = priv->pdev->irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004451
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004452 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004453 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004454 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004455
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004456 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004457 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Nishant Sarmukadam12488e02011-04-08 14:38:27 +05304458 iowrite32(MWL8K_A2H_EVENTS,
4459 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004460
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004461 rc = mwl8k_fw_lock(hw);
4462 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004463 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004464
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02004465 if (!priv->ap_fw) {
4466 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004467 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004468
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02004469 if (!rc)
4470 rc = mwl8k_cmd_set_pre_scan(hw);
4471
4472 if (!rc)
4473 rc = mwl8k_cmd_set_post_scan(hw,
4474 "\x00\x00\x00\x00\x00\x00");
4475 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004476
4477 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004478 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004479
4480 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004481 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004482
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004483 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004484 }
4485
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004486 if (rc) {
4487 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4488 free_irq(priv->pdev->irq, hw);
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304489 priv->irq = -1;
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004490 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004491 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004492 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004493
4494 return rc;
4495}
4496
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004497static void mwl8k_stop(struct ieee80211_hw *hw)
4498{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004499 struct mwl8k_priv *priv = hw->priv;
4500 int i;
4501
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304502 if (!priv->hw_restart_in_progress)
4503 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004504
4505 ieee80211_stop_queues(hw);
4506
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004507 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004508 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304509 if (priv->irq != -1) {
4510 free_irq(priv->pdev->irq, hw);
4511 priv->irq = -1;
4512 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004513
4514 /* Stop finalize join worker */
4515 cancel_work_sync(&priv->finalize_join_worker);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07004516 cancel_work_sync(&priv->watchdog_ba_handle);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004517 if (priv->beacon_skb != NULL)
4518 dev_kfree_skb(priv->beacon_skb);
4519
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004520 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004521 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004522 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004523
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004524 /* Return all skbs to mac80211 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07004525 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004526 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004527}
4528
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004529static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
4530
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004531static int mwl8k_add_interface(struct ieee80211_hw *hw,
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004532 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004533{
4534 struct mwl8k_priv *priv = hw->priv;
4535 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004536 u32 macids_supported;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004537 int macid, rc;
4538 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004539
4540 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004541 * Reject interface creation if sniffer mode is active, as
4542 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004543 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004544 */
4545 if (priv->sniffer_enabled) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004546 wiphy_info(hw->wiphy,
4547 "unable to create STA interface because sniffer mode is enabled\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004548 return -EINVAL;
4549 }
4550
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004551 di = priv->device_info;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004552 switch (vif->type) {
4553 case NL80211_IFTYPE_AP:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004554 if (!priv->ap_fw && di->fw_image_ap) {
4555 /* we must load the ap fw to meet this request */
4556 if (!list_empty(&priv->vif_list))
4557 return -EBUSY;
4558 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4559 if (rc)
4560 return rc;
4561 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004562 macids_supported = priv->ap_macids_supported;
4563 break;
4564 case NL80211_IFTYPE_STATION:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004565 if (priv->ap_fw && di->fw_image_sta) {
4566 /* we must load the sta fw to meet this request */
4567 if (!list_empty(&priv->vif_list))
4568 return -EBUSY;
4569 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4570 if (rc)
4571 return rc;
4572 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004573 macids_supported = priv->sta_macids_supported;
4574 break;
4575 default:
4576 return -EINVAL;
4577 }
4578
4579 macid = ffs(macids_supported & ~priv->macids_used);
4580 if (!macid--)
4581 return -EBUSY;
4582
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004583 /* Setup driver private area. */
Johannes Berg1ed32e42009-12-23 13:15:45 +01004584 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004585 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004586 mwl8k_vif->vif = vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004587 mwl8k_vif->macid = macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004588 mwl8k_vif->seqno = 0;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08004589 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
4590 mwl8k_vif->is_hw_crypto_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004591
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004592 /* Set the mac address. */
4593 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
4594
4595 if (priv->ap_fw)
4596 mwl8k_cmd_set_new_stn_add_self(hw, vif);
4597
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004598 priv->macids_used |= 1 << mwl8k_vif->macid;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004599 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004600
4601 return 0;
4602}
4603
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304604static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
4605{
4606 /* Has ieee80211_restart_hw re-added the removed interfaces? */
4607 if (!priv->macids_used)
4608 return;
4609
4610 priv->macids_used &= ~(1 << vif->macid);
4611 list_del(&vif->list);
4612}
4613
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004614static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01004615 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004616{
4617 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004618 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004619
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004620 if (priv->ap_fw)
4621 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
4622
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05304623 mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004624
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304625 mwl8k_remove_vif(priv, mwl8k_vif);
4626}
4627
4628static void mwl8k_hw_restart_work(struct work_struct *work)
4629{
4630 struct mwl8k_priv *priv =
4631 container_of(work, struct mwl8k_priv, fw_reload);
4632 struct ieee80211_hw *hw = priv->hw;
4633 struct mwl8k_device_info *di;
4634 int rc;
4635
4636 /* If some command is waiting for a response, clear it */
4637 if (priv->hostcmd_wait != NULL) {
4638 complete(priv->hostcmd_wait);
4639 priv->hostcmd_wait = NULL;
4640 }
4641
4642 priv->hw_restart_owner = current;
4643 di = priv->device_info;
4644 mwl8k_fw_lock(hw);
4645
4646 if (priv->ap_fw)
4647 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4648 else
4649 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4650
4651 if (rc)
4652 goto fail;
4653
4654 priv->hw_restart_owner = NULL;
4655 priv->hw_restart_in_progress = false;
4656
4657 /*
4658 * This unlock will wake up the queues and
4659 * also opens the command path for other
4660 * commands
4661 */
4662 mwl8k_fw_unlock(hw);
4663
4664 ieee80211_restart_hw(hw);
4665
4666 wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
4667
4668 return;
4669fail:
4670 mwl8k_fw_unlock(hw);
4671
4672 wiphy_err(hw->wiphy, "Firmware restart failed\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004673}
4674
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004675static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004676{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004677 struct ieee80211_conf *conf = &hw->conf;
4678 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004679 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004680
Lennert Buytenhek7595d672009-08-17 23:59:40 +02004681 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004682 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004683 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02004684 }
4685
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004686 rc = mwl8k_fw_lock(hw);
4687 if (rc)
4688 return rc;
4689
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004690 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004691 if (rc)
4692 goto out;
4693
Lennert Buytenhek610677d2010-01-04 21:56:46 +01004694 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004695 if (rc)
4696 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004697
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004698 if (conf->power_level > 18)
4699 conf->power_level = 18;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004700
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004701 if (priv->ap_fw) {
Nishant Sarmukadam03217082011-04-05 14:18:09 +05304702
4703 if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
4704 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
4705 if (rc)
4706 goto out;
4707 }
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08004708
Nishant Sarmukadamda62b762011-02-17 14:45:16 -08004709 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
4710 if (rc)
4711 wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
4712 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
4713 if (rc)
4714 wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
4715
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004716 } else {
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08004717 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
4718 if (rc)
4719 goto out;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004720 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
4721 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004722
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004723out:
4724 mwl8k_fw_unlock(hw);
4725
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004726 return rc;
4727}
4728
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004729static void
4730mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4731 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004732{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004733 struct mwl8k_priv *priv = hw->priv;
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05304734 u32 ap_legacy_rates = 0;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004735 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004736 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004737
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004738 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004739 return;
4740
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004741 /*
4742 * No need to capture a beacon if we're no longer associated.
4743 */
4744 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
4745 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004746
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004747 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004748 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004749 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004750 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004751 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01004752
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004753 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004754
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004755 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004756 if (ap == NULL) {
4757 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004758 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004759 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004760
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004761 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
4762 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
4763 } else {
4764 ap_legacy_rates =
4765 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4766 }
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004767 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004768
4769 rcu_read_unlock();
4770 }
4771
4772 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004773 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004774 if (rc)
4775 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004776
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01004777 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004778 if (rc)
4779 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004780 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004781
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004782 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004783 rc = mwl8k_set_radio_preamble(hw,
4784 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004785 if (rc)
4786 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004787 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004788
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004789 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004790 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004791 if (rc)
4792 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004793 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004794
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01004795 if (vif->bss_conf.assoc &&
4796 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4797 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004798 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004799 if (rc)
4800 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004801 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004802
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004803 if (vif->bss_conf.assoc &&
4804 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004805 /*
4806 * Finalize the join. Tell rx handler to process
4807 * next beacon from our BSSID.
4808 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01004809 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004810 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004811 }
4812
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004813out:
4814 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004815}
4816
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004817static void
4818mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4819 struct ieee80211_bss_conf *info, u32 changed)
4820{
4821 int rc;
4822
4823 if (mwl8k_fw_lock(hw))
4824 return;
4825
4826 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4827 rc = mwl8k_set_radio_preamble(hw,
4828 vif->bss_conf.use_short_preamble);
4829 if (rc)
4830 goto out;
4831 }
4832
4833 if (changed & BSS_CHANGED_BASIC_RATES) {
4834 int idx;
4835 int rate;
4836
4837 /*
4838 * Use lowest supported basic rate for multicasts
4839 * and management frames (such as probe responses --
4840 * beacons will always go out at 1 Mb/s).
4841 */
4842 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004843 if (idx)
4844 idx--;
4845
4846 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4847 rate = mwl8k_rates_24[idx].hw_value;
4848 else
4849 rate = mwl8k_rates_50[idx].hw_value;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004850
4851 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4852 }
4853
4854 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
4855 struct sk_buff *skb;
4856
4857 skb = ieee80211_beacon_get(hw, vif);
4858 if (skb != NULL) {
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004859 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004860 kfree_skb(skb);
4861 }
4862 }
4863
4864 if (changed & BSS_CHANGED_BEACON_ENABLED)
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004865 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004866
4867out:
4868 mwl8k_fw_unlock(hw);
4869}
4870
4871static void
4872mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4873 struct ieee80211_bss_conf *info, u32 changed)
4874{
4875 struct mwl8k_priv *priv = hw->priv;
4876
4877 if (!priv->ap_fw)
4878 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
4879 else
4880 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
4881}
4882
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004883static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad2010-04-01 21:22:57 +00004884 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004885{
4886 struct mwl8k_cmd_pkt *cmd;
4887
Lennert Buytenhek447ced02009-10-22 20:19:50 +02004888 /*
4889 * Synthesize and return a command packet that programs the
4890 * hardware multicast address filter. At this point we don't
4891 * know whether FIF_ALLMULTI is being requested, but if it is,
4892 * we'll end up throwing this packet away and creating a new
4893 * one in mwl8k_configure_filter().
4894 */
Jiri Pirko22bedad2010-04-01 21:22:57 +00004895 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004896
4897 return (unsigned long)cmd;
4898}
4899
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004900static int
4901mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
4902 unsigned int changed_flags,
4903 unsigned int *total_flags)
4904{
4905 struct mwl8k_priv *priv = hw->priv;
4906
4907 /*
4908 * Hardware sniffer mode is mutually exclusive with STA
4909 * operation, so refuse to enable sniffer mode if a STA
4910 * interface is active.
4911 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004912 if (!list_empty(&priv->vif_list)) {
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004913 if (net_ratelimit())
Joe Perchesc96c31e2010-07-26 14:39:58 -07004914 wiphy_info(hw->wiphy,
4915 "not enabling sniffer mode because STA interface is active\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004916 return 0;
4917 }
4918
4919 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004920 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004921 return 0;
4922 priv->sniffer_enabled = true;
4923 }
4924
4925 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
4926 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
4927 FIF_OTHER_BSS;
4928
4929 return 1;
4930}
4931
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004932static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
4933{
4934 if (!list_empty(&priv->vif_list))
4935 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
4936
4937 return NULL;
4938}
4939
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004940static void mwl8k_configure_filter(struct ieee80211_hw *hw,
4941 unsigned int changed_flags,
4942 unsigned int *total_flags,
4943 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004944{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004945 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004946 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
4947
4948 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02004949 * AP firmware doesn't allow fine-grained control over
4950 * the receive filter.
4951 */
4952 if (priv->ap_fw) {
4953 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4954 kfree(cmd);
4955 return;
4956 }
4957
4958 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004959 * Enable hardware sniffer mode if FIF_CONTROL or
4960 * FIF_OTHER_BSS is requested.
4961 */
4962 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
4963 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
4964 kfree(cmd);
4965 return;
4966 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004967
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004968 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02004969 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004970
Lennert Buytenhek90852f72010-01-02 10:31:42 +01004971 if (mwl8k_fw_lock(hw)) {
4972 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004973 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01004974 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004975
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004976 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004977 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004978 priv->sniffer_enabled = false;
4979 }
4980
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004981 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02004982 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
4983 /*
4984 * Disable the BSS filter.
4985 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004986 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02004987 } else {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004988 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01004989 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02004990
Lennert Buytenhek77165d82009-10-22 20:19:53 +02004991 /*
4992 * Enable the BSS filter.
4993 *
4994 * If there is an active STA interface, use that
4995 * interface's BSSID, otherwise use a dummy one
4996 * (where the OUI part needs to be nonzero for
4997 * the BSSID to be accepted by POST_SCAN).
4998 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004999 mwl8k_vif = mwl8k_first_vif(priv);
5000 if (mwl8k_vif != NULL)
5001 bssid = mwl8k_vif->vif->bss_conf.bssid;
5002 else
5003 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02005004
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005005 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005006 }
5007 }
5008
Lennert Buytenhek447ced02009-10-22 20:19:50 +02005009 /*
5010 * If FIF_ALLMULTI is being requested, throw away the command
5011 * packet that ->prepare_multicast() built and replace it with
5012 * a command packet that enables reception of all multicast
5013 * packets.
5014 */
5015 if (*total_flags & FIF_ALLMULTI) {
5016 kfree(cmd);
Jiri Pirko22bedad2010-04-01 21:22:57 +00005017 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
Lennert Buytenhek447ced02009-10-22 20:19:50 +02005018 }
5019
5020 if (cmd != NULL) {
5021 mwl8k_post_cmd(hw, cmd);
5022 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005023 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02005024
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005025 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005026}
5027
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005028static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5029{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01005030 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005031}
5032
Johannes Berg4a6967b2010-02-19 19:18:37 +01005033static int mwl8k_sta_remove(struct ieee80211_hw *hw,
5034 struct ieee80211_vif *vif,
5035 struct ieee80211_sta *sta)
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005036{
5037 struct mwl8k_priv *priv = hw->priv;
5038
Johannes Berg4a6967b2010-02-19 19:18:37 +01005039 if (priv->ap_fw)
5040 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
5041 else
5042 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
5043}
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005044
Johannes Berg4a6967b2010-02-19 19:18:37 +01005045static int mwl8k_sta_add(struct ieee80211_hw *hw,
5046 struct ieee80211_vif *vif,
5047 struct ieee80211_sta *sta)
5048{
5049 struct mwl8k_priv *priv = hw->priv;
5050 int ret;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005051 int i;
5052 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
5053 struct ieee80211_key_conf *key;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005054
Johannes Berg4a6967b2010-02-19 19:18:37 +01005055 if (!priv->ap_fw) {
5056 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
5057 if (ret >= 0) {
5058 MWL8K_STA(sta)->peer_id = ret;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07005059 if (sta->ht_cap.ht_supported)
5060 MWL8K_STA(sta)->is_ampdu_allowed = true;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005061 ret = 0;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005062 }
Johannes Berg4a6967b2010-02-19 19:18:37 +01005063
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08005064 } else {
5065 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005066 }
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005067
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08005068 for (i = 0; i < NUM_WEP_KEYS; i++) {
5069 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
5070 if (mwl8k_vif->wep_key_conf[i].enabled)
5071 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
5072 }
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005073 return ret;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01005074}
5075
Eliad Peller8a3a3c82011-10-02 10:15:52 +02005076static int mwl8k_conf_tx(struct ieee80211_hw *hw,
5077 struct ieee80211_vif *vif, u16 queue,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005078 const struct ieee80211_tx_queue_params *params)
5079{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005080 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005081 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005082
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005083 rc = mwl8k_fw_lock(hw);
5084 if (!rc) {
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005085 BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005086 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
5087
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005088 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005089 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005090
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005091 if (!rc) {
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005092 int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005093 rc = mwl8k_cmd_set_edca_params(hw, q,
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005094 params->cw_min,
5095 params->cw_max,
5096 params->aifs,
5097 params->txop);
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005098 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005099
5100 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005101 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005102
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005103 return rc;
5104}
5105
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005106static int mwl8k_get_stats(struct ieee80211_hw *hw,
5107 struct ieee80211_low_level_stats *stats)
5108{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005109 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005110}
5111
John W. Linville0d462bb2010-07-28 14:04:24 -04005112static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
5113 struct survey_info *survey)
5114{
5115 struct mwl8k_priv *priv = hw->priv;
5116 struct ieee80211_conf *conf = &hw->conf;
5117
5118 if (idx != 0)
5119 return -ENOENT;
5120
5121 survey->channel = conf->channel;
5122 survey->filled = SURVEY_INFO_NOISE_DBM;
5123 survey->noise = priv->noise;
5124
5125 return 0;
5126}
5127
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005128#define MAX_AMPDU_ATTEMPTS 5
5129
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005130static int
5131mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5132 enum ieee80211_ampdu_mlme_action action,
Johannes Berg0b01f032011-01-18 13:51:05 +01005133 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5134 u8 buf_size)
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005135{
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005136
5137 int i, rc = 0;
5138 struct mwl8k_priv *priv = hw->priv;
5139 struct mwl8k_ampdu_stream *stream;
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305140 u8 *addr = sta->addr, idx;
Yogesh Ashok Powarfd712f52012-11-06 19:22:35 +05305141 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005142
5143 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
5144 return -ENOTSUPP;
5145
5146 spin_lock(&priv->stream_lock);
5147 stream = mwl8k_lookup_stream(hw, addr, tid);
5148
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005149 switch (action) {
5150 case IEEE80211_AMPDU_RX_START:
5151 case IEEE80211_AMPDU_RX_STOP:
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005152 break;
5153 case IEEE80211_AMPDU_TX_START:
5154 /* By the time we get here the hw queues may contain outgoing
5155 * packets for this RA/TID that are not part of this BA
5156 * session. The hw will assign sequence numbers to these
5157 * packets as they go out. So if we query the hw for its next
5158 * sequence number and use that for the SSN here, it may end up
5159 * being wrong, which will lead to sequence number mismatch at
5160 * the recipient. To avoid this, we reset the sequence number
5161 * to O for the first MPDU in this BA stream.
5162 */
5163 *ssn = 0;
5164 if (stream == NULL) {
5165 /* This means that somebody outside this driver called
5166 * ieee80211_start_tx_ba_session. This is unexpected
5167 * because we do our own rate control. Just warn and
5168 * move on.
5169 */
5170 wiphy_warn(hw->wiphy, "Unexpected call to %s. "
5171 "Proceeding anyway.\n", __func__);
5172 stream = mwl8k_add_stream(hw, sta, tid);
5173 }
5174 if (stream == NULL) {
5175 wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
5176 rc = -EBUSY;
5177 break;
5178 }
5179 stream->state = AMPDU_STREAM_IN_PROGRESS;
5180
5181 /* Release the lock before we do the time consuming stuff */
5182 spin_unlock(&priv->stream_lock);
5183 for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
Yogesh Ashok Powarfd712f52012-11-06 19:22:35 +05305184
5185 /* Check if link is still valid */
5186 if (!sta_info->is_ampdu_allowed) {
5187 spin_lock(&priv->stream_lock);
5188 mwl8k_remove_stream(hw, stream);
5189 spin_unlock(&priv->stream_lock);
5190 return -EBUSY;
5191 }
5192
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05305193 rc = mwl8k_check_ba(hw, stream, vif);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005194
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305195 /* If HW restart is in progress mwl8k_post_cmd will
5196 * return -EBUSY. Avoid retrying mwl8k_check_ba in
5197 * such cases
5198 */
5199 if (!rc || rc == -EBUSY)
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005200 break;
5201 /*
5202 * HW queues take time to be flushed, give them
5203 * sufficient time
5204 */
5205
5206 msleep(1000);
5207 }
5208 spin_lock(&priv->stream_lock);
5209 if (rc) {
5210 wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
5211 " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
5212 mwl8k_remove_stream(hw, stream);
5213 rc = -EBUSY;
5214 break;
5215 }
5216 ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
5217 break;
Johannes Berg18b559d2012-07-18 13:51:25 +02005218 case IEEE80211_AMPDU_TX_STOP_CONT:
5219 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5220 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305221 if (stream) {
5222 if (stream->state == AMPDU_STREAM_ACTIVE) {
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305223 idx = stream->idx;
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305224 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305225 mwl8k_destroy_ba(hw, idx);
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305226 spin_lock(&priv->stream_lock);
5227 }
5228 mwl8k_remove_stream(hw, stream);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005229 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005230 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
5231 break;
5232 case IEEE80211_AMPDU_TX_OPERATIONAL:
5233 BUG_ON(stream == NULL);
5234 BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
5235 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05305236 rc = mwl8k_create_ba(hw, stream, buf_size, vif);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005237 spin_lock(&priv->stream_lock);
5238 if (!rc)
5239 stream->state = AMPDU_STREAM_ACTIVE;
5240 else {
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305241 idx = stream->idx;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005242 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305243 mwl8k_destroy_ba(hw, idx);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005244 spin_lock(&priv->stream_lock);
5245 wiphy_debug(hw->wiphy,
5246 "Failed adding stream for sta %pM tid %d\n",
5247 addr, tid);
5248 mwl8k_remove_stream(hw, stream);
5249 }
5250 break;
5251
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005252 default:
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005253 rc = -ENOTSUPP;
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005254 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005255
5256 spin_unlock(&priv->stream_lock);
5257 return rc;
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005258}
5259
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005260static const struct ieee80211_ops mwl8k_ops = {
5261 .tx = mwl8k_tx,
5262 .start = mwl8k_start,
5263 .stop = mwl8k_stop,
5264 .add_interface = mwl8k_add_interface,
5265 .remove_interface = mwl8k_remove_interface,
5266 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005267 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02005268 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005269 .configure_filter = mwl8k_configure_filter,
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005270 .set_key = mwl8k_set_key,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005271 .set_rts_threshold = mwl8k_set_rts_threshold,
Johannes Berg4a6967b2010-02-19 19:18:37 +01005272 .sta_add = mwl8k_sta_add,
5273 .sta_remove = mwl8k_sta_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005274 .conf_tx = mwl8k_conf_tx,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005275 .get_stats = mwl8k_get_stats,
John W. Linville0d462bb2010-07-28 14:04:24 -04005276 .get_survey = mwl8k_get_survey,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005277 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005278};
5279
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005280static void mwl8k_finalize_join_worker(struct work_struct *work)
5281{
5282 struct mwl8k_priv *priv =
5283 container_of(work, struct mwl8k_priv, finalize_join_worker);
5284 struct sk_buff *skb = priv->beacon_skb;
Johannes Berg56007a02010-01-26 14:19:52 +01005285 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5286 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
5287 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
5288 mgmt->u.beacon.variable, len);
5289 int dtim_period = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005290
Johannes Berg56007a02010-01-26 14:19:52 +01005291 if (tim && tim[1] >= 2)
5292 dtim_period = tim[3];
5293
5294 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005295
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005296 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005297 priv->beacon_skb = NULL;
5298}
5299
John W. Linvillebcb628d2009-11-06 16:40:16 -05005300enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005301 MWL8363 = 0,
5302 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05005303 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02005304};
5305
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07005306#define MWL8K_8366_AP_FW_API 2
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005307#define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5308#define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5309
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005310static struct mwl8k_device_info mwl8k_info_tbl[] = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005311 [MWL8363] = {
5312 .part_name = "88w8363",
5313 .helper_image = "mwl8k/helper_8363.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005314 .fw_image_sta = "mwl8k/fmimage_8363.fw",
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005315 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01005316 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05005317 .part_name = "88w8687",
5318 .helper_image = "mwl8k/helper_8687.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005319 .fw_image_sta = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05005320 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01005321 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05005322 .part_name = "88w8366",
5323 .helper_image = "mwl8k/helper_8366.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005324 .fw_image_sta = "mwl8k/fmimage_8366.fw",
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005325 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
5326 .fw_api_ap = MWL8K_8366_AP_FW_API,
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01005327 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05005328 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005329};
5330
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01005331MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5332MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5333MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5334MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5335MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5336MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005337MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01005338
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005339static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Benjamin Larssone5868ba2010-03-19 01:46:10 +01005340 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005341 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
5342 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05005343 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
5344 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
5345 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01005346 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05005347 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005348};
5349MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
5350
Brian Cavagnolo99020472010-11-12 17:23:52 -08005351static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
5352{
5353 int rc;
5354 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
5355 "Trying alternative firmware %s\n", pci_name(priv->pdev),
5356 priv->fw_pref, priv->fw_alt);
5357 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
5358 if (rc) {
5359 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5360 pci_name(priv->pdev), priv->fw_alt);
5361 return rc;
5362 }
5363 return 0;
5364}
5365
5366static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
5367static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
5368{
5369 struct mwl8k_priv *priv = context;
5370 struct mwl8k_device_info *di = priv->device_info;
5371 int rc;
5372
5373 switch (priv->fw_state) {
5374 case FW_STATE_INIT:
5375 if (!fw) {
5376 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
5377 pci_name(priv->pdev), di->helper_image);
5378 goto fail;
5379 }
5380 priv->fw_helper = fw;
5381 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
5382 true);
5383 if (rc && priv->fw_alt) {
5384 rc = mwl8k_request_alt_fw(priv);
5385 if (rc)
5386 goto fail;
5387 priv->fw_state = FW_STATE_LOADING_ALT;
5388 } else if (rc)
5389 goto fail;
5390 else
5391 priv->fw_state = FW_STATE_LOADING_PREF;
5392 break;
5393
5394 case FW_STATE_LOADING_PREF:
5395 if (!fw) {
5396 if (priv->fw_alt) {
5397 rc = mwl8k_request_alt_fw(priv);
5398 if (rc)
5399 goto fail;
5400 priv->fw_state = FW_STATE_LOADING_ALT;
5401 } else
5402 goto fail;
5403 } else {
5404 priv->fw_ucode = fw;
5405 rc = mwl8k_firmware_load_success(priv);
5406 if (rc)
5407 goto fail;
5408 else
5409 complete(&priv->firmware_loading_complete);
5410 }
5411 break;
5412
5413 case FW_STATE_LOADING_ALT:
5414 if (!fw) {
5415 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5416 pci_name(priv->pdev), di->helper_image);
5417 goto fail;
5418 }
5419 priv->fw_ucode = fw;
5420 rc = mwl8k_firmware_load_success(priv);
5421 if (rc)
5422 goto fail;
5423 else
5424 complete(&priv->firmware_loading_complete);
5425 break;
5426
5427 default:
5428 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
5429 MWL8K_NAME, priv->fw_state);
5430 BUG_ON(1);
5431 }
5432
5433 return;
5434
5435fail:
5436 priv->fw_state = FW_STATE_ERROR;
5437 complete(&priv->firmware_loading_complete);
5438 device_release_driver(&priv->pdev->dev);
5439 mwl8k_release_firmware(priv);
5440}
5441
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305442#define MAX_RESTART_ATTEMPTS 1
Brian Cavagnolo99020472010-11-12 17:23:52 -08005443static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
5444 bool nowait)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005445{
5446 struct mwl8k_priv *priv = hw->priv;
5447 int rc;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305448 int count = MAX_RESTART_ATTEMPTS;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005449
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305450retry:
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005451 /* Reset firmware and hardware */
5452 mwl8k_hw_reset(priv);
5453
5454 /* Ask userland hotplug daemon for the device firmware */
Brian Cavagnolo99020472010-11-12 17:23:52 -08005455 rc = mwl8k_request_firmware(priv, fw_image, nowait);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005456 if (rc) {
5457 wiphy_err(hw->wiphy, "Firmware files not found\n");
5458 return rc;
5459 }
5460
Brian Cavagnolo99020472010-11-12 17:23:52 -08005461 if (nowait)
5462 return rc;
5463
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005464 /* Load firmware into hardware */
5465 rc = mwl8k_load_firmware(hw);
5466 if (rc)
5467 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5468
5469 /* Reclaim memory once firmware is successfully loaded */
5470 mwl8k_release_firmware(priv);
5471
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305472 if (rc && count) {
5473 /* FW did not start successfully;
5474 * lets try one more time
5475 */
5476 count--;
5477 wiphy_err(hw->wiphy, "Trying to reload the firmware again\n");
5478 msleep(20);
5479 goto retry;
5480 }
5481
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005482 return rc;
5483}
5484
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005485static int mwl8k_init_txqs(struct ieee80211_hw *hw)
5486{
5487 struct mwl8k_priv *priv = hw->priv;
5488 int rc = 0;
5489 int i;
5490
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005491 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005492 rc = mwl8k_txq_init(hw, i);
5493 if (rc)
5494 break;
5495 if (priv->ap_fw)
5496 iowrite32(priv->txq[i].txd_dma,
5497 priv->sram + priv->txq_offset[i]);
5498 }
5499 return rc;
5500}
5501
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005502/* initialize hw after successfully loading a firmware image */
5503static int mwl8k_probe_hw(struct ieee80211_hw *hw)
5504{
5505 struct mwl8k_priv *priv = hw->priv;
5506 int rc = 0;
5507 int i;
5508
5509 if (priv->ap_fw) {
5510 priv->rxd_ops = priv->device_info->ap_rxd_ops;
5511 if (priv->rxd_ops == NULL) {
5512 wiphy_err(hw->wiphy,
5513 "Driver does not have AP firmware image support for this hardware\n");
5514 goto err_stop_firmware;
5515 }
5516 } else {
5517 priv->rxd_ops = &rxd_sta_ops;
5518 }
5519
5520 priv->sniffer_enabled = false;
5521 priv->wmm_enabled = false;
5522 priv->pending_tx_pkts = 0;
5523
5524 rc = mwl8k_rxq_init(hw, 0);
5525 if (rc)
5526 goto err_stop_firmware;
5527 rxq_refill(hw, 0, INT_MAX);
5528
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005529 /* For the sta firmware, we need to know the dma addresses of tx queues
5530 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5531 * prior to issuing this command. But for the AP case, we learn the
5532 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5533 * case we must initialize the tx queues after.
5534 */
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07005535 priv->num_ampdu_queues = 0;
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005536 if (!priv->ap_fw) {
5537 rc = mwl8k_init_txqs(hw);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005538 if (rc)
5539 goto err_free_queues;
5540 }
5541
5542 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
5543 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07005544 iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
5545 MWL8K_A2H_INT_BA_WATCHDOG,
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005546 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
Nishant Sarmukadam12488e02011-04-08 14:38:27 +05305547 iowrite32(MWL8K_A2H_INT_OPC_DONE,
5548 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005549
5550 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
5551 IRQF_SHARED, MWL8K_NAME, hw);
5552 if (rc) {
5553 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
5554 goto err_free_queues;
5555 }
5556
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305557 /*
5558 * When hw restart is requested,
5559 * mac80211 will take care of clearing
5560 * the ampdu streams, so do not clear
5561 * the ampdu state here
5562 */
5563 if (!priv->hw_restart_in_progress)
5564 memset(priv->ampdu, 0, sizeof(priv->ampdu));
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07005565
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005566 /*
5567 * Temporarily enable interrupts. Initial firmware host
5568 * commands use interrupts and avoid polling. Disable
5569 * interrupts when done.
5570 */
5571 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5572
5573 /* Get config data, mac addrs etc */
5574 if (priv->ap_fw) {
5575 rc = mwl8k_cmd_get_hw_spec_ap(hw);
5576 if (!rc)
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005577 rc = mwl8k_init_txqs(hw);
5578 if (!rc)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005579 rc = mwl8k_cmd_set_hw_spec(hw);
5580 } else {
5581 rc = mwl8k_cmd_get_hw_spec_sta(hw);
5582 }
5583 if (rc) {
5584 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
5585 goto err_free_irq;
5586 }
5587
5588 /* Turn radio off */
5589 rc = mwl8k_cmd_radio_disable(hw);
5590 if (rc) {
5591 wiphy_err(hw->wiphy, "Cannot disable\n");
5592 goto err_free_irq;
5593 }
5594
5595 /* Clear MAC address */
5596 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
5597 if (rc) {
5598 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
5599 goto err_free_irq;
5600 }
5601
5602 /* Disable interrupts */
5603 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5604 free_irq(priv->pdev->irq, hw);
5605
5606 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5607 priv->device_info->part_name,
5608 priv->hw_rev, hw->wiphy->perm_addr,
5609 priv->ap_fw ? "AP" : "STA",
5610 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
5611 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
5612
5613 return 0;
5614
5615err_free_irq:
5616 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5617 free_irq(priv->pdev->irq, hw);
5618
5619err_free_queues:
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005620 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005621 mwl8k_txq_deinit(hw, i);
5622 mwl8k_rxq_deinit(hw, 0);
5623
5624err_stop_firmware:
5625 mwl8k_hw_reset(priv);
5626
5627 return rc;
5628}
5629
5630/*
5631 * invoke mwl8k_reload_firmware to change the firmware image after the device
5632 * has already been registered
5633 */
5634static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
5635{
5636 int i, rc = 0;
5637 struct mwl8k_priv *priv = hw->priv;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305638 struct mwl8k_vif *vif, *tmp_vif;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005639
5640 mwl8k_stop(hw);
5641 mwl8k_rxq_deinit(hw, 0);
5642
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305643 /*
5644 * All the existing interfaces are re-added by the ieee80211_reconfig;
5645 * which means driver should remove existing interfaces before calling
5646 * ieee80211_restart_hw
5647 */
5648 if (priv->hw_restart_in_progress)
5649 list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list)
5650 mwl8k_remove_vif(priv, vif);
5651
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005652 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005653 mwl8k_txq_deinit(hw, i);
5654
Brian Cavagnolo99020472010-11-12 17:23:52 -08005655 rc = mwl8k_init_firmware(hw, fw_image, false);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005656 if (rc)
5657 goto fail;
5658
5659 rc = mwl8k_probe_hw(hw);
5660 if (rc)
5661 goto fail;
5662
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305663 if (priv->hw_restart_in_progress)
5664 return rc;
5665
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005666 rc = mwl8k_start(hw);
5667 if (rc)
5668 goto fail;
5669
5670 rc = mwl8k_config(hw, ~0);
5671 if (rc)
5672 goto fail;
5673
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005674 for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
Eliad Peller8a3a3c82011-10-02 10:15:52 +02005675 rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005676 if (rc)
5677 goto fail;
5678 }
5679
5680 return rc;
5681
5682fail:
5683 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
5684 return rc;
5685}
5686
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305687static const struct ieee80211_iface_limit ap_if_limits[] = {
5688 { .max = 8, .types = BIT(NL80211_IFTYPE_AP) },
5689};
5690
5691static const struct ieee80211_iface_combination ap_if_comb = {
5692 .limits = ap_if_limits,
5693 .n_limits = ARRAY_SIZE(ap_if_limits),
5694 .max_interfaces = 8,
5695 .num_different_channels = 1,
5696};
5697
5698
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005699static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
5700{
5701 struct ieee80211_hw *hw = priv->hw;
5702 int i, rc;
5703
Brian Cavagnolo99020472010-11-12 17:23:52 -08005704 rc = mwl8k_load_firmware(hw);
5705 mwl8k_release_firmware(priv);
5706 if (rc) {
5707 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5708 return rc;
5709 }
5710
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005711 /*
5712 * Extra headroom is the size of the required DMA header
5713 * minus the size of the smallest 802.11 frame (CTS frame).
5714 */
5715 hw->extra_tx_headroom =
5716 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
5717
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +05305718 hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0;
5719
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005720 hw->channel_change_time = 10;
5721
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005722 hw->queues = MWL8K_TX_WMM_QUEUES;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005723
5724 /* Set rssi values to dBm */
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08005725 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
Yogesh Ashok Powar2a36a0e2011-08-29 17:12:44 +05305726
5727 /*
5728 * Ask mac80211 to not to trigger PS mode
5729 * based on PM bit of incoming frames.
5730 */
5731 if (priv->ap_fw)
5732 hw->flags |= IEEE80211_HW_AP_LINK_PS;
5733
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005734 hw->vif_data_size = sizeof(struct mwl8k_vif);
5735 hw->sta_data_size = sizeof(struct mwl8k_sta);
5736
5737 priv->macids_used = 0;
5738 INIT_LIST_HEAD(&priv->vif_list);
5739
5740 /* Set default radio state and preamble */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005741 priv->radio_on = false;
5742 priv->radio_short_preamble = false;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005743
5744 /* Finalize join worker */
5745 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07005746 /* Handle watchdog ba events */
5747 INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305748 /* To reload the firmware if it crashes */
5749 INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005750
5751 /* TX reclaim and RX tasklets. */
5752 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
5753 tasklet_disable(&priv->poll_tx_task);
5754 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
5755 tasklet_disable(&priv->poll_rx_task);
5756
5757 /* Power management cookie */
5758 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
5759 if (priv->cookie == NULL)
5760 return -ENOMEM;
5761
5762 mutex_init(&priv->fw_mutex);
5763 priv->fw_mutex_owner = NULL;
5764 priv->fw_mutex_depth = 0;
5765 priv->hostcmd_wait = NULL;
5766
5767 spin_lock_init(&priv->tx_lock);
5768
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07005769 spin_lock_init(&priv->stream_lock);
5770
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005771 priv->tx_wait = NULL;
5772
5773 rc = mwl8k_probe_hw(hw);
5774 if (rc)
5775 goto err_free_cookie;
5776
5777 hw->wiphy->interface_modes = 0;
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305778
5779 if (priv->ap_macids_supported || priv->device_info->fw_image_ap) {
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005780 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305781 hw->wiphy->iface_combinations = &ap_if_comb;
5782 hw->wiphy->n_iface_combinations = 1;
5783 }
5784
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005785 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
5786 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
5787
5788 rc = ieee80211_register_hw(hw);
5789 if (rc) {
5790 wiphy_err(hw->wiphy, "Cannot register device\n");
5791 goto err_unprobe_hw;
5792 }
5793
5794 return 0;
5795
5796err_unprobe_hw:
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005797 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005798 mwl8k_txq_deinit(hw, i);
5799 mwl8k_rxq_deinit(hw, 0);
5800
5801err_free_cookie:
5802 if (priv->cookie != NULL)
5803 pci_free_consistent(priv->pdev, 4,
5804 priv->cookie, priv->cookie_dma);
5805
5806 return rc;
5807}
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005808static int mwl8k_probe(struct pci_dev *pdev,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005809 const struct pci_device_id *id)
5810{
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005811 static int printed_version;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005812 struct ieee80211_hw *hw;
5813 struct mwl8k_priv *priv;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005814 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005815 int rc;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02005816
5817 if (!printed_version) {
5818 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
5819 printed_version = 1;
5820 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005821
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005822
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005823 rc = pci_enable_device(pdev);
5824 if (rc) {
5825 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
5826 MWL8K_NAME);
5827 return rc;
5828 }
5829
5830 rc = pci_request_regions(pdev, MWL8K_NAME);
5831 if (rc) {
5832 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
5833 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01005834 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005835 }
5836
5837 pci_set_master(pdev);
5838
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005839
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005840 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
5841 if (hw == NULL) {
5842 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
5843 rc = -ENOMEM;
5844 goto err_free_reg;
5845 }
5846
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005847 SET_IEEE80211_DEV(hw, &pdev->dev);
5848 pci_set_drvdata(pdev, hw);
5849
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005850 priv = hw->priv;
5851 priv->hw = hw;
5852 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05005853 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005854
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005855
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005856 priv->sram = pci_iomap(pdev, 0, 0x10000);
5857 if (priv->sram == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07005858 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005859 goto err_iounmap;
5860 }
5861
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005862 /*
5863 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
5864 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
5865 */
5866 priv->regs = pci_iomap(pdev, 1, 0x10000);
5867 if (priv->regs == NULL) {
5868 priv->regs = pci_iomap(pdev, 2, 0x10000);
5869 if (priv->regs == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07005870 wiphy_err(hw->wiphy, "Cannot map device registers\n");
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005871 goto err_iounmap;
5872 }
5873 }
5874
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005875 /*
Brian Cavagnolo99020472010-11-12 17:23:52 -08005876 * Choose the initial fw image depending on user input. If a second
5877 * image is available, make it the alternative image that will be
5878 * loaded if the first one fails.
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005879 */
Brian Cavagnolo99020472010-11-12 17:23:52 -08005880 init_completion(&priv->firmware_loading_complete);
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005881 di = priv->device_info;
Brian Cavagnolo99020472010-11-12 17:23:52 -08005882 if (ap_mode_default && di->fw_image_ap) {
5883 priv->fw_pref = di->fw_image_ap;
5884 priv->fw_alt = di->fw_image_sta;
5885 } else if (!ap_mode_default && di->fw_image_sta) {
5886 priv->fw_pref = di->fw_image_sta;
5887 priv->fw_alt = di->fw_image_ap;
5888 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005889 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08005890 priv->fw_pref = di->fw_image_sta;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005891 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
5892 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08005893 priv->fw_pref = di->fw_image_ap;
5894 }
5895 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005896 if (rc)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005897 goto err_stop_firmware;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305898
5899 priv->hw_restart_in_progress = false;
5900
Brian Cavagnolo99020472010-11-12 17:23:52 -08005901 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005902
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005903err_stop_firmware:
5904 mwl8k_hw_reset(priv);
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005905
5906err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005907 if (priv->regs != NULL)
5908 pci_iounmap(pdev, priv->regs);
5909
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005910 if (priv->sram != NULL)
5911 pci_iounmap(pdev, priv->sram);
5912
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005913 pci_set_drvdata(pdev, NULL);
5914 ieee80211_free_hw(hw);
5915
5916err_free_reg:
5917 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01005918
5919err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005920 pci_disable_device(pdev);
5921
5922 return rc;
5923}
5924
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005925static void mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005926{
5927 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
5928 struct mwl8k_priv *priv;
5929 int i;
5930
5931 if (hw == NULL)
5932 return;
5933 priv = hw->priv;
5934
Brian Cavagnolo99020472010-11-12 17:23:52 -08005935 wait_for_completion(&priv->firmware_loading_complete);
5936
5937 if (priv->fw_state == FW_STATE_ERROR) {
5938 mwl8k_hw_reset(priv);
5939 goto unmap;
5940 }
5941
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005942 ieee80211_stop_queues(hw);
5943
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02005944 ieee80211_unregister_hw(hw);
5945
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01005946 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01005947 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01005948 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005949
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005950 /* Stop hardware */
5951 mwl8k_hw_reset(priv);
5952
5953 /* Return all skbs to mac80211 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005954 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01005955 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005956
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005957 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005958 mwl8k_txq_deinit(hw, i);
5959
5960 mwl8k_rxq_deinit(hw, 0);
5961
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02005962 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005963
Brian Cavagnolo99020472010-11-12 17:23:52 -08005964unmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005965 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005966 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005967 pci_set_drvdata(pdev, NULL);
5968 ieee80211_free_hw(hw);
5969 pci_release_regions(pdev);
5970 pci_disable_device(pdev);
5971}
5972
5973static struct pci_driver mwl8k_driver = {
5974 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005975 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005976 .probe = mwl8k_probe,
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005977 .remove = mwl8k_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005978};
5979
Axel Lin5b0a3b72012-04-14 10:38:36 +08005980module_pci_driver(mwl8k_driver);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02005981
5982MODULE_DESCRIPTION(MWL8K_DESC);
5983MODULE_VERSION(MWL8K_VERSION);
5984MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
5985MODULE_LICENSE("GPL");