blob: b0080ae98a8385f4aa74cb26a38860618c5113c6 [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;
133
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100134 /* firmware files and meta data */
135 struct mwl8k_firmware fw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100136
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200137 /* firmware access */
138 struct mutex fw_mutex;
139 struct task_struct *fw_mutex_owner;
140 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200141 struct completion *hostcmd_wait;
142
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100143 /* lock held over TX and TX reap */
144 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100145
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200146 /* TX quiesce completion, protected by fw_mutex and tx_lock */
147 struct completion *tx_wait;
148
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100149 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100150
151 struct ieee80211_channel *current_channel;
152
153 /* power management status cookie from firmware */
154 u32 *cookie;
155 dma_addr_t cookie_dma;
156
157 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100158 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200159 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100160
161 /*
162 * Running count of TX packets in flight, to avoid
163 * iterating over the transmit rings each time.
164 */
165 int pending_tx_pkts;
166
167 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
168 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
169
170 /* PHY parameters */
171 struct ieee80211_supported_band band;
172 struct ieee80211_channel channels[14];
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200173 struct ieee80211_rate rates[13];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100174
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200175 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200176 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200177 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200178 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100179
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100180 /* XXX need to convert this to handle multiple interfaces */
181 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200182 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100183 struct sk_buff *beacon_skb;
184
185 /*
186 * This FJ worker has to be global as it is scheduled from the
187 * RX handler. At this point we don't know which interface it
188 * belongs to until the list of bssids waiting to complete join
189 * is checked.
190 */
191 struct work_struct finalize_join_worker;
192
193 /* Tasklet to reclaim TX descriptors and buffers after tx */
194 struct tasklet_struct tx_reclaim_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100195};
196
197/* Per interface specific private data */
198struct mwl8k_vif {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100199 /* backpointer to parent config block */
200 struct mwl8k_priv *priv;
201
202 /* BSS config of AP or IBSS from mac80211*/
203 struct ieee80211_bss_conf bss_info;
204
205 /* BSSID of AP or IBSS */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200206 u8 bssid[ETH_ALEN];
207 u8 mac_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100208
209 /*
210 * Subset of supported legacy rates.
211 * Intersection of AP and STA supported rates.
212 */
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200213 struct ieee80211_rate legacy_rates[13];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100214
215 /* number of supported legacy rates */
216 u8 legacy_nrates;
217
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100218 /* Index into station database.Returned by update_sta_db call */
219 u8 peer_id;
220
221 /* Non AMPDU sequence number assigned by driver */
222 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100223};
224
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200225#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100226
227static const struct ieee80211_channel mwl8k_channels[] = {
228 { .center_freq = 2412, .hw_value = 1, },
229 { .center_freq = 2417, .hw_value = 2, },
230 { .center_freq = 2422, .hw_value = 3, },
231 { .center_freq = 2427, .hw_value = 4, },
232 { .center_freq = 2432, .hw_value = 5, },
233 { .center_freq = 2437, .hw_value = 6, },
234 { .center_freq = 2442, .hw_value = 7, },
235 { .center_freq = 2447, .hw_value = 8, },
236 { .center_freq = 2452, .hw_value = 9, },
237 { .center_freq = 2457, .hw_value = 10, },
238 { .center_freq = 2462, .hw_value = 11, },
239};
240
241static const struct ieee80211_rate mwl8k_rates[] = {
242 { .bitrate = 10, .hw_value = 2, },
243 { .bitrate = 20, .hw_value = 4, },
244 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200245 { .bitrate = 110, .hw_value = 22, },
246 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100247 { .bitrate = 60, .hw_value = 12, },
248 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100249 { .bitrate = 120, .hw_value = 24, },
250 { .bitrate = 180, .hw_value = 36, },
251 { .bitrate = 240, .hw_value = 48, },
252 { .bitrate = 360, .hw_value = 72, },
253 { .bitrate = 480, .hw_value = 96, },
254 { .bitrate = 540, .hw_value = 108, },
255};
256
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100257/* Set or get info from Firmware */
258#define MWL8K_CMD_SET 0x0001
259#define MWL8K_CMD_GET 0x0000
260
261/* Firmware command codes */
262#define MWL8K_CMD_CODE_DNLD 0x0001
263#define MWL8K_CMD_GET_HW_SPEC 0x0003
264#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
265#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200266#define MWL8K_CMD_RADIO_CONTROL 0x001c
267#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100268#define MWL8K_CMD_SET_PRE_SCAN 0x0107
269#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200270#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100271#define MWL8K_CMD_SET_AID 0x010d
272#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200273#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100274#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200275#define MWL8K_CMD_SET_SLOT 0x0114
276#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
277#define MWL8K_CMD_SET_WMM_MODE 0x0123
278#define MWL8K_CMD_MIMO_CONFIG 0x0125
279#define MWL8K_CMD_USE_FIXED_RATE 0x0126
280#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200281#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200282#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
283#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100284
285static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
286{
287#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
288 snprintf(buf, bufsize, "%s", #x);\
289 return buf;\
290 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200291 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100292 MWL8K_CMDNAME(CODE_DNLD);
293 MWL8K_CMDNAME(GET_HW_SPEC);
294 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
295 MWL8K_CMDNAME(GET_STAT);
296 MWL8K_CMDNAME(RADIO_CONTROL);
297 MWL8K_CMDNAME(RF_TX_POWER);
298 MWL8K_CMDNAME(SET_PRE_SCAN);
299 MWL8K_CMDNAME(SET_POST_SCAN);
300 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100301 MWL8K_CMDNAME(SET_AID);
302 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200303 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100304 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200305 MWL8K_CMDNAME(SET_SLOT);
306 MWL8K_CMDNAME(SET_EDCA_PARAMS);
307 MWL8K_CMDNAME(SET_WMM_MODE);
308 MWL8K_CMDNAME(MIMO_CONFIG);
309 MWL8K_CMDNAME(USE_FIXED_RATE);
310 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200311 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200312 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
313 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100314 default:
315 snprintf(buf, bufsize, "0x%x", cmd);
316 }
317#undef MWL8K_CMDNAME
318
319 return buf;
320}
321
322/* Hardware and firmware reset */
323static void mwl8k_hw_reset(struct mwl8k_priv *priv)
324{
325 iowrite32(MWL8K_H2A_INT_RESET,
326 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
327 iowrite32(MWL8K_H2A_INT_RESET,
328 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
329 msleep(20);
330}
331
332/* Release fw image */
333static void mwl8k_release_fw(struct firmware **fw)
334{
335 if (*fw == NULL)
336 return;
337 release_firmware(*fw);
338 *fw = NULL;
339}
340
341static void mwl8k_release_firmware(struct mwl8k_priv *priv)
342{
343 mwl8k_release_fw(&priv->fw.ucode);
344 mwl8k_release_fw(&priv->fw.helper);
345}
346
347/* Request fw image */
348static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200349 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100350{
351 /* release current image */
352 if (*fw != NULL)
353 mwl8k_release_fw(fw);
354
355 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200356 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100357}
358
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200359static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100360{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200361 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100362 int rc;
363
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200364 if (di->helper_image != NULL) {
365 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
366 if (rc) {
367 printk(KERN_ERR "%s: Error requesting helper "
368 "firmware file %s\n", pci_name(priv->pdev),
369 di->helper_image);
370 return rc;
371 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100372 }
373
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200374 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100375 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200376 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200377 pci_name(priv->pdev), di->fw_image);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100378 mwl8k_release_fw(&priv->fw.helper);
379 return rc;
380 }
381
382 return 0;
383}
384
385struct mwl8k_cmd_pkt {
386 __le16 code;
387 __le16 length;
388 __le16 seq_num;
389 __le16 result;
390 char payload[0];
391} __attribute__((packed));
392
393/*
394 * Firmware loading.
395 */
396static int
397mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
398{
399 void __iomem *regs = priv->regs;
400 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100401 int loops;
402
403 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
404 if (pci_dma_mapping_error(priv->pdev, dma_addr))
405 return -ENOMEM;
406
407 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
408 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
409 iowrite32(MWL8K_H2A_INT_DOORBELL,
410 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
411 iowrite32(MWL8K_H2A_INT_DUMMY,
412 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
413
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100414 loops = 1000;
415 do {
416 u32 int_code;
417
418 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
419 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
420 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100421 break;
422 }
423
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200424 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100425 udelay(1);
426 } while (--loops);
427
428 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
429
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200430 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100431}
432
433static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
434 const u8 *data, size_t length)
435{
436 struct mwl8k_cmd_pkt *cmd;
437 int done;
438 int rc = 0;
439
440 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
441 if (cmd == NULL)
442 return -ENOMEM;
443
444 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
445 cmd->seq_num = 0;
446 cmd->result = 0;
447
448 done = 0;
449 while (length) {
450 int block_size = length > 256 ? 256 : length;
451
452 memcpy(cmd->payload, data + done, block_size);
453 cmd->length = cpu_to_le16(block_size);
454
455 rc = mwl8k_send_fw_load_cmd(priv, cmd,
456 sizeof(*cmd) + block_size);
457 if (rc)
458 break;
459
460 done += block_size;
461 length -= block_size;
462 }
463
464 if (!rc) {
465 cmd->length = 0;
466 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
467 }
468
469 kfree(cmd);
470
471 return rc;
472}
473
474static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
475 const u8 *data, size_t length)
476{
477 unsigned char *buffer;
478 int may_continue, rc = 0;
479 u32 done, prev_block_size;
480
481 buffer = kmalloc(1024, GFP_KERNEL);
482 if (buffer == NULL)
483 return -ENOMEM;
484
485 done = 0;
486 prev_block_size = 0;
487 may_continue = 1000;
488 while (may_continue > 0) {
489 u32 block_size;
490
491 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
492 if (block_size & 1) {
493 block_size &= ~1;
494 may_continue--;
495 } else {
496 done += prev_block_size;
497 length -= prev_block_size;
498 }
499
500 if (block_size > 1024 || block_size > length) {
501 rc = -EOVERFLOW;
502 break;
503 }
504
505 if (length == 0) {
506 rc = 0;
507 break;
508 }
509
510 if (block_size == 0) {
511 rc = -EPROTO;
512 may_continue--;
513 udelay(1);
514 continue;
515 }
516
517 prev_block_size = block_size;
518 memcpy(buffer, data + done, block_size);
519
520 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
521 if (rc)
522 break;
523 }
524
525 if (!rc && length != 0)
526 rc = -EREMOTEIO;
527
528 kfree(buffer);
529
530 return rc;
531}
532
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200533static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100534{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200535 struct mwl8k_priv *priv = hw->priv;
536 struct firmware *fw = priv->fw.ucode;
537 int rc;
538 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100539
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200540 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
541 struct firmware *helper = priv->fw.helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100542
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200543 if (helper == NULL) {
544 printk(KERN_ERR "%s: helper image needed but none "
545 "given\n", pci_name(priv->pdev));
546 return -EINVAL;
547 }
548
549 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100550 if (rc) {
551 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200552 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100553 return rc;
554 }
555 msleep(1);
556
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200557 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100558 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200559 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100560 }
561
562 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200563 printk(KERN_ERR "%s: unable to load firmware image\n",
564 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100565 return rc;
566 }
567
568 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
569 msleep(1);
570
571 loops = 200000;
572 do {
573 if (ioread32(priv->regs + MWL8K_HIU_INT_CODE)
574 == MWL8K_FWSTA_READY)
575 break;
576 udelay(1);
577 } while (--loops);
578
579 return loops ? 0 : -ETIMEDOUT;
580}
581
582
583/*
584 * Defines shared between transmission and reception.
585 */
586/* HT control fields for firmware */
587struct ewc_ht_info {
588 __le16 control1;
589 __le16 control2;
590 __le16 control3;
591} __attribute__((packed));
592
593/* Firmware Station database operations */
594#define MWL8K_STA_DB_ADD_ENTRY 0
595#define MWL8K_STA_DB_MODIFY_ENTRY 1
596#define MWL8K_STA_DB_DEL_ENTRY 2
597#define MWL8K_STA_DB_FLUSH 3
598
599/* Peer Entry flags - used to define the type of the peer node */
600#define MWL8K_PEER_TYPE_ACCESSPOINT 2
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100601
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200602#define MWL8K_IEEE_LEGACY_DATA_RATES 13
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100603#define MWL8K_MCS_BITMAP_SIZE 16
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100604
605struct peer_capability_info {
606 /* Peer type - AP vs. STA. */
607 __u8 peer_type;
608
609 /* Basic 802.11 capabilities from assoc resp. */
610 __le16 basic_caps;
611
612 /* Set if peer supports 802.11n high throughput (HT). */
613 __u8 ht_support;
614
615 /* Valid if HT is supported. */
616 __le16 ht_caps;
617 __u8 extended_ht_caps;
618 struct ewc_ht_info ewc_info;
619
620 /* Legacy rate table. Intersection of our rates and peer rates. */
621 __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
622
623 /* HT rate table. Intersection of our rates and peer rates. */
624 __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +0200625 __u8 pad[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100626
627 /* If set, interoperability mode, no proprietary extensions. */
628 __u8 interop;
629 __u8 pad2;
630 __u8 station_id;
631 __le16 amsdu_enabled;
632} __attribute__((packed));
633
634/* Inline functions to manipulate QoS field in data descriptor. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100635static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
636{
637 u16 val_mask = 1 << 4;
638
639 /* End of Service Period Bit 4 */
640 return qos | val_mask;
641}
642
643static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
644{
645 u16 val_mask = 0x3;
646 u8 shift = 5;
647 u16 qos_mask = ~(val_mask << shift);
648
649 /* Ack Policy Bit 5-6 */
650 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
651}
652
653static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
654{
655 u16 val_mask = 1 << 7;
656
657 /* AMSDU present Bit 7 */
658 return qos | val_mask;
659}
660
661static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
662{
663 u16 val_mask = 0xff;
664 u8 shift = 8;
665 u16 qos_mask = ~(val_mask << shift);
666
667 /* Queue Length Bits 8-15 */
668 return (qos & qos_mask) | ((len & val_mask) << shift);
669}
670
671/* DMA header used by firmware and hardware. */
672struct mwl8k_dma_data {
673 __le16 fwlen;
674 struct ieee80211_hdr wh;
675} __attribute__((packed));
676
677/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200678static inline void mwl8k_remove_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100679{
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200680 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)skb->data;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100681 void *dst, *src = &tr->wh;
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200682 int hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100683 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
684
685 dst = (void *)tr + space;
686 if (dst != src) {
687 memmove(dst, src, hdrlen);
688 skb_pull(skb, space);
689 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100690}
691
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200692static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100693{
694 struct ieee80211_hdr *wh;
695 u32 hdrlen, pktlen;
696 struct mwl8k_dma_data *tr;
697
698 wh = (struct ieee80211_hdr *)skb->data;
699 hdrlen = ieee80211_hdrlen(wh->frame_control);
700 pktlen = skb->len;
701
702 /*
703 * Copy up/down the 802.11 header; the firmware requires
704 * we present a 2-byte payload length followed by a
705 * 4-address header (w/o QoS), followed (optionally) by
706 * any WEP/ExtIV header (but only filled in for CCMP).
707 */
708 if (hdrlen != sizeof(struct mwl8k_dma_data))
709 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
710
711 tr = (struct mwl8k_dma_data *)skb->data;
712 if (wh != &tr->wh)
713 memmove(&tr->wh, wh, hdrlen);
714
715 /* Clear addr4 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200716 memset(tr->wh.addr4, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100717
718 /*
719 * Firmware length is the length of the fully formed "802.11
720 * payload". That is, everything except for the 802.11 header.
721 * This includes all crypto material including the MIC.
722 */
723 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100724}
725
726
727/*
728 * Packet reception.
729 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100730#define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100731
732struct mwl8k_rx_desc {
733 __le16 pkt_len;
734 __u8 link_quality;
735 __u8 noise_level;
736 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200737 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100738 __le16 qos_control;
739 __le16 rate_info;
740 __le32 pad0[4];
741 __u8 rssi;
742 __u8 channel;
743 __le16 pad1;
744 __u8 rx_ctrl;
745 __u8 rx_status;
746 __u8 pad2[2];
747} __attribute__((packed));
748
749#define MWL8K_RX_DESCS 256
750#define MWL8K_RX_MAXSZ 3800
751
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200752#define RATE_INFO_SHORTPRE 0x8000
753#define RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
754#define RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
755#define RATE_INFO_40MHZ 0x0004
756#define RATE_INFO_SHORTGI 0x0002
757#define RATE_INFO_MCS_FORMAT 0x0001
758
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100759static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
760{
761 struct mwl8k_priv *priv = hw->priv;
762 struct mwl8k_rx_queue *rxq = priv->rxq + index;
763 int size;
764 int i;
765
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200766 rxq->rxd_count = 0;
767 rxq->head = 0;
768 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100769
770 size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc);
771
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200772 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
773 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100774 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200775 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100776 return -ENOMEM;
777 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200778 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100779
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200780 rxq->skb = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->skb), GFP_KERNEL);
781 if (rxq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100782 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200783 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200784 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100785 return -ENOMEM;
786 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200787 memset(rxq->skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100788
789 for (i = 0; i < MWL8K_RX_DESCS; i++) {
790 struct mwl8k_rx_desc *rx_desc;
791 int nexti;
792
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200793 rx_desc = rxq->rxd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100794 nexti = (i + 1) % MWL8K_RX_DESCS;
795
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200796 rx_desc->next_rxd_phys_addr =
797 cpu_to_le32(rxq->rxd_dma + nexti * sizeof(*rx_desc));
Rami Rosenc491bf12009-04-21 16:22:01 +0300798 rx_desc->rx_ctrl = MWL8K_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100799 }
800
801 return 0;
802}
803
804static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
805{
806 struct mwl8k_priv *priv = hw->priv;
807 struct mwl8k_rx_queue *rxq = priv->rxq + index;
808 int refilled;
809
810 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200811 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100812 struct sk_buff *skb;
813 int rx;
814
815 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
816 if (skb == NULL)
817 break;
818
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200819 rxq->rxd_count++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100820
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200821 rx = rxq->tail;
822 rxq->tail = (rx + 1) % MWL8K_RX_DESCS;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100823
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200824 rxq->rxd[rx].pkt_phys_addr =
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100825 cpu_to_le32(pci_map_single(priv->pdev, skb->data,
826 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE));
827
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200828 rxq->rxd[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ);
829 rxq->skb[rx] = skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100830 wmb();
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200831 rxq->rxd[rx].rx_ctrl = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100832
833 refilled++;
834 }
835
836 return refilled;
837}
838
839/* Must be called only when the card's reception is completely halted */
840static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
841{
842 struct mwl8k_priv *priv = hw->priv;
843 struct mwl8k_rx_queue *rxq = priv->rxq + index;
844 int i;
845
846 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200847 if (rxq->skb[i] != NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100848 unsigned long addr;
849
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200850 addr = le32_to_cpu(rxq->rxd[i].pkt_phys_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100851 pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ,
852 PCI_DMA_FROMDEVICE);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200853 kfree_skb(rxq->skb[i]);
854 rxq->skb[i] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100855 }
856 }
857
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200858 kfree(rxq->skb);
859 rxq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100860
861 pci_free_consistent(priv->pdev,
862 MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200863 rxq->rxd, rxq->rxd_dma);
864 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100865}
866
867
868/*
869 * Scan a list of BSSIDs to process for finalize join.
870 * Allows for extension to process multiple BSSIDs.
871 */
872static inline int
873mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
874{
875 return priv->capture_beacon &&
876 ieee80211_is_beacon(wh->frame_control) &&
877 !compare_ether_addr(wh->addr3, priv->capture_bssid);
878}
879
Lennert Buytenhek37797522009-10-22 20:19:45 +0200880static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
881 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100882{
Lennert Buytenhek37797522009-10-22 20:19:45 +0200883 struct mwl8k_priv *priv = hw->priv;
884
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100885 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200886 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100887
888 /*
889 * Use GFP_ATOMIC as rxq_process is called from
890 * the primary interrupt handler, memory allocation call
891 * must not sleep.
892 */
893 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
894 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +0200895 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100896}
897
898static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
899{
900 struct mwl8k_priv *priv = hw->priv;
901 struct mwl8k_rx_queue *rxq = priv->rxq + index;
902 int processed;
903
904 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200905 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100906 struct mwl8k_rx_desc *rx_desc;
907 struct sk_buff *skb;
908 struct ieee80211_rx_status status;
909 unsigned long addr;
910 struct ieee80211_hdr *wh;
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200911 u16 rate_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100912
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200913 rx_desc = rxq->rxd + rxq->head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100914 if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST))
915 break;
916 rmb();
917
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200918 skb = rxq->skb[rxq->head];
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +0200919 if (skb == NULL)
920 break;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200921 rxq->skb[rxq->head] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100922
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200923 rxq->head = (rxq->head + 1) % MWL8K_RX_DESCS;
924 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100925
926 addr = le32_to_cpu(rx_desc->pkt_phys_addr);
927 pci_unmap_single(priv->pdev, addr,
928 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
929
930 skb_put(skb, le16_to_cpu(rx_desc->pkt_len));
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200931 mwl8k_remove_dma_header(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100932
933 wh = (struct ieee80211_hdr *)skb->data;
934
935 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200936 * Check for a pending join operation. Save a
937 * copy of the beacon and schedule a tasklet to
938 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100939 */
940 if (mwl8k_capture_bssid(priv, wh))
Lennert Buytenhek37797522009-10-22 20:19:45 +0200941 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100942
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200943 rate_info = le16_to_cpu(rx_desc->rate_info);
944
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100945 memset(&status, 0, sizeof(status));
946 status.mactime = 0;
947 status.signal = -rx_desc->rssi;
948 status.noise = -rx_desc->noise_level;
949 status.qual = rx_desc->link_quality;
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200950 status.antenna = RATE_INFO_ANTSELECT(rate_info);
951 status.rate_idx = RATE_INFO_RATEID(rate_info);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100952 status.flag = 0;
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200953 if (rate_info & RATE_INFO_SHORTPRE)
954 status.flag |= RX_FLAG_SHORTPRE;
955 if (rate_info & RATE_INFO_40MHZ)
956 status.flag |= RX_FLAG_40MHZ;
957 if (rate_info & RATE_INFO_SHORTGI)
958 status.flag |= RX_FLAG_SHORT_GI;
959 if (rate_info & RATE_INFO_MCS_FORMAT)
960 status.flag |= RX_FLAG_HT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100961 status.band = IEEE80211_BAND_2GHZ;
962 status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
Johannes Bergf1d58c22009-06-17 13:13:00 +0200963 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
964 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100965
966 processed++;
967 }
968
969 return processed;
970}
971
972
973/*
974 * Packet transmission.
975 */
976
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100977/* Transmit packet ACK policy */
978#define MWL8K_TXD_ACK_POLICY_NORMAL 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100979#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
980
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100981#define MWL8K_TXD_STATUS_OK 0x00000001
982#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
983#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
984#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100985#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100986
987struct mwl8k_tx_desc {
988 __le32 status;
989 __u8 data_rate;
990 __u8 tx_priority;
991 __le16 qos_control;
992 __le32 pkt_phys_addr;
993 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200994 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200995 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100996 __le32 reserved;
997 __le16 rate_info;
998 __u8 peer_id;
999 __u8 tx_frag_cnt;
1000} __attribute__((packed));
1001
1002#define MWL8K_TX_DESCS 128
1003
1004static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1005{
1006 struct mwl8k_priv *priv = hw->priv;
1007 struct mwl8k_tx_queue *txq = priv->txq + index;
1008 int size;
1009 int i;
1010
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001011 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1012 txq->stats.limit = MWL8K_TX_DESCS;
1013 txq->head = 0;
1014 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001015
1016 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1017
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001018 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1019 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001020 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001021 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001022 return -ENOMEM;
1023 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001024 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001025
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001026 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1027 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001028 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001029 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001030 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001031 return -ENOMEM;
1032 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001033 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001034
1035 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1036 struct mwl8k_tx_desc *tx_desc;
1037 int nexti;
1038
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001039 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001040 nexti = (i + 1) % MWL8K_TX_DESCS;
1041
1042 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001043 tx_desc->next_txd_phys_addr =
1044 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001045 }
1046
1047 return 0;
1048}
1049
1050static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1051{
1052 iowrite32(MWL8K_H2A_INT_PPA_READY,
1053 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1054 iowrite32(MWL8K_H2A_INT_DUMMY,
1055 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1056 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1057}
1058
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001059struct mwl8k_txq_info {
1060 u32 fw_owned;
1061 u32 drv_owned;
1062 u32 unused;
1063 u32 len;
1064 u32 head;
1065 u32 tail;
1066};
1067
1068static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001069 struct mwl8k_txq_info *txinfo)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001070{
1071 int count, desc, status;
1072 struct mwl8k_tx_queue *txq;
1073 struct mwl8k_tx_desc *tx_desc;
1074 int ndescs = 0;
1075
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001076 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
1077
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001078 for (count = 0; count < MWL8K_TX_QUEUES; count++) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001079 txq = priv->txq + count;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001080 txinfo[count].len = txq->stats.len;
1081 txinfo[count].head = txq->head;
1082 txinfo[count].tail = txq->tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001083 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001084 tx_desc = txq->txd + desc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001085 status = le32_to_cpu(tx_desc->status);
1086
1087 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1088 txinfo[count].fw_owned++;
1089 else
1090 txinfo[count].drv_owned++;
1091
1092 if (tx_desc->pkt_len == 0)
1093 txinfo[count].unused++;
1094 }
1095 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001096
1097 return ndescs;
1098}
1099
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001100/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001101 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001102 */
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001103static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001104{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001105 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001106 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001107 u32 count;
1108 unsigned long timeout;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001109
1110 might_sleep();
1111
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001112 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001113 count = priv->pending_tx_pkts;
1114 if (count)
1115 priv->tx_wait = &tx_wait;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001116 spin_unlock_bh(&priv->tx_lock);
1117
1118 if (count) {
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001119 struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001120 int index;
1121 int newcount;
1122
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001123 timeout = wait_for_completion_timeout(&tx_wait,
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001124 msecs_to_jiffies(5000));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001125 if (timeout)
1126 return 0;
1127
1128 spin_lock_bh(&priv->tx_lock);
1129 priv->tx_wait = NULL;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001130 newcount = priv->pending_tx_pkts;
1131 mwl8k_scan_tx_ring(priv, txinfo);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001132 spin_unlock_bh(&priv->tx_lock);
1133
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001134 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001135 __func__, __LINE__, count, newcount);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001136
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001137 for (index = 0; index < MWL8K_TX_QUEUES; index++)
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001138 printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u "
1139 "DRV:%u U:%u\n",
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001140 index,
1141 txinfo[index].len,
1142 txinfo[index].head,
1143 txinfo[index].tail,
1144 txinfo[index].fw_owned,
1145 txinfo[index].drv_owned,
1146 txinfo[index].unused);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001147
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001148 return -ETIMEDOUT;
1149 }
1150
1151 return 0;
1152}
1153
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001154#define MWL8K_TXD_SUCCESS(status) \
1155 ((status) & (MWL8K_TXD_STATUS_OK | \
1156 MWL8K_TXD_STATUS_OK_RETRY | \
1157 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001158
1159static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1160{
1161 struct mwl8k_priv *priv = hw->priv;
1162 struct mwl8k_tx_queue *txq = priv->txq + index;
1163 int wake = 0;
1164
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001165 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001166 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001167 struct mwl8k_tx_desc *tx_desc;
1168 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001169 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001170 struct sk_buff *skb;
1171 struct ieee80211_tx_info *info;
1172 u32 status;
1173
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001174 tx = txq->head;
1175 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001176
1177 status = le32_to_cpu(tx_desc->status);
1178
1179 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1180 if (!force)
1181 break;
1182 tx_desc->status &=
1183 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1184 }
1185
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001186 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1187 BUG_ON(txq->stats.len == 0);
1188 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001189 priv->pending_tx_pkts--;
1190
1191 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001192 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001193 skb = txq->skb[tx];
1194 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001195
1196 BUG_ON(skb == NULL);
1197 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1198
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001199 mwl8k_remove_dma_header(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001200
1201 /* Mark descriptor as unused */
1202 tx_desc->pkt_phys_addr = 0;
1203 tx_desc->pkt_len = 0;
1204
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001205 info = IEEE80211_SKB_CB(skb);
1206 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001207 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001208 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001209
1210 ieee80211_tx_status_irqsafe(hw, skb);
1211
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001212 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001213 }
1214
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001215 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001216 ieee80211_wake_queue(hw, index);
1217}
1218
1219/* must be called only when the card's transmit is completely halted */
1220static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1221{
1222 struct mwl8k_priv *priv = hw->priv;
1223 struct mwl8k_tx_queue *txq = priv->txq + index;
1224
1225 mwl8k_txq_reclaim(hw, index, 1);
1226
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001227 kfree(txq->skb);
1228 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001229
1230 pci_free_consistent(priv->pdev,
1231 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001232 txq->txd, txq->txd_dma);
1233 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001234}
1235
1236static int
1237mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1238{
1239 struct mwl8k_priv *priv = hw->priv;
1240 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001241 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001242 struct ieee80211_hdr *wh;
1243 struct mwl8k_tx_queue *txq;
1244 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001245 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001246 u32 txstatus;
1247 u8 txdatarate;
1248 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001249
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001250 wh = (struct ieee80211_hdr *)skb->data;
1251 if (ieee80211_is_data_qos(wh->frame_control))
1252 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1253 else
1254 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001255
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001256 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001257 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001258
1259 tx_info = IEEE80211_SKB_CB(skb);
1260 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001261
1262 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1263 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001264
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001265 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1266 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1267 mwl8k_vif->seqno = seqno++ % 4096;
1268 }
1269
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001270 /* Setup firmware control bit fields for each frame type. */
1271 txstatus = 0;
1272 txdatarate = 0;
1273 if (ieee80211_is_mgmt(wh->frame_control) ||
1274 ieee80211_is_ctl(wh->frame_control)) {
1275 txdatarate = 0;
1276 qos = mwl8k_qos_setbit_eosp(qos);
1277 /* Set Queue size to unspecified */
1278 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1279 } else if (ieee80211_is_data(wh->frame_control)) {
1280 txdatarate = 1;
1281 if (is_multicast_ether_addr(wh->addr1))
1282 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1283
1284 /* Send pkt in an aggregate if AMPDU frame. */
1285 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1286 qos = mwl8k_qos_setbit_ack(qos,
1287 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1288 else
1289 qos = mwl8k_qos_setbit_ack(qos,
1290 MWL8K_TXD_ACK_POLICY_NORMAL);
1291
1292 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1293 qos = mwl8k_qos_setbit_amsdu(qos);
1294 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001295
1296 dma = pci_map_single(priv->pdev, skb->data,
1297 skb->len, PCI_DMA_TODEVICE);
1298
1299 if (pci_dma_mapping_error(priv->pdev, dma)) {
1300 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001301 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001302 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001303 return NETDEV_TX_OK;
1304 }
1305
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001306 spin_lock_bh(&priv->tx_lock);
1307
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001308 txq = priv->txq + index;
1309
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001310 BUG_ON(txq->skb[txq->tail] != NULL);
1311 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001312
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001313 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001314 tx->data_rate = txdatarate;
1315 tx->tx_priority = index;
1316 tx->qos_control = cpu_to_le16(qos);
1317 tx->pkt_phys_addr = cpu_to_le32(dma);
1318 tx->pkt_len = cpu_to_le16(skb->len);
1319 tx->rate_info = 0;
1320 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001321 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001322 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1323
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001324 txq->stats.count++;
1325 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001326 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001327
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001328 txq->tail++;
1329 if (txq->tail == MWL8K_TX_DESCS)
1330 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001331
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001332 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001333 ieee80211_stop_queue(hw, index);
1334
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001335 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001336
1337 spin_unlock_bh(&priv->tx_lock);
1338
1339 return NETDEV_TX_OK;
1340}
1341
1342
1343/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001344 * Firmware access.
1345 *
1346 * We have the following requirements for issuing firmware commands:
1347 * - Some commands require that the packet transmit path is idle when
1348 * the command is issued. (For simplicity, we'll just quiesce the
1349 * transmit path for every command.)
1350 * - There are certain sequences of commands that need to be issued to
1351 * the hardware sequentially, with no other intervening commands.
1352 *
1353 * This leads to an implementation of a "firmware lock" as a mutex that
1354 * can be taken recursively, and which is taken by both the low-level
1355 * command submission function (mwl8k_post_cmd) as well as any users of
1356 * that function that require issuing of an atomic sequence of commands,
1357 * and quiesces the transmit path whenever it's taken.
1358 */
1359static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1360{
1361 struct mwl8k_priv *priv = hw->priv;
1362
1363 if (priv->fw_mutex_owner != current) {
1364 int rc;
1365
1366 mutex_lock(&priv->fw_mutex);
1367 ieee80211_stop_queues(hw);
1368
1369 rc = mwl8k_tx_wait_empty(hw);
1370 if (rc) {
1371 ieee80211_wake_queues(hw);
1372 mutex_unlock(&priv->fw_mutex);
1373
1374 return rc;
1375 }
1376
1377 priv->fw_mutex_owner = current;
1378 }
1379
1380 priv->fw_mutex_depth++;
1381
1382 return 0;
1383}
1384
1385static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1386{
1387 struct mwl8k_priv *priv = hw->priv;
1388
1389 if (!--priv->fw_mutex_depth) {
1390 ieee80211_wake_queues(hw);
1391 priv->fw_mutex_owner = NULL;
1392 mutex_unlock(&priv->fw_mutex);
1393 }
1394}
1395
1396
1397/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001398 * Command processing.
1399 */
1400
1401/* Timeout firmware commands after 2000ms */
1402#define MWL8K_CMD_TIMEOUT_MS 2000
1403
1404static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1405{
1406 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1407 struct mwl8k_priv *priv = hw->priv;
1408 void __iomem *regs = priv->regs;
1409 dma_addr_t dma_addr;
1410 unsigned int dma_size;
1411 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001412 unsigned long timeout = 0;
1413 u8 buf[32];
1414
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001415 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001416 dma_size = le16_to_cpu(cmd->length);
1417 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1418 PCI_DMA_BIDIRECTIONAL);
1419 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1420 return -ENOMEM;
1421
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001422 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001423 if (rc) {
1424 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1425 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001426 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001427 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001428
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001429 priv->hostcmd_wait = &cmd_wait;
1430 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1431 iowrite32(MWL8K_H2A_INT_DOORBELL,
1432 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1433 iowrite32(MWL8K_H2A_INT_DUMMY,
1434 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001435
1436 timeout = wait_for_completion_timeout(&cmd_wait,
1437 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1438
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001439 priv->hostcmd_wait = NULL;
1440
1441 mwl8k_fw_unlock(hw);
1442
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001443 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1444 PCI_DMA_BIDIRECTIONAL);
1445
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001446 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001447 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001448 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001449 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1450 MWL8K_CMD_TIMEOUT_MS);
1451 rc = -ETIMEDOUT;
1452 } else {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001453 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001454 if (rc)
1455 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001456 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001457 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001458 le16_to_cpu(cmd->result));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001459 }
1460
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001461 return rc;
1462}
1463
1464/*
1465 * GET_HW_SPEC.
1466 */
1467struct mwl8k_cmd_get_hw_spec {
1468 struct mwl8k_cmd_pkt header;
1469 __u8 hw_rev;
1470 __u8 host_interface;
1471 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001472 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001473 __le16 region_code;
1474 __le32 fw_rev;
1475 __le32 ps_cookie;
1476 __le32 caps;
1477 __u8 mcs_bitmap[16];
1478 __le32 rx_queue_ptr;
1479 __le32 num_tx_queues;
1480 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1481 __le32 caps2;
1482 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001483 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001484} __attribute__((packed));
1485
1486static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
1487{
1488 struct mwl8k_priv *priv = hw->priv;
1489 struct mwl8k_cmd_get_hw_spec *cmd;
1490 int rc;
1491 int i;
1492
1493 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1494 if (cmd == NULL)
1495 return -ENOMEM;
1496
1497 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1498 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1499
1500 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1501 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001502 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001503 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001504 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001505 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001506 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001507 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001508
1509 rc = mwl8k_post_cmd(hw, &cmd->header);
1510
1511 if (!rc) {
1512 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1513 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001514 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001515 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001516 }
1517
1518 kfree(cmd);
1519 return rc;
1520}
1521
1522/*
1523 * CMD_MAC_MULTICAST_ADR.
1524 */
1525struct mwl8k_cmd_mac_multicast_adr {
1526 struct mwl8k_cmd_pkt header;
1527 __le16 action;
1528 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001529 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001530};
1531
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001532#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1533#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1534#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1535#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001536
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001537static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001538__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001539 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001540{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001541 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001542 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001543 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001544
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001545 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001546 allmulti = 1;
1547 mc_count = 0;
1548 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001549
1550 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1551
1552 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001553 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001554 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001555
1556 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1557 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001558 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1559 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001560
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001561 if (allmulti) {
1562 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1563 } else if (mc_count) {
1564 int i;
1565
1566 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1567 cmd->numaddr = cpu_to_le16(mc_count);
1568 for (i = 0; i < mc_count && mclist; i++) {
1569 if (mclist->da_addrlen != ETH_ALEN) {
1570 kfree(cmd);
1571 return NULL;
1572 }
1573 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1574 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001575 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001576 }
1577
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001578 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001579}
1580
1581/*
1582 * CMD_802_11_GET_STAT.
1583 */
1584struct mwl8k_cmd_802_11_get_stat {
1585 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001586 __le32 stats[64];
1587} __attribute__((packed));
1588
1589#define MWL8K_STAT_ACK_FAILURE 9
1590#define MWL8K_STAT_RTS_FAILURE 12
1591#define MWL8K_STAT_FCS_ERROR 24
1592#define MWL8K_STAT_RTS_SUCCESS 11
1593
1594static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1595 struct ieee80211_low_level_stats *stats)
1596{
1597 struct mwl8k_cmd_802_11_get_stat *cmd;
1598 int rc;
1599
1600 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1601 if (cmd == NULL)
1602 return -ENOMEM;
1603
1604 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1605 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001606
1607 rc = mwl8k_post_cmd(hw, &cmd->header);
1608 if (!rc) {
1609 stats->dot11ACKFailureCount =
1610 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1611 stats->dot11RTSFailureCount =
1612 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1613 stats->dot11FCSErrorCount =
1614 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1615 stats->dot11RTSSuccessCount =
1616 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1617 }
1618 kfree(cmd);
1619
1620 return rc;
1621}
1622
1623/*
1624 * CMD_802_11_RADIO_CONTROL.
1625 */
1626struct mwl8k_cmd_802_11_radio_control {
1627 struct mwl8k_cmd_pkt header;
1628 __le16 action;
1629 __le16 control;
1630 __le16 radio_on;
1631} __attribute__((packed));
1632
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001633static int
1634mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001635{
1636 struct mwl8k_priv *priv = hw->priv;
1637 struct mwl8k_cmd_802_11_radio_control *cmd;
1638 int rc;
1639
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001640 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001641 return 0;
1642
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001643 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1644 if (cmd == NULL)
1645 return -ENOMEM;
1646
1647 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1648 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1649 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001650 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001651 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1652
1653 rc = mwl8k_post_cmd(hw, &cmd->header);
1654 kfree(cmd);
1655
1656 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001657 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001658
1659 return rc;
1660}
1661
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001662static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1663{
1664 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1665}
1666
1667static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1668{
1669 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1670}
1671
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001672static int
1673mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1674{
1675 struct mwl8k_priv *priv;
1676
1677 if (hw == NULL || hw->priv == NULL)
1678 return -EINVAL;
1679 priv = hw->priv;
1680
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001681 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001682
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001683 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001684}
1685
1686/*
1687 * CMD_802_11_RF_TX_POWER.
1688 */
1689#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1690
1691struct mwl8k_cmd_802_11_rf_tx_power {
1692 struct mwl8k_cmd_pkt header;
1693 __le16 action;
1694 __le16 support_level;
1695 __le16 current_level;
1696 __le16 reserved;
1697 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1698} __attribute__((packed));
1699
1700static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1701{
1702 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1703 int rc;
1704
1705 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1706 if (cmd == NULL)
1707 return -ENOMEM;
1708
1709 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1710 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1711 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1712 cmd->support_level = cpu_to_le16(dBm);
1713
1714 rc = mwl8k_post_cmd(hw, &cmd->header);
1715 kfree(cmd);
1716
1717 return rc;
1718}
1719
1720/*
1721 * CMD_SET_PRE_SCAN.
1722 */
1723struct mwl8k_cmd_set_pre_scan {
1724 struct mwl8k_cmd_pkt header;
1725} __attribute__((packed));
1726
1727static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
1728{
1729 struct mwl8k_cmd_set_pre_scan *cmd;
1730 int rc;
1731
1732 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1733 if (cmd == NULL)
1734 return -ENOMEM;
1735
1736 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
1737 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1738
1739 rc = mwl8k_post_cmd(hw, &cmd->header);
1740 kfree(cmd);
1741
1742 return rc;
1743}
1744
1745/*
1746 * CMD_SET_POST_SCAN.
1747 */
1748struct mwl8k_cmd_set_post_scan {
1749 struct mwl8k_cmd_pkt header;
1750 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001751 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001752} __attribute__((packed));
1753
1754static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001755mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001756{
1757 struct mwl8k_cmd_set_post_scan *cmd;
1758 int rc;
1759
1760 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1761 if (cmd == NULL)
1762 return -ENOMEM;
1763
1764 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
1765 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1766 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001767 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001768
1769 rc = mwl8k_post_cmd(hw, &cmd->header);
1770 kfree(cmd);
1771
1772 return rc;
1773}
1774
1775/*
1776 * CMD_SET_RF_CHANNEL.
1777 */
1778struct mwl8k_cmd_set_rf_channel {
1779 struct mwl8k_cmd_pkt header;
1780 __le16 action;
1781 __u8 current_channel;
1782 __le32 channel_flags;
1783} __attribute__((packed));
1784
1785static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
1786 struct ieee80211_channel *channel)
1787{
1788 struct mwl8k_cmd_set_rf_channel *cmd;
1789 int rc;
1790
1791 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1792 if (cmd == NULL)
1793 return -ENOMEM;
1794
1795 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
1796 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1797 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1798 cmd->current_channel = channel->hw_value;
1799 if (channel->band == IEEE80211_BAND_2GHZ)
1800 cmd->channel_flags = cpu_to_le32(0x00000081);
1801 else
1802 cmd->channel_flags = cpu_to_le32(0x00000000);
1803
1804 rc = mwl8k_post_cmd(hw, &cmd->header);
1805 kfree(cmd);
1806
1807 return rc;
1808}
1809
1810/*
1811 * CMD_SET_SLOT.
1812 */
1813struct mwl8k_cmd_set_slot {
1814 struct mwl8k_cmd_pkt header;
1815 __le16 action;
1816 __u8 short_slot;
1817} __attribute__((packed));
1818
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02001819static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001820{
1821 struct mwl8k_cmd_set_slot *cmd;
1822 int rc;
1823
1824 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1825 if (cmd == NULL)
1826 return -ENOMEM;
1827
1828 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
1829 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1830 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02001831 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001832
1833 rc = mwl8k_post_cmd(hw, &cmd->header);
1834 kfree(cmd);
1835
1836 return rc;
1837}
1838
1839/*
1840 * CMD_MIMO_CONFIG.
1841 */
1842struct mwl8k_cmd_mimo_config {
1843 struct mwl8k_cmd_pkt header;
1844 __le32 action;
1845 __u8 rx_antenna_map;
1846 __u8 tx_antenna_map;
1847} __attribute__((packed));
1848
1849static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
1850{
1851 struct mwl8k_cmd_mimo_config *cmd;
1852 int rc;
1853
1854 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1855 if (cmd == NULL)
1856 return -ENOMEM;
1857
1858 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
1859 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1860 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
1861 cmd->rx_antenna_map = rx;
1862 cmd->tx_antenna_map = tx;
1863
1864 rc = mwl8k_post_cmd(hw, &cmd->header);
1865 kfree(cmd);
1866
1867 return rc;
1868}
1869
1870/*
1871 * CMD_ENABLE_SNIFFER.
1872 */
1873struct mwl8k_cmd_enable_sniffer {
1874 struct mwl8k_cmd_pkt header;
1875 __le32 action;
1876} __attribute__((packed));
1877
1878static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
1879{
1880 struct mwl8k_cmd_enable_sniffer *cmd;
1881 int rc;
1882
1883 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1884 if (cmd == NULL)
1885 return -ENOMEM;
1886
1887 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
1888 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001889 cmd->action = cpu_to_le32(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001890
1891 rc = mwl8k_post_cmd(hw, &cmd->header);
1892 kfree(cmd);
1893
1894 return rc;
1895}
1896
1897/*
Lennert Buytenhek32060e12009-10-22 20:20:04 +02001898 * CMD_SET_MAC_ADDR.
1899 */
1900struct mwl8k_cmd_set_mac_addr {
1901 struct mwl8k_cmd_pkt header;
1902 __u8 mac_addr[ETH_ALEN];
1903} __attribute__((packed));
1904
1905static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
1906{
1907 struct mwl8k_cmd_set_mac_addr *cmd;
1908 int rc;
1909
1910 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1911 if (cmd == NULL)
1912 return -ENOMEM;
1913
1914 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
1915 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1916 memcpy(cmd->mac_addr, mac, ETH_ALEN);
1917
1918 rc = mwl8k_post_cmd(hw, &cmd->header);
1919 kfree(cmd);
1920
1921 return rc;
1922}
1923
1924
1925/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001926 * CMD_SET_RATEADAPT_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001927 */
1928struct mwl8k_cmd_set_rate_adapt_mode {
1929 struct mwl8k_cmd_pkt header;
1930 __le16 action;
1931 __le16 mode;
1932} __attribute__((packed));
1933
1934static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
1935{
1936 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
1937 int rc;
1938
1939 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1940 if (cmd == NULL)
1941 return -ENOMEM;
1942
1943 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
1944 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1945 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1946 cmd->mode = cpu_to_le16(mode);
1947
1948 rc = mwl8k_post_cmd(hw, &cmd->header);
1949 kfree(cmd);
1950
1951 return rc;
1952}
1953
1954/*
1955 * CMD_SET_WMM_MODE.
1956 */
1957struct mwl8k_cmd_set_wmm {
1958 struct mwl8k_cmd_pkt header;
1959 __le16 action;
1960} __attribute__((packed));
1961
1962static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
1963{
1964 struct mwl8k_priv *priv = hw->priv;
1965 struct mwl8k_cmd_set_wmm *cmd;
1966 int rc;
1967
1968 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1969 if (cmd == NULL)
1970 return -ENOMEM;
1971
1972 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
1973 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02001974 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001975
1976 rc = mwl8k_post_cmd(hw, &cmd->header);
1977 kfree(cmd);
1978
1979 if (!rc)
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02001980 priv->wmm_enabled = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001981
1982 return rc;
1983}
1984
1985/*
1986 * CMD_SET_RTS_THRESHOLD.
1987 */
1988struct mwl8k_cmd_rts_threshold {
1989 struct mwl8k_cmd_pkt header;
1990 __le16 action;
1991 __le16 threshold;
1992} __attribute__((packed));
1993
1994static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
Lennert Buytenhek733d3062009-07-17 07:24:15 +02001995 u16 action, u16 threshold)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001996{
1997 struct mwl8k_cmd_rts_threshold *cmd;
1998 int rc;
1999
2000 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2001 if (cmd == NULL)
2002 return -ENOMEM;
2003
2004 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2005 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2006 cmd->action = cpu_to_le16(action);
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002007 cmd->threshold = cpu_to_le16(threshold);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002008
2009 rc = mwl8k_post_cmd(hw, &cmd->header);
2010 kfree(cmd);
2011
2012 return rc;
2013}
2014
2015/*
2016 * CMD_SET_EDCA_PARAMS.
2017 */
2018struct mwl8k_cmd_set_edca_params {
2019 struct mwl8k_cmd_pkt header;
2020
2021 /* See MWL8K_SET_EDCA_XXX below */
2022 __le16 action;
2023
2024 /* TX opportunity in units of 32 us */
2025 __le16 txop;
2026
2027 /* Log exponent of max contention period: 0...15*/
2028 __u8 log_cw_max;
2029
2030 /* Log exponent of min contention period: 0...15 */
2031 __u8 log_cw_min;
2032
2033 /* Adaptive interframe spacing in units of 32us */
2034 __u8 aifs;
2035
2036 /* TX queue to configure */
2037 __u8 txq;
2038} __attribute__((packed));
2039
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002040#define MWL8K_SET_EDCA_CW 0x01
2041#define MWL8K_SET_EDCA_TXOP 0x02
2042#define MWL8K_SET_EDCA_AIFS 0x04
2043
2044#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2045 MWL8K_SET_EDCA_TXOP | \
2046 MWL8K_SET_EDCA_AIFS)
2047
2048static int
2049mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2050 __u16 cw_min, __u16 cw_max,
2051 __u8 aifs, __u16 txop)
2052{
2053 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002054 int rc;
2055
2056 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2057 if (cmd == NULL)
2058 return -ENOMEM;
2059
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002060 /*
2061 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2062 * this call.
2063 */
2064 qnum ^= !(qnum >> 1);
2065
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002066 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2067 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002068 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2069 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002070 cmd->log_cw_max = (u8)ilog2(cw_max + 1);
2071 cmd->log_cw_min = (u8)ilog2(cw_min + 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002072 cmd->aifs = aifs;
2073 cmd->txq = qnum;
2074
2075 rc = mwl8k_post_cmd(hw, &cmd->header);
2076 kfree(cmd);
2077
2078 return rc;
2079}
2080
2081/*
2082 * CMD_FINALIZE_JOIN.
2083 */
2084
2085/* FJ beacon buffer size is compiled into the firmware. */
2086#define MWL8K_FJ_BEACON_MAXLEN 128
2087
2088struct mwl8k_cmd_finalize_join {
2089 struct mwl8k_cmd_pkt header;
2090 __le32 sleep_interval; /* Number of beacon periods to sleep */
2091 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2092} __attribute__((packed));
2093
2094static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2095 __u16 framelen, __u16 dtim)
2096{
2097 struct mwl8k_cmd_finalize_join *cmd;
2098 struct ieee80211_mgmt *payload = frame;
2099 u16 hdrlen;
2100 u32 payload_len;
2101 int rc;
2102
2103 if (frame == NULL)
2104 return -EINVAL;
2105
2106 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2107 if (cmd == NULL)
2108 return -ENOMEM;
2109
2110 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2111 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002112 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002113
2114 hdrlen = ieee80211_hdrlen(payload->frame_control);
2115
2116 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2117
2118 /* XXX TBD Might just have to abort and return an error */
2119 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2120 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002121 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2122 payload_len, MWL8K_FJ_BEACON_MAXLEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002123
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002124 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2125 payload_len = MWL8K_FJ_BEACON_MAXLEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002126
2127 if (payload && payload_len)
2128 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2129
2130 rc = mwl8k_post_cmd(hw, &cmd->header);
2131 kfree(cmd);
2132 return rc;
2133}
2134
2135/*
2136 * CMD_UPDATE_STADB.
2137 */
2138struct mwl8k_cmd_update_sta_db {
2139 struct mwl8k_cmd_pkt header;
2140
2141 /* See STADB_ACTION_TYPE */
2142 __le32 action;
2143
2144 /* Peer MAC address */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002145 __u8 peer_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002146
2147 __le32 reserved;
2148
2149 /* Peer info - valid during add/update. */
2150 struct peer_capability_info peer_info;
2151} __attribute__((packed));
2152
2153static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2154 struct ieee80211_vif *vif, __u32 action)
2155{
2156 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2157 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2158 struct mwl8k_cmd_update_sta_db *cmd;
2159 struct peer_capability_info *peer_info;
2160 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002161 int rc;
2162 __u8 count, *rates;
2163
2164 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2165 if (cmd == NULL)
2166 return -ENOMEM;
2167
2168 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2169 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2170
2171 cmd->action = cpu_to_le32(action);
2172 peer_info = &cmd->peer_info;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002173 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002174
2175 switch (action) {
2176 case MWL8K_STA_DB_ADD_ENTRY:
2177 case MWL8K_STA_DB_MODIFY_ENTRY:
2178 /* Build peer_info block */
2179 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2180 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2181 peer_info->interop = 1;
2182 peer_info->amsdu_enabled = 0;
2183
2184 rates = peer_info->legacy_rates;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002185 for (count = 0; count < mv_vif->legacy_nrates; count++)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002186 rates[count] = bitrates[count].hw_value;
2187
2188 rc = mwl8k_post_cmd(hw, &cmd->header);
2189 if (rc == 0)
2190 mv_vif->peer_id = peer_info->station_id;
2191
2192 break;
2193
2194 case MWL8K_STA_DB_DEL_ENTRY:
2195 case MWL8K_STA_DB_FLUSH:
2196 default:
2197 rc = mwl8k_post_cmd(hw, &cmd->header);
2198 if (rc == 0)
2199 mv_vif->peer_id = 0;
2200 break;
2201 }
2202 kfree(cmd);
2203
2204 return rc;
2205}
2206
2207/*
2208 * CMD_SET_AID.
2209 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002210#define MWL8K_RATE_INDEX_MAX_ARRAY 14
2211
2212#define MWL8K_FRAME_PROT_DISABLED 0x00
2213#define MWL8K_FRAME_PROT_11G 0x07
2214#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2215#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002216
2217struct mwl8k_cmd_update_set_aid {
2218 struct mwl8k_cmd_pkt header;
2219 __le16 aid;
2220
2221 /* AP's MAC address (BSSID) */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002222 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002223 __le16 protection_mode;
2224 __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2225} __attribute__((packed));
2226
2227static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2228 struct ieee80211_vif *vif)
2229{
2230 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2231 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2232 struct mwl8k_cmd_update_set_aid *cmd;
2233 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2234 int count;
2235 u16 prot_mode;
2236 int rc;
2237
2238 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2239 if (cmd == NULL)
2240 return -ENOMEM;
2241
2242 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2243 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2244 cmd->aid = cpu_to_le16(info->aid);
2245
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002246 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002247
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002248 if (info->use_cts_prot) {
2249 prot_mode = MWL8K_FRAME_PROT_11G;
2250 } else {
Johannes Berg9ed6bcc2009-05-08 20:47:39 +02002251 switch (info->ht_operation_mode &
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002252 IEEE80211_HT_OP_MODE_PROTECTION) {
2253 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2254 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2255 break;
2256 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2257 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2258 break;
2259 default:
2260 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2261 break;
2262 }
2263 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002264 cmd->protection_mode = cpu_to_le16(prot_mode);
2265
2266 for (count = 0; count < mv_vif->legacy_nrates; count++)
2267 cmd->supp_rates[count] = bitrates[count].hw_value;
2268
2269 rc = mwl8k_post_cmd(hw, &cmd->header);
2270 kfree(cmd);
2271
2272 return rc;
2273}
2274
2275/*
2276 * CMD_SET_RATE.
2277 */
2278struct mwl8k_cmd_update_rateset {
2279 struct mwl8k_cmd_pkt header;
2280 __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2281
2282 /* Bitmap for supported MCS codes. */
2283 __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
2284 __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
2285} __attribute__((packed));
2286
2287static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2288 struct ieee80211_vif *vif)
2289{
2290 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2291 struct mwl8k_cmd_update_rateset *cmd;
2292 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2293 int count;
2294 int rc;
2295
2296 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2297 if (cmd == NULL)
2298 return -ENOMEM;
2299
2300 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2301 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2302
2303 for (count = 0; count < mv_vif->legacy_nrates; count++)
2304 cmd->legacy_rates[count] = bitrates[count].hw_value;
2305
2306 rc = mwl8k_post_cmd(hw, &cmd->header);
2307 kfree(cmd);
2308
2309 return rc;
2310}
2311
2312/*
2313 * CMD_USE_FIXED_RATE.
2314 */
2315#define MWL8K_RATE_TABLE_SIZE 8
2316#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002317#define MWL8K_USE_AUTO_RATE 0x0002
2318
2319struct mwl8k_rate_entry {
2320 /* Set to 1 if HT rate, 0 if legacy. */
2321 __le32 is_ht_rate;
2322
2323 /* Set to 1 to use retry_count field. */
2324 __le32 enable_retry;
2325
2326 /* Specified legacy rate or MCS. */
2327 __le32 rate;
2328
2329 /* Number of allowed retries. */
2330 __le32 retry_count;
2331} __attribute__((packed));
2332
2333struct mwl8k_rate_table {
2334 /* 1 to allow specified rate and below */
2335 __le32 allow_rate_drop;
2336 __le32 num_rates;
2337 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2338} __attribute__((packed));
2339
2340struct mwl8k_cmd_use_fixed_rate {
2341 struct mwl8k_cmd_pkt header;
2342 __le32 action;
2343 struct mwl8k_rate_table rate_table;
2344
2345 /* Unicast, Broadcast or Multicast */
2346 __le32 rate_type;
2347 __le32 reserved1;
2348 __le32 reserved2;
2349} __attribute__((packed));
2350
2351static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2352 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2353{
2354 struct mwl8k_cmd_use_fixed_rate *cmd;
2355 int count;
2356 int rc;
2357
2358 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2359 if (cmd == NULL)
2360 return -ENOMEM;
2361
2362 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2363 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2364
2365 cmd->action = cpu_to_le32(action);
2366 cmd->rate_type = cpu_to_le32(rate_type);
2367
2368 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002369 /*
2370 * Copy over each field manually so that endian
2371 * conversion can be done.
2372 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002373 cmd->rate_table.allow_rate_drop =
2374 cpu_to_le32(rate_table->allow_rate_drop);
2375 cmd->rate_table.num_rates =
2376 cpu_to_le32(rate_table->num_rates);
2377
2378 for (count = 0; count < rate_table->num_rates; count++) {
2379 struct mwl8k_rate_entry *dst =
2380 &cmd->rate_table.rate_entry[count];
2381 struct mwl8k_rate_entry *src =
2382 &rate_table->rate_entry[count];
2383
2384 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2385 dst->enable_retry = cpu_to_le32(src->enable_retry);
2386 dst->rate = cpu_to_le32(src->rate);
2387 dst->retry_count = cpu_to_le32(src->retry_count);
2388 }
2389 }
2390
2391 rc = mwl8k_post_cmd(hw, &cmd->header);
2392 kfree(cmd);
2393
2394 return rc;
2395}
2396
2397
2398/*
2399 * Interrupt handling.
2400 */
2401static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2402{
2403 struct ieee80211_hw *hw = dev_id;
2404 struct mwl8k_priv *priv = hw->priv;
2405 u32 status;
2406
2407 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2408 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2409
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002410 if (!status)
2411 return IRQ_NONE;
2412
2413 if (status & MWL8K_A2H_INT_TX_DONE)
2414 tasklet_schedule(&priv->tx_reclaim_task);
2415
2416 if (status & MWL8K_A2H_INT_RX_READY) {
2417 while (rxq_process(hw, 0, 1))
2418 rxq_refill(hw, 0, 1);
2419 }
2420
2421 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002422 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002423 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002424 }
2425
2426 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002427 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002428 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002429 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002430 }
2431
2432 return IRQ_HANDLED;
2433}
2434
2435
2436/*
2437 * Core driver operations.
2438 */
2439static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2440{
2441 struct mwl8k_priv *priv = hw->priv;
2442 int index = skb_get_queue_mapping(skb);
2443 int rc;
2444
2445 if (priv->current_channel == NULL) {
2446 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002447 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002448 dev_kfree_skb(skb);
2449 return NETDEV_TX_OK;
2450 }
2451
2452 rc = mwl8k_txq_xmit(hw, index, skb);
2453
2454 return rc;
2455}
2456
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002457static int mwl8k_start(struct ieee80211_hw *hw)
2458{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002459 struct mwl8k_priv *priv = hw->priv;
2460 int rc;
2461
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002462 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
2463 IRQF_SHARED, MWL8K_NAME, hw);
2464 if (rc) {
2465 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002466 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002467 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002468 }
2469
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002470 /* Enable tx reclaim tasklet */
2471 tasklet_enable(&priv->tx_reclaim_task);
2472
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002473 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002474 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002475
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002476 rc = mwl8k_fw_lock(hw);
2477 if (!rc) {
2478 rc = mwl8k_cmd_802_11_radio_enable(hw);
2479
2480 if (!rc)
2481 rc = mwl8k_cmd_set_pre_scan(hw);
2482
2483 if (!rc)
2484 rc = mwl8k_cmd_set_post_scan(hw,
2485 "\x00\x00\x00\x00\x00\x00");
2486
2487 if (!rc)
2488 rc = mwl8k_cmd_setrateadaptmode(hw, 0);
2489
2490 if (!rc)
2491 rc = mwl8k_set_wmm(hw, 0);
2492
2493 if (!rc)
2494 rc = mwl8k_enable_sniffer(hw, 0);
2495
2496 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002497 }
2498
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002499 if (rc) {
2500 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2501 free_irq(priv->pdev->irq, hw);
2502 tasklet_disable(&priv->tx_reclaim_task);
2503 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002504
2505 return rc;
2506}
2507
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002508static void mwl8k_stop(struct ieee80211_hw *hw)
2509{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002510 struct mwl8k_priv *priv = hw->priv;
2511 int i;
2512
Lennert Buytenhekd3cea0b2009-07-17 07:15:49 +02002513 mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002514
2515 ieee80211_stop_queues(hw);
2516
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002517 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002518 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002519 free_irq(priv->pdev->irq, hw);
2520
2521 /* Stop finalize join worker */
2522 cancel_work_sync(&priv->finalize_join_worker);
2523 if (priv->beacon_skb != NULL)
2524 dev_kfree_skb(priv->beacon_skb);
2525
2526 /* Stop tx reclaim tasklet */
2527 tasklet_disable(&priv->tx_reclaim_task);
2528
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002529 /* Return all skbs to mac80211 */
2530 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2531 mwl8k_txq_reclaim(hw, i, 1);
2532}
2533
2534static int mwl8k_add_interface(struct ieee80211_hw *hw,
2535 struct ieee80211_if_init_conf *conf)
2536{
2537 struct mwl8k_priv *priv = hw->priv;
2538 struct mwl8k_vif *mwl8k_vif;
2539
2540 /*
2541 * We only support one active interface at a time.
2542 */
2543 if (priv->vif != NULL)
2544 return -EBUSY;
2545
2546 /*
2547 * We only support managed interfaces for now.
2548 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002549 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002550 return -EINVAL;
2551
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002552 /*
2553 * Reject interface creation if sniffer mode is active, as
2554 * STA operation is mutually exclusive with hardware sniffer
2555 * mode.
2556 */
2557 if (priv->sniffer_enabled) {
2558 printk(KERN_INFO "%s: unable to create STA "
2559 "interface due to sniffer mode being enabled\n",
2560 wiphy_name(hw->wiphy));
2561 return -EINVAL;
2562 }
2563
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002564 /* Clean out driver private area */
2565 mwl8k_vif = MWL8K_VIF(conf->vif);
2566 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2567
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002568 /* Set and save the mac address */
2569 mwl8k_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002570 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002571
2572 /* Back pointer to parent config block */
2573 mwl8k_vif->priv = priv;
2574
2575 /* Setup initial PHY parameters */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002576 memcpy(mwl8k_vif->legacy_rates,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002577 priv->rates, sizeof(mwl8k_vif->legacy_rates));
2578 mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
2579
2580 /* Set Initial sequence number to zero */
2581 mwl8k_vif->seqno = 0;
2582
2583 priv->vif = conf->vif;
2584 priv->current_channel = NULL;
2585
2586 return 0;
2587}
2588
2589static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2590 struct ieee80211_if_init_conf *conf)
2591{
2592 struct mwl8k_priv *priv = hw->priv;
2593
2594 if (priv->vif == NULL)
2595 return;
2596
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002597 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
2598
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002599 priv->vif = NULL;
2600}
2601
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002602static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002603{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002604 struct ieee80211_conf *conf = &hw->conf;
2605 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002606 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002607
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002608 if (conf->flags & IEEE80211_CONF_IDLE) {
2609 mwl8k_cmd_802_11_radio_disable(hw);
2610 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002611 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002612 }
2613
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002614 rc = mwl8k_fw_lock(hw);
2615 if (rc)
2616 return rc;
2617
2618 rc = mwl8k_cmd_802_11_radio_enable(hw);
2619 if (rc)
2620 goto out;
2621
2622 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2623 if (rc)
2624 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002625
2626 priv->current_channel = conf->channel;
2627
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002628 if (conf->power_level > 18)
2629 conf->power_level = 18;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002630 rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level);
2631 if (rc)
2632 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002633
2634 if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
2635 rc = -EINVAL;
2636
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002637out:
2638 mwl8k_fw_unlock(hw);
2639
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002640 return rc;
2641}
2642
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002643static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
2644 struct ieee80211_vif *vif,
2645 struct ieee80211_bss_conf *info,
2646 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002647{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002648 struct mwl8k_priv *priv = hw->priv;
2649 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002650 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002651
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002652 if (changed & BSS_CHANGED_BSSID)
2653 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
2654
2655 if ((changed & BSS_CHANGED_ASSOC) == 0)
2656 return;
2657
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002658 priv->capture_beacon = false;
2659
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002660 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02002661 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002662 return;
2663
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002664 if (info->assoc) {
2665 memcpy(&mwl8k_vif->bss_info, info,
2666 sizeof(struct ieee80211_bss_conf));
2667
2668 /* Install rates */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002669 rc = mwl8k_update_rateset(hw, vif);
2670 if (rc)
2671 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002672
2673 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002674 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
2675 MWL8K_UCAST_RATE, NULL);
2676 if (rc)
2677 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002678
2679 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002680 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
2681 if (rc)
2682 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002683
2684 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002685 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
2686 if (rc)
2687 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002688
2689 /* Update peer rate info */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002690 rc = mwl8k_cmd_update_sta_db(hw, vif,
2691 MWL8K_STA_DB_MODIFY_ENTRY);
2692 if (rc)
2693 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002694
2695 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002696 rc = mwl8k_cmd_set_aid(hw, vif);
2697 if (rc)
2698 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002699
2700 /*
2701 * Finalize the join. Tell rx handler to process
2702 * next beacon from our BSSID.
2703 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002704 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002705 priv->capture_beacon = true;
2706 } else {
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002707 rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002708 memset(&mwl8k_vif->bss_info, 0,
2709 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002710 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002711 }
2712
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002713out:
2714 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002715}
2716
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002717static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
2718 int mc_count, struct dev_addr_list *mclist)
2719{
2720 struct mwl8k_cmd_pkt *cmd;
2721
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002722 /*
2723 * Synthesize and return a command packet that programs the
2724 * hardware multicast address filter. At this point we don't
2725 * know whether FIF_ALLMULTI is being requested, but if it is,
2726 * we'll end up throwing this packet away and creating a new
2727 * one in mwl8k_configure_filter().
2728 */
2729 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02002730
2731 return (unsigned long)cmd;
2732}
2733
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002734static int
2735mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
2736 unsigned int changed_flags,
2737 unsigned int *total_flags)
2738{
2739 struct mwl8k_priv *priv = hw->priv;
2740
2741 /*
2742 * Hardware sniffer mode is mutually exclusive with STA
2743 * operation, so refuse to enable sniffer mode if a STA
2744 * interface is active.
2745 */
2746 if (priv->vif != NULL) {
2747 if (net_ratelimit())
2748 printk(KERN_INFO "%s: not enabling sniffer "
2749 "mode because STA interface is active\n",
2750 wiphy_name(hw->wiphy));
2751 return 0;
2752 }
2753
2754 if (!priv->sniffer_enabled) {
2755 if (mwl8k_enable_sniffer(hw, 1))
2756 return 0;
2757 priv->sniffer_enabled = true;
2758 }
2759
2760 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
2761 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
2762 FIF_OTHER_BSS;
2763
2764 return 1;
2765}
2766
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002767static void mwl8k_configure_filter(struct ieee80211_hw *hw,
2768 unsigned int changed_flags,
2769 unsigned int *total_flags,
2770 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002771{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002772 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002773 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
2774
2775 /*
2776 * Enable hardware sniffer mode if FIF_CONTROL or
2777 * FIF_OTHER_BSS is requested.
2778 */
2779 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
2780 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
2781 kfree(cmd);
2782 return;
2783 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002784
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002785 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002786 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002787
2788 if (mwl8k_fw_lock(hw))
2789 return;
2790
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002791 if (priv->sniffer_enabled) {
2792 mwl8k_enable_sniffer(hw, 0);
2793 priv->sniffer_enabled = false;
2794 }
2795
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002796 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02002797 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
2798 /*
2799 * Disable the BSS filter.
2800 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002801 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02002802 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02002803 u8 *bssid;
2804
Lennert Buytenhek77165d82009-10-22 20:19:53 +02002805 /*
2806 * Enable the BSS filter.
2807 *
2808 * If there is an active STA interface, use that
2809 * interface's BSSID, otherwise use a dummy one
2810 * (where the OUI part needs to be nonzero for
2811 * the BSSID to be accepted by POST_SCAN).
2812 */
2813 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02002814 if (priv->vif != NULL)
2815 bssid = MWL8K_VIF(priv->vif)->bssid;
2816
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002817 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002818 }
2819 }
2820
Lennert Buytenhek447ced02009-10-22 20:19:50 +02002821 /*
2822 * If FIF_ALLMULTI is being requested, throw away the command
2823 * packet that ->prepare_multicast() built and replace it with
2824 * a command packet that enables reception of all multicast
2825 * packets.
2826 */
2827 if (*total_flags & FIF_ALLMULTI) {
2828 kfree(cmd);
2829 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
2830 }
2831
2832 if (cmd != NULL) {
2833 mwl8k_post_cmd(hw, cmd);
2834 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002835 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002836
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02002837 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002838}
2839
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002840static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2841{
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002842 return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002843}
2844
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002845static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
2846 const struct ieee80211_tx_queue_params *params)
2847{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02002848 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002849 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002850
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02002851 rc = mwl8k_fw_lock(hw);
2852 if (!rc) {
2853 if (!priv->wmm_enabled)
2854 rc = mwl8k_set_wmm(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002855
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02002856 if (!rc)
2857 rc = mwl8k_set_edca_params(hw, queue,
2858 params->cw_min,
2859 params->cw_max,
2860 params->aifs,
2861 params->txop);
2862
2863 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002864 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02002865
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002866 return rc;
2867}
2868
2869static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
2870 struct ieee80211_tx_queue_stats *stats)
2871{
2872 struct mwl8k_priv *priv = hw->priv;
2873 struct mwl8k_tx_queue *txq;
2874 int index;
2875
2876 spin_lock_bh(&priv->tx_lock);
2877 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
2878 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02002879 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002880 sizeof(struct ieee80211_tx_queue_stats));
2881 }
2882 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02002883
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002884 return 0;
2885}
2886
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002887static int mwl8k_get_stats(struct ieee80211_hw *hw,
2888 struct ieee80211_low_level_stats *stats)
2889{
Lennert Buytenhek954ef502009-07-17 07:26:27 +02002890 return mwl8k_cmd_802_11_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002891}
2892
2893static const struct ieee80211_ops mwl8k_ops = {
2894 .tx = mwl8k_tx,
2895 .start = mwl8k_start,
2896 .stop = mwl8k_stop,
2897 .add_interface = mwl8k_add_interface,
2898 .remove_interface = mwl8k_remove_interface,
2899 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002900 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02002901 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002902 .configure_filter = mwl8k_configure_filter,
2903 .set_rts_threshold = mwl8k_set_rts_threshold,
2904 .conf_tx = mwl8k_conf_tx,
2905 .get_tx_stats = mwl8k_get_tx_stats,
2906 .get_stats = mwl8k_get_stats,
2907};
2908
2909static void mwl8k_tx_reclaim_handler(unsigned long data)
2910{
2911 int i;
2912 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
2913 struct mwl8k_priv *priv = hw->priv;
2914
2915 spin_lock_bh(&priv->tx_lock);
2916 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2917 mwl8k_txq_reclaim(hw, i, 0);
2918
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002919 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002920 complete(priv->tx_wait);
2921 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002922 }
2923 spin_unlock_bh(&priv->tx_lock);
2924}
2925
2926static void mwl8k_finalize_join_worker(struct work_struct *work)
2927{
2928 struct mwl8k_priv *priv =
2929 container_of(work, struct mwl8k_priv, finalize_join_worker);
2930 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002931 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002932
2933 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
2934 dev_kfree_skb(skb);
2935
2936 priv->beacon_skb = NULL;
2937}
2938
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02002939static struct mwl8k_device_info di_8687 = {
Lennert Buytenheka74b2952009-10-22 20:20:50 +02002940 .part_name = "88w8687",
2941 .helper_image = "mwl8k/helper_8687.fw",
2942 .fw_image = "mwl8k/fmimage_8687.fw",
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02002943};
2944
2945static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
2946 {
2947 PCI_VDEVICE(MARVELL, 0x2a2b),
2948 .driver_data = (unsigned long)&di_8687,
2949 }, {
2950 PCI_VDEVICE(MARVELL, 0x2a30),
2951 .driver_data = (unsigned long)&di_8687,
2952 }, {
2953 },
2954};
2955MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
2956
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002957static int __devinit mwl8k_probe(struct pci_dev *pdev,
2958 const struct pci_device_id *id)
2959{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02002960 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002961 struct ieee80211_hw *hw;
2962 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002963 int rc;
2964 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02002965
2966 if (!printed_version) {
2967 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
2968 printed_version = 1;
2969 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002970
2971 rc = pci_enable_device(pdev);
2972 if (rc) {
2973 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
2974 MWL8K_NAME);
2975 return rc;
2976 }
2977
2978 rc = pci_request_regions(pdev, MWL8K_NAME);
2979 if (rc) {
2980 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
2981 MWL8K_NAME);
2982 return rc;
2983 }
2984
2985 pci_set_master(pdev);
2986
2987 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
2988 if (hw == NULL) {
2989 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
2990 rc = -ENOMEM;
2991 goto err_free_reg;
2992 }
2993
2994 priv = hw->priv;
2995 priv->hw = hw;
2996 priv->pdev = pdev;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02002997 priv->device_info = (void *)id->driver_data;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002998 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002999 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003000 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003001
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003002 SET_IEEE80211_DEV(hw, &pdev->dev);
3003 pci_set_drvdata(pdev, hw);
3004
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003005 priv->sram = pci_iomap(pdev, 0, 0x10000);
3006 if (priv->sram == NULL) {
3007 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003008 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003009 goto err_iounmap;
3010 }
3011
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003012 /*
3013 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3014 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3015 */
3016 priv->regs = pci_iomap(pdev, 1, 0x10000);
3017 if (priv->regs == NULL) {
3018 priv->regs = pci_iomap(pdev, 2, 0x10000);
3019 if (priv->regs == NULL) {
3020 printk(KERN_ERR "%s: Cannot map device registers\n",
3021 wiphy_name(hw->wiphy));
3022 goto err_iounmap;
3023 }
3024 }
3025
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003026 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3027 priv->band.band = IEEE80211_BAND_2GHZ;
3028 priv->band.channels = priv->channels;
3029 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3030 priv->band.bitrates = priv->rates;
3031 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3032 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3033
3034 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3035 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3036
3037 /*
3038 * Extra headroom is the size of the required DMA header
3039 * minus the size of the smallest 802.11 frame (CTS frame).
3040 */
3041 hw->extra_tx_headroom =
3042 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3043
3044 hw->channel_change_time = 10;
3045
3046 hw->queues = MWL8K_TX_QUEUES;
3047
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02003048 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003049
3050 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003051 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003052 hw->vif_data_size = sizeof(struct mwl8k_vif);
3053 priv->vif = NULL;
3054
3055 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003056 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003057 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003058
3059 /* Finalize join worker */
3060 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3061
3062 /* TX reclaim tasklet */
3063 tasklet_init(&priv->tx_reclaim_task,
3064 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3065 tasklet_disable(&priv->tx_reclaim_task);
3066
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003067 /* Power management cookie */
3068 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3069 if (priv->cookie == NULL)
3070 goto err_iounmap;
3071
3072 rc = mwl8k_rxq_init(hw, 0);
3073 if (rc)
3074 goto err_iounmap;
3075 rxq_refill(hw, 0, INT_MAX);
3076
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003077 mutex_init(&priv->fw_mutex);
3078 priv->fw_mutex_owner = NULL;
3079 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003080 priv->hostcmd_wait = NULL;
3081
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003082 spin_lock_init(&priv->tx_lock);
3083
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003084 priv->tx_wait = NULL;
3085
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003086 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3087 rc = mwl8k_txq_init(hw, i);
3088 if (rc)
3089 goto err_free_queues;
3090 }
3091
3092 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003093 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003094 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3095 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3096
3097 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
3098 IRQF_SHARED, MWL8K_NAME, hw);
3099 if (rc) {
3100 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003101 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003102 goto err_free_queues;
3103 }
3104
3105 /* Reset firmware and hardware */
3106 mwl8k_hw_reset(priv);
3107
3108 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003109 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003110 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003111 printk(KERN_ERR "%s: Firmware files not found\n",
3112 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003113 goto err_free_irq;
3114 }
3115
3116 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003117 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003118 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003119 printk(KERN_ERR "%s: Cannot start firmware\n",
3120 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003121 goto err_stop_firmware;
3122 }
3123
3124 /* Reclaim memory once firmware is successfully loaded */
3125 mwl8k_release_firmware(priv);
3126
3127 /*
3128 * Temporarily enable interrupts. Initial firmware host
3129 * commands use interrupts and avoids polling. Disable
3130 * interrupts when done.
3131 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003132 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003133
3134 /* Get config data, mac addrs etc */
3135 rc = mwl8k_cmd_get_hw_spec(hw);
3136 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003137 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3138 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003139 goto err_stop_firmware;
3140 }
3141
3142 /* Turn radio off */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003143 rc = mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003144 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003145 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003146 goto err_stop_firmware;
3147 }
3148
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003149 /* Clear MAC address */
3150 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3151 if (rc) {
3152 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3153 wiphy_name(hw->wiphy));
3154 goto err_stop_firmware;
3155 }
3156
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003157 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003158 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003159 free_irq(priv->pdev->irq, hw);
3160
3161 rc = ieee80211_register_hw(hw);
3162 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003163 printk(KERN_ERR "%s: Cannot register device\n",
3164 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003165 goto err_stop_firmware;
3166 }
3167
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003168 printk(KERN_INFO "%s: %s v%d, %pM, firmware version %u.%u.%u.%u\n",
3169 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003170 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003171 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3172 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003173
3174 return 0;
3175
3176err_stop_firmware:
3177 mwl8k_hw_reset(priv);
3178 mwl8k_release_firmware(priv);
3179
3180err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003181 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003182 free_irq(priv->pdev->irq, hw);
3183
3184err_free_queues:
3185 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3186 mwl8k_txq_deinit(hw, i);
3187 mwl8k_rxq_deinit(hw, 0);
3188
3189err_iounmap:
3190 if (priv->cookie != NULL)
3191 pci_free_consistent(priv->pdev, 4,
3192 priv->cookie, priv->cookie_dma);
3193
3194 if (priv->regs != NULL)
3195 pci_iounmap(pdev, priv->regs);
3196
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003197 if (priv->sram != NULL)
3198 pci_iounmap(pdev, priv->sram);
3199
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003200 pci_set_drvdata(pdev, NULL);
3201 ieee80211_free_hw(hw);
3202
3203err_free_reg:
3204 pci_release_regions(pdev);
3205 pci_disable_device(pdev);
3206
3207 return rc;
3208}
3209
Joerg Albert230f7af2009-04-18 02:10:45 +02003210static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003211{
3212 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3213}
3214
Joerg Albert230f7af2009-04-18 02:10:45 +02003215static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003216{
3217 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3218 struct mwl8k_priv *priv;
3219 int i;
3220
3221 if (hw == NULL)
3222 return;
3223 priv = hw->priv;
3224
3225 ieee80211_stop_queues(hw);
3226
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003227 ieee80211_unregister_hw(hw);
3228
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003229 /* Remove tx reclaim tasklet */
3230 tasklet_kill(&priv->tx_reclaim_task);
3231
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003232 /* Stop hardware */
3233 mwl8k_hw_reset(priv);
3234
3235 /* Return all skbs to mac80211 */
3236 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3237 mwl8k_txq_reclaim(hw, i, 1);
3238
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003239 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3240 mwl8k_txq_deinit(hw, i);
3241
3242 mwl8k_rxq_deinit(hw, 0);
3243
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003244 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003245
3246 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003247 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003248 pci_set_drvdata(pdev, NULL);
3249 ieee80211_free_hw(hw);
3250 pci_release_regions(pdev);
3251 pci_disable_device(pdev);
3252}
3253
3254static struct pci_driver mwl8k_driver = {
3255 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003256 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003257 .probe = mwl8k_probe,
3258 .remove = __devexit_p(mwl8k_remove),
3259 .shutdown = __devexit_p(mwl8k_shutdown),
3260};
3261
3262static int __init mwl8k_init(void)
3263{
3264 return pci_register_driver(&mwl8k_driver);
3265}
3266
3267static void __exit mwl8k_exit(void)
3268{
3269 pci_unregister_driver(&mwl8k_driver);
3270}
3271
3272module_init(mwl8k_init);
3273module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003274
3275MODULE_DESCRIPTION(MWL8K_DESC);
3276MODULE_VERSION(MWL8K_VERSION);
3277MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3278MODULE_LICENSE("GPL");