blob: 1798b7e8283ffd667382330d03c7b30d6ec7b446 [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
235/* Per interface specific private data */
236struct mwl8k_vif {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100237 struct list_head list;
238 struct ieee80211_vif *vif;
239
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100240 /* Firmware macid for this vif. */
241 int macid;
242
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100243 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100244 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100245};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200246#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100247
Lennert Buytenheka6804002010-01-04 21:55:42 +0100248struct mwl8k_sta {
249 /* Index into station database. Returned by UPDATE_STADB. */
250 u8 peer_id;
251};
252#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
253
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100254static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100255 { .center_freq = 2412, .hw_value = 1, },
256 { .center_freq = 2417, .hw_value = 2, },
257 { .center_freq = 2422, .hw_value = 3, },
258 { .center_freq = 2427, .hw_value = 4, },
259 { .center_freq = 2432, .hw_value = 5, },
260 { .center_freq = 2437, .hw_value = 6, },
261 { .center_freq = 2442, .hw_value = 7, },
262 { .center_freq = 2447, .hw_value = 8, },
263 { .center_freq = 2452, .hw_value = 9, },
264 { .center_freq = 2457, .hw_value = 10, },
265 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100266 { .center_freq = 2467, .hw_value = 12, },
267 { .center_freq = 2472, .hw_value = 13, },
268 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100269};
270
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100271static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100272 { .bitrate = 10, .hw_value = 2, },
273 { .bitrate = 20, .hw_value = 4, },
274 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200275 { .bitrate = 110, .hw_value = 22, },
276 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100277 { .bitrate = 60, .hw_value = 12, },
278 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100279 { .bitrate = 120, .hw_value = 24, },
280 { .bitrate = 180, .hw_value = 36, },
281 { .bitrate = 240, .hw_value = 48, },
282 { .bitrate = 360, .hw_value = 72, },
283 { .bitrate = 480, .hw_value = 96, },
284 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100285 { .bitrate = 720, .hw_value = 144, },
286};
287
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100288static const struct ieee80211_channel mwl8k_channels_50[] = {
289 { .center_freq = 5180, .hw_value = 36, },
290 { .center_freq = 5200, .hw_value = 40, },
291 { .center_freq = 5220, .hw_value = 44, },
292 { .center_freq = 5240, .hw_value = 48, },
293};
294
295static const struct ieee80211_rate mwl8k_rates_50[] = {
296 { .bitrate = 60, .hw_value = 12, },
297 { .bitrate = 90, .hw_value = 18, },
298 { .bitrate = 120, .hw_value = 24, },
299 { .bitrate = 180, .hw_value = 36, },
300 { .bitrate = 240, .hw_value = 48, },
301 { .bitrate = 360, .hw_value = 72, },
302 { .bitrate = 480, .hw_value = 96, },
303 { .bitrate = 540, .hw_value = 108, },
304 { .bitrate = 720, .hw_value = 144, },
305};
306
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100307/* Set or get info from Firmware */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100308#define MWL8K_CMD_GET 0x0000
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800309#define MWL8K_CMD_SET 0x0001
310#define MWL8K_CMD_SET_LIST 0x0002
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100311
312/* Firmware command codes */
313#define MWL8K_CMD_CODE_DNLD 0x0001
314#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200315#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100316#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
317#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200318#define MWL8K_CMD_RADIO_CONTROL 0x001c
319#define MWL8K_CMD_RF_TX_POWER 0x001e
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800320#define MWL8K_CMD_TX_POWER 0x001f
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200321#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100322#define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100323#define MWL8K_CMD_SET_PRE_SCAN 0x0107
324#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200325#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100326#define MWL8K_CMD_SET_AID 0x010d
327#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200328#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100329#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200330#define MWL8K_CMD_SET_SLOT 0x0114
331#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
332#define MWL8K_CMD_SET_WMM_MODE 0x0123
333#define MWL8K_CMD_MIMO_CONFIG 0x0125
334#define MWL8K_CMD_USE_FIXED_RATE 0x0126
335#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100336#define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200337#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100338#define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
339#define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200340#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100341
John W. Linvilleb6037422010-07-20 13:55:00 -0400342static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100343{
John W. Linvilleb6037422010-07-20 13:55:00 -0400344 u16 command = le16_to_cpu(cmd);
345
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100346#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
347 snprintf(buf, bufsize, "%s", #x);\
348 return buf;\
349 } while (0)
John W. Linvilleb6037422010-07-20 13:55:00 -0400350 switch (command & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100351 MWL8K_CMDNAME(CODE_DNLD);
352 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200353 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100354 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
355 MWL8K_CMDNAME(GET_STAT);
356 MWL8K_CMDNAME(RADIO_CONTROL);
357 MWL8K_CMDNAME(RF_TX_POWER);
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -0800358 MWL8K_CMDNAME(TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200359 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100360 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100361 MWL8K_CMDNAME(SET_PRE_SCAN);
362 MWL8K_CMDNAME(SET_POST_SCAN);
363 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100364 MWL8K_CMDNAME(SET_AID);
365 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200366 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100367 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200368 MWL8K_CMDNAME(SET_SLOT);
369 MWL8K_CMDNAME(SET_EDCA_PARAMS);
370 MWL8K_CMDNAME(SET_WMM_MODE);
371 MWL8K_CMDNAME(MIMO_CONFIG);
372 MWL8K_CMDNAME(USE_FIXED_RATE);
373 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200374 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200375 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100376 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100377 MWL8K_CMDNAME(SET_NEW_STN);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200378 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100379 default:
380 snprintf(buf, bufsize, "0x%x", cmd);
381 }
382#undef MWL8K_CMDNAME
383
384 return buf;
385}
386
387/* Hardware and firmware reset */
388static void mwl8k_hw_reset(struct mwl8k_priv *priv)
389{
390 iowrite32(MWL8K_H2A_INT_RESET,
391 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
392 iowrite32(MWL8K_H2A_INT_RESET,
393 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
394 msleep(20);
395}
396
397/* Release fw image */
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800398static void mwl8k_release_fw(const struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100399{
400 if (*fw == NULL)
401 return;
402 release_firmware(*fw);
403 *fw = NULL;
404}
405
406static void mwl8k_release_firmware(struct mwl8k_priv *priv)
407{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100408 mwl8k_release_fw(&priv->fw_ucode);
409 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100410}
411
Brian Cavagnolo99020472010-11-12 17:23:52 -0800412/* states for asynchronous f/w loading */
413static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
414enum {
415 FW_STATE_INIT = 0,
416 FW_STATE_LOADING_PREF,
417 FW_STATE_LOADING_ALT,
418 FW_STATE_ERROR,
419};
420
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100421/* Request fw image */
422static int mwl8k_request_fw(struct mwl8k_priv *priv,
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800423 const char *fname, const struct firmware **fw,
Brian Cavagnolo99020472010-11-12 17:23:52 -0800424 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100425{
426 /* release current image */
427 if (*fw != NULL)
428 mwl8k_release_fw(fw);
429
Brian Cavagnolo99020472010-11-12 17:23:52 -0800430 if (nowait)
431 return request_firmware_nowait(THIS_MODULE, 1, fname,
432 &priv->pdev->dev, GFP_KERNEL,
433 priv, mwl8k_fw_state_machine);
434 else
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800435 return request_firmware(fw, fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100436}
437
Brian Cavagnolo99020472010-11-12 17:23:52 -0800438static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
439 bool nowait)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100440{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200441 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100442 int rc;
443
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200444 if (di->helper_image != NULL) {
Brian Cavagnolo99020472010-11-12 17:23:52 -0800445 if (nowait)
446 rc = mwl8k_request_fw(priv, di->helper_image,
447 &priv->fw_helper, true);
448 else
449 rc = mwl8k_request_fw(priv, di->helper_image,
450 &priv->fw_helper, false);
451 if (rc)
452 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
453 pci_name(priv->pdev), di->helper_image);
454
455 if (rc || nowait)
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200456 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100457 }
458
Brian Cavagnolo99020472010-11-12 17:23:52 -0800459 if (nowait) {
460 /*
461 * if we get here, no helper image is needed. Skip the
462 * FW_STATE_INIT state.
463 */
464 priv->fw_state = FW_STATE_LOADING_PREF;
465 rc = mwl8k_request_fw(priv, fw_image,
466 &priv->fw_ucode,
467 true);
468 } else
469 rc = mwl8k_request_fw(priv, fw_image,
470 &priv->fw_ucode, false);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100471 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200472 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -0800473 pci_name(priv->pdev), fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100474 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100475 return rc;
476 }
477
478 return 0;
479}
480
481struct mwl8k_cmd_pkt {
482 __le16 code;
483 __le16 length;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100484 __u8 seq_num;
485 __u8 macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100486 __le16 result;
487 char payload[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000488} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100489
490/*
491 * Firmware loading.
492 */
493static int
494mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
495{
496 void __iomem *regs = priv->regs;
497 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100498 int loops;
499
500 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
501 if (pci_dma_mapping_error(priv->pdev, dma_addr))
502 return -ENOMEM;
503
504 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
505 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
506 iowrite32(MWL8K_H2A_INT_DOORBELL,
507 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
508 iowrite32(MWL8K_H2A_INT_DUMMY,
509 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
510
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100511 loops = 1000;
512 do {
513 u32 int_code;
514
515 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
516 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
517 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100518 break;
519 }
520
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200521 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100522 udelay(1);
523 } while (--loops);
524
525 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
526
Lennert Buytenhekd4b705702009-07-16 12:44:45 +0200527 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100528}
529
530static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
531 const u8 *data, size_t length)
532{
533 struct mwl8k_cmd_pkt *cmd;
534 int done;
535 int rc = 0;
536
537 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
538 if (cmd == NULL)
539 return -ENOMEM;
540
541 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
542 cmd->seq_num = 0;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100543 cmd->macid = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100544 cmd->result = 0;
545
546 done = 0;
547 while (length) {
548 int block_size = length > 256 ? 256 : length;
549
550 memcpy(cmd->payload, data + done, block_size);
551 cmd->length = cpu_to_le16(block_size);
552
553 rc = mwl8k_send_fw_load_cmd(priv, cmd,
554 sizeof(*cmd) + block_size);
555 if (rc)
556 break;
557
558 done += block_size;
559 length -= block_size;
560 }
561
562 if (!rc) {
563 cmd->length = 0;
564 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
565 }
566
567 kfree(cmd);
568
569 return rc;
570}
571
572static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
573 const u8 *data, size_t length)
574{
575 unsigned char *buffer;
576 int may_continue, rc = 0;
577 u32 done, prev_block_size;
578
579 buffer = kmalloc(1024, GFP_KERNEL);
580 if (buffer == NULL)
581 return -ENOMEM;
582
583 done = 0;
584 prev_block_size = 0;
585 may_continue = 1000;
586 while (may_continue > 0) {
587 u32 block_size;
588
589 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
590 if (block_size & 1) {
591 block_size &= ~1;
592 may_continue--;
593 } else {
594 done += prev_block_size;
595 length -= prev_block_size;
596 }
597
598 if (block_size > 1024 || block_size > length) {
599 rc = -EOVERFLOW;
600 break;
601 }
602
603 if (length == 0) {
604 rc = 0;
605 break;
606 }
607
608 if (block_size == 0) {
609 rc = -EPROTO;
610 may_continue--;
611 udelay(1);
612 continue;
613 }
614
615 prev_block_size = block_size;
616 memcpy(buffer, data + done, block_size);
617
618 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
619 if (rc)
620 break;
621 }
622
623 if (!rc && length != 0)
624 rc = -EREMOTEIO;
625
626 kfree(buffer);
627
628 return rc;
629}
630
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200631static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100632{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200633 struct mwl8k_priv *priv = hw->priv;
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800634 const struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200635 int rc;
636 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100637
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200638 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Brian Cavagnolod1f9e412010-11-12 17:23:53 -0800639 const struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100640
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200641 if (helper == NULL) {
642 printk(KERN_ERR "%s: helper image needed but none "
643 "given\n", pci_name(priv->pdev));
644 return -EINVAL;
645 }
646
647 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100648 if (rc) {
649 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200650 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100651 return rc;
652 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100653 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100654
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200655 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100656 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200657 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100658 }
659
660 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200661 printk(KERN_ERR "%s: unable to load firmware image\n",
662 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100663 return rc;
664 }
665
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100666 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100667
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100668 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100669 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200670 u32 ready_code;
671
672 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
673 if (ready_code == MWL8K_FWAP_READY) {
674 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100675 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200676 } else if (ready_code == MWL8K_FWSTA_READY) {
677 priv->ap_fw = 0;
678 break;
679 }
680
681 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100682 udelay(1);
683 } while (--loops);
684
685 return loops ? 0 : -ETIMEDOUT;
686}
687
688
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100689/* DMA header used by firmware and hardware. */
690struct mwl8k_dma_data {
691 __le16 fwlen;
692 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100693 char data[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000694} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100695
696/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100697static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100698{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100699 struct mwl8k_dma_data *tr;
700 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100701
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100702 tr = (struct mwl8k_dma_data *)skb->data;
703 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
704
705 if (hdrlen != sizeof(tr->wh)) {
706 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
707 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
708 *((__le16 *)(tr->data - 2)) = qos;
709 } else {
710 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
711 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100712 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100713
714 if (hdrlen != sizeof(*tr))
715 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100716}
717
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800718static void
719mwl8k_add_dma_header(struct sk_buff *skb, int tail_pad)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100720{
721 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100722 int hdrlen;
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800723 int reqd_hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100724 struct mwl8k_dma_data *tr;
725
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100726 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100727 * Add a firmware DMA header; the firmware requires that we
728 * present a 2-byte payload length followed by a 4-address
729 * header (without QoS field), followed (optionally) by any
730 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100731 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100732 wh = (struct ieee80211_hdr *)skb->data;
733
734 hdrlen = ieee80211_hdrlen(wh->frame_control);
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800735 reqd_hdrlen = sizeof(*tr);
736
737 if (hdrlen != reqd_hdrlen)
738 skb_push(skb, reqd_hdrlen - hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100739
740 if (ieee80211_is_data_qos(wh->frame_control))
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800741 hdrlen -= IEEE80211_QOS_CTL_LEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100742
743 tr = (struct mwl8k_dma_data *)skb->data;
744 if (wh != &tr->wh)
745 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100746 if (hdrlen != sizeof(tr->wh))
747 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100748
749 /*
750 * Firmware length is the length of the fully formed "802.11
751 * payload". That is, everything except for the 802.11 header.
752 * This includes all crypto material including the MIC.
753 */
Nishant Sarmukadam252486a2010-12-30 11:23:31 -0800754 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100755}
756
757
758/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100759 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200760 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100761struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200762 __le16 pkt_len;
763 __u8 sq2;
764 __u8 rate;
765 __le32 pkt_phys_addr;
766 __le32 next_rxd_phys_addr;
767 __le16 qos_control;
768 __le16 htsig2;
769 __le32 hw_rssi_info;
770 __le32 hw_noise_floor_info;
771 __u8 noise_floor;
772 __u8 pad0[3];
773 __u8 rssi;
774 __u8 rx_status;
775 __u8 channel;
776 __u8 rx_ctrl;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000777} __packed;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200778
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100779#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
780#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
781#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100782
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100783#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200784
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100785static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200786{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100787 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200788
789 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100790 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200791}
792
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100793static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200794{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100795 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200796
797 rxd->pkt_len = cpu_to_le16(len);
798 rxd->pkt_phys_addr = cpu_to_le32(addr);
799 wmb();
800 rxd->rx_ctrl = 0;
801}
802
803static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100804mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -0400805 __le16 *qos, s8 *noise)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200806{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100807 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200808
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100809 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200810 return -1;
811 rmb();
812
813 memset(status, 0, sizeof(*status));
814
815 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -0400816 *noise = -rxd->noise_floor;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200817
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100818 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200819 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100820 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100821 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100822 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200823 } else {
824 int i;
825
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100826 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
827 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200828 status->rate_idx = i;
829 break;
830 }
831 }
832 }
833
Lennert Buytenhek85478342010-01-12 13:48:56 +0100834 if (rxd->channel > 14) {
835 status->band = IEEE80211_BAND_5GHZ;
836 if (!(status->flag & RX_FLAG_HT))
837 status->rate_idx -= 5;
838 } else {
839 status->band = IEEE80211_BAND_2GHZ;
840 }
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200841 status->freq = ieee80211_channel_to_frequency(rxd->channel);
842
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100843 *qos = rxd->qos_control;
844
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200845 return le16_to_cpu(rxd->pkt_len);
846}
847
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100848static struct rxd_ops rxd_8366_ap_ops = {
849 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
850 .rxd_init = mwl8k_rxd_8366_ap_init,
851 .rxd_refill = mwl8k_rxd_8366_ap_refill,
852 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200853};
854
855/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100856 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100857 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100858struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100859 __le16 pkt_len;
860 __u8 link_quality;
861 __u8 noise_level;
862 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200863 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100864 __le16 qos_control;
865 __le16 rate_info;
866 __le32 pad0[4];
867 __u8 rssi;
868 __u8 channel;
869 __le16 pad1;
870 __u8 rx_ctrl;
871 __u8 rx_status;
872 __u8 pad2[2];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000873} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100874
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100875#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
876#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
877#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
878#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
879#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
880#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200881
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100882#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200883
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100884static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200885{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100886 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200887
888 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100889 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200890}
891
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100892static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200893{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100894 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200895
896 rxd->pkt_len = cpu_to_le16(len);
897 rxd->pkt_phys_addr = cpu_to_le32(addr);
898 wmb();
899 rxd->rx_ctrl = 0;
900}
901
902static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100903mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
John W. Linville0d462bb2010-07-28 14:04:24 -0400904 __le16 *qos, s8 *noise)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200905{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100906 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200907 u16 rate_info;
908
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100909 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200910 return -1;
911 rmb();
912
913 rate_info = le16_to_cpu(rxd->rate_info);
914
915 memset(status, 0, sizeof(*status));
916
917 status->signal = -rxd->rssi;
John W. Linville0d462bb2010-07-28 14:04:24 -0400918 *noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100919 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
920 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200921
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100922 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200923 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100924 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200925 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100926 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200927 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100928 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200929 status->flag |= RX_FLAG_HT;
930
Lennert Buytenhek85478342010-01-12 13:48:56 +0100931 if (rxd->channel > 14) {
932 status->band = IEEE80211_BAND_5GHZ;
933 if (!(status->flag & RX_FLAG_HT))
934 status->rate_idx -= 5;
935 } else {
936 status->band = IEEE80211_BAND_2GHZ;
937 }
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200938 status->freq = ieee80211_channel_to_frequency(rxd->channel);
939
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100940 *qos = rxd->qos_control;
941
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200942 return le16_to_cpu(rxd->pkt_len);
943}
944
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100945static struct rxd_ops rxd_sta_ops = {
946 .rxd_size = sizeof(struct mwl8k_rxd_sta),
947 .rxd_init = mwl8k_rxd_sta_init,
948 .rxd_refill = mwl8k_rxd_sta_refill,
949 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200950};
951
952
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100953#define MWL8K_RX_DESCS 256
954#define MWL8K_RX_MAXSZ 3800
955
956static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
957{
958 struct mwl8k_priv *priv = hw->priv;
959 struct mwl8k_rx_queue *rxq = priv->rxq + index;
960 int size;
961 int i;
962
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200963 rxq->rxd_count = 0;
964 rxq->head = 0;
965 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100966
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200967 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100968
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200969 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
970 if (rxq->rxd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -0700971 wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100972 return -ENOMEM;
973 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200974 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100975
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200976 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
977 if (rxq->buf == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -0700978 wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200979 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100980 return -ENOMEM;
981 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200982 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100983
984 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200985 int desc_size;
986 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100987 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200988 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100989
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200990 desc_size = priv->rxd_ops->rxd_size;
991 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100992
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200993 nexti = i + 1;
994 if (nexti == MWL8K_RX_DESCS)
995 nexti = 0;
996 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
997
998 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100999 }
1000
1001 return 0;
1002}
1003
1004static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1005{
1006 struct mwl8k_priv *priv = hw->priv;
1007 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1008 int refilled;
1009
1010 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001011 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001012 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001013 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001014 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001015 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001016
1017 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1018 if (skb == NULL)
1019 break;
1020
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001021 addr = pci_map_single(priv->pdev, skb->data,
1022 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001023
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001024 rxq->rxd_count++;
1025 rx = rxq->tail++;
1026 if (rxq->tail == MWL8K_RX_DESCS)
1027 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001028 rxq->buf[rx].skb = skb;
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001029 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001030
1031 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1032 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001033
1034 refilled++;
1035 }
1036
1037 return refilled;
1038}
1039
1040/* Must be called only when the card's reception is completely halted */
1041static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1042{
1043 struct mwl8k_priv *priv = hw->priv;
1044 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1045 int i;
1046
1047 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001048 if (rxq->buf[i].skb != NULL) {
1049 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001050 dma_unmap_addr(&rxq->buf[i], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001051 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001052 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001053
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001054 kfree_skb(rxq->buf[i].skb);
1055 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001056 }
1057 }
1058
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001059 kfree(rxq->buf);
1060 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001061
1062 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001063 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001064 rxq->rxd, rxq->rxd_dma);
1065 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001066}
1067
1068
1069/*
1070 * Scan a list of BSSIDs to process for finalize join.
1071 * Allows for extension to process multiple BSSIDs.
1072 */
1073static inline int
1074mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1075{
1076 return priv->capture_beacon &&
1077 ieee80211_is_beacon(wh->frame_control) &&
1078 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1079}
1080
Lennert Buytenhek37797522009-10-22 20:19:45 +02001081static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1082 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001083{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001084 struct mwl8k_priv *priv = hw->priv;
1085
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001086 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001087 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001088
1089 /*
1090 * Use GFP_ATOMIC as rxq_process is called from
1091 * the primary interrupt handler, memory allocation call
1092 * must not sleep.
1093 */
1094 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1095 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001096 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001097}
1098
1099static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1100{
1101 struct mwl8k_priv *priv = hw->priv;
1102 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1103 int processed;
1104
1105 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001106 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001107 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001108 void *rxd;
1109 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001110 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001111 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001112
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001113 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001114 if (skb == NULL)
1115 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001116
1117 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1118
John W. Linville0d462bb2010-07-28 14:04:24 -04001119 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
1120 &priv->noise);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001121 if (pkt_len < 0)
1122 break;
1123
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001124 rxq->buf[rxq->head].skb = NULL;
1125
1126 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001127 dma_unmap_addr(&rxq->buf[rxq->head], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001128 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001129 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001130
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001131 rxq->head++;
1132 if (rxq->head == MWL8K_RX_DESCS)
1133 rxq->head = 0;
1134
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001135 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001136
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001137 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001138 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001139
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001140 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001141 * Check for a pending join operation. Save a
1142 * copy of the beacon and schedule a tasklet to
1143 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001144 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001145 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001146 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001147
Johannes Bergf1d58c22009-06-17 13:13:00 +02001148 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1149 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001150
1151 processed++;
1152 }
1153
1154 return processed;
1155}
1156
1157
1158/*
1159 * Packet transmission.
1160 */
1161
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001162#define MWL8K_TXD_STATUS_OK 0x00000001
1163#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1164#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1165#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001166#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001167
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001168#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1169#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1170#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1171#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1172#define MWL8K_QOS_EOSP 0x0010
1173
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001174struct mwl8k_tx_desc {
1175 __le32 status;
1176 __u8 data_rate;
1177 __u8 tx_priority;
1178 __le16 qos_control;
1179 __le32 pkt_phys_addr;
1180 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001181 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001182 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001183 __le32 reserved;
1184 __le16 rate_info;
1185 __u8 peer_id;
Brian Cavagnoloa1fe24b2010-11-12 17:23:47 -08001186 __u8 tx_frag_cnt;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001187} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001188
1189#define MWL8K_TX_DESCS 128
1190
1191static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1192{
1193 struct mwl8k_priv *priv = hw->priv;
1194 struct mwl8k_tx_queue *txq = priv->txq + index;
1195 int size;
1196 int i;
1197
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001198 txq->len = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001199 txq->head = 0;
1200 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001201
1202 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1203
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001204 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1205 if (txq->txd == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001206 wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001207 return -ENOMEM;
1208 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001209 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001210
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001211 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1212 if (txq->skb == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07001213 wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001214 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001215 return -ENOMEM;
1216 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001217 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001218
1219 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1220 struct mwl8k_tx_desc *tx_desc;
1221 int nexti;
1222
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001223 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001224 nexti = (i + 1) % MWL8K_TX_DESCS;
1225
1226 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001227 tx_desc->next_txd_phys_addr =
1228 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001229 }
1230
1231 return 0;
1232}
1233
1234static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1235{
1236 iowrite32(MWL8K_H2A_INT_PPA_READY,
1237 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1238 iowrite32(MWL8K_H2A_INT_DUMMY,
1239 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1240 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1241}
1242
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001243static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001244{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001245 struct mwl8k_priv *priv = hw->priv;
1246 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001247
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001248 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1249 struct mwl8k_tx_queue *txq = priv->txq + i;
1250 int fw_owned = 0;
1251 int drv_owned = 0;
1252 int unused = 0;
1253 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001254
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001255 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001256 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1257 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001258
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001259 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001260 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001261 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001262 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001263 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001264
1265 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001266 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001267 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001268
Joe Perchesc96c31e2010-07-26 14:39:58 -07001269 wiphy_err(hw->wiphy,
1270 "txq[%d] len=%d head=%d tail=%d "
1271 "fw_owned=%d drv_owned=%d unused=%d\n",
1272 i,
1273 txq->len, txq->head, txq->tail,
1274 fw_owned, drv_owned, unused);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001275 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001276}
1277
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001278/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001279 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001280 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001281#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001282
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001283static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001284{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001285 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001286 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001287 int retry;
1288 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001289
1290 might_sleep();
1291
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001292 /*
1293 * The TX queues are stopped at this point, so this test
1294 * doesn't need to take ->tx_lock.
1295 */
1296 if (!priv->pending_tx_pkts)
1297 return 0;
1298
1299 retry = 0;
1300 rc = 0;
1301
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001302 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001303 priv->tx_wait = &tx_wait;
1304 while (!rc) {
1305 int oldcount;
1306 unsigned long timeout;
1307
1308 oldcount = priv->pending_tx_pkts;
1309
1310 spin_unlock_bh(&priv->tx_lock);
1311 timeout = wait_for_completion_timeout(&tx_wait,
1312 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1313 spin_lock_bh(&priv->tx_lock);
1314
1315 if (timeout) {
1316 WARN_ON(priv->pending_tx_pkts);
1317 if (retry) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001318 wiphy_notice(hw->wiphy, "tx rings drained\n");
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001319 }
1320 break;
1321 }
1322
1323 if (priv->pending_tx_pkts < oldcount) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001324 wiphy_notice(hw->wiphy,
1325 "waiting for tx rings to drain (%d -> %d pkts)\n",
1326 oldcount, priv->pending_tx_pkts);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001327 retry = 1;
1328 continue;
1329 }
1330
1331 priv->tx_wait = NULL;
1332
Joe Perchesc96c31e2010-07-26 14:39:58 -07001333 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1334 MWL8K_TX_WAIT_TIMEOUT_MS);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001335 mwl8k_dump_tx_rings(hw);
1336
1337 rc = -ETIMEDOUT;
1338 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001339 spin_unlock_bh(&priv->tx_lock);
1340
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001341 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001342}
1343
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001344#define MWL8K_TXD_SUCCESS(status) \
1345 ((status) & (MWL8K_TXD_STATUS_OK | \
1346 MWL8K_TXD_STATUS_OK_RETRY | \
1347 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001348
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001349static int
1350mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001351{
1352 struct mwl8k_priv *priv = hw->priv;
1353 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001354 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001355
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001356 processed = 0;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001357 while (txq->len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001358 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001359 struct mwl8k_tx_desc *tx_desc;
1360 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001361 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001362 struct sk_buff *skb;
1363 struct ieee80211_tx_info *info;
1364 u32 status;
1365
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001366 tx = txq->head;
1367 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001368
1369 status = le32_to_cpu(tx_desc->status);
1370
1371 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1372 if (!force)
1373 break;
1374 tx_desc->status &=
1375 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1376 }
1377
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001378 txq->head = (tx + 1) % MWL8K_TX_DESCS;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001379 BUG_ON(txq->len == 0);
1380 txq->len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001381 priv->pending_tx_pkts--;
1382
1383 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001384 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001385 skb = txq->skb[tx];
1386 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001387
1388 BUG_ON(skb == NULL);
1389 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1390
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001391 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001392
1393 /* Mark descriptor as unused */
1394 tx_desc->pkt_phys_addr = 0;
1395 tx_desc->pkt_len = 0;
1396
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001397 info = IEEE80211_SKB_CB(skb);
1398 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001399 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001400 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001401
1402 ieee80211_tx_status_irqsafe(hw, skb);
1403
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001404 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001405 }
1406
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001407 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001408 ieee80211_wake_queue(hw, index);
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001409
1410 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001411}
1412
1413/* must be called only when the card's transmit is completely halted */
1414static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1415{
1416 struct mwl8k_priv *priv = hw->priv;
1417 struct mwl8k_tx_queue *txq = priv->txq + index;
1418
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001419 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001420
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001421 kfree(txq->skb);
1422 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001423
1424 pci_free_consistent(priv->pdev,
1425 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001426 txq->txd, txq->txd_dma);
1427 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001428}
1429
1430static int
1431mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1432{
1433 struct mwl8k_priv *priv = hw->priv;
1434 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001435 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001436 struct ieee80211_hdr *wh;
1437 struct mwl8k_tx_queue *txq;
1438 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001439 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001440 u32 txstatus;
1441 u8 txdatarate;
1442 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001443
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001444 wh = (struct ieee80211_hdr *)skb->data;
1445 if (ieee80211_is_data_qos(wh->frame_control))
1446 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1447 else
1448 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001449
Nishant Sarmukadam252486a2010-12-30 11:23:31 -08001450 mwl8k_add_dma_header(skb, 0);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001451 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001452
1453 tx_info = IEEE80211_SKB_CB(skb);
1454 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001455
1456 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001457 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001458 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1459 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001460 }
1461
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001462 /* Setup firmware control bit fields for each frame type. */
1463 txstatus = 0;
1464 txdatarate = 0;
1465 if (ieee80211_is_mgmt(wh->frame_control) ||
1466 ieee80211_is_ctl(wh->frame_control)) {
1467 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001468 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001469 } else if (ieee80211_is_data(wh->frame_control)) {
1470 txdatarate = 1;
1471 if (is_multicast_ether_addr(wh->addr1))
1472 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1473
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001474 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001475 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001476 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001477 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001478 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001479 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001480
1481 dma = pci_map_single(priv->pdev, skb->data,
1482 skb->len, PCI_DMA_TODEVICE);
1483
1484 if (pci_dma_mapping_error(priv->pdev, dma)) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001485 wiphy_debug(hw->wiphy,
1486 "failed to dma map skb, dropping TX frame.\n");
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001487 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001488 return NETDEV_TX_OK;
1489 }
1490
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001491 spin_lock_bh(&priv->tx_lock);
1492
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001493 txq = priv->txq + index;
1494
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001495 BUG_ON(txq->skb[txq->tail] != NULL);
1496 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001497
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001498 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001499 tx->data_rate = txdatarate;
1500 tx->tx_priority = index;
1501 tx->qos_control = cpu_to_le16(qos);
1502 tx->pkt_phys_addr = cpu_to_le32(dma);
1503 tx->pkt_len = cpu_to_le16(skb->len);
1504 tx->rate_info = 0;
Lennert Buytenheka6804002010-01-04 21:55:42 +01001505 if (!priv->ap_fw && tx_info->control.sta != NULL)
1506 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1507 else
1508 tx->peer_id = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001509 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001510 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1511
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001512 txq->len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001513 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001514
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001515 txq->tail++;
1516 if (txq->tail == MWL8K_TX_DESCS)
1517 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001518
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001519 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001520 ieee80211_stop_queue(hw, index);
1521
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001522 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001523
1524 spin_unlock_bh(&priv->tx_lock);
1525
1526 return NETDEV_TX_OK;
1527}
1528
1529
1530/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001531 * Firmware access.
1532 *
1533 * We have the following requirements for issuing firmware commands:
1534 * - Some commands require that the packet transmit path is idle when
1535 * the command is issued. (For simplicity, we'll just quiesce the
1536 * transmit path for every command.)
1537 * - There are certain sequences of commands that need to be issued to
1538 * the hardware sequentially, with no other intervening commands.
1539 *
1540 * This leads to an implementation of a "firmware lock" as a mutex that
1541 * can be taken recursively, and which is taken by both the low-level
1542 * command submission function (mwl8k_post_cmd) as well as any users of
1543 * that function that require issuing of an atomic sequence of commands,
1544 * and quiesces the transmit path whenever it's taken.
1545 */
1546static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1547{
1548 struct mwl8k_priv *priv = hw->priv;
1549
1550 if (priv->fw_mutex_owner != current) {
1551 int rc;
1552
1553 mutex_lock(&priv->fw_mutex);
1554 ieee80211_stop_queues(hw);
1555
1556 rc = mwl8k_tx_wait_empty(hw);
1557 if (rc) {
1558 ieee80211_wake_queues(hw);
1559 mutex_unlock(&priv->fw_mutex);
1560
1561 return rc;
1562 }
1563
1564 priv->fw_mutex_owner = current;
1565 }
1566
1567 priv->fw_mutex_depth++;
1568
1569 return 0;
1570}
1571
1572static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1573{
1574 struct mwl8k_priv *priv = hw->priv;
1575
1576 if (!--priv->fw_mutex_depth) {
1577 ieee80211_wake_queues(hw);
1578 priv->fw_mutex_owner = NULL;
1579 mutex_unlock(&priv->fw_mutex);
1580 }
1581}
1582
1583
1584/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001585 * Command processing.
1586 */
1587
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001588/* Timeout firmware commands after 10s */
1589#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001590
1591static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1592{
1593 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1594 struct mwl8k_priv *priv = hw->priv;
1595 void __iomem *regs = priv->regs;
1596 dma_addr_t dma_addr;
1597 unsigned int dma_size;
1598 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001599 unsigned long timeout = 0;
1600 u8 buf[32];
1601
John W. Linvilleb6037422010-07-20 13:55:00 -04001602 cmd->result = (__force __le16) 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001603 dma_size = le16_to_cpu(cmd->length);
1604 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1605 PCI_DMA_BIDIRECTIONAL);
1606 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1607 return -ENOMEM;
1608
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001609 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001610 if (rc) {
1611 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1612 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001613 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001614 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001615
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001616 priv->hostcmd_wait = &cmd_wait;
1617 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1618 iowrite32(MWL8K_H2A_INT_DOORBELL,
1619 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1620 iowrite32(MWL8K_H2A_INT_DUMMY,
1621 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001622
1623 timeout = wait_for_completion_timeout(&cmd_wait,
1624 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1625
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001626 priv->hostcmd_wait = NULL;
1627
1628 mwl8k_fw_unlock(hw);
1629
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001630 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1631 PCI_DMA_BIDIRECTIONAL);
1632
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001633 if (!timeout) {
Joe Perches5db55842010-08-11 19:11:19 -07001634 wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07001635 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1636 MWL8K_CMD_TIMEOUT_MS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001637 rc = -ETIMEDOUT;
1638 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001639 int ms;
1640
1641 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1642
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001643 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001644 if (rc)
Joe Perches5db55842010-08-11 19:11:19 -07001645 wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07001646 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1647 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001648 else if (ms > 2000)
Joe Perches5db55842010-08-11 19:11:19 -07001649 wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
Joe Perchesc96c31e2010-07-26 14:39:58 -07001650 mwl8k_cmd_name(cmd->code,
1651 buf, sizeof(buf)),
1652 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001653 }
1654
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001655 return rc;
1656}
1657
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +01001658static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
1659 struct ieee80211_vif *vif,
1660 struct mwl8k_cmd_pkt *cmd)
1661{
1662 if (vif != NULL)
1663 cmd->macid = MWL8K_VIF(vif)->macid;
1664 return mwl8k_post_cmd(hw, cmd);
1665}
1666
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001667/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001668 * Setup code shared between STA and AP firmware images.
1669 */
1670static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1671{
1672 struct mwl8k_priv *priv = hw->priv;
1673
1674 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1675 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1676
1677 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1678 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1679
1680 priv->band_24.band = IEEE80211_BAND_2GHZ;
1681 priv->band_24.channels = priv->channels_24;
1682 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1683 priv->band_24.bitrates = priv->rates_24;
1684 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1685
1686 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1687}
1688
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01001689static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
1690{
1691 struct mwl8k_priv *priv = hw->priv;
1692
1693 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
1694 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
1695
1696 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
1697 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
1698
1699 priv->band_50.band = IEEE80211_BAND_5GHZ;
1700 priv->band_50.channels = priv->channels_50;
1701 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
1702 priv->band_50.bitrates = priv->rates_50;
1703 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
1704
1705 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
1706}
1707
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001708/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001709 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001710 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001711struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001712 struct mwl8k_cmd_pkt header;
1713 __u8 hw_rev;
1714 __u8 host_interface;
1715 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001716 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001717 __le16 region_code;
1718 __le32 fw_rev;
1719 __le32 ps_cookie;
1720 __le32 caps;
1721 __u8 mcs_bitmap[16];
1722 __le32 rx_queue_ptr;
1723 __le32 num_tx_queues;
1724 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1725 __le32 caps2;
1726 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001727 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001728} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001729
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001730#define MWL8K_CAP_MAX_AMSDU 0x20000000
1731#define MWL8K_CAP_GREENFIELD 0x08000000
1732#define MWL8K_CAP_AMPDU 0x04000000
1733#define MWL8K_CAP_RX_STBC 0x01000000
1734#define MWL8K_CAP_TX_STBC 0x00800000
1735#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1736#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1737#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1738#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1739#define MWL8K_CAP_DELAY_BA 0x00003000
1740#define MWL8K_CAP_MIMO 0x00000200
1741#define MWL8K_CAP_40MHZ 0x00000100
Lennert Buytenhek06953232010-01-12 13:49:41 +01001742#define MWL8K_CAP_BAND_MASK 0x00000007
1743#define MWL8K_CAP_5GHZ 0x00000004
1744#define MWL8K_CAP_2GHZ4 0x00000001
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001745
Lennert Buytenhek06953232010-01-12 13:49:41 +01001746static void
1747mwl8k_set_ht_caps(struct ieee80211_hw *hw,
1748 struct ieee80211_supported_band *band, u32 cap)
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001749{
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001750 int rx_streams;
1751 int tx_streams;
1752
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001753 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001754
1755 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001756 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001757 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001758 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001759 if (cap & MWL8K_CAP_AMPDU) {
1760 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001761 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1762 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001763 }
1764 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001765 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001766 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001767 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001768 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001769 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001770 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001771 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001772 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001773 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001774 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001775 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001776
1777 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1778 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1779
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001780 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001781 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001782 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001783 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001784 band->ht_cap.mcs.rx_mask[2] = 0xff;
1785 band->ht_cap.mcs.rx_mask[4] = 0x01;
1786 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001787
1788 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001789 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1790 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001791 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1792 }
1793}
1794
Lennert Buytenhek06953232010-01-12 13:49:41 +01001795static void
1796mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
1797{
1798 struct mwl8k_priv *priv = hw->priv;
1799
1800 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
1801 mwl8k_setup_2ghz_band(hw);
1802 if (caps & MWL8K_CAP_MIMO)
1803 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
1804 }
1805
1806 if (caps & MWL8K_CAP_5GHZ) {
1807 mwl8k_setup_5ghz_band(hw);
1808 if (caps & MWL8K_CAP_MIMO)
1809 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
1810 }
1811}
1812
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001813static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001814{
1815 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001816 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001817 int rc;
1818 int i;
1819
1820 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1821 if (cmd == NULL)
1822 return -ENOMEM;
1823
1824 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1825 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1826
1827 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1828 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001829 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001830 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001831 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001832 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001833 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001834 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001835
1836 rc = mwl8k_post_cmd(hw, &cmd->header);
1837
1838 if (!rc) {
1839 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1840 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001841 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001842 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek06953232010-01-12 13:49:41 +01001843 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01001844 priv->ap_macids_supported = 0x00000000;
1845 priv->sta_macids_supported = 0x00000001;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001846 }
1847
1848 kfree(cmd);
1849 return rc;
1850}
1851
1852/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001853 * CMD_GET_HW_SPEC (AP version).
1854 */
1855struct mwl8k_cmd_get_hw_spec_ap {
1856 struct mwl8k_cmd_pkt header;
1857 __u8 hw_rev;
1858 __u8 host_interface;
1859 __le16 num_wcb;
1860 __le16 num_mcaddrs;
1861 __u8 perm_addr[ETH_ALEN];
1862 __le16 region_code;
1863 __le16 num_antenna;
1864 __le32 fw_rev;
1865 __le32 wcbbase0;
1866 __le32 rxwrptr;
1867 __le32 rxrdptr;
1868 __le32 ps_cookie;
1869 __le32 wcbbase1;
1870 __le32 wcbbase2;
1871 __le32 wcbbase3;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08001872 __le32 fw_api_version;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001873} __packed;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001874
1875static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1876{
1877 struct mwl8k_priv *priv = hw->priv;
1878 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1879 int rc;
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08001880 u32 api_version;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001881
1882 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1883 if (cmd == NULL)
1884 return -ENOMEM;
1885
1886 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1887 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1888
1889 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1890 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1891
1892 rc = mwl8k_post_cmd(hw, &cmd->header);
1893
1894 if (!rc) {
1895 int off;
1896
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08001897 api_version = le32_to_cpu(cmd->fw_api_version);
1898 if (priv->device_info->fw_api_ap != api_version) {
1899 printk(KERN_ERR "%s: Unsupported fw API version for %s."
1900 " Expected %d got %d.\n", MWL8K_NAME,
1901 priv->device_info->part_name,
1902 priv->device_info->fw_api_ap,
1903 api_version);
1904 rc = -EINVAL;
1905 goto done;
1906 }
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001907 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1908 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1909 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1910 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001911 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01001912 priv->ap_macids_supported = 0x000000ff;
1913 priv->sta_macids_supported = 0x00000000;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001914
1915 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001916 iowrite32(priv->txq[0].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001917
1918 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001919 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001920
1921 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001922 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001923
1924 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001925 iowrite32(priv->txq[1].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001926
1927 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001928 iowrite32(priv->txq[2].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001929
1930 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001931 iowrite32(priv->txq[3].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001932 }
1933
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08001934done:
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001935 kfree(cmd);
1936 return rc;
1937}
1938
1939/*
1940 * CMD_SET_HW_SPEC.
1941 */
1942struct mwl8k_cmd_set_hw_spec {
1943 struct mwl8k_cmd_pkt header;
1944 __u8 hw_rev;
1945 __u8 host_interface;
1946 __le16 num_mcaddrs;
1947 __u8 perm_addr[ETH_ALEN];
1948 __le16 region_code;
1949 __le32 fw_rev;
1950 __le32 ps_cookie;
1951 __le32 caps;
1952 __le32 rx_queue_ptr;
1953 __le32 num_tx_queues;
1954 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1955 __le32 flags;
1956 __le32 num_tx_desc_per_queue;
1957 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001958} __packed;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001959
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001960#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1961#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1962#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001963
1964static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1965{
1966 struct mwl8k_priv *priv = hw->priv;
1967 struct mwl8k_cmd_set_hw_spec *cmd;
1968 int rc;
1969 int i;
1970
1971 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1972 if (cmd == NULL)
1973 return -ENOMEM;
1974
1975 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1976 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1977
1978 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1979 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1980 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1981 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1982 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001983 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1984 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1985 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001986 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1987 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1988
1989 rc = mwl8k_post_cmd(hw, &cmd->header);
1990 kfree(cmd);
1991
1992 return rc;
1993}
1994
1995/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001996 * CMD_MAC_MULTICAST_ADR.
1997 */
1998struct mwl8k_cmd_mac_multicast_adr {
1999 struct mwl8k_cmd_pkt header;
2000 __le16 action;
2001 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002002 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002003};
2004
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002005#define MWL8K_ENABLE_RX_DIRECTED 0x0001
2006#define MWL8K_ENABLE_RX_MULTICAST 0x0002
2007#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
2008#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002009
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002010static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002011__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Jiri Pirko22bedad2010-04-01 21:22:57 +00002012 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002013{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002014 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002015 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002016 int size;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002017 int mc_count = 0;
2018
2019 if (mc_list)
2020 mc_count = netdev_hw_addr_list_count(mc_list);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002021
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002022 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002023 allmulti = 1;
2024 mc_count = 0;
2025 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002026
2027 size = sizeof(*cmd) + mc_count * ETH_ALEN;
2028
2029 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002030 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002031 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002032
2033 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
2034 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002035 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
2036 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002037
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002038 if (allmulti) {
2039 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
2040 } else if (mc_count) {
Jiri Pirko22bedad2010-04-01 21:22:57 +00002041 struct netdev_hw_addr *ha;
2042 int i = 0;
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02002043
2044 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
2045 cmd->numaddr = cpu_to_le16(mc_count);
Jiri Pirko22bedad2010-04-01 21:22:57 +00002046 netdev_hw_addr_list_for_each(ha, mc_list) {
2047 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002048 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002049 }
2050
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002051 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002052}
2053
2054/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002055 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002056 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002057struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002058 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002059 __le32 stats[64];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002060} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002061
2062#define MWL8K_STAT_ACK_FAILURE 9
2063#define MWL8K_STAT_RTS_FAILURE 12
2064#define MWL8K_STAT_FCS_ERROR 24
2065#define MWL8K_STAT_RTS_SUCCESS 11
2066
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002067static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
2068 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002069{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002070 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002071 int rc;
2072
2073 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2074 if (cmd == NULL)
2075 return -ENOMEM;
2076
2077 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2078 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002079
2080 rc = mwl8k_post_cmd(hw, &cmd->header);
2081 if (!rc) {
2082 stats->dot11ACKFailureCount =
2083 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2084 stats->dot11RTSFailureCount =
2085 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2086 stats->dot11FCSErrorCount =
2087 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2088 stats->dot11RTSSuccessCount =
2089 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2090 }
2091 kfree(cmd);
2092
2093 return rc;
2094}
2095
2096/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002097 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002098 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002099struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002100 struct mwl8k_cmd_pkt header;
2101 __le16 action;
2102 __le16 control;
2103 __le16 radio_on;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002104} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002105
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002106static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002107mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002108{
2109 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002110 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002111 int rc;
2112
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002113 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002114 return 0;
2115
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002116 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2117 if (cmd == NULL)
2118 return -ENOMEM;
2119
2120 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2121 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2122 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002123 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002124 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2125
2126 rc = mwl8k_post_cmd(hw, &cmd->header);
2127 kfree(cmd);
2128
2129 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002130 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002131
2132 return rc;
2133}
2134
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002135static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002136{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002137 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002138}
2139
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002140static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002141{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002142 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002143}
2144
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002145static int
2146mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2147{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002148 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002149
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002150 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002151
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002152 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002153}
2154
2155/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002156 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002157 */
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002158#define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002159
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002160struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002161 struct mwl8k_cmd_pkt header;
2162 __le16 action;
2163 __le16 support_level;
2164 __le16 current_level;
2165 __le16 reserved;
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002166 __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002167} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002168
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002169static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002170{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002171 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002172 int rc;
2173
2174 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2175 if (cmd == NULL)
2176 return -ENOMEM;
2177
2178 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2179 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2180 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2181 cmd->support_level = cpu_to_le16(dBm);
2182
2183 rc = mwl8k_post_cmd(hw, &cmd->header);
2184 kfree(cmd);
2185
2186 return rc;
2187}
2188
2189/*
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08002190 * CMD_TX_POWER.
2191 */
2192#define MWL8K_TX_POWER_LEVEL_TOTAL 12
2193
2194struct mwl8k_cmd_tx_power {
2195 struct mwl8k_cmd_pkt header;
2196 __le16 action;
2197 __le16 band;
2198 __le16 channel;
2199 __le16 bw;
2200 __le16 sub_ch;
2201 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2202} __attribute__((packed));
2203
2204static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
2205 struct ieee80211_conf *conf,
2206 unsigned short pwr)
2207{
2208 struct ieee80211_channel *channel = conf->channel;
2209 struct mwl8k_cmd_tx_power *cmd;
2210 int rc;
2211 int i;
2212
2213 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2214 if (cmd == NULL)
2215 return -ENOMEM;
2216
2217 cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
2218 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2219 cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
2220
2221 if (channel->band == IEEE80211_BAND_2GHZ)
2222 cmd->band = cpu_to_le16(0x1);
2223 else if (channel->band == IEEE80211_BAND_5GHZ)
2224 cmd->band = cpu_to_le16(0x4);
2225
2226 cmd->channel = channel->hw_value;
2227
2228 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2229 conf->channel_type == NL80211_CHAN_HT20) {
2230 cmd->bw = cpu_to_le16(0x2);
2231 } else {
2232 cmd->bw = cpu_to_le16(0x4);
2233 if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2234 cmd->sub_ch = cpu_to_le16(0x3);
2235 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2236 cmd->sub_ch = cpu_to_le16(0x1);
2237 }
2238
2239 for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
2240 cmd->power_level_list[i] = cpu_to_le16(pwr);
2241
2242 rc = mwl8k_post_cmd(hw, &cmd->header);
2243 kfree(cmd);
2244
2245 return rc;
2246}
2247
2248/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002249 * CMD_RF_ANTENNA.
2250 */
2251struct mwl8k_cmd_rf_antenna {
2252 struct mwl8k_cmd_pkt header;
2253 __le16 antenna;
2254 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002255} __packed;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002256
2257#define MWL8K_RF_ANTENNA_RX 1
2258#define MWL8K_RF_ANTENNA_TX 2
2259
2260static int
2261mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2262{
2263 struct mwl8k_cmd_rf_antenna *cmd;
2264 int rc;
2265
2266 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2267 if (cmd == NULL)
2268 return -ENOMEM;
2269
2270 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2271 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2272 cmd->antenna = cpu_to_le16(antenna);
2273 cmd->mode = cpu_to_le16(mask);
2274
2275 rc = mwl8k_post_cmd(hw, &cmd->header);
2276 kfree(cmd);
2277
2278 return rc;
2279}
2280
2281/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002282 * CMD_SET_BEACON.
2283 */
2284struct mwl8k_cmd_set_beacon {
2285 struct mwl8k_cmd_pkt header;
2286 __le16 beacon_len;
2287 __u8 beacon[0];
2288};
2289
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002290static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2291 struct ieee80211_vif *vif, u8 *beacon, int len)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002292{
2293 struct mwl8k_cmd_set_beacon *cmd;
2294 int rc;
2295
2296 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2297 if (cmd == NULL)
2298 return -ENOMEM;
2299
2300 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2301 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2302 cmd->beacon_len = cpu_to_le16(len);
2303 memcpy(cmd->beacon, beacon, len);
2304
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002305 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002306 kfree(cmd);
2307
2308 return rc;
2309}
2310
2311/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002312 * CMD_SET_PRE_SCAN.
2313 */
2314struct mwl8k_cmd_set_pre_scan {
2315 struct mwl8k_cmd_pkt header;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002316} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002317
2318static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2319{
2320 struct mwl8k_cmd_set_pre_scan *cmd;
2321 int rc;
2322
2323 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2324 if (cmd == NULL)
2325 return -ENOMEM;
2326
2327 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2328 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2329
2330 rc = mwl8k_post_cmd(hw, &cmd->header);
2331 kfree(cmd);
2332
2333 return rc;
2334}
2335
2336/*
2337 * CMD_SET_POST_SCAN.
2338 */
2339struct mwl8k_cmd_set_post_scan {
2340 struct mwl8k_cmd_pkt header;
2341 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002342 __u8 bssid[ETH_ALEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002343} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002344
2345static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002346mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002347{
2348 struct mwl8k_cmd_set_post_scan *cmd;
2349 int rc;
2350
2351 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2352 if (cmd == NULL)
2353 return -ENOMEM;
2354
2355 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2356 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2357 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002358 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002359
2360 rc = mwl8k_post_cmd(hw, &cmd->header);
2361 kfree(cmd);
2362
2363 return rc;
2364}
2365
2366/*
2367 * CMD_SET_RF_CHANNEL.
2368 */
2369struct mwl8k_cmd_set_rf_channel {
2370 struct mwl8k_cmd_pkt header;
2371 __le16 action;
2372 __u8 current_channel;
2373 __le32 channel_flags;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002374} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002375
2376static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002377 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002378{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002379 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002380 struct mwl8k_cmd_set_rf_channel *cmd;
2381 int rc;
2382
2383 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2384 if (cmd == NULL)
2385 return -ENOMEM;
2386
2387 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2388 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2389 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2390 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002391
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002392 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002393 cmd->channel_flags |= cpu_to_le32(0x00000001);
Lennert Buytenhek42574ea2010-01-12 13:49:18 +01002394 else if (channel->band == IEEE80211_BAND_5GHZ)
2395 cmd->channel_flags |= cpu_to_le32(0x00000004);
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002396
2397 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2398 conf->channel_type == NL80211_CHAN_HT20)
2399 cmd->channel_flags |= cpu_to_le32(0x00000080);
2400 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2401 cmd->channel_flags |= cpu_to_le32(0x000001900);
2402 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2403 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002404
2405 rc = mwl8k_post_cmd(hw, &cmd->header);
2406 kfree(cmd);
2407
2408 return rc;
2409}
2410
2411/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002412 * CMD_SET_AID.
2413 */
2414#define MWL8K_FRAME_PROT_DISABLED 0x00
2415#define MWL8K_FRAME_PROT_11G 0x07
2416#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2417#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2418
2419struct mwl8k_cmd_update_set_aid {
2420 struct mwl8k_cmd_pkt header;
2421 __le16 aid;
2422
2423 /* AP's MAC address (BSSID) */
2424 __u8 bssid[ETH_ALEN];
2425 __le16 protection_mode;
2426 __u8 supp_rates[14];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002427} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002428
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002429static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2430{
2431 int i;
2432 int j;
2433
2434 /*
2435 * Clear nonstandard rates 4 and 13.
2436 */
2437 mask &= 0x1fef;
2438
2439 for (i = 0, j = 0; i < 14; i++) {
2440 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002441 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002442 }
2443}
2444
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002445static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002446mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2447 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002448{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002449 struct mwl8k_cmd_update_set_aid *cmd;
2450 u16 prot_mode;
2451 int rc;
2452
2453 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2454 if (cmd == NULL)
2455 return -ENOMEM;
2456
2457 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2458 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002459 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002460 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002461
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002462 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002463 prot_mode = MWL8K_FRAME_PROT_11G;
2464 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002465 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002466 IEEE80211_HT_OP_MODE_PROTECTION) {
2467 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2468 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2469 break;
2470 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2471 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2472 break;
2473 default:
2474 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2475 break;
2476 }
2477 }
2478 cmd->protection_mode = cpu_to_le16(prot_mode);
2479
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002480 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002481
2482 rc = mwl8k_post_cmd(hw, &cmd->header);
2483 kfree(cmd);
2484
2485 return rc;
2486}
2487
2488/*
2489 * CMD_SET_RATE.
2490 */
2491struct mwl8k_cmd_set_rate {
2492 struct mwl8k_cmd_pkt header;
2493 __u8 legacy_rates[14];
2494
2495 /* Bitmap for supported MCS codes. */
2496 __u8 mcs_set[16];
2497 __u8 reserved[16];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002498} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002499
2500static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002501mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002502 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002503{
2504 struct mwl8k_cmd_set_rate *cmd;
2505 int rc;
2506
2507 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2508 if (cmd == NULL)
2509 return -ENOMEM;
2510
2511 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2512 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002513 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002514 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002515
2516 rc = mwl8k_post_cmd(hw, &cmd->header);
2517 kfree(cmd);
2518
2519 return rc;
2520}
2521
2522/*
2523 * CMD_FINALIZE_JOIN.
2524 */
2525#define MWL8K_FJ_BEACON_MAXLEN 128
2526
2527struct mwl8k_cmd_finalize_join {
2528 struct mwl8k_cmd_pkt header;
2529 __le32 sleep_interval; /* Number of beacon periods to sleep */
2530 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002531} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002532
2533static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2534 int framelen, int dtim)
2535{
2536 struct mwl8k_cmd_finalize_join *cmd;
2537 struct ieee80211_mgmt *payload = frame;
2538 int payload_len;
2539 int rc;
2540
2541 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2542 if (cmd == NULL)
2543 return -ENOMEM;
2544
2545 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2546 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2547 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2548
2549 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2550 if (payload_len < 0)
2551 payload_len = 0;
2552 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2553 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2554
2555 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2556
2557 rc = mwl8k_post_cmd(hw, &cmd->header);
2558 kfree(cmd);
2559
2560 return rc;
2561}
2562
2563/*
2564 * CMD_SET_RTS_THRESHOLD.
2565 */
2566struct mwl8k_cmd_set_rts_threshold {
2567 struct mwl8k_cmd_pkt header;
2568 __le16 action;
2569 __le16 threshold;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002570} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002571
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002572static int
2573mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002574{
2575 struct mwl8k_cmd_set_rts_threshold *cmd;
2576 int rc;
2577
2578 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2579 if (cmd == NULL)
2580 return -ENOMEM;
2581
2582 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2583 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002584 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2585 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002586
2587 rc = mwl8k_post_cmd(hw, &cmd->header);
2588 kfree(cmd);
2589
2590 return rc;
2591}
2592
2593/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002594 * CMD_SET_SLOT.
2595 */
2596struct mwl8k_cmd_set_slot {
2597 struct mwl8k_cmd_pkt header;
2598 __le16 action;
2599 __u8 short_slot;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002600} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002601
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002602static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002603{
2604 struct mwl8k_cmd_set_slot *cmd;
2605 int rc;
2606
2607 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2608 if (cmd == NULL)
2609 return -ENOMEM;
2610
2611 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2612 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2613 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002614 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002615
2616 rc = mwl8k_post_cmd(hw, &cmd->header);
2617 kfree(cmd);
2618
2619 return rc;
2620}
2621
2622/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002623 * CMD_SET_EDCA_PARAMS.
2624 */
2625struct mwl8k_cmd_set_edca_params {
2626 struct mwl8k_cmd_pkt header;
2627
2628 /* See MWL8K_SET_EDCA_XXX below */
2629 __le16 action;
2630
2631 /* TX opportunity in units of 32 us */
2632 __le16 txop;
2633
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002634 union {
2635 struct {
2636 /* Log exponent of max contention period: 0...15 */
2637 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002638
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002639 /* Log exponent of min contention period: 0...15 */
2640 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002641
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002642 /* Adaptive interframe spacing in units of 32us */
2643 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002644
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002645 /* TX queue to configure */
2646 __u8 txq;
2647 } ap;
2648 struct {
2649 /* Log exponent of max contention period: 0...15 */
2650 __u8 log_cw_max;
2651
2652 /* Log exponent of min contention period: 0...15 */
2653 __u8 log_cw_min;
2654
2655 /* Adaptive interframe spacing in units of 32us */
2656 __u8 aifs;
2657
2658 /* TX queue to configure */
2659 __u8 txq;
2660 } sta;
2661 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00002662} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002663
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002664#define MWL8K_SET_EDCA_CW 0x01
2665#define MWL8K_SET_EDCA_TXOP 0x02
2666#define MWL8K_SET_EDCA_AIFS 0x04
2667
2668#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2669 MWL8K_SET_EDCA_TXOP | \
2670 MWL8K_SET_EDCA_AIFS)
2671
2672static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002673mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2674 __u16 cw_min, __u16 cw_max,
2675 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002676{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002677 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002678 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002679 int rc;
2680
2681 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2682 if (cmd == NULL)
2683 return -ENOMEM;
2684
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002685 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2686 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002687 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2688 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002689 if (priv->ap_fw) {
2690 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2691 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2692 cmd->ap.aifs = aifs;
2693 cmd->ap.txq = qnum;
2694 } else {
2695 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2696 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2697 cmd->sta.aifs = aifs;
2698 cmd->sta.txq = qnum;
2699 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002700
2701 rc = mwl8k_post_cmd(hw, &cmd->header);
2702 kfree(cmd);
2703
2704 return rc;
2705}
2706
2707/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002708 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002709 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002710struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002711 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002712 __le16 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002713} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002714
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002715static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002716{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002717 struct mwl8k_priv *priv = hw->priv;
2718 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002719 int rc;
2720
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002721 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2722 if (cmd == NULL)
2723 return -ENOMEM;
2724
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002725 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002726 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002727 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002728
2729 rc = mwl8k_post_cmd(hw, &cmd->header);
2730 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002731
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002732 if (!rc)
2733 priv->wmm_enabled = enable;
2734
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002735 return rc;
2736}
2737
2738/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002739 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002740 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002741struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002742 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002743 __le32 action;
2744 __u8 rx_antenna_map;
2745 __u8 tx_antenna_map;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002746} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002747
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002748static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002749{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002750 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002751 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002752
2753 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2754 if (cmd == NULL)
2755 return -ENOMEM;
2756
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002757 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002758 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002759 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2760 cmd->rx_antenna_map = rx;
2761 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002762
2763 rc = mwl8k_post_cmd(hw, &cmd->header);
2764 kfree(cmd);
2765
2766 return rc;
2767}
2768
2769/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002770 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002771 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002772struct mwl8k_cmd_use_fixed_rate_sta {
2773 struct mwl8k_cmd_pkt header;
2774 __le32 action;
2775 __le32 allow_rate_drop;
2776 __le32 num_rates;
2777 struct {
2778 __le32 is_ht_rate;
2779 __le32 enable_retry;
2780 __le32 rate;
2781 __le32 retry_count;
2782 } rate_entry[8];
2783 __le32 rate_type;
2784 __le32 reserved1;
2785 __le32 reserved2;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002786} __packed;
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002787
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002788#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002789#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002790
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002791static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002792{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002793 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002794 int rc;
2795
2796 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2797 if (cmd == NULL)
2798 return -ENOMEM;
2799
2800 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2801 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002802 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2803 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002804
2805 rc = mwl8k_post_cmd(hw, &cmd->header);
2806 kfree(cmd);
2807
2808 return rc;
2809}
2810
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002811/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002812 * CMD_USE_FIXED_RATE (AP version).
2813 */
2814struct mwl8k_cmd_use_fixed_rate_ap {
2815 struct mwl8k_cmd_pkt header;
2816 __le32 action;
2817 __le32 allow_rate_drop;
2818 __le32 num_rates;
2819 struct mwl8k_rate_entry_ap {
2820 __le32 is_ht_rate;
2821 __le32 enable_retry;
2822 __le32 rate;
2823 __le32 retry_count;
2824 } rate_entry[4];
2825 u8 multicast_rate;
2826 u8 multicast_rate_type;
2827 u8 management_rate;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002828} __packed;
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002829
2830static int
2831mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2832{
2833 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2834 int rc;
2835
2836 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2837 if (cmd == NULL)
2838 return -ENOMEM;
2839
2840 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2841 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2842 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2843 cmd->multicast_rate = mcast;
2844 cmd->management_rate = mgmt;
2845
2846 rc = mwl8k_post_cmd(hw, &cmd->header);
2847 kfree(cmd);
2848
2849 return rc;
2850}
2851
2852/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002853 * CMD_ENABLE_SNIFFER.
2854 */
2855struct mwl8k_cmd_enable_sniffer {
2856 struct mwl8k_cmd_pkt header;
2857 __le32 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002858} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002859
2860static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2861{
2862 struct mwl8k_cmd_enable_sniffer *cmd;
2863 int rc;
2864
2865 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2866 if (cmd == NULL)
2867 return -ENOMEM;
2868
2869 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2870 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2871 cmd->action = cpu_to_le32(!!enable);
2872
2873 rc = mwl8k_post_cmd(hw, &cmd->header);
2874 kfree(cmd);
2875
2876 return rc;
2877}
2878
2879/*
2880 * CMD_SET_MAC_ADDR.
2881 */
2882struct mwl8k_cmd_set_mac_addr {
2883 struct mwl8k_cmd_pkt header;
2884 union {
2885 struct {
2886 __le16 mac_type;
2887 __u8 mac_addr[ETH_ALEN];
2888 } mbss;
2889 __u8 mac_addr[ETH_ALEN];
2890 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00002891} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002892
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002893#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2894#define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
2895#define MWL8K_MAC_TYPE_PRIMARY_AP 2
2896#define MWL8K_MAC_TYPE_SECONDARY_AP 3
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002897
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002898static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
2899 struct ieee80211_vif *vif, u8 *mac)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002900{
2901 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002902 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002903 struct mwl8k_cmd_set_mac_addr *cmd;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002904 int mac_type;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002905 int rc;
2906
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002907 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
2908 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
2909 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
2910 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
2911 else
2912 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
2913 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
2914 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
2915 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
2916 else
2917 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
2918 }
2919
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002920 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2921 if (cmd == NULL)
2922 return -ENOMEM;
2923
2924 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2925 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2926 if (priv->ap_fw) {
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002927 cmd->mbss.mac_type = cpu_to_le16(mac_type);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002928 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2929 } else {
2930 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2931 }
2932
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002933 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002934 kfree(cmd);
2935
2936 return rc;
2937}
2938
2939/*
2940 * CMD_SET_RATEADAPT_MODE.
2941 */
2942struct mwl8k_cmd_set_rate_adapt_mode {
2943 struct mwl8k_cmd_pkt header;
2944 __le16 action;
2945 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002946} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002947
2948static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2949{
2950 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2951 int rc;
2952
2953 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2954 if (cmd == NULL)
2955 return -ENOMEM;
2956
2957 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2958 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2959 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2960 cmd->mode = cpu_to_le16(mode);
2961
2962 rc = mwl8k_post_cmd(hw, &cmd->header);
2963 kfree(cmd);
2964
2965 return rc;
2966}
2967
2968/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002969 * CMD_BSS_START.
2970 */
2971struct mwl8k_cmd_bss_start {
2972 struct mwl8k_cmd_pkt header;
2973 __le32 enable;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002974} __packed;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002975
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002976static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
2977 struct ieee80211_vif *vif, int enable)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002978{
2979 struct mwl8k_cmd_bss_start *cmd;
2980 int rc;
2981
2982 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2983 if (cmd == NULL)
2984 return -ENOMEM;
2985
2986 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2987 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2988 cmd->enable = cpu_to_le32(enable);
2989
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002990 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002991 kfree(cmd);
2992
2993 return rc;
2994}
2995
2996/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002997 * CMD_SET_NEW_STN.
2998 */
2999struct mwl8k_cmd_set_new_stn {
3000 struct mwl8k_cmd_pkt header;
3001 __le16 aid;
3002 __u8 mac_addr[6];
3003 __le16 stn_id;
3004 __le16 action;
3005 __le16 rsvd;
3006 __le32 legacy_rates;
3007 __u8 ht_rates[4];
3008 __le16 cap_info;
3009 __le16 ht_capabilities_info;
3010 __u8 mac_ht_param_info;
3011 __u8 rev;
3012 __u8 control_channel;
3013 __u8 add_channel;
3014 __le16 op_mode;
3015 __le16 stbc;
3016 __u8 add_qos_info;
3017 __u8 is_qos_sta;
3018 __le32 fw_sta_ptr;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003019} __packed;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003020
3021#define MWL8K_STA_ACTION_ADD 0
3022#define MWL8K_STA_ACTION_REMOVE 2
3023
3024static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
3025 struct ieee80211_vif *vif,
3026 struct ieee80211_sta *sta)
3027{
3028 struct mwl8k_cmd_set_new_stn *cmd;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003029 u32 rates;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003030 int rc;
3031
3032 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3033 if (cmd == NULL)
3034 return -ENOMEM;
3035
3036 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3037 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3038 cmd->aid = cpu_to_le16(sta->aid);
3039 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
3040 cmd->stn_id = cpu_to_le16(sta->aid);
3041 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003042 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3043 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3044 else
3045 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3046 cmd->legacy_rates = cpu_to_le32(rates);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003047 if (sta->ht_cap.ht_supported) {
3048 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
3049 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
3050 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
3051 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
3052 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
3053 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
3054 ((sta->ht_cap.ampdu_density & 7) << 2);
3055 cmd->is_qos_sta = 1;
3056 }
3057
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003058 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003059 kfree(cmd);
3060
3061 return rc;
3062}
3063
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003064static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
3065 struct ieee80211_vif *vif)
3066{
3067 struct mwl8k_cmd_set_new_stn *cmd;
3068 int rc;
3069
3070 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3071 if (cmd == NULL)
3072 return -ENOMEM;
3073
3074 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3075 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3076 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
3077
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003078 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003079 kfree(cmd);
3080
3081 return rc;
3082}
3083
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003084static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
3085 struct ieee80211_vif *vif, u8 *addr)
3086{
3087 struct mwl8k_cmd_set_new_stn *cmd;
3088 int rc;
3089
3090 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3091 if (cmd == NULL)
3092 return -ENOMEM;
3093
3094 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
3095 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3096 memcpy(cmd->mac_addr, addr, ETH_ALEN);
3097 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
3098
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003099 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003100 kfree(cmd);
3101
3102 return rc;
3103}
3104
3105/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003106 * CMD_UPDATE_STADB.
3107 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01003108struct ewc_ht_info {
3109 __le16 control1;
3110 __le16 control2;
3111 __le16 control3;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003112} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01003113
3114struct peer_capability_info {
3115 /* Peer type - AP vs. STA. */
3116 __u8 peer_type;
3117
3118 /* Basic 802.11 capabilities from assoc resp. */
3119 __le16 basic_caps;
3120
3121 /* Set if peer supports 802.11n high throughput (HT). */
3122 __u8 ht_support;
3123
3124 /* Valid if HT is supported. */
3125 __le16 ht_caps;
3126 __u8 extended_ht_caps;
3127 struct ewc_ht_info ewc_info;
3128
3129 /* Legacy rate table. Intersection of our rates and peer rates. */
3130 __u8 legacy_rates[12];
3131
3132 /* HT rate table. Intersection of our rates and peer rates. */
3133 __u8 ht_rates[16];
3134 __u8 pad[16];
3135
3136 /* If set, interoperability mode, no proprietary extensions. */
3137 __u8 interop;
3138 __u8 pad2;
3139 __u8 station_id;
3140 __le16 amsdu_enabled;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003141} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01003142
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003143struct mwl8k_cmd_update_stadb {
3144 struct mwl8k_cmd_pkt header;
3145
3146 /* See STADB_ACTION_TYPE */
3147 __le32 action;
3148
3149 /* Peer MAC address */
3150 __u8 peer_addr[ETH_ALEN];
3151
3152 __le32 reserved;
3153
3154 /* Peer info - valid during add/update. */
3155 struct peer_capability_info peer_info;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003156} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003157
Lennert Buytenheka6804002010-01-04 21:55:42 +01003158#define MWL8K_STA_DB_MODIFY_ENTRY 1
3159#define MWL8K_STA_DB_DEL_ENTRY 2
3160
3161/* Peer Entry flags - used to define the type of the peer node */
3162#define MWL8K_PEER_TYPE_ACCESSPOINT 2
3163
3164static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003165 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003166 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003167{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003168 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01003169 struct peer_capability_info *p;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003170 u32 rates;
Lennert Buytenhek55489b62009-11-30 18:31:33 +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_UPDATE_STADB);
3178 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01003179 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003180 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003181
Lennert Buytenheka6804002010-01-04 21:55:42 +01003182 p = &cmd->peer_info;
3183 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
3184 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003185 p->ht_support = sta->ht_cap.ht_supported;
John W. Linvilleb6037422010-07-20 13:55:00 -04003186 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003187 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
3188 ((sta->ht_cap.ampdu_density & 7) << 2);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003189 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3190 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3191 else
3192 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3193 legacy_rate_mask_to_array(p->legacy_rates, rates);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003194 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003195 p->interop = 1;
3196 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003197
Lennert Buytenheka6804002010-01-04 21:55:42 +01003198 rc = mwl8k_post_cmd(hw, &cmd->header);
3199 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003200
Lennert Buytenheka6804002010-01-04 21:55:42 +01003201 return rc ? rc : p->station_id;
3202}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003203
Lennert Buytenheka6804002010-01-04 21:55:42 +01003204static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
3205 struct ieee80211_vif *vif, u8 *addr)
3206{
3207 struct mwl8k_cmd_update_stadb *cmd;
3208 int rc;
3209
3210 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3211 if (cmd == NULL)
3212 return -ENOMEM;
3213
3214 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3215 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3216 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
3217 memcpy(cmd->peer_addr, addr, ETH_ALEN);
3218
3219 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003220 kfree(cmd);
3221
3222 return rc;
3223}
3224
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003225
3226/*
3227 * Interrupt handling.
3228 */
3229static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
3230{
3231 struct ieee80211_hw *hw = dev_id;
3232 struct mwl8k_priv *priv = hw->priv;
3233 u32 status;
3234
3235 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003236 if (!status)
3237 return IRQ_NONE;
3238
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003239 if (status & MWL8K_A2H_INT_TX_DONE) {
3240 status &= ~MWL8K_A2H_INT_TX_DONE;
3241 tasklet_schedule(&priv->poll_tx_task);
3242 }
3243
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003244 if (status & MWL8K_A2H_INT_RX_READY) {
3245 status &= ~MWL8K_A2H_INT_RX_READY;
3246 tasklet_schedule(&priv->poll_rx_task);
3247 }
3248
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003249 if (status)
3250 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003251
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003252 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003253 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003254 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003255 }
3256
3257 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003258 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003259 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003260 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003261 }
3262
3263 return IRQ_HANDLED;
3264}
3265
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003266static void mwl8k_tx_poll(unsigned long data)
3267{
3268 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3269 struct mwl8k_priv *priv = hw->priv;
3270 int limit;
3271 int i;
3272
3273 limit = 32;
3274
3275 spin_lock_bh(&priv->tx_lock);
3276
3277 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3278 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3279
3280 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3281 complete(priv->tx_wait);
3282 priv->tx_wait = NULL;
3283 }
3284
3285 spin_unlock_bh(&priv->tx_lock);
3286
3287 if (limit) {
3288 writel(~MWL8K_A2H_INT_TX_DONE,
3289 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3290 } else {
3291 tasklet_schedule(&priv->poll_tx_task);
3292 }
3293}
3294
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003295static void mwl8k_rx_poll(unsigned long data)
3296{
3297 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3298 struct mwl8k_priv *priv = hw->priv;
3299 int limit;
3300
3301 limit = 32;
3302 limit -= rxq_process(hw, 0, limit);
3303 limit -= rxq_refill(hw, 0, limit);
3304
3305 if (limit) {
3306 writel(~MWL8K_A2H_INT_RX_READY,
3307 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3308 } else {
3309 tasklet_schedule(&priv->poll_rx_task);
3310 }
3311}
3312
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003313
3314/*
3315 * Core driver operations.
3316 */
3317static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3318{
3319 struct mwl8k_priv *priv = hw->priv;
3320 int index = skb_get_queue_mapping(skb);
3321 int rc;
3322
Lennert Buytenhek9189c102010-01-12 13:47:32 +01003323 if (!priv->radio_on) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003324 wiphy_debug(hw->wiphy,
3325 "dropped TX frame since radio disabled\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003326 dev_kfree_skb(skb);
3327 return NETDEV_TX_OK;
3328 }
3329
3330 rc = mwl8k_txq_xmit(hw, index, skb);
3331
3332 return rc;
3333}
3334
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003335static int mwl8k_start(struct ieee80211_hw *hw)
3336{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003337 struct mwl8k_priv *priv = hw->priv;
3338 int rc;
3339
Joe Perchesa0607fd2009-11-18 23:29:17 -08003340 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003341 IRQF_SHARED, MWL8K_NAME, hw);
3342 if (rc) {
Joe Perches5db55842010-08-11 19:11:19 -07003343 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003344 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003345 }
3346
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003347 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003348 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003349 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003350
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003351 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003352 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003353
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003354 rc = mwl8k_fw_lock(hw);
3355 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003356 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003357
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003358 if (!priv->ap_fw) {
3359 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003360 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003361
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003362 if (!rc)
3363 rc = mwl8k_cmd_set_pre_scan(hw);
3364
3365 if (!rc)
3366 rc = mwl8k_cmd_set_post_scan(hw,
3367 "\x00\x00\x00\x00\x00\x00");
3368 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003369
3370 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003371 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003372
3373 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003374 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003375
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003376 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003377 }
3378
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003379 if (rc) {
3380 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3381 free_irq(priv->pdev->irq, hw);
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003382 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003383 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003384 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003385
3386 return rc;
3387}
3388
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003389static void mwl8k_stop(struct ieee80211_hw *hw)
3390{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003391 struct mwl8k_priv *priv = hw->priv;
3392 int i;
3393
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003394 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003395
3396 ieee80211_stop_queues(hw);
3397
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003398 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003399 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003400 free_irq(priv->pdev->irq, hw);
3401
3402 /* Stop finalize join worker */
3403 cancel_work_sync(&priv->finalize_join_worker);
3404 if (priv->beacon_skb != NULL)
3405 dev_kfree_skb(priv->beacon_skb);
3406
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003407 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003408 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003409 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003410
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003411 /* Return all skbs to mac80211 */
3412 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01003413 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003414}
3415
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003416static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
3417
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003418static int mwl8k_add_interface(struct ieee80211_hw *hw,
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003419 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003420{
3421 struct mwl8k_priv *priv = hw->priv;
3422 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003423 u32 macids_supported;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003424 int macid, rc;
3425 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003426
3427 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003428 * Reject interface creation if sniffer mode is active, as
3429 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003430 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003431 */
3432 if (priv->sniffer_enabled) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003433 wiphy_info(hw->wiphy,
3434 "unable to create STA interface because sniffer mode is enabled\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003435 return -EINVAL;
3436 }
3437
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003438 di = priv->device_info;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003439 switch (vif->type) {
3440 case NL80211_IFTYPE_AP:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003441 if (!priv->ap_fw && di->fw_image_ap) {
3442 /* we must load the ap fw to meet this request */
3443 if (!list_empty(&priv->vif_list))
3444 return -EBUSY;
3445 rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
3446 if (rc)
3447 return rc;
3448 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003449 macids_supported = priv->ap_macids_supported;
3450 break;
3451 case NL80211_IFTYPE_STATION:
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003452 if (priv->ap_fw && di->fw_image_sta) {
3453 /* we must load the sta fw to meet this request */
3454 if (!list_empty(&priv->vif_list))
3455 return -EBUSY;
3456 rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
3457 if (rc)
3458 return rc;
3459 }
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003460 macids_supported = priv->sta_macids_supported;
3461 break;
3462 default:
3463 return -EINVAL;
3464 }
3465
3466 macid = ffs(macids_supported & ~priv->macids_used);
3467 if (!macid--)
3468 return -EBUSY;
3469
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003470 /* Setup driver private area. */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003471 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003472 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003473 mwl8k_vif->vif = vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003474 mwl8k_vif->macid = macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003475 mwl8k_vif->seqno = 0;
3476
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003477 /* Set the mac address. */
3478 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
3479
3480 if (priv->ap_fw)
3481 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3482
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003483 priv->macids_used |= 1 << mwl8k_vif->macid;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003484 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003485
3486 return 0;
3487}
3488
3489static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003490 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003491{
3492 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003493 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003494
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003495 if (priv->ap_fw)
3496 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3497
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003498 mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003499
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003500 priv->macids_used &= ~(1 << mwl8k_vif->macid);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003501 list_del(&mwl8k_vif->list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003502}
3503
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003504static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003505{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003506 struct ieee80211_conf *conf = &hw->conf;
3507 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003508 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003509
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003510 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003511 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003512 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003513 }
3514
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003515 rc = mwl8k_fw_lock(hw);
3516 if (rc)
3517 return rc;
3518
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003519 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003520 if (rc)
3521 goto out;
3522
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003523 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003524 if (rc)
3525 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003526
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003527 if (conf->power_level > 18)
3528 conf->power_level = 18;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003529
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003530 if (priv->ap_fw) {
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08003531 rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
3532 if (rc)
3533 goto out;
3534
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003535 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3536 if (!rc)
3537 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3538 } else {
Nishant Sarmukadam41fdf092010-11-12 17:23:48 -08003539 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
3540 if (rc)
3541 goto out;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003542 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3543 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003544
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003545out:
3546 mwl8k_fw_unlock(hw);
3547
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003548 return rc;
3549}
3550
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003551static void
3552mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3553 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003554{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003555 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003556 u32 ap_legacy_rates;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003557 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003558 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003559
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003560 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003561 return;
3562
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003563 /*
3564 * No need to capture a beacon if we're no longer associated.
3565 */
3566 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3567 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003568
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003569 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003570 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003571 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003572 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003573 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003574
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003575 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003576
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003577 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003578 if (ap == NULL) {
3579 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003580 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003581 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003582
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003583 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
3584 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3585 } else {
3586 ap_legacy_rates =
3587 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3588 }
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003589 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003590
3591 rcu_read_unlock();
3592 }
3593
3594 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003595 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003596 if (rc)
3597 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003598
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003599 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003600 if (rc)
3601 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003602 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003603
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003604 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003605 rc = mwl8k_set_radio_preamble(hw,
3606 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003607 if (rc)
3608 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003609 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003610
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003611 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003612 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003613 if (rc)
3614 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003615 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003616
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003617 if (vif->bss_conf.assoc &&
3618 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3619 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003620 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003621 if (rc)
3622 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003623 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003624
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003625 if (vif->bss_conf.assoc &&
3626 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003627 /*
3628 * Finalize the join. Tell rx handler to process
3629 * next beacon from our BSSID.
3630 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003631 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003632 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003633 }
3634
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003635out:
3636 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003637}
3638
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003639static void
3640mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3641 struct ieee80211_bss_conf *info, u32 changed)
3642{
3643 int rc;
3644
3645 if (mwl8k_fw_lock(hw))
3646 return;
3647
3648 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3649 rc = mwl8k_set_radio_preamble(hw,
3650 vif->bss_conf.use_short_preamble);
3651 if (rc)
3652 goto out;
3653 }
3654
3655 if (changed & BSS_CHANGED_BASIC_RATES) {
3656 int idx;
3657 int rate;
3658
3659 /*
3660 * Use lowest supported basic rate for multicasts
3661 * and management frames (such as probe responses --
3662 * beacons will always go out at 1 Mb/s).
3663 */
3664 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003665 if (idx)
3666 idx--;
3667
3668 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3669 rate = mwl8k_rates_24[idx].hw_value;
3670 else
3671 rate = mwl8k_rates_50[idx].hw_value;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003672
3673 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3674 }
3675
3676 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3677 struct sk_buff *skb;
3678
3679 skb = ieee80211_beacon_get(hw, vif);
3680 if (skb != NULL) {
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003681 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003682 kfree_skb(skb);
3683 }
3684 }
3685
3686 if (changed & BSS_CHANGED_BEACON_ENABLED)
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003687 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003688
3689out:
3690 mwl8k_fw_unlock(hw);
3691}
3692
3693static void
3694mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3695 struct ieee80211_bss_conf *info, u32 changed)
3696{
3697 struct mwl8k_priv *priv = hw->priv;
3698
3699 if (!priv->ap_fw)
3700 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3701 else
3702 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3703}
3704
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003705static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad2010-04-01 21:22:57 +00003706 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003707{
3708 struct mwl8k_cmd_pkt *cmd;
3709
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003710 /*
3711 * Synthesize and return a command packet that programs the
3712 * hardware multicast address filter. At this point we don't
3713 * know whether FIF_ALLMULTI is being requested, but if it is,
3714 * we'll end up throwing this packet away and creating a new
3715 * one in mwl8k_configure_filter().
3716 */
Jiri Pirko22bedad2010-04-01 21:22:57 +00003717 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003718
3719 return (unsigned long)cmd;
3720}
3721
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003722static int
3723mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3724 unsigned int changed_flags,
3725 unsigned int *total_flags)
3726{
3727 struct mwl8k_priv *priv = hw->priv;
3728
3729 /*
3730 * Hardware sniffer mode is mutually exclusive with STA
3731 * operation, so refuse to enable sniffer mode if a STA
3732 * interface is active.
3733 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003734 if (!list_empty(&priv->vif_list)) {
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003735 if (net_ratelimit())
Joe Perchesc96c31e2010-07-26 14:39:58 -07003736 wiphy_info(hw->wiphy,
3737 "not enabling sniffer mode because STA interface is active\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003738 return 0;
3739 }
3740
3741 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003742 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003743 return 0;
3744 priv->sniffer_enabled = true;
3745 }
3746
3747 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3748 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3749 FIF_OTHER_BSS;
3750
3751 return 1;
3752}
3753
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003754static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
3755{
3756 if (!list_empty(&priv->vif_list))
3757 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
3758
3759 return NULL;
3760}
3761
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003762static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3763 unsigned int changed_flags,
3764 unsigned int *total_flags,
3765 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003766{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003767 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003768 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3769
3770 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003771 * AP firmware doesn't allow fine-grained control over
3772 * the receive filter.
3773 */
3774 if (priv->ap_fw) {
3775 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3776 kfree(cmd);
3777 return;
3778 }
3779
3780 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003781 * Enable hardware sniffer mode if FIF_CONTROL or
3782 * FIF_OTHER_BSS is requested.
3783 */
3784 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3785 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3786 kfree(cmd);
3787 return;
3788 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003789
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003790 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003791 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003792
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003793 if (mwl8k_fw_lock(hw)) {
3794 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003795 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003796 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003797
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003798 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003799 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003800 priv->sniffer_enabled = false;
3801 }
3802
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003803 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003804 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3805 /*
3806 * Disable the BSS filter.
3807 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003808 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003809 } else {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003810 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003811 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003812
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003813 /*
3814 * Enable the BSS filter.
3815 *
3816 * If there is an active STA interface, use that
3817 * interface's BSSID, otherwise use a dummy one
3818 * (where the OUI part needs to be nonzero for
3819 * the BSSID to be accepted by POST_SCAN).
3820 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003821 mwl8k_vif = mwl8k_first_vif(priv);
3822 if (mwl8k_vif != NULL)
3823 bssid = mwl8k_vif->vif->bss_conf.bssid;
3824 else
3825 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003826
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003827 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003828 }
3829 }
3830
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003831 /*
3832 * If FIF_ALLMULTI is being requested, throw away the command
3833 * packet that ->prepare_multicast() built and replace it with
3834 * a command packet that enables reception of all multicast
3835 * packets.
3836 */
3837 if (*total_flags & FIF_ALLMULTI) {
3838 kfree(cmd);
Jiri Pirko22bedad2010-04-01 21:22:57 +00003839 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003840 }
3841
3842 if (cmd != NULL) {
3843 mwl8k_post_cmd(hw, cmd);
3844 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003845 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003846
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003847 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003848}
3849
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003850static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3851{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003852 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003853}
3854
Johannes Berg4a6967b2010-02-19 19:18:37 +01003855static int mwl8k_sta_remove(struct ieee80211_hw *hw,
3856 struct ieee80211_vif *vif,
3857 struct ieee80211_sta *sta)
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003858{
3859 struct mwl8k_priv *priv = hw->priv;
3860
Johannes Berg4a6967b2010-02-19 19:18:37 +01003861 if (priv->ap_fw)
3862 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
3863 else
3864 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
3865}
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003866
Johannes Berg4a6967b2010-02-19 19:18:37 +01003867static int mwl8k_sta_add(struct ieee80211_hw *hw,
3868 struct ieee80211_vif *vif,
3869 struct ieee80211_sta *sta)
3870{
3871 struct mwl8k_priv *priv = hw->priv;
3872 int ret;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003873
Johannes Berg4a6967b2010-02-19 19:18:37 +01003874 if (!priv->ap_fw) {
3875 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
3876 if (ret >= 0) {
3877 MWL8K_STA(sta)->peer_id = ret;
3878 return 0;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003879 }
Johannes Berg4a6967b2010-02-19 19:18:37 +01003880
3881 return ret;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003882 }
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003883
Johannes Berg4a6967b2010-02-19 19:18:37 +01003884 return mwl8k_cmd_set_new_stn_add(hw, vif, sta);
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003885}
3886
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003887static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3888 const struct ieee80211_tx_queue_params *params)
3889{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003890 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003891 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003892
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003893 rc = mwl8k_fw_lock(hw);
3894 if (!rc) {
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08003895 BUG_ON(queue > MWL8K_TX_QUEUES - 1);
3896 memcpy(&priv->wmm_params[queue], params, sizeof(*params));
3897
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003898 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003899 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003900
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003901 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003902 rc = mwl8k_cmd_set_edca_params(hw, queue,
3903 params->cw_min,
3904 params->cw_max,
3905 params->aifs,
3906 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003907
3908 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003909 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003910
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003911 return rc;
3912}
3913
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003914static int mwl8k_get_stats(struct ieee80211_hw *hw,
3915 struct ieee80211_low_level_stats *stats)
3916{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003917 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003918}
3919
John W. Linville0d462bb2010-07-28 14:04:24 -04003920static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
3921 struct survey_info *survey)
3922{
3923 struct mwl8k_priv *priv = hw->priv;
3924 struct ieee80211_conf *conf = &hw->conf;
3925
3926 if (idx != 0)
3927 return -ENOENT;
3928
3929 survey->channel = conf->channel;
3930 survey->filled = SURVEY_INFO_NOISE_DBM;
3931 survey->noise = priv->noise;
3932
3933 return 0;
3934}
3935
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003936static int
3937mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3938 enum ieee80211_ampdu_mlme_action action,
3939 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3940{
3941 switch (action) {
3942 case IEEE80211_AMPDU_RX_START:
3943 case IEEE80211_AMPDU_RX_STOP:
3944 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3945 return -ENOTSUPP;
3946 return 0;
3947 default:
3948 return -ENOTSUPP;
3949 }
3950}
3951
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003952static const struct ieee80211_ops mwl8k_ops = {
3953 .tx = mwl8k_tx,
3954 .start = mwl8k_start,
3955 .stop = mwl8k_stop,
3956 .add_interface = mwl8k_add_interface,
3957 .remove_interface = mwl8k_remove_interface,
3958 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003959 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003960 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003961 .configure_filter = mwl8k_configure_filter,
3962 .set_rts_threshold = mwl8k_set_rts_threshold,
Johannes Berg4a6967b2010-02-19 19:18:37 +01003963 .sta_add = mwl8k_sta_add,
3964 .sta_remove = mwl8k_sta_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003965 .conf_tx = mwl8k_conf_tx,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003966 .get_stats = mwl8k_get_stats,
John W. Linville0d462bb2010-07-28 14:04:24 -04003967 .get_survey = mwl8k_get_survey,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003968 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003969};
3970
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003971static void mwl8k_finalize_join_worker(struct work_struct *work)
3972{
3973 struct mwl8k_priv *priv =
3974 container_of(work, struct mwl8k_priv, finalize_join_worker);
3975 struct sk_buff *skb = priv->beacon_skb;
Johannes Berg56007a02010-01-26 14:19:52 +01003976 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3977 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
3978 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
3979 mgmt->u.beacon.variable, len);
3980 int dtim_period = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003981
Johannes Berg56007a02010-01-26 14:19:52 +01003982 if (tim && tim[1] >= 2)
3983 dtim_period = tim[3];
3984
3985 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003986
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003987 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003988 priv->beacon_skb = NULL;
3989}
3990
John W. Linvillebcb628d2009-11-06 16:40:16 -05003991enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003992 MWL8363 = 0,
3993 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003994 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003995};
3996
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08003997#define MWL8K_8366_AP_FW_API 1
3998#define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
3999#define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
4000
John W. Linvillebcb628d2009-11-06 16:40:16 -05004001static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01004002 [MWL8363] = {
4003 .part_name = "88w8363",
4004 .helper_image = "mwl8k/helper_8363.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004005 .fw_image_sta = "mwl8k/fmimage_8363.fw",
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01004006 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01004007 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05004008 .part_name = "88w8687",
4009 .helper_image = "mwl8k/helper_8687.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004010 .fw_image_sta = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05004011 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01004012 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05004013 .part_name = "88w8366",
4014 .helper_image = "mwl8k/helper_8366.fw",
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004015 .fw_image_sta = "mwl8k/fmimage_8366.fw",
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08004016 .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
4017 .fw_api_ap = MWL8K_8366_AP_FW_API,
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01004018 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05004019 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004020};
4021
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01004022MODULE_FIRMWARE("mwl8k/helper_8363.fw");
4023MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
4024MODULE_FIRMWARE("mwl8k/helper_8687.fw");
4025MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
4026MODULE_FIRMWARE("mwl8k/helper_8366.fw");
4027MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
Brian Cavagnolo952a0e92010-11-12 17:23:51 -08004028MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01004029
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004030static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Benjamin Larssone5868ba2010-03-19 01:46:10 +01004031 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01004032 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
4033 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05004034 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
4035 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
4036 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01004037 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05004038 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004039};
4040MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
4041
Brian Cavagnolo99020472010-11-12 17:23:52 -08004042static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
4043{
4044 int rc;
4045 printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
4046 "Trying alternative firmware %s\n", pci_name(priv->pdev),
4047 priv->fw_pref, priv->fw_alt);
4048 rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
4049 if (rc) {
4050 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
4051 pci_name(priv->pdev), priv->fw_alt);
4052 return rc;
4053 }
4054 return 0;
4055}
4056
4057static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
4058static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
4059{
4060 struct mwl8k_priv *priv = context;
4061 struct mwl8k_device_info *di = priv->device_info;
4062 int rc;
4063
4064 switch (priv->fw_state) {
4065 case FW_STATE_INIT:
4066 if (!fw) {
4067 printk(KERN_ERR "%s: Error requesting helper fw %s\n",
4068 pci_name(priv->pdev), di->helper_image);
4069 goto fail;
4070 }
4071 priv->fw_helper = fw;
4072 rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
4073 true);
4074 if (rc && priv->fw_alt) {
4075 rc = mwl8k_request_alt_fw(priv);
4076 if (rc)
4077 goto fail;
4078 priv->fw_state = FW_STATE_LOADING_ALT;
4079 } else if (rc)
4080 goto fail;
4081 else
4082 priv->fw_state = FW_STATE_LOADING_PREF;
4083 break;
4084
4085 case FW_STATE_LOADING_PREF:
4086 if (!fw) {
4087 if (priv->fw_alt) {
4088 rc = mwl8k_request_alt_fw(priv);
4089 if (rc)
4090 goto fail;
4091 priv->fw_state = FW_STATE_LOADING_ALT;
4092 } else
4093 goto fail;
4094 } else {
4095 priv->fw_ucode = fw;
4096 rc = mwl8k_firmware_load_success(priv);
4097 if (rc)
4098 goto fail;
4099 else
4100 complete(&priv->firmware_loading_complete);
4101 }
4102 break;
4103
4104 case FW_STATE_LOADING_ALT:
4105 if (!fw) {
4106 printk(KERN_ERR "%s: Error requesting alt fw %s\n",
4107 pci_name(priv->pdev), di->helper_image);
4108 goto fail;
4109 }
4110 priv->fw_ucode = fw;
4111 rc = mwl8k_firmware_load_success(priv);
4112 if (rc)
4113 goto fail;
4114 else
4115 complete(&priv->firmware_loading_complete);
4116 break;
4117
4118 default:
4119 printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
4120 MWL8K_NAME, priv->fw_state);
4121 BUG_ON(1);
4122 }
4123
4124 return;
4125
4126fail:
4127 priv->fw_state = FW_STATE_ERROR;
4128 complete(&priv->firmware_loading_complete);
4129 device_release_driver(&priv->pdev->dev);
4130 mwl8k_release_firmware(priv);
4131}
4132
4133static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
4134 bool nowait)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004135{
4136 struct mwl8k_priv *priv = hw->priv;
4137 int rc;
4138
4139 /* Reset firmware and hardware */
4140 mwl8k_hw_reset(priv);
4141
4142 /* Ask userland hotplug daemon for the device firmware */
Brian Cavagnolo99020472010-11-12 17:23:52 -08004143 rc = mwl8k_request_firmware(priv, fw_image, nowait);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004144 if (rc) {
4145 wiphy_err(hw->wiphy, "Firmware files not found\n");
4146 return rc;
4147 }
4148
Brian Cavagnolo99020472010-11-12 17:23:52 -08004149 if (nowait)
4150 return rc;
4151
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004152 /* Load firmware into hardware */
4153 rc = mwl8k_load_firmware(hw);
4154 if (rc)
4155 wiphy_err(hw->wiphy, "Cannot start firmware\n");
4156
4157 /* Reclaim memory once firmware is successfully loaded */
4158 mwl8k_release_firmware(priv);
4159
4160 return rc;
4161}
4162
4163/* initialize hw after successfully loading a firmware image */
4164static int mwl8k_probe_hw(struct ieee80211_hw *hw)
4165{
4166 struct mwl8k_priv *priv = hw->priv;
4167 int rc = 0;
4168 int i;
4169
4170 if (priv->ap_fw) {
4171 priv->rxd_ops = priv->device_info->ap_rxd_ops;
4172 if (priv->rxd_ops == NULL) {
4173 wiphy_err(hw->wiphy,
4174 "Driver does not have AP firmware image support for this hardware\n");
4175 goto err_stop_firmware;
4176 }
4177 } else {
4178 priv->rxd_ops = &rxd_sta_ops;
4179 }
4180
4181 priv->sniffer_enabled = false;
4182 priv->wmm_enabled = false;
4183 priv->pending_tx_pkts = 0;
4184
4185 rc = mwl8k_rxq_init(hw, 0);
4186 if (rc)
4187 goto err_stop_firmware;
4188 rxq_refill(hw, 0, INT_MAX);
4189
4190 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
4191 rc = mwl8k_txq_init(hw, i);
4192 if (rc)
4193 goto err_free_queues;
4194 }
4195
4196 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
4197 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4198 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
4199 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
4200 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4201
4202 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
4203 IRQF_SHARED, MWL8K_NAME, hw);
4204 if (rc) {
4205 wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
4206 goto err_free_queues;
4207 }
4208
4209 /*
4210 * Temporarily enable interrupts. Initial firmware host
4211 * commands use interrupts and avoid polling. Disable
4212 * interrupts when done.
4213 */
4214 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4215
4216 /* Get config data, mac addrs etc */
4217 if (priv->ap_fw) {
4218 rc = mwl8k_cmd_get_hw_spec_ap(hw);
4219 if (!rc)
4220 rc = mwl8k_cmd_set_hw_spec(hw);
4221 } else {
4222 rc = mwl8k_cmd_get_hw_spec_sta(hw);
4223 }
4224 if (rc) {
4225 wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
4226 goto err_free_irq;
4227 }
4228
4229 /* Turn radio off */
4230 rc = mwl8k_cmd_radio_disable(hw);
4231 if (rc) {
4232 wiphy_err(hw->wiphy, "Cannot disable\n");
4233 goto err_free_irq;
4234 }
4235
4236 /* Clear MAC address */
4237 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
4238 if (rc) {
4239 wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
4240 goto err_free_irq;
4241 }
4242
4243 /* Disable interrupts */
4244 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4245 free_irq(priv->pdev->irq, hw);
4246
4247 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
4248 priv->device_info->part_name,
4249 priv->hw_rev, hw->wiphy->perm_addr,
4250 priv->ap_fw ? "AP" : "STA",
4251 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4252 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
4253
4254 return 0;
4255
4256err_free_irq:
4257 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
4258 free_irq(priv->pdev->irq, hw);
4259
4260err_free_queues:
4261 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4262 mwl8k_txq_deinit(hw, i);
4263 mwl8k_rxq_deinit(hw, 0);
4264
4265err_stop_firmware:
4266 mwl8k_hw_reset(priv);
4267
4268 return rc;
4269}
4270
4271/*
4272 * invoke mwl8k_reload_firmware to change the firmware image after the device
4273 * has already been registered
4274 */
4275static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
4276{
4277 int i, rc = 0;
4278 struct mwl8k_priv *priv = hw->priv;
4279
4280 mwl8k_stop(hw);
4281 mwl8k_rxq_deinit(hw, 0);
4282
4283 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4284 mwl8k_txq_deinit(hw, i);
4285
Brian Cavagnolo99020472010-11-12 17:23:52 -08004286 rc = mwl8k_init_firmware(hw, fw_image, false);
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004287 if (rc)
4288 goto fail;
4289
4290 rc = mwl8k_probe_hw(hw);
4291 if (rc)
4292 goto fail;
4293
4294 rc = mwl8k_start(hw);
4295 if (rc)
4296 goto fail;
4297
4298 rc = mwl8k_config(hw, ~0);
4299 if (rc)
4300 goto fail;
4301
4302 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
4303 rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
4304 if (rc)
4305 goto fail;
4306 }
4307
4308 return rc;
4309
4310fail:
4311 printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
4312 return rc;
4313}
4314
4315static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
4316{
4317 struct ieee80211_hw *hw = priv->hw;
4318 int i, rc;
4319
Brian Cavagnolo99020472010-11-12 17:23:52 -08004320 rc = mwl8k_load_firmware(hw);
4321 mwl8k_release_firmware(priv);
4322 if (rc) {
4323 wiphy_err(hw->wiphy, "Cannot start firmware\n");
4324 return rc;
4325 }
4326
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004327 /*
4328 * Extra headroom is the size of the required DMA header
4329 * minus the size of the smallest 802.11 frame (CTS frame).
4330 */
4331 hw->extra_tx_headroom =
4332 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
4333
4334 hw->channel_change_time = 10;
4335
4336 hw->queues = MWL8K_TX_QUEUES;
4337
4338 /* Set rssi values to dBm */
4339 hw->flags |= IEEE80211_HW_SIGNAL_DBM;
4340 hw->vif_data_size = sizeof(struct mwl8k_vif);
4341 hw->sta_data_size = sizeof(struct mwl8k_sta);
4342
4343 priv->macids_used = 0;
4344 INIT_LIST_HEAD(&priv->vif_list);
4345
4346 /* Set default radio state and preamble */
4347 priv->radio_on = 0;
4348 priv->radio_short_preamble = 0;
4349
4350 /* Finalize join worker */
4351 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
4352
4353 /* TX reclaim and RX tasklets. */
4354 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
4355 tasklet_disable(&priv->poll_tx_task);
4356 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
4357 tasklet_disable(&priv->poll_rx_task);
4358
4359 /* Power management cookie */
4360 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
4361 if (priv->cookie == NULL)
4362 return -ENOMEM;
4363
4364 mutex_init(&priv->fw_mutex);
4365 priv->fw_mutex_owner = NULL;
4366 priv->fw_mutex_depth = 0;
4367 priv->hostcmd_wait = NULL;
4368
4369 spin_lock_init(&priv->tx_lock);
4370
4371 priv->tx_wait = NULL;
4372
4373 rc = mwl8k_probe_hw(hw);
4374 if (rc)
4375 goto err_free_cookie;
4376
4377 hw->wiphy->interface_modes = 0;
4378 if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
4379 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
4380 if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
4381 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
4382
4383 rc = ieee80211_register_hw(hw);
4384 if (rc) {
4385 wiphy_err(hw->wiphy, "Cannot register device\n");
4386 goto err_unprobe_hw;
4387 }
4388
4389 return 0;
4390
4391err_unprobe_hw:
4392 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4393 mwl8k_txq_deinit(hw, i);
4394 mwl8k_rxq_deinit(hw, 0);
4395
4396err_free_cookie:
4397 if (priv->cookie != NULL)
4398 pci_free_consistent(priv->pdev, 4,
4399 priv->cookie, priv->cookie_dma);
4400
4401 return rc;
4402}
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004403static int __devinit mwl8k_probe(struct pci_dev *pdev,
4404 const struct pci_device_id *id)
4405{
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004406 static int printed_version;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004407 struct ieee80211_hw *hw;
4408 struct mwl8k_priv *priv;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004409 struct mwl8k_device_info *di;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004410 int rc;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02004411
4412 if (!printed_version) {
4413 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
4414 printed_version = 1;
4415 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004416
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004417
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004418 rc = pci_enable_device(pdev);
4419 if (rc) {
4420 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
4421 MWL8K_NAME);
4422 return rc;
4423 }
4424
4425 rc = pci_request_regions(pdev, MWL8K_NAME);
4426 if (rc) {
4427 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
4428 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004429 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004430 }
4431
4432 pci_set_master(pdev);
4433
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004434
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004435 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
4436 if (hw == NULL) {
4437 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
4438 rc = -ENOMEM;
4439 goto err_free_reg;
4440 }
4441
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004442 SET_IEEE80211_DEV(hw, &pdev->dev);
4443 pci_set_drvdata(pdev, hw);
4444
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004445 priv = hw->priv;
4446 priv->hw = hw;
4447 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05004448 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004449
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004450
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004451 priv->sram = pci_iomap(pdev, 0, 0x10000);
4452 if (priv->sram == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07004453 wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004454 goto err_iounmap;
4455 }
4456
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004457 /*
4458 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
4459 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
4460 */
4461 priv->regs = pci_iomap(pdev, 1, 0x10000);
4462 if (priv->regs == NULL) {
4463 priv->regs = pci_iomap(pdev, 2, 0x10000);
4464 if (priv->regs == NULL) {
Joe Perches5db55842010-08-11 19:11:19 -07004465 wiphy_err(hw->wiphy, "Cannot map device registers\n");
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004466 goto err_iounmap;
4467 }
4468 }
4469
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004470 /*
Brian Cavagnolo99020472010-11-12 17:23:52 -08004471 * Choose the initial fw image depending on user input. If a second
4472 * image is available, make it the alternative image that will be
4473 * loaded if the first one fails.
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004474 */
Brian Cavagnolo99020472010-11-12 17:23:52 -08004475 init_completion(&priv->firmware_loading_complete);
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004476 di = priv->device_info;
Brian Cavagnolo99020472010-11-12 17:23:52 -08004477 if (ap_mode_default && di->fw_image_ap) {
4478 priv->fw_pref = di->fw_image_ap;
4479 priv->fw_alt = di->fw_image_sta;
4480 } else if (!ap_mode_default && di->fw_image_sta) {
4481 priv->fw_pref = di->fw_image_sta;
4482 priv->fw_alt = di->fw_image_ap;
4483 } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004484 printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08004485 priv->fw_pref = di->fw_image_sta;
Brian Cavagnolo0863ade2010-11-12 17:23:50 -08004486 } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
4487 printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
Brian Cavagnolo99020472010-11-12 17:23:52 -08004488 priv->fw_pref = di->fw_image_ap;
4489 }
4490 rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004491 if (rc)
Brian Cavagnolo3cc77722010-11-12 17:23:49 -08004492 goto err_stop_firmware;
Brian Cavagnolo99020472010-11-12 17:23:52 -08004493 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004494
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004495err_stop_firmware:
4496 mwl8k_hw_reset(priv);
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004497
4498err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004499 if (priv->regs != NULL)
4500 pci_iounmap(pdev, priv->regs);
4501
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004502 if (priv->sram != NULL)
4503 pci_iounmap(pdev, priv->sram);
4504
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004505 pci_set_drvdata(pdev, NULL);
4506 ieee80211_free_hw(hw);
4507
4508err_free_reg:
4509 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004510
4511err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004512 pci_disable_device(pdev);
4513
4514 return rc;
4515}
4516
Joerg Albert230f7af2009-04-18 02:10:45 +02004517static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004518{
4519 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4520}
4521
Joerg Albert230f7af2009-04-18 02:10:45 +02004522static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004523{
4524 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4525 struct mwl8k_priv *priv;
4526 int i;
4527
4528 if (hw == NULL)
4529 return;
4530 priv = hw->priv;
4531
Brian Cavagnolo99020472010-11-12 17:23:52 -08004532 wait_for_completion(&priv->firmware_loading_complete);
4533
4534 if (priv->fw_state == FW_STATE_ERROR) {
4535 mwl8k_hw_reset(priv);
4536 goto unmap;
4537 }
4538
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004539 ieee80211_stop_queues(hw);
4540
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02004541 ieee80211_unregister_hw(hw);
4542
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004543 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004544 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004545 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004546
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004547 /* Stop hardware */
4548 mwl8k_hw_reset(priv);
4549
4550 /* Return all skbs to mac80211 */
4551 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004552 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004553
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004554 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4555 mwl8k_txq_deinit(hw, i);
4556
4557 mwl8k_rxq_deinit(hw, 0);
4558
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004559 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004560
Brian Cavagnolo99020472010-11-12 17:23:52 -08004561unmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004562 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004563 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004564 pci_set_drvdata(pdev, NULL);
4565 ieee80211_free_hw(hw);
4566 pci_release_regions(pdev);
4567 pci_disable_device(pdev);
4568}
4569
4570static struct pci_driver mwl8k_driver = {
4571 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004572 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004573 .probe = mwl8k_probe,
4574 .remove = __devexit_p(mwl8k_remove),
4575 .shutdown = __devexit_p(mwl8k_shutdown),
4576};
4577
4578static int __init mwl8k_init(void)
4579{
4580 return pci_register_driver(&mwl8k_driver);
4581}
4582
4583static void __exit mwl8k_exit(void)
4584{
4585 pci_unregister_driver(&mwl8k_driver);
4586}
4587
4588module_init(mwl8k_init);
4589module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004590
4591MODULE_DESCRIPTION(MWL8K_DESC);
4592MODULE_VERSION(MWL8K_VERSION);
4593MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4594MODULE_LICENSE("GPL");