blob: c4d287b48e6452f473a888be2b1a019736ba15f4 [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
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +0530216 atomic_t watchdog_event_pending;
217
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100218 /* lock held over TX and TX reap */
219 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100220
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200221 /* TX quiesce completion, protected by fw_mutex and tx_lock */
222 struct completion *tx_wait;
223
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100224 /* List of interfaces. */
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100225 u32 macids_used;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100226 struct list_head vif_list;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100227
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100228 /* power management status cookie from firmware */
229 u32 *cookie;
230 dma_addr_t cookie_dma;
231
232 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100233 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200234 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100235
236 /*
237 * Running count of TX packets in flight, to avoid
238 * iterating over the transmit rings each time.
239 */
240 int pending_tx_pkts;
241
242 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
Brian Cavagnoloe6007072011-03-17 11:58:44 -0700243 struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
244 u32 txq_offset[MWL8K_MAX_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100245
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200246 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200247 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200248 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200249 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100250
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100251 /* XXX need to convert this to handle multiple interfaces */
252 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200253 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100254 struct sk_buff *beacon_skb;
255
256 /*
257 * This FJ worker has to be global as it is scheduled from the
258 * RX handler. At this point we don't know which interface it
259 * belongs to until the list of bssids waiting to complete join
260 * is checked.
261 */
262 struct work_struct finalize_join_worker;
263
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100264 /* Tasklet to perform TX reclaim. */
265 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100266
267 /* Tasklet to perform RX. */
268 struct tasklet_struct poll_rx_task;
John W. Linville0d462bb2010-07-28 14:04:24 -0400269
270 /* Most recently reported noise in dBm */
271 s8 noise;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800272
273 /*
274 * preserve the queue configurations so they can be restored if/when
275 * the firmware image is swapped.
276 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -0700277 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
Brian Cavagnolo99020472010-11-12 17:23:52 -0800278
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +0530279 /* To perform the task of reloading the firmware */
280 struct work_struct fw_reload;
281 bool hw_restart_in_progress;
282
Brian Cavagnolo99020472010-11-12 17:23:52 -0800283 /* async firmware loading state */
284 unsigned fw_state;
285 char *fw_pref;
286 char *fw_alt;
287 struct completion firmware_loading_complete;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100288};
289
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800290#define MAX_WEP_KEY_LEN 13
291#define NUM_WEP_KEYS 4
292
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100293/* Per interface specific private data */
294struct mwl8k_vif {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100295 struct list_head list;
296 struct ieee80211_vif *vif;
297
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100298 /* Firmware macid for this vif. */
299 int macid;
300
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100301 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100302 u16 seqno;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800303
304 /* Saved WEP keys */
305 struct {
306 u8 enabled;
307 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
308 } wep_key_conf[NUM_WEP_KEYS];
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800309
310 /* BSSID */
311 u8 bssid[ETH_ALEN];
312
313 /* A flag to indicate is HW crypto is enabled for this bssid */
314 bool is_hw_crypto_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100315};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200316#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800317#define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100318
Brian Cavagnolod0805c12011-04-12 11:06:28 -0700319struct tx_traffic_info {
320 u32 start_time;
321 u32 pkts;
322};
323
324#define MWL8K_MAX_TID 8
Lennert Buytenheka6804002010-01-04 21:55:42 +0100325struct mwl8k_sta {
326 /* Index into station database. Returned by UPDATE_STADB. */
327 u8 peer_id;
Nishant Sarmukadam170335432011-03-17 11:58:48 -0700328 u8 is_ampdu_allowed;
Brian Cavagnolod0805c12011-04-12 11:06:28 -0700329 struct tx_traffic_info tx_stats[MWL8K_MAX_TID];
Lennert Buytenheka6804002010-01-04 21:55:42 +0100330};
331#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
332
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100333static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100334 { .center_freq = 2412, .hw_value = 1, },
335 { .center_freq = 2417, .hw_value = 2, },
336 { .center_freq = 2422, .hw_value = 3, },
337 { .center_freq = 2427, .hw_value = 4, },
338 { .center_freq = 2432, .hw_value = 5, },
339 { .center_freq = 2437, .hw_value = 6, },
340 { .center_freq = 2442, .hw_value = 7, },
341 { .center_freq = 2447, .hw_value = 8, },
342 { .center_freq = 2452, .hw_value = 9, },
343 { .center_freq = 2457, .hw_value = 10, },
344 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100345 { .center_freq = 2467, .hw_value = 12, },
346 { .center_freq = 2472, .hw_value = 13, },
347 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100348};
349
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100350static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100351 { .bitrate = 10, .hw_value = 2, },
352 { .bitrate = 20, .hw_value = 4, },
353 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200354 { .bitrate = 110, .hw_value = 22, },
355 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100356 { .bitrate = 60, .hw_value = 12, },
357 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100358 { .bitrate = 120, .hw_value = 24, },
359 { .bitrate = 180, .hw_value = 36, },
360 { .bitrate = 240, .hw_value = 48, },
361 { .bitrate = 360, .hw_value = 72, },
362 { .bitrate = 480, .hw_value = 96, },
363 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100364 { .bitrate = 720, .hw_value = 144, },
365};
366
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100367static const struct ieee80211_channel mwl8k_channels_50[] = {
368 { .center_freq = 5180, .hw_value = 36, },
369 { .center_freq = 5200, .hw_value = 40, },
370 { .center_freq = 5220, .hw_value = 44, },
371 { .center_freq = 5240, .hw_value = 48, },
372};
373
374static const struct ieee80211_rate mwl8k_rates_50[] = {
375 { .bitrate = 60, .hw_value = 12, },
376 { .bitrate = 90, .hw_value = 18, },
377 { .bitrate = 120, .hw_value = 24, },
378 { .bitrate = 180, .hw_value = 36, },
379 { .bitrate = 240, .hw_value = 48, },
380 { .bitrate = 360, .hw_value = 72, },
381 { .bitrate = 480, .hw_value = 96, },
382 { .bitrate = 540, .hw_value = 108, },
383 { .bitrate = 720, .hw_value = 144, },
384};
385
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100386/* Set or get info from Firmware */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100387#define MWL8K_CMD_GET 0x0000
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800388#define MWL8K_CMD_SET 0x0001
389#define MWL8K_CMD_SET_LIST 0x0002
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100390
391/* Firmware command codes */
392#define MWL8K_CMD_CODE_DNLD 0x0001
393#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200394#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100395#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
396#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200397#define MWL8K_CMD_RADIO_CONTROL 0x001c
398#define MWL8K_CMD_RF_TX_POWER 0x001e
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800399#define MWL8K_CMD_TX_POWER 0x001f
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200400#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100401#define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100402#define MWL8K_CMD_SET_PRE_SCAN 0x0107
403#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200404#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100405#define MWL8K_CMD_SET_AID 0x010d
406#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200407#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100408#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200409#define MWL8K_CMD_SET_SLOT 0x0114
410#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
411#define MWL8K_CMD_SET_WMM_MODE 0x0123
412#define MWL8K_CMD_MIMO_CONFIG 0x0125
413#define MWL8K_CMD_USE_FIXED_RATE 0x0126
414#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100415#define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200416#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -0700417#define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +0530418#define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +0100419#define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
420#define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800421#define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200422#define MWL8K_CMD_UPDATE_STADB 0x1123
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700423#define MWL8K_CMD_BASTREAM 0x1125
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100424
John W. Linvilleb6037422010-07-20 13:55:00 -0400425static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100426{
John W. Linvilleb6037422010-07-20 13:55:00 -0400427 u16 command = le16_to_cpu(cmd);
428
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100429#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
430 snprintf(buf, bufsize, "%s", #x);\
431 return buf;\
432 } while (0)
John W. Linvilleb6037422010-07-20 13:55:00 -0400433 switch (command & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100434 MWL8K_CMDNAME(CODE_DNLD);
435 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200436 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100437 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
438 MWL8K_CMDNAME(GET_STAT);
439 MWL8K_CMDNAME(RADIO_CONTROL);
440 MWL8K_CMDNAME(RF_TX_POWER);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800441 MWL8K_CMDNAME(TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200442 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100443 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100444 MWL8K_CMDNAME(SET_PRE_SCAN);
445 MWL8K_CMDNAME(SET_POST_SCAN);
446 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100447 MWL8K_CMDNAME(SET_AID);
448 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200449 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100450 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200451 MWL8K_CMDNAME(SET_SLOT);
452 MWL8K_CMDNAME(SET_EDCA_PARAMS);
453 MWL8K_CMDNAME(SET_WMM_MODE);
454 MWL8K_CMDNAME(MIMO_CONFIG);
455 MWL8K_CMDNAME(USE_FIXED_RATE);
456 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200457 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200458 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100459 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100460 MWL8K_CMDNAME(SET_NEW_STN);
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800461 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200462 MWL8K_CMDNAME(UPDATE_STADB);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -0700463 MWL8K_CMDNAME(BASTREAM);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -0700464 MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100465 default:
466 snprintf(buf, bufsize, "0x%x", cmd);
467 }
468#undef MWL8K_CMDNAME
469
470 return buf;
471}
472
473/* Hardware and firmware reset */
474static void mwl8k_hw_reset(struct mwl8k_priv *priv)
475{
476 iowrite32(MWL8K_H2A_INT_RESET,
477 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
478 iowrite32(MWL8K_H2A_INT_RESET,
479 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
480 msleep(20);
481}
482
483/* Release fw image */
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800484static void mwl8k_release_fw(const struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100485{
486 if (*fw == NULL)
487 return;
488 release_firmware(*fw);
489 *fw = NULL;
490}
491
492static void mwl8k_release_firmware(struct mwl8k_priv *priv)
493{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100494 mwl8k_release_fw(&priv->fw_ucode);
495 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100496}
497
Brian Cavagnolo99020472010-11-12 17:23:52 -0800498/* states for asynchronous f/w loading */
499static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
500enum {
501 FW_STATE_INIT = 0,
502 FW_STATE_LOADING_PREF,
503 FW_STATE_LOADING_ALT,
504 FW_STATE_ERROR,
505};
506
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100507/* Request fw image */
508static int mwl8k_request_fw(struct mwl8k_priv *priv,
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800509 const char *fname, const struct firmware **fw,
Brian Cavagnolo99020472010-11-12 17:23:52 -0800510 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100511{
512 /* release current image */
513 if (*fw != NULL)
514 mwl8k_release_fw(fw);
515
Brian Cavagnolo99020472010-11-12 17:23:52 -0800516 if (nowait)
517 return request_firmware_nowait(THIS_MODULE, 1, fname,
518 &priv->pdev->dev, GFP_KERNEL,
519 priv, mwl8k_fw_state_machine);
520 else
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800521 return request_firmware(fw, fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100522}
523
Brian Cavagnolo99020472010-11-12 17:23:52 -0800524static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
525 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100526{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200527 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100528 int rc;
529
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200530 if (di->helper_image != NULL) {
Brian Cavagnolo99020472010-11-12 17:23:52 -0800531 if (nowait)
532 rc = mwl8k_request_fw(priv, di->helper_image,
533 &priv->fw_helper, true);
534 else
535 rc = mwl8k_request_fw(priv, di->helper_image,
536 &priv->fw_helper, false);
537 if (rc)
538 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
539 pci_name(priv->pdev), di->helper_image);
540
541 if (rc || nowait)
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200542 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100543 }
544
Brian Cavagnolo99020472010-11-12 17:23:52 -0800545 if (nowait) {
546 /*
547 * if we get here, no helper image is needed. Skip the
548 * FW_STATE_INIT state.
549 */
550 priv->fw_state = FW_STATE_LOADING_PREF;
551 rc = mwl8k_request_fw(priv, fw_image,
552 &priv->fw_ucode,
553 true);
554 } else
555 rc = mwl8k_request_fw(priv, fw_image,
556 &priv->fw_ucode, false);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100557 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200558 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800559 pci_name(priv->pdev), fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100560 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100561 return rc;
562 }
563
564 return 0;
565}
566
567struct mwl8k_cmd_pkt {
568 __le16 code;
569 __le16 length;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100570 __u8 seq_num;
571 __u8 macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100572 __le16 result;
573 char payload[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000574} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100575
576/*
577 * Firmware loading.
578 */
579static int
580mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
581{
582 void __iomem *regs = priv->regs;
583 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100584 int loops;
585
586 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
587 if (pci_dma_mapping_error(priv->pdev, dma_addr))
588 return -ENOMEM;
589
590 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
591 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
592 iowrite32(MWL8K_H2A_INT_DOORBELL,
593 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
594 iowrite32(MWL8K_H2A_INT_DUMMY,
595 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
596
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100597 loops = 1000;
598 do {
599 u32 int_code;
600
601 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
602 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
603 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100604 break;
605 }
606
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200607 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100608 udelay(1);
609 } while (--loops);
610
611 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
612
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200613 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100614}
615
616static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
617 const u8 *data, size_t length)
618{
619 struct mwl8k_cmd_pkt *cmd;
620 int done;
621 int rc = 0;
622
623 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
624 if (cmd == NULL)
625 return -ENOMEM;
626
627 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
628 cmd->seq_num = 0;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100629 cmd->macid = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100630 cmd->result = 0;
631
632 done = 0;
633 while (length) {
634 int block_size = length > 256 ? 256 : length;
635
636 memcpy(cmd->payload, data + done, block_size);
637 cmd->length = cpu_to_le16(block_size);
638
639 rc = mwl8k_send_fw_load_cmd(priv, cmd,
640 sizeof(*cmd) + block_size);
641 if (rc)
642 break;
643
644 done += block_size;
645 length -= block_size;
646 }
647
648 if (!rc) {
649 cmd->length = 0;
650 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
651 }
652
653 kfree(cmd);
654
655 return rc;
656}
657
658static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
659 const u8 *data, size_t length)
660{
661 unsigned char *buffer;
662 int may_continue, rc = 0;
663 u32 done, prev_block_size;
664
665 buffer = kmalloc(1024, GFP_KERNEL);
666 if (buffer == NULL)
667 return -ENOMEM;
668
669 done = 0;
670 prev_block_size = 0;
671 may_continue = 1000;
672 while (may_continue > 0) {
673 u32 block_size;
674
675 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
676 if (block_size & 1) {
677 block_size &= ~1;
678 may_continue--;
679 } else {
680 done += prev_block_size;
681 length -= prev_block_size;
682 }
683
684 if (block_size > 1024 || block_size > length) {
685 rc = -EOVERFLOW;
686 break;
687 }
688
689 if (length == 0) {
690 rc = 0;
691 break;
692 }
693
694 if (block_size == 0) {
695 rc = -EPROTO;
696 may_continue--;
697 udelay(1);
698 continue;
699 }
700
701 prev_block_size = block_size;
702 memcpy(buffer, data + done, block_size);
703
704 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
705 if (rc)
706 break;
707 }
708
709 if (!rc && length != 0)
710 rc = -EREMOTEIO;
711
712 kfree(buffer);
713
714 return rc;
715}
716
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200717static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100718{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200719 struct mwl8k_priv *priv = hw->priv;
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800720 const struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200721 int rc;
722 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100723
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200724 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800725 const struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100726
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200727 if (helper == NULL) {
728 printk(KERN_ERR "%s: helper image needed but none "
729 "given\n", pci_name(priv->pdev));
730 return -EINVAL;
731 }
732
733 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100734 if (rc) {
735 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200736 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100737 return rc;
738 }
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +0530739 msleep(20);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100740
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200741 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100742 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200743 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100744 }
745
746 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200747 printk(KERN_ERR "%s: unable to load firmware image\n",
748 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100749 return rc;
750 }
751
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100752 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100753
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100754 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100755 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200756 u32 ready_code;
757
758 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
759 if (ready_code == MWL8K_FWAP_READY) {
Rusty Russell3db1cd52011-12-19 13:56:45 +0000760 priv->ap_fw = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100761 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200762 } else if (ready_code == MWL8K_FWSTA_READY) {
Rusty Russell3db1cd52011-12-19 13:56:45 +0000763 priv->ap_fw = false;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200764 break;
765 }
766
767 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100768 udelay(1);
769 } while (--loops);
770
771 return loops ? 0 : -ETIMEDOUT;
772}
773
774
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100775/* DMA header used by firmware and hardware. */
776struct mwl8k_dma_data {
777 __le16 fwlen;
778 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100779 char data[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000780} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100781
782/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100783static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100784{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100785 struct mwl8k_dma_data *tr;
786 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100787
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100788 tr = (struct mwl8k_dma_data *)skb->data;
789 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
790
791 if (hdrlen != sizeof(tr->wh)) {
792 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
793 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
794 *((__le16 *)(tr->data - 2)) = qos;
795 } else {
796 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
797 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100798 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100799
800 if (hdrlen != sizeof(*tr))
801 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100802}
803
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530804#define REDUCED_TX_HEADROOM 8
805
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800806static void
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530807mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb,
808 int head_pad, int tail_pad)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100809{
810 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100811 int hdrlen;
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800812 int reqd_hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100813 struct mwl8k_dma_data *tr;
814
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100815 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100816 * Add a firmware DMA header; the firmware requires that we
817 * present a 2-byte payload length followed by a 4-address
818 * header (without QoS field), followed (optionally) by any
819 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100820 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100821 wh = (struct ieee80211_hdr *)skb->data;
822
823 hdrlen = ieee80211_hdrlen(wh->frame_control);
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530824
825 /*
826 * Check if skb_resize is required because of
827 * tx_headroom adjustment.
828 */
829 if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts)
830 + REDUCED_TX_HEADROOM))) {
831 if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) {
832
833 wiphy_err(priv->hw->wiphy,
834 "Failed to reallocate TX buffer\n");
835 return;
836 }
837 skb->truesize += REDUCED_TX_HEADROOM;
838 }
839
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530840 reqd_hdrlen = sizeof(*tr) + head_pad;
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800841
842 if (hdrlen != reqd_hdrlen)
843 skb_push(skb, reqd_hdrlen - hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100844
845 if (ieee80211_is_data_qos(wh->frame_control))
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800846 hdrlen -= IEEE80211_QOS_CTL_LEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100847
848 tr = (struct mwl8k_dma_data *)skb->data;
849 if (wh != &tr->wh)
850 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100851 if (hdrlen != sizeof(tr->wh))
852 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100853
854 /*
855 * Firmware length is the length of the fully formed "802.11
856 * payload". That is, everything except for the 802.11 header.
857 * This includes all crypto material including the MIC.
858 */
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800859 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100860}
861
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +0530862static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv,
863 struct sk_buff *skb)
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800864{
865 struct ieee80211_hdr *wh;
866 struct ieee80211_tx_info *tx_info;
867 struct ieee80211_key_conf *key_conf;
868 int data_pad;
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530869 int head_pad = 0;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800870
871 wh = (struct ieee80211_hdr *)skb->data;
872
873 tx_info = IEEE80211_SKB_CB(skb);
874
875 key_conf = NULL;
876 if (ieee80211_is_data(wh->frame_control))
877 key_conf = tx_info->control.hw_key;
878
879 /*
880 * Make sure the packet header is in the DMA header format (4-address
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530881 * without QoS), and add head & tail padding when HW crypto is enabled.
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800882 *
883 * We have the following trailer padding requirements:
884 * - WEP: 4 trailer bytes (ICV)
885 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
886 * - CCMP: 8 trailer bytes (MIC)
887 */
888 data_pad = 0;
889 if (key_conf != NULL) {
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530890 head_pad = key_conf->iv_len;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800891 switch (key_conf->cipher) {
892 case WLAN_CIPHER_SUITE_WEP40:
893 case WLAN_CIPHER_SUITE_WEP104:
894 data_pad = 4;
895 break;
896 case WLAN_CIPHER_SUITE_TKIP:
897 data_pad = 12;
898 break;
899 case WLAN_CIPHER_SUITE_CCMP:
900 data_pad = 8;
901 break;
902 }
903 }
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +0530904 mwl8k_add_dma_header(priv, skb, head_pad, data_pad);
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800905}
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100906
907/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100908 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200909 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100910struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200911 __le16 pkt_len;
912 __u8 sq2;
913 __u8 rate;
914 __le32 pkt_phys_addr;
915 __le32 next_rxd_phys_addr;
916 __le16 qos_control;
917 __le16 htsig2;
918 __le32 hw_rssi_info;
919 __le32 hw_noise_floor_info;
920 __u8 noise_floor;
921 __u8 pad0[3];
922 __u8 rssi;
923 __u8 rx_status;
924 __u8 channel;
925 __u8 rx_ctrl;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000926} __packed;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200927
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100928#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
929#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
930#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100931
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100932#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200933
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800934/* 8366 AP rx_status bits */
935#define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
936#define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
937#define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
938#define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
939#define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
940
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100941static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200942{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100943 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200944
945 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100946 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200947}
948
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100949static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200950{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100951 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200952
953 rxd->pkt_len = cpu_to_le16(len);
954 rxd->pkt_phys_addr = cpu_to_le32(addr);
955 wmb();
956 rxd->rx_ctrl = 0;
957}
958
959static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100960mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -0400961 __le16 *qos, s8 *noise)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200962{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100963 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200964
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100965 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200966 return -1;
967 rmb();
968
969 memset(status, 0, sizeof(*status));
970
971 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -0400972 *noise = -rxd->noise_floor;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200973
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100974 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200975 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100976 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100977 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100978 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200979 } else {
980 int i;
981
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100982 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
983 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200984 status->rate_idx = i;
985 break;
986 }
987 }
988 }
989
Lennert Buytenhek85478342010-01-12 13:48:56 +0100990 if (rxd->channel > 14) {
991 status->band = IEEE80211_BAND_5GHZ;
992 if (!(status->flag & RX_FLAG_HT))
993 status->rate_idx -= 5;
994 } else {
995 status->band = IEEE80211_BAND_2GHZ;
996 }
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900997 status->freq = ieee80211_channel_to_frequency(rxd->channel,
998 status->band);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200999
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001000 *qos = rxd->qos_control;
1001
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001002 if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
1003 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) &&
1004 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
1005 status->flag |= RX_FLAG_MMIC_ERROR;
1006
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02001007 return le16_to_cpu(rxd->pkt_len);
1008}
1009
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001010static struct rxd_ops rxd_8366_ap_ops = {
1011 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
1012 .rxd_init = mwl8k_rxd_8366_ap_init,
1013 .rxd_refill = mwl8k_rxd_8366_ap_refill,
1014 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02001015};
1016
1017/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001018 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001019 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001020struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001021 __le16 pkt_len;
1022 __u8 link_quality;
1023 __u8 noise_level;
1024 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001025 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001026 __le16 qos_control;
1027 __le16 rate_info;
1028 __le32 pad0[4];
1029 __u8 rssi;
1030 __u8 channel;
1031 __le16 pad1;
1032 __u8 rx_ctrl;
1033 __u8 rx_status;
1034 __u8 pad2[2];
Eric Dumazetba2d3582010-06-02 18:10:09 +00001035} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001036
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001037#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
1038#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
1039#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
1040#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
1041#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
1042#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001043
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001044#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001045#define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
1046/* ICV=0 or MIC=1 */
1047#define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
1048/* Key is uploaded only in failure case */
1049#define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001050
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001051static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001052{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001053 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001054
1055 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001056 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001057}
1058
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001059static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001060{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001061 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001062
1063 rxd->pkt_len = cpu_to_le16(len);
1064 rxd->pkt_phys_addr = cpu_to_le32(addr);
1065 wmb();
1066 rxd->rx_ctrl = 0;
1067}
1068
1069static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001070mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -04001071 __le16 *qos, s8 *noise)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001072{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001073 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001074 u16 rate_info;
1075
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001076 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001077 return -1;
1078 rmb();
1079
1080 rate_info = le16_to_cpu(rxd->rate_info);
1081
1082 memset(status, 0, sizeof(*status));
1083
1084 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -04001085 *noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001086 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
1087 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001088
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001089 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001090 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001091 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001092 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001093 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001094 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001095 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001096 status->flag |= RX_FLAG_HT;
1097
Lennert Buytenhek85478342010-01-12 13:48:56 +01001098 if (rxd->channel > 14) {
1099 status->band = IEEE80211_BAND_5GHZ;
1100 if (!(status->flag & RX_FLAG_HT))
1101 status->rate_idx -= 5;
1102 } else {
1103 status->band = IEEE80211_BAND_2GHZ;
1104 }
Bruno Randolf59eb21a2011-01-17 13:37:28 +09001105 status->freq = ieee80211_channel_to_frequency(rxd->channel,
1106 status->band);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001107
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001108 *qos = rxd->qos_control;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001109 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1110 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1111 status->flag |= RX_FLAG_MMIC_ERROR;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001112
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001113 return le16_to_cpu(rxd->pkt_len);
1114}
1115
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001116static struct rxd_ops rxd_sta_ops = {
1117 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1118 .rxd_init = mwl8k_rxd_sta_init,
1119 .rxd_refill = mwl8k_rxd_sta_refill,
1120 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001121};
1122
1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001124#define MWL8K_RX_DESCS 256
1125#define MWL8K_RX_MAXSZ 3800
1126
1127static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1128{
1129 struct mwl8k_priv *priv = hw->priv;
1130 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1131 int size;
1132 int i;
1133
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001134 rxq->rxd_count = 0;
1135 rxq->head = 0;
1136 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001137
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001138 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001139
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001140 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1141 if (rxq->rxd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001142 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001143 return -ENOMEM;
1144 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001145 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001146
Shan Weib9ede5f2011-03-08 11:02:03 +08001147 rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001148 if (rxq->buf == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001149 wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001150 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001151 return -ENOMEM;
1152 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001153
1154 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001155 int desc_size;
1156 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001157 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001158 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001159
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001160 desc_size = priv->rxd_ops->rxd_size;
1161 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001162
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001163 nexti = i + 1;
1164 if (nexti == MWL8K_RX_DESCS)
1165 nexti = 0;
1166 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1167
1168 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001169 }
1170
1171 return 0;
1172}
1173
1174static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1175{
1176 struct mwl8k_priv *priv = hw->priv;
1177 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1178 int refilled;
1179
1180 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001181 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001182 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001183 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001184 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001185 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001186
1187 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1188 if (skb == NULL)
1189 break;
1190
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001191 addr = pci_map_single(priv->pdev, skb->data,
1192 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001193
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001194 rxq->rxd_count++;
1195 rx = rxq->tail++;
1196 if (rxq->tail == MWL8K_RX_DESCS)
1197 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001198 rxq->buf[rx].skb = skb;
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001199 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001200
1201 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1202 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203
1204 refilled++;
1205 }
1206
1207 return refilled;
1208}
1209
1210/* Must be called only when the card's reception is completely halted */
1211static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1212{
1213 struct mwl8k_priv *priv = hw->priv;
1214 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1215 int i;
1216
Brian Cavagnolo73b46322011-03-17 11:58:41 -07001217 if (rxq->rxd == NULL)
1218 return;
1219
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001220 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001221 if (rxq->buf[i].skb != NULL) {
1222 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001223 dma_unmap_addr(&rxq->buf[i], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001224 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001225 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001226
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001227 kfree_skb(rxq->buf[i].skb);
1228 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001229 }
1230 }
1231
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001232 kfree(rxq->buf);
1233 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001234
1235 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001236 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001237 rxq->rxd, rxq->rxd_dma);
1238 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001239}
1240
1241
1242/*
1243 * Scan a list of BSSIDs to process for finalize join.
1244 * Allows for extension to process multiple BSSIDs.
1245 */
1246static inline int
1247mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1248{
1249 return priv->capture_beacon &&
1250 ieee80211_is_beacon(wh->frame_control) &&
Joe Perches2e42e472012-05-09 17:17:46 +00001251 ether_addr_equal(wh->addr3, priv->capture_bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001252}
1253
Lennert Buytenhek37797522009-10-22 20:19:45 +02001254static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1255 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001256{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001257 struct mwl8k_priv *priv = hw->priv;
1258
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001259 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001260 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001261
1262 /*
1263 * Use GFP_ATOMIC as rxq_process is called from
1264 * the primary interrupt handler, memory allocation call
1265 * must not sleep.
1266 */
1267 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1268 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001269 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001270}
1271
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001272static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1273 u8 *bssid)
1274{
1275 struct mwl8k_vif *mwl8k_vif;
1276
1277 list_for_each_entry(mwl8k_vif,
1278 vif_list, list) {
1279 if (memcmp(bssid, mwl8k_vif->bssid,
1280 ETH_ALEN) == 0)
1281 return mwl8k_vif;
1282 }
1283
1284 return NULL;
1285}
1286
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001287static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1288{
1289 struct mwl8k_priv *priv = hw->priv;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001290 struct mwl8k_vif *mwl8k_vif = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001291 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1292 int processed;
1293
1294 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001295 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001296 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001297 void *rxd;
1298 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001299 struct ieee80211_rx_status status;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001300 struct ieee80211_hdr *wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001301 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001302
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001303 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001304 if (skb == NULL)
1305 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001306
1307 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1308
John W. Linville0d462bb2010-07-28 14:04:24 -04001309 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1310 &priv->noise);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001311 if (pkt_len < 0)
1312 break;
1313
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001314 rxq->buf[rxq->head].skb = NULL;
1315
1316 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001317 dma_unmap_addr(&rxq->buf[rxq->head], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001318 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e12010-04-02 13:10:38 +09001319 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001320
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001321 rxq->head++;
1322 if (rxq->head == MWL8K_RX_DESCS)
1323 rxq->head = 0;
1324
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001325 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001326
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001327 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001328
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001329 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001330 * Check for a pending join operation. Save a
1331 * copy of the beacon and schedule a tasklet to
1332 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001333 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001334 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001335 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001336
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001337 if (ieee80211_has_protected(wh->frame_control)) {
1338
1339 /* Check if hw crypto has been enabled for
1340 * this bss. If yes, set the status flags
1341 * accordingly
1342 */
1343 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1344 wh->addr1);
1345
1346 if (mwl8k_vif != NULL &&
Joe Perches23677ce2012-02-09 11:17:23 +00001347 mwl8k_vif->is_hw_crypto_enabled) {
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001348 /*
1349 * When MMIC ERROR is encountered
1350 * by the firmware, payload is
1351 * dropped and only 32 bytes of
1352 * mwl8k Firmware header is sent
1353 * to the host.
1354 *
1355 * We need to add four bytes of
1356 * key information. In it
1357 * MAC80211 expects keyidx set to
1358 * 0 for triggering Counter
1359 * Measure of MMIC failure.
1360 */
1361 if (status.flag & RX_FLAG_MMIC_ERROR) {
1362 struct mwl8k_dma_data *tr;
1363 tr = (struct mwl8k_dma_data *)skb->data;
1364 memset((void *)&(tr->data), 0, 4);
1365 pkt_len += 4;
1366 }
1367
1368 if (!ieee80211_is_auth(wh->frame_control))
1369 status.flag |= RX_FLAG_IV_STRIPPED |
1370 RX_FLAG_DECRYPTED |
1371 RX_FLAG_MMIC_STRIPPED;
1372 }
1373 }
1374
1375 skb_put(skb, pkt_len);
1376 mwl8k_remove_dma_header(skb, qos);
Johannes Bergf1d58c22009-06-17 13:13:00 +02001377 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1378 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001379
1380 processed++;
1381 }
1382
1383 return processed;
1384}
1385
1386
1387/*
1388 * Packet transmission.
1389 */
1390
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001391#define MWL8K_TXD_STATUS_OK 0x00000001
1392#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1393#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1394#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001395#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001396
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001397#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1398#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1399#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1400#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1401#define MWL8K_QOS_EOSP 0x0010
1402
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001403struct mwl8k_tx_desc {
1404 __le32 status;
1405 __u8 data_rate;
1406 __u8 tx_priority;
1407 __le16 qos_control;
1408 __le32 pkt_phys_addr;
1409 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001410 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001411 __le32 next_txd_phys_addr;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07001412 __le32 timestamp;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001413 __le16 rate_info;
1414 __u8 peer_id;
Brian Cavagnoloa1fe24b2010-11-12 17:23:47 -08001415 __u8 tx_frag_cnt;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001416} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001417
1418#define MWL8K_TX_DESCS 128
1419
1420static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1421{
1422 struct mwl8k_priv *priv = hw->priv;
1423 struct mwl8k_tx_queue *txq = priv->txq + index;
1424 int size;
1425 int i;
1426
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001427 txq->len = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001428 txq->head = 0;
1429 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001430
1431 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1432
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001433 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1434 if (txq->txd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001435 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001436 return -ENOMEM;
1437 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001438 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001439
Shan Weib9ede5f2011-03-08 11:02:03 +08001440 txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001441 if (txq->skb == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001442 wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001443 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001444 return -ENOMEM;
1445 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001446
1447 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1448 struct mwl8k_tx_desc *tx_desc;
1449 int nexti;
1450
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001451 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001452 nexti = (i + 1) % MWL8K_TX_DESCS;
1453
1454 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001455 tx_desc->next_txd_phys_addr =
1456 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001457 }
1458
1459 return 0;
1460}
1461
1462static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1463{
1464 iowrite32(MWL8K_H2A_INT_PPA_READY,
1465 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1466 iowrite32(MWL8K_H2A_INT_DUMMY,
1467 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1468 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1469}
1470
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001471static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001472{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001473 struct mwl8k_priv *priv = hw->priv;
1474 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001475
Brian Cavagnoloe6007072011-03-17 11:58:44 -07001476 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001477 struct mwl8k_tx_queue *txq = priv->txq + i;
1478 int fw_owned = 0;
1479 int drv_owned = 0;
1480 int unused = 0;
1481 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001482
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001483 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001484 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1485 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001486
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001487 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001488 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001489 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001490 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001491 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001492
1493 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001494 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001495 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001496
Joe Perchesc96c31e2010-07-26 14:39:58 -07001497 wiphy_err(hw->wiphy,
1498 "txq[%d] len=%d head=%d tail=%d "
1499 "fw_owned=%d drv_owned=%d unused=%d\n",
1500 i,
1501 txq->len, txq->head, txq->tail,
1502 fw_owned, drv_owned, unused);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001503 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001504}
1505
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001506/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001507 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001508 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001509#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001510
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001511static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001512{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001513 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001514 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001515 int retry;
1516 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001517
1518 might_sleep();
1519
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05301520 /* Since fw restart is in progress, allow only the firmware
1521 * commands from the restart code and block the other
1522 * commands since they are going to fail in any case since
1523 * the firmware has crashed
1524 */
1525 if (priv->hw_restart_in_progress) {
1526 if (priv->hw_restart_owner == current)
1527 return 0;
1528 else
1529 return -EBUSY;
1530 }
1531
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05301532 if (atomic_read(&priv->watchdog_event_pending))
1533 return 0;
1534
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001535 /*
1536 * The TX queues are stopped at this point, so this test
1537 * doesn't need to take ->tx_lock.
1538 */
1539 if (!priv->pending_tx_pkts)
1540 return 0;
1541
1542 retry = 0;
1543 rc = 0;
1544
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001545 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001546 priv->tx_wait = &tx_wait;
1547 while (!rc) {
1548 int oldcount;
1549 unsigned long timeout;
1550
1551 oldcount = priv->pending_tx_pkts;
1552
1553 spin_unlock_bh(&priv->tx_lock);
1554 timeout = wait_for_completion_timeout(&tx_wait,
1555 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05301556
1557 if (atomic_read(&priv->watchdog_event_pending)) {
1558 spin_lock_bh(&priv->tx_lock);
1559 priv->tx_wait = NULL;
1560 spin_unlock_bh(&priv->tx_lock);
1561 return 0;
1562 }
1563
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001564 spin_lock_bh(&priv->tx_lock);
1565
1566 if (timeout) {
1567 WARN_ON(priv->pending_tx_pkts);
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301568 if (retry)
Joe Perchesc96c31e2010-07-26 14:39:58 -07001569 wiphy_notice(hw->wiphy, "tx rings drained\n");
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001570 break;
1571 }
1572
1573 if (priv->pending_tx_pkts < oldcount) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001574 wiphy_notice(hw->wiphy,
1575 "waiting for tx rings to drain (%d -> %d pkts)\n",
1576 oldcount, priv->pending_tx_pkts);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001577 retry = 1;
1578 continue;
1579 }
1580
1581 priv->tx_wait = NULL;
1582
Joe Perchesc96c31e2010-07-26 14:39:58 -07001583 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1584 MWL8K_TX_WAIT_TIMEOUT_MS);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001585 mwl8k_dump_tx_rings(hw);
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05301586 priv->hw_restart_in_progress = true;
1587 ieee80211_queue_work(hw, &priv->fw_reload);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001588
1589 rc = -ETIMEDOUT;
1590 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001591 spin_unlock_bh(&priv->tx_lock);
1592
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001593 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001594}
1595
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001596#define MWL8K_TXD_SUCCESS(status) \
1597 ((status) & (MWL8K_TXD_STATUS_OK | \
1598 MWL8K_TXD_STATUS_OK_RETRY | \
1599 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001600
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001601static int mwl8k_tid_queue_mapping(u8 tid)
1602{
1603 BUG_ON(tid > 7);
1604
1605 switch (tid) {
1606 case 0:
1607 case 3:
1608 return IEEE80211_AC_BE;
1609 break;
1610 case 1:
1611 case 2:
1612 return IEEE80211_AC_BK;
1613 break;
1614 case 4:
1615 case 5:
1616 return IEEE80211_AC_VI;
1617 break;
1618 case 6:
1619 case 7:
1620 return IEEE80211_AC_VO;
1621 break;
1622 default:
1623 return -1;
1624 break;
1625 }
1626}
1627
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001628/* The firmware will fill in the rate information
1629 * for each packet that gets queued in the hardware
John W. Linville49adc5c2011-04-27 15:04:28 -04001630 * and these macros will interpret that info.
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001631 */
1632
John W. Linville49adc5c2011-04-27 15:04:28 -04001633#define RI_FORMAT(a) (a & 0x0001)
1634#define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001635
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001636static int
1637mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001638{
1639 struct mwl8k_priv *priv = hw->priv;
1640 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001641 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001642
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001643 processed = 0;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001644 while (txq->len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001645 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001646 struct mwl8k_tx_desc *tx_desc;
1647 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001648 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001649 struct sk_buff *skb;
1650 struct ieee80211_tx_info *info;
1651 u32 status;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001652 struct ieee80211_sta *sta;
1653 struct mwl8k_sta *sta_info = NULL;
1654 u16 rate_info;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001655 struct ieee80211_hdr *wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001656
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001657 tx = txq->head;
1658 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001659
1660 status = le32_to_cpu(tx_desc->status);
1661
1662 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1663 if (!force)
1664 break;
1665 tx_desc->status &=
1666 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1667 }
1668
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001669 txq->head = (tx + 1) % MWL8K_TX_DESCS;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001670 BUG_ON(txq->len == 0);
1671 txq->len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001672 priv->pending_tx_pkts--;
1673
1674 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001675 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001676 skb = txq->skb[tx];
1677 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001678
1679 BUG_ON(skb == NULL);
1680 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1681
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001682 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001683
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001684 wh = (struct ieee80211_hdr *) skb->data;
1685
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001686 /* Mark descriptor as unused */
1687 tx_desc->pkt_phys_addr = 0;
1688 tx_desc->pkt_len = 0;
1689
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001690 info = IEEE80211_SKB_CB(skb);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001691 if (ieee80211_is_data(wh->frame_control)) {
Thomas Huehn89e11802012-07-11 13:21:41 +02001692 rcu_read_lock();
1693 sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
1694 wh->addr2);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001695 if (sta) {
1696 sta_info = MWL8K_STA(sta);
1697 BUG_ON(sta_info == NULL);
1698 rate_info = le16_to_cpu(tx_desc->rate_info);
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001699 /* If rate is < 6.5 Mpbs for an ht station
1700 * do not form an ampdu. If the station is a
1701 * legacy station (format = 0), do not form an
1702 * ampdu
1703 */
John W. Linville49adc5c2011-04-27 15:04:28 -04001704 if (RI_RATE_ID_MCS(rate_info) < 1 ||
1705 RI_FORMAT(rate_info) == 0) {
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001706 sta_info->is_ampdu_allowed = false;
1707 } else {
1708 sta_info->is_ampdu_allowed = true;
1709 }
1710 }
Thomas Huehn89e11802012-07-11 13:21:41 +02001711 rcu_read_unlock();
Nishant Sarmukadam170335432011-03-17 11:58:48 -07001712 }
1713
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001714 ieee80211_tx_info_clear_status(info);
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08001715
1716 /* Rate control is happening in the firmware.
1717 * Ensure no tx rate is being reported.
1718 */
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301719 info->status.rates[0].idx = -1;
1720 info->status.rates[0].count = 1;
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08001721
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001722 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001723 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001724
1725 ieee80211_tx_status_irqsafe(hw, skb);
1726
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001727 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001728 }
1729
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001730 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001731}
1732
1733/* must be called only when the card's transmit is completely halted */
1734static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1735{
1736 struct mwl8k_priv *priv = hw->priv;
1737 struct mwl8k_tx_queue *txq = priv->txq + index;
1738
Brian Cavagnolo73b46322011-03-17 11:58:41 -07001739 if (txq->txd == NULL)
1740 return;
1741
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001742 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001743
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001744 kfree(txq->skb);
1745 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001746
1747 pci_free_consistent(priv->pdev,
1748 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001749 txq->txd, txq->txd_dma);
1750 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001751}
1752
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001753/* caller must hold priv->stream_lock when calling the stream functions */
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05301754static struct mwl8k_ampdu_stream *
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001755mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
1756{
1757 struct mwl8k_ampdu_stream *stream;
1758 struct mwl8k_priv *priv = hw->priv;
1759 int i;
1760
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301761 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001762 stream = &priv->ampdu[i];
1763 if (stream->state == AMPDU_NO_STREAM) {
1764 stream->sta = sta;
1765 stream->state = AMPDU_STREAM_NEW;
1766 stream->tid = tid;
1767 stream->idx = i;
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001768 wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
1769 sta->addr, tid);
1770 return stream;
1771 }
1772 }
1773 return NULL;
1774}
1775
1776static int
1777mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1778{
1779 int ret;
1780
1781 /* if the stream has already been started, don't start it again */
1782 if (stream->state != AMPDU_STREAM_NEW)
1783 return 0;
1784 ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
1785 if (ret)
1786 wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
1787 "%d\n", stream->sta->addr, stream->tid, ret);
1788 else
1789 wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
1790 stream->sta->addr, stream->tid);
1791 return ret;
1792}
1793
1794static void
1795mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
1796{
1797 wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
1798 stream->tid);
1799 memset(stream, 0, sizeof(*stream));
1800}
1801
1802static struct mwl8k_ampdu_stream *
1803mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
1804{
1805 struct mwl8k_priv *priv = hw->priv;
1806 int i;
1807
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301808 for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07001809 struct mwl8k_ampdu_stream *stream;
1810 stream = &priv->ampdu[i];
1811 if (stream->state == AMPDU_NO_STREAM)
1812 continue;
1813 if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
1814 stream->tid == tid)
1815 return stream;
1816 }
1817 return NULL;
1818}
1819
Brian Cavagnolod0805c12011-04-12 11:06:28 -07001820#define MWL8K_AMPDU_PACKET_THRESHOLD 64
1821static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
1822{
1823 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1824 struct tx_traffic_info *tx_stats;
1825
1826 BUG_ON(tid >= MWL8K_MAX_TID);
1827 tx_stats = &sta_info->tx_stats[tid];
1828
1829 return sta_info->is_ampdu_allowed &&
1830 tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
1831}
1832
1833static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
1834{
1835 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
1836 struct tx_traffic_info *tx_stats;
1837
1838 BUG_ON(tid >= MWL8K_MAX_TID);
1839 tx_stats = &sta_info->tx_stats[tid];
1840
1841 if (tx_stats->start_time == 0)
1842 tx_stats->start_time = jiffies;
1843
1844 /* reset the packet count after each second elapses. If the number of
1845 * packets ever exceeds the ampdu_min_traffic threshold, we will allow
1846 * an ampdu stream to be started.
1847 */
1848 if (jiffies - tx_stats->start_time > HZ) {
1849 tx_stats->pkts = 0;
1850 tx_stats->start_time = 0;
1851 } else
1852 tx_stats->pkts++;
1853}
1854
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301855/* The hardware ampdu queues start from 5.
1856 * txpriorities for ampdu queues are
1857 * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
1858 * and queue 3 is lowest (queue 4 is reserved)
1859 */
1860#define BA_QUEUE 5
1861
Johannes Berg7bb45682011-02-24 14:42:06 +01001862static void
Thomas Huehn36323f82012-07-23 21:33:42 +02001863mwl8k_txq_xmit(struct ieee80211_hw *hw,
1864 int index,
1865 struct ieee80211_sta *sta,
1866 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001867{
1868 struct mwl8k_priv *priv = hw->priv;
1869 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001870 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001871 struct ieee80211_hdr *wh;
1872 struct mwl8k_tx_queue *txq;
1873 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001874 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001875 u32 txstatus;
1876 u8 txdatarate;
1877 u16 qos;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001878 int txpriority;
1879 u8 tid = 0;
1880 struct mwl8k_ampdu_stream *stream = NULL;
1881 bool start_ba_session = false;
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05301882 bool mgmtframe = false;
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001883 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301884 bool eapol_frame = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001885
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001886 wh = (struct ieee80211_hdr *)skb->data;
1887 if (ieee80211_is_data_qos(wh->frame_control))
1888 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1889 else
1890 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001891
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301892 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
1893 eapol_frame = true;
1894
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05301895 if (ieee80211_is_mgmt(wh->frame_control))
1896 mgmtframe = true;
1897
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001898 if (priv->ap_fw)
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +05301899 mwl8k_encapsulate_tx_frame(priv, skb);
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001900 else
Yogesh Ashok Poware4eefec2011-05-05 16:30:48 +05301901 mwl8k_add_dma_header(priv, skb, 0, 0);
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001902
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001903 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001904
1905 tx_info = IEEE80211_SKB_CB(skb);
1906 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001907
1908 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001909 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001910 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1911 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001912 }
1913
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001914 /* Setup firmware control bit fields for each frame type. */
1915 txstatus = 0;
1916 txdatarate = 0;
1917 if (ieee80211_is_mgmt(wh->frame_control) ||
1918 ieee80211_is_ctl(wh->frame_control)) {
1919 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001920 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001921 } else if (ieee80211_is_data(wh->frame_control)) {
1922 txdatarate = 1;
1923 if (is_multicast_ether_addr(wh->addr1))
1924 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1925
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001926 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001927 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001928 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001929 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001930 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001931 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001932
Nishant Sarmukadama0e7c6c2011-03-17 11:58:49 -07001933 /* Queue ADDBA request in the respective data queue. While setting up
1934 * the ampdu stream, mac80211 queues further packets for that
1935 * particular ra/tid pair. However, packets piled up in the hardware
1936 * for that ra/tid pair will still go out. ADDBA request and the
1937 * related data packets going out from different queues asynchronously
1938 * will cause a shift in the receiver window which might result in
1939 * ampdu packets getting dropped at the receiver after the stream has
1940 * been setup.
1941 */
1942 if (unlikely(ieee80211_is_action(wh->frame_control) &&
1943 mgmt->u.action.category == WLAN_CATEGORY_BACK &&
1944 mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
1945 priv->ap_fw)) {
1946 u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1947 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1948 index = mwl8k_tid_queue_mapping(tid);
1949 }
1950
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001951 txpriority = index;
1952
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05301953 if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame &&
1954 ieee80211_is_data_qos(wh->frame_control)) {
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001955 tid = qos & 0xf;
Brian Cavagnolod0805c12011-04-12 11:06:28 -07001956 mwl8k_tx_count_packet(sta, tid);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001957 spin_lock(&priv->stream_lock);
1958 stream = mwl8k_lookup_stream(hw, sta->addr, tid);
1959 if (stream != NULL) {
1960 if (stream->state == AMPDU_STREAM_ACTIVE) {
Yogesh Ashok Powar5f2a1492013-01-03 13:21:25 +05301961 WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK));
Yogesh Ashok Powar7fb978b2013-01-03 13:22:56 +05301962 txpriority = (BA_QUEUE + stream->idx) %
1963 TOTAL_HW_TX_QUEUES;
1964 if (stream->idx <= 1)
1965 index = stream->idx +
1966 MWL8K_TX_WMM_QUEUES;
1967
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07001968 } else if (stream->state == AMPDU_STREAM_NEW) {
1969 /* We get here if the driver sends us packets
1970 * after we've initiated a stream, but before
1971 * our ampdu_action routine has been called
1972 * with IEEE80211_AMPDU_TX_START to get the SSN
1973 * for the ADDBA request. So this packet can
1974 * go out with no risk of sequence number
1975 * mismatch. No special handling is required.
1976 */
1977 } else {
1978 /* Drop packets that would go out after the
1979 * ADDBA request was sent but before the ADDBA
1980 * response is received. If we don't do this,
1981 * the recipient would probably receive it
1982 * after the ADDBA request with SSN 0. This
1983 * will cause the recipient's BA receive window
1984 * to shift, which would cause the subsequent
1985 * packets in the BA stream to be discarded.
1986 * mac80211 queues our packets for us in this
1987 * case, so this is really just a safety check.
1988 */
1989 wiphy_warn(hw->wiphy,
1990 "Cannot send packet while ADDBA "
1991 "dialog is underway.\n");
1992 spin_unlock(&priv->stream_lock);
1993 dev_kfree_skb(skb);
1994 return;
1995 }
1996 } else {
1997 /* Defer calling mwl8k_start_stream so that the current
1998 * skb can go out before the ADDBA request. This
1999 * prevents sequence number mismatch at the recepient
2000 * as described above.
2001 */
Brian Cavagnolod0805c12011-04-12 11:06:28 -07002002 if (mwl8k_ampdu_allowed(sta, tid)) {
Nishant Sarmukadam170335432011-03-17 11:58:48 -07002003 stream = mwl8k_add_stream(hw, sta, tid);
2004 if (stream != NULL)
2005 start_ba_session = true;
2006 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002007 }
2008 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar5f2a1492013-01-03 13:21:25 +05302009 } else {
2010 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
2011 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002012 }
2013
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002014 dma = pci_map_single(priv->pdev, skb->data,
2015 skb->len, PCI_DMA_TODEVICE);
2016
2017 if (pci_dma_mapping_error(priv->pdev, dma)) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07002018 wiphy_debug(hw->wiphy,
2019 "failed to dma map skb, dropping TX frame.\n");
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002020 if (start_ba_session) {
2021 spin_lock(&priv->stream_lock);
2022 mwl8k_remove_stream(hw, stream);
2023 spin_unlock(&priv->stream_lock);
2024 }
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002025 dev_kfree_skb(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +01002026 return;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002027 }
2028
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002029 spin_lock_bh(&priv->tx_lock);
2030
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002031 txq = priv->txq + index;
2032
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302033 /* Mgmt frames that go out frequently are probe
2034 * responses. Other mgmt frames got out relatively
2035 * infrequently. Hence reserve 2 buffers so that
2036 * other mgmt frames do not get dropped due to an
2037 * already queued probe response in one of the
2038 * reserved buffers.
2039 */
2040
2041 if (txq->len >= MWL8K_TX_DESCS - 2) {
Joe Perches23677ce2012-02-09 11:17:23 +00002042 if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302043 if (start_ba_session) {
2044 spin_lock(&priv->stream_lock);
2045 mwl8k_remove_stream(hw, stream);
2046 spin_unlock(&priv->stream_lock);
2047 }
2048 spin_unlock_bh(&priv->tx_lock);
Nishant Sarmukadamff7aa962012-11-06 19:22:48 +05302049 pci_unmap_single(priv->pdev, dma, skb->len,
2050 PCI_DMA_TODEVICE);
Nishant Sarmukadam3a769882011-04-21 16:34:58 +05302051 dev_kfree_skb(skb);
2052 return;
Pradeep Nemavat3a7dbc32011-04-21 16:34:56 +05302053 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002054 }
2055
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002056 BUG_ON(txq->skb[txq->tail] != NULL);
2057 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002058
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002059 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002060 tx->data_rate = txdatarate;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002061 tx->tx_priority = txpriority;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002062 tx->qos_control = cpu_to_le16(qos);
2063 tx->pkt_phys_addr = cpu_to_le32(dma);
2064 tx->pkt_len = cpu_to_le16(skb->len);
2065 tx->rate_info = 0;
Thomas Huehn36323f82012-07-23 21:33:42 +02002066 if (!priv->ap_fw && sta != NULL)
2067 tx->peer_id = MWL8K_STA(sta)->peer_id;
Lennert Buytenheka6804002010-01-04 21:55:42 +01002068 else
2069 tx->peer_id = 0;
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302070
Nishant Sarmukadame1f4d692012-11-06 19:23:01 +05302071 if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame)
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302072 tx->timestamp = cpu_to_le32(ioread32(priv->regs +
2073 MWL8K_HW_TIMER_REGISTER));
Nishant Sarmukadamb8d9e572012-11-06 19:23:15 +05302074 else
2075 tx->timestamp = 0;
Pradeep Nemavat566875d2011-04-21 16:34:57 +05302076
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002077 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002078 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
2079
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02002080 txq->len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002081 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002082
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002083 txq->tail++;
2084 if (txq->tail == MWL8K_TX_DESCS)
2085 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002086
Lennert Buytenhek23b33902009-07-17 05:21:04 +02002087 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002088
2089 spin_unlock_bh(&priv->tx_lock);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07002090
2091 /* Initiate the ampdu session here */
2092 if (start_ba_session) {
2093 spin_lock(&priv->stream_lock);
2094 if (mwl8k_start_stream(hw, stream))
2095 mwl8k_remove_stream(hw, stream);
2096 spin_unlock(&priv->stream_lock);
2097 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002098}
2099
2100
2101/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002102 * Firmware access.
2103 *
2104 * We have the following requirements for issuing firmware commands:
2105 * - Some commands require that the packet transmit path is idle when
2106 * the command is issued. (For simplicity, we'll just quiesce the
2107 * transmit path for every command.)
2108 * - There are certain sequences of commands that need to be issued to
2109 * the hardware sequentially, with no other intervening commands.
2110 *
2111 * This leads to an implementation of a "firmware lock" as a mutex that
2112 * can be taken recursively, and which is taken by both the low-level
2113 * command submission function (mwl8k_post_cmd) as well as any users of
2114 * that function that require issuing of an atomic sequence of commands,
2115 * and quiesces the transmit path whenever it's taken.
2116 */
2117static int mwl8k_fw_lock(struct ieee80211_hw *hw)
2118{
2119 struct mwl8k_priv *priv = hw->priv;
2120
2121 if (priv->fw_mutex_owner != current) {
2122 int rc;
2123
2124 mutex_lock(&priv->fw_mutex);
2125 ieee80211_stop_queues(hw);
2126
2127 rc = mwl8k_tx_wait_empty(hw);
2128 if (rc) {
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05302129 if (!priv->hw_restart_in_progress)
2130 ieee80211_wake_queues(hw);
2131
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002132 mutex_unlock(&priv->fw_mutex);
2133
2134 return rc;
2135 }
2136
2137 priv->fw_mutex_owner = current;
2138 }
2139
2140 priv->fw_mutex_depth++;
2141
2142 return 0;
2143}
2144
2145static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
2146{
2147 struct mwl8k_priv *priv = hw->priv;
2148
2149 if (!--priv->fw_mutex_depth) {
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05302150 if (!priv->hw_restart_in_progress)
2151 ieee80211_wake_queues(hw);
2152
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002153 priv->fw_mutex_owner = NULL;
2154 mutex_unlock(&priv->fw_mutex);
2155 }
2156}
2157
2158
2159/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002160 * Command processing.
2161 */
2162
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01002163/* Timeout firmware commands after 10s */
2164#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002165
2166static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
2167{
2168 DECLARE_COMPLETION_ONSTACK(cmd_wait);
2169 struct mwl8k_priv *priv = hw->priv;
2170 void __iomem *regs = priv->regs;
2171 dma_addr_t dma_addr;
2172 unsigned int dma_size;
2173 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002174 unsigned long timeout = 0;
2175 u8 buf[32];
2176
John W. Linvilleb6037422010-07-20 13:55:00 -04002177 cmd->result = (__force __le16) 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002178 dma_size = le16_to_cpu(cmd->length);
2179 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
2180 PCI_DMA_BIDIRECTIONAL);
2181 if (pci_dma_mapping_error(priv->pdev, dma_addr))
2182 return -ENOMEM;
2183
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002184 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02002185 if (rc) {
2186 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2187 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002188 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02002189 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002190
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002191 priv->hostcmd_wait = &cmd_wait;
2192 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
2193 iowrite32(MWL8K_H2A_INT_DOORBELL,
2194 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
2195 iowrite32(MWL8K_H2A_INT_DUMMY,
2196 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002197
2198 timeout = wait_for_completion_timeout(&cmd_wait,
2199 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
2200
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002201 priv->hostcmd_wait = NULL;
2202
2203 mwl8k_fw_unlock(hw);
2204
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02002205 pci_unmap_single(priv->pdev, dma_addr, dma_size,
2206 PCI_DMA_BIDIRECTIONAL);
2207
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002208 if (!timeout) {
Joe Perches5db55842010-08-11 19:11:19 -07002209 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002210 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2211 MWL8K_CMD_TIMEOUT_MS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002212 rc = -ETIMEDOUT;
2213 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01002214 int ms;
2215
2216 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
2217
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002218 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002219 if (rc)
Joe Perches5db55842010-08-11 19:11:19 -07002220 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002221 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
2222 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01002223 else if (ms > 2000)
Joe Perches5db55842010-08-11 19:11:19 -07002224 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07002225 mwl8k_cmd_name(cmd->code,
2226 buf, sizeof(buf)),
2227 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002228 }
2229
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002230 return rc;
2231}
2232
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +01002233static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
2234 struct ieee80211_vif *vif,
2235 struct mwl8k_cmd_pkt *cmd)
2236{
2237 if (vif != NULL)
2238 cmd->macid = MWL8K_VIF(vif)->macid;
2239 return mwl8k_post_cmd(hw, cmd);
2240}
2241
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002242/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01002243 * Setup code shared between STA and AP firmware images.
2244 */
2245static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
2246{
2247 struct mwl8k_priv *priv = hw->priv;
2248
2249 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
2250 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
2251
2252 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
2253 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
2254
2255 priv->band_24.band = IEEE80211_BAND_2GHZ;
2256 priv->band_24.channels = priv->channels_24;
2257 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
2258 priv->band_24.bitrates = priv->rates_24;
2259 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
2260
2261 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
2262}
2263
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01002264static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
2265{
2266 struct mwl8k_priv *priv = hw->priv;
2267
2268 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
2269 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
2270
2271 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
2272 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
2273
2274 priv->band_50.band = IEEE80211_BAND_5GHZ;
2275 priv->band_50.channels = priv->channels_50;
2276 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
2277 priv->band_50.bitrates = priv->rates_50;
2278 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
2279
2280 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
2281}
2282
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01002283/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02002284 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002285 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02002286struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002287 struct mwl8k_cmd_pkt header;
2288 __u8 hw_rev;
2289 __u8 host_interface;
2290 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002291 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002292 __le16 region_code;
2293 __le32 fw_rev;
2294 __le32 ps_cookie;
2295 __le32 caps;
2296 __u8 mcs_bitmap[16];
2297 __le32 rx_queue_ptr;
2298 __le32 num_tx_queues;
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002299 __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002300 __le32 caps2;
2301 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002302 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002303} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002304
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002305#define MWL8K_CAP_MAX_AMSDU 0x20000000
2306#define MWL8K_CAP_GREENFIELD 0x08000000
2307#define MWL8K_CAP_AMPDU 0x04000000
2308#define MWL8K_CAP_RX_STBC 0x01000000
2309#define MWL8K_CAP_TX_STBC 0x00800000
2310#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
2311#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
2312#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
2313#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
2314#define MWL8K_CAP_DELAY_BA 0x00003000
2315#define MWL8K_CAP_MIMO 0x00000200
2316#define MWL8K_CAP_40MHZ 0x00000100
Lennert Buytenhek06953232010-01-12 13:49:41 +01002317#define MWL8K_CAP_BAND_MASK 0x00000007
2318#define MWL8K_CAP_5GHZ 0x00000004
2319#define MWL8K_CAP_2GHZ4 0x00000001
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002320
Lennert Buytenhek06953232010-01-12 13:49:41 +01002321static void
2322mwl8k_set_ht_caps(struct ieee80211_hw *hw,
2323 struct ieee80211_supported_band *band, u32 cap)
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002324{
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002325 int rx_streams;
2326 int tx_streams;
2327
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002328 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002329
2330 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002331 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002332 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002333 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002334 if (cap & MWL8K_CAP_AMPDU) {
2335 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002336 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2337 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002338 }
2339 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002340 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002341 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002342 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002343 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002344 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002345 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002346 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002347 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002348 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002349 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002350 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002351
2352 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
2353 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
2354
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002355 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002356 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002357 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002358 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002359 band->ht_cap.mcs.rx_mask[2] = 0xff;
2360 band->ht_cap.mcs.rx_mask[4] = 0x01;
2361 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002362
2363 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002364 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
2365 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01002366 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2367 }
2368}
2369
Lennert Buytenhek06953232010-01-12 13:49:41 +01002370static void
2371mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
2372{
2373 struct mwl8k_priv *priv = hw->priv;
2374
2375 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
2376 mwl8k_setup_2ghz_band(hw);
2377 if (caps & MWL8K_CAP_MIMO)
2378 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
2379 }
2380
2381 if (caps & MWL8K_CAP_5GHZ) {
2382 mwl8k_setup_5ghz_band(hw);
2383 if (caps & MWL8K_CAP_MIMO)
2384 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
2385 }
2386}
2387
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02002388static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002389{
2390 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02002391 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002392 int rc;
2393 int i;
2394
2395 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2396 if (cmd == NULL)
2397 return -ENOMEM;
2398
2399 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2400 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2401
2402 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2403 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002404 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002405 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
2406 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002407 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02002408 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002409 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002410
2411 rc = mwl8k_post_cmd(hw, &cmd->header);
2412
2413 if (!rc) {
2414 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2415 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02002416 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002417 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek06953232010-01-12 13:49:41 +01002418 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002419 priv->ap_macids_supported = 0x00000000;
2420 priv->sta_macids_supported = 0x00000001;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002421 }
2422
2423 kfree(cmd);
2424 return rc;
2425}
2426
2427/*
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002428 * CMD_GET_HW_SPEC (AP version).
2429 */
2430struct mwl8k_cmd_get_hw_spec_ap {
2431 struct mwl8k_cmd_pkt header;
2432 __u8 hw_rev;
2433 __u8 host_interface;
2434 __le16 num_wcb;
2435 __le16 num_mcaddrs;
2436 __u8 perm_addr[ETH_ALEN];
2437 __le16 region_code;
2438 __le16 num_antenna;
2439 __le32 fw_rev;
2440 __le32 wcbbase0;
2441 __le32 rxwrptr;
2442 __le32 rxrdptr;
2443 __le32 ps_cookie;
2444 __le32 wcbbase1;
2445 __le32 wcbbase2;
2446 __le32 wcbbase3;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002447 __le32 fw_api_version;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002448 __le32 caps;
2449 __le32 num_of_ampdu_queues;
2450 __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002451} __packed;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002452
2453static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2454{
2455 struct mwl8k_priv *priv = hw->priv;
2456 struct mwl8k_cmd_get_hw_spec_ap *cmd;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002457 int rc, i;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002458 u32 api_version;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002459
2460 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2461 if (cmd == NULL)
2462 return -ENOMEM;
2463
2464 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2465 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2466
2467 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2468 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2469
2470 rc = mwl8k_post_cmd(hw, &cmd->header);
2471
2472 if (!rc) {
2473 int off;
2474
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002475 api_version = le32_to_cpu(cmd->fw_api_version);
2476 if (priv->device_info->fw_api_ap != api_version) {
2477 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2478 " Expected %d got %d.\n", MWL8K_NAME,
2479 priv->device_info->part_name,
2480 priv->device_info->fw_api_ap,
2481 api_version);
2482 rc = -EINVAL;
2483 goto done;
2484 }
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002485 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2486 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2487 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2488 priv->hw_rev = cmd->hw_rev;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002489 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002490 priv->ap_macids_supported = 0x000000ff;
2491 priv->sta_macids_supported = 0x00000000;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002492 priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
2493 if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
2494 wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
2495 " but we only support %d.\n",
2496 priv->num_ampdu_queues,
2497 MWL8K_MAX_AMPDU_QUEUES);
2498 priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
2499 }
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002500 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002501 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002502
2503 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002504 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002505
Brian Cavagnolo73b46322011-03-17 11:58:41 -07002506 priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
2507 priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
2508 priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
2509 priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002510
2511 for (i = 0; i < priv->num_ampdu_queues; i++)
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002512 priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002513 le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002514 }
2515
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002516done:
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002517 kfree(cmd);
2518 return rc;
2519}
2520
2521/*
2522 * CMD_SET_HW_SPEC.
2523 */
2524struct mwl8k_cmd_set_hw_spec {
2525 struct mwl8k_cmd_pkt header;
2526 __u8 hw_rev;
2527 __u8 host_interface;
2528 __le16 num_mcaddrs;
2529 __u8 perm_addr[ETH_ALEN];
2530 __le16 region_code;
2531 __le32 fw_rev;
2532 __le32 ps_cookie;
2533 __le32 caps;
2534 __le32 rx_queue_ptr;
2535 __le32 num_tx_queues;
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002536 __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002537 __le32 flags;
2538 __le32 num_tx_desc_per_queue;
2539 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002540} __packed;
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002541
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07002542/* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
2543 * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
2544 * the packets that are queued for more than 500ms, will be dropped in the
2545 * hardware. This helps minimizing the issues caused due to head-of-line
2546 * blocking where a slow client can hog the bandwidth and affect traffic to a
2547 * faster client.
2548 */
2549#define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
Nishant Sarmukadam3373b282011-06-13 16:26:15 +05302550#define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002551#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2552#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2553#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002554
2555static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2556{
2557 struct mwl8k_priv *priv = hw->priv;
2558 struct mwl8k_cmd_set_hw_spec *cmd;
2559 int rc;
2560 int i;
2561
2562 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2563 if (cmd == NULL)
2564 return -ENOMEM;
2565
2566 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2567 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2568
2569 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2570 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002571 cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08002572
2573 /*
2574 * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
2575 * that order. Firmware has Q3 as highest priority and Q0 as lowest
2576 * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
2577 * priority is interpreted the right way in firmware.
2578 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07002579 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
2580 int j = mwl8k_tx_queues(priv) - 1 - i;
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08002581 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
2582 }
2583
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002584 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2585 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
Nishant Sarmukadam31d291a2011-04-21 16:34:59 +05302586 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
Nishant Sarmukadam3373b282011-06-13 16:26:15 +05302587 MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
2588 MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02002589 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2590 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2591
2592 rc = mwl8k_post_cmd(hw, &cmd->header);
2593 kfree(cmd);
2594
2595 return rc;
2596}
2597
2598/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002599 * CMD_MAC_MULTICAST_ADR.
2600 */
2601struct mwl8k_cmd_mac_multicast_adr {
2602 struct mwl8k_cmd_pkt header;
2603 __le16 action;
2604 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002605 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002606};
2607
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002608#define MWL8K_ENABLE_RX_DIRECTED 0x0001
2609#define MWL8K_ENABLE_RX_MULTICAST 0x0002
2610#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2611#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002612
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002613static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002614__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Jiri Pirko22bedad2010-04-01 21:22:57 +00002615 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002616{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002617 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002618 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002619 int size;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002620 int mc_count = 0;
2621
2622 if (mc_list)
2623 mc_count = netdev_hw_addr_list_count(mc_list);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002624
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002625 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002626 allmulti = 1;
2627 mc_count = 0;
2628 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002629
2630 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2631
2632 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002633 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002634 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002635
2636 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2637 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002638 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2639 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002640
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002641 if (allmulti) {
2642 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2643 } else if (mc_count) {
Jiri Pirko22bedad2010-04-01 21:22:57 +00002644 struct netdev_hw_addr *ha;
2645 int i = 0;
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002646
2647 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2648 cmd->numaddr = cpu_to_le16(mc_count);
Jiri Pirko22bedad2010-04-01 21:22:57 +00002649 netdev_hw_addr_list_for_each(ha, mc_list) {
2650 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002651 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002652 }
2653
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002654 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002655}
2656
2657/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002658 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002659 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002660struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002661 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002662 __le32 stats[64];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002663} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002664
2665#define MWL8K_STAT_ACK_FAILURE 9
2666#define MWL8K_STAT_RTS_FAILURE 12
2667#define MWL8K_STAT_FCS_ERROR 24
2668#define MWL8K_STAT_RTS_SUCCESS 11
2669
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002670static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2671 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002672{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002673 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002674 int rc;
2675
2676 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2677 if (cmd == NULL)
2678 return -ENOMEM;
2679
2680 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2681 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002682
2683 rc = mwl8k_post_cmd(hw, &cmd->header);
2684 if (!rc) {
2685 stats->dot11ACKFailureCount =
2686 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2687 stats->dot11RTSFailureCount =
2688 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2689 stats->dot11FCSErrorCount =
2690 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2691 stats->dot11RTSSuccessCount =
2692 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2693 }
2694 kfree(cmd);
2695
2696 return rc;
2697}
2698
2699/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002700 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002701 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002702struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002703 struct mwl8k_cmd_pkt header;
2704 __le16 action;
2705 __le16 control;
2706 __le16 radio_on;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002707} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002708
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002709static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002710mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002711{
2712 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002713 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002714 int rc;
2715
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002716 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002717 return 0;
2718
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002719 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2720 if (cmd == NULL)
2721 return -ENOMEM;
2722
2723 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2724 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2725 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002726 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002727 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2728
2729 rc = mwl8k_post_cmd(hw, &cmd->header);
2730 kfree(cmd);
2731
2732 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002733 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002734
2735 return rc;
2736}
2737
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002738static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002739{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002740 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002741}
2742
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002743static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002744{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002745 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002746}
2747
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002748static int
2749mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2750{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002751 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002752
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002753 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002754
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002755 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002756}
2757
2758/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002759 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002760 */
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002761#define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002762
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002763struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002764 struct mwl8k_cmd_pkt header;
2765 __le16 action;
2766 __le16 support_level;
2767 __le16 current_level;
2768 __le16 reserved;
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002769 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002770} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002771
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002772static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002773{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002774 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002775 int rc;
2776
2777 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2778 if (cmd == NULL)
2779 return -ENOMEM;
2780
2781 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2782 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2783 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2784 cmd->support_level = cpu_to_le16(dBm);
2785
2786 rc = mwl8k_post_cmd(hw, &cmd->header);
2787 kfree(cmd);
2788
2789 return rc;
2790}
2791
2792/*
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002793 * CMD_TX_POWER.
2794 */
2795#define MWL8K_TX_POWER_LEVEL_TOTAL 12
2796
2797struct mwl8k_cmd_tx_power {
2798 struct mwl8k_cmd_pkt header;
2799 __le16 action;
2800 __le16 band;
2801 __le16 channel;
2802 __le16 bw;
2803 __le16 sub_ch;
2804 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05302805} __packed;
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002806
2807static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2808 struct ieee80211_conf *conf,
2809 unsigned short pwr)
2810{
2811 struct ieee80211_channel *channel = conf->channel;
2812 struct mwl8k_cmd_tx_power *cmd;
2813 int rc;
2814 int i;
2815
2816 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2817 if (cmd == NULL)
2818 return -ENOMEM;
2819
2820 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2821 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2822 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2823
2824 if (channel->band == IEEE80211_BAND_2GHZ)
2825 cmd->band = cpu_to_le16(0x1);
2826 else if (channel->band == IEEE80211_BAND_5GHZ)
2827 cmd->band = cpu_to_le16(0x4);
2828
Yogesh Ashok Powar604c4ef2012-01-17 15:45:15 +05302829 cmd->channel = cpu_to_le16(channel->hw_value);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002830
2831 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2832 conf->channel_type == NL80211_CHAN_HT20) {
2833 cmd->bw = cpu_to_le16(0x2);
2834 } else {
2835 cmd->bw = cpu_to_le16(0x4);
2836 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2837 cmd->sub_ch = cpu_to_le16(0x3);
2838 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2839 cmd->sub_ch = cpu_to_le16(0x1);
2840 }
2841
2842 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2843 cmd->power_level_list[i] = cpu_to_le16(pwr);
2844
2845 rc = mwl8k_post_cmd(hw, &cmd->header);
2846 kfree(cmd);
2847
2848 return rc;
2849}
2850
2851/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002852 * CMD_RF_ANTENNA.
2853 */
2854struct mwl8k_cmd_rf_antenna {
2855 struct mwl8k_cmd_pkt header;
2856 __le16 antenna;
2857 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002858} __packed;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002859
2860#define MWL8K_RF_ANTENNA_RX 1
2861#define MWL8K_RF_ANTENNA_TX 2
2862
2863static int
2864mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2865{
2866 struct mwl8k_cmd_rf_antenna *cmd;
2867 int rc;
2868
2869 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2870 if (cmd == NULL)
2871 return -ENOMEM;
2872
2873 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2874 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2875 cmd->antenna = cpu_to_le16(antenna);
2876 cmd->mode = cpu_to_le16(mask);
2877
2878 rc = mwl8k_post_cmd(hw, &cmd->header);
2879 kfree(cmd);
2880
2881 return rc;
2882}
2883
2884/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002885 * CMD_SET_BEACON.
2886 */
2887struct mwl8k_cmd_set_beacon {
2888 struct mwl8k_cmd_pkt header;
2889 __le16 beacon_len;
2890 __u8 beacon[0];
2891};
2892
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01002893static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2894 struct ieee80211_vif *vif, u8 *beacon, int len)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002895{
2896 struct mwl8k_cmd_set_beacon *cmd;
2897 int rc;
2898
2899 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2900 if (cmd == NULL)
2901 return -ENOMEM;
2902
2903 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2904 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2905 cmd->beacon_len = cpu_to_le16(len);
2906 memcpy(cmd->beacon, beacon, len);
2907
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01002908 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002909 kfree(cmd);
2910
2911 return rc;
2912}
2913
2914/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002915 * CMD_SET_PRE_SCAN.
2916 */
2917struct mwl8k_cmd_set_pre_scan {
2918 struct mwl8k_cmd_pkt header;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002919} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002920
2921static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2922{
2923 struct mwl8k_cmd_set_pre_scan *cmd;
2924 int rc;
2925
2926 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2927 if (cmd == NULL)
2928 return -ENOMEM;
2929
2930 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2931 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2932
2933 rc = mwl8k_post_cmd(hw, &cmd->header);
2934 kfree(cmd);
2935
2936 return rc;
2937}
2938
2939/*
2940 * CMD_SET_POST_SCAN.
2941 */
2942struct mwl8k_cmd_set_post_scan {
2943 struct mwl8k_cmd_pkt header;
2944 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002945 __u8 bssid[ETH_ALEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002946} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002947
2948static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002949mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002950{
2951 struct mwl8k_cmd_set_post_scan *cmd;
2952 int rc;
2953
2954 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2955 if (cmd == NULL)
2956 return -ENOMEM;
2957
2958 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2959 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2960 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002961 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002962
2963 rc = mwl8k_post_cmd(hw, &cmd->header);
2964 kfree(cmd);
2965
2966 return rc;
2967}
2968
2969/*
2970 * CMD_SET_RF_CHANNEL.
2971 */
2972struct mwl8k_cmd_set_rf_channel {
2973 struct mwl8k_cmd_pkt header;
2974 __le16 action;
2975 __u8 current_channel;
2976 __le32 channel_flags;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002977} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002978
2979static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002980 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002981{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002982 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002983 struct mwl8k_cmd_set_rf_channel *cmd;
2984 int rc;
2985
2986 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2987 if (cmd == NULL)
2988 return -ENOMEM;
2989
2990 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2991 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2992 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2993 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002994
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002995 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002996 cmd->channel_flags |= cpu_to_le32(0x00000001);
Lennert Buytenhek42574ea2010-01-12 13:49:18 +01002997 else if (channel->band == IEEE80211_BAND_5GHZ)
2998 cmd->channel_flags |= cpu_to_le32(0x00000004);
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002999
3000 if (conf->channel_type == NL80211_CHAN_NO_HT ||
3001 conf->channel_type == NL80211_CHAN_HT20)
3002 cmd->channel_flags |= cpu_to_le32(0x00000080);
3003 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
3004 cmd->channel_flags |= cpu_to_le32(0x000001900);
3005 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
3006 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003007
3008 rc = mwl8k_post_cmd(hw, &cmd->header);
3009 kfree(cmd);
3010
3011 return rc;
3012}
3013
3014/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003015 * CMD_SET_AID.
3016 */
3017#define MWL8K_FRAME_PROT_DISABLED 0x00
3018#define MWL8K_FRAME_PROT_11G 0x07
3019#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
3020#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
3021
3022struct mwl8k_cmd_update_set_aid {
3023 struct mwl8k_cmd_pkt header;
3024 __le16 aid;
3025
3026 /* AP's MAC address (BSSID) */
3027 __u8 bssid[ETH_ALEN];
3028 __le16 protection_mode;
3029 __u8 supp_rates[14];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003030} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003031
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003032static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
3033{
3034 int i;
3035 int j;
3036
3037 /*
3038 * Clear nonstandard rates 4 and 13.
3039 */
3040 mask &= 0x1fef;
3041
3042 for (i = 0, j = 0; i < 14; i++) {
3043 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01003044 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003045 }
3046}
3047
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003048static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003049mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
3050 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003051{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003052 struct mwl8k_cmd_update_set_aid *cmd;
3053 u16 prot_mode;
3054 int rc;
3055
3056 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3057 if (cmd == NULL)
3058 return -ENOMEM;
3059
3060 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
3061 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003062 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003063 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003064
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003065 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003066 prot_mode = MWL8K_FRAME_PROT_11G;
3067 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003068 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003069 IEEE80211_HT_OP_MODE_PROTECTION) {
3070 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
3071 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
3072 break;
3073 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
3074 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
3075 break;
3076 default:
3077 prot_mode = MWL8K_FRAME_PROT_DISABLED;
3078 break;
3079 }
3080 }
3081 cmd->protection_mode = cpu_to_le16(prot_mode);
3082
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003083 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003084
3085 rc = mwl8k_post_cmd(hw, &cmd->header);
3086 kfree(cmd);
3087
3088 return rc;
3089}
3090
3091/*
3092 * CMD_SET_RATE.
3093 */
3094struct mwl8k_cmd_set_rate {
3095 struct mwl8k_cmd_pkt header;
3096 __u8 legacy_rates[14];
3097
3098 /* Bitmap for supported MCS codes. */
3099 __u8 mcs_set[16];
3100 __u8 reserved[16];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003101} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003102
3103static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003104mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003105 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003106{
3107 struct mwl8k_cmd_set_rate *cmd;
3108 int rc;
3109
3110 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3111 if (cmd == NULL)
3112 return -ENOMEM;
3113
3114 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
3115 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003116 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003117 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003118
3119 rc = mwl8k_post_cmd(hw, &cmd->header);
3120 kfree(cmd);
3121
3122 return rc;
3123}
3124
3125/*
3126 * CMD_FINALIZE_JOIN.
3127 */
3128#define MWL8K_FJ_BEACON_MAXLEN 128
3129
3130struct mwl8k_cmd_finalize_join {
3131 struct mwl8k_cmd_pkt header;
3132 __le32 sleep_interval; /* Number of beacon periods to sleep */
3133 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00003134} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003135
3136static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
3137 int framelen, int dtim)
3138{
3139 struct mwl8k_cmd_finalize_join *cmd;
3140 struct ieee80211_mgmt *payload = frame;
3141 int payload_len;
3142 int rc;
3143
3144 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3145 if (cmd == NULL)
3146 return -ENOMEM;
3147
3148 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
3149 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3150 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
3151
3152 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
3153 if (payload_len < 0)
3154 payload_len = 0;
3155 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
3156 payload_len = MWL8K_FJ_BEACON_MAXLEN;
3157
3158 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
3159
3160 rc = mwl8k_post_cmd(hw, &cmd->header);
3161 kfree(cmd);
3162
3163 return rc;
3164}
3165
3166/*
3167 * CMD_SET_RTS_THRESHOLD.
3168 */
3169struct mwl8k_cmd_set_rts_threshold {
3170 struct mwl8k_cmd_pkt header;
3171 __le16 action;
3172 __le16 threshold;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003173} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003174
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003175static int
3176mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003177{
3178 struct mwl8k_cmd_set_rts_threshold *cmd;
3179 int rc;
3180
3181 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3182 if (cmd == NULL)
3183 return -ENOMEM;
3184
3185 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
3186 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003187 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3188 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003189
3190 rc = mwl8k_post_cmd(hw, &cmd->header);
3191 kfree(cmd);
3192
3193 return rc;
3194}
3195
3196/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003197 * CMD_SET_SLOT.
3198 */
3199struct mwl8k_cmd_set_slot {
3200 struct mwl8k_cmd_pkt header;
3201 __le16 action;
3202 __u8 short_slot;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003203} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003204
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02003205static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003206{
3207 struct mwl8k_cmd_set_slot *cmd;
3208 int rc;
3209
3210 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3211 if (cmd == NULL)
3212 return -ENOMEM;
3213
3214 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
3215 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3216 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02003217 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003218
3219 rc = mwl8k_post_cmd(hw, &cmd->header);
3220 kfree(cmd);
3221
3222 return rc;
3223}
3224
3225/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003226 * CMD_SET_EDCA_PARAMS.
3227 */
3228struct mwl8k_cmd_set_edca_params {
3229 struct mwl8k_cmd_pkt header;
3230
3231 /* See MWL8K_SET_EDCA_XXX below */
3232 __le16 action;
3233
3234 /* TX opportunity in units of 32 us */
3235 __le16 txop;
3236
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003237 union {
3238 struct {
3239 /* Log exponent of max contention period: 0...15 */
3240 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003241
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003242 /* Log exponent of min contention period: 0...15 */
3243 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003244
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003245 /* Adaptive interframe spacing in units of 32us */
3246 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003247
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003248 /* TX queue to configure */
3249 __u8 txq;
3250 } ap;
3251 struct {
3252 /* Log exponent of max contention period: 0...15 */
3253 __u8 log_cw_max;
3254
3255 /* Log exponent of min contention period: 0...15 */
3256 __u8 log_cw_min;
3257
3258 /* Adaptive interframe spacing in units of 32us */
3259 __u8 aifs;
3260
3261 /* TX queue to configure */
3262 __u8 txq;
3263 } sta;
3264 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00003265} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003266
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003267#define MWL8K_SET_EDCA_CW 0x01
3268#define MWL8K_SET_EDCA_TXOP 0x02
3269#define MWL8K_SET_EDCA_AIFS 0x04
3270
3271#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
3272 MWL8K_SET_EDCA_TXOP | \
3273 MWL8K_SET_EDCA_AIFS)
3274
3275static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003276mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
3277 __u16 cw_min, __u16 cw_max,
3278 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003279{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003280 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003281 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003282 int rc;
3283
3284 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3285 if (cmd == NULL)
3286 return -ENOMEM;
3287
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003288 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
3289 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003290 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
3291 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02003292 if (priv->ap_fw) {
3293 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
3294 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
3295 cmd->ap.aifs = aifs;
3296 cmd->ap.txq = qnum;
3297 } else {
3298 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
3299 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
3300 cmd->sta.aifs = aifs;
3301 cmd->sta.txq = qnum;
3302 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003303
3304 rc = mwl8k_post_cmd(hw, &cmd->header);
3305 kfree(cmd);
3306
3307 return rc;
3308}
3309
3310/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003311 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003312 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003313struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003314 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003315 __le16 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003316} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003317
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003318static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003319{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003320 struct mwl8k_priv *priv = hw->priv;
3321 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003322 int rc;
3323
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003324 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3325 if (cmd == NULL)
3326 return -ENOMEM;
3327
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003328 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003329 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003330 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003331
3332 rc = mwl8k_post_cmd(hw, &cmd->header);
3333 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01003334
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003335 if (!rc)
3336 priv->wmm_enabled = enable;
3337
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003338 return rc;
3339}
3340
3341/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003342 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003343 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003344struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003345 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003346 __le32 action;
3347 __u8 rx_antenna_map;
3348 __u8 tx_antenna_map;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003349} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003350
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003351static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003352{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003353 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003354 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003355
3356 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3357 if (cmd == NULL)
3358 return -ENOMEM;
3359
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003360 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003361 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003362 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
3363 cmd->rx_antenna_map = rx;
3364 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003365
3366 rc = mwl8k_post_cmd(hw, &cmd->header);
3367 kfree(cmd);
3368
3369 return rc;
3370}
3371
3372/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003373 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003374 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003375struct mwl8k_cmd_use_fixed_rate_sta {
3376 struct mwl8k_cmd_pkt header;
3377 __le32 action;
3378 __le32 allow_rate_drop;
3379 __le32 num_rates;
3380 struct {
3381 __le32 is_ht_rate;
3382 __le32 enable_retry;
3383 __le32 rate;
3384 __le32 retry_count;
3385 } rate_entry[8];
3386 __le32 rate_type;
3387 __le32 reserved1;
3388 __le32 reserved2;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003389} __packed;
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003390
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003391#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003392#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003393
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003394static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003395{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003396 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003397 int rc;
3398
3399 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3400 if (cmd == NULL)
3401 return -ENOMEM;
3402
3403 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3404 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003405 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3406 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003407
3408 rc = mwl8k_post_cmd(hw, &cmd->header);
3409 kfree(cmd);
3410
3411 return rc;
3412}
3413
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003414/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01003415 * CMD_USE_FIXED_RATE (AP version).
3416 */
3417struct mwl8k_cmd_use_fixed_rate_ap {
3418 struct mwl8k_cmd_pkt header;
3419 __le32 action;
3420 __le32 allow_rate_drop;
3421 __le32 num_rates;
3422 struct mwl8k_rate_entry_ap {
3423 __le32 is_ht_rate;
3424 __le32 enable_retry;
3425 __le32 rate;
3426 __le32 retry_count;
3427 } rate_entry[4];
3428 u8 multicast_rate;
3429 u8 multicast_rate_type;
3430 u8 management_rate;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003431} __packed;
Lennert Buytenhek088aab82010-01-08 18:30:36 +01003432
3433static int
3434mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
3435{
3436 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
3437 int rc;
3438
3439 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3440 if (cmd == NULL)
3441 return -ENOMEM;
3442
3443 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
3444 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3445 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
3446 cmd->multicast_rate = mcast;
3447 cmd->management_rate = mgmt;
3448
3449 rc = mwl8k_post_cmd(hw, &cmd->header);
3450 kfree(cmd);
3451
3452 return rc;
3453}
3454
3455/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003456 * CMD_ENABLE_SNIFFER.
3457 */
3458struct mwl8k_cmd_enable_sniffer {
3459 struct mwl8k_cmd_pkt header;
3460 __le32 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003461} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003462
3463static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3464{
3465 struct mwl8k_cmd_enable_sniffer *cmd;
3466 int rc;
3467
3468 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3469 if (cmd == NULL)
3470 return -ENOMEM;
3471
3472 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3473 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3474 cmd->action = cpu_to_le32(!!enable);
3475
3476 rc = mwl8k_post_cmd(hw, &cmd->header);
3477 kfree(cmd);
3478
3479 return rc;
3480}
3481
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303482struct mwl8k_cmd_update_mac_addr {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003483 struct mwl8k_cmd_pkt header;
3484 union {
3485 struct {
3486 __le16 mac_type;
3487 __u8 mac_addr[ETH_ALEN];
3488 } mbss;
3489 __u8 mac_addr[ETH_ALEN];
3490 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00003491} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003492
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003493#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3494#define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3495#define MWL8K_MAC_TYPE_PRIMARY_AP 2
3496#define MWL8K_MAC_TYPE_SECONDARY_AP 3
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01003497
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303498static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
3499 struct ieee80211_vif *vif, u8 *mac, bool set)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003500{
3501 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003502 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303503 struct mwl8k_cmd_update_mac_addr *cmd;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003504 int mac_type;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003505 int rc;
3506
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003507 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3508 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3509 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
3510 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
3511 else
3512 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3513 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3514 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3515 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3516 else
3517 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3518 }
3519
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003520 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3521 if (cmd == NULL)
3522 return -ENOMEM;
3523
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303524 if (set)
3525 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3526 else
3527 cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
3528
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003529 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3530 if (priv->ap_fw) {
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003531 cmd->mbss.mac_type = cpu_to_le16(mac_type);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003532 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3533 } else {
3534 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3535 }
3536
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003537 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003538 kfree(cmd);
3539
3540 return rc;
3541}
3542
3543/*
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05303544 * MWL8K_CMD_SET_MAC_ADDR.
3545 */
3546static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3547 struct ieee80211_vif *vif, u8 *mac)
3548{
3549 return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
3550}
3551
3552/*
3553 * MWL8K_CMD_DEL_MAC_ADDR.
3554 */
3555static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
3556 struct ieee80211_vif *vif, u8 *mac)
3557{
3558 return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
3559}
3560
3561/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003562 * CMD_SET_RATEADAPT_MODE.
3563 */
3564struct mwl8k_cmd_set_rate_adapt_mode {
3565 struct mwl8k_cmd_pkt header;
3566 __le16 action;
3567 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003568} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003569
3570static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3571{
3572 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
3573 int rc;
3574
3575 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3576 if (cmd == NULL)
3577 return -ENOMEM;
3578
3579 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
3580 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3581 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3582 cmd->mode = cpu_to_le16(mode);
3583
3584 rc = mwl8k_post_cmd(hw, &cmd->header);
3585 kfree(cmd);
3586
3587 return rc;
3588}
3589
3590/*
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003591 * CMD_GET_WATCHDOG_BITMAP.
3592 */
3593struct mwl8k_cmd_get_watchdog_bitmap {
3594 struct mwl8k_cmd_pkt header;
3595 u8 bitmap;
3596} __packed;
3597
3598static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
3599{
3600 struct mwl8k_cmd_get_watchdog_bitmap *cmd;
3601 int rc;
3602
3603 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3604 if (cmd == NULL)
3605 return -ENOMEM;
3606
3607 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
3608 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3609
3610 rc = mwl8k_post_cmd(hw, &cmd->header);
3611 if (!rc)
3612 *bitmap = cmd->bitmap;
3613
3614 kfree(cmd);
3615
3616 return rc;
3617}
3618
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303619#define MWL8K_WMM_QUEUE_NUMBER 3
3620
3621static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
3622 u8 idx);
3623
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003624static void mwl8k_watchdog_ba_events(struct work_struct *work)
3625{
3626 int rc;
3627 u8 bitmap = 0, stream_index;
3628 struct mwl8k_ampdu_stream *streams;
3629 struct mwl8k_priv *priv =
3630 container_of(work, struct mwl8k_priv, watchdog_ba_handle);
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303631 struct ieee80211_hw *hw = priv->hw;
3632 int i;
3633 u32 status = 0;
3634
3635 mwl8k_fw_lock(hw);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003636
3637 rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
3638 if (rc)
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303639 goto done;
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003640
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303641 spin_lock(&priv->stream_lock);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003642
3643 /* the bitmap is the hw queue number. Map it to the ampdu queue. */
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303644 for (i = 0; i < TOTAL_HW_TX_QUEUES; i++) {
3645 if (bitmap & (1 << i)) {
3646 stream_index = (i + MWL8K_WMM_QUEUE_NUMBER) %
3647 TOTAL_HW_TX_QUEUES;
3648 streams = &priv->ampdu[stream_index];
3649 if (streams->state == AMPDU_STREAM_ACTIVE) {
3650 ieee80211_stop_tx_ba_session(streams->sta,
3651 streams->tid);
3652 spin_unlock(&priv->stream_lock);
3653 mwl8k_destroy_ba(hw, stream_index);
3654 spin_lock(&priv->stream_lock);
3655 }
3656 }
3657 }
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003658
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303659 spin_unlock(&priv->stream_lock);
3660done:
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05303661 atomic_dec(&priv->watchdog_event_pending);
Yogesh Ashok Powarcfacba12013-01-03 13:24:03 +05303662 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3663 iowrite32((status | MWL8K_A2H_INT_BA_WATCHDOG),
3664 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3665 mwl8k_fw_unlock(hw);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07003666 return;
3667}
3668
3669
3670/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003671 * CMD_BSS_START.
3672 */
3673struct mwl8k_cmd_bss_start {
3674 struct mwl8k_cmd_pkt header;
3675 __le32 enable;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003676} __packed;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003677
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003678static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3679 struct ieee80211_vif *vif, int enable)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003680{
3681 struct mwl8k_cmd_bss_start *cmd;
3682 int rc;
3683
3684 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3685 if (cmd == NULL)
3686 return -ENOMEM;
3687
3688 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3689 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3690 cmd->enable = cpu_to_le32(enable);
3691
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003692 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003693 kfree(cmd);
3694
3695 return rc;
3696}
3697
3698/*
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003699 * CMD_BASTREAM.
3700 */
3701
3702/*
3703 * UPSTREAM is tx direction
3704 */
3705#define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
3706#define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
3707
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303708enum ba_stream_action_type {
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003709 MWL8K_BA_CREATE,
3710 MWL8K_BA_UPDATE,
3711 MWL8K_BA_DESTROY,
3712 MWL8K_BA_FLUSH,
3713 MWL8K_BA_CHECK,
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303714};
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003715
3716
3717struct mwl8k_create_ba_stream {
3718 __le32 flags;
3719 __le32 idle_thrs;
3720 __le32 bar_thrs;
3721 __le32 window_size;
3722 u8 peer_mac_addr[6];
3723 u8 dialog_token;
3724 u8 tid;
3725 u8 queue_id;
3726 u8 param_info;
3727 __le32 ba_context;
3728 u8 reset_seq_no_flag;
3729 __le16 curr_seq_no;
3730 u8 sta_src_mac_addr[6];
3731} __packed;
3732
3733struct mwl8k_destroy_ba_stream {
3734 __le32 flags;
3735 __le32 ba_context;
3736} __packed;
3737
3738struct mwl8k_cmd_bastream {
3739 struct mwl8k_cmd_pkt header;
3740 __le32 action;
3741 union {
3742 struct mwl8k_create_ba_stream create_params;
3743 struct mwl8k_destroy_ba_stream destroy_params;
3744 };
3745} __packed;
3746
3747static int
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303748mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
3749 struct ieee80211_vif *vif)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003750{
3751 struct mwl8k_cmd_bastream *cmd;
3752 int rc;
3753
3754 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3755 if (cmd == NULL)
3756 return -ENOMEM;
3757
3758 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3759 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3760
3761 cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
3762
3763 cmd->create_params.queue_id = stream->idx;
3764 memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
3765 ETH_ALEN);
3766 cmd->create_params.tid = stream->tid;
3767
3768 cmd->create_params.flags =
3769 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
3770 cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
3771
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303772 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003773
3774 kfree(cmd);
3775
3776 return rc;
3777}
3778
3779static int
3780mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303781 u8 buf_size, struct ieee80211_vif *vif)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003782{
3783 struct mwl8k_cmd_bastream *cmd;
3784 int rc;
3785
3786 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3787 if (cmd == NULL)
3788 return -ENOMEM;
3789
3790
3791 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3792 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3793
3794 cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
3795
3796 cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
3797 cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
3798 cmd->create_params.queue_id = stream->idx;
3799
3800 memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
3801 cmd->create_params.tid = stream->tid;
3802 cmd->create_params.curr_seq_no = cpu_to_le16(0);
3803 cmd->create_params.reset_seq_no_flag = 1;
3804
3805 cmd->create_params.param_info =
3806 (stream->sta->ht_cap.ampdu_factor &
3807 IEEE80211_HT_AMPDU_PARM_FACTOR) |
3808 ((stream->sta->ht_cap.ampdu_density << 2) &
3809 IEEE80211_HT_AMPDU_PARM_DENSITY);
3810
3811 cmd->create_params.flags =
3812 cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
3813 BASTREAM_FLAG_DIRECTION_UPSTREAM);
3814
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05303815 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003816
3817 wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
3818 stream->sta->addr, stream->tid);
3819 kfree(cmd);
3820
3821 return rc;
3822}
3823
3824static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303825 u8 idx)
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003826{
3827 struct mwl8k_cmd_bastream *cmd;
3828
3829 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3830 if (cmd == NULL)
3831 return;
3832
3833 cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
3834 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3835 cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
3836
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303837 cmd->destroy_params.ba_context = cpu_to_le32(idx);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003838 mwl8k_post_cmd(hw, &cmd->header);
3839
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05303840 wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", idx);
Nishant Sarmukadam5faa1af2011-03-17 11:58:43 -07003841
3842 kfree(cmd);
3843}
3844
3845/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003846 * CMD_SET_NEW_STN.
3847 */
3848struct mwl8k_cmd_set_new_stn {
3849 struct mwl8k_cmd_pkt header;
3850 __le16 aid;
3851 __u8 mac_addr[6];
3852 __le16 stn_id;
3853 __le16 action;
3854 __le16 rsvd;
3855 __le32 legacy_rates;
3856 __u8 ht_rates[4];
3857 __le16 cap_info;
3858 __le16 ht_capabilities_info;
3859 __u8 mac_ht_param_info;
3860 __u8 rev;
3861 __u8 control_channel;
3862 __u8 add_channel;
3863 __le16 op_mode;
3864 __le16 stbc;
3865 __u8 add_qos_info;
3866 __u8 is_qos_sta;
3867 __le32 fw_sta_ptr;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003868} __packed;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003869
3870#define MWL8K_STA_ACTION_ADD 0
3871#define MWL8K_STA_ACTION_REMOVE 2
3872
3873static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3874 struct ieee80211_vif *vif,
3875 struct ieee80211_sta *sta)
3876{
3877 struct mwl8k_cmd_set_new_stn *cmd;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003878 u32 rates;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003879 int rc;
3880
3881 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3882 if (cmd == NULL)
3883 return -ENOMEM;
3884
3885 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3886 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3887 cmd->aid = cpu_to_le16(sta->aid);
3888 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3889 cmd->stn_id = cpu_to_le16(sta->aid);
3890 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003891 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3892 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3893 else
3894 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3895 cmd->legacy_rates = cpu_to_le32(rates);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003896 if (sta->ht_cap.ht_supported) {
3897 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3898 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3899 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3900 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3901 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3902 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3903 ((sta->ht_cap.ampdu_density & 7) << 2);
3904 cmd->is_qos_sta = 1;
3905 }
3906
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003907 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003908 kfree(cmd);
3909
3910 return rc;
3911}
3912
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003913static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3914 struct ieee80211_vif *vif)
3915{
3916 struct mwl8k_cmd_set_new_stn *cmd;
3917 int rc;
3918
3919 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3920 if (cmd == NULL)
3921 return -ENOMEM;
3922
3923 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3924 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3925 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3926
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003927 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003928 kfree(cmd);
3929
3930 return rc;
3931}
3932
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003933static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
3934 struct ieee80211_vif *vif, u8 *addr)
3935{
3936 struct mwl8k_cmd_set_new_stn *cmd;
3937 int rc;
3938
3939 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3940 if (cmd == NULL)
3941 return -ENOMEM;
3942
3943 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3944 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3945 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3946 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
3947
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01003948 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003949 kfree(cmd);
3950
3951 return rc;
3952}
3953
3954/*
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08003955 * CMD_UPDATE_ENCRYPTION.
3956 */
3957
3958#define MAX_ENCR_KEY_LENGTH 16
3959#define MIC_KEY_LENGTH 8
3960
3961struct mwl8k_cmd_update_encryption {
3962 struct mwl8k_cmd_pkt header;
3963
3964 __le32 action;
3965 __le32 reserved;
3966 __u8 mac_addr[6];
3967 __u8 encr_type;
3968
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303969} __packed;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08003970
3971struct mwl8k_cmd_set_key {
3972 struct mwl8k_cmd_pkt header;
3973
3974 __le32 action;
3975 __le32 reserved;
3976 __le16 length;
3977 __le16 key_type_id;
3978 __le32 key_info;
3979 __le32 key_id;
3980 __le16 key_len;
3981 __u8 key_material[MAX_ENCR_KEY_LENGTH];
3982 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
3983 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
3984 __le16 tkip_rsc_low;
3985 __le32 tkip_rsc_high;
3986 __le16 tkip_tsc_low;
3987 __le32 tkip_tsc_high;
3988 __u8 mac_addr[6];
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05303989} __packed;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08003990
3991enum {
3992 MWL8K_ENCR_ENABLE,
3993 MWL8K_ENCR_SET_KEY,
3994 MWL8K_ENCR_REMOVE_KEY,
3995 MWL8K_ENCR_SET_GROUP_KEY,
3996};
3997
3998#define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
3999#define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
4000#define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
4001#define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
4002#define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
4003
4004enum {
4005 MWL8K_ALG_WEP,
4006 MWL8K_ALG_TKIP,
4007 MWL8K_ALG_CCMP,
4008};
4009
4010#define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
4011#define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
4012#define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
4013#define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
4014#define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
4015
4016static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
4017 struct ieee80211_vif *vif,
4018 u8 *addr,
4019 u8 encr_type)
4020{
4021 struct mwl8k_cmd_update_encryption *cmd;
4022 int rc;
4023
4024 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4025 if (cmd == NULL)
4026 return -ENOMEM;
4027
4028 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4029 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4030 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
4031 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4032 cmd->encr_type = encr_type;
4033
4034 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4035 kfree(cmd);
4036
4037 return rc;
4038}
4039
4040static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
4041 u8 *addr,
4042 struct ieee80211_key_conf *key)
4043{
4044 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
4045 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4046 cmd->length = cpu_to_le16(sizeof(*cmd) -
4047 offsetof(struct mwl8k_cmd_set_key, length));
4048 cmd->key_id = cpu_to_le32(key->keyidx);
4049 cmd->key_len = cpu_to_le16(key->keylen);
4050 memcpy(cmd->mac_addr, addr, ETH_ALEN);
4051
4052 switch (key->cipher) {
4053 case WLAN_CIPHER_SUITE_WEP40:
4054 case WLAN_CIPHER_SUITE_WEP104:
4055 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
4056 if (key->keyidx == 0)
4057 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
4058
4059 break;
4060 case WLAN_CIPHER_SUITE_TKIP:
4061 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
4062 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4063 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4064 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4065 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
4066 | MWL8K_KEY_FLAG_TSC_VALID);
4067 break;
4068 case WLAN_CIPHER_SUITE_CCMP:
4069 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
4070 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4071 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
4072 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
4073 break;
4074 default:
4075 return -ENOTSUPP;
4076 }
4077
4078 return 0;
4079}
4080
4081static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
4082 struct ieee80211_vif *vif,
4083 u8 *addr,
4084 struct ieee80211_key_conf *key)
4085{
4086 struct mwl8k_cmd_set_key *cmd;
4087 int rc;
4088 int keymlen;
4089 u32 action;
4090 u8 idx;
4091 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4092
4093 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4094 if (cmd == NULL)
4095 return -ENOMEM;
4096
4097 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4098 if (rc < 0)
4099 goto done;
4100
4101 idx = key->keyidx;
4102
4103 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4104 action = MWL8K_ENCR_SET_KEY;
4105 else
4106 action = MWL8K_ENCR_SET_GROUP_KEY;
4107
4108 switch (key->cipher) {
4109 case WLAN_CIPHER_SUITE_WEP40:
4110 case WLAN_CIPHER_SUITE_WEP104:
4111 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
4112 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
4113 sizeof(*key) + key->keylen);
4114 mwl8k_vif->wep_key_conf[idx].enabled = 1;
4115 }
4116
Yogesh Ashok Powar9b571e22011-05-04 17:22:16 +05304117 keymlen = key->keylen;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004118 action = MWL8K_ENCR_SET_KEY;
4119 break;
4120 case WLAN_CIPHER_SUITE_TKIP:
4121 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
4122 break;
4123 case WLAN_CIPHER_SUITE_CCMP:
4124 keymlen = key->keylen;
4125 break;
4126 default:
4127 rc = -ENOTSUPP;
4128 goto done;
4129 }
4130
4131 memcpy(cmd->key_material, key->key, keymlen);
4132 cmd->action = cpu_to_le32(action);
4133
4134 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4135done:
4136 kfree(cmd);
4137
4138 return rc;
4139}
4140
4141static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
4142 struct ieee80211_vif *vif,
4143 u8 *addr,
4144 struct ieee80211_key_conf *key)
4145{
4146 struct mwl8k_cmd_set_key *cmd;
4147 int rc;
4148 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4149
4150 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4151 if (cmd == NULL)
4152 return -ENOMEM;
4153
4154 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
4155 if (rc < 0)
4156 goto done;
4157
4158 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
Dan Carpenterd981e052012-01-17 10:33:31 +03004159 key->cipher == WLAN_CIPHER_SUITE_WEP104)
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004160 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
4161
4162 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
4163
4164 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
4165done:
4166 kfree(cmd);
4167
4168 return rc;
4169}
4170
4171static int mwl8k_set_key(struct ieee80211_hw *hw,
4172 enum set_key_cmd cmd_param,
4173 struct ieee80211_vif *vif,
4174 struct ieee80211_sta *sta,
4175 struct ieee80211_key_conf *key)
4176{
4177 int rc = 0;
4178 u8 encr_type;
4179 u8 *addr;
4180 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4181
4182 if (vif->type == NL80211_IFTYPE_STATION)
4183 return -EOPNOTSUPP;
4184
4185 if (sta == NULL)
Yogesh Ashok Powarff7e9f92012-01-27 16:08:27 +05304186 addr = vif->addr;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004187 else
4188 addr = sta->addr;
4189
4190 if (cmd_param == SET_KEY) {
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004191 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
4192 if (rc)
4193 goto out;
4194
4195 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
4196 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
4197 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
4198 else
4199 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
4200
4201 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
4202 encr_type);
4203 if (rc)
4204 goto out;
4205
4206 mwl8k_vif->is_hw_crypto_enabled = true;
4207
4208 } else {
4209 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
4210
4211 if (rc)
4212 goto out;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004213 }
4214out:
4215 return rc;
4216}
4217
4218/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004219 * CMD_UPDATE_STADB.
4220 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004221struct ewc_ht_info {
4222 __le16 control1;
4223 __le16 control2;
4224 __le16 control3;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004225} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004226
4227struct peer_capability_info {
4228 /* Peer type - AP vs. STA. */
4229 __u8 peer_type;
4230
4231 /* Basic 802.11 capabilities from assoc resp. */
4232 __le16 basic_caps;
4233
4234 /* Set if peer supports 802.11n high throughput (HT). */
4235 __u8 ht_support;
4236
4237 /* Valid if HT is supported. */
4238 __le16 ht_caps;
4239 __u8 extended_ht_caps;
4240 struct ewc_ht_info ewc_info;
4241
4242 /* Legacy rate table. Intersection of our rates and peer rates. */
4243 __u8 legacy_rates[12];
4244
4245 /* HT rate table. Intersection of our rates and peer rates. */
4246 __u8 ht_rates[16];
4247 __u8 pad[16];
4248
4249 /* If set, interoperability mode, no proprietary extensions. */
4250 __u8 interop;
4251 __u8 pad2;
4252 __u8 station_id;
4253 __le16 amsdu_enabled;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004254} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01004255
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004256struct mwl8k_cmd_update_stadb {
4257 struct mwl8k_cmd_pkt header;
4258
4259 /* See STADB_ACTION_TYPE */
4260 __le32 action;
4261
4262 /* Peer MAC address */
4263 __u8 peer_addr[ETH_ALEN];
4264
4265 __le32 reserved;
4266
4267 /* Peer info - valid during add/update. */
4268 struct peer_capability_info peer_info;
Eric Dumazetba2d3582010-06-02 18:10:09 +00004269} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004270
Lennert Buytenheka6804002010-01-04 21:55:42 +01004271#define MWL8K_STA_DB_MODIFY_ENTRY 1
4272#define MWL8K_STA_DB_DEL_ENTRY 2
4273
4274/* Peer Entry flags - used to define the type of the peer node */
4275#define MWL8K_PEER_TYPE_ACCESSPOINT 2
4276
4277static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004278 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004279 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004280{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004281 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01004282 struct peer_capability_info *p;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004283 u32 rates;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004284 int rc;
4285
4286 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4287 if (cmd == NULL)
4288 return -ENOMEM;
4289
4290 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4291 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01004292 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004293 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004294
Lennert Buytenheka6804002010-01-04 21:55:42 +01004295 p = &cmd->peer_info;
4296 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
4297 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004298 p->ht_support = sta->ht_cap.ht_supported;
John W. Linvilleb6037422010-07-20 13:55:00 -04004299 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004300 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
4301 ((sta->ht_cap.ampdu_density & 7) << 2);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004302 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4303 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
4304 else
4305 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4306 legacy_rate_mask_to_array(p->legacy_rates, rates);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004307 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01004308 p->interop = 1;
4309 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004310
Lennert Buytenheka6804002010-01-04 21:55:42 +01004311 rc = mwl8k_post_cmd(hw, &cmd->header);
4312 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004313
Lennert Buytenheka6804002010-01-04 21:55:42 +01004314 return rc ? rc : p->station_id;
4315}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004316
Lennert Buytenheka6804002010-01-04 21:55:42 +01004317static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
4318 struct ieee80211_vif *vif, u8 *addr)
4319{
4320 struct mwl8k_cmd_update_stadb *cmd;
4321 int rc;
4322
4323 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
4324 if (cmd == NULL)
4325 return -ENOMEM;
4326
4327 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
4328 cmd->header.length = cpu_to_le16(sizeof(*cmd));
4329 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
4330 memcpy(cmd->peer_addr, addr, ETH_ALEN);
4331
4332 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004333 kfree(cmd);
4334
4335 return rc;
4336}
4337
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004338
4339/*
4340 * Interrupt handling.
4341 */
4342static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
4343{
4344 struct ieee80211_hw *hw = dev_id;
4345 struct mwl8k_priv *priv = hw->priv;
4346 u32 status;
4347
4348 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004349 if (!status)
4350 return IRQ_NONE;
4351
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004352 if (status & MWL8K_A2H_INT_TX_DONE) {
4353 status &= ~MWL8K_A2H_INT_TX_DONE;
4354 tasklet_schedule(&priv->poll_tx_task);
4355 }
4356
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004357 if (status & MWL8K_A2H_INT_RX_READY) {
4358 status &= ~MWL8K_A2H_INT_RX_READY;
4359 tasklet_schedule(&priv->poll_rx_task);
4360 }
4361
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07004362 if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05304363 iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG,
4364 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4365
4366 atomic_inc(&priv->watchdog_event_pending);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07004367 status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
4368 ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
4369 }
4370
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004371 if (status)
4372 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004373
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004374 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004375 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004376 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004377 }
4378
4379 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004380 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02004381 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004382 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004383 }
4384
4385 return IRQ_HANDLED;
4386}
4387
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004388static void mwl8k_tx_poll(unsigned long data)
4389{
4390 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4391 struct mwl8k_priv *priv = hw->priv;
4392 int limit;
4393 int i;
4394
4395 limit = 32;
4396
4397 spin_lock_bh(&priv->tx_lock);
4398
Brian Cavagnoloe6007072011-03-17 11:58:44 -07004399 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004400 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
4401
4402 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
4403 complete(priv->tx_wait);
4404 priv->tx_wait = NULL;
4405 }
4406
4407 spin_unlock_bh(&priv->tx_lock);
4408
4409 if (limit) {
4410 writel(~MWL8K_A2H_INT_TX_DONE,
4411 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4412 } else {
4413 tasklet_schedule(&priv->poll_tx_task);
4414 }
4415}
4416
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004417static void mwl8k_rx_poll(unsigned long data)
4418{
4419 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
4420 struct mwl8k_priv *priv = hw->priv;
4421 int limit;
4422
4423 limit = 32;
4424 limit -= rxq_process(hw, 0, limit);
4425 limit -= rxq_refill(hw, 0, limit);
4426
4427 if (limit) {
4428 writel(~MWL8K_A2H_INT_RX_READY,
4429 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4430 } else {
4431 tasklet_schedule(&priv->poll_rx_task);
4432 }
4433}
4434
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004435
4436/*
4437 * Core driver operations.
4438 */
Thomas Huehn36323f82012-07-23 21:33:42 +02004439static void mwl8k_tx(struct ieee80211_hw *hw,
4440 struct ieee80211_tx_control *control,
4441 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004442{
4443 struct mwl8k_priv *priv = hw->priv;
4444 int index = skb_get_queue_mapping(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004445
Lennert Buytenhek9189c102010-01-12 13:47:32 +01004446 if (!priv->radio_on) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004447 wiphy_debug(hw->wiphy,
4448 "dropped TX frame since radio disabled\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004449 dev_kfree_skb(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +01004450 return;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004451 }
4452
Thomas Huehn36323f82012-07-23 21:33:42 +02004453 mwl8k_txq_xmit(hw, index, control->sta, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004454}
4455
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004456static int mwl8k_start(struct ieee80211_hw *hw)
4457{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004458 struct mwl8k_priv *priv = hw->priv;
4459 int rc;
4460
Joe Perchesa0607fd2009-11-18 23:29:17 -08004461 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004462 IRQF_SHARED, MWL8K_NAME, hw);
4463 if (rc) {
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304464 priv->irq = -1;
Joe Perches5db55842010-08-11 19:11:19 -07004465 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004466 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004467 }
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304468 priv->irq = priv->pdev->irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004469
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004470 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004471 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004472 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004473
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004474 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004475 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Nishant Sarmukadam12488e02011-04-08 14:38:27 +05304476 iowrite32(MWL8K_A2H_EVENTS,
4477 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004478
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004479 rc = mwl8k_fw_lock(hw);
4480 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004481 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004482
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02004483 if (!priv->ap_fw) {
4484 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004485 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004486
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02004487 if (!rc)
4488 rc = mwl8k_cmd_set_pre_scan(hw);
4489
4490 if (!rc)
4491 rc = mwl8k_cmd_set_post_scan(hw,
4492 "\x00\x00\x00\x00\x00\x00");
4493 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004494
4495 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004496 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004497
4498 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004499 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004500
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004501 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004502 }
4503
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004504 if (rc) {
4505 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4506 free_irq(priv->pdev->irq, hw);
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304507 priv->irq = -1;
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004508 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004509 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02004510 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004511
4512 return rc;
4513}
4514
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004515static void mwl8k_stop(struct ieee80211_hw *hw)
4516{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004517 struct mwl8k_priv *priv = hw->priv;
4518 int i;
4519
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304520 if (!priv->hw_restart_in_progress)
4521 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004522
4523 ieee80211_stop_queues(hw);
4524
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004525 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004526 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Brian Cavagnolobf3ca7f2011-04-06 14:18:46 +05304527 if (priv->irq != -1) {
4528 free_irq(priv->pdev->irq, hw);
4529 priv->irq = -1;
4530 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004531
4532 /* Stop finalize join worker */
4533 cancel_work_sync(&priv->finalize_join_worker);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07004534 cancel_work_sync(&priv->watchdog_ba_handle);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004535 if (priv->beacon_skb != NULL)
4536 dev_kfree_skb(priv->beacon_skb);
4537
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004538 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004539 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004540 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004541
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004542 /* Return all skbs to mac80211 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07004543 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004544 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004545}
4546
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004547static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
4548
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004549static int mwl8k_add_interface(struct ieee80211_hw *hw,
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004550 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004551{
4552 struct mwl8k_priv *priv = hw->priv;
4553 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004554 u32 macids_supported;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004555 int macid, rc;
4556 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004557
4558 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004559 * Reject interface creation if sniffer mode is active, as
4560 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004561 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004562 */
4563 if (priv->sniffer_enabled) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004564 wiphy_info(hw->wiphy,
4565 "unable to create STA interface because sniffer mode is enabled\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004566 return -EINVAL;
4567 }
4568
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004569 di = priv->device_info;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004570 switch (vif->type) {
4571 case NL80211_IFTYPE_AP:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004572 if (!priv->ap_fw && di->fw_image_ap) {
4573 /* we must load the ap fw to meet this request */
4574 if (!list_empty(&priv->vif_list))
4575 return -EBUSY;
4576 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4577 if (rc)
4578 return rc;
4579 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004580 macids_supported = priv->ap_macids_supported;
4581 break;
4582 case NL80211_IFTYPE_STATION:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004583 if (priv->ap_fw && di->fw_image_sta) {
4584 /* we must load the sta fw to meet this request */
4585 if (!list_empty(&priv->vif_list))
4586 return -EBUSY;
4587 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4588 if (rc)
4589 return rc;
4590 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004591 macids_supported = priv->sta_macids_supported;
4592 break;
4593 default:
4594 return -EINVAL;
4595 }
4596
4597 macid = ffs(macids_supported & ~priv->macids_used);
4598 if (!macid--)
4599 return -EBUSY;
4600
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004601 /* Setup driver private area. */
Johannes Berg1ed32e42009-12-23 13:15:45 +01004602 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004603 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004604 mwl8k_vif->vif = vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004605 mwl8k_vif->macid = macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004606 mwl8k_vif->seqno = 0;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08004607 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
4608 mwl8k_vif->is_hw_crypto_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004609
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004610 /* Set the mac address. */
4611 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
4612
4613 if (priv->ap_fw)
4614 mwl8k_cmd_set_new_stn_add_self(hw, vif);
4615
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004616 priv->macids_used |= 1 << mwl8k_vif->macid;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004617 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004618
4619 return 0;
4620}
4621
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304622static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
4623{
4624 /* Has ieee80211_restart_hw re-added the removed interfaces? */
4625 if (!priv->macids_used)
4626 return;
4627
4628 priv->macids_used &= ~(1 << vif->macid);
4629 list_del(&vif->list);
4630}
4631
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004632static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01004633 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004634{
4635 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004636 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004637
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004638 if (priv->ap_fw)
4639 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
4640
Yogesh Ashok Powar197a4e42012-02-01 16:19:54 +05304641 mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004642
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05304643 mwl8k_remove_vif(priv, mwl8k_vif);
4644}
4645
4646static void mwl8k_hw_restart_work(struct work_struct *work)
4647{
4648 struct mwl8k_priv *priv =
4649 container_of(work, struct mwl8k_priv, fw_reload);
4650 struct ieee80211_hw *hw = priv->hw;
4651 struct mwl8k_device_info *di;
4652 int rc;
4653
4654 /* If some command is waiting for a response, clear it */
4655 if (priv->hostcmd_wait != NULL) {
4656 complete(priv->hostcmd_wait);
4657 priv->hostcmd_wait = NULL;
4658 }
4659
4660 priv->hw_restart_owner = current;
4661 di = priv->device_info;
4662 mwl8k_fw_lock(hw);
4663
4664 if (priv->ap_fw)
4665 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
4666 else
4667 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
4668
4669 if (rc)
4670 goto fail;
4671
4672 priv->hw_restart_owner = NULL;
4673 priv->hw_restart_in_progress = false;
4674
4675 /*
4676 * This unlock will wake up the queues and
4677 * also opens the command path for other
4678 * commands
4679 */
4680 mwl8k_fw_unlock(hw);
4681
4682 ieee80211_restart_hw(hw);
4683
4684 wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
4685
4686 return;
4687fail:
4688 mwl8k_fw_unlock(hw);
4689
4690 wiphy_err(hw->wiphy, "Firmware restart failed\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004691}
4692
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004693static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004694{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004695 struct ieee80211_conf *conf = &hw->conf;
4696 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004697 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004698
Lennert Buytenhek7595d672009-08-17 23:59:40 +02004699 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004700 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004701 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02004702 }
4703
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004704 rc = mwl8k_fw_lock(hw);
4705 if (rc)
4706 return rc;
4707
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004708 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004709 if (rc)
4710 goto out;
4711
Lennert Buytenhek610677d2010-01-04 21:56:46 +01004712 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004713 if (rc)
4714 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004715
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004716 if (conf->power_level > 18)
4717 conf->power_level = 18;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004718
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004719 if (priv->ap_fw) {
Nishant Sarmukadam03217082011-04-05 14:18:09 +05304720
4721 if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
4722 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
4723 if (rc)
4724 goto out;
4725 }
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08004726
Nishant Sarmukadamda62b762011-02-17 14:45:16 -08004727 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
4728 if (rc)
4729 wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
4730 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
4731 if (rc)
4732 wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
4733
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004734 } else {
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08004735 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
4736 if (rc)
4737 goto out;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02004738 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
4739 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004740
Lennert Buytenhekee03a932009-07-17 07:19:37 +02004741out:
4742 mwl8k_fw_unlock(hw);
4743
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004744 return rc;
4745}
4746
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004747static void
4748mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4749 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004750{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004751 struct mwl8k_priv *priv = hw->priv;
Yogesh Ashok Powarba30c4a2011-04-09 00:25:37 +05304752 u32 ap_legacy_rates = 0;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004753 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004754 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004755
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004756 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004757 return;
4758
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004759 /*
4760 * No need to capture a beacon if we're no longer associated.
4761 */
4762 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
4763 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004764
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004765 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004766 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004767 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004768 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004769 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01004770
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004771 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004772
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004773 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004774 if (ap == NULL) {
4775 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004776 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004777 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01004778
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004779 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
4780 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
4781 } else {
4782 ap_legacy_rates =
4783 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
4784 }
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004785 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004786
4787 rcu_read_unlock();
4788 }
4789
4790 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004791 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004792 if (rc)
4793 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004794
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01004795 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004796 if (rc)
4797 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004798 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004799
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004800 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004801 rc = mwl8k_set_radio_preamble(hw,
4802 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004803 if (rc)
4804 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004805 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004806
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004807 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004808 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004809 if (rc)
4810 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004811 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004812
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01004813 if (vif->bss_conf.assoc &&
4814 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4815 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004816 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004817 if (rc)
4818 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004819 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004820
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004821 if (vif->bss_conf.assoc &&
4822 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004823 /*
4824 * Finalize the join. Tell rx handler to process
4825 * next beacon from our BSSID.
4826 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01004827 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004828 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004829 }
4830
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004831out:
4832 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004833}
4834
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004835static void
4836mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4837 struct ieee80211_bss_conf *info, u32 changed)
4838{
4839 int rc;
4840
4841 if (mwl8k_fw_lock(hw))
4842 return;
4843
4844 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4845 rc = mwl8k_set_radio_preamble(hw,
4846 vif->bss_conf.use_short_preamble);
4847 if (rc)
4848 goto out;
4849 }
4850
4851 if (changed & BSS_CHANGED_BASIC_RATES) {
4852 int idx;
4853 int rate;
4854
4855 /*
4856 * Use lowest supported basic rate for multicasts
4857 * and management frames (such as probe responses --
4858 * beacons will always go out at 1 Mb/s).
4859 */
4860 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004861 if (idx)
4862 idx--;
4863
4864 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4865 rate = mwl8k_rates_24[idx].hw_value;
4866 else
4867 rate = mwl8k_rates_50[idx].hw_value;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004868
4869 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4870 }
4871
4872 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
4873 struct sk_buff *skb;
4874
4875 skb = ieee80211_beacon_get(hw, vif);
4876 if (skb != NULL) {
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004877 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004878 kfree_skb(skb);
4879 }
4880 }
4881
4882 if (changed & BSS_CHANGED_BEACON_ENABLED)
Lennert Buytenhekaa21d0f62010-01-12 13:50:36 +01004883 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004884
4885out:
4886 mwl8k_fw_unlock(hw);
4887}
4888
4889static void
4890mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4891 struct ieee80211_bss_conf *info, u32 changed)
4892{
4893 struct mwl8k_priv *priv = hw->priv;
4894
4895 if (!priv->ap_fw)
4896 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
4897 else
4898 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
4899}
4900
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004901static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad2010-04-01 21:22:57 +00004902 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004903{
4904 struct mwl8k_cmd_pkt *cmd;
4905
Lennert Buytenhek447ced02009-10-22 20:19:50 +02004906 /*
4907 * Synthesize and return a command packet that programs the
4908 * hardware multicast address filter. At this point we don't
4909 * know whether FIF_ALLMULTI is being requested, but if it is,
4910 * we'll end up throwing this packet away and creating a new
4911 * one in mwl8k_configure_filter().
4912 */
Jiri Pirko22bedad2010-04-01 21:22:57 +00004913 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004914
4915 return (unsigned long)cmd;
4916}
4917
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004918static int
4919mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
4920 unsigned int changed_flags,
4921 unsigned int *total_flags)
4922{
4923 struct mwl8k_priv *priv = hw->priv;
4924
4925 /*
4926 * Hardware sniffer mode is mutually exclusive with STA
4927 * operation, so refuse to enable sniffer mode if a STA
4928 * interface is active.
4929 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004930 if (!list_empty(&priv->vif_list)) {
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004931 if (net_ratelimit())
Joe Perchesc96c31e2010-07-26 14:39:58 -07004932 wiphy_info(hw->wiphy,
4933 "not enabling sniffer mode because STA interface is active\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004934 return 0;
4935 }
4936
4937 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004938 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004939 return 0;
4940 priv->sniffer_enabled = true;
4941 }
4942
4943 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
4944 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
4945 FIF_OTHER_BSS;
4946
4947 return 1;
4948}
4949
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004950static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
4951{
4952 if (!list_empty(&priv->vif_list))
4953 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
4954
4955 return NULL;
4956}
4957
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004958static void mwl8k_configure_filter(struct ieee80211_hw *hw,
4959 unsigned int changed_flags,
4960 unsigned int *total_flags,
4961 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004962{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004963 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004964 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
4965
4966 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02004967 * AP firmware doesn't allow fine-grained control over
4968 * the receive filter.
4969 */
4970 if (priv->ap_fw) {
4971 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4972 kfree(cmd);
4973 return;
4974 }
4975
4976 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004977 * Enable hardware sniffer mode if FIF_CONTROL or
4978 * FIF_OTHER_BSS is requested.
4979 */
4980 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
4981 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
4982 kfree(cmd);
4983 return;
4984 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004985
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004986 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02004987 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004988
Lennert Buytenhek90852f72010-01-02 10:31:42 +01004989 if (mwl8k_fw_lock(hw)) {
4990 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004991 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01004992 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004993
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004994 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004995 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004996 priv->sniffer_enabled = false;
4997 }
4998
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004999 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02005000 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
5001 /*
5002 * Disable the BSS filter.
5003 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005004 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02005005 } else {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005006 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01005007 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02005008
Lennert Buytenhek77165d82009-10-22 20:19:53 +02005009 /*
5010 * Enable the BSS filter.
5011 *
5012 * If there is an active STA interface, use that
5013 * interface's BSSID, otherwise use a dummy one
5014 * (where the OUI part needs to be nonzero for
5015 * the BSSID to be accepted by POST_SCAN).
5016 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005017 mwl8k_vif = mwl8k_first_vif(priv);
5018 if (mwl8k_vif != NULL)
5019 bssid = mwl8k_vif->vif->bss_conf.bssid;
5020 else
5021 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02005022
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005023 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005024 }
5025 }
5026
Lennert Buytenhek447ced02009-10-22 20:19:50 +02005027 /*
5028 * If FIF_ALLMULTI is being requested, throw away the command
5029 * packet that ->prepare_multicast() built and replace it with
5030 * a command packet that enables reception of all multicast
5031 * packets.
5032 */
5033 if (*total_flags & FIF_ALLMULTI) {
5034 kfree(cmd);
Jiri Pirko22bedad2010-04-01 21:22:57 +00005035 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
Lennert Buytenhek447ced02009-10-22 20:19:50 +02005036 }
5037
5038 if (cmd != NULL) {
5039 mwl8k_post_cmd(hw, cmd);
5040 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005041 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02005042
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02005043 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005044}
5045
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005046static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5047{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01005048 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005049}
5050
Johannes Berg4a6967b2010-02-19 19:18:37 +01005051static int mwl8k_sta_remove(struct ieee80211_hw *hw,
5052 struct ieee80211_vif *vif,
5053 struct ieee80211_sta *sta)
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005054{
5055 struct mwl8k_priv *priv = hw->priv;
5056
Johannes Berg4a6967b2010-02-19 19:18:37 +01005057 if (priv->ap_fw)
5058 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
5059 else
5060 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
5061}
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005062
Johannes Berg4a6967b2010-02-19 19:18:37 +01005063static int mwl8k_sta_add(struct ieee80211_hw *hw,
5064 struct ieee80211_vif *vif,
5065 struct ieee80211_sta *sta)
5066{
5067 struct mwl8k_priv *priv = hw->priv;
5068 int ret;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005069 int i;
5070 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
5071 struct ieee80211_key_conf *key;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005072
Johannes Berg4a6967b2010-02-19 19:18:37 +01005073 if (!priv->ap_fw) {
5074 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
5075 if (ret >= 0) {
5076 MWL8K_STA(sta)->peer_id = ret;
Nishant Sarmukadam170335432011-03-17 11:58:48 -07005077 if (sta->ht_cap.ht_supported)
5078 MWL8K_STA(sta)->is_ampdu_allowed = true;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005079 ret = 0;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005080 }
Johannes Berg4a6967b2010-02-19 19:18:37 +01005081
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08005082 } else {
5083 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005084 }
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01005085
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08005086 for (i = 0; i < NUM_WEP_KEYS; i++) {
5087 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
5088 if (mwl8k_vif->wep_key_conf[i].enabled)
5089 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
5090 }
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005091 return ret;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01005092}
5093
Eliad Peller8a3a3c82011-10-02 10:15:52 +02005094static int mwl8k_conf_tx(struct ieee80211_hw *hw,
5095 struct ieee80211_vif *vif, u16 queue,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005096 const struct ieee80211_tx_queue_params *params)
5097{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005098 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005099 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005100
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005101 rc = mwl8k_fw_lock(hw);
5102 if (!rc) {
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005103 BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005104 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
5105
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005106 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005107 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005108
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005109 if (!rc) {
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005110 int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005111 rc = mwl8k_cmd_set_edca_params(hw, q,
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005112 params->cw_min,
5113 params->cw_max,
5114 params->aifs,
5115 params->txop);
Nishant Sarmukadam85c92052011-02-17 14:45:18 -08005116 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005117
5118 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005119 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02005120
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005121 return rc;
5122}
5123
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005124static int mwl8k_get_stats(struct ieee80211_hw *hw,
5125 struct ieee80211_low_level_stats *stats)
5126{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01005127 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005128}
5129
John W. Linville0d462bb2010-07-28 14:04:24 -04005130static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
5131 struct survey_info *survey)
5132{
5133 struct mwl8k_priv *priv = hw->priv;
5134 struct ieee80211_conf *conf = &hw->conf;
5135
5136 if (idx != 0)
5137 return -ENOENT;
5138
5139 survey->channel = conf->channel;
5140 survey->filled = SURVEY_INFO_NOISE_DBM;
5141 survey->noise = priv->noise;
5142
5143 return 0;
5144}
5145
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005146#define MAX_AMPDU_ATTEMPTS 5
5147
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005148static int
5149mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5150 enum ieee80211_ampdu_mlme_action action,
Johannes Berg0b01f032011-01-18 13:51:05 +01005151 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5152 u8 buf_size)
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005153{
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005154
5155 int i, rc = 0;
5156 struct mwl8k_priv *priv = hw->priv;
5157 struct mwl8k_ampdu_stream *stream;
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305158 u8 *addr = sta->addr, idx;
Yogesh Ashok Powarfd712f52012-11-06 19:22:35 +05305159 struct mwl8k_sta *sta_info = MWL8K_STA(sta);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005160
5161 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
5162 return -ENOTSUPP;
5163
5164 spin_lock(&priv->stream_lock);
5165 stream = mwl8k_lookup_stream(hw, addr, tid);
5166
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005167 switch (action) {
5168 case IEEE80211_AMPDU_RX_START:
5169 case IEEE80211_AMPDU_RX_STOP:
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005170 break;
5171 case IEEE80211_AMPDU_TX_START:
5172 /* By the time we get here the hw queues may contain outgoing
5173 * packets for this RA/TID that are not part of this BA
5174 * session. The hw will assign sequence numbers to these
5175 * packets as they go out. So if we query the hw for its next
5176 * sequence number and use that for the SSN here, it may end up
5177 * being wrong, which will lead to sequence number mismatch at
5178 * the recipient. To avoid this, we reset the sequence number
5179 * to O for the first MPDU in this BA stream.
5180 */
5181 *ssn = 0;
5182 if (stream == NULL) {
5183 /* This means that somebody outside this driver called
5184 * ieee80211_start_tx_ba_session. This is unexpected
5185 * because we do our own rate control. Just warn and
5186 * move on.
5187 */
5188 wiphy_warn(hw->wiphy, "Unexpected call to %s. "
5189 "Proceeding anyway.\n", __func__);
5190 stream = mwl8k_add_stream(hw, sta, tid);
5191 }
5192 if (stream == NULL) {
5193 wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
5194 rc = -EBUSY;
5195 break;
5196 }
5197 stream->state = AMPDU_STREAM_IN_PROGRESS;
5198
5199 /* Release the lock before we do the time consuming stuff */
5200 spin_unlock(&priv->stream_lock);
5201 for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
Yogesh Ashok Powarfd712f52012-11-06 19:22:35 +05305202
5203 /* Check if link is still valid */
5204 if (!sta_info->is_ampdu_allowed) {
5205 spin_lock(&priv->stream_lock);
5206 mwl8k_remove_stream(hw, stream);
5207 spin_unlock(&priv->stream_lock);
5208 return -EBUSY;
5209 }
5210
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05305211 rc = mwl8k_check_ba(hw, stream, vif);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005212
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305213 /* If HW restart is in progress mwl8k_post_cmd will
5214 * return -EBUSY. Avoid retrying mwl8k_check_ba in
5215 * such cases
5216 */
5217 if (!rc || rc == -EBUSY)
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005218 break;
5219 /*
5220 * HW queues take time to be flushed, give them
5221 * sufficient time
5222 */
5223
5224 msleep(1000);
5225 }
5226 spin_lock(&priv->stream_lock);
5227 if (rc) {
5228 wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
5229 " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
5230 mwl8k_remove_stream(hw, stream);
5231 rc = -EBUSY;
5232 break;
5233 }
5234 ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
5235 break;
Johannes Berg18b559d2012-07-18 13:51:25 +02005236 case IEEE80211_AMPDU_TX_STOP_CONT:
5237 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5238 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305239 if (stream) {
5240 if (stream->state == AMPDU_STREAM_ACTIVE) {
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305241 idx = stream->idx;
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305242 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305243 mwl8k_destroy_ba(hw, idx);
Yogesh Ashok Powareca107f2011-12-20 11:37:08 +05305244 spin_lock(&priv->stream_lock);
5245 }
5246 mwl8k_remove_stream(hw, stream);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005247 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005248 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
5249 break;
5250 case IEEE80211_AMPDU_TX_OPERATIONAL:
5251 BUG_ON(stream == NULL);
5252 BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
5253 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powarf95275c2012-11-08 19:10:44 +05305254 rc = mwl8k_create_ba(hw, stream, buf_size, vif);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005255 spin_lock(&priv->stream_lock);
5256 if (!rc)
5257 stream->state = AMPDU_STREAM_ACTIVE;
5258 else {
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305259 idx = stream->idx;
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005260 spin_unlock(&priv->stream_lock);
Yogesh Ashok Powar07f6dda2013-01-03 13:23:33 +05305261 mwl8k_destroy_ba(hw, idx);
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005262 spin_lock(&priv->stream_lock);
5263 wiphy_debug(hw->wiphy,
5264 "Failed adding stream for sta %pM tid %d\n",
5265 addr, tid);
5266 mwl8k_remove_stream(hw, stream);
5267 }
5268 break;
5269
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005270 default:
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005271 rc = -ENOTSUPP;
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005272 }
Nishant Sarmukadam65f3ddc2011-03-17 11:58:46 -07005273
5274 spin_unlock(&priv->stream_lock);
5275 return rc;
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005276}
5277
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005278static const struct ieee80211_ops mwl8k_ops = {
5279 .tx = mwl8k_tx,
5280 .start = mwl8k_start,
5281 .stop = mwl8k_stop,
5282 .add_interface = mwl8k_add_interface,
5283 .remove_interface = mwl8k_remove_interface,
5284 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005285 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02005286 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005287 .configure_filter = mwl8k_configure_filter,
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08005288 .set_key = mwl8k_set_key,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005289 .set_rts_threshold = mwl8k_set_rts_threshold,
Johannes Berg4a6967b2010-02-19 19:18:37 +01005290 .sta_add = mwl8k_sta_add,
5291 .sta_remove = mwl8k_sta_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005292 .conf_tx = mwl8k_conf_tx,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005293 .get_stats = mwl8k_get_stats,
John W. Linville0d462bb2010-07-28 14:04:24 -04005294 .get_survey = mwl8k_get_survey,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01005295 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005296};
5297
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005298static void mwl8k_finalize_join_worker(struct work_struct *work)
5299{
5300 struct mwl8k_priv *priv =
5301 container_of(work, struct mwl8k_priv, finalize_join_worker);
5302 struct sk_buff *skb = priv->beacon_skb;
Johannes Berg56007a02010-01-26 14:19:52 +01005303 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5304 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
5305 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
5306 mgmt->u.beacon.variable, len);
5307 int dtim_period = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005308
Johannes Berg56007a02010-01-26 14:19:52 +01005309 if (tim && tim[1] >= 2)
5310 dtim_period = tim[3];
5311
5312 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01005313
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005314 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005315 priv->beacon_skb = NULL;
5316}
5317
John W. Linvillebcb628d2009-11-06 16:40:16 -05005318enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005319 MWL8363 = 0,
5320 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05005321 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02005322};
5323
Yogesh Ashok Powarc2f2e202013-01-03 13:24:44 +05305324#define MWL8K_8366_AP_FW_API 3
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005325#define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
5326#define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
5327
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005328static struct mwl8k_device_info mwl8k_info_tbl[] = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005329 [MWL8363] = {
5330 .part_name = "88w8363",
5331 .helper_image = "mwl8k/helper_8363.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005332 .fw_image_sta = "mwl8k/fmimage_8363.fw",
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005333 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01005334 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05005335 .part_name = "88w8687",
5336 .helper_image = "mwl8k/helper_8687.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005337 .fw_image_sta = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05005338 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01005339 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05005340 .part_name = "88w8366",
5341 .helper_image = "mwl8k/helper_8366.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005342 .fw_image_sta = "mwl8k/fmimage_8366.fw",
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005343 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
5344 .fw_api_ap = MWL8K_8366_AP_FW_API,
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01005345 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05005346 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005347};
5348
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01005349MODULE_FIRMWARE("mwl8k/helper_8363.fw");
5350MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
5351MODULE_FIRMWARE("mwl8k/helper_8687.fw");
5352MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
5353MODULE_FIRMWARE("mwl8k/helper_8366.fw");
5354MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08005355MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01005356
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005357static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Benjamin Larssone5868ba2010-03-19 01:46:10 +01005358 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01005359 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
5360 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05005361 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
5362 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
5363 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01005364 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05005365 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005366};
5367MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
5368
Brian Cavagnolo99020472010-11-12 17:23:52 -08005369static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
5370{
5371 int rc;
5372 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
5373 "Trying alternative firmware %s\n", pci_name(priv->pdev),
5374 priv->fw_pref, priv->fw_alt);
5375 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
5376 if (rc) {
5377 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5378 pci_name(priv->pdev), priv->fw_alt);
5379 return rc;
5380 }
5381 return 0;
5382}
5383
5384static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
5385static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
5386{
5387 struct mwl8k_priv *priv = context;
5388 struct mwl8k_device_info *di = priv->device_info;
5389 int rc;
5390
5391 switch (priv->fw_state) {
5392 case FW_STATE_INIT:
5393 if (!fw) {
5394 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
5395 pci_name(priv->pdev), di->helper_image);
5396 goto fail;
5397 }
5398 priv->fw_helper = fw;
5399 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
5400 true);
5401 if (rc && priv->fw_alt) {
5402 rc = mwl8k_request_alt_fw(priv);
5403 if (rc)
5404 goto fail;
5405 priv->fw_state = FW_STATE_LOADING_ALT;
5406 } else if (rc)
5407 goto fail;
5408 else
5409 priv->fw_state = FW_STATE_LOADING_PREF;
5410 break;
5411
5412 case FW_STATE_LOADING_PREF:
5413 if (!fw) {
5414 if (priv->fw_alt) {
5415 rc = mwl8k_request_alt_fw(priv);
5416 if (rc)
5417 goto fail;
5418 priv->fw_state = FW_STATE_LOADING_ALT;
5419 } else
5420 goto fail;
5421 } else {
5422 priv->fw_ucode = fw;
5423 rc = mwl8k_firmware_load_success(priv);
5424 if (rc)
5425 goto fail;
5426 else
5427 complete(&priv->firmware_loading_complete);
5428 }
5429 break;
5430
5431 case FW_STATE_LOADING_ALT:
5432 if (!fw) {
5433 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
5434 pci_name(priv->pdev), di->helper_image);
5435 goto fail;
5436 }
5437 priv->fw_ucode = fw;
5438 rc = mwl8k_firmware_load_success(priv);
5439 if (rc)
5440 goto fail;
5441 else
5442 complete(&priv->firmware_loading_complete);
5443 break;
5444
5445 default:
5446 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
5447 MWL8K_NAME, priv->fw_state);
5448 BUG_ON(1);
5449 }
5450
5451 return;
5452
5453fail:
5454 priv->fw_state = FW_STATE_ERROR;
5455 complete(&priv->firmware_loading_complete);
5456 device_release_driver(&priv->pdev->dev);
5457 mwl8k_release_firmware(priv);
5458}
5459
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305460#define MAX_RESTART_ATTEMPTS 1
Brian Cavagnolo99020472010-11-12 17:23:52 -08005461static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
5462 bool nowait)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005463{
5464 struct mwl8k_priv *priv = hw->priv;
5465 int rc;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305466 int count = MAX_RESTART_ATTEMPTS;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005467
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305468retry:
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005469 /* Reset firmware and hardware */
5470 mwl8k_hw_reset(priv);
5471
5472 /* Ask userland hotplug daemon for the device firmware */
Brian Cavagnolo99020472010-11-12 17:23:52 -08005473 rc = mwl8k_request_firmware(priv, fw_image, nowait);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005474 if (rc) {
5475 wiphy_err(hw->wiphy, "Firmware files not found\n");
5476 return rc;
5477 }
5478
Brian Cavagnolo99020472010-11-12 17:23:52 -08005479 if (nowait)
5480 return rc;
5481
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005482 /* Load firmware into hardware */
5483 rc = mwl8k_load_firmware(hw);
5484 if (rc)
5485 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5486
5487 /* Reclaim memory once firmware is successfully loaded */
5488 mwl8k_release_firmware(priv);
5489
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305490 if (rc && count) {
5491 /* FW did not start successfully;
5492 * lets try one more time
5493 */
5494 count--;
5495 wiphy_err(hw->wiphy, "Trying to reload the firmware again\n");
5496 msleep(20);
5497 goto retry;
5498 }
5499
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005500 return rc;
5501}
5502
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005503static int mwl8k_init_txqs(struct ieee80211_hw *hw)
5504{
5505 struct mwl8k_priv *priv = hw->priv;
5506 int rc = 0;
5507 int i;
5508
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005509 for (i = 0; i < mwl8k_tx_queues(priv); i++) {
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005510 rc = mwl8k_txq_init(hw, i);
5511 if (rc)
5512 break;
5513 if (priv->ap_fw)
5514 iowrite32(priv->txq[i].txd_dma,
5515 priv->sram + priv->txq_offset[i]);
5516 }
5517 return rc;
5518}
5519
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005520/* initialize hw after successfully loading a firmware image */
5521static int mwl8k_probe_hw(struct ieee80211_hw *hw)
5522{
5523 struct mwl8k_priv *priv = hw->priv;
5524 int rc = 0;
5525 int i;
5526
5527 if (priv->ap_fw) {
5528 priv->rxd_ops = priv->device_info->ap_rxd_ops;
5529 if (priv->rxd_ops == NULL) {
5530 wiphy_err(hw->wiphy,
5531 "Driver does not have AP firmware image support for this hardware\n");
5532 goto err_stop_firmware;
5533 }
5534 } else {
5535 priv->rxd_ops = &rxd_sta_ops;
5536 }
5537
5538 priv->sniffer_enabled = false;
5539 priv->wmm_enabled = false;
5540 priv->pending_tx_pkts = 0;
Yogesh Ashok Powarc27a54d2013-01-03 13:24:19 +05305541 atomic_set(&priv->watchdog_event_pending, 0);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005542
5543 rc = mwl8k_rxq_init(hw, 0);
5544 if (rc)
5545 goto err_stop_firmware;
5546 rxq_refill(hw, 0, INT_MAX);
5547
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005548 /* For the sta firmware, we need to know the dma addresses of tx queues
5549 * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
5550 * prior to issuing this command. But for the AP case, we learn the
5551 * total number of queues from the result CMD_GET_HW_SPEC, so for this
5552 * case we must initialize the tx queues after.
5553 */
Brian Cavagnolo8a7a5782011-03-17 11:58:42 -07005554 priv->num_ampdu_queues = 0;
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005555 if (!priv->ap_fw) {
5556 rc = mwl8k_init_txqs(hw);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005557 if (rc)
5558 goto err_free_queues;
5559 }
5560
5561 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
5562 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07005563 iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
5564 MWL8K_A2H_INT_BA_WATCHDOG,
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005565 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
Nishant Sarmukadam12488e02011-04-08 14:38:27 +05305566 iowrite32(MWL8K_A2H_INT_OPC_DONE,
5567 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005568
5569 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
5570 IRQF_SHARED, MWL8K_NAME, hw);
5571 if (rc) {
5572 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
5573 goto err_free_queues;
5574 }
5575
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305576 /*
5577 * When hw restart is requested,
5578 * mac80211 will take care of clearing
5579 * the ampdu streams, so do not clear
5580 * the ampdu state here
5581 */
5582 if (!priv->hw_restart_in_progress)
5583 memset(priv->ampdu, 0, sizeof(priv->ampdu));
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07005584
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005585 /*
5586 * Temporarily enable interrupts. Initial firmware host
5587 * commands use interrupts and avoid polling. Disable
5588 * interrupts when done.
5589 */
5590 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5591
5592 /* Get config data, mac addrs etc */
5593 if (priv->ap_fw) {
5594 rc = mwl8k_cmd_get_hw_spec_ap(hw);
5595 if (!rc)
Brian Cavagnolo73b46322011-03-17 11:58:41 -07005596 rc = mwl8k_init_txqs(hw);
5597 if (!rc)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005598 rc = mwl8k_cmd_set_hw_spec(hw);
5599 } else {
5600 rc = mwl8k_cmd_get_hw_spec_sta(hw);
5601 }
5602 if (rc) {
5603 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
5604 goto err_free_irq;
5605 }
5606
5607 /* Turn radio off */
5608 rc = mwl8k_cmd_radio_disable(hw);
5609 if (rc) {
5610 wiphy_err(hw->wiphy, "Cannot disable\n");
5611 goto err_free_irq;
5612 }
5613
5614 /* Clear MAC address */
5615 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
5616 if (rc) {
5617 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
5618 goto err_free_irq;
5619 }
5620
5621 /* Disable interrupts */
5622 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5623 free_irq(priv->pdev->irq, hw);
5624
5625 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
5626 priv->device_info->part_name,
5627 priv->hw_rev, hw->wiphy->perm_addr,
5628 priv->ap_fw ? "AP" : "STA",
5629 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
5630 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
5631
5632 return 0;
5633
5634err_free_irq:
5635 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
5636 free_irq(priv->pdev->irq, hw);
5637
5638err_free_queues:
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005639 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005640 mwl8k_txq_deinit(hw, i);
5641 mwl8k_rxq_deinit(hw, 0);
5642
5643err_stop_firmware:
5644 mwl8k_hw_reset(priv);
5645
5646 return rc;
5647}
5648
5649/*
5650 * invoke mwl8k_reload_firmware to change the firmware image after the device
5651 * has already been registered
5652 */
5653static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
5654{
5655 int i, rc = 0;
5656 struct mwl8k_priv *priv = hw->priv;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305657 struct mwl8k_vif *vif, *tmp_vif;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005658
5659 mwl8k_stop(hw);
5660 mwl8k_rxq_deinit(hw, 0);
5661
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305662 /*
5663 * All the existing interfaces are re-added by the ieee80211_reconfig;
5664 * which means driver should remove existing interfaces before calling
5665 * ieee80211_restart_hw
5666 */
5667 if (priv->hw_restart_in_progress)
5668 list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list)
5669 mwl8k_remove_vif(priv, vif);
5670
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005671 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005672 mwl8k_txq_deinit(hw, i);
5673
Brian Cavagnolo99020472010-11-12 17:23:52 -08005674 rc = mwl8k_init_firmware(hw, fw_image, false);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005675 if (rc)
5676 goto fail;
5677
5678 rc = mwl8k_probe_hw(hw);
5679 if (rc)
5680 goto fail;
5681
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305682 if (priv->hw_restart_in_progress)
5683 return rc;
5684
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005685 rc = mwl8k_start(hw);
5686 if (rc)
5687 goto fail;
5688
5689 rc = mwl8k_config(hw, ~0);
5690 if (rc)
5691 goto fail;
5692
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005693 for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
Eliad Peller8a3a3c82011-10-02 10:15:52 +02005694 rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005695 if (rc)
5696 goto fail;
5697 }
5698
5699 return rc;
5700
5701fail:
5702 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
5703 return rc;
5704}
5705
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305706static const struct ieee80211_iface_limit ap_if_limits[] = {
5707 { .max = 8, .types = BIT(NL80211_IFTYPE_AP) },
5708};
5709
5710static const struct ieee80211_iface_combination ap_if_comb = {
5711 .limits = ap_if_limits,
5712 .n_limits = ARRAY_SIZE(ap_if_limits),
5713 .max_interfaces = 8,
5714 .num_different_channels = 1,
5715};
5716
5717
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005718static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
5719{
5720 struct ieee80211_hw *hw = priv->hw;
5721 int i, rc;
5722
Brian Cavagnolo99020472010-11-12 17:23:52 -08005723 rc = mwl8k_load_firmware(hw);
5724 mwl8k_release_firmware(priv);
5725 if (rc) {
5726 wiphy_err(hw->wiphy, "Cannot start firmware\n");
5727 return rc;
5728 }
5729
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005730 /*
5731 * Extra headroom is the size of the required DMA header
5732 * minus the size of the smallest 802.11 frame (CTS frame).
5733 */
5734 hw->extra_tx_headroom =
5735 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
5736
Yogesh Ashok Powarff776ce2011-04-28 17:34:48 +05305737 hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0;
5738
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005739 hw->channel_change_time = 10;
5740
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005741 hw->queues = MWL8K_TX_WMM_QUEUES;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005742
5743 /* Set rssi values to dBm */
Nishant Sarmukadam0bf22c32011-02-17 14:45:17 -08005744 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
Yogesh Ashok Powar2a36a0e2011-08-29 17:12:44 +05305745
5746 /*
5747 * Ask mac80211 to not to trigger PS mode
5748 * based on PM bit of incoming frames.
5749 */
5750 if (priv->ap_fw)
5751 hw->flags |= IEEE80211_HW_AP_LINK_PS;
5752
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005753 hw->vif_data_size = sizeof(struct mwl8k_vif);
5754 hw->sta_data_size = sizeof(struct mwl8k_sta);
5755
5756 priv->macids_used = 0;
5757 INIT_LIST_HEAD(&priv->vif_list);
5758
5759 /* Set default radio state and preamble */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005760 priv->radio_on = false;
5761 priv->radio_short_preamble = false;
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005762
5763 /* Finalize join worker */
5764 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
Nishant Sarmukadam3aefc372011-03-17 11:58:47 -07005765 /* Handle watchdog ba events */
5766 INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305767 /* To reload the firmware if it crashes */
5768 INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005769
5770 /* TX reclaim and RX tasklets. */
5771 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
5772 tasklet_disable(&priv->poll_tx_task);
5773 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
5774 tasklet_disable(&priv->poll_rx_task);
5775
5776 /* Power management cookie */
5777 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
5778 if (priv->cookie == NULL)
5779 return -ENOMEM;
5780
5781 mutex_init(&priv->fw_mutex);
5782 priv->fw_mutex_owner = NULL;
5783 priv->fw_mutex_depth = 0;
5784 priv->hostcmd_wait = NULL;
5785
5786 spin_lock_init(&priv->tx_lock);
5787
Brian Cavagnoloac109fd2011-03-17 11:58:45 -07005788 spin_lock_init(&priv->stream_lock);
5789
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005790 priv->tx_wait = NULL;
5791
5792 rc = mwl8k_probe_hw(hw);
5793 if (rc)
5794 goto err_free_cookie;
5795
5796 hw->wiphy->interface_modes = 0;
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305797
5798 if (priv->ap_macids_supported || priv->device_info->fw_image_ap) {
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005799 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
Yogesh Ashok Powar5d377fc2012-11-06 19:22:16 +05305800 hw->wiphy->iface_combinations = &ap_if_comb;
5801 hw->wiphy->n_iface_combinations = 1;
5802 }
5803
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005804 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
5805 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
5806
5807 rc = ieee80211_register_hw(hw);
5808 if (rc) {
5809 wiphy_err(hw->wiphy, "Cannot register device\n");
5810 goto err_unprobe_hw;
5811 }
5812
5813 return 0;
5814
5815err_unprobe_hw:
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005816 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005817 mwl8k_txq_deinit(hw, i);
5818 mwl8k_rxq_deinit(hw, 0);
5819
5820err_free_cookie:
5821 if (priv->cookie != NULL)
5822 pci_free_consistent(priv->pdev, 4,
5823 priv->cookie, priv->cookie_dma);
5824
5825 return rc;
5826}
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005827static int mwl8k_probe(struct pci_dev *pdev,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005828 const struct pci_device_id *id)
5829{
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005830 static int printed_version;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005831 struct ieee80211_hw *hw;
5832 struct mwl8k_priv *priv;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005833 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005834 int rc;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02005835
5836 if (!printed_version) {
5837 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
5838 printed_version = 1;
5839 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005840
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005841
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005842 rc = pci_enable_device(pdev);
5843 if (rc) {
5844 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
5845 MWL8K_NAME);
5846 return rc;
5847 }
5848
5849 rc = pci_request_regions(pdev, MWL8K_NAME);
5850 if (rc) {
5851 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
5852 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01005853 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005854 }
5855
5856 pci_set_master(pdev);
5857
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005858
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005859 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
5860 if (hw == NULL) {
5861 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
5862 rc = -ENOMEM;
5863 goto err_free_reg;
5864 }
5865
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005866 SET_IEEE80211_DEV(hw, &pdev->dev);
5867 pci_set_drvdata(pdev, hw);
5868
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005869 priv = hw->priv;
5870 priv->hw = hw;
5871 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05005872 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005873
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005874
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005875 priv->sram = pci_iomap(pdev, 0, 0x10000);
5876 if (priv->sram == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07005877 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005878 goto err_iounmap;
5879 }
5880
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005881 /*
5882 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
5883 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
5884 */
5885 priv->regs = pci_iomap(pdev, 1, 0x10000);
5886 if (priv->regs == NULL) {
5887 priv->regs = pci_iomap(pdev, 2, 0x10000);
5888 if (priv->regs == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07005889 wiphy_err(hw->wiphy, "Cannot map device registers\n");
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005890 goto err_iounmap;
5891 }
5892 }
5893
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005894 /*
Brian Cavagnolo99020472010-11-12 17:23:52 -08005895 * Choose the initial fw image depending on user input. If a second
5896 * image is available, make it the alternative image that will be
5897 * loaded if the first one fails.
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005898 */
Brian Cavagnolo99020472010-11-12 17:23:52 -08005899 init_completion(&priv->firmware_loading_complete);
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005900 di = priv->device_info;
Brian Cavagnolo99020472010-11-12 17:23:52 -08005901 if (ap_mode_default && di->fw_image_ap) {
5902 priv->fw_pref = di->fw_image_ap;
5903 priv->fw_alt = di->fw_image_sta;
5904 } else if (!ap_mode_default && di->fw_image_sta) {
5905 priv->fw_pref = di->fw_image_sta;
5906 priv->fw_alt = di->fw_image_ap;
5907 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005908 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08005909 priv->fw_pref = di->fw_image_sta;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08005910 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
5911 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08005912 priv->fw_pref = di->fw_image_ap;
5913 }
5914 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005915 if (rc)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08005916 goto err_stop_firmware;
Yogesh Ashok Powar6b6accc2011-12-30 16:35:27 +05305917
5918 priv->hw_restart_in_progress = false;
5919
Brian Cavagnolo99020472010-11-12 17:23:52 -08005920 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005921
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005922err_stop_firmware:
5923 mwl8k_hw_reset(priv);
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01005924
5925err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005926 if (priv->regs != NULL)
5927 pci_iounmap(pdev, priv->regs);
5928
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005929 if (priv->sram != NULL)
5930 pci_iounmap(pdev, priv->sram);
5931
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005932 pci_set_drvdata(pdev, NULL);
5933 ieee80211_free_hw(hw);
5934
5935err_free_reg:
5936 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01005937
5938err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005939 pci_disable_device(pdev);
5940
5941 return rc;
5942}
5943
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005944static void mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005945{
5946 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
5947 struct mwl8k_priv *priv;
5948 int i;
5949
5950 if (hw == NULL)
5951 return;
5952 priv = hw->priv;
5953
Brian Cavagnolo99020472010-11-12 17:23:52 -08005954 wait_for_completion(&priv->firmware_loading_complete);
5955
5956 if (priv->fw_state == FW_STATE_ERROR) {
5957 mwl8k_hw_reset(priv);
5958 goto unmap;
5959 }
5960
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005961 ieee80211_stop_queues(hw);
5962
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02005963 ieee80211_unregister_hw(hw);
5964
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01005965 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01005966 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01005967 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005968
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005969 /* Stop hardware */
5970 mwl8k_hw_reset(priv);
5971
5972 /* Return all skbs to mac80211 */
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005973 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01005974 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005975
Brian Cavagnoloe6007072011-03-17 11:58:44 -07005976 for (i = 0; i < mwl8k_tx_queues(priv); i++)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005977 mwl8k_txq_deinit(hw, i);
5978
5979 mwl8k_rxq_deinit(hw, 0);
5980
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02005981 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005982
Brian Cavagnolo99020472010-11-12 17:23:52 -08005983unmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005984 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02005985 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005986 pci_set_drvdata(pdev, NULL);
5987 ieee80211_free_hw(hw);
5988 pci_release_regions(pdev);
5989 pci_disable_device(pdev);
5990}
5991
5992static struct pci_driver mwl8k_driver = {
5993 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02005994 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005995 .probe = mwl8k_probe,
Bill Pemberton8dee5ee2012-12-03 09:56:36 -05005996 .remove = mwl8k_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01005997};
5998
Axel Lin5b0a3b72012-04-14 10:38:36 +08005999module_pci_driver(mwl8k_driver);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02006000
6001MODULE_DESCRIPTION(MWL8K_DESC);
6002MODULE_VERSION(MWL8K_VERSION);
6003MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
6004MODULE_LICENSE("GPL");