blob: 106b427d0064424b82f7771f035b9e6cc3ead2d6 [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>
13#include <linux/module.h>
14#include <linux/kernel.h>
Lennert Buytenhek3d76e822009-10-22 20:20:16 +020015#include <linux/sched.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010016#include <linux/spinlock.h>
17#include <linux/list.h>
18#include <linux/pci.h>
19#include <linux/delay.h>
20#include <linux/completion.h>
21#include <linux/etherdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010023#include <net/mac80211.h>
24#include <linux/moduleparam.h>
25#include <linux/firmware.h>
26#include <linux/workqueue.h>
27
28#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
29#define MWL8K_NAME KBUILD_MODNAME
Lennert Buytenheka5fb2972010-01-12 13:51:38 +010030#define MWL8K_VERSION "0.12"
Lennert Buytenheka66098d2009-03-10 10:13:33 +010031
Brian Cavagnolo0863ade2010-11-12 17:23:50 -080032/* Module parameters */
33static unsigned ap_mode_default;
34module_param(ap_mode_default, bool, 0);
35MODULE_PARM_DESC(ap_mode_default,
36 "Set to 1 to make ap mode the default instead of sta mode");
37
Lennert Buytenheka66098d2009-03-10 10:13:33 +010038/* Register definitions */
39#define MWL8K_HIU_GEN_PTR 0x00000c10
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020040#define MWL8K_MODE_STA 0x0000005a
41#define MWL8K_MODE_AP 0x000000a5
Lennert Buytenheka66098d2009-03-10 10:13:33 +010042#define MWL8K_HIU_INT_CODE 0x00000c14
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020043#define MWL8K_FWSTA_READY 0xf0f1f2f4
44#define MWL8K_FWAP_READY 0xf1f2f4a5
45#define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
Lennert Buytenheka66098d2009-03-10 10:13:33 +010046#define MWL8K_HIU_SCRATCH 0x00000c40
47
48/* Host->device communications */
49#define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
50#define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
51#define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
52#define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
53#define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020054#define MWL8K_H2A_INT_DUMMY (1 << 20)
55#define MWL8K_H2A_INT_RESET (1 << 15)
56#define MWL8K_H2A_INT_DOORBELL (1 << 1)
57#define MWL8K_H2A_INT_PPA_READY (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010058
59/* Device->host communications */
60#define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
61#define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
62#define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
63#define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
64#define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020065#define MWL8K_A2H_INT_DUMMY (1 << 20)
66#define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
67#define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
68#define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
69#define MWL8K_A2H_INT_RADIO_ON (1 << 6)
70#define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
71#define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
72#define MWL8K_A2H_INT_OPC_DONE (1 << 2)
73#define MWL8K_A2H_INT_RX_READY (1 << 1)
74#define MWL8K_A2H_INT_TX_DONE (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010075
76#define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
77 MWL8K_A2H_INT_CHNL_SWITCHED | \
78 MWL8K_A2H_INT_QUEUE_EMPTY | \
79 MWL8K_A2H_INT_RADAR_DETECT | \
80 MWL8K_A2H_INT_RADIO_ON | \
81 MWL8K_A2H_INT_RADIO_OFF | \
82 MWL8K_A2H_INT_MAC_EVENT | \
83 MWL8K_A2H_INT_OPC_DONE | \
84 MWL8K_A2H_INT_RX_READY | \
85 MWL8K_A2H_INT_TX_DONE)
86
Lennert Buytenheka66098d2009-03-10 10:13:33 +010087#define MWL8K_RX_QUEUES 1
88#define MWL8K_TX_QUEUES 4
89
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020090struct rxd_ops {
91 int rxd_size;
92 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
93 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +010094 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -040095 __le16 *qos, s8 *noise);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020096};
97
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020098struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +020099 char *part_name;
100 char *helper_image;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800101 char *fw_image_sta;
102 char *fw_image_ap;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100103 struct rxd_ops *ap_rxd_ops;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -0800104 u32 fw_api_ap;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200105};
106
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100107struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200108 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100109
110 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200111 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100112
113 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200114 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100115
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200116 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200117 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200118 struct {
119 struct sk_buff *skb;
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +0900120 DEFINE_DMA_UNMAP_ADDR(dma);
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200121 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100122};
123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100124struct mwl8k_tx_queue {
125 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200126 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100127
128 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200129 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100130
Kalle Valo8ccbc3b2010-02-07 10:20:52 +0200131 unsigned int len;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200132 struct mwl8k_tx_desc *txd;
133 dma_addr_t txd_dma;
134 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100135};
136
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100137struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100138 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100139 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100140
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200141 struct mwl8k_device_info *device_info;
142
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100143 void __iomem *sram;
144 void __iomem *regs;
145
146 /* firmware */
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800147 const struct firmware *fw_helper;
148 const struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100149
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100150 /* hardware/firmware parameters */
151 bool ap_fw;
152 struct rxd_ops *rxd_ops;
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100153 struct ieee80211_supported_band band_24;
154 struct ieee80211_channel channels_24[14];
155 struct ieee80211_rate rates_24[14];
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100156 struct ieee80211_supported_band band_50;
157 struct ieee80211_channel channels_50[4];
158 struct ieee80211_rate rates_50[9];
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100159 u32 ap_macids_supported;
160 u32 sta_macids_supported;
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100161
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200162 /* firmware access */
163 struct mutex fw_mutex;
164 struct task_struct *fw_mutex_owner;
165 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200166 struct completion *hostcmd_wait;
167
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100168 /* lock held over TX and TX reap */
169 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100170
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200171 /* TX quiesce completion, protected by fw_mutex and tx_lock */
172 struct completion *tx_wait;
173
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100174 /* List of interfaces. */
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100175 u32 macids_used;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100176 struct list_head vif_list;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100177
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100178 /* power management status cookie from firmware */
179 u32 *cookie;
180 dma_addr_t cookie_dma;
181
182 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100183 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200184 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100185
186 /*
187 * Running count of TX packets in flight, to avoid
188 * iterating over the transmit rings each time.
189 */
190 int pending_tx_pkts;
191
192 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
193 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
194
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200195 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200196 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200197 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200198 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100199
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100200 /* XXX need to convert this to handle multiple interfaces */
201 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200202 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100203 struct sk_buff *beacon_skb;
204
205 /*
206 * This FJ worker has to be global as it is scheduled from the
207 * RX handler. At this point we don't know which interface it
208 * belongs to until the list of bssids waiting to complete join
209 * is checked.
210 */
211 struct work_struct finalize_join_worker;
212
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100213 /* Tasklet to perform TX reclaim. */
214 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100215
216 /* Tasklet to perform RX. */
217 struct tasklet_struct poll_rx_task;
John W. Linville0d462bb2010-07-28 14:04:24 -0400218
219 /* Most recently reported noise in dBm */
220 s8 noise;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800221
222 /*
223 * preserve the queue configurations so they can be restored if/when
224 * the firmware image is swapped.
225 */
226 struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_QUEUES];
Brian Cavagnolo99020472010-11-12 17:23:52 -0800227
228 /* async firmware loading state */
229 unsigned fw_state;
230 char *fw_pref;
231 char *fw_alt;
232 struct completion firmware_loading_complete;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100233};
234
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800235#define MAX_WEP_KEY_LEN 13
236#define NUM_WEP_KEYS 4
237
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100238/* Per interface specific private data */
239struct mwl8k_vif {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100240 struct list_head list;
241 struct ieee80211_vif *vif;
242
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100243 /* Firmware macid for this vif. */
244 int macid;
245
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100246 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100247 u16 seqno;
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800248
249 /* Saved WEP keys */
250 struct {
251 u8 enabled;
252 u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
253 } wep_key_conf[NUM_WEP_KEYS];
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800254
255 /* BSSID */
256 u8 bssid[ETH_ALEN];
257
258 /* A flag to indicate is HW crypto is enabled for this bssid */
259 bool is_hw_crypto_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100260};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200261#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800262#define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100263
Lennert Buytenheka6804002010-01-04 21:55:42 +0100264struct mwl8k_sta {
265 /* Index into station database. Returned by UPDATE_STADB. */
266 u8 peer_id;
267};
268#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
269
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100270static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100271 { .center_freq = 2412, .hw_value = 1, },
272 { .center_freq = 2417, .hw_value = 2, },
273 { .center_freq = 2422, .hw_value = 3, },
274 { .center_freq = 2427, .hw_value = 4, },
275 { .center_freq = 2432, .hw_value = 5, },
276 { .center_freq = 2437, .hw_value = 6, },
277 { .center_freq = 2442, .hw_value = 7, },
278 { .center_freq = 2447, .hw_value = 8, },
279 { .center_freq = 2452, .hw_value = 9, },
280 { .center_freq = 2457, .hw_value = 10, },
281 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100282 { .center_freq = 2467, .hw_value = 12, },
283 { .center_freq = 2472, .hw_value = 13, },
284 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100285};
286
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100287static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100288 { .bitrate = 10, .hw_value = 2, },
289 { .bitrate = 20, .hw_value = 4, },
290 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200291 { .bitrate = 110, .hw_value = 22, },
292 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100293 { .bitrate = 60, .hw_value = 12, },
294 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100295 { .bitrate = 120, .hw_value = 24, },
296 { .bitrate = 180, .hw_value = 36, },
297 { .bitrate = 240, .hw_value = 48, },
298 { .bitrate = 360, .hw_value = 72, },
299 { .bitrate = 480, .hw_value = 96, },
300 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100301 { .bitrate = 720, .hw_value = 144, },
302};
303
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100304static const struct ieee80211_channel mwl8k_channels_50[] = {
305 { .center_freq = 5180, .hw_value = 36, },
306 { .center_freq = 5200, .hw_value = 40, },
307 { .center_freq = 5220, .hw_value = 44, },
308 { .center_freq = 5240, .hw_value = 48, },
309};
310
311static const struct ieee80211_rate mwl8k_rates_50[] = {
312 { .bitrate = 60, .hw_value = 12, },
313 { .bitrate = 90, .hw_value = 18, },
314 { .bitrate = 120, .hw_value = 24, },
315 { .bitrate = 180, .hw_value = 36, },
316 { .bitrate = 240, .hw_value = 48, },
317 { .bitrate = 360, .hw_value = 72, },
318 { .bitrate = 480, .hw_value = 96, },
319 { .bitrate = 540, .hw_value = 108, },
320 { .bitrate = 720, .hw_value = 144, },
321};
322
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100323/* Set or get info from Firmware */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100324#define MWL8K_CMD_GET 0x0000
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800325#define MWL8K_CMD_SET 0x0001
326#define MWL8K_CMD_SET_LIST 0x0002
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100327
328/* Firmware command codes */
329#define MWL8K_CMD_CODE_DNLD 0x0001
330#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200331#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100332#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
333#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200334#define MWL8K_CMD_RADIO_CONTROL 0x001c
335#define MWL8K_CMD_RF_TX_POWER 0x001e
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800336#define MWL8K_CMD_TX_POWER 0x001f
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200337#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100338#define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100339#define MWL8K_CMD_SET_PRE_SCAN 0x0107
340#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200341#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100342#define MWL8K_CMD_SET_AID 0x010d
343#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200344#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100345#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200346#define MWL8K_CMD_SET_SLOT 0x0114
347#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
348#define MWL8K_CMD_SET_WMM_MODE 0x0123
349#define MWL8K_CMD_MIMO_CONFIG 0x0125
350#define MWL8K_CMD_USE_FIXED_RATE 0x0126
351#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100352#define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200353#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100354#define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
355#define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800356#define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200357#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100358
John W. Linvilleb6037422010-07-20 13:55:00 -0400359static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100360{
John W. Linvilleb6037422010-07-20 13:55:00 -0400361 u16 command = le16_to_cpu(cmd);
362
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100363#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
364 snprintf(buf, bufsize, "%s", #x);\
365 return buf;\
366 } while (0)
John W. Linvilleb6037422010-07-20 13:55:00 -0400367 switch (command & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100368 MWL8K_CMDNAME(CODE_DNLD);
369 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200370 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100371 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
372 MWL8K_CMDNAME(GET_STAT);
373 MWL8K_CMDNAME(RADIO_CONTROL);
374 MWL8K_CMDNAME(RF_TX_POWER);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800375 MWL8K_CMDNAME(TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200376 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100377 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100378 MWL8K_CMDNAME(SET_PRE_SCAN);
379 MWL8K_CMDNAME(SET_POST_SCAN);
380 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100381 MWL8K_CMDNAME(SET_AID);
382 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200383 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100384 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200385 MWL8K_CMDNAME(SET_SLOT);
386 MWL8K_CMDNAME(SET_EDCA_PARAMS);
387 MWL8K_CMDNAME(SET_WMM_MODE);
388 MWL8K_CMDNAME(MIMO_CONFIG);
389 MWL8K_CMDNAME(USE_FIXED_RATE);
390 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200391 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200392 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100393 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100394 MWL8K_CMDNAME(SET_NEW_STN);
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -0800395 MWL8K_CMDNAME(UPDATE_ENCRYPTION);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200396 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100397 default:
398 snprintf(buf, bufsize, "0x%x", cmd);
399 }
400#undef MWL8K_CMDNAME
401
402 return buf;
403}
404
405/* Hardware and firmware reset */
406static void mwl8k_hw_reset(struct mwl8k_priv *priv)
407{
408 iowrite32(MWL8K_H2A_INT_RESET,
409 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
410 iowrite32(MWL8K_H2A_INT_RESET,
411 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
412 msleep(20);
413}
414
415/* Release fw image */
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800416static void mwl8k_release_fw(const struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100417{
418 if (*fw == NULL)
419 return;
420 release_firmware(*fw);
421 *fw = NULL;
422}
423
424static void mwl8k_release_firmware(struct mwl8k_priv *priv)
425{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100426 mwl8k_release_fw(&priv->fw_ucode);
427 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100428}
429
Brian Cavagnolo99020472010-11-12 17:23:52 -0800430/* states for asynchronous f/w loading */
431static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
432enum {
433 FW_STATE_INIT = 0,
434 FW_STATE_LOADING_PREF,
435 FW_STATE_LOADING_ALT,
436 FW_STATE_ERROR,
437};
438
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100439/* Request fw image */
440static int mwl8k_request_fw(struct mwl8k_priv *priv,
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800441 const char *fname, const struct firmware **fw,
Brian Cavagnolo99020472010-11-12 17:23:52 -0800442 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100443{
444 /* release current image */
445 if (*fw != NULL)
446 mwl8k_release_fw(fw);
447
Brian Cavagnolo99020472010-11-12 17:23:52 -0800448 if (nowait)
449 return request_firmware_nowait(THIS_MODULE, 1, fname,
450 &priv->pdev->dev, GFP_KERNEL,
451 priv, mwl8k_fw_state_machine);
452 else
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800453 return request_firmware(fw, fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100454}
455
Brian Cavagnolo99020472010-11-12 17:23:52 -0800456static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
457 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100458{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200459 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100460 int rc;
461
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200462 if (di->helper_image != NULL) {
Brian Cavagnolo99020472010-11-12 17:23:52 -0800463 if (nowait)
464 rc = mwl8k_request_fw(priv, di->helper_image,
465 &priv->fw_helper, true);
466 else
467 rc = mwl8k_request_fw(priv, di->helper_image,
468 &priv->fw_helper, false);
469 if (rc)
470 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
471 pci_name(priv->pdev), di->helper_image);
472
473 if (rc || nowait)
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200474 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100475 }
476
Brian Cavagnolo99020472010-11-12 17:23:52 -0800477 if (nowait) {
478 /*
479 * if we get here, no helper image is needed. Skip the
480 * FW_STATE_INIT state.
481 */
482 priv->fw_state = FW_STATE_LOADING_PREF;
483 rc = mwl8k_request_fw(priv, fw_image,
484 &priv->fw_ucode,
485 true);
486 } else
487 rc = mwl8k_request_fw(priv, fw_image,
488 &priv->fw_ucode, false);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100489 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200490 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800491 pci_name(priv->pdev), fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100492 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100493 return rc;
494 }
495
496 return 0;
497}
498
499struct mwl8k_cmd_pkt {
500 __le16 code;
501 __le16 length;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100502 __u8 seq_num;
503 __u8 macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100504 __le16 result;
505 char payload[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000506} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100507
508/*
509 * Firmware loading.
510 */
511static int
512mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
513{
514 void __iomem *regs = priv->regs;
515 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100516 int loops;
517
518 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
519 if (pci_dma_mapping_error(priv->pdev, dma_addr))
520 return -ENOMEM;
521
522 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
523 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
524 iowrite32(MWL8K_H2A_INT_DOORBELL,
525 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
526 iowrite32(MWL8K_H2A_INT_DUMMY,
527 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
528
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100529 loops = 1000;
530 do {
531 u32 int_code;
532
533 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
534 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
535 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100536 break;
537 }
538
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200539 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100540 udelay(1);
541 } while (--loops);
542
543 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
544
Lennert Buytenhekd4b705702009-07-16 12:44:45 +0200545 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100546}
547
548static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
549 const u8 *data, size_t length)
550{
551 struct mwl8k_cmd_pkt *cmd;
552 int done;
553 int rc = 0;
554
555 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
556 if (cmd == NULL)
557 return -ENOMEM;
558
559 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
560 cmd->seq_num = 0;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100561 cmd->macid = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100562 cmd->result = 0;
563
564 done = 0;
565 while (length) {
566 int block_size = length > 256 ? 256 : length;
567
568 memcpy(cmd->payload, data + done, block_size);
569 cmd->length = cpu_to_le16(block_size);
570
571 rc = mwl8k_send_fw_load_cmd(priv, cmd,
572 sizeof(*cmd) + block_size);
573 if (rc)
574 break;
575
576 done += block_size;
577 length -= block_size;
578 }
579
580 if (!rc) {
581 cmd->length = 0;
582 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
583 }
584
585 kfree(cmd);
586
587 return rc;
588}
589
590static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
591 const u8 *data, size_t length)
592{
593 unsigned char *buffer;
594 int may_continue, rc = 0;
595 u32 done, prev_block_size;
596
597 buffer = kmalloc(1024, GFP_KERNEL);
598 if (buffer == NULL)
599 return -ENOMEM;
600
601 done = 0;
602 prev_block_size = 0;
603 may_continue = 1000;
604 while (may_continue > 0) {
605 u32 block_size;
606
607 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
608 if (block_size & 1) {
609 block_size &= ~1;
610 may_continue--;
611 } else {
612 done += prev_block_size;
613 length -= prev_block_size;
614 }
615
616 if (block_size > 1024 || block_size > length) {
617 rc = -EOVERFLOW;
618 break;
619 }
620
621 if (length == 0) {
622 rc = 0;
623 break;
624 }
625
626 if (block_size == 0) {
627 rc = -EPROTO;
628 may_continue--;
629 udelay(1);
630 continue;
631 }
632
633 prev_block_size = block_size;
634 memcpy(buffer, data + done, block_size);
635
636 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
637 if (rc)
638 break;
639 }
640
641 if (!rc && length != 0)
642 rc = -EREMOTEIO;
643
644 kfree(buffer);
645
646 return rc;
647}
648
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200649static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100650{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200651 struct mwl8k_priv *priv = hw->priv;
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800652 const struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200653 int rc;
654 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100655
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200656 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800657 const struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100658
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200659 if (helper == NULL) {
660 printk(KERN_ERR "%s: helper image needed but none "
661 "given\n", pci_name(priv->pdev));
662 return -EINVAL;
663 }
664
665 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100666 if (rc) {
667 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200668 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100669 return rc;
670 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100671 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100672
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200673 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100674 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200675 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100676 }
677
678 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200679 printk(KERN_ERR "%s: unable to load firmware image\n",
680 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100681 return rc;
682 }
683
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100684 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100685
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100686 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100687 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200688 u32 ready_code;
689
690 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
691 if (ready_code == MWL8K_FWAP_READY) {
692 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100693 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200694 } else if (ready_code == MWL8K_FWSTA_READY) {
695 priv->ap_fw = 0;
696 break;
697 }
698
699 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100700 udelay(1);
701 } while (--loops);
702
703 return loops ? 0 : -ETIMEDOUT;
704}
705
706
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100707/* DMA header used by firmware and hardware. */
708struct mwl8k_dma_data {
709 __le16 fwlen;
710 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100711 char data[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000712} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100713
714/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100715static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100716{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100717 struct mwl8k_dma_data *tr;
718 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100719
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100720 tr = (struct mwl8k_dma_data *)skb->data;
721 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
722
723 if (hdrlen != sizeof(tr->wh)) {
724 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
725 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
726 *((__le16 *)(tr->data - 2)) = qos;
727 } else {
728 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
729 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100730 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100731
732 if (hdrlen != sizeof(*tr))
733 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100734}
735
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800736static void
737mwl8k_add_dma_header(struct sk_buff *skb, int tail_pad)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100738{
739 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100740 int hdrlen;
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800741 int reqd_hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100742 struct mwl8k_dma_data *tr;
743
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100744 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100745 * Add a firmware DMA header; the firmware requires that we
746 * present a 2-byte payload length followed by a 4-address
747 * header (without QoS field), followed (optionally) by any
748 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100749 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100750 wh = (struct ieee80211_hdr *)skb->data;
751
752 hdrlen = ieee80211_hdrlen(wh->frame_control);
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800753 reqd_hdrlen = sizeof(*tr);
754
755 if (hdrlen != reqd_hdrlen)
756 skb_push(skb, reqd_hdrlen - hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100757
758 if (ieee80211_is_data_qos(wh->frame_control))
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800759 hdrlen -= IEEE80211_QOS_CTL_LEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100760
761 tr = (struct mwl8k_dma_data *)skb->data;
762 if (wh != &tr->wh)
763 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100764 if (hdrlen != sizeof(tr->wh))
765 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100766
767 /*
768 * Firmware length is the length of the fully formed "802.11
769 * payload". That is, everything except for the 802.11 header.
770 * This includes all crypto material including the MIC.
771 */
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800772 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100773}
774
Nishant Sarmukadame53d9b92010-12-30 11:23:32 -0800775static void mwl8k_encapsulate_tx_frame(struct sk_buff *skb)
776{
777 struct ieee80211_hdr *wh;
778 struct ieee80211_tx_info *tx_info;
779 struct ieee80211_key_conf *key_conf;
780 int data_pad;
781
782 wh = (struct ieee80211_hdr *)skb->data;
783
784 tx_info = IEEE80211_SKB_CB(skb);
785
786 key_conf = NULL;
787 if (ieee80211_is_data(wh->frame_control))
788 key_conf = tx_info->control.hw_key;
789
790 /*
791 * Make sure the packet header is in the DMA header format (4-address
792 * without QoS), the necessary crypto padding between the header and the
793 * payload has already been provided by mac80211, but it doesn't add tail
794 * padding when HW crypto is enabled.
795 *
796 * We have the following trailer padding requirements:
797 * - WEP: 4 trailer bytes (ICV)
798 * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
799 * - CCMP: 8 trailer bytes (MIC)
800 */
801 data_pad = 0;
802 if (key_conf != NULL) {
803 switch (key_conf->cipher) {
804 case WLAN_CIPHER_SUITE_WEP40:
805 case WLAN_CIPHER_SUITE_WEP104:
806 data_pad = 4;
807 break;
808 case WLAN_CIPHER_SUITE_TKIP:
809 data_pad = 12;
810 break;
811 case WLAN_CIPHER_SUITE_CCMP:
812 data_pad = 8;
813 break;
814 }
815 }
816 mwl8k_add_dma_header(skb, data_pad);
817}
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100818
819/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100820 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200821 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100822struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200823 __le16 pkt_len;
824 __u8 sq2;
825 __u8 rate;
826 __le32 pkt_phys_addr;
827 __le32 next_rxd_phys_addr;
828 __le16 qos_control;
829 __le16 htsig2;
830 __le32 hw_rssi_info;
831 __le32 hw_noise_floor_info;
832 __u8 noise_floor;
833 __u8 pad0[3];
834 __u8 rssi;
835 __u8 rx_status;
836 __u8 channel;
837 __u8 rx_ctrl;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000838} __packed;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200839
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100840#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
841#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
842#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100843
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100844#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200845
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800846/* 8366 AP rx_status bits */
847#define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
848#define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
849#define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
850#define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
851#define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
852
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100853static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200854{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100855 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200856
857 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100858 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200859}
860
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100861static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200862{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100863 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200864
865 rxd->pkt_len = cpu_to_le16(len);
866 rxd->pkt_phys_addr = cpu_to_le32(addr);
867 wmb();
868 rxd->rx_ctrl = 0;
869}
870
871static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100872mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -0400873 __le16 *qos, s8 *noise)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200874{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100875 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200876
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100877 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200878 return -1;
879 rmb();
880
881 memset(status, 0, sizeof(*status));
882
883 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -0400884 *noise = -rxd->noise_floor;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200885
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100886 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200887 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100888 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100889 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100890 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200891 } else {
892 int i;
893
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100894 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
895 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200896 status->rate_idx = i;
897 break;
898 }
899 }
900 }
901
Lennert Buytenhek85478342010-01-12 13:48:56 +0100902 if (rxd->channel > 14) {
903 status->band = IEEE80211_BAND_5GHZ;
904 if (!(status->flag & RX_FLAG_HT))
905 status->rate_idx -= 5;
906 } else {
907 status->band = IEEE80211_BAND_2GHZ;
908 }
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200909 status->freq = ieee80211_channel_to_frequency(rxd->channel);
910
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100911 *qos = rxd->qos_control;
912
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800913 if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
914 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) &&
915 (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
916 status->flag |= RX_FLAG_MMIC_ERROR;
917
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200918 return le16_to_cpu(rxd->pkt_len);
919}
920
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100921static struct rxd_ops rxd_8366_ap_ops = {
922 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
923 .rxd_init = mwl8k_rxd_8366_ap_init,
924 .rxd_refill = mwl8k_rxd_8366_ap_refill,
925 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200926};
927
928/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100929 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100930 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100931struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100932 __le16 pkt_len;
933 __u8 link_quality;
934 __u8 noise_level;
935 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200936 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100937 __le16 qos_control;
938 __le16 rate_info;
939 __le32 pad0[4];
940 __u8 rssi;
941 __u8 channel;
942 __le16 pad1;
943 __u8 rx_ctrl;
944 __u8 rx_status;
945 __u8 pad2[2];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000946} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100947
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100948#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
949#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
950#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
951#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
952#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
953#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200954
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100955#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -0800956#define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
957/* ICV=0 or MIC=1 */
958#define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
959/* Key is uploaded only in failure case */
960#define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200961
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100962static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200963{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100964 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200965
966 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100967 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200968}
969
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100970static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200971{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100972 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200973
974 rxd->pkt_len = cpu_to_le16(len);
975 rxd->pkt_phys_addr = cpu_to_le32(addr);
976 wmb();
977 rxd->rx_ctrl = 0;
978}
979
980static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100981mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -0400982 __le16 *qos, s8 *noise)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200983{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100984 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200985 u16 rate_info;
986
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100987 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200988 return -1;
989 rmb();
990
991 rate_info = le16_to_cpu(rxd->rate_info);
992
993 memset(status, 0, sizeof(*status));
994
995 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -0400996 *noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100997 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
998 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200999
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001000 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001001 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001002 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001003 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001004 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001005 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001006 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001007 status->flag |= RX_FLAG_HT;
1008
Lennert Buytenhek85478342010-01-12 13:48:56 +01001009 if (rxd->channel > 14) {
1010 status->band = IEEE80211_BAND_5GHZ;
1011 if (!(status->flag & RX_FLAG_HT))
1012 status->rate_idx -= 5;
1013 } else {
1014 status->band = IEEE80211_BAND_2GHZ;
1015 }
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001016 status->freq = ieee80211_channel_to_frequency(rxd->channel);
1017
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001018 *qos = rxd->qos_control;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001019 if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
1020 (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
1021 status->flag |= RX_FLAG_MMIC_ERROR;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001022
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001023 return le16_to_cpu(rxd->pkt_len);
1024}
1025
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01001026static struct rxd_ops rxd_sta_ops = {
1027 .rxd_size = sizeof(struct mwl8k_rxd_sta),
1028 .rxd_init = mwl8k_rxd_sta_init,
1029 .rxd_refill = mwl8k_rxd_sta_refill,
1030 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001031};
1032
1033
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001034#define MWL8K_RX_DESCS 256
1035#define MWL8K_RX_MAXSZ 3800
1036
1037static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
1038{
1039 struct mwl8k_priv *priv = hw->priv;
1040 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1041 int size;
1042 int i;
1043
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001044 rxq->rxd_count = 0;
1045 rxq->head = 0;
1046 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001047
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001048 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001049
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001050 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
1051 if (rxq->rxd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001052 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001053 return -ENOMEM;
1054 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001055 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001056
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001057 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
1058 if (rxq->buf == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001059 wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001060 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001061 return -ENOMEM;
1062 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001063 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001064
1065 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001066 int desc_size;
1067 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001068 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001069 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001070
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001071 desc_size = priv->rxd_ops->rxd_size;
1072 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001073
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001074 nexti = i + 1;
1075 if (nexti == MWL8K_RX_DESCS)
1076 nexti = 0;
1077 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
1078
1079 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001080 }
1081
1082 return 0;
1083}
1084
1085static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1086{
1087 struct mwl8k_priv *priv = hw->priv;
1088 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1089 int refilled;
1090
1091 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001092 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001093 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001094 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001095 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001096 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001097
1098 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1099 if (skb == NULL)
1100 break;
1101
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001102 addr = pci_map_single(priv->pdev, skb->data,
1103 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001104
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001105 rxq->rxd_count++;
1106 rx = rxq->tail++;
1107 if (rxq->tail == MWL8K_RX_DESCS)
1108 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001109 rxq->buf[rx].skb = skb;
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001110 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001111
1112 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1113 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001114
1115 refilled++;
1116 }
1117
1118 return refilled;
1119}
1120
1121/* Must be called only when the card's reception is completely halted */
1122static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1123{
1124 struct mwl8k_priv *priv = hw->priv;
1125 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1126 int i;
1127
1128 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001129 if (rxq->buf[i].skb != NULL) {
1130 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001131 dma_unmap_addr(&rxq->buf[i], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001132 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001133 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001134
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001135 kfree_skb(rxq->buf[i].skb);
1136 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001137 }
1138 }
1139
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001140 kfree(rxq->buf);
1141 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001142
1143 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001144 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001145 rxq->rxd, rxq->rxd_dma);
1146 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001147}
1148
1149
1150/*
1151 * Scan a list of BSSIDs to process for finalize join.
1152 * Allows for extension to process multiple BSSIDs.
1153 */
1154static inline int
1155mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1156{
1157 return priv->capture_beacon &&
1158 ieee80211_is_beacon(wh->frame_control) &&
1159 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1160}
1161
Lennert Buytenhek37797522009-10-22 20:19:45 +02001162static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1163 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001164{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001165 struct mwl8k_priv *priv = hw->priv;
1166
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001167 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001168 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001169
1170 /*
1171 * Use GFP_ATOMIC as rxq_process is called from
1172 * the primary interrupt handler, memory allocation call
1173 * must not sleep.
1174 */
1175 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1176 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001177 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001178}
1179
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001180static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
1181 u8 *bssid)
1182{
1183 struct mwl8k_vif *mwl8k_vif;
1184
1185 list_for_each_entry(mwl8k_vif,
1186 vif_list, list) {
1187 if (memcmp(bssid, mwl8k_vif->bssid,
1188 ETH_ALEN) == 0)
1189 return mwl8k_vif;
1190 }
1191
1192 return NULL;
1193}
1194
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001195static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1196{
1197 struct mwl8k_priv *priv = hw->priv;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001198 struct mwl8k_vif *mwl8k_vif = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001199 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1200 int processed;
1201
1202 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001203 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001204 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001205 void *rxd;
1206 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001207 struct ieee80211_rx_status status;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001208 struct ieee80211_hdr *wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001209 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001210
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001211 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001212 if (skb == NULL)
1213 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001214
1215 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1216
John W. Linville0d462bb2010-07-28 14:04:24 -04001217 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1218 &priv->noise);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001219 if (pkt_len < 0)
1220 break;
1221
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001222 rxq->buf[rxq->head].skb = NULL;
1223
1224 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001225 dma_unmap_addr(&rxq->buf[rxq->head], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001226 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001227 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001228
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001229 rxq->head++;
1230 if (rxq->head == MWL8K_RX_DESCS)
1231 rxq->head = 0;
1232
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001233 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001234
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001235 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001236
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001237 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001238 * Check for a pending join operation. Save a
1239 * copy of the beacon and schedule a tasklet to
1240 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001241 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001242 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001243 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001244
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001245 if (ieee80211_has_protected(wh->frame_control)) {
1246
1247 /* Check if hw crypto has been enabled for
1248 * this bss. If yes, set the status flags
1249 * accordingly
1250 */
1251 mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
1252 wh->addr1);
1253
1254 if (mwl8k_vif != NULL &&
1255 mwl8k_vif->is_hw_crypto_enabled == true) {
1256 /*
1257 * When MMIC ERROR is encountered
1258 * by the firmware, payload is
1259 * dropped and only 32 bytes of
1260 * mwl8k Firmware header is sent
1261 * to the host.
1262 *
1263 * We need to add four bytes of
1264 * key information. In it
1265 * MAC80211 expects keyidx set to
1266 * 0 for triggering Counter
1267 * Measure of MMIC failure.
1268 */
1269 if (status.flag & RX_FLAG_MMIC_ERROR) {
1270 struct mwl8k_dma_data *tr;
1271 tr = (struct mwl8k_dma_data *)skb->data;
1272 memset((void *)&(tr->data), 0, 4);
1273 pkt_len += 4;
1274 }
1275
1276 if (!ieee80211_is_auth(wh->frame_control))
1277 status.flag |= RX_FLAG_IV_STRIPPED |
1278 RX_FLAG_DECRYPTED |
1279 RX_FLAG_MMIC_STRIPPED;
1280 }
1281 }
1282
1283 skb_put(skb, pkt_len);
1284 mwl8k_remove_dma_header(skb, qos);
Johannes Bergf1d58c22009-06-17 13:13:00 +02001285 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1286 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001287
1288 processed++;
1289 }
1290
1291 return processed;
1292}
1293
1294
1295/*
1296 * Packet transmission.
1297 */
1298
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001299#define MWL8K_TXD_STATUS_OK 0x00000001
1300#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1301#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1302#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001303#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001304
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001305#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1306#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1307#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1308#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1309#define MWL8K_QOS_EOSP 0x0010
1310
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001311struct mwl8k_tx_desc {
1312 __le32 status;
1313 __u8 data_rate;
1314 __u8 tx_priority;
1315 __le16 qos_control;
1316 __le32 pkt_phys_addr;
1317 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001318 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001319 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001320 __le32 reserved;
1321 __le16 rate_info;
1322 __u8 peer_id;
Brian Cavagnoloa1fe24b2010-11-12 17:23:47 -08001323 __u8 tx_frag_cnt;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001324} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001325
1326#define MWL8K_TX_DESCS 128
1327
1328static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1329{
1330 struct mwl8k_priv *priv = hw->priv;
1331 struct mwl8k_tx_queue *txq = priv->txq + index;
1332 int size;
1333 int i;
1334
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001335 txq->len = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001336 txq->head = 0;
1337 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001338
1339 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1340
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001341 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1342 if (txq->txd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001343 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001344 return -ENOMEM;
1345 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001346 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001347
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001348 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1349 if (txq->skb == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001350 wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001351 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001352 return -ENOMEM;
1353 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001354 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001355
1356 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1357 struct mwl8k_tx_desc *tx_desc;
1358 int nexti;
1359
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001360 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001361 nexti = (i + 1) % MWL8K_TX_DESCS;
1362
1363 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001364 tx_desc->next_txd_phys_addr =
1365 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001366 }
1367
1368 return 0;
1369}
1370
1371static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1372{
1373 iowrite32(MWL8K_H2A_INT_PPA_READY,
1374 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1375 iowrite32(MWL8K_H2A_INT_DUMMY,
1376 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1377 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1378}
1379
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001380static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001381{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001382 struct mwl8k_priv *priv = hw->priv;
1383 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001384
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001385 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1386 struct mwl8k_tx_queue *txq = priv->txq + i;
1387 int fw_owned = 0;
1388 int drv_owned = 0;
1389 int unused = 0;
1390 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001391
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001392 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001393 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1394 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001395
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001396 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001397 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001398 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001399 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001400 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001401
1402 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001403 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001404 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001405
Joe Perchesc96c31e2010-07-26 14:39:58 -07001406 wiphy_err(hw->wiphy,
1407 "txq[%d] len=%d head=%d tail=%d "
1408 "fw_owned=%d drv_owned=%d unused=%d\n",
1409 i,
1410 txq->len, txq->head, txq->tail,
1411 fw_owned, drv_owned, unused);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001412 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001413}
1414
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001415/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001416 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001417 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001418#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001419
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001420static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001421{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001422 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001423 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001424 int retry;
1425 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001426
1427 might_sleep();
1428
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001429 /*
1430 * The TX queues are stopped at this point, so this test
1431 * doesn't need to take ->tx_lock.
1432 */
1433 if (!priv->pending_tx_pkts)
1434 return 0;
1435
1436 retry = 0;
1437 rc = 0;
1438
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001439 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001440 priv->tx_wait = &tx_wait;
1441 while (!rc) {
1442 int oldcount;
1443 unsigned long timeout;
1444
1445 oldcount = priv->pending_tx_pkts;
1446
1447 spin_unlock_bh(&priv->tx_lock);
1448 timeout = wait_for_completion_timeout(&tx_wait,
1449 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1450 spin_lock_bh(&priv->tx_lock);
1451
1452 if (timeout) {
1453 WARN_ON(priv->pending_tx_pkts);
1454 if (retry) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001455 wiphy_notice(hw->wiphy, "tx rings drained\n");
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001456 }
1457 break;
1458 }
1459
1460 if (priv->pending_tx_pkts < oldcount) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001461 wiphy_notice(hw->wiphy,
1462 "waiting for tx rings to drain (%d -> %d pkts)\n",
1463 oldcount, priv->pending_tx_pkts);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001464 retry = 1;
1465 continue;
1466 }
1467
1468 priv->tx_wait = NULL;
1469
Joe Perchesc96c31e2010-07-26 14:39:58 -07001470 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1471 MWL8K_TX_WAIT_TIMEOUT_MS);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001472 mwl8k_dump_tx_rings(hw);
1473
1474 rc = -ETIMEDOUT;
1475 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001476 spin_unlock_bh(&priv->tx_lock);
1477
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001478 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001479}
1480
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001481#define MWL8K_TXD_SUCCESS(status) \
1482 ((status) & (MWL8K_TXD_STATUS_OK | \
1483 MWL8K_TXD_STATUS_OK_RETRY | \
1484 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001485
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001486static int
1487mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001488{
1489 struct mwl8k_priv *priv = hw->priv;
1490 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001491 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001492
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001493 processed = 0;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001494 while (txq->len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001495 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001496 struct mwl8k_tx_desc *tx_desc;
1497 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001498 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001499 struct sk_buff *skb;
1500 struct ieee80211_tx_info *info;
1501 u32 status;
1502
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001503 tx = txq->head;
1504 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001505
1506 status = le32_to_cpu(tx_desc->status);
1507
1508 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1509 if (!force)
1510 break;
1511 tx_desc->status &=
1512 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1513 }
1514
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001515 txq->head = (tx + 1) % MWL8K_TX_DESCS;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001516 BUG_ON(txq->len == 0);
1517 txq->len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001518 priv->pending_tx_pkts--;
1519
1520 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001521 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001522 skb = txq->skb[tx];
1523 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001524
1525 BUG_ON(skb == NULL);
1526 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1527
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001528 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001529
1530 /* Mark descriptor as unused */
1531 tx_desc->pkt_phys_addr = 0;
1532 tx_desc->pkt_len = 0;
1533
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001534 info = IEEE80211_SKB_CB(skb);
1535 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001536 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001537 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001538
1539 ieee80211_tx_status_irqsafe(hw, skb);
1540
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001541 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001542 }
1543
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001544 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001545 ieee80211_wake_queue(hw, index);
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001546
1547 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001548}
1549
1550/* must be called only when the card's transmit is completely halted */
1551static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1552{
1553 struct mwl8k_priv *priv = hw->priv;
1554 struct mwl8k_tx_queue *txq = priv->txq + index;
1555
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001556 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001557
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001558 kfree(txq->skb);
1559 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001560
1561 pci_free_consistent(priv->pdev,
1562 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001563 txq->txd, txq->txd_dma);
1564 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001565}
1566
1567static int
1568mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1569{
1570 struct mwl8k_priv *priv = hw->priv;
1571 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001572 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001573 struct ieee80211_hdr *wh;
1574 struct mwl8k_tx_queue *txq;
1575 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001576 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001577 u32 txstatus;
1578 u8 txdatarate;
1579 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001580
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001581 wh = (struct ieee80211_hdr *)skb->data;
1582 if (ieee80211_is_data_qos(wh->frame_control))
1583 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1584 else
1585 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001586
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08001587 if (priv->ap_fw)
1588 mwl8k_encapsulate_tx_frame(skb);
1589 else
1590 mwl8k_add_dma_header(skb, 0);
1591
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001592 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001593
1594 tx_info = IEEE80211_SKB_CB(skb);
1595 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001596
1597 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001598 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001599 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1600 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001601 }
1602
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001603 /* Setup firmware control bit fields for each frame type. */
1604 txstatus = 0;
1605 txdatarate = 0;
1606 if (ieee80211_is_mgmt(wh->frame_control) ||
1607 ieee80211_is_ctl(wh->frame_control)) {
1608 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001609 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001610 } else if (ieee80211_is_data(wh->frame_control)) {
1611 txdatarate = 1;
1612 if (is_multicast_ether_addr(wh->addr1))
1613 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1614
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001615 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001616 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001617 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001618 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001619 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001620 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001621
1622 dma = pci_map_single(priv->pdev, skb->data,
1623 skb->len, PCI_DMA_TODEVICE);
1624
1625 if (pci_dma_mapping_error(priv->pdev, dma)) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001626 wiphy_debug(hw->wiphy,
1627 "failed to dma map skb, dropping TX frame.\n");
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001628 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001629 return NETDEV_TX_OK;
1630 }
1631
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001632 spin_lock_bh(&priv->tx_lock);
1633
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001634 txq = priv->txq + index;
1635
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001636 BUG_ON(txq->skb[txq->tail] != NULL);
1637 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001638
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001639 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001640 tx->data_rate = txdatarate;
1641 tx->tx_priority = index;
1642 tx->qos_control = cpu_to_le16(qos);
1643 tx->pkt_phys_addr = cpu_to_le32(dma);
1644 tx->pkt_len = cpu_to_le16(skb->len);
1645 tx->rate_info = 0;
Lennert Buytenheka6804002010-01-04 21:55:42 +01001646 if (!priv->ap_fw && tx_info->control.sta != NULL)
1647 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1648 else
1649 tx->peer_id = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001650 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001651 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1652
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001653 txq->len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001654 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001655
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001656 txq->tail++;
1657 if (txq->tail == MWL8K_TX_DESCS)
1658 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001659
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001660 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001661 ieee80211_stop_queue(hw, index);
1662
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001663 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001664
1665 spin_unlock_bh(&priv->tx_lock);
1666
1667 return NETDEV_TX_OK;
1668}
1669
1670
1671/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001672 * Firmware access.
1673 *
1674 * We have the following requirements for issuing firmware commands:
1675 * - Some commands require that the packet transmit path is idle when
1676 * the command is issued. (For simplicity, we'll just quiesce the
1677 * transmit path for every command.)
1678 * - There are certain sequences of commands that need to be issued to
1679 * the hardware sequentially, with no other intervening commands.
1680 *
1681 * This leads to an implementation of a "firmware lock" as a mutex that
1682 * can be taken recursively, and which is taken by both the low-level
1683 * command submission function (mwl8k_post_cmd) as well as any users of
1684 * that function that require issuing of an atomic sequence of commands,
1685 * and quiesces the transmit path whenever it's taken.
1686 */
1687static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1688{
1689 struct mwl8k_priv *priv = hw->priv;
1690
1691 if (priv->fw_mutex_owner != current) {
1692 int rc;
1693
1694 mutex_lock(&priv->fw_mutex);
1695 ieee80211_stop_queues(hw);
1696
1697 rc = mwl8k_tx_wait_empty(hw);
1698 if (rc) {
1699 ieee80211_wake_queues(hw);
1700 mutex_unlock(&priv->fw_mutex);
1701
1702 return rc;
1703 }
1704
1705 priv->fw_mutex_owner = current;
1706 }
1707
1708 priv->fw_mutex_depth++;
1709
1710 return 0;
1711}
1712
1713static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1714{
1715 struct mwl8k_priv *priv = hw->priv;
1716
1717 if (!--priv->fw_mutex_depth) {
1718 ieee80211_wake_queues(hw);
1719 priv->fw_mutex_owner = NULL;
1720 mutex_unlock(&priv->fw_mutex);
1721 }
1722}
1723
1724
1725/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001726 * Command processing.
1727 */
1728
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001729/* Timeout firmware commands after 10s */
1730#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001731
1732static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1733{
1734 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1735 struct mwl8k_priv *priv = hw->priv;
1736 void __iomem *regs = priv->regs;
1737 dma_addr_t dma_addr;
1738 unsigned int dma_size;
1739 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001740 unsigned long timeout = 0;
1741 u8 buf[32];
1742
John W. Linvilleb6037422010-07-20 13:55:00 -04001743 cmd->result = (__force __le16) 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001744 dma_size = le16_to_cpu(cmd->length);
1745 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1746 PCI_DMA_BIDIRECTIONAL);
1747 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1748 return -ENOMEM;
1749
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001750 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001751 if (rc) {
1752 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1753 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001754 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001755 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001756
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001757 priv->hostcmd_wait = &cmd_wait;
1758 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1759 iowrite32(MWL8K_H2A_INT_DOORBELL,
1760 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1761 iowrite32(MWL8K_H2A_INT_DUMMY,
1762 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001763
1764 timeout = wait_for_completion_timeout(&cmd_wait,
1765 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1766
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001767 priv->hostcmd_wait = NULL;
1768
1769 mwl8k_fw_unlock(hw);
1770
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001771 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1772 PCI_DMA_BIDIRECTIONAL);
1773
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001774 if (!timeout) {
Joe Perches5db55842010-08-11 19:11:19 -07001775 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07001776 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1777 MWL8K_CMD_TIMEOUT_MS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001778 rc = -ETIMEDOUT;
1779 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001780 int ms;
1781
1782 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1783
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001784 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001785 if (rc)
Joe Perches5db55842010-08-11 19:11:19 -07001786 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07001787 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1788 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001789 else if (ms > 2000)
Joe Perches5db55842010-08-11 19:11:19 -07001790 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07001791 mwl8k_cmd_name(cmd->code,
1792 buf, sizeof(buf)),
1793 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001794 }
1795
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001796 return rc;
1797}
1798
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +01001799static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
1800 struct ieee80211_vif *vif,
1801 struct mwl8k_cmd_pkt *cmd)
1802{
1803 if (vif != NULL)
1804 cmd->macid = MWL8K_VIF(vif)->macid;
1805 return mwl8k_post_cmd(hw, cmd);
1806}
1807
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001808/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001809 * Setup code shared between STA and AP firmware images.
1810 */
1811static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1812{
1813 struct mwl8k_priv *priv = hw->priv;
1814
1815 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1816 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1817
1818 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1819 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1820
1821 priv->band_24.band = IEEE80211_BAND_2GHZ;
1822 priv->band_24.channels = priv->channels_24;
1823 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1824 priv->band_24.bitrates = priv->rates_24;
1825 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1826
1827 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1828}
1829
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01001830static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
1831{
1832 struct mwl8k_priv *priv = hw->priv;
1833
1834 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
1835 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
1836
1837 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
1838 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
1839
1840 priv->band_50.band = IEEE80211_BAND_5GHZ;
1841 priv->band_50.channels = priv->channels_50;
1842 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
1843 priv->band_50.bitrates = priv->rates_50;
1844 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
1845
1846 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
1847}
1848
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001849/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001850 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001851 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001852struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001853 struct mwl8k_cmd_pkt header;
1854 __u8 hw_rev;
1855 __u8 host_interface;
1856 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001857 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001858 __le16 region_code;
1859 __le32 fw_rev;
1860 __le32 ps_cookie;
1861 __le32 caps;
1862 __u8 mcs_bitmap[16];
1863 __le32 rx_queue_ptr;
1864 __le32 num_tx_queues;
1865 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1866 __le32 caps2;
1867 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001868 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001869} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001870
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001871#define MWL8K_CAP_MAX_AMSDU 0x20000000
1872#define MWL8K_CAP_GREENFIELD 0x08000000
1873#define MWL8K_CAP_AMPDU 0x04000000
1874#define MWL8K_CAP_RX_STBC 0x01000000
1875#define MWL8K_CAP_TX_STBC 0x00800000
1876#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1877#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1878#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1879#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1880#define MWL8K_CAP_DELAY_BA 0x00003000
1881#define MWL8K_CAP_MIMO 0x00000200
1882#define MWL8K_CAP_40MHZ 0x00000100
Lennert Buytenhek06953232010-01-12 13:49:41 +01001883#define MWL8K_CAP_BAND_MASK 0x00000007
1884#define MWL8K_CAP_5GHZ 0x00000004
1885#define MWL8K_CAP_2GHZ4 0x00000001
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001886
Lennert Buytenhek06953232010-01-12 13:49:41 +01001887static void
1888mwl8k_set_ht_caps(struct ieee80211_hw *hw,
1889 struct ieee80211_supported_band *band, u32 cap)
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001890{
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001891 int rx_streams;
1892 int tx_streams;
1893
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001894 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001895
1896 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001897 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001898 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001899 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001900 if (cap & MWL8K_CAP_AMPDU) {
1901 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001902 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1903 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001904 }
1905 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001906 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001907 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001908 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001909 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001910 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001911 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001912 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001913 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001914 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001915 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001916 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001917
1918 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1919 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1920
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001921 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001922 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001923 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001924 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001925 band->ht_cap.mcs.rx_mask[2] = 0xff;
1926 band->ht_cap.mcs.rx_mask[4] = 0x01;
1927 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001928
1929 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001930 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1931 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001932 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1933 }
1934}
1935
Lennert Buytenhek06953232010-01-12 13:49:41 +01001936static void
1937mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
1938{
1939 struct mwl8k_priv *priv = hw->priv;
1940
1941 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
1942 mwl8k_setup_2ghz_band(hw);
1943 if (caps & MWL8K_CAP_MIMO)
1944 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
1945 }
1946
1947 if (caps & MWL8K_CAP_5GHZ) {
1948 mwl8k_setup_5ghz_band(hw);
1949 if (caps & MWL8K_CAP_MIMO)
1950 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
1951 }
1952}
1953
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001954static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001955{
1956 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001957 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001958 int rc;
1959 int i;
1960
1961 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1962 if (cmd == NULL)
1963 return -ENOMEM;
1964
1965 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1966 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1967
1968 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1969 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001970 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001971 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001972 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001973 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001974 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001975 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001976
1977 rc = mwl8k_post_cmd(hw, &cmd->header);
1978
1979 if (!rc) {
1980 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1981 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001982 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001983 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek06953232010-01-12 13:49:41 +01001984 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01001985 priv->ap_macids_supported = 0x00000000;
1986 priv->sta_macids_supported = 0x00000001;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001987 }
1988
1989 kfree(cmd);
1990 return rc;
1991}
1992
1993/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001994 * CMD_GET_HW_SPEC (AP version).
1995 */
1996struct mwl8k_cmd_get_hw_spec_ap {
1997 struct mwl8k_cmd_pkt header;
1998 __u8 hw_rev;
1999 __u8 host_interface;
2000 __le16 num_wcb;
2001 __le16 num_mcaddrs;
2002 __u8 perm_addr[ETH_ALEN];
2003 __le16 region_code;
2004 __le16 num_antenna;
2005 __le32 fw_rev;
2006 __le32 wcbbase0;
2007 __le32 rxwrptr;
2008 __le32 rxrdptr;
2009 __le32 ps_cookie;
2010 __le32 wcbbase1;
2011 __le32 wcbbase2;
2012 __le32 wcbbase3;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002013 __le32 fw_api_version;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002014} __packed;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002015
2016static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
2017{
2018 struct mwl8k_priv *priv = hw->priv;
2019 struct mwl8k_cmd_get_hw_spec_ap *cmd;
2020 int rc;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002021 u32 api_version;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002022
2023 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2024 if (cmd == NULL)
2025 return -ENOMEM;
2026
2027 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
2028 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2029
2030 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
2031 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2032
2033 rc = mwl8k_post_cmd(hw, &cmd->header);
2034
2035 if (!rc) {
2036 int off;
2037
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002038 api_version = le32_to_cpu(cmd->fw_api_version);
2039 if (priv->device_info->fw_api_ap != api_version) {
2040 printk(KERN_ERR "%s: Unsupported fw API version for %s."
2041 " Expected %d got %d.\n", MWL8K_NAME,
2042 priv->device_info->part_name,
2043 priv->device_info->fw_api_ap,
2044 api_version);
2045 rc = -EINVAL;
2046 goto done;
2047 }
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002048 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
2049 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
2050 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
2051 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01002052 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002053 priv->ap_macids_supported = 0x000000ff;
2054 priv->sta_macids_supported = 0x00000000;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002055
2056 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002057 iowrite32(priv->txq[0].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002058
2059 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002060 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002061
2062 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002063 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002064
2065 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002066 iowrite32(priv->txq[1].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002067
2068 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002069 iowrite32(priv->txq[2].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002070
2071 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04002072 iowrite32(priv->txq[3].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002073 }
2074
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08002075done:
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002076 kfree(cmd);
2077 return rc;
2078}
2079
2080/*
2081 * CMD_SET_HW_SPEC.
2082 */
2083struct mwl8k_cmd_set_hw_spec {
2084 struct mwl8k_cmd_pkt header;
2085 __u8 hw_rev;
2086 __u8 host_interface;
2087 __le16 num_mcaddrs;
2088 __u8 perm_addr[ETH_ALEN];
2089 __le16 region_code;
2090 __le32 fw_rev;
2091 __le32 ps_cookie;
2092 __le32 caps;
2093 __le32 rx_queue_ptr;
2094 __le32 num_tx_queues;
2095 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
2096 __le32 flags;
2097 __le32 num_tx_desc_per_queue;
2098 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002099} __packed;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002100
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002101#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
2102#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
2103#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002104
2105static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
2106{
2107 struct mwl8k_priv *priv = hw->priv;
2108 struct mwl8k_cmd_set_hw_spec *cmd;
2109 int rc;
2110 int i;
2111
2112 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2113 if (cmd == NULL)
2114 return -ENOMEM;
2115
2116 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
2117 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2118
2119 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
2120 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
2121 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
2122 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2123 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002124 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
2125 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
2126 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02002127 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
2128 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
2129
2130 rc = mwl8k_post_cmd(hw, &cmd->header);
2131 kfree(cmd);
2132
2133 return rc;
2134}
2135
2136/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002137 * CMD_MAC_MULTICAST_ADR.
2138 */
2139struct mwl8k_cmd_mac_multicast_adr {
2140 struct mwl8k_cmd_pkt header;
2141 __le16 action;
2142 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002143 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002144};
2145
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002146#define MWL8K_ENABLE_RX_DIRECTED 0x0001
2147#define MWL8K_ENABLE_RX_MULTICAST 0x0002
2148#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2149#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002150
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002151static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002152__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Jiri Pirko22bedad2010-04-01 21:22:57 +00002153 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002154{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002155 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002156 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002157 int size;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002158 int mc_count = 0;
2159
2160 if (mc_list)
2161 mc_count = netdev_hw_addr_list_count(mc_list);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002162
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002163 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002164 allmulti = 1;
2165 mc_count = 0;
2166 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002167
2168 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2169
2170 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002171 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002172 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002173
2174 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2175 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002176 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2177 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002178
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002179 if (allmulti) {
2180 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2181 } else if (mc_count) {
Jiri Pirko22bedad2010-04-01 21:22:57 +00002182 struct netdev_hw_addr *ha;
2183 int i = 0;
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002184
2185 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2186 cmd->numaddr = cpu_to_le16(mc_count);
Jiri Pirko22bedad2010-04-01 21:22:57 +00002187 netdev_hw_addr_list_for_each(ha, mc_list) {
2188 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002189 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002190 }
2191
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002192 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002193}
2194
2195/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002196 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002197 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002198struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002199 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002200 __le32 stats[64];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002201} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002202
2203#define MWL8K_STAT_ACK_FAILURE 9
2204#define MWL8K_STAT_RTS_FAILURE 12
2205#define MWL8K_STAT_FCS_ERROR 24
2206#define MWL8K_STAT_RTS_SUCCESS 11
2207
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002208static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2209 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002210{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002211 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002212 int rc;
2213
2214 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2215 if (cmd == NULL)
2216 return -ENOMEM;
2217
2218 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2219 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002220
2221 rc = mwl8k_post_cmd(hw, &cmd->header);
2222 if (!rc) {
2223 stats->dot11ACKFailureCount =
2224 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2225 stats->dot11RTSFailureCount =
2226 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2227 stats->dot11FCSErrorCount =
2228 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2229 stats->dot11RTSSuccessCount =
2230 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2231 }
2232 kfree(cmd);
2233
2234 return rc;
2235}
2236
2237/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002238 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002239 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002240struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002241 struct mwl8k_cmd_pkt header;
2242 __le16 action;
2243 __le16 control;
2244 __le16 radio_on;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002245} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002246
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002247static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002248mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002249{
2250 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002251 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002252 int rc;
2253
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002254 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002255 return 0;
2256
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002257 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2258 if (cmd == NULL)
2259 return -ENOMEM;
2260
2261 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2262 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2263 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002264 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002265 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2266
2267 rc = mwl8k_post_cmd(hw, &cmd->header);
2268 kfree(cmd);
2269
2270 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002271 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002272
2273 return rc;
2274}
2275
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002276static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002277{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002278 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002279}
2280
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002281static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002282{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002283 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002284}
2285
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002286static int
2287mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2288{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002289 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002290
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002291 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002292
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002293 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002294}
2295
2296/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002297 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002298 */
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002299#define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002300
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002301struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002302 struct mwl8k_cmd_pkt header;
2303 __le16 action;
2304 __le16 support_level;
2305 __le16 current_level;
2306 __le16 reserved;
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002307 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002308} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002309
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002310static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002311{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002312 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002313 int rc;
2314
2315 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2316 if (cmd == NULL)
2317 return -ENOMEM;
2318
2319 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2320 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2321 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2322 cmd->support_level = cpu_to_le16(dBm);
2323
2324 rc = mwl8k_post_cmd(hw, &cmd->header);
2325 kfree(cmd);
2326
2327 return rc;
2328}
2329
2330/*
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002331 * CMD_TX_POWER.
2332 */
2333#define MWL8K_TX_POWER_LEVEL_TOTAL 12
2334
2335struct mwl8k_cmd_tx_power {
2336 struct mwl8k_cmd_pkt header;
2337 __le16 action;
2338 __le16 band;
2339 __le16 channel;
2340 __le16 bw;
2341 __le16 sub_ch;
2342 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2343} __attribute__((packed));
2344
2345static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2346 struct ieee80211_conf *conf,
2347 unsigned short pwr)
2348{
2349 struct ieee80211_channel *channel = conf->channel;
2350 struct mwl8k_cmd_tx_power *cmd;
2351 int rc;
2352 int i;
2353
2354 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2355 if (cmd == NULL)
2356 return -ENOMEM;
2357
2358 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2359 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2360 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2361
2362 if (channel->band == IEEE80211_BAND_2GHZ)
2363 cmd->band = cpu_to_le16(0x1);
2364 else if (channel->band == IEEE80211_BAND_5GHZ)
2365 cmd->band = cpu_to_le16(0x4);
2366
2367 cmd->channel = channel->hw_value;
2368
2369 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2370 conf->channel_type == NL80211_CHAN_HT20) {
2371 cmd->bw = cpu_to_le16(0x2);
2372 } else {
2373 cmd->bw = cpu_to_le16(0x4);
2374 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2375 cmd->sub_ch = cpu_to_le16(0x3);
2376 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2377 cmd->sub_ch = cpu_to_le16(0x1);
2378 }
2379
2380 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2381 cmd->power_level_list[i] = cpu_to_le16(pwr);
2382
2383 rc = mwl8k_post_cmd(hw, &cmd->header);
2384 kfree(cmd);
2385
2386 return rc;
2387}
2388
2389/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002390 * CMD_RF_ANTENNA.
2391 */
2392struct mwl8k_cmd_rf_antenna {
2393 struct mwl8k_cmd_pkt header;
2394 __le16 antenna;
2395 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002396} __packed;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002397
2398#define MWL8K_RF_ANTENNA_RX 1
2399#define MWL8K_RF_ANTENNA_TX 2
2400
2401static int
2402mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2403{
2404 struct mwl8k_cmd_rf_antenna *cmd;
2405 int rc;
2406
2407 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2408 if (cmd == NULL)
2409 return -ENOMEM;
2410
2411 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2412 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2413 cmd->antenna = cpu_to_le16(antenna);
2414 cmd->mode = cpu_to_le16(mask);
2415
2416 rc = mwl8k_post_cmd(hw, &cmd->header);
2417 kfree(cmd);
2418
2419 return rc;
2420}
2421
2422/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002423 * CMD_SET_BEACON.
2424 */
2425struct mwl8k_cmd_set_beacon {
2426 struct mwl8k_cmd_pkt header;
2427 __le16 beacon_len;
2428 __u8 beacon[0];
2429};
2430
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002431static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2432 struct ieee80211_vif *vif, u8 *beacon, int len)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002433{
2434 struct mwl8k_cmd_set_beacon *cmd;
2435 int rc;
2436
2437 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2438 if (cmd == NULL)
2439 return -ENOMEM;
2440
2441 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2442 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2443 cmd->beacon_len = cpu_to_le16(len);
2444 memcpy(cmd->beacon, beacon, len);
2445
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002446 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002447 kfree(cmd);
2448
2449 return rc;
2450}
2451
2452/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002453 * CMD_SET_PRE_SCAN.
2454 */
2455struct mwl8k_cmd_set_pre_scan {
2456 struct mwl8k_cmd_pkt header;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002457} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002458
2459static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2460{
2461 struct mwl8k_cmd_set_pre_scan *cmd;
2462 int rc;
2463
2464 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2465 if (cmd == NULL)
2466 return -ENOMEM;
2467
2468 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2469 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2470
2471 rc = mwl8k_post_cmd(hw, &cmd->header);
2472 kfree(cmd);
2473
2474 return rc;
2475}
2476
2477/*
2478 * CMD_SET_POST_SCAN.
2479 */
2480struct mwl8k_cmd_set_post_scan {
2481 struct mwl8k_cmd_pkt header;
2482 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002483 __u8 bssid[ETH_ALEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002484} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002485
2486static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002487mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002488{
2489 struct mwl8k_cmd_set_post_scan *cmd;
2490 int rc;
2491
2492 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2493 if (cmd == NULL)
2494 return -ENOMEM;
2495
2496 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2497 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2498 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002499 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002500
2501 rc = mwl8k_post_cmd(hw, &cmd->header);
2502 kfree(cmd);
2503
2504 return rc;
2505}
2506
2507/*
2508 * CMD_SET_RF_CHANNEL.
2509 */
2510struct mwl8k_cmd_set_rf_channel {
2511 struct mwl8k_cmd_pkt header;
2512 __le16 action;
2513 __u8 current_channel;
2514 __le32 channel_flags;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002515} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002516
2517static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002518 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002519{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002520 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002521 struct mwl8k_cmd_set_rf_channel *cmd;
2522 int rc;
2523
2524 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2525 if (cmd == NULL)
2526 return -ENOMEM;
2527
2528 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2529 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2530 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2531 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002532
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002533 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002534 cmd->channel_flags |= cpu_to_le32(0x00000001);
Lennert Buytenhek42574ea2010-01-12 13:49:18 +01002535 else if (channel->band == IEEE80211_BAND_5GHZ)
2536 cmd->channel_flags |= cpu_to_le32(0x00000004);
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002537
2538 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2539 conf->channel_type == NL80211_CHAN_HT20)
2540 cmd->channel_flags |= cpu_to_le32(0x00000080);
2541 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2542 cmd->channel_flags |= cpu_to_le32(0x000001900);
2543 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2544 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002545
2546 rc = mwl8k_post_cmd(hw, &cmd->header);
2547 kfree(cmd);
2548
2549 return rc;
2550}
2551
2552/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002553 * CMD_SET_AID.
2554 */
2555#define MWL8K_FRAME_PROT_DISABLED 0x00
2556#define MWL8K_FRAME_PROT_11G 0x07
2557#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2558#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2559
2560struct mwl8k_cmd_update_set_aid {
2561 struct mwl8k_cmd_pkt header;
2562 __le16 aid;
2563
2564 /* AP's MAC address (BSSID) */
2565 __u8 bssid[ETH_ALEN];
2566 __le16 protection_mode;
2567 __u8 supp_rates[14];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002568} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002569
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002570static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2571{
2572 int i;
2573 int j;
2574
2575 /*
2576 * Clear nonstandard rates 4 and 13.
2577 */
2578 mask &= 0x1fef;
2579
2580 for (i = 0, j = 0; i < 14; i++) {
2581 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002582 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002583 }
2584}
2585
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002586static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002587mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2588 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002589{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002590 struct mwl8k_cmd_update_set_aid *cmd;
2591 u16 prot_mode;
2592 int rc;
2593
2594 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2595 if (cmd == NULL)
2596 return -ENOMEM;
2597
2598 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2599 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002600 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002601 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002602
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002603 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002604 prot_mode = MWL8K_FRAME_PROT_11G;
2605 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002606 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002607 IEEE80211_HT_OP_MODE_PROTECTION) {
2608 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2609 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2610 break;
2611 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2612 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2613 break;
2614 default:
2615 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2616 break;
2617 }
2618 }
2619 cmd->protection_mode = cpu_to_le16(prot_mode);
2620
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002621 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002622
2623 rc = mwl8k_post_cmd(hw, &cmd->header);
2624 kfree(cmd);
2625
2626 return rc;
2627}
2628
2629/*
2630 * CMD_SET_RATE.
2631 */
2632struct mwl8k_cmd_set_rate {
2633 struct mwl8k_cmd_pkt header;
2634 __u8 legacy_rates[14];
2635
2636 /* Bitmap for supported MCS codes. */
2637 __u8 mcs_set[16];
2638 __u8 reserved[16];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002639} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002640
2641static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002642mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002643 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002644{
2645 struct mwl8k_cmd_set_rate *cmd;
2646 int rc;
2647
2648 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2649 if (cmd == NULL)
2650 return -ENOMEM;
2651
2652 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2653 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002654 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002655 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002656
2657 rc = mwl8k_post_cmd(hw, &cmd->header);
2658 kfree(cmd);
2659
2660 return rc;
2661}
2662
2663/*
2664 * CMD_FINALIZE_JOIN.
2665 */
2666#define MWL8K_FJ_BEACON_MAXLEN 128
2667
2668struct mwl8k_cmd_finalize_join {
2669 struct mwl8k_cmd_pkt header;
2670 __le32 sleep_interval; /* Number of beacon periods to sleep */
2671 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002672} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002673
2674static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2675 int framelen, int dtim)
2676{
2677 struct mwl8k_cmd_finalize_join *cmd;
2678 struct ieee80211_mgmt *payload = frame;
2679 int payload_len;
2680 int rc;
2681
2682 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2683 if (cmd == NULL)
2684 return -ENOMEM;
2685
2686 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2687 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2688 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2689
2690 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2691 if (payload_len < 0)
2692 payload_len = 0;
2693 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2694 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2695
2696 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2697
2698 rc = mwl8k_post_cmd(hw, &cmd->header);
2699 kfree(cmd);
2700
2701 return rc;
2702}
2703
2704/*
2705 * CMD_SET_RTS_THRESHOLD.
2706 */
2707struct mwl8k_cmd_set_rts_threshold {
2708 struct mwl8k_cmd_pkt header;
2709 __le16 action;
2710 __le16 threshold;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002711} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002712
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002713static int
2714mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002715{
2716 struct mwl8k_cmd_set_rts_threshold *cmd;
2717 int rc;
2718
2719 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2720 if (cmd == NULL)
2721 return -ENOMEM;
2722
2723 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2724 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002725 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2726 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002727
2728 rc = mwl8k_post_cmd(hw, &cmd->header);
2729 kfree(cmd);
2730
2731 return rc;
2732}
2733
2734/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002735 * CMD_SET_SLOT.
2736 */
2737struct mwl8k_cmd_set_slot {
2738 struct mwl8k_cmd_pkt header;
2739 __le16 action;
2740 __u8 short_slot;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002741} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002742
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002743static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002744{
2745 struct mwl8k_cmd_set_slot *cmd;
2746 int rc;
2747
2748 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2749 if (cmd == NULL)
2750 return -ENOMEM;
2751
2752 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2753 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2754 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002755 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002756
2757 rc = mwl8k_post_cmd(hw, &cmd->header);
2758 kfree(cmd);
2759
2760 return rc;
2761}
2762
2763/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002764 * CMD_SET_EDCA_PARAMS.
2765 */
2766struct mwl8k_cmd_set_edca_params {
2767 struct mwl8k_cmd_pkt header;
2768
2769 /* See MWL8K_SET_EDCA_XXX below */
2770 __le16 action;
2771
2772 /* TX opportunity in units of 32 us */
2773 __le16 txop;
2774
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002775 union {
2776 struct {
2777 /* Log exponent of max contention period: 0...15 */
2778 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002779
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002780 /* Log exponent of min contention period: 0...15 */
2781 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002782
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002783 /* Adaptive interframe spacing in units of 32us */
2784 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002785
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002786 /* TX queue to configure */
2787 __u8 txq;
2788 } ap;
2789 struct {
2790 /* Log exponent of max contention period: 0...15 */
2791 __u8 log_cw_max;
2792
2793 /* Log exponent of min contention period: 0...15 */
2794 __u8 log_cw_min;
2795
2796 /* Adaptive interframe spacing in units of 32us */
2797 __u8 aifs;
2798
2799 /* TX queue to configure */
2800 __u8 txq;
2801 } sta;
2802 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00002803} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002804
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002805#define MWL8K_SET_EDCA_CW 0x01
2806#define MWL8K_SET_EDCA_TXOP 0x02
2807#define MWL8K_SET_EDCA_AIFS 0x04
2808
2809#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2810 MWL8K_SET_EDCA_TXOP | \
2811 MWL8K_SET_EDCA_AIFS)
2812
2813static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002814mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2815 __u16 cw_min, __u16 cw_max,
2816 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002817{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002818 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002819 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002820 int rc;
2821
2822 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2823 if (cmd == NULL)
2824 return -ENOMEM;
2825
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002826 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2827 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002828 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2829 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002830 if (priv->ap_fw) {
2831 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2832 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2833 cmd->ap.aifs = aifs;
2834 cmd->ap.txq = qnum;
2835 } else {
2836 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2837 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2838 cmd->sta.aifs = aifs;
2839 cmd->sta.txq = qnum;
2840 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002841
2842 rc = mwl8k_post_cmd(hw, &cmd->header);
2843 kfree(cmd);
2844
2845 return rc;
2846}
2847
2848/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002849 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002850 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002851struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002852 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002853 __le16 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002854} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002855
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002856static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002857{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002858 struct mwl8k_priv *priv = hw->priv;
2859 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002860 int rc;
2861
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002862 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2863 if (cmd == NULL)
2864 return -ENOMEM;
2865
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002866 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002867 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002868 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002869
2870 rc = mwl8k_post_cmd(hw, &cmd->header);
2871 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002872
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002873 if (!rc)
2874 priv->wmm_enabled = enable;
2875
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002876 return rc;
2877}
2878
2879/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002880 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002881 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002882struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002883 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002884 __le32 action;
2885 __u8 rx_antenna_map;
2886 __u8 tx_antenna_map;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002887} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002888
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002889static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002890{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002891 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002892 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002893
2894 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2895 if (cmd == NULL)
2896 return -ENOMEM;
2897
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002898 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002899 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002900 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2901 cmd->rx_antenna_map = rx;
2902 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002903
2904 rc = mwl8k_post_cmd(hw, &cmd->header);
2905 kfree(cmd);
2906
2907 return rc;
2908}
2909
2910/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002911 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002912 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002913struct mwl8k_cmd_use_fixed_rate_sta {
2914 struct mwl8k_cmd_pkt header;
2915 __le32 action;
2916 __le32 allow_rate_drop;
2917 __le32 num_rates;
2918 struct {
2919 __le32 is_ht_rate;
2920 __le32 enable_retry;
2921 __le32 rate;
2922 __le32 retry_count;
2923 } rate_entry[8];
2924 __le32 rate_type;
2925 __le32 reserved1;
2926 __le32 reserved2;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002927} __packed;
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002928
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002929#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002930#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002931
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002932static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002933{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002934 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002935 int rc;
2936
2937 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2938 if (cmd == NULL)
2939 return -ENOMEM;
2940
2941 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2942 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002943 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2944 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002945
2946 rc = mwl8k_post_cmd(hw, &cmd->header);
2947 kfree(cmd);
2948
2949 return rc;
2950}
2951
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002952/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002953 * CMD_USE_FIXED_RATE (AP version).
2954 */
2955struct mwl8k_cmd_use_fixed_rate_ap {
2956 struct mwl8k_cmd_pkt header;
2957 __le32 action;
2958 __le32 allow_rate_drop;
2959 __le32 num_rates;
2960 struct mwl8k_rate_entry_ap {
2961 __le32 is_ht_rate;
2962 __le32 enable_retry;
2963 __le32 rate;
2964 __le32 retry_count;
2965 } rate_entry[4];
2966 u8 multicast_rate;
2967 u8 multicast_rate_type;
2968 u8 management_rate;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002969} __packed;
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002970
2971static int
2972mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2973{
2974 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2975 int rc;
2976
2977 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2978 if (cmd == NULL)
2979 return -ENOMEM;
2980
2981 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2982 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2983 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2984 cmd->multicast_rate = mcast;
2985 cmd->management_rate = mgmt;
2986
2987 rc = mwl8k_post_cmd(hw, &cmd->header);
2988 kfree(cmd);
2989
2990 return rc;
2991}
2992
2993/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002994 * CMD_ENABLE_SNIFFER.
2995 */
2996struct mwl8k_cmd_enable_sniffer {
2997 struct mwl8k_cmd_pkt header;
2998 __le32 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002999} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003000
3001static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
3002{
3003 struct mwl8k_cmd_enable_sniffer *cmd;
3004 int rc;
3005
3006 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3007 if (cmd == NULL)
3008 return -ENOMEM;
3009
3010 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
3011 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3012 cmd->action = cpu_to_le32(!!enable);
3013
3014 rc = mwl8k_post_cmd(hw, &cmd->header);
3015 kfree(cmd);
3016
3017 return rc;
3018}
3019
3020/*
3021 * CMD_SET_MAC_ADDR.
3022 */
3023struct mwl8k_cmd_set_mac_addr {
3024 struct mwl8k_cmd_pkt header;
3025 union {
3026 struct {
3027 __le16 mac_type;
3028 __u8 mac_addr[ETH_ALEN];
3029 } mbss;
3030 __u8 mac_addr[ETH_ALEN];
3031 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00003032} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003033
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003034#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
3035#define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
3036#define MWL8K_MAC_TYPE_PRIMARY_AP 2
3037#define MWL8K_MAC_TYPE_SECONDARY_AP 3
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01003038
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003039static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
3040 struct ieee80211_vif *vif, u8 *mac)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003041{
3042 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003043 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003044 struct mwl8k_cmd_set_mac_addr *cmd;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003045 int mac_type;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003046 int rc;
3047
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003048 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3049 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
3050 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
3051 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
3052 else
3053 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
3054 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
3055 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
3056 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
3057 else
3058 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
3059 }
3060
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003061 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3062 if (cmd == NULL)
3063 return -ENOMEM;
3064
3065 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
3066 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3067 if (priv->ap_fw) {
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003068 cmd->mbss.mac_type = cpu_to_le16(mac_type);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003069 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
3070 } else {
3071 memcpy(cmd->mac_addr, mac, ETH_ALEN);
3072 }
3073
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003074 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003075 kfree(cmd);
3076
3077 return rc;
3078}
3079
3080/*
3081 * CMD_SET_RATEADAPT_MODE.
3082 */
3083struct mwl8k_cmd_set_rate_adapt_mode {
3084 struct mwl8k_cmd_pkt header;
3085 __le16 action;
3086 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003087} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003088
3089static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
3090{
3091 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
3092 int rc;
3093
3094 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3095 if (cmd == NULL)
3096 return -ENOMEM;
3097
3098 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
3099 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3100 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
3101 cmd->mode = cpu_to_le16(mode);
3102
3103 rc = mwl8k_post_cmd(hw, &cmd->header);
3104 kfree(cmd);
3105
3106 return rc;
3107}
3108
3109/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003110 * CMD_BSS_START.
3111 */
3112struct mwl8k_cmd_bss_start {
3113 struct mwl8k_cmd_pkt header;
3114 __le32 enable;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003115} __packed;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003116
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003117static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
3118 struct ieee80211_vif *vif, int enable)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003119{
3120 struct mwl8k_cmd_bss_start *cmd;
3121 int rc;
3122
3123 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3124 if (cmd == NULL)
3125 return -ENOMEM;
3126
3127 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
3128 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3129 cmd->enable = cpu_to_le32(enable);
3130
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003131 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003132 kfree(cmd);
3133
3134 return rc;
3135}
3136
3137/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003138 * CMD_SET_NEW_STN.
3139 */
3140struct mwl8k_cmd_set_new_stn {
3141 struct mwl8k_cmd_pkt header;
3142 __le16 aid;
3143 __u8 mac_addr[6];
3144 __le16 stn_id;
3145 __le16 action;
3146 __le16 rsvd;
3147 __le32 legacy_rates;
3148 __u8 ht_rates[4];
3149 __le16 cap_info;
3150 __le16 ht_capabilities_info;
3151 __u8 mac_ht_param_info;
3152 __u8 rev;
3153 __u8 control_channel;
3154 __u8 add_channel;
3155 __le16 op_mode;
3156 __le16 stbc;
3157 __u8 add_qos_info;
3158 __u8 is_qos_sta;
3159 __le32 fw_sta_ptr;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003160} __packed;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003161
3162#define MWL8K_STA_ACTION_ADD 0
3163#define MWL8K_STA_ACTION_REMOVE 2
3164
3165static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3166 struct ieee80211_vif *vif,
3167 struct ieee80211_sta *sta)
3168{
3169 struct mwl8k_cmd_set_new_stn *cmd;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003170 u32 rates;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003171 int rc;
3172
3173 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3174 if (cmd == NULL)
3175 return -ENOMEM;
3176
3177 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3178 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3179 cmd->aid = cpu_to_le16(sta->aid);
3180 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3181 cmd->stn_id = cpu_to_le16(sta->aid);
3182 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003183 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3184 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3185 else
3186 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3187 cmd->legacy_rates = cpu_to_le32(rates);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003188 if (sta->ht_cap.ht_supported) {
3189 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3190 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3191 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3192 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3193 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3194 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3195 ((sta->ht_cap.ampdu_density & 7) << 2);
3196 cmd->is_qos_sta = 1;
3197 }
3198
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003199 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003200 kfree(cmd);
3201
3202 return rc;
3203}
3204
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003205static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3206 struct ieee80211_vif *vif)
3207{
3208 struct mwl8k_cmd_set_new_stn *cmd;
3209 int rc;
3210
3211 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3212 if (cmd == NULL)
3213 return -ENOMEM;
3214
3215 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3216 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3217 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3218
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003219 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003220 kfree(cmd);
3221
3222 return rc;
3223}
3224
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003225static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
3226 struct ieee80211_vif *vif, u8 *addr)
3227{
3228 struct mwl8k_cmd_set_new_stn *cmd;
3229 int rc;
3230
3231 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3232 if (cmd == NULL)
3233 return -ENOMEM;
3234
3235 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3236 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3237 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3238 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
3239
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003240 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003241 kfree(cmd);
3242
3243 return rc;
3244}
3245
3246/*
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08003247 * CMD_UPDATE_ENCRYPTION.
3248 */
3249
3250#define MAX_ENCR_KEY_LENGTH 16
3251#define MIC_KEY_LENGTH 8
3252
3253struct mwl8k_cmd_update_encryption {
3254 struct mwl8k_cmd_pkt header;
3255
3256 __le32 action;
3257 __le32 reserved;
3258 __u8 mac_addr[6];
3259 __u8 encr_type;
3260
3261} __attribute__((packed));
3262
3263struct mwl8k_cmd_set_key {
3264 struct mwl8k_cmd_pkt header;
3265
3266 __le32 action;
3267 __le32 reserved;
3268 __le16 length;
3269 __le16 key_type_id;
3270 __le32 key_info;
3271 __le32 key_id;
3272 __le16 key_len;
3273 __u8 key_material[MAX_ENCR_KEY_LENGTH];
3274 __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
3275 __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
3276 __le16 tkip_rsc_low;
3277 __le32 tkip_rsc_high;
3278 __le16 tkip_tsc_low;
3279 __le32 tkip_tsc_high;
3280 __u8 mac_addr[6];
3281} __attribute__((packed));
3282
3283enum {
3284 MWL8K_ENCR_ENABLE,
3285 MWL8K_ENCR_SET_KEY,
3286 MWL8K_ENCR_REMOVE_KEY,
3287 MWL8K_ENCR_SET_GROUP_KEY,
3288};
3289
3290#define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
3291#define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
3292#define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
3293#define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
3294#define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
3295
3296enum {
3297 MWL8K_ALG_WEP,
3298 MWL8K_ALG_TKIP,
3299 MWL8K_ALG_CCMP,
3300};
3301
3302#define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
3303#define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
3304#define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
3305#define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
3306#define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
3307
3308static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
3309 struct ieee80211_vif *vif,
3310 u8 *addr,
3311 u8 encr_type)
3312{
3313 struct mwl8k_cmd_update_encryption *cmd;
3314 int rc;
3315
3316 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3317 if (cmd == NULL)
3318 return -ENOMEM;
3319
3320 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3321 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3322 cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
3323 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3324 cmd->encr_type = encr_type;
3325
3326 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3327 kfree(cmd);
3328
3329 return rc;
3330}
3331
3332static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
3333 u8 *addr,
3334 struct ieee80211_key_conf *key)
3335{
3336 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
3337 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3338 cmd->length = cpu_to_le16(sizeof(*cmd) -
3339 offsetof(struct mwl8k_cmd_set_key, length));
3340 cmd->key_id = cpu_to_le32(key->keyidx);
3341 cmd->key_len = cpu_to_le16(key->keylen);
3342 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3343
3344 switch (key->cipher) {
3345 case WLAN_CIPHER_SUITE_WEP40:
3346 case WLAN_CIPHER_SUITE_WEP104:
3347 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
3348 if (key->keyidx == 0)
3349 cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
3350
3351 break;
3352 case WLAN_CIPHER_SUITE_TKIP:
3353 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
3354 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3355 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
3356 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
3357 cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
3358 | MWL8K_KEY_FLAG_TSC_VALID);
3359 break;
3360 case WLAN_CIPHER_SUITE_CCMP:
3361 cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
3362 cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3363 ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
3364 : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
3365 break;
3366 default:
3367 return -ENOTSUPP;
3368 }
3369
3370 return 0;
3371}
3372
3373static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
3374 struct ieee80211_vif *vif,
3375 u8 *addr,
3376 struct ieee80211_key_conf *key)
3377{
3378 struct mwl8k_cmd_set_key *cmd;
3379 int rc;
3380 int keymlen;
3381 u32 action;
3382 u8 idx;
3383 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3384
3385 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3386 if (cmd == NULL)
3387 return -ENOMEM;
3388
3389 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
3390 if (rc < 0)
3391 goto done;
3392
3393 idx = key->keyidx;
3394
3395 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3396 action = MWL8K_ENCR_SET_KEY;
3397 else
3398 action = MWL8K_ENCR_SET_GROUP_KEY;
3399
3400 switch (key->cipher) {
3401 case WLAN_CIPHER_SUITE_WEP40:
3402 case WLAN_CIPHER_SUITE_WEP104:
3403 if (!mwl8k_vif->wep_key_conf[idx].enabled) {
3404 memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
3405 sizeof(*key) + key->keylen);
3406 mwl8k_vif->wep_key_conf[idx].enabled = 1;
3407 }
3408
3409 keymlen = 0;
3410 action = MWL8K_ENCR_SET_KEY;
3411 break;
3412 case WLAN_CIPHER_SUITE_TKIP:
3413 keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
3414 break;
3415 case WLAN_CIPHER_SUITE_CCMP:
3416 keymlen = key->keylen;
3417 break;
3418 default:
3419 rc = -ENOTSUPP;
3420 goto done;
3421 }
3422
3423 memcpy(cmd->key_material, key->key, keymlen);
3424 cmd->action = cpu_to_le32(action);
3425
3426 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3427done:
3428 kfree(cmd);
3429
3430 return rc;
3431}
3432
3433static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
3434 struct ieee80211_vif *vif,
3435 u8 *addr,
3436 struct ieee80211_key_conf *key)
3437{
3438 struct mwl8k_cmd_set_key *cmd;
3439 int rc;
3440 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3441
3442 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3443 if (cmd == NULL)
3444 return -ENOMEM;
3445
3446 rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
3447 if (rc < 0)
3448 goto done;
3449
3450 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3451 WLAN_CIPHER_SUITE_WEP104)
3452 mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
3453
3454 cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
3455
3456 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
3457done:
3458 kfree(cmd);
3459
3460 return rc;
3461}
3462
3463static int mwl8k_set_key(struct ieee80211_hw *hw,
3464 enum set_key_cmd cmd_param,
3465 struct ieee80211_vif *vif,
3466 struct ieee80211_sta *sta,
3467 struct ieee80211_key_conf *key)
3468{
3469 int rc = 0;
3470 u8 encr_type;
3471 u8 *addr;
3472 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
3473
3474 if (vif->type == NL80211_IFTYPE_STATION)
3475 return -EOPNOTSUPP;
3476
3477 if (sta == NULL)
3478 addr = hw->wiphy->perm_addr;
3479 else
3480 addr = sta->addr;
3481
3482 if (cmd_param == SET_KEY) {
3483 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
3484 rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
3485 if (rc)
3486 goto out;
3487
3488 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
3489 || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
3490 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
3491 else
3492 encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
3493
3494 rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
3495 encr_type);
3496 if (rc)
3497 goto out;
3498
3499 mwl8k_vif->is_hw_crypto_enabled = true;
3500
3501 } else {
3502 rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
3503
3504 if (rc)
3505 goto out;
3506
3507 mwl8k_vif->is_hw_crypto_enabled = false;
3508
3509 }
3510out:
3511 return rc;
3512}
3513
3514/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003515 * CMD_UPDATE_STADB.
3516 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01003517struct ewc_ht_info {
3518 __le16 control1;
3519 __le16 control2;
3520 __le16 control3;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003521} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01003522
3523struct peer_capability_info {
3524 /* Peer type - AP vs. STA. */
3525 __u8 peer_type;
3526
3527 /* Basic 802.11 capabilities from assoc resp. */
3528 __le16 basic_caps;
3529
3530 /* Set if peer supports 802.11n high throughput (HT). */
3531 __u8 ht_support;
3532
3533 /* Valid if HT is supported. */
3534 __le16 ht_caps;
3535 __u8 extended_ht_caps;
3536 struct ewc_ht_info ewc_info;
3537
3538 /* Legacy rate table. Intersection of our rates and peer rates. */
3539 __u8 legacy_rates[12];
3540
3541 /* HT rate table. Intersection of our rates and peer rates. */
3542 __u8 ht_rates[16];
3543 __u8 pad[16];
3544
3545 /* If set, interoperability mode, no proprietary extensions. */
3546 __u8 interop;
3547 __u8 pad2;
3548 __u8 station_id;
3549 __le16 amsdu_enabled;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003550} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01003551
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003552struct mwl8k_cmd_update_stadb {
3553 struct mwl8k_cmd_pkt header;
3554
3555 /* See STADB_ACTION_TYPE */
3556 __le32 action;
3557
3558 /* Peer MAC address */
3559 __u8 peer_addr[ETH_ALEN];
3560
3561 __le32 reserved;
3562
3563 /* Peer info - valid during add/update. */
3564 struct peer_capability_info peer_info;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003565} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003566
Lennert Buytenheka6804002010-01-04 21:55:42 +01003567#define MWL8K_STA_DB_MODIFY_ENTRY 1
3568#define MWL8K_STA_DB_DEL_ENTRY 2
3569
3570/* Peer Entry flags - used to define the type of the peer node */
3571#define MWL8K_PEER_TYPE_ACCESSPOINT 2
3572
3573static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003574 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003575 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003576{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003577 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01003578 struct peer_capability_info *p;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003579 u32 rates;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003580 int rc;
3581
3582 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3583 if (cmd == NULL)
3584 return -ENOMEM;
3585
3586 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3587 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01003588 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003589 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003590
Lennert Buytenheka6804002010-01-04 21:55:42 +01003591 p = &cmd->peer_info;
3592 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
3593 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003594 p->ht_support = sta->ht_cap.ht_supported;
John W. Linvilleb6037422010-07-20 13:55:00 -04003595 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003596 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
3597 ((sta->ht_cap.ampdu_density & 7) << 2);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003598 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3599 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3600 else
3601 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3602 legacy_rate_mask_to_array(p->legacy_rates, rates);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003603 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003604 p->interop = 1;
3605 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003606
Lennert Buytenheka6804002010-01-04 21:55:42 +01003607 rc = mwl8k_post_cmd(hw, &cmd->header);
3608 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003609
Lennert Buytenheka6804002010-01-04 21:55:42 +01003610 return rc ? rc : p->station_id;
3611}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003612
Lennert Buytenheka6804002010-01-04 21:55:42 +01003613static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
3614 struct ieee80211_vif *vif, u8 *addr)
3615{
3616 struct mwl8k_cmd_update_stadb *cmd;
3617 int rc;
3618
3619 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3620 if (cmd == NULL)
3621 return -ENOMEM;
3622
3623 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3624 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3625 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
3626 memcpy(cmd->peer_addr, addr, ETH_ALEN);
3627
3628 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003629 kfree(cmd);
3630
3631 return rc;
3632}
3633
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003634
3635/*
3636 * Interrupt handling.
3637 */
3638static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
3639{
3640 struct ieee80211_hw *hw = dev_id;
3641 struct mwl8k_priv *priv = hw->priv;
3642 u32 status;
3643
3644 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003645 if (!status)
3646 return IRQ_NONE;
3647
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003648 if (status & MWL8K_A2H_INT_TX_DONE) {
3649 status &= ~MWL8K_A2H_INT_TX_DONE;
3650 tasklet_schedule(&priv->poll_tx_task);
3651 }
3652
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003653 if (status & MWL8K_A2H_INT_RX_READY) {
3654 status &= ~MWL8K_A2H_INT_RX_READY;
3655 tasklet_schedule(&priv->poll_rx_task);
3656 }
3657
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003658 if (status)
3659 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003660
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003661 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003662 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003663 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003664 }
3665
3666 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003667 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003668 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003669 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003670 }
3671
3672 return IRQ_HANDLED;
3673}
3674
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003675static void mwl8k_tx_poll(unsigned long data)
3676{
3677 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3678 struct mwl8k_priv *priv = hw->priv;
3679 int limit;
3680 int i;
3681
3682 limit = 32;
3683
3684 spin_lock_bh(&priv->tx_lock);
3685
3686 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3687 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3688
3689 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3690 complete(priv->tx_wait);
3691 priv->tx_wait = NULL;
3692 }
3693
3694 spin_unlock_bh(&priv->tx_lock);
3695
3696 if (limit) {
3697 writel(~MWL8K_A2H_INT_TX_DONE,
3698 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3699 } else {
3700 tasklet_schedule(&priv->poll_tx_task);
3701 }
3702}
3703
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003704static void mwl8k_rx_poll(unsigned long data)
3705{
3706 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3707 struct mwl8k_priv *priv = hw->priv;
3708 int limit;
3709
3710 limit = 32;
3711 limit -= rxq_process(hw, 0, limit);
3712 limit -= rxq_refill(hw, 0, limit);
3713
3714 if (limit) {
3715 writel(~MWL8K_A2H_INT_RX_READY,
3716 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3717 } else {
3718 tasklet_schedule(&priv->poll_rx_task);
3719 }
3720}
3721
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003722
3723/*
3724 * Core driver operations.
3725 */
3726static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3727{
3728 struct mwl8k_priv *priv = hw->priv;
3729 int index = skb_get_queue_mapping(skb);
3730 int rc;
3731
Lennert Buytenhek9189c102010-01-12 13:47:32 +01003732 if (!priv->radio_on) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003733 wiphy_debug(hw->wiphy,
3734 "dropped TX frame since radio disabled\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003735 dev_kfree_skb(skb);
3736 return NETDEV_TX_OK;
3737 }
3738
3739 rc = mwl8k_txq_xmit(hw, index, skb);
3740
3741 return rc;
3742}
3743
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003744static int mwl8k_start(struct ieee80211_hw *hw)
3745{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003746 struct mwl8k_priv *priv = hw->priv;
3747 int rc;
3748
Joe Perchesa0607fd2009-11-18 23:29:17 -08003749 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003750 IRQF_SHARED, MWL8K_NAME, hw);
3751 if (rc) {
Joe Perches5db55842010-08-11 19:11:19 -07003752 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003753 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003754 }
3755
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003756 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003757 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003758 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003759
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003760 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003761 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003762
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003763 rc = mwl8k_fw_lock(hw);
3764 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003765 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003766
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003767 if (!priv->ap_fw) {
3768 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003769 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003770
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003771 if (!rc)
3772 rc = mwl8k_cmd_set_pre_scan(hw);
3773
3774 if (!rc)
3775 rc = mwl8k_cmd_set_post_scan(hw,
3776 "\x00\x00\x00\x00\x00\x00");
3777 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003778
3779 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003780 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003781
3782 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003783 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003784
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003785 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003786 }
3787
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003788 if (rc) {
3789 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3790 free_irq(priv->pdev->irq, hw);
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003791 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003792 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003793 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003794
3795 return rc;
3796}
3797
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003798static void mwl8k_stop(struct ieee80211_hw *hw)
3799{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003800 struct mwl8k_priv *priv = hw->priv;
3801 int i;
3802
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003803 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003804
3805 ieee80211_stop_queues(hw);
3806
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003807 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003808 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003809 free_irq(priv->pdev->irq, hw);
3810
3811 /* Stop finalize join worker */
3812 cancel_work_sync(&priv->finalize_join_worker);
3813 if (priv->beacon_skb != NULL)
3814 dev_kfree_skb(priv->beacon_skb);
3815
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003816 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003817 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003818 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003819
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003820 /* Return all skbs to mac80211 */
3821 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01003822 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003823}
3824
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003825static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
3826
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003827static int mwl8k_add_interface(struct ieee80211_hw *hw,
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003828 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003829{
3830 struct mwl8k_priv *priv = hw->priv;
3831 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003832 u32 macids_supported;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003833 int macid, rc;
3834 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003835
3836 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003837 * Reject interface creation if sniffer mode is active, as
3838 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003839 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003840 */
3841 if (priv->sniffer_enabled) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003842 wiphy_info(hw->wiphy,
3843 "unable to create STA interface because sniffer mode is enabled\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003844 return -EINVAL;
3845 }
3846
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003847 di = priv->device_info;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003848 switch (vif->type) {
3849 case NL80211_IFTYPE_AP:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003850 if (!priv->ap_fw && di->fw_image_ap) {
3851 /* we must load the ap fw to meet this request */
3852 if (!list_empty(&priv->vif_list))
3853 return -EBUSY;
3854 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
3855 if (rc)
3856 return rc;
3857 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003858 macids_supported = priv->ap_macids_supported;
3859 break;
3860 case NL80211_IFTYPE_STATION:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003861 if (priv->ap_fw && di->fw_image_sta) {
3862 /* we must load the sta fw to meet this request */
3863 if (!list_empty(&priv->vif_list))
3864 return -EBUSY;
3865 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
3866 if (rc)
3867 return rc;
3868 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003869 macids_supported = priv->sta_macids_supported;
3870 break;
3871 default:
3872 return -EINVAL;
3873 }
3874
3875 macid = ffs(macids_supported & ~priv->macids_used);
3876 if (!macid--)
3877 return -EBUSY;
3878
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003879 /* Setup driver private area. */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003880 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003881 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003882 mwl8k_vif->vif = vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003883 mwl8k_vif->macid = macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003884 mwl8k_vif->seqno = 0;
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08003885 memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
3886 mwl8k_vif->is_hw_crypto_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003887
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003888 /* Set the mac address. */
3889 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
3890
3891 if (priv->ap_fw)
3892 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3893
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003894 priv->macids_used |= 1 << mwl8k_vif->macid;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003895 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003896
3897 return 0;
3898}
3899
3900static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003901 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003902{
3903 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003904 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003905
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003906 if (priv->ap_fw)
3907 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3908
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003909 mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003910
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003911 priv->macids_used &= ~(1 << mwl8k_vif->macid);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003912 list_del(&mwl8k_vif->list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003913}
3914
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003915static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003916{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003917 struct ieee80211_conf *conf = &hw->conf;
3918 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003919 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003920
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003921 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003922 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003923 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003924 }
3925
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003926 rc = mwl8k_fw_lock(hw);
3927 if (rc)
3928 return rc;
3929
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003930 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003931 if (rc)
3932 goto out;
3933
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003934 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003935 if (rc)
3936 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003937
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003938 if (conf->power_level > 18)
3939 conf->power_level = 18;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003940
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003941 if (priv->ap_fw) {
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08003942 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
3943 if (rc)
3944 goto out;
3945
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003946 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3947 if (!rc)
3948 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3949 } else {
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08003950 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
3951 if (rc)
3952 goto out;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003953 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3954 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003955
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003956out:
3957 mwl8k_fw_unlock(hw);
3958
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003959 return rc;
3960}
3961
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003962static void
3963mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3964 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003965{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003966 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003967 u32 ap_legacy_rates;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003968 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003969 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003970
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003971 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003972 return;
3973
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003974 /*
3975 * No need to capture a beacon if we're no longer associated.
3976 */
3977 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3978 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003979
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003980 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003981 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003982 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003983 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003984 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003985
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003986 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003987
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003988 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003989 if (ap == NULL) {
3990 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003991 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003992 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003993
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003994 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
3995 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3996 } else {
3997 ap_legacy_rates =
3998 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3999 }
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004000 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004001
4002 rcu_read_unlock();
4003 }
4004
4005 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01004006 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004007 if (rc)
4008 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004009
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01004010 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004011 if (rc)
4012 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004013 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004014
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004015 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004016 rc = mwl8k_set_radio_preamble(hw,
4017 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004018 if (rc)
4019 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004020 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004021
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004022 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01004023 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004024 if (rc)
4025 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004026 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004027
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01004028 if (vif->bss_conf.assoc &&
4029 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
4030 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004031 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004032 if (rc)
4033 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004034 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004035
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01004036 if (vif->bss_conf.assoc &&
4037 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004038 /*
4039 * Finalize the join. Tell rx handler to process
4040 * next beacon from our BSSID.
4041 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01004042 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004043 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004044 }
4045
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02004046out:
4047 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004048}
4049
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004050static void
4051mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4052 struct ieee80211_bss_conf *info, u32 changed)
4053{
4054 int rc;
4055
4056 if (mwl8k_fw_lock(hw))
4057 return;
4058
4059 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4060 rc = mwl8k_set_radio_preamble(hw,
4061 vif->bss_conf.use_short_preamble);
4062 if (rc)
4063 goto out;
4064 }
4065
4066 if (changed & BSS_CHANGED_BASIC_RATES) {
4067 int idx;
4068 int rate;
4069
4070 /*
4071 * Use lowest supported basic rate for multicasts
4072 * and management frames (such as probe responses --
4073 * beacons will always go out at 1 Mb/s).
4074 */
4075 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01004076 if (idx)
4077 idx--;
4078
4079 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
4080 rate = mwl8k_rates_24[idx].hw_value;
4081 else
4082 rate = mwl8k_rates_50[idx].hw_value;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004083
4084 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
4085 }
4086
4087 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
4088 struct sk_buff *skb;
4089
4090 skb = ieee80211_beacon_get(hw, vif);
4091 if (skb != NULL) {
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01004092 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004093 kfree_skb(skb);
4094 }
4095 }
4096
4097 if (changed & BSS_CHANGED_BEACON_ENABLED)
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01004098 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004099
4100out:
4101 mwl8k_fw_unlock(hw);
4102}
4103
4104static void
4105mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4106 struct ieee80211_bss_conf *info, u32 changed)
4107{
4108 struct mwl8k_priv *priv = hw->priv;
4109
4110 if (!priv->ap_fw)
4111 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
4112 else
4113 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
4114}
4115
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004116static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad2010-04-01 21:22:57 +00004117 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004118{
4119 struct mwl8k_cmd_pkt *cmd;
4120
Lennert Buytenhek447ced02009-10-22 20:19:50 +02004121 /*
4122 * Synthesize and return a command packet that programs the
4123 * hardware multicast address filter. At this point we don't
4124 * know whether FIF_ALLMULTI is being requested, but if it is,
4125 * we'll end up throwing this packet away and creating a new
4126 * one in mwl8k_configure_filter().
4127 */
Jiri Pirko22bedad2010-04-01 21:22:57 +00004128 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02004129
4130 return (unsigned long)cmd;
4131}
4132
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004133static int
4134mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
4135 unsigned int changed_flags,
4136 unsigned int *total_flags)
4137{
4138 struct mwl8k_priv *priv = hw->priv;
4139
4140 /*
4141 * Hardware sniffer mode is mutually exclusive with STA
4142 * operation, so refuse to enable sniffer mode if a STA
4143 * interface is active.
4144 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004145 if (!list_empty(&priv->vif_list)) {
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004146 if (net_ratelimit())
Joe Perchesc96c31e2010-07-26 14:39:58 -07004147 wiphy_info(hw->wiphy,
4148 "not enabling sniffer mode because STA interface is active\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004149 return 0;
4150 }
4151
4152 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004153 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004154 return 0;
4155 priv->sniffer_enabled = true;
4156 }
4157
4158 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
4159 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
4160 FIF_OTHER_BSS;
4161
4162 return 1;
4163}
4164
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004165static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
4166{
4167 if (!list_empty(&priv->vif_list))
4168 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
4169
4170 return NULL;
4171}
4172
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004173static void mwl8k_configure_filter(struct ieee80211_hw *hw,
4174 unsigned int changed_flags,
4175 unsigned int *total_flags,
4176 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004177{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004178 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004179 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
4180
4181 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02004182 * AP firmware doesn't allow fine-grained control over
4183 * the receive filter.
4184 */
4185 if (priv->ap_fw) {
4186 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
4187 kfree(cmd);
4188 return;
4189 }
4190
4191 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004192 * Enable hardware sniffer mode if FIF_CONTROL or
4193 * FIF_OTHER_BSS is requested.
4194 */
4195 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
4196 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
4197 kfree(cmd);
4198 return;
4199 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004200
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004201 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02004202 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004203
Lennert Buytenhek90852f72010-01-02 10:31:42 +01004204 if (mwl8k_fw_lock(hw)) {
4205 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004206 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01004207 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004208
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004209 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004210 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02004211 priv->sniffer_enabled = false;
4212 }
4213
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004214 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02004215 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
4216 /*
4217 * Disable the BSS filter.
4218 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004219 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02004220 } else {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004221 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01004222 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02004223
Lennert Buytenhek77165d82009-10-22 20:19:53 +02004224 /*
4225 * Enable the BSS filter.
4226 *
4227 * If there is an active STA interface, use that
4228 * interface's BSSID, otherwise use a dummy one
4229 * (where the OUI part needs to be nonzero for
4230 * the BSSID to be accepted by POST_SCAN).
4231 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004232 mwl8k_vif = mwl8k_first_vif(priv);
4233 if (mwl8k_vif != NULL)
4234 bssid = mwl8k_vif->vif->bss_conf.bssid;
4235 else
4236 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02004237
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004238 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004239 }
4240 }
4241
Lennert Buytenhek447ced02009-10-22 20:19:50 +02004242 /*
4243 * If FIF_ALLMULTI is being requested, throw away the command
4244 * packet that ->prepare_multicast() built and replace it with
4245 * a command packet that enables reception of all multicast
4246 * packets.
4247 */
4248 if (*total_flags & FIF_ALLMULTI) {
4249 kfree(cmd);
Jiri Pirko22bedad2010-04-01 21:22:57 +00004250 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
Lennert Buytenhek447ced02009-10-22 20:19:50 +02004251 }
4252
4253 if (cmd != NULL) {
4254 mwl8k_post_cmd(hw, cmd);
4255 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004256 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02004257
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02004258 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004259}
4260
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004261static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4262{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01004263 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004264}
4265
Johannes Berg4a6967b2010-02-19 19:18:37 +01004266static int mwl8k_sta_remove(struct ieee80211_hw *hw,
4267 struct ieee80211_vif *vif,
4268 struct ieee80211_sta *sta)
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004269{
4270 struct mwl8k_priv *priv = hw->priv;
4271
Johannes Berg4a6967b2010-02-19 19:18:37 +01004272 if (priv->ap_fw)
4273 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
4274 else
4275 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
4276}
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004277
Johannes Berg4a6967b2010-02-19 19:18:37 +01004278static int mwl8k_sta_add(struct ieee80211_hw *hw,
4279 struct ieee80211_vif *vif,
4280 struct ieee80211_sta *sta)
4281{
4282 struct mwl8k_priv *priv = hw->priv;
4283 int ret;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004284 int i;
4285 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
4286 struct ieee80211_key_conf *key;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004287
Johannes Berg4a6967b2010-02-19 19:18:37 +01004288 if (!priv->ap_fw) {
4289 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
4290 if (ret >= 0) {
4291 MWL8K_STA(sta)->peer_id = ret;
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004292 ret = 0;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004293 }
Johannes Berg4a6967b2010-02-19 19:18:37 +01004294
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08004295 } else {
4296 ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004297 }
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01004298
Nishant Sarmukadamd9a07d42010-12-30 11:23:33 -08004299 for (i = 0; i < NUM_WEP_KEYS; i++) {
4300 key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
4301 if (mwl8k_vif->wep_key_conf[i].enabled)
4302 mwl8k_set_key(hw, SET_KEY, vif, sta, key);
4303 }
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004304 return ret;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01004305}
4306
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004307static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
4308 const struct ieee80211_tx_queue_params *params)
4309{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02004310 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004311 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004312
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02004313 rc = mwl8k_fw_lock(hw);
4314 if (!rc) {
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004315 BUG_ON(queue > MWL8K_TX_QUEUES - 1);
4316 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
4317
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02004318 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004319 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004320
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02004321 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004322 rc = mwl8k_cmd_set_edca_params(hw, queue,
4323 params->cw_min,
4324 params->cw_max,
4325 params->aifs,
4326 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02004327
4328 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004329 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02004330
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004331 return rc;
4332}
4333
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004334static int mwl8k_get_stats(struct ieee80211_hw *hw,
4335 struct ieee80211_low_level_stats *stats)
4336{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004337 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004338}
4339
John W. Linville0d462bb2010-07-28 14:04:24 -04004340static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
4341 struct survey_info *survey)
4342{
4343 struct mwl8k_priv *priv = hw->priv;
4344 struct ieee80211_conf *conf = &hw->conf;
4345
4346 if (idx != 0)
4347 return -ENOENT;
4348
4349 survey->channel = conf->channel;
4350 survey->filled = SURVEY_INFO_NOISE_DBM;
4351 survey->noise = priv->noise;
4352
4353 return 0;
4354}
4355
Lennert Buytenheka2292d82010-01-04 21:58:12 +01004356static int
4357mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4358 enum ieee80211_ampdu_mlme_action action,
Johannes Berg0b01f032011-01-18 13:51:05 +01004359 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4360 u8 buf_size)
Lennert Buytenheka2292d82010-01-04 21:58:12 +01004361{
4362 switch (action) {
4363 case IEEE80211_AMPDU_RX_START:
4364 case IEEE80211_AMPDU_RX_STOP:
4365 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
4366 return -ENOTSUPP;
4367 return 0;
4368 default:
4369 return -ENOTSUPP;
4370 }
4371}
4372
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004373static const struct ieee80211_ops mwl8k_ops = {
4374 .tx = mwl8k_tx,
4375 .start = mwl8k_start,
4376 .stop = mwl8k_stop,
4377 .add_interface = mwl8k_add_interface,
4378 .remove_interface = mwl8k_remove_interface,
4379 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004380 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02004381 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004382 .configure_filter = mwl8k_configure_filter,
Nishant Sarmukadamfcdc4032010-12-30 11:23:34 -08004383 .set_key = mwl8k_set_key,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004384 .set_rts_threshold = mwl8k_set_rts_threshold,
Johannes Berg4a6967b2010-02-19 19:18:37 +01004385 .sta_add = mwl8k_sta_add,
4386 .sta_remove = mwl8k_sta_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004387 .conf_tx = mwl8k_conf_tx,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004388 .get_stats = mwl8k_get_stats,
John W. Linville0d462bb2010-07-28 14:04:24 -04004389 .get_survey = mwl8k_get_survey,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01004390 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004391};
4392
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004393static void mwl8k_finalize_join_worker(struct work_struct *work)
4394{
4395 struct mwl8k_priv *priv =
4396 container_of(work, struct mwl8k_priv, finalize_join_worker);
4397 struct sk_buff *skb = priv->beacon_skb;
Johannes Berg56007a02010-01-26 14:19:52 +01004398 struct ieee80211_mgmt *mgmt = (void *)skb->data;
4399 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
4400 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
4401 mgmt->u.beacon.variable, len);
4402 int dtim_period = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004403
Johannes Berg56007a02010-01-26 14:19:52 +01004404 if (tim && tim[1] >= 2)
4405 dtim_period = tim[3];
4406
4407 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004408
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004409 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004410 priv->beacon_skb = NULL;
4411}
4412
John W. Linvillebcb628d2009-11-06 16:40:16 -05004413enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01004414 MWL8363 = 0,
4415 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05004416 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02004417};
4418
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08004419#define MWL8K_8366_AP_FW_API 1
4420#define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
4421#define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
4422
John W. Linvillebcb628d2009-11-06 16:40:16 -05004423static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01004424 [MWL8363] = {
4425 .part_name = "88w8363",
4426 .helper_image = "mwl8k/helper_8363.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004427 .fw_image_sta = "mwl8k/fmimage_8363.fw",
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01004428 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01004429 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05004430 .part_name = "88w8687",
4431 .helper_image = "mwl8k/helper_8687.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004432 .fw_image_sta = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05004433 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01004434 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05004435 .part_name = "88w8366",
4436 .helper_image = "mwl8k/helper_8366.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004437 .fw_image_sta = "mwl8k/fmimage_8366.fw",
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08004438 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
4439 .fw_api_ap = MWL8K_8366_AP_FW_API,
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01004440 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05004441 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004442};
4443
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01004444MODULE_FIRMWARE("mwl8k/helper_8363.fw");
4445MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
4446MODULE_FIRMWARE("mwl8k/helper_8687.fw");
4447MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
4448MODULE_FIRMWARE("mwl8k/helper_8366.fw");
4449MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08004450MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01004451
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004452static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Benjamin Larssone5868ba2010-03-19 01:46:10 +01004453 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01004454 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
4455 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05004456 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
4457 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
4458 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01004459 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05004460 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004461};
4462MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
4463
Brian Cavagnolo99020472010-11-12 17:23:52 -08004464static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
4465{
4466 int rc;
4467 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
4468 "Trying alternative firmware %s\n", pci_name(priv->pdev),
4469 priv->fw_pref, priv->fw_alt);
4470 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
4471 if (rc) {
4472 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
4473 pci_name(priv->pdev), priv->fw_alt);
4474 return rc;
4475 }
4476 return 0;
4477}
4478
4479static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
4480static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
4481{
4482 struct mwl8k_priv *priv = context;
4483 struct mwl8k_device_info *di = priv->device_info;
4484 int rc;
4485
4486 switch (priv->fw_state) {
4487 case FW_STATE_INIT:
4488 if (!fw) {
4489 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
4490 pci_name(priv->pdev), di->helper_image);
4491 goto fail;
4492 }
4493 priv->fw_helper = fw;
4494 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
4495 true);
4496 if (rc && priv->fw_alt) {
4497 rc = mwl8k_request_alt_fw(priv);
4498 if (rc)
4499 goto fail;
4500 priv->fw_state = FW_STATE_LOADING_ALT;
4501 } else if (rc)
4502 goto fail;
4503 else
4504 priv->fw_state = FW_STATE_LOADING_PREF;
4505 break;
4506
4507 case FW_STATE_LOADING_PREF:
4508 if (!fw) {
4509 if (priv->fw_alt) {
4510 rc = mwl8k_request_alt_fw(priv);
4511 if (rc)
4512 goto fail;
4513 priv->fw_state = FW_STATE_LOADING_ALT;
4514 } else
4515 goto fail;
4516 } else {
4517 priv->fw_ucode = fw;
4518 rc = mwl8k_firmware_load_success(priv);
4519 if (rc)
4520 goto fail;
4521 else
4522 complete(&priv->firmware_loading_complete);
4523 }
4524 break;
4525
4526 case FW_STATE_LOADING_ALT:
4527 if (!fw) {
4528 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
4529 pci_name(priv->pdev), di->helper_image);
4530 goto fail;
4531 }
4532 priv->fw_ucode = fw;
4533 rc = mwl8k_firmware_load_success(priv);
4534 if (rc)
4535 goto fail;
4536 else
4537 complete(&priv->firmware_loading_complete);
4538 break;
4539
4540 default:
4541 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
4542 MWL8K_NAME, priv->fw_state);
4543 BUG_ON(1);
4544 }
4545
4546 return;
4547
4548fail:
4549 priv->fw_state = FW_STATE_ERROR;
4550 complete(&priv->firmware_loading_complete);
4551 device_release_driver(&priv->pdev->dev);
4552 mwl8k_release_firmware(priv);
4553}
4554
4555static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
4556 bool nowait)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004557{
4558 struct mwl8k_priv *priv = hw->priv;
4559 int rc;
4560
4561 /* Reset firmware and hardware */
4562 mwl8k_hw_reset(priv);
4563
4564 /* Ask userland hotplug daemon for the device firmware */
Brian Cavagnolo99020472010-11-12 17:23:52 -08004565 rc = mwl8k_request_firmware(priv, fw_image, nowait);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004566 if (rc) {
4567 wiphy_err(hw->wiphy, "Firmware files not found\n");
4568 return rc;
4569 }
4570
Brian Cavagnolo99020472010-11-12 17:23:52 -08004571 if (nowait)
4572 return rc;
4573
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004574 /* Load firmware into hardware */
4575 rc = mwl8k_load_firmware(hw);
4576 if (rc)
4577 wiphy_err(hw->wiphy, "Cannot start firmware\n");
4578
4579 /* Reclaim memory once firmware is successfully loaded */
4580 mwl8k_release_firmware(priv);
4581
4582 return rc;
4583}
4584
4585/* initialize hw after successfully loading a firmware image */
4586static int mwl8k_probe_hw(struct ieee80211_hw *hw)
4587{
4588 struct mwl8k_priv *priv = hw->priv;
4589 int rc = 0;
4590 int i;
4591
4592 if (priv->ap_fw) {
4593 priv->rxd_ops = priv->device_info->ap_rxd_ops;
4594 if (priv->rxd_ops == NULL) {
4595 wiphy_err(hw->wiphy,
4596 "Driver does not have AP firmware image support for this hardware\n");
4597 goto err_stop_firmware;
4598 }
4599 } else {
4600 priv->rxd_ops = &rxd_sta_ops;
4601 }
4602
4603 priv->sniffer_enabled = false;
4604 priv->wmm_enabled = false;
4605 priv->pending_tx_pkts = 0;
4606
4607 rc = mwl8k_rxq_init(hw, 0);
4608 if (rc)
4609 goto err_stop_firmware;
4610 rxq_refill(hw, 0, INT_MAX);
4611
4612 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
4613 rc = mwl8k_txq_init(hw, i);
4614 if (rc)
4615 goto err_free_queues;
4616 }
4617
4618 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4619 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4620 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
4621 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
4622 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4623
4624 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
4625 IRQF_SHARED, MWL8K_NAME, hw);
4626 if (rc) {
4627 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
4628 goto err_free_queues;
4629 }
4630
4631 /*
4632 * Temporarily enable interrupts. Initial firmware host
4633 * commands use interrupts and avoid polling. Disable
4634 * interrupts when done.
4635 */
4636 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4637
4638 /* Get config data, mac addrs etc */
4639 if (priv->ap_fw) {
4640 rc = mwl8k_cmd_get_hw_spec_ap(hw);
4641 if (!rc)
4642 rc = mwl8k_cmd_set_hw_spec(hw);
4643 } else {
4644 rc = mwl8k_cmd_get_hw_spec_sta(hw);
4645 }
4646 if (rc) {
4647 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
4648 goto err_free_irq;
4649 }
4650
4651 /* Turn radio off */
4652 rc = mwl8k_cmd_radio_disable(hw);
4653 if (rc) {
4654 wiphy_err(hw->wiphy, "Cannot disable\n");
4655 goto err_free_irq;
4656 }
4657
4658 /* Clear MAC address */
4659 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
4660 if (rc) {
4661 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
4662 goto err_free_irq;
4663 }
4664
4665 /* Disable interrupts */
4666 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4667 free_irq(priv->pdev->irq, hw);
4668
4669 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
4670 priv->device_info->part_name,
4671 priv->hw_rev, hw->wiphy->perm_addr,
4672 priv->ap_fw ? "AP" : "STA",
4673 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4674 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
4675
4676 return 0;
4677
4678err_free_irq:
4679 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4680 free_irq(priv->pdev->irq, hw);
4681
4682err_free_queues:
4683 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4684 mwl8k_txq_deinit(hw, i);
4685 mwl8k_rxq_deinit(hw, 0);
4686
4687err_stop_firmware:
4688 mwl8k_hw_reset(priv);
4689
4690 return rc;
4691}
4692
4693/*
4694 * invoke mwl8k_reload_firmware to change the firmware image after the device
4695 * has already been registered
4696 */
4697static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
4698{
4699 int i, rc = 0;
4700 struct mwl8k_priv *priv = hw->priv;
4701
4702 mwl8k_stop(hw);
4703 mwl8k_rxq_deinit(hw, 0);
4704
4705 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4706 mwl8k_txq_deinit(hw, i);
4707
Brian Cavagnolo99020472010-11-12 17:23:52 -08004708 rc = mwl8k_init_firmware(hw, fw_image, false);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004709 if (rc)
4710 goto fail;
4711
4712 rc = mwl8k_probe_hw(hw);
4713 if (rc)
4714 goto fail;
4715
4716 rc = mwl8k_start(hw);
4717 if (rc)
4718 goto fail;
4719
4720 rc = mwl8k_config(hw, ~0);
4721 if (rc)
4722 goto fail;
4723
4724 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
4725 rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
4726 if (rc)
4727 goto fail;
4728 }
4729
4730 return rc;
4731
4732fail:
4733 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
4734 return rc;
4735}
4736
4737static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
4738{
4739 struct ieee80211_hw *hw = priv->hw;
4740 int i, rc;
4741
Brian Cavagnolo99020472010-11-12 17:23:52 -08004742 rc = mwl8k_load_firmware(hw);
4743 mwl8k_release_firmware(priv);
4744 if (rc) {
4745 wiphy_err(hw->wiphy, "Cannot start firmware\n");
4746 return rc;
4747 }
4748
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004749 /*
4750 * Extra headroom is the size of the required DMA header
4751 * minus the size of the smallest 802.11 frame (CTS frame).
4752 */
4753 hw->extra_tx_headroom =
4754 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
4755
4756 hw->channel_change_time = 10;
4757
4758 hw->queues = MWL8K_TX_QUEUES;
4759
4760 /* Set rssi values to dBm */
4761 hw->flags |= IEEE80211_HW_SIGNAL_DBM;
4762 hw->vif_data_size = sizeof(struct mwl8k_vif);
4763 hw->sta_data_size = sizeof(struct mwl8k_sta);
4764
4765 priv->macids_used = 0;
4766 INIT_LIST_HEAD(&priv->vif_list);
4767
4768 /* Set default radio state and preamble */
4769 priv->radio_on = 0;
4770 priv->radio_short_preamble = 0;
4771
4772 /* Finalize join worker */
4773 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
4774
4775 /* TX reclaim and RX tasklets. */
4776 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
4777 tasklet_disable(&priv->poll_tx_task);
4778 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
4779 tasklet_disable(&priv->poll_rx_task);
4780
4781 /* Power management cookie */
4782 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
4783 if (priv->cookie == NULL)
4784 return -ENOMEM;
4785
4786 mutex_init(&priv->fw_mutex);
4787 priv->fw_mutex_owner = NULL;
4788 priv->fw_mutex_depth = 0;
4789 priv->hostcmd_wait = NULL;
4790
4791 spin_lock_init(&priv->tx_lock);
4792
4793 priv->tx_wait = NULL;
4794
4795 rc = mwl8k_probe_hw(hw);
4796 if (rc)
4797 goto err_free_cookie;
4798
4799 hw->wiphy->interface_modes = 0;
4800 if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
4801 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
4802 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
4803 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
4804
4805 rc = ieee80211_register_hw(hw);
4806 if (rc) {
4807 wiphy_err(hw->wiphy, "Cannot register device\n");
4808 goto err_unprobe_hw;
4809 }
4810
4811 return 0;
4812
4813err_unprobe_hw:
4814 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4815 mwl8k_txq_deinit(hw, i);
4816 mwl8k_rxq_deinit(hw, 0);
4817
4818err_free_cookie:
4819 if (priv->cookie != NULL)
4820 pci_free_consistent(priv->pdev, 4,
4821 priv->cookie, priv->cookie_dma);
4822
4823 return rc;
4824}
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004825static int __devinit mwl8k_probe(struct pci_dev *pdev,
4826 const struct pci_device_id *id)
4827{
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004828 static int printed_version;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004829 struct ieee80211_hw *hw;
4830 struct mwl8k_priv *priv;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004831 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004832 int rc;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02004833
4834 if (!printed_version) {
4835 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
4836 printed_version = 1;
4837 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004838
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004839
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004840 rc = pci_enable_device(pdev);
4841 if (rc) {
4842 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
4843 MWL8K_NAME);
4844 return rc;
4845 }
4846
4847 rc = pci_request_regions(pdev, MWL8K_NAME);
4848 if (rc) {
4849 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
4850 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004851 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004852 }
4853
4854 pci_set_master(pdev);
4855
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004856
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004857 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
4858 if (hw == NULL) {
4859 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
4860 rc = -ENOMEM;
4861 goto err_free_reg;
4862 }
4863
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004864 SET_IEEE80211_DEV(hw, &pdev->dev);
4865 pci_set_drvdata(pdev, hw);
4866
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004867 priv = hw->priv;
4868 priv->hw = hw;
4869 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05004870 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004871
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004872
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004873 priv->sram = pci_iomap(pdev, 0, 0x10000);
4874 if (priv->sram == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07004875 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004876 goto err_iounmap;
4877 }
4878
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004879 /*
4880 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
4881 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
4882 */
4883 priv->regs = pci_iomap(pdev, 1, 0x10000);
4884 if (priv->regs == NULL) {
4885 priv->regs = pci_iomap(pdev, 2, 0x10000);
4886 if (priv->regs == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07004887 wiphy_err(hw->wiphy, "Cannot map device registers\n");
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004888 goto err_iounmap;
4889 }
4890 }
4891
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004892 /*
Brian Cavagnolo99020472010-11-12 17:23:52 -08004893 * Choose the initial fw image depending on user input. If a second
4894 * image is available, make it the alternative image that will be
4895 * loaded if the first one fails.
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004896 */
Brian Cavagnolo99020472010-11-12 17:23:52 -08004897 init_completion(&priv->firmware_loading_complete);
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004898 di = priv->device_info;
Brian Cavagnolo99020472010-11-12 17:23:52 -08004899 if (ap_mode_default && di->fw_image_ap) {
4900 priv->fw_pref = di->fw_image_ap;
4901 priv->fw_alt = di->fw_image_sta;
4902 } else if (!ap_mode_default && di->fw_image_sta) {
4903 priv->fw_pref = di->fw_image_sta;
4904 priv->fw_alt = di->fw_image_ap;
4905 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004906 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08004907 priv->fw_pref = di->fw_image_sta;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004908 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
4909 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08004910 priv->fw_pref = di->fw_image_ap;
4911 }
4912 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004913 if (rc)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004914 goto err_stop_firmware;
Brian Cavagnolo99020472010-11-12 17:23:52 -08004915 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004916
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004917err_stop_firmware:
4918 mwl8k_hw_reset(priv);
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004919
4920err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004921 if (priv->regs != NULL)
4922 pci_iounmap(pdev, priv->regs);
4923
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004924 if (priv->sram != NULL)
4925 pci_iounmap(pdev, priv->sram);
4926
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004927 pci_set_drvdata(pdev, NULL);
4928 ieee80211_free_hw(hw);
4929
4930err_free_reg:
4931 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004932
4933err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004934 pci_disable_device(pdev);
4935
4936 return rc;
4937}
4938
Joerg Albert230f7af2009-04-18 02:10:45 +02004939static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004940{
4941 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4942}
4943
Joerg Albert230f7af2009-04-18 02:10:45 +02004944static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004945{
4946 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4947 struct mwl8k_priv *priv;
4948 int i;
4949
4950 if (hw == NULL)
4951 return;
4952 priv = hw->priv;
4953
Brian Cavagnolo99020472010-11-12 17:23:52 -08004954 wait_for_completion(&priv->firmware_loading_complete);
4955
4956 if (priv->fw_state == FW_STATE_ERROR) {
4957 mwl8k_hw_reset(priv);
4958 goto unmap;
4959 }
4960
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004961 ieee80211_stop_queues(hw);
4962
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02004963 ieee80211_unregister_hw(hw);
4964
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004965 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004966 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004967 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004968
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004969 /* Stop hardware */
4970 mwl8k_hw_reset(priv);
4971
4972 /* Return all skbs to mac80211 */
4973 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004974 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004975
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004976 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4977 mwl8k_txq_deinit(hw, i);
4978
4979 mwl8k_rxq_deinit(hw, 0);
4980
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004981 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004982
Brian Cavagnolo99020472010-11-12 17:23:52 -08004983unmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004984 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004985 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004986 pci_set_drvdata(pdev, NULL);
4987 ieee80211_free_hw(hw);
4988 pci_release_regions(pdev);
4989 pci_disable_device(pdev);
4990}
4991
4992static struct pci_driver mwl8k_driver = {
4993 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004994 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004995 .probe = mwl8k_probe,
4996 .remove = __devexit_p(mwl8k_remove),
4997 .shutdown = __devexit_p(mwl8k_shutdown),
4998};
4999
5000static int __init mwl8k_init(void)
5001{
5002 return pci_register_driver(&mwl8k_driver);
5003}
5004
5005static void __exit mwl8k_exit(void)
5006{
5007 pci_unregister_driver(&mwl8k_driver);
5008}
5009
5010module_init(mwl8k_init);
5011module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02005012
5013MODULE_DESCRIPTION(MWL8K_DESC);
5014MODULE_VERSION(MWL8K_VERSION);
5015MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
5016MODULE_LICENSE("GPL");