blob: 8bec4652fda1aa690ea408efa88724a5b0052432 [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 Buytenheka145d572009-08-18 04:34:26 +02005 * Copyright (C) 2008-2009 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>
22#include <net/mac80211.h>
23#include <linux/moduleparam.h>
24#include <linux/firmware.h>
25#include <linux/workqueue.h>
26
27#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
28#define MWL8K_NAME KBUILD_MODNAME
Lennert Buytenheka145d572009-08-18 04:34:26 +020029#define MWL8K_VERSION "0.10"
Lennert Buytenheka66098d2009-03-10 10:13:33 +010030
Lennert Buytenheka66098d2009-03-10 10:13:33 +010031/* Register definitions */
32#define MWL8K_HIU_GEN_PTR 0x00000c10
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020033#define MWL8K_MODE_STA 0x0000005a
34#define MWL8K_MODE_AP 0x000000a5
Lennert Buytenheka66098d2009-03-10 10:13:33 +010035#define MWL8K_HIU_INT_CODE 0x00000c14
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020036#define MWL8K_FWSTA_READY 0xf0f1f2f4
37#define MWL8K_FWAP_READY 0xf1f2f4a5
38#define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
Lennert Buytenheka66098d2009-03-10 10:13:33 +010039#define MWL8K_HIU_SCRATCH 0x00000c40
40
41/* Host->device communications */
42#define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
43#define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
44#define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
45#define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
46#define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020047#define MWL8K_H2A_INT_DUMMY (1 << 20)
48#define MWL8K_H2A_INT_RESET (1 << 15)
49#define MWL8K_H2A_INT_DOORBELL (1 << 1)
50#define MWL8K_H2A_INT_PPA_READY (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010051
52/* Device->host communications */
53#define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
54#define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
55#define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
56#define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
57#define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020058#define MWL8K_A2H_INT_DUMMY (1 << 20)
59#define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
60#define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
61#define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
62#define MWL8K_A2H_INT_RADIO_ON (1 << 6)
63#define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
64#define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
65#define MWL8K_A2H_INT_OPC_DONE (1 << 2)
66#define MWL8K_A2H_INT_RX_READY (1 << 1)
67#define MWL8K_A2H_INT_TX_DONE (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010068
69#define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
70 MWL8K_A2H_INT_CHNL_SWITCHED | \
71 MWL8K_A2H_INT_QUEUE_EMPTY | \
72 MWL8K_A2H_INT_RADAR_DETECT | \
73 MWL8K_A2H_INT_RADIO_ON | \
74 MWL8K_A2H_INT_RADIO_OFF | \
75 MWL8K_A2H_INT_MAC_EVENT | \
76 MWL8K_A2H_INT_OPC_DONE | \
77 MWL8K_A2H_INT_RX_READY | \
78 MWL8K_A2H_INT_TX_DONE)
79
Lennert Buytenheka66098d2009-03-10 10:13:33 +010080#define MWL8K_RX_QUEUES 1
81#define MWL8K_TX_QUEUES 4
82
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020083struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +020084 char *part_name;
85 char *helper_image;
86 char *fw_image;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020087};
88
Lennert Buytenheka66098d2009-03-10 10:13:33 +010089struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020090 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +010091
92 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020093 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +010094
95 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020096 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +010097
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020098 struct mwl8k_rx_desc *rxd;
99 dma_addr_t rxd_dma;
100 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100101};
102
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100103struct mwl8k_tx_queue {
104 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200105 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100106
107 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200108 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100109
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200110 struct ieee80211_tx_queue_stats stats;
111 struct mwl8k_tx_desc *txd;
112 dma_addr_t txd_dma;
113 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100114};
115
116/* Pointers to the firmware data and meta information about it. */
117struct mwl8k_firmware {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100118 /* Boot helper code */
119 struct firmware *helper;
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200120
121 /* Microcode */
122 struct firmware *ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100123};
124
125struct mwl8k_priv {
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +0200126 void __iomem *sram;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100127 void __iomem *regs;
128 struct ieee80211_hw *hw;
129
130 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200132 struct mwl8k_device_info *device_info;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200133 bool ap_fw;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200134
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100135 /* firmware files and meta data */
136 struct mwl8k_firmware fw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100137
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200138 /* firmware access */
139 struct mutex fw_mutex;
140 struct task_struct *fw_mutex_owner;
141 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200142 struct completion *hostcmd_wait;
143
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100144 /* lock held over TX and TX reap */
145 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100146
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200147 /* TX quiesce completion, protected by fw_mutex and tx_lock */
148 struct completion *tx_wait;
149
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100150 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100151
152 struct ieee80211_channel *current_channel;
153
154 /* power management status cookie from firmware */
155 u32 *cookie;
156 dma_addr_t cookie_dma;
157
158 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100159 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200160 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100161
162 /*
163 * Running count of TX packets in flight, to avoid
164 * iterating over the transmit rings each time.
165 */
166 int pending_tx_pkts;
167
168 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
169 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
170
171 /* PHY parameters */
172 struct ieee80211_supported_band band;
173 struct ieee80211_channel channels[14];
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200174 struct ieee80211_rate rates[13];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100175
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200176 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200177 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200178 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200179 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100180
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100181 /* XXX need to convert this to handle multiple interfaces */
182 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200183 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100184 struct sk_buff *beacon_skb;
185
186 /*
187 * This FJ worker has to be global as it is scheduled from the
188 * RX handler. At this point we don't know which interface it
189 * belongs to until the list of bssids waiting to complete join
190 * is checked.
191 */
192 struct work_struct finalize_join_worker;
193
194 /* Tasklet to reclaim TX descriptors and buffers after tx */
195 struct tasklet_struct tx_reclaim_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100196};
197
198/* Per interface specific private data */
199struct mwl8k_vif {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100200 /* backpointer to parent config block */
201 struct mwl8k_priv *priv;
202
203 /* BSS config of AP or IBSS from mac80211*/
204 struct ieee80211_bss_conf bss_info;
205
206 /* BSSID of AP or IBSS */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200207 u8 bssid[ETH_ALEN];
208 u8 mac_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100209
210 /*
211 * Subset of supported legacy rates.
212 * Intersection of AP and STA supported rates.
213 */
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200214 struct ieee80211_rate legacy_rates[13];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100215
216 /* number of supported legacy rates */
217 u8 legacy_nrates;
218
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100219 /* Index into station database.Returned by update_sta_db call */
220 u8 peer_id;
221
222 /* Non AMPDU sequence number assigned by driver */
223 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100224};
225
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200226#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100227
228static const struct ieee80211_channel mwl8k_channels[] = {
229 { .center_freq = 2412, .hw_value = 1, },
230 { .center_freq = 2417, .hw_value = 2, },
231 { .center_freq = 2422, .hw_value = 3, },
232 { .center_freq = 2427, .hw_value = 4, },
233 { .center_freq = 2432, .hw_value = 5, },
234 { .center_freq = 2437, .hw_value = 6, },
235 { .center_freq = 2442, .hw_value = 7, },
236 { .center_freq = 2447, .hw_value = 8, },
237 { .center_freq = 2452, .hw_value = 9, },
238 { .center_freq = 2457, .hw_value = 10, },
239 { .center_freq = 2462, .hw_value = 11, },
240};
241
242static const struct ieee80211_rate mwl8k_rates[] = {
243 { .bitrate = 10, .hw_value = 2, },
244 { .bitrate = 20, .hw_value = 4, },
245 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200246 { .bitrate = 110, .hw_value = 22, },
247 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100248 { .bitrate = 60, .hw_value = 12, },
249 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100250 { .bitrate = 120, .hw_value = 24, },
251 { .bitrate = 180, .hw_value = 36, },
252 { .bitrate = 240, .hw_value = 48, },
253 { .bitrate = 360, .hw_value = 72, },
254 { .bitrate = 480, .hw_value = 96, },
255 { .bitrate = 540, .hw_value = 108, },
256};
257
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100258/* Set or get info from Firmware */
259#define MWL8K_CMD_SET 0x0001
260#define MWL8K_CMD_GET 0x0000
261
262/* Firmware command codes */
263#define MWL8K_CMD_CODE_DNLD 0x0001
264#define MWL8K_CMD_GET_HW_SPEC 0x0003
265#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
266#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200267#define MWL8K_CMD_RADIO_CONTROL 0x001c
268#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100269#define MWL8K_CMD_SET_PRE_SCAN 0x0107
270#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200271#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100272#define MWL8K_CMD_SET_AID 0x010d
273#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200274#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100275#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200276#define MWL8K_CMD_SET_SLOT 0x0114
277#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
278#define MWL8K_CMD_SET_WMM_MODE 0x0123
279#define MWL8K_CMD_MIMO_CONFIG 0x0125
280#define MWL8K_CMD_USE_FIXED_RATE 0x0126
281#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200282#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200283#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
284#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100285
286static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
287{
288#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
289 snprintf(buf, bufsize, "%s", #x);\
290 return buf;\
291 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200292 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100293 MWL8K_CMDNAME(CODE_DNLD);
294 MWL8K_CMDNAME(GET_HW_SPEC);
295 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
296 MWL8K_CMDNAME(GET_STAT);
297 MWL8K_CMDNAME(RADIO_CONTROL);
298 MWL8K_CMDNAME(RF_TX_POWER);
299 MWL8K_CMDNAME(SET_PRE_SCAN);
300 MWL8K_CMDNAME(SET_POST_SCAN);
301 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100302 MWL8K_CMDNAME(SET_AID);
303 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200304 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100305 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200306 MWL8K_CMDNAME(SET_SLOT);
307 MWL8K_CMDNAME(SET_EDCA_PARAMS);
308 MWL8K_CMDNAME(SET_WMM_MODE);
309 MWL8K_CMDNAME(MIMO_CONFIG);
310 MWL8K_CMDNAME(USE_FIXED_RATE);
311 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200312 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200313 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
314 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100315 default:
316 snprintf(buf, bufsize, "0x%x", cmd);
317 }
318#undef MWL8K_CMDNAME
319
320 return buf;
321}
322
323/* Hardware and firmware reset */
324static void mwl8k_hw_reset(struct mwl8k_priv *priv)
325{
326 iowrite32(MWL8K_H2A_INT_RESET,
327 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
328 iowrite32(MWL8K_H2A_INT_RESET,
329 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
330 msleep(20);
331}
332
333/* Release fw image */
334static void mwl8k_release_fw(struct firmware **fw)
335{
336 if (*fw == NULL)
337 return;
338 release_firmware(*fw);
339 *fw = NULL;
340}
341
342static void mwl8k_release_firmware(struct mwl8k_priv *priv)
343{
344 mwl8k_release_fw(&priv->fw.ucode);
345 mwl8k_release_fw(&priv->fw.helper);
346}
347
348/* Request fw image */
349static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200350 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100351{
352 /* release current image */
353 if (*fw != NULL)
354 mwl8k_release_fw(fw);
355
356 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200357 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100358}
359
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200360static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100361{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200362 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100363 int rc;
364
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200365 if (di->helper_image != NULL) {
366 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
367 if (rc) {
368 printk(KERN_ERR "%s: Error requesting helper "
369 "firmware file %s\n", pci_name(priv->pdev),
370 di->helper_image);
371 return rc;
372 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100373 }
374
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200375 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100376 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200377 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200378 pci_name(priv->pdev), di->fw_image);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100379 mwl8k_release_fw(&priv->fw.helper);
380 return rc;
381 }
382
383 return 0;
384}
385
386struct mwl8k_cmd_pkt {
387 __le16 code;
388 __le16 length;
389 __le16 seq_num;
390 __le16 result;
391 char payload[0];
392} __attribute__((packed));
393
394/*
395 * Firmware loading.
396 */
397static int
398mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
399{
400 void __iomem *regs = priv->regs;
401 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100402 int loops;
403
404 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
405 if (pci_dma_mapping_error(priv->pdev, dma_addr))
406 return -ENOMEM;
407
408 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
409 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
410 iowrite32(MWL8K_H2A_INT_DOORBELL,
411 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
412 iowrite32(MWL8K_H2A_INT_DUMMY,
413 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
414
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100415 loops = 1000;
416 do {
417 u32 int_code;
418
419 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
420 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
421 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100422 break;
423 }
424
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200425 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100426 udelay(1);
427 } while (--loops);
428
429 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
430
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200431 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100432}
433
434static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
435 const u8 *data, size_t length)
436{
437 struct mwl8k_cmd_pkt *cmd;
438 int done;
439 int rc = 0;
440
441 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
442 if (cmd == NULL)
443 return -ENOMEM;
444
445 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
446 cmd->seq_num = 0;
447 cmd->result = 0;
448
449 done = 0;
450 while (length) {
451 int block_size = length > 256 ? 256 : length;
452
453 memcpy(cmd->payload, data + done, block_size);
454 cmd->length = cpu_to_le16(block_size);
455
456 rc = mwl8k_send_fw_load_cmd(priv, cmd,
457 sizeof(*cmd) + block_size);
458 if (rc)
459 break;
460
461 done += block_size;
462 length -= block_size;
463 }
464
465 if (!rc) {
466 cmd->length = 0;
467 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
468 }
469
470 kfree(cmd);
471
472 return rc;
473}
474
475static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
476 const u8 *data, size_t length)
477{
478 unsigned char *buffer;
479 int may_continue, rc = 0;
480 u32 done, prev_block_size;
481
482 buffer = kmalloc(1024, GFP_KERNEL);
483 if (buffer == NULL)
484 return -ENOMEM;
485
486 done = 0;
487 prev_block_size = 0;
488 may_continue = 1000;
489 while (may_continue > 0) {
490 u32 block_size;
491
492 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
493 if (block_size & 1) {
494 block_size &= ~1;
495 may_continue--;
496 } else {
497 done += prev_block_size;
498 length -= prev_block_size;
499 }
500
501 if (block_size > 1024 || block_size > length) {
502 rc = -EOVERFLOW;
503 break;
504 }
505
506 if (length == 0) {
507 rc = 0;
508 break;
509 }
510
511 if (block_size == 0) {
512 rc = -EPROTO;
513 may_continue--;
514 udelay(1);
515 continue;
516 }
517
518 prev_block_size = block_size;
519 memcpy(buffer, data + done, block_size);
520
521 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
522 if (rc)
523 break;
524 }
525
526 if (!rc && length != 0)
527 rc = -EREMOTEIO;
528
529 kfree(buffer);
530
531 return rc;
532}
533
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200534static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100535{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200536 struct mwl8k_priv *priv = hw->priv;
537 struct firmware *fw = priv->fw.ucode;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200538 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200539 int rc;
540 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100541
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200542 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
543 struct firmware *helper = priv->fw.helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100544
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200545 if (helper == NULL) {
546 printk(KERN_ERR "%s: helper image needed but none "
547 "given\n", pci_name(priv->pdev));
548 return -EINVAL;
549 }
550
551 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100552 if (rc) {
553 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200554 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100555 return rc;
556 }
557 msleep(1);
558
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200559 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100560 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200561 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100562 }
563
564 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200565 printk(KERN_ERR "%s: unable to load firmware image\n",
566 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100567 return rc;
568 }
569
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200570 if (di->modes & BIT(NL80211_IFTYPE_AP))
571 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
572 else
573 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100574 msleep(1);
575
576 loops = 200000;
577 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200578 u32 ready_code;
579
580 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
581 if (ready_code == MWL8K_FWAP_READY) {
582 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100583 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200584 } else if (ready_code == MWL8K_FWSTA_READY) {
585 priv->ap_fw = 0;
586 break;
587 }
588
589 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100590 udelay(1);
591 } while (--loops);
592
593 return loops ? 0 : -ETIMEDOUT;
594}
595
596
597/*
598 * Defines shared between transmission and reception.
599 */
600/* HT control fields for firmware */
601struct ewc_ht_info {
602 __le16 control1;
603 __le16 control2;
604 __le16 control3;
605} __attribute__((packed));
606
607/* Firmware Station database operations */
608#define MWL8K_STA_DB_ADD_ENTRY 0
609#define MWL8K_STA_DB_MODIFY_ENTRY 1
610#define MWL8K_STA_DB_DEL_ENTRY 2
611#define MWL8K_STA_DB_FLUSH 3
612
613/* Peer Entry flags - used to define the type of the peer node */
614#define MWL8K_PEER_TYPE_ACCESSPOINT 2
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100615
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200616#define MWL8K_IEEE_LEGACY_DATA_RATES 13
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100617#define MWL8K_MCS_BITMAP_SIZE 16
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100618
619struct peer_capability_info {
620 /* Peer type - AP vs. STA. */
621 __u8 peer_type;
622
623 /* Basic 802.11 capabilities from assoc resp. */
624 __le16 basic_caps;
625
626 /* Set if peer supports 802.11n high throughput (HT). */
627 __u8 ht_support;
628
629 /* Valid if HT is supported. */
630 __le16 ht_caps;
631 __u8 extended_ht_caps;
632 struct ewc_ht_info ewc_info;
633
634 /* Legacy rate table. Intersection of our rates and peer rates. */
635 __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
636
637 /* HT rate table. Intersection of our rates and peer rates. */
638 __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +0200639 __u8 pad[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100640
641 /* If set, interoperability mode, no proprietary extensions. */
642 __u8 interop;
643 __u8 pad2;
644 __u8 station_id;
645 __le16 amsdu_enabled;
646} __attribute__((packed));
647
648/* Inline functions to manipulate QoS field in data descriptor. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100649static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
650{
651 u16 val_mask = 1 << 4;
652
653 /* End of Service Period Bit 4 */
654 return qos | val_mask;
655}
656
657static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
658{
659 u16 val_mask = 0x3;
660 u8 shift = 5;
661 u16 qos_mask = ~(val_mask << shift);
662
663 /* Ack Policy Bit 5-6 */
664 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
665}
666
667static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
668{
669 u16 val_mask = 1 << 7;
670
671 /* AMSDU present Bit 7 */
672 return qos | val_mask;
673}
674
675static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
676{
677 u16 val_mask = 0xff;
678 u8 shift = 8;
679 u16 qos_mask = ~(val_mask << shift);
680
681 /* Queue Length Bits 8-15 */
682 return (qos & qos_mask) | ((len & val_mask) << shift);
683}
684
685/* DMA header used by firmware and hardware. */
686struct mwl8k_dma_data {
687 __le16 fwlen;
688 struct ieee80211_hdr wh;
689} __attribute__((packed));
690
691/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200692static inline void mwl8k_remove_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100693{
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200694 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)skb->data;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100695 void *dst, *src = &tr->wh;
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200696 int hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100697 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
698
699 dst = (void *)tr + space;
700 if (dst != src) {
701 memmove(dst, src, hdrlen);
702 skb_pull(skb, space);
703 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100704}
705
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200706static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100707{
708 struct ieee80211_hdr *wh;
709 u32 hdrlen, pktlen;
710 struct mwl8k_dma_data *tr;
711
712 wh = (struct ieee80211_hdr *)skb->data;
713 hdrlen = ieee80211_hdrlen(wh->frame_control);
714 pktlen = skb->len;
715
716 /*
717 * Copy up/down the 802.11 header; the firmware requires
718 * we present a 2-byte payload length followed by a
719 * 4-address header (w/o QoS), followed (optionally) by
720 * any WEP/ExtIV header (but only filled in for CCMP).
721 */
722 if (hdrlen != sizeof(struct mwl8k_dma_data))
723 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
724
725 tr = (struct mwl8k_dma_data *)skb->data;
726 if (wh != &tr->wh)
727 memmove(&tr->wh, wh, hdrlen);
728
729 /* Clear addr4 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200730 memset(tr->wh.addr4, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100731
732 /*
733 * Firmware length is the length of the fully formed "802.11
734 * payload". That is, everything except for the 802.11 header.
735 * This includes all crypto material including the MIC.
736 */
737 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100738}
739
740
741/*
742 * Packet reception.
743 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100744#define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100745
746struct mwl8k_rx_desc {
747 __le16 pkt_len;
748 __u8 link_quality;
749 __u8 noise_level;
750 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200751 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100752 __le16 qos_control;
753 __le16 rate_info;
754 __le32 pad0[4];
755 __u8 rssi;
756 __u8 channel;
757 __le16 pad1;
758 __u8 rx_ctrl;
759 __u8 rx_status;
760 __u8 pad2[2];
761} __attribute__((packed));
762
763#define MWL8K_RX_DESCS 256
764#define MWL8K_RX_MAXSZ 3800
765
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200766#define RATE_INFO_SHORTPRE 0x8000
767#define RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
768#define RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
769#define RATE_INFO_40MHZ 0x0004
770#define RATE_INFO_SHORTGI 0x0002
771#define RATE_INFO_MCS_FORMAT 0x0001
772
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100773static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
774{
775 struct mwl8k_priv *priv = hw->priv;
776 struct mwl8k_rx_queue *rxq = priv->rxq + index;
777 int size;
778 int i;
779
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200780 rxq->rxd_count = 0;
781 rxq->head = 0;
782 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100783
784 size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc);
785
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200786 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
787 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100788 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200789 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100790 return -ENOMEM;
791 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200792 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100793
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200794 rxq->skb = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->skb), GFP_KERNEL);
795 if (rxq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100796 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200797 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200798 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100799 return -ENOMEM;
800 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200801 memset(rxq->skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100802
803 for (i = 0; i < MWL8K_RX_DESCS; i++) {
804 struct mwl8k_rx_desc *rx_desc;
805 int nexti;
806
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200807 rx_desc = rxq->rxd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100808 nexti = (i + 1) % MWL8K_RX_DESCS;
809
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200810 rx_desc->next_rxd_phys_addr =
811 cpu_to_le32(rxq->rxd_dma + nexti * sizeof(*rx_desc));
Rami Rosenc491bf12009-04-21 16:22:01 +0300812 rx_desc->rx_ctrl = MWL8K_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100813 }
814
815 return 0;
816}
817
818static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
819{
820 struct mwl8k_priv *priv = hw->priv;
821 struct mwl8k_rx_queue *rxq = priv->rxq + index;
822 int refilled;
823
824 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200825 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100826 struct sk_buff *skb;
827 int rx;
828
829 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
830 if (skb == NULL)
831 break;
832
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200833 rxq->rxd_count++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100834
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200835 rx = rxq->tail;
836 rxq->tail = (rx + 1) % MWL8K_RX_DESCS;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100837
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200838 rxq->rxd[rx].pkt_phys_addr =
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100839 cpu_to_le32(pci_map_single(priv->pdev, skb->data,
840 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE));
841
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200842 rxq->rxd[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ);
843 rxq->skb[rx] = skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100844 wmb();
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200845 rxq->rxd[rx].rx_ctrl = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100846
847 refilled++;
848 }
849
850 return refilled;
851}
852
853/* Must be called only when the card's reception is completely halted */
854static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
855{
856 struct mwl8k_priv *priv = hw->priv;
857 struct mwl8k_rx_queue *rxq = priv->rxq + index;
858 int i;
859
860 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200861 if (rxq->skb[i] != NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100862 unsigned long addr;
863
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200864 addr = le32_to_cpu(rxq->rxd[i].pkt_phys_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100865 pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ,
866 PCI_DMA_FROMDEVICE);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200867 kfree_skb(rxq->skb[i]);
868 rxq->skb[i] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100869 }
870 }
871
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200872 kfree(rxq->skb);
873 rxq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100874
875 pci_free_consistent(priv->pdev,
876 MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200877 rxq->rxd, rxq->rxd_dma);
878 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100879}
880
881
882/*
883 * Scan a list of BSSIDs to process for finalize join.
884 * Allows for extension to process multiple BSSIDs.
885 */
886static inline int
887mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
888{
889 return priv->capture_beacon &&
890 ieee80211_is_beacon(wh->frame_control) &&
891 !compare_ether_addr(wh->addr3, priv->capture_bssid);
892}
893
Lennert Buytenhek37797522009-10-22 20:19:45 +0200894static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
895 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100896{
Lennert Buytenhek37797522009-10-22 20:19:45 +0200897 struct mwl8k_priv *priv = hw->priv;
898
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100899 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200900 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100901
902 /*
903 * Use GFP_ATOMIC as rxq_process is called from
904 * the primary interrupt handler, memory allocation call
905 * must not sleep.
906 */
907 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
908 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +0200909 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100910}
911
912static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
913{
914 struct mwl8k_priv *priv = hw->priv;
915 struct mwl8k_rx_queue *rxq = priv->rxq + index;
916 int processed;
917
918 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200919 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100920 struct mwl8k_rx_desc *rx_desc;
921 struct sk_buff *skb;
922 struct ieee80211_rx_status status;
923 unsigned long addr;
924 struct ieee80211_hdr *wh;
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200925 u16 rate_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100926
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200927 rx_desc = rxq->rxd + rxq->head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100928 if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST))
929 break;
930 rmb();
931
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200932 skb = rxq->skb[rxq->head];
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +0200933 if (skb == NULL)
934 break;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200935 rxq->skb[rxq->head] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100936
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200937 rxq->head = (rxq->head + 1) % MWL8K_RX_DESCS;
938 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100939
940 addr = le32_to_cpu(rx_desc->pkt_phys_addr);
941 pci_unmap_single(priv->pdev, addr,
942 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
943
944 skb_put(skb, le16_to_cpu(rx_desc->pkt_len));
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200945 mwl8k_remove_dma_header(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100946
947 wh = (struct ieee80211_hdr *)skb->data;
948
949 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200950 * Check for a pending join operation. Save a
951 * copy of the beacon and schedule a tasklet to
952 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100953 */
954 if (mwl8k_capture_bssid(priv, wh))
Lennert Buytenhek37797522009-10-22 20:19:45 +0200955 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100956
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200957 rate_info = le16_to_cpu(rx_desc->rate_info);
958
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100959 memset(&status, 0, sizeof(status));
960 status.mactime = 0;
961 status.signal = -rx_desc->rssi;
962 status.noise = -rx_desc->noise_level;
963 status.qual = rx_desc->link_quality;
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200964 status.antenna = RATE_INFO_ANTSELECT(rate_info);
965 status.rate_idx = RATE_INFO_RATEID(rate_info);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100966 status.flag = 0;
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200967 if (rate_info & RATE_INFO_SHORTPRE)
968 status.flag |= RX_FLAG_SHORTPRE;
969 if (rate_info & RATE_INFO_40MHZ)
970 status.flag |= RX_FLAG_40MHZ;
971 if (rate_info & RATE_INFO_SHORTGI)
972 status.flag |= RX_FLAG_SHORT_GI;
973 if (rate_info & RATE_INFO_MCS_FORMAT)
974 status.flag |= RX_FLAG_HT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100975 status.band = IEEE80211_BAND_2GHZ;
976 status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
Johannes Bergf1d58c22009-06-17 13:13:00 +0200977 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
978 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100979
980 processed++;
981 }
982
983 return processed;
984}
985
986
987/*
988 * Packet transmission.
989 */
990
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100991/* Transmit packet ACK policy */
992#define MWL8K_TXD_ACK_POLICY_NORMAL 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100993#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
994
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100995#define MWL8K_TXD_STATUS_OK 0x00000001
996#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
997#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
998#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100999#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001000
1001struct mwl8k_tx_desc {
1002 __le32 status;
1003 __u8 data_rate;
1004 __u8 tx_priority;
1005 __le16 qos_control;
1006 __le32 pkt_phys_addr;
1007 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001008 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001009 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001010 __le32 reserved;
1011 __le16 rate_info;
1012 __u8 peer_id;
1013 __u8 tx_frag_cnt;
1014} __attribute__((packed));
1015
1016#define MWL8K_TX_DESCS 128
1017
1018static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1019{
1020 struct mwl8k_priv *priv = hw->priv;
1021 struct mwl8k_tx_queue *txq = priv->txq + index;
1022 int size;
1023 int i;
1024
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001025 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1026 txq->stats.limit = MWL8K_TX_DESCS;
1027 txq->head = 0;
1028 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001029
1030 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1031
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001032 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1033 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001034 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001035 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001036 return -ENOMEM;
1037 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001038 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001039
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001040 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1041 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001042 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001043 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001044 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001045 return -ENOMEM;
1046 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001047 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001048
1049 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1050 struct mwl8k_tx_desc *tx_desc;
1051 int nexti;
1052
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001053 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001054 nexti = (i + 1) % MWL8K_TX_DESCS;
1055
1056 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001057 tx_desc->next_txd_phys_addr =
1058 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001059 }
1060
1061 return 0;
1062}
1063
1064static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1065{
1066 iowrite32(MWL8K_H2A_INT_PPA_READY,
1067 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1068 iowrite32(MWL8K_H2A_INT_DUMMY,
1069 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1070 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1071}
1072
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001073struct mwl8k_txq_info {
1074 u32 fw_owned;
1075 u32 drv_owned;
1076 u32 unused;
1077 u32 len;
1078 u32 head;
1079 u32 tail;
1080};
1081
1082static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001083 struct mwl8k_txq_info *txinfo)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001084{
1085 int count, desc, status;
1086 struct mwl8k_tx_queue *txq;
1087 struct mwl8k_tx_desc *tx_desc;
1088 int ndescs = 0;
1089
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001090 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
1091
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001092 for (count = 0; count < MWL8K_TX_QUEUES; count++) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001093 txq = priv->txq + count;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001094 txinfo[count].len = txq->stats.len;
1095 txinfo[count].head = txq->head;
1096 txinfo[count].tail = txq->tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001097 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001098 tx_desc = txq->txd + desc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001099 status = le32_to_cpu(tx_desc->status);
1100
1101 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1102 txinfo[count].fw_owned++;
1103 else
1104 txinfo[count].drv_owned++;
1105
1106 if (tx_desc->pkt_len == 0)
1107 txinfo[count].unused++;
1108 }
1109 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001110
1111 return ndescs;
1112}
1113
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001114/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001115 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001116 */
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001117static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001118{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001119 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001120 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001121 u32 count;
1122 unsigned long timeout;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001123
1124 might_sleep();
1125
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001126 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001127 count = priv->pending_tx_pkts;
1128 if (count)
1129 priv->tx_wait = &tx_wait;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001130 spin_unlock_bh(&priv->tx_lock);
1131
1132 if (count) {
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001133 struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001134 int index;
1135 int newcount;
1136
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001137 timeout = wait_for_completion_timeout(&tx_wait,
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001138 msecs_to_jiffies(5000));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001139 if (timeout)
1140 return 0;
1141
1142 spin_lock_bh(&priv->tx_lock);
1143 priv->tx_wait = NULL;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001144 newcount = priv->pending_tx_pkts;
1145 mwl8k_scan_tx_ring(priv, txinfo);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001146 spin_unlock_bh(&priv->tx_lock);
1147
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001148 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001149 __func__, __LINE__, count, newcount);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001150
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001151 for (index = 0; index < MWL8K_TX_QUEUES; index++)
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001152 printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u "
1153 "DRV:%u U:%u\n",
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001154 index,
1155 txinfo[index].len,
1156 txinfo[index].head,
1157 txinfo[index].tail,
1158 txinfo[index].fw_owned,
1159 txinfo[index].drv_owned,
1160 txinfo[index].unused);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001161
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001162 return -ETIMEDOUT;
1163 }
1164
1165 return 0;
1166}
1167
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001168#define MWL8K_TXD_SUCCESS(status) \
1169 ((status) & (MWL8K_TXD_STATUS_OK | \
1170 MWL8K_TXD_STATUS_OK_RETRY | \
1171 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001172
1173static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1174{
1175 struct mwl8k_priv *priv = hw->priv;
1176 struct mwl8k_tx_queue *txq = priv->txq + index;
1177 int wake = 0;
1178
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001179 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001180 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001181 struct mwl8k_tx_desc *tx_desc;
1182 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001183 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001184 struct sk_buff *skb;
1185 struct ieee80211_tx_info *info;
1186 u32 status;
1187
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001188 tx = txq->head;
1189 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001190
1191 status = le32_to_cpu(tx_desc->status);
1192
1193 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1194 if (!force)
1195 break;
1196 tx_desc->status &=
1197 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1198 }
1199
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001200 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1201 BUG_ON(txq->stats.len == 0);
1202 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203 priv->pending_tx_pkts--;
1204
1205 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001206 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001207 skb = txq->skb[tx];
1208 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001209
1210 BUG_ON(skb == NULL);
1211 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1212
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001213 mwl8k_remove_dma_header(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001214
1215 /* Mark descriptor as unused */
1216 tx_desc->pkt_phys_addr = 0;
1217 tx_desc->pkt_len = 0;
1218
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001219 info = IEEE80211_SKB_CB(skb);
1220 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001221 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001222 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001223
1224 ieee80211_tx_status_irqsafe(hw, skb);
1225
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001226 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001227 }
1228
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001229 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001230 ieee80211_wake_queue(hw, index);
1231}
1232
1233/* must be called only when the card's transmit is completely halted */
1234static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1235{
1236 struct mwl8k_priv *priv = hw->priv;
1237 struct mwl8k_tx_queue *txq = priv->txq + index;
1238
1239 mwl8k_txq_reclaim(hw, index, 1);
1240
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001241 kfree(txq->skb);
1242 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001243
1244 pci_free_consistent(priv->pdev,
1245 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001246 txq->txd, txq->txd_dma);
1247 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001248}
1249
1250static int
1251mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1252{
1253 struct mwl8k_priv *priv = hw->priv;
1254 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001255 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001256 struct ieee80211_hdr *wh;
1257 struct mwl8k_tx_queue *txq;
1258 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001259 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001260 u32 txstatus;
1261 u8 txdatarate;
1262 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001263
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001264 wh = (struct ieee80211_hdr *)skb->data;
1265 if (ieee80211_is_data_qos(wh->frame_control))
1266 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1267 else
1268 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001269
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001270 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001271 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001272
1273 tx_info = IEEE80211_SKB_CB(skb);
1274 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001275
1276 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1277 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001278
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001279 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1280 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1281 mwl8k_vif->seqno = seqno++ % 4096;
1282 }
1283
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001284 /* Setup firmware control bit fields for each frame type. */
1285 txstatus = 0;
1286 txdatarate = 0;
1287 if (ieee80211_is_mgmt(wh->frame_control) ||
1288 ieee80211_is_ctl(wh->frame_control)) {
1289 txdatarate = 0;
1290 qos = mwl8k_qos_setbit_eosp(qos);
1291 /* Set Queue size to unspecified */
1292 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1293 } else if (ieee80211_is_data(wh->frame_control)) {
1294 txdatarate = 1;
1295 if (is_multicast_ether_addr(wh->addr1))
1296 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1297
1298 /* Send pkt in an aggregate if AMPDU frame. */
1299 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1300 qos = mwl8k_qos_setbit_ack(qos,
1301 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1302 else
1303 qos = mwl8k_qos_setbit_ack(qos,
1304 MWL8K_TXD_ACK_POLICY_NORMAL);
1305
1306 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1307 qos = mwl8k_qos_setbit_amsdu(qos);
1308 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001309
1310 dma = pci_map_single(priv->pdev, skb->data,
1311 skb->len, PCI_DMA_TODEVICE);
1312
1313 if (pci_dma_mapping_error(priv->pdev, dma)) {
1314 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001315 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001316 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001317 return NETDEV_TX_OK;
1318 }
1319
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001320 spin_lock_bh(&priv->tx_lock);
1321
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001322 txq = priv->txq + index;
1323
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001324 BUG_ON(txq->skb[txq->tail] != NULL);
1325 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001326
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001327 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001328 tx->data_rate = txdatarate;
1329 tx->tx_priority = index;
1330 tx->qos_control = cpu_to_le16(qos);
1331 tx->pkt_phys_addr = cpu_to_le32(dma);
1332 tx->pkt_len = cpu_to_le16(skb->len);
1333 tx->rate_info = 0;
1334 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001335 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001336 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1337
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001338 txq->stats.count++;
1339 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001340 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001341
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001342 txq->tail++;
1343 if (txq->tail == MWL8K_TX_DESCS)
1344 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001345
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001346 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001347 ieee80211_stop_queue(hw, index);
1348
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001349 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001350
1351 spin_unlock_bh(&priv->tx_lock);
1352
1353 return NETDEV_TX_OK;
1354}
1355
1356
1357/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001358 * Firmware access.
1359 *
1360 * We have the following requirements for issuing firmware commands:
1361 * - Some commands require that the packet transmit path is idle when
1362 * the command is issued. (For simplicity, we'll just quiesce the
1363 * transmit path for every command.)
1364 * - There are certain sequences of commands that need to be issued to
1365 * the hardware sequentially, with no other intervening commands.
1366 *
1367 * This leads to an implementation of a "firmware lock" as a mutex that
1368 * can be taken recursively, and which is taken by both the low-level
1369 * command submission function (mwl8k_post_cmd) as well as any users of
1370 * that function that require issuing of an atomic sequence of commands,
1371 * and quiesces the transmit path whenever it's taken.
1372 */
1373static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1374{
1375 struct mwl8k_priv *priv = hw->priv;
1376
1377 if (priv->fw_mutex_owner != current) {
1378 int rc;
1379
1380 mutex_lock(&priv->fw_mutex);
1381 ieee80211_stop_queues(hw);
1382
1383 rc = mwl8k_tx_wait_empty(hw);
1384 if (rc) {
1385 ieee80211_wake_queues(hw);
1386 mutex_unlock(&priv->fw_mutex);
1387
1388 return rc;
1389 }
1390
1391 priv->fw_mutex_owner = current;
1392 }
1393
1394 priv->fw_mutex_depth++;
1395
1396 return 0;
1397}
1398
1399static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1400{
1401 struct mwl8k_priv *priv = hw->priv;
1402
1403 if (!--priv->fw_mutex_depth) {
1404 ieee80211_wake_queues(hw);
1405 priv->fw_mutex_owner = NULL;
1406 mutex_unlock(&priv->fw_mutex);
1407 }
1408}
1409
1410
1411/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001412 * Command processing.
1413 */
1414
1415/* Timeout firmware commands after 2000ms */
1416#define MWL8K_CMD_TIMEOUT_MS 2000
1417
1418static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1419{
1420 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1421 struct mwl8k_priv *priv = hw->priv;
1422 void __iomem *regs = priv->regs;
1423 dma_addr_t dma_addr;
1424 unsigned int dma_size;
1425 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001426 unsigned long timeout = 0;
1427 u8 buf[32];
1428
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001429 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001430 dma_size = le16_to_cpu(cmd->length);
1431 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1432 PCI_DMA_BIDIRECTIONAL);
1433 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1434 return -ENOMEM;
1435
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001436 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001437 if (rc) {
1438 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1439 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001440 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001441 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001442
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001443 priv->hostcmd_wait = &cmd_wait;
1444 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1445 iowrite32(MWL8K_H2A_INT_DOORBELL,
1446 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1447 iowrite32(MWL8K_H2A_INT_DUMMY,
1448 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001449
1450 timeout = wait_for_completion_timeout(&cmd_wait,
1451 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1452
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001453 priv->hostcmd_wait = NULL;
1454
1455 mwl8k_fw_unlock(hw);
1456
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001457 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1458 PCI_DMA_BIDIRECTIONAL);
1459
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001460 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001461 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001462 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001463 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1464 MWL8K_CMD_TIMEOUT_MS);
1465 rc = -ETIMEDOUT;
1466 } else {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001467 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001468 if (rc)
1469 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001470 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001471 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001472 le16_to_cpu(cmd->result));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001473 }
1474
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001475 return rc;
1476}
1477
1478/*
1479 * GET_HW_SPEC.
1480 */
1481struct mwl8k_cmd_get_hw_spec {
1482 struct mwl8k_cmd_pkt header;
1483 __u8 hw_rev;
1484 __u8 host_interface;
1485 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001486 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001487 __le16 region_code;
1488 __le32 fw_rev;
1489 __le32 ps_cookie;
1490 __le32 caps;
1491 __u8 mcs_bitmap[16];
1492 __le32 rx_queue_ptr;
1493 __le32 num_tx_queues;
1494 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1495 __le32 caps2;
1496 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001497 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001498} __attribute__((packed));
1499
1500static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
1501{
1502 struct mwl8k_priv *priv = hw->priv;
1503 struct mwl8k_cmd_get_hw_spec *cmd;
1504 int rc;
1505 int i;
1506
1507 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1508 if (cmd == NULL)
1509 return -ENOMEM;
1510
1511 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1512 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1513
1514 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1515 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001516 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001517 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001518 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001519 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001520 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001521 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001522
1523 rc = mwl8k_post_cmd(hw, &cmd->header);
1524
1525 if (!rc) {
1526 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1527 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001528 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001529 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001530 }
1531
1532 kfree(cmd);
1533 return rc;
1534}
1535
1536/*
1537 * CMD_MAC_MULTICAST_ADR.
1538 */
1539struct mwl8k_cmd_mac_multicast_adr {
1540 struct mwl8k_cmd_pkt header;
1541 __le16 action;
1542 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001543 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001544};
1545
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001546#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1547#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1548#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1549#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001550
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001551static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001552__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001553 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001554{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001555 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001556 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001557 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001558
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001559 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001560 allmulti = 1;
1561 mc_count = 0;
1562 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001563
1564 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1565
1566 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001567 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001568 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001569
1570 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1571 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001572 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1573 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001574
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001575 if (allmulti) {
1576 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1577 } else if (mc_count) {
1578 int i;
1579
1580 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1581 cmd->numaddr = cpu_to_le16(mc_count);
1582 for (i = 0; i < mc_count && mclist; i++) {
1583 if (mclist->da_addrlen != ETH_ALEN) {
1584 kfree(cmd);
1585 return NULL;
1586 }
1587 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1588 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001589 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001590 }
1591
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001592 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001593}
1594
1595/*
1596 * CMD_802_11_GET_STAT.
1597 */
1598struct mwl8k_cmd_802_11_get_stat {
1599 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001600 __le32 stats[64];
1601} __attribute__((packed));
1602
1603#define MWL8K_STAT_ACK_FAILURE 9
1604#define MWL8K_STAT_RTS_FAILURE 12
1605#define MWL8K_STAT_FCS_ERROR 24
1606#define MWL8K_STAT_RTS_SUCCESS 11
1607
1608static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1609 struct ieee80211_low_level_stats *stats)
1610{
1611 struct mwl8k_cmd_802_11_get_stat *cmd;
1612 int rc;
1613
1614 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1615 if (cmd == NULL)
1616 return -ENOMEM;
1617
1618 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1619 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001620
1621 rc = mwl8k_post_cmd(hw, &cmd->header);
1622 if (!rc) {
1623 stats->dot11ACKFailureCount =
1624 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1625 stats->dot11RTSFailureCount =
1626 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1627 stats->dot11FCSErrorCount =
1628 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1629 stats->dot11RTSSuccessCount =
1630 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1631 }
1632 kfree(cmd);
1633
1634 return rc;
1635}
1636
1637/*
1638 * CMD_802_11_RADIO_CONTROL.
1639 */
1640struct mwl8k_cmd_802_11_radio_control {
1641 struct mwl8k_cmd_pkt header;
1642 __le16 action;
1643 __le16 control;
1644 __le16 radio_on;
1645} __attribute__((packed));
1646
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001647static int
1648mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001649{
1650 struct mwl8k_priv *priv = hw->priv;
1651 struct mwl8k_cmd_802_11_radio_control *cmd;
1652 int rc;
1653
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001654 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001655 return 0;
1656
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001657 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1658 if (cmd == NULL)
1659 return -ENOMEM;
1660
1661 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1662 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1663 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001664 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001665 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1666
1667 rc = mwl8k_post_cmd(hw, &cmd->header);
1668 kfree(cmd);
1669
1670 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001671 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001672
1673 return rc;
1674}
1675
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001676static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1677{
1678 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1679}
1680
1681static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1682{
1683 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1684}
1685
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001686static int
1687mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1688{
1689 struct mwl8k_priv *priv;
1690
1691 if (hw == NULL || hw->priv == NULL)
1692 return -EINVAL;
1693 priv = hw->priv;
1694
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001695 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001696
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001697 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001698}
1699
1700/*
1701 * CMD_802_11_RF_TX_POWER.
1702 */
1703#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1704
1705struct mwl8k_cmd_802_11_rf_tx_power {
1706 struct mwl8k_cmd_pkt header;
1707 __le16 action;
1708 __le16 support_level;
1709 __le16 current_level;
1710 __le16 reserved;
1711 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1712} __attribute__((packed));
1713
1714static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1715{
1716 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1717 int rc;
1718
1719 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1720 if (cmd == NULL)
1721 return -ENOMEM;
1722
1723 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1724 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1725 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1726 cmd->support_level = cpu_to_le16(dBm);
1727
1728 rc = mwl8k_post_cmd(hw, &cmd->header);
1729 kfree(cmd);
1730
1731 return rc;
1732}
1733
1734/*
1735 * CMD_SET_PRE_SCAN.
1736 */
1737struct mwl8k_cmd_set_pre_scan {
1738 struct mwl8k_cmd_pkt header;
1739} __attribute__((packed));
1740
1741static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
1742{
1743 struct mwl8k_cmd_set_pre_scan *cmd;
1744 int rc;
1745
1746 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1747 if (cmd == NULL)
1748 return -ENOMEM;
1749
1750 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
1751 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1752
1753 rc = mwl8k_post_cmd(hw, &cmd->header);
1754 kfree(cmd);
1755
1756 return rc;
1757}
1758
1759/*
1760 * CMD_SET_POST_SCAN.
1761 */
1762struct mwl8k_cmd_set_post_scan {
1763 struct mwl8k_cmd_pkt header;
1764 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001765 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001766} __attribute__((packed));
1767
1768static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001769mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001770{
1771 struct mwl8k_cmd_set_post_scan *cmd;
1772 int rc;
1773
1774 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1775 if (cmd == NULL)
1776 return -ENOMEM;
1777
1778 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
1779 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1780 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001781 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001782
1783 rc = mwl8k_post_cmd(hw, &cmd->header);
1784 kfree(cmd);
1785
1786 return rc;
1787}
1788
1789/*
1790 * CMD_SET_RF_CHANNEL.
1791 */
1792struct mwl8k_cmd_set_rf_channel {
1793 struct mwl8k_cmd_pkt header;
1794 __le16 action;
1795 __u8 current_channel;
1796 __le32 channel_flags;
1797} __attribute__((packed));
1798
1799static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
1800 struct ieee80211_channel *channel)
1801{
1802 struct mwl8k_cmd_set_rf_channel *cmd;
1803 int rc;
1804
1805 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1806 if (cmd == NULL)
1807 return -ENOMEM;
1808
1809 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
1810 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1811 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1812 cmd->current_channel = channel->hw_value;
1813 if (channel->band == IEEE80211_BAND_2GHZ)
1814 cmd->channel_flags = cpu_to_le32(0x00000081);
1815 else
1816 cmd->channel_flags = cpu_to_le32(0x00000000);
1817
1818 rc = mwl8k_post_cmd(hw, &cmd->header);
1819 kfree(cmd);
1820
1821 return rc;
1822}
1823
1824/*
1825 * CMD_SET_SLOT.
1826 */
1827struct mwl8k_cmd_set_slot {
1828 struct mwl8k_cmd_pkt header;
1829 __le16 action;
1830 __u8 short_slot;
1831} __attribute__((packed));
1832
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02001833static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001834{
1835 struct mwl8k_cmd_set_slot *cmd;
1836 int rc;
1837
1838 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1839 if (cmd == NULL)
1840 return -ENOMEM;
1841
1842 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
1843 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1844 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02001845 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001846
1847 rc = mwl8k_post_cmd(hw, &cmd->header);
1848 kfree(cmd);
1849
1850 return rc;
1851}
1852
1853/*
1854 * CMD_MIMO_CONFIG.
1855 */
1856struct mwl8k_cmd_mimo_config {
1857 struct mwl8k_cmd_pkt header;
1858 __le32 action;
1859 __u8 rx_antenna_map;
1860 __u8 tx_antenna_map;
1861} __attribute__((packed));
1862
1863static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
1864{
1865 struct mwl8k_cmd_mimo_config *cmd;
1866 int rc;
1867
1868 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1869 if (cmd == NULL)
1870 return -ENOMEM;
1871
1872 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
1873 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1874 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
1875 cmd->rx_antenna_map = rx;
1876 cmd->tx_antenna_map = tx;
1877
1878 rc = mwl8k_post_cmd(hw, &cmd->header);
1879 kfree(cmd);
1880
1881 return rc;
1882}
1883
1884/*
1885 * CMD_ENABLE_SNIFFER.
1886 */
1887struct mwl8k_cmd_enable_sniffer {
1888 struct mwl8k_cmd_pkt header;
1889 __le32 action;
1890} __attribute__((packed));
1891
1892static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
1893{
1894 struct mwl8k_cmd_enable_sniffer *cmd;
1895 int rc;
1896
1897 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1898 if (cmd == NULL)
1899 return -ENOMEM;
1900
1901 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
1902 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001903 cmd->action = cpu_to_le32(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001904
1905 rc = mwl8k_post_cmd(hw, &cmd->header);
1906 kfree(cmd);
1907
1908 return rc;
1909}
1910
1911/*
Lennert Buytenhek32060e12009-10-22 20:20:04 +02001912 * CMD_SET_MAC_ADDR.
1913 */
1914struct mwl8k_cmd_set_mac_addr {
1915 struct mwl8k_cmd_pkt header;
1916 __u8 mac_addr[ETH_ALEN];
1917} __attribute__((packed));
1918
1919static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
1920{
1921 struct mwl8k_cmd_set_mac_addr *cmd;
1922 int rc;
1923
1924 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1925 if (cmd == NULL)
1926 return -ENOMEM;
1927
1928 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
1929 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1930 memcpy(cmd->mac_addr, mac, ETH_ALEN);
1931
1932 rc = mwl8k_post_cmd(hw, &cmd->header);
1933 kfree(cmd);
1934
1935 return rc;
1936}
1937
1938
1939/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001940 * CMD_SET_RATEADAPT_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001941 */
1942struct mwl8k_cmd_set_rate_adapt_mode {
1943 struct mwl8k_cmd_pkt header;
1944 __le16 action;
1945 __le16 mode;
1946} __attribute__((packed));
1947
1948static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
1949{
1950 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
1951 int rc;
1952
1953 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1954 if (cmd == NULL)
1955 return -ENOMEM;
1956
1957 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
1958 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1959 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1960 cmd->mode = cpu_to_le16(mode);
1961
1962 rc = mwl8k_post_cmd(hw, &cmd->header);
1963 kfree(cmd);
1964
1965 return rc;
1966}
1967
1968/*
1969 * CMD_SET_WMM_MODE.
1970 */
1971struct mwl8k_cmd_set_wmm {
1972 struct mwl8k_cmd_pkt header;
1973 __le16 action;
1974} __attribute__((packed));
1975
1976static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
1977{
1978 struct mwl8k_priv *priv = hw->priv;
1979 struct mwl8k_cmd_set_wmm *cmd;
1980 int rc;
1981
1982 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1983 if (cmd == NULL)
1984 return -ENOMEM;
1985
1986 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
1987 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02001988 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001989
1990 rc = mwl8k_post_cmd(hw, &cmd->header);
1991 kfree(cmd);
1992
1993 if (!rc)
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02001994 priv->wmm_enabled = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001995
1996 return rc;
1997}
1998
1999/*
2000 * CMD_SET_RTS_THRESHOLD.
2001 */
2002struct mwl8k_cmd_rts_threshold {
2003 struct mwl8k_cmd_pkt header;
2004 __le16 action;
2005 __le16 threshold;
2006} __attribute__((packed));
2007
2008static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002009 u16 action, u16 threshold)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002010{
2011 struct mwl8k_cmd_rts_threshold *cmd;
2012 int rc;
2013
2014 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2015 if (cmd == NULL)
2016 return -ENOMEM;
2017
2018 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2019 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2020 cmd->action = cpu_to_le16(action);
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002021 cmd->threshold = cpu_to_le16(threshold);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002022
2023 rc = mwl8k_post_cmd(hw, &cmd->header);
2024 kfree(cmd);
2025
2026 return rc;
2027}
2028
2029/*
2030 * CMD_SET_EDCA_PARAMS.
2031 */
2032struct mwl8k_cmd_set_edca_params {
2033 struct mwl8k_cmd_pkt header;
2034
2035 /* See MWL8K_SET_EDCA_XXX below */
2036 __le16 action;
2037
2038 /* TX opportunity in units of 32 us */
2039 __le16 txop;
2040
2041 /* Log exponent of max contention period: 0...15*/
2042 __u8 log_cw_max;
2043
2044 /* Log exponent of min contention period: 0...15 */
2045 __u8 log_cw_min;
2046
2047 /* Adaptive interframe spacing in units of 32us */
2048 __u8 aifs;
2049
2050 /* TX queue to configure */
2051 __u8 txq;
2052} __attribute__((packed));
2053
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002054#define MWL8K_SET_EDCA_CW 0x01
2055#define MWL8K_SET_EDCA_TXOP 0x02
2056#define MWL8K_SET_EDCA_AIFS 0x04
2057
2058#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2059 MWL8K_SET_EDCA_TXOP | \
2060 MWL8K_SET_EDCA_AIFS)
2061
2062static int
2063mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2064 __u16 cw_min, __u16 cw_max,
2065 __u8 aifs, __u16 txop)
2066{
2067 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002068 int rc;
2069
2070 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2071 if (cmd == NULL)
2072 return -ENOMEM;
2073
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002074 /*
2075 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2076 * this call.
2077 */
2078 qnum ^= !(qnum >> 1);
2079
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002080 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2081 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002082 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2083 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002084 cmd->log_cw_max = (u8)ilog2(cw_max + 1);
2085 cmd->log_cw_min = (u8)ilog2(cw_min + 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002086 cmd->aifs = aifs;
2087 cmd->txq = qnum;
2088
2089 rc = mwl8k_post_cmd(hw, &cmd->header);
2090 kfree(cmd);
2091
2092 return rc;
2093}
2094
2095/*
2096 * CMD_FINALIZE_JOIN.
2097 */
2098
2099/* FJ beacon buffer size is compiled into the firmware. */
2100#define MWL8K_FJ_BEACON_MAXLEN 128
2101
2102struct mwl8k_cmd_finalize_join {
2103 struct mwl8k_cmd_pkt header;
2104 __le32 sleep_interval; /* Number of beacon periods to sleep */
2105 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2106} __attribute__((packed));
2107
2108static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2109 __u16 framelen, __u16 dtim)
2110{
2111 struct mwl8k_cmd_finalize_join *cmd;
2112 struct ieee80211_mgmt *payload = frame;
2113 u16 hdrlen;
2114 u32 payload_len;
2115 int rc;
2116
2117 if (frame == NULL)
2118 return -EINVAL;
2119
2120 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2121 if (cmd == NULL)
2122 return -ENOMEM;
2123
2124 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2125 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002126 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002127
2128 hdrlen = ieee80211_hdrlen(payload->frame_control);
2129
2130 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2131
2132 /* XXX TBD Might just have to abort and return an error */
2133 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2134 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002135 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2136 payload_len, MWL8K_FJ_BEACON_MAXLEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002137
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002138 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2139 payload_len = MWL8K_FJ_BEACON_MAXLEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002140
2141 if (payload && payload_len)
2142 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2143
2144 rc = mwl8k_post_cmd(hw, &cmd->header);
2145 kfree(cmd);
2146 return rc;
2147}
2148
2149/*
2150 * CMD_UPDATE_STADB.
2151 */
2152struct mwl8k_cmd_update_sta_db {
2153 struct mwl8k_cmd_pkt header;
2154
2155 /* See STADB_ACTION_TYPE */
2156 __le32 action;
2157
2158 /* Peer MAC address */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002159 __u8 peer_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002160
2161 __le32 reserved;
2162
2163 /* Peer info - valid during add/update. */
2164 struct peer_capability_info peer_info;
2165} __attribute__((packed));
2166
2167static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2168 struct ieee80211_vif *vif, __u32 action)
2169{
2170 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2171 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2172 struct mwl8k_cmd_update_sta_db *cmd;
2173 struct peer_capability_info *peer_info;
2174 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002175 int rc;
2176 __u8 count, *rates;
2177
2178 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2179 if (cmd == NULL)
2180 return -ENOMEM;
2181
2182 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2183 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2184
2185 cmd->action = cpu_to_le32(action);
2186 peer_info = &cmd->peer_info;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002187 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002188
2189 switch (action) {
2190 case MWL8K_STA_DB_ADD_ENTRY:
2191 case MWL8K_STA_DB_MODIFY_ENTRY:
2192 /* Build peer_info block */
2193 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2194 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2195 peer_info->interop = 1;
2196 peer_info->amsdu_enabled = 0;
2197
2198 rates = peer_info->legacy_rates;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002199 for (count = 0; count < mv_vif->legacy_nrates; count++)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002200 rates[count] = bitrates[count].hw_value;
2201
2202 rc = mwl8k_post_cmd(hw, &cmd->header);
2203 if (rc == 0)
2204 mv_vif->peer_id = peer_info->station_id;
2205
2206 break;
2207
2208 case MWL8K_STA_DB_DEL_ENTRY:
2209 case MWL8K_STA_DB_FLUSH:
2210 default:
2211 rc = mwl8k_post_cmd(hw, &cmd->header);
2212 if (rc == 0)
2213 mv_vif->peer_id = 0;
2214 break;
2215 }
2216 kfree(cmd);
2217
2218 return rc;
2219}
2220
2221/*
2222 * CMD_SET_AID.
2223 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002224#define MWL8K_RATE_INDEX_MAX_ARRAY 14
2225
2226#define MWL8K_FRAME_PROT_DISABLED 0x00
2227#define MWL8K_FRAME_PROT_11G 0x07
2228#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2229#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002230
2231struct mwl8k_cmd_update_set_aid {
2232 struct mwl8k_cmd_pkt header;
2233 __le16 aid;
2234
2235 /* AP's MAC address (BSSID) */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002236 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002237 __le16 protection_mode;
2238 __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2239} __attribute__((packed));
2240
2241static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2242 struct ieee80211_vif *vif)
2243{
2244 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2245 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2246 struct mwl8k_cmd_update_set_aid *cmd;
2247 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2248 int count;
2249 u16 prot_mode;
2250 int rc;
2251
2252 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2253 if (cmd == NULL)
2254 return -ENOMEM;
2255
2256 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2257 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2258 cmd->aid = cpu_to_le16(info->aid);
2259
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002260 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002261
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002262 if (info->use_cts_prot) {
2263 prot_mode = MWL8K_FRAME_PROT_11G;
2264 } else {
Johannes Berg9ed6bcc2009-05-08 20:47:39 +02002265 switch (info->ht_operation_mode &
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002266 IEEE80211_HT_OP_MODE_PROTECTION) {
2267 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2268 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2269 break;
2270 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2271 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2272 break;
2273 default:
2274 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2275 break;
2276 }
2277 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002278 cmd->protection_mode = cpu_to_le16(prot_mode);
2279
2280 for (count = 0; count < mv_vif->legacy_nrates; count++)
2281 cmd->supp_rates[count] = bitrates[count].hw_value;
2282
2283 rc = mwl8k_post_cmd(hw, &cmd->header);
2284 kfree(cmd);
2285
2286 return rc;
2287}
2288
2289/*
2290 * CMD_SET_RATE.
2291 */
2292struct mwl8k_cmd_update_rateset {
2293 struct mwl8k_cmd_pkt header;
2294 __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2295
2296 /* Bitmap for supported MCS codes. */
2297 __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
2298 __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
2299} __attribute__((packed));
2300
2301static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2302 struct ieee80211_vif *vif)
2303{
2304 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2305 struct mwl8k_cmd_update_rateset *cmd;
2306 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2307 int count;
2308 int rc;
2309
2310 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2311 if (cmd == NULL)
2312 return -ENOMEM;
2313
2314 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2315 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2316
2317 for (count = 0; count < mv_vif->legacy_nrates; count++)
2318 cmd->legacy_rates[count] = bitrates[count].hw_value;
2319
2320 rc = mwl8k_post_cmd(hw, &cmd->header);
2321 kfree(cmd);
2322
2323 return rc;
2324}
2325
2326/*
2327 * CMD_USE_FIXED_RATE.
2328 */
2329#define MWL8K_RATE_TABLE_SIZE 8
2330#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002331#define MWL8K_USE_AUTO_RATE 0x0002
2332
2333struct mwl8k_rate_entry {
2334 /* Set to 1 if HT rate, 0 if legacy. */
2335 __le32 is_ht_rate;
2336
2337 /* Set to 1 to use retry_count field. */
2338 __le32 enable_retry;
2339
2340 /* Specified legacy rate or MCS. */
2341 __le32 rate;
2342
2343 /* Number of allowed retries. */
2344 __le32 retry_count;
2345} __attribute__((packed));
2346
2347struct mwl8k_rate_table {
2348 /* 1 to allow specified rate and below */
2349 __le32 allow_rate_drop;
2350 __le32 num_rates;
2351 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2352} __attribute__((packed));
2353
2354struct mwl8k_cmd_use_fixed_rate {
2355 struct mwl8k_cmd_pkt header;
2356 __le32 action;
2357 struct mwl8k_rate_table rate_table;
2358
2359 /* Unicast, Broadcast or Multicast */
2360 __le32 rate_type;
2361 __le32 reserved1;
2362 __le32 reserved2;
2363} __attribute__((packed));
2364
2365static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2366 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2367{
2368 struct mwl8k_cmd_use_fixed_rate *cmd;
2369 int count;
2370 int rc;
2371
2372 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2373 if (cmd == NULL)
2374 return -ENOMEM;
2375
2376 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2377 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2378
2379 cmd->action = cpu_to_le32(action);
2380 cmd->rate_type = cpu_to_le32(rate_type);
2381
2382 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002383 /*
2384 * Copy over each field manually so that endian
2385 * conversion can be done.
2386 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002387 cmd->rate_table.allow_rate_drop =
2388 cpu_to_le32(rate_table->allow_rate_drop);
2389 cmd->rate_table.num_rates =
2390 cpu_to_le32(rate_table->num_rates);
2391
2392 for (count = 0; count < rate_table->num_rates; count++) {
2393 struct mwl8k_rate_entry *dst =
2394 &cmd->rate_table.rate_entry[count];
2395 struct mwl8k_rate_entry *src =
2396 &rate_table->rate_entry[count];
2397
2398 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2399 dst->enable_retry = cpu_to_le32(src->enable_retry);
2400 dst->rate = cpu_to_le32(src->rate);
2401 dst->retry_count = cpu_to_le32(src->retry_count);
2402 }
2403 }
2404
2405 rc = mwl8k_post_cmd(hw, &cmd->header);
2406 kfree(cmd);
2407
2408 return rc;
2409}
2410
2411
2412/*
2413 * Interrupt handling.
2414 */
2415static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2416{
2417 struct ieee80211_hw *hw = dev_id;
2418 struct mwl8k_priv *priv = hw->priv;
2419 u32 status;
2420
2421 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2422 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2423
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002424 if (!status)
2425 return IRQ_NONE;
2426
2427 if (status & MWL8K_A2H_INT_TX_DONE)
2428 tasklet_schedule(&priv->tx_reclaim_task);
2429
2430 if (status & MWL8K_A2H_INT_RX_READY) {
2431 while (rxq_process(hw, 0, 1))
2432 rxq_refill(hw, 0, 1);
2433 }
2434
2435 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002436 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002437 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002438 }
2439
2440 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002441 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002442 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002443 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002444 }
2445
2446 return IRQ_HANDLED;
2447}
2448
2449
2450/*
2451 * Core driver operations.
2452 */
2453static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2454{
2455 struct mwl8k_priv *priv = hw->priv;
2456 int index = skb_get_queue_mapping(skb);
2457 int rc;
2458
2459 if (priv->current_channel == NULL) {
2460 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002461 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002462 dev_kfree_skb(skb);
2463 return NETDEV_TX_OK;
2464 }
2465
2466 rc = mwl8k_txq_xmit(hw, index, skb);
2467
2468 return rc;
2469}
2470
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002471static int mwl8k_start(struct ieee80211_hw *hw)
2472{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002473 struct mwl8k_priv *priv = hw->priv;
2474 int rc;
2475
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002476 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
2477 IRQF_SHARED, MWL8K_NAME, hw);
2478 if (rc) {
2479 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002480 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002481 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002482 }
2483
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002484 /* Enable tx reclaim tasklet */
2485 tasklet_enable(&priv->tx_reclaim_task);
2486
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002487 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002488 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002489
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002490 rc = mwl8k_fw_lock(hw);
2491 if (!rc) {
2492 rc = mwl8k_cmd_802_11_radio_enable(hw);
2493
2494 if (!rc)
2495 rc = mwl8k_cmd_set_pre_scan(hw);
2496
2497 if (!rc)
2498 rc = mwl8k_cmd_set_post_scan(hw,
2499 "\x00\x00\x00\x00\x00\x00");
2500
2501 if (!rc)
2502 rc = mwl8k_cmd_setrateadaptmode(hw, 0);
2503
2504 if (!rc)
2505 rc = mwl8k_set_wmm(hw, 0);
2506
2507 if (!rc)
2508 rc = mwl8k_enable_sniffer(hw, 0);
2509
2510 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002511 }
2512
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002513 if (rc) {
2514 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2515 free_irq(priv->pdev->irq, hw);
2516 tasklet_disable(&priv->tx_reclaim_task);
2517 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002518
2519 return rc;
2520}
2521
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002522static void mwl8k_stop(struct ieee80211_hw *hw)
2523{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002524 struct mwl8k_priv *priv = hw->priv;
2525 int i;
2526
Lennert Buytenhekd3cea0b2009-07-17 07:15:49 +02002527 mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002528
2529 ieee80211_stop_queues(hw);
2530
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002531 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002532 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002533 free_irq(priv->pdev->irq, hw);
2534
2535 /* Stop finalize join worker */
2536 cancel_work_sync(&priv->finalize_join_worker);
2537 if (priv->beacon_skb != NULL)
2538 dev_kfree_skb(priv->beacon_skb);
2539
2540 /* Stop tx reclaim tasklet */
2541 tasklet_disable(&priv->tx_reclaim_task);
2542
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002543 /* Return all skbs to mac80211 */
2544 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2545 mwl8k_txq_reclaim(hw, i, 1);
2546}
2547
2548static int mwl8k_add_interface(struct ieee80211_hw *hw,
2549 struct ieee80211_if_init_conf *conf)
2550{
2551 struct mwl8k_priv *priv = hw->priv;
2552 struct mwl8k_vif *mwl8k_vif;
2553
2554 /*
2555 * We only support one active interface at a time.
2556 */
2557 if (priv->vif != NULL)
2558 return -EBUSY;
2559
2560 /*
2561 * We only support managed interfaces for now.
2562 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002563 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002564 return -EINVAL;
2565
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002566 /*
2567 * Reject interface creation if sniffer mode is active, as
2568 * STA operation is mutually exclusive with hardware sniffer
2569 * mode.
2570 */
2571 if (priv->sniffer_enabled) {
2572 printk(KERN_INFO "%s: unable to create STA "
2573 "interface due to sniffer mode being enabled\n",
2574 wiphy_name(hw->wiphy));
2575 return -EINVAL;
2576 }
2577
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002578 /* Clean out driver private area */
2579 mwl8k_vif = MWL8K_VIF(conf->vif);
2580 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2581
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002582 /* Set and save the mac address */
2583 mwl8k_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002584 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002585
2586 /* Back pointer to parent config block */
2587 mwl8k_vif->priv = priv;
2588
2589 /* Setup initial PHY parameters */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002590 memcpy(mwl8k_vif->legacy_rates,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002591 priv->rates, sizeof(mwl8k_vif->legacy_rates));
2592 mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
2593
2594 /* Set Initial sequence number to zero */
2595 mwl8k_vif->seqno = 0;
2596
2597 priv->vif = conf->vif;
2598 priv->current_channel = NULL;
2599
2600 return 0;
2601}
2602
2603static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2604 struct ieee80211_if_init_conf *conf)
2605{
2606 struct mwl8k_priv *priv = hw->priv;
2607
2608 if (priv->vif == NULL)
2609 return;
2610
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002611 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
2612
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002613 priv->vif = NULL;
2614}
2615
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002616static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002617{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002618 struct ieee80211_conf *conf = &hw->conf;
2619 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002620 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002621
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002622 if (conf->flags & IEEE80211_CONF_IDLE) {
2623 mwl8k_cmd_802_11_radio_disable(hw);
2624 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002625 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002626 }
2627
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002628 rc = mwl8k_fw_lock(hw);
2629 if (rc)
2630 return rc;
2631
2632 rc = mwl8k_cmd_802_11_radio_enable(hw);
2633 if (rc)
2634 goto out;
2635
2636 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2637 if (rc)
2638 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002639
2640 priv->current_channel = conf->channel;
2641
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002642 if (conf->power_level > 18)
2643 conf->power_level = 18;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002644 rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level);
2645 if (rc)
2646 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002647
2648 if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
2649 rc = -EINVAL;
2650
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002651out:
2652 mwl8k_fw_unlock(hw);
2653
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002654 return rc;
2655}
2656
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002657static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
2658 struct ieee80211_vif *vif,
2659 struct ieee80211_bss_conf *info,
2660 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002661{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002662 struct mwl8k_priv *priv = hw->priv;
2663 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002664 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002665
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002666 if (changed & BSS_CHANGED_BSSID)
2667 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
2668
2669 if ((changed & BSS_CHANGED_ASSOC) == 0)
2670 return;
2671
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002672 priv->capture_beacon = false;
2673
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002674 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02002675 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002676 return;
2677
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002678 if (info->assoc) {
2679 memcpy(&mwl8k_vif->bss_info, info,
2680 sizeof(struct ieee80211_bss_conf));
2681
2682 /* Install rates */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002683 rc = mwl8k_update_rateset(hw, vif);
2684 if (rc)
2685 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002686
2687 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002688 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
2689 MWL8K_UCAST_RATE, NULL);
2690 if (rc)
2691 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002692
2693 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002694 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
2695 if (rc)
2696 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002697
2698 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002699 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
2700 if (rc)
2701 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002702
2703 /* Update peer rate info */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002704 rc = mwl8k_cmd_update_sta_db(hw, vif,
2705 MWL8K_STA_DB_MODIFY_ENTRY);
2706 if (rc)
2707 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002708
2709 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002710 rc = mwl8k_cmd_set_aid(hw, vif);
2711 if (rc)
2712 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002713
2714 /*
2715 * Finalize the join. Tell rx handler to process
2716 * next beacon from our BSSID.
2717 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002718 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002719 priv->capture_beacon = true;
2720 } else {
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002721 rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002722 memset(&mwl8k_vif->bss_info, 0,
2723 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002724 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002725 }
2726
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002727out:
2728 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002729}
2730
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002731static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
2732 int mc_count, struct dev_addr_list *mclist)
2733{
2734 struct mwl8k_cmd_pkt *cmd;
2735
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002736 /*
2737 * Synthesize and return a command packet that programs the
2738 * hardware multicast address filter. At this point we don't
2739 * know whether FIF_ALLMULTI is being requested, but if it is,
2740 * we'll end up throwing this packet away and creating a new
2741 * one in mwl8k_configure_filter().
2742 */
2743 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002744
2745 return (unsigned long)cmd;
2746}
2747
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002748static int
2749mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
2750 unsigned int changed_flags,
2751 unsigned int *total_flags)
2752{
2753 struct mwl8k_priv *priv = hw->priv;
2754
2755 /*
2756 * Hardware sniffer mode is mutually exclusive with STA
2757 * operation, so refuse to enable sniffer mode if a STA
2758 * interface is active.
2759 */
2760 if (priv->vif != NULL) {
2761 if (net_ratelimit())
2762 printk(KERN_INFO "%s: not enabling sniffer "
2763 "mode because STA interface is active\n",
2764 wiphy_name(hw->wiphy));
2765 return 0;
2766 }
2767
2768 if (!priv->sniffer_enabled) {
2769 if (mwl8k_enable_sniffer(hw, 1))
2770 return 0;
2771 priv->sniffer_enabled = true;
2772 }
2773
2774 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
2775 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
2776 FIF_OTHER_BSS;
2777
2778 return 1;
2779}
2780
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002781static void mwl8k_configure_filter(struct ieee80211_hw *hw,
2782 unsigned int changed_flags,
2783 unsigned int *total_flags,
2784 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002785{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002786 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002787 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
2788
2789 /*
2790 * Enable hardware sniffer mode if FIF_CONTROL or
2791 * FIF_OTHER_BSS is requested.
2792 */
2793 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
2794 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
2795 kfree(cmd);
2796 return;
2797 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002798
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002799 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002800 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002801
2802 if (mwl8k_fw_lock(hw))
2803 return;
2804
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002805 if (priv->sniffer_enabled) {
2806 mwl8k_enable_sniffer(hw, 0);
2807 priv->sniffer_enabled = false;
2808 }
2809
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002810 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02002811 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
2812 /*
2813 * Disable the BSS filter.
2814 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002815 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02002816 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02002817 u8 *bssid;
2818
Lennert Buytenhek77165d82009-10-22 20:19:53 +02002819 /*
2820 * Enable the BSS filter.
2821 *
2822 * If there is an active STA interface, use that
2823 * interface's BSSID, otherwise use a dummy one
2824 * (where the OUI part needs to be nonzero for
2825 * the BSSID to be accepted by POST_SCAN).
2826 */
2827 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02002828 if (priv->vif != NULL)
2829 bssid = MWL8K_VIF(priv->vif)->bssid;
2830
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002831 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002832 }
2833 }
2834
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002835 /*
2836 * If FIF_ALLMULTI is being requested, throw away the command
2837 * packet that ->prepare_multicast() built and replace it with
2838 * a command packet that enables reception of all multicast
2839 * packets.
2840 */
2841 if (*total_flags & FIF_ALLMULTI) {
2842 kfree(cmd);
2843 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
2844 }
2845
2846 if (cmd != NULL) {
2847 mwl8k_post_cmd(hw, cmd);
2848 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002849 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002850
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002851 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002852}
2853
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002854static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2855{
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002856 return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002857}
2858
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002859static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
2860 const struct ieee80211_tx_queue_params *params)
2861{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02002862 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002863 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002864
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02002865 rc = mwl8k_fw_lock(hw);
2866 if (!rc) {
2867 if (!priv->wmm_enabled)
2868 rc = mwl8k_set_wmm(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002869
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02002870 if (!rc)
2871 rc = mwl8k_set_edca_params(hw, queue,
2872 params->cw_min,
2873 params->cw_max,
2874 params->aifs,
2875 params->txop);
2876
2877 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002878 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02002879
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002880 return rc;
2881}
2882
2883static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
2884 struct ieee80211_tx_queue_stats *stats)
2885{
2886 struct mwl8k_priv *priv = hw->priv;
2887 struct mwl8k_tx_queue *txq;
2888 int index;
2889
2890 spin_lock_bh(&priv->tx_lock);
2891 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
2892 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002893 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002894 sizeof(struct ieee80211_tx_queue_stats));
2895 }
2896 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02002897
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002898 return 0;
2899}
2900
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002901static int mwl8k_get_stats(struct ieee80211_hw *hw,
2902 struct ieee80211_low_level_stats *stats)
2903{
Lennert Buytenhek954ef502009-07-17 07:26:27 +02002904 return mwl8k_cmd_802_11_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002905}
2906
2907static const struct ieee80211_ops mwl8k_ops = {
2908 .tx = mwl8k_tx,
2909 .start = mwl8k_start,
2910 .stop = mwl8k_stop,
2911 .add_interface = mwl8k_add_interface,
2912 .remove_interface = mwl8k_remove_interface,
2913 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002914 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02002915 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002916 .configure_filter = mwl8k_configure_filter,
2917 .set_rts_threshold = mwl8k_set_rts_threshold,
2918 .conf_tx = mwl8k_conf_tx,
2919 .get_tx_stats = mwl8k_get_tx_stats,
2920 .get_stats = mwl8k_get_stats,
2921};
2922
2923static void mwl8k_tx_reclaim_handler(unsigned long data)
2924{
2925 int i;
2926 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
2927 struct mwl8k_priv *priv = hw->priv;
2928
2929 spin_lock_bh(&priv->tx_lock);
2930 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2931 mwl8k_txq_reclaim(hw, i, 0);
2932
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002933 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002934 complete(priv->tx_wait);
2935 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002936 }
2937 spin_unlock_bh(&priv->tx_lock);
2938}
2939
2940static void mwl8k_finalize_join_worker(struct work_struct *work)
2941{
2942 struct mwl8k_priv *priv =
2943 container_of(work, struct mwl8k_priv, finalize_join_worker);
2944 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002945 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002946
2947 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
2948 dev_kfree_skb(skb);
2949
2950 priv->beacon_skb = NULL;
2951}
2952
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02002953static struct mwl8k_device_info di_8687 = {
Lennert Buytenheka74b2952009-10-22 20:20:50 +02002954 .part_name = "88w8687",
2955 .helper_image = "mwl8k/helper_8687.fw",
2956 .fw_image = "mwl8k/fmimage_8687.fw",
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02002957};
2958
2959static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
2960 {
2961 PCI_VDEVICE(MARVELL, 0x2a2b),
2962 .driver_data = (unsigned long)&di_8687,
2963 }, {
2964 PCI_VDEVICE(MARVELL, 0x2a30),
2965 .driver_data = (unsigned long)&di_8687,
2966 }, {
2967 },
2968};
2969MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
2970
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002971static int __devinit mwl8k_probe(struct pci_dev *pdev,
2972 const struct pci_device_id *id)
2973{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02002974 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002975 struct ieee80211_hw *hw;
2976 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002977 int rc;
2978 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02002979
2980 if (!printed_version) {
2981 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
2982 printed_version = 1;
2983 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002984
2985 rc = pci_enable_device(pdev);
2986 if (rc) {
2987 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
2988 MWL8K_NAME);
2989 return rc;
2990 }
2991
2992 rc = pci_request_regions(pdev, MWL8K_NAME);
2993 if (rc) {
2994 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
2995 MWL8K_NAME);
2996 return rc;
2997 }
2998
2999 pci_set_master(pdev);
3000
3001 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3002 if (hw == NULL) {
3003 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3004 rc = -ENOMEM;
3005 goto err_free_reg;
3006 }
3007
3008 priv = hw->priv;
3009 priv->hw = hw;
3010 priv->pdev = pdev;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003011 priv->device_info = (void *)id->driver_data;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003012 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02003013 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003014 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003015
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003016 SET_IEEE80211_DEV(hw, &pdev->dev);
3017 pci_set_drvdata(pdev, hw);
3018
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003019 priv->sram = pci_iomap(pdev, 0, 0x10000);
3020 if (priv->sram == NULL) {
3021 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003022 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003023 goto err_iounmap;
3024 }
3025
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003026 /*
3027 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3028 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3029 */
3030 priv->regs = pci_iomap(pdev, 1, 0x10000);
3031 if (priv->regs == NULL) {
3032 priv->regs = pci_iomap(pdev, 2, 0x10000);
3033 if (priv->regs == NULL) {
3034 printk(KERN_ERR "%s: Cannot map device registers\n",
3035 wiphy_name(hw->wiphy));
3036 goto err_iounmap;
3037 }
3038 }
3039
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003040 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3041 priv->band.band = IEEE80211_BAND_2GHZ;
3042 priv->band.channels = priv->channels;
3043 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3044 priv->band.bitrates = priv->rates;
3045 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3046 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3047
3048 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3049 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3050
3051 /*
3052 * Extra headroom is the size of the required DMA header
3053 * minus the size of the smallest 802.11 frame (CTS frame).
3054 */
3055 hw->extra_tx_headroom =
3056 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3057
3058 hw->channel_change_time = 10;
3059
3060 hw->queues = MWL8K_TX_QUEUES;
3061
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02003062 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003063
3064 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003065 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003066 hw->vif_data_size = sizeof(struct mwl8k_vif);
3067 priv->vif = NULL;
3068
3069 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003070 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003071 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003072
3073 /* Finalize join worker */
3074 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3075
3076 /* TX reclaim tasklet */
3077 tasklet_init(&priv->tx_reclaim_task,
3078 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3079 tasklet_disable(&priv->tx_reclaim_task);
3080
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003081 /* Power management cookie */
3082 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3083 if (priv->cookie == NULL)
3084 goto err_iounmap;
3085
3086 rc = mwl8k_rxq_init(hw, 0);
3087 if (rc)
3088 goto err_iounmap;
3089 rxq_refill(hw, 0, INT_MAX);
3090
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003091 mutex_init(&priv->fw_mutex);
3092 priv->fw_mutex_owner = NULL;
3093 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003094 priv->hostcmd_wait = NULL;
3095
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003096 spin_lock_init(&priv->tx_lock);
3097
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003098 priv->tx_wait = NULL;
3099
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003100 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3101 rc = mwl8k_txq_init(hw, i);
3102 if (rc)
3103 goto err_free_queues;
3104 }
3105
3106 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003107 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003108 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3109 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3110
3111 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
3112 IRQF_SHARED, MWL8K_NAME, hw);
3113 if (rc) {
3114 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003115 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003116 goto err_free_queues;
3117 }
3118
3119 /* Reset firmware and hardware */
3120 mwl8k_hw_reset(priv);
3121
3122 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003123 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003124 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003125 printk(KERN_ERR "%s: Firmware files not found\n",
3126 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003127 goto err_free_irq;
3128 }
3129
3130 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003131 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003132 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003133 printk(KERN_ERR "%s: Cannot start firmware\n",
3134 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003135 goto err_stop_firmware;
3136 }
3137
3138 /* Reclaim memory once firmware is successfully loaded */
3139 mwl8k_release_firmware(priv);
3140
3141 /*
3142 * Temporarily enable interrupts. Initial firmware host
3143 * commands use interrupts and avoids polling. Disable
3144 * interrupts when done.
3145 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003146 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003147
3148 /* Get config data, mac addrs etc */
3149 rc = mwl8k_cmd_get_hw_spec(hw);
3150 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003151 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3152 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003153 goto err_stop_firmware;
3154 }
3155
3156 /* Turn radio off */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003157 rc = mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003158 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003159 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003160 goto err_stop_firmware;
3161 }
3162
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003163 /* Clear MAC address */
3164 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3165 if (rc) {
3166 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3167 wiphy_name(hw->wiphy));
3168 goto err_stop_firmware;
3169 }
3170
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003171 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003172 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003173 free_irq(priv->pdev->irq, hw);
3174
3175 rc = ieee80211_register_hw(hw);
3176 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003177 printk(KERN_ERR "%s: Cannot register device\n",
3178 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003179 goto err_stop_firmware;
3180 }
3181
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003182 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003183 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003184 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003185 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003186 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3187 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003188
3189 return 0;
3190
3191err_stop_firmware:
3192 mwl8k_hw_reset(priv);
3193 mwl8k_release_firmware(priv);
3194
3195err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003196 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003197 free_irq(priv->pdev->irq, hw);
3198
3199err_free_queues:
3200 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3201 mwl8k_txq_deinit(hw, i);
3202 mwl8k_rxq_deinit(hw, 0);
3203
3204err_iounmap:
3205 if (priv->cookie != NULL)
3206 pci_free_consistent(priv->pdev, 4,
3207 priv->cookie, priv->cookie_dma);
3208
3209 if (priv->regs != NULL)
3210 pci_iounmap(pdev, priv->regs);
3211
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003212 if (priv->sram != NULL)
3213 pci_iounmap(pdev, priv->sram);
3214
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003215 pci_set_drvdata(pdev, NULL);
3216 ieee80211_free_hw(hw);
3217
3218err_free_reg:
3219 pci_release_regions(pdev);
3220 pci_disable_device(pdev);
3221
3222 return rc;
3223}
3224
Joerg Albert230f7af2009-04-18 02:10:45 +02003225static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003226{
3227 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3228}
3229
Joerg Albert230f7af2009-04-18 02:10:45 +02003230static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003231{
3232 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3233 struct mwl8k_priv *priv;
3234 int i;
3235
3236 if (hw == NULL)
3237 return;
3238 priv = hw->priv;
3239
3240 ieee80211_stop_queues(hw);
3241
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003242 ieee80211_unregister_hw(hw);
3243
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003244 /* Remove tx reclaim tasklet */
3245 tasklet_kill(&priv->tx_reclaim_task);
3246
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003247 /* Stop hardware */
3248 mwl8k_hw_reset(priv);
3249
3250 /* Return all skbs to mac80211 */
3251 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3252 mwl8k_txq_reclaim(hw, i, 1);
3253
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003254 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3255 mwl8k_txq_deinit(hw, i);
3256
3257 mwl8k_rxq_deinit(hw, 0);
3258
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003259 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003260
3261 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003262 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003263 pci_set_drvdata(pdev, NULL);
3264 ieee80211_free_hw(hw);
3265 pci_release_regions(pdev);
3266 pci_disable_device(pdev);
3267}
3268
3269static struct pci_driver mwl8k_driver = {
3270 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003271 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003272 .probe = mwl8k_probe,
3273 .remove = __devexit_p(mwl8k_remove),
3274 .shutdown = __devexit_p(mwl8k_shutdown),
3275};
3276
3277static int __init mwl8k_init(void)
3278{
3279 return pci_register_driver(&mwl8k_driver);
3280}
3281
3282static void __exit mwl8k_exit(void)
3283{
3284 pci_unregister_driver(&mwl8k_driver);
3285}
3286
3287module_init(mwl8k_init);
3288module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003289
3290MODULE_DESCRIPTION(MWL8K_DESC);
3291MODULE_VERSION(MWL8K_VERSION);
3292MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3293MODULE_LICENSE("GPL");