blob: 2ebfee4da3faa564de07a7feff1df57a8acdc902 [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 Buytenhek54bc3a02009-10-22 20:20:59 +020083struct rxd_ops {
84 int rxd_size;
85 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
86 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
87 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status);
88};
89
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020090struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +020091 char *part_name;
92 char *helper_image;
93 char *fw_image;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020094 struct rxd_ops *rxd_ops;
Lennert Buytenhek547810e2009-10-22 20:21:02 +020095 u16 modes;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020096};
97
Lennert Buytenheka66098d2009-03-10 10:13:33 +010098struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020099 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100100
101 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200102 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100103
104 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200105 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100106
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200107 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200108 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200109 struct {
110 struct sk_buff *skb;
111 DECLARE_PCI_UNMAP_ADDR(dma)
112 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100113};
114
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100115struct mwl8k_tx_queue {
116 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200117 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100118
119 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200120 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100121
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200122 struct ieee80211_tx_queue_stats stats;
123 struct mwl8k_tx_desc *txd;
124 dma_addr_t txd_dma;
125 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100126};
127
128/* Pointers to the firmware data and meta information about it. */
129struct mwl8k_firmware {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100130 /* Boot helper code */
131 struct firmware *helper;
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200132
133 /* Microcode */
134 struct firmware *ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100135};
136
137struct mwl8k_priv {
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +0200138 void __iomem *sram;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100139 void __iomem *regs;
140 struct ieee80211_hw *hw;
141
142 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100143
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200144 struct mwl8k_device_info *device_info;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200145 bool ap_fw;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200146 struct rxd_ops *rxd_ops;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200147
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100148 /* firmware files and meta data */
149 struct mwl8k_firmware fw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100150
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200151 /* firmware access */
152 struct mutex fw_mutex;
153 struct task_struct *fw_mutex_owner;
154 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200155 struct completion *hostcmd_wait;
156
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100157 /* lock held over TX and TX reap */
158 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100159
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200160 /* TX quiesce completion, protected by fw_mutex and tx_lock */
161 struct completion *tx_wait;
162
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100163 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100164
165 struct ieee80211_channel *current_channel;
166
167 /* power management status cookie from firmware */
168 u32 *cookie;
169 dma_addr_t cookie_dma;
170
171 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100172 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200173 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100174
175 /*
176 * Running count of TX packets in flight, to avoid
177 * iterating over the transmit rings each time.
178 */
179 int pending_tx_pkts;
180
181 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
182 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
183
184 /* PHY parameters */
185 struct ieee80211_supported_band band;
186 struct ieee80211_channel channels[14];
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200187 struct ieee80211_rate rates[13];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100188
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200189 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200190 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200191 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200192 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100193
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100194 /* XXX need to convert this to handle multiple interfaces */
195 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200196 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100197 struct sk_buff *beacon_skb;
198
199 /*
200 * This FJ worker has to be global as it is scheduled from the
201 * RX handler. At this point we don't know which interface it
202 * belongs to until the list of bssids waiting to complete join
203 * is checked.
204 */
205 struct work_struct finalize_join_worker;
206
207 /* Tasklet to reclaim TX descriptors and buffers after tx */
208 struct tasklet_struct tx_reclaim_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100209};
210
211/* Per interface specific private data */
212struct mwl8k_vif {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100213 /* backpointer to parent config block */
214 struct mwl8k_priv *priv;
215
216 /* BSS config of AP or IBSS from mac80211*/
217 struct ieee80211_bss_conf bss_info;
218
219 /* BSSID of AP or IBSS */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200220 u8 bssid[ETH_ALEN];
221 u8 mac_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100222
223 /*
224 * Subset of supported legacy rates.
225 * Intersection of AP and STA supported rates.
226 */
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200227 struct ieee80211_rate legacy_rates[13];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100228
229 /* number of supported legacy rates */
230 u8 legacy_nrates;
231
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100232 /* Index into station database.Returned by update_sta_db call */
233 u8 peer_id;
234
235 /* Non AMPDU sequence number assigned by driver */
236 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100237};
238
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200239#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100240
241static const struct ieee80211_channel mwl8k_channels[] = {
242 { .center_freq = 2412, .hw_value = 1, },
243 { .center_freq = 2417, .hw_value = 2, },
244 { .center_freq = 2422, .hw_value = 3, },
245 { .center_freq = 2427, .hw_value = 4, },
246 { .center_freq = 2432, .hw_value = 5, },
247 { .center_freq = 2437, .hw_value = 6, },
248 { .center_freq = 2442, .hw_value = 7, },
249 { .center_freq = 2447, .hw_value = 8, },
250 { .center_freq = 2452, .hw_value = 9, },
251 { .center_freq = 2457, .hw_value = 10, },
252 { .center_freq = 2462, .hw_value = 11, },
253};
254
255static const struct ieee80211_rate mwl8k_rates[] = {
256 { .bitrate = 10, .hw_value = 2, },
257 { .bitrate = 20, .hw_value = 4, },
258 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200259 { .bitrate = 110, .hw_value = 22, },
260 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100261 { .bitrate = 60, .hw_value = 12, },
262 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100263 { .bitrate = 120, .hw_value = 24, },
264 { .bitrate = 180, .hw_value = 36, },
265 { .bitrate = 240, .hw_value = 48, },
266 { .bitrate = 360, .hw_value = 72, },
267 { .bitrate = 480, .hw_value = 96, },
268 { .bitrate = 540, .hw_value = 108, },
269};
270
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100271/* Set or get info from Firmware */
272#define MWL8K_CMD_SET 0x0001
273#define MWL8K_CMD_GET 0x0000
274
275/* Firmware command codes */
276#define MWL8K_CMD_CODE_DNLD 0x0001
277#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200278#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100279#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
280#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200281#define MWL8K_CMD_RADIO_CONTROL 0x001c
282#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200283#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100284#define MWL8K_CMD_SET_PRE_SCAN 0x0107
285#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200286#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100287#define MWL8K_CMD_SET_AID 0x010d
288#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200289#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100290#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200291#define MWL8K_CMD_SET_SLOT 0x0114
292#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
293#define MWL8K_CMD_SET_WMM_MODE 0x0123
294#define MWL8K_CMD_MIMO_CONFIG 0x0125
295#define MWL8K_CMD_USE_FIXED_RATE 0x0126
296#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200297#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200298#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
299#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100300
301static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
302{
303#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
304 snprintf(buf, bufsize, "%s", #x);\
305 return buf;\
306 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200307 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100308 MWL8K_CMDNAME(CODE_DNLD);
309 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200310 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100311 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
312 MWL8K_CMDNAME(GET_STAT);
313 MWL8K_CMDNAME(RADIO_CONTROL);
314 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200315 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100316 MWL8K_CMDNAME(SET_PRE_SCAN);
317 MWL8K_CMDNAME(SET_POST_SCAN);
318 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100319 MWL8K_CMDNAME(SET_AID);
320 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200321 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100322 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200323 MWL8K_CMDNAME(SET_SLOT);
324 MWL8K_CMDNAME(SET_EDCA_PARAMS);
325 MWL8K_CMDNAME(SET_WMM_MODE);
326 MWL8K_CMDNAME(MIMO_CONFIG);
327 MWL8K_CMDNAME(USE_FIXED_RATE);
328 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200329 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200330 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
331 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100332 default:
333 snprintf(buf, bufsize, "0x%x", cmd);
334 }
335#undef MWL8K_CMDNAME
336
337 return buf;
338}
339
340/* Hardware and firmware reset */
341static void mwl8k_hw_reset(struct mwl8k_priv *priv)
342{
343 iowrite32(MWL8K_H2A_INT_RESET,
344 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
345 iowrite32(MWL8K_H2A_INT_RESET,
346 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
347 msleep(20);
348}
349
350/* Release fw image */
351static void mwl8k_release_fw(struct firmware **fw)
352{
353 if (*fw == NULL)
354 return;
355 release_firmware(*fw);
356 *fw = NULL;
357}
358
359static void mwl8k_release_firmware(struct mwl8k_priv *priv)
360{
361 mwl8k_release_fw(&priv->fw.ucode);
362 mwl8k_release_fw(&priv->fw.helper);
363}
364
365/* Request fw image */
366static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200367 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100368{
369 /* release current image */
370 if (*fw != NULL)
371 mwl8k_release_fw(fw);
372
373 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200374 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100375}
376
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200377static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100378{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200379 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100380 int rc;
381
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200382 if (di->helper_image != NULL) {
383 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
384 if (rc) {
385 printk(KERN_ERR "%s: Error requesting helper "
386 "firmware file %s\n", pci_name(priv->pdev),
387 di->helper_image);
388 return rc;
389 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100390 }
391
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200392 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100393 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200394 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200395 pci_name(priv->pdev), di->fw_image);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100396 mwl8k_release_fw(&priv->fw.helper);
397 return rc;
398 }
399
400 return 0;
401}
402
403struct mwl8k_cmd_pkt {
404 __le16 code;
405 __le16 length;
406 __le16 seq_num;
407 __le16 result;
408 char payload[0];
409} __attribute__((packed));
410
411/*
412 * Firmware loading.
413 */
414static int
415mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
416{
417 void __iomem *regs = priv->regs;
418 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100419 int loops;
420
421 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
422 if (pci_dma_mapping_error(priv->pdev, dma_addr))
423 return -ENOMEM;
424
425 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
426 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
427 iowrite32(MWL8K_H2A_INT_DOORBELL,
428 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
429 iowrite32(MWL8K_H2A_INT_DUMMY,
430 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
431
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100432 loops = 1000;
433 do {
434 u32 int_code;
435
436 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
437 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
438 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100439 break;
440 }
441
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200442 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100443 udelay(1);
444 } while (--loops);
445
446 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
447
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200448 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100449}
450
451static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
452 const u8 *data, size_t length)
453{
454 struct mwl8k_cmd_pkt *cmd;
455 int done;
456 int rc = 0;
457
458 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
459 if (cmd == NULL)
460 return -ENOMEM;
461
462 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
463 cmd->seq_num = 0;
464 cmd->result = 0;
465
466 done = 0;
467 while (length) {
468 int block_size = length > 256 ? 256 : length;
469
470 memcpy(cmd->payload, data + done, block_size);
471 cmd->length = cpu_to_le16(block_size);
472
473 rc = mwl8k_send_fw_load_cmd(priv, cmd,
474 sizeof(*cmd) + block_size);
475 if (rc)
476 break;
477
478 done += block_size;
479 length -= block_size;
480 }
481
482 if (!rc) {
483 cmd->length = 0;
484 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
485 }
486
487 kfree(cmd);
488
489 return rc;
490}
491
492static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
493 const u8 *data, size_t length)
494{
495 unsigned char *buffer;
496 int may_continue, rc = 0;
497 u32 done, prev_block_size;
498
499 buffer = kmalloc(1024, GFP_KERNEL);
500 if (buffer == NULL)
501 return -ENOMEM;
502
503 done = 0;
504 prev_block_size = 0;
505 may_continue = 1000;
506 while (may_continue > 0) {
507 u32 block_size;
508
509 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
510 if (block_size & 1) {
511 block_size &= ~1;
512 may_continue--;
513 } else {
514 done += prev_block_size;
515 length -= prev_block_size;
516 }
517
518 if (block_size > 1024 || block_size > length) {
519 rc = -EOVERFLOW;
520 break;
521 }
522
523 if (length == 0) {
524 rc = 0;
525 break;
526 }
527
528 if (block_size == 0) {
529 rc = -EPROTO;
530 may_continue--;
531 udelay(1);
532 continue;
533 }
534
535 prev_block_size = block_size;
536 memcpy(buffer, data + done, block_size);
537
538 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
539 if (rc)
540 break;
541 }
542
543 if (!rc && length != 0)
544 rc = -EREMOTEIO;
545
546 kfree(buffer);
547
548 return rc;
549}
550
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200551static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100552{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200553 struct mwl8k_priv *priv = hw->priv;
554 struct firmware *fw = priv->fw.ucode;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200555 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200556 int rc;
557 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100558
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200559 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
560 struct firmware *helper = priv->fw.helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100561
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200562 if (helper == NULL) {
563 printk(KERN_ERR "%s: helper image needed but none "
564 "given\n", pci_name(priv->pdev));
565 return -EINVAL;
566 }
567
568 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100569 if (rc) {
570 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200571 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100572 return rc;
573 }
574 msleep(1);
575
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200576 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100577 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200578 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100579 }
580
581 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200582 printk(KERN_ERR "%s: unable to load firmware image\n",
583 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100584 return rc;
585 }
586
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200587 if (di->modes & BIT(NL80211_IFTYPE_AP))
588 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
589 else
590 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100591 msleep(1);
592
593 loops = 200000;
594 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200595 u32 ready_code;
596
597 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
598 if (ready_code == MWL8K_FWAP_READY) {
599 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100600 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200601 } else if (ready_code == MWL8K_FWSTA_READY) {
602 priv->ap_fw = 0;
603 break;
604 }
605
606 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100607 udelay(1);
608 } while (--loops);
609
610 return loops ? 0 : -ETIMEDOUT;
611}
612
613
614/*
615 * Defines shared between transmission and reception.
616 */
617/* HT control fields for firmware */
618struct ewc_ht_info {
619 __le16 control1;
620 __le16 control2;
621 __le16 control3;
622} __attribute__((packed));
623
624/* Firmware Station database operations */
625#define MWL8K_STA_DB_ADD_ENTRY 0
626#define MWL8K_STA_DB_MODIFY_ENTRY 1
627#define MWL8K_STA_DB_DEL_ENTRY 2
628#define MWL8K_STA_DB_FLUSH 3
629
630/* Peer Entry flags - used to define the type of the peer node */
631#define MWL8K_PEER_TYPE_ACCESSPOINT 2
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100632
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200633#define MWL8K_IEEE_LEGACY_DATA_RATES 13
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100634#define MWL8K_MCS_BITMAP_SIZE 16
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100635
636struct peer_capability_info {
637 /* Peer type - AP vs. STA. */
638 __u8 peer_type;
639
640 /* Basic 802.11 capabilities from assoc resp. */
641 __le16 basic_caps;
642
643 /* Set if peer supports 802.11n high throughput (HT). */
644 __u8 ht_support;
645
646 /* Valid if HT is supported. */
647 __le16 ht_caps;
648 __u8 extended_ht_caps;
649 struct ewc_ht_info ewc_info;
650
651 /* Legacy rate table. Intersection of our rates and peer rates. */
652 __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
653
654 /* HT rate table. Intersection of our rates and peer rates. */
655 __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +0200656 __u8 pad[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100657
658 /* If set, interoperability mode, no proprietary extensions. */
659 __u8 interop;
660 __u8 pad2;
661 __u8 station_id;
662 __le16 amsdu_enabled;
663} __attribute__((packed));
664
665/* Inline functions to manipulate QoS field in data descriptor. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100666static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
667{
668 u16 val_mask = 1 << 4;
669
670 /* End of Service Period Bit 4 */
671 return qos | val_mask;
672}
673
674static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
675{
676 u16 val_mask = 0x3;
677 u8 shift = 5;
678 u16 qos_mask = ~(val_mask << shift);
679
680 /* Ack Policy Bit 5-6 */
681 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
682}
683
684static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
685{
686 u16 val_mask = 1 << 7;
687
688 /* AMSDU present Bit 7 */
689 return qos | val_mask;
690}
691
692static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
693{
694 u16 val_mask = 0xff;
695 u8 shift = 8;
696 u16 qos_mask = ~(val_mask << shift);
697
698 /* Queue Length Bits 8-15 */
699 return (qos & qos_mask) | ((len & val_mask) << shift);
700}
701
702/* DMA header used by firmware and hardware. */
703struct mwl8k_dma_data {
704 __le16 fwlen;
705 struct ieee80211_hdr wh;
706} __attribute__((packed));
707
708/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200709static inline void mwl8k_remove_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100710{
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200711 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)skb->data;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100712 void *dst, *src = &tr->wh;
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200713 int hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100714 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
715
716 dst = (void *)tr + space;
717 if (dst != src) {
718 memmove(dst, src, hdrlen);
719 skb_pull(skb, space);
720 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100721}
722
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200723static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100724{
725 struct ieee80211_hdr *wh;
726 u32 hdrlen, pktlen;
727 struct mwl8k_dma_data *tr;
728
729 wh = (struct ieee80211_hdr *)skb->data;
730 hdrlen = ieee80211_hdrlen(wh->frame_control);
731 pktlen = skb->len;
732
733 /*
734 * Copy up/down the 802.11 header; the firmware requires
735 * we present a 2-byte payload length followed by a
736 * 4-address header (w/o QoS), followed (optionally) by
737 * any WEP/ExtIV header (but only filled in for CCMP).
738 */
739 if (hdrlen != sizeof(struct mwl8k_dma_data))
740 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
741
742 tr = (struct mwl8k_dma_data *)skb->data;
743 if (wh != &tr->wh)
744 memmove(&tr->wh, wh, hdrlen);
745
746 /* Clear addr4 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200747 memset(tr->wh.addr4, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100748
749 /*
750 * Firmware length is the length of the fully formed "802.11
751 * payload". That is, everything except for the 802.11 header.
752 * This includes all crypto material including the MIC.
753 */
754 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100755}
756
757
758/*
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200759 * Packet reception for 88w8366.
760 */
761struct mwl8k_rxd_8366 {
762 __le16 pkt_len;
763 __u8 sq2;
764 __u8 rate;
765 __le32 pkt_phys_addr;
766 __le32 next_rxd_phys_addr;
767 __le16 qos_control;
768 __le16 htsig2;
769 __le32 hw_rssi_info;
770 __le32 hw_noise_floor_info;
771 __u8 noise_floor;
772 __u8 pad0[3];
773 __u8 rssi;
774 __u8 rx_status;
775 __u8 channel;
776 __u8 rx_ctrl;
777} __attribute__((packed));
778
779#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
780
781static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
782{
783 struct mwl8k_rxd_8366 *rxd = _rxd;
784
785 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
786 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
787}
788
789static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
790{
791 struct mwl8k_rxd_8366 *rxd = _rxd;
792
793 rxd->pkt_len = cpu_to_le16(len);
794 rxd->pkt_phys_addr = cpu_to_le32(addr);
795 wmb();
796 rxd->rx_ctrl = 0;
797}
798
799static int
800mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status)
801{
802 struct mwl8k_rxd_8366 *rxd = _rxd;
803
804 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
805 return -1;
806 rmb();
807
808 memset(status, 0, sizeof(*status));
809
810 status->signal = -rxd->rssi;
811 status->noise = -rxd->noise_floor;
812
813 if (rxd->rate & 0x80) {
814 status->flag |= RX_FLAG_HT;
815 status->rate_idx = rxd->rate & 0x7f;
816 } else {
817 int i;
818
819 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
820 if (mwl8k_rates[i].hw_value == rxd->rate) {
821 status->rate_idx = i;
822 break;
823 }
824 }
825 }
826
827 status->band = IEEE80211_BAND_2GHZ;
828 status->freq = ieee80211_channel_to_frequency(rxd->channel);
829
830 return le16_to_cpu(rxd->pkt_len);
831}
832
833static struct rxd_ops rxd_8366_ops = {
834 .rxd_size = sizeof(struct mwl8k_rxd_8366),
835 .rxd_init = mwl8k_rxd_8366_init,
836 .rxd_refill = mwl8k_rxd_8366_refill,
837 .rxd_process = mwl8k_rxd_8366_process,
838};
839
840/*
841 * Packet reception for 88w8687.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100842 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200843struct mwl8k_rxd_8687 {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100844 __le16 pkt_len;
845 __u8 link_quality;
846 __u8 noise_level;
847 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200848 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100849 __le16 qos_control;
850 __le16 rate_info;
851 __le32 pad0[4];
852 __u8 rssi;
853 __u8 channel;
854 __le16 pad1;
855 __u8 rx_ctrl;
856 __u8 rx_status;
857 __u8 pad2[2];
858} __attribute__((packed));
859
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200860#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
861#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
862#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
863#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
864#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
865#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
866
867#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
868
869static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
870{
871 struct mwl8k_rxd_8687 *rxd = _rxd;
872
873 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
874 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
875}
876
877static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
878{
879 struct mwl8k_rxd_8687 *rxd = _rxd;
880
881 rxd->pkt_len = cpu_to_le16(len);
882 rxd->pkt_phys_addr = cpu_to_le32(addr);
883 wmb();
884 rxd->rx_ctrl = 0;
885}
886
887static int
888mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status)
889{
890 struct mwl8k_rxd_8687 *rxd = _rxd;
891 u16 rate_info;
892
893 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
894 return -1;
895 rmb();
896
897 rate_info = le16_to_cpu(rxd->rate_info);
898
899 memset(status, 0, sizeof(*status));
900
901 status->signal = -rxd->rssi;
902 status->noise = -rxd->noise_level;
903 status->qual = rxd->link_quality;
904 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
905 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
906
907 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
908 status->flag |= RX_FLAG_SHORTPRE;
909 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
910 status->flag |= RX_FLAG_40MHZ;
911 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
912 status->flag |= RX_FLAG_SHORT_GI;
913 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
914 status->flag |= RX_FLAG_HT;
915
916 status->band = IEEE80211_BAND_2GHZ;
917 status->freq = ieee80211_channel_to_frequency(rxd->channel);
918
919 return le16_to_cpu(rxd->pkt_len);
920}
921
922static struct rxd_ops rxd_8687_ops = {
923 .rxd_size = sizeof(struct mwl8k_rxd_8687),
924 .rxd_init = mwl8k_rxd_8687_init,
925 .rxd_refill = mwl8k_rxd_8687_refill,
926 .rxd_process = mwl8k_rxd_8687_process,
927};
928
929
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100930#define MWL8K_RX_DESCS 256
931#define MWL8K_RX_MAXSZ 3800
932
933static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
934{
935 struct mwl8k_priv *priv = hw->priv;
936 struct mwl8k_rx_queue *rxq = priv->rxq + index;
937 int size;
938 int i;
939
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200940 rxq->rxd_count = 0;
941 rxq->head = 0;
942 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100943
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200944 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100945
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200946 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
947 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100948 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200949 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100950 return -ENOMEM;
951 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200952 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100953
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200954 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
955 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100956 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200957 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200958 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100959 return -ENOMEM;
960 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200961 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100962
963 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200964 int desc_size;
965 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100966 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200967 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100968
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200969 desc_size = priv->rxd_ops->rxd_size;
970 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100971
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200972 nexti = i + 1;
973 if (nexti == MWL8K_RX_DESCS)
974 nexti = 0;
975 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
976
977 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100978 }
979
980 return 0;
981}
982
983static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
984{
985 struct mwl8k_priv *priv = hw->priv;
986 struct mwl8k_rx_queue *rxq = priv->rxq + index;
987 int refilled;
988
989 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200990 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100991 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200992 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100993 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200994 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100995
996 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
997 if (skb == NULL)
998 break;
999
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001000 addr = pci_map_single(priv->pdev, skb->data,
1001 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001002
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001003 rxq->rxd_count++;
1004 rx = rxq->tail++;
1005 if (rxq->tail == MWL8K_RX_DESCS)
1006 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001007 rxq->buf[rx].skb = skb;
1008 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001009
1010 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1011 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001012
1013 refilled++;
1014 }
1015
1016 return refilled;
1017}
1018
1019/* Must be called only when the card's reception is completely halted */
1020static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1021{
1022 struct mwl8k_priv *priv = hw->priv;
1023 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1024 int i;
1025
1026 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001027 if (rxq->buf[i].skb != NULL) {
1028 pci_unmap_single(priv->pdev,
1029 pci_unmap_addr(&rxq->buf[i], dma),
1030 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1031 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001032
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001033 kfree_skb(rxq->buf[i].skb);
1034 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001035 }
1036 }
1037
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001038 kfree(rxq->buf);
1039 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001040
1041 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001042 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001043 rxq->rxd, rxq->rxd_dma);
1044 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001045}
1046
1047
1048/*
1049 * Scan a list of BSSIDs to process for finalize join.
1050 * Allows for extension to process multiple BSSIDs.
1051 */
1052static inline int
1053mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1054{
1055 return priv->capture_beacon &&
1056 ieee80211_is_beacon(wh->frame_control) &&
1057 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1058}
1059
Lennert Buytenhek37797522009-10-22 20:19:45 +02001060static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1061 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001062{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001063 struct mwl8k_priv *priv = hw->priv;
1064
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001065 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001066 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001067
1068 /*
1069 * Use GFP_ATOMIC as rxq_process is called from
1070 * the primary interrupt handler, memory allocation call
1071 * must not sleep.
1072 */
1073 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1074 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001075 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001076}
1077
1078static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1079{
1080 struct mwl8k_priv *priv = hw->priv;
1081 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1082 int processed;
1083
1084 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001085 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001086 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001087 void *rxd;
1088 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001089 struct ieee80211_rx_status status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001090
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001091 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001092 if (skb == NULL)
1093 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001094
1095 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1096
1097 pkt_len = priv->rxd_ops->rxd_process(rxd, &status);
1098 if (pkt_len < 0)
1099 break;
1100
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001101 rxq->buf[rxq->head].skb = NULL;
1102
1103 pci_unmap_single(priv->pdev,
1104 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1105 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1106 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001107
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001108 rxq->head++;
1109 if (rxq->head == MWL8K_RX_DESCS)
1110 rxq->head = 0;
1111
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001112 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001113
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001114 skb_put(skb, pkt_len);
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001115 mwl8k_remove_dma_header(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001116
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001117 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001118 * Check for a pending join operation. Save a
1119 * copy of the beacon and schedule a tasklet to
1120 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001121 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001122 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001123 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001124
Johannes Bergf1d58c22009-06-17 13:13:00 +02001125 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1126 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001127
1128 processed++;
1129 }
1130
1131 return processed;
1132}
1133
1134
1135/*
1136 * Packet transmission.
1137 */
1138
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001139/* Transmit packet ACK policy */
1140#define MWL8K_TXD_ACK_POLICY_NORMAL 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001141#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1142
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001143#define MWL8K_TXD_STATUS_OK 0x00000001
1144#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1145#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1146#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001147#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001148
1149struct mwl8k_tx_desc {
1150 __le32 status;
1151 __u8 data_rate;
1152 __u8 tx_priority;
1153 __le16 qos_control;
1154 __le32 pkt_phys_addr;
1155 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001156 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001157 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001158 __le32 reserved;
1159 __le16 rate_info;
1160 __u8 peer_id;
1161 __u8 tx_frag_cnt;
1162} __attribute__((packed));
1163
1164#define MWL8K_TX_DESCS 128
1165
1166static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1167{
1168 struct mwl8k_priv *priv = hw->priv;
1169 struct mwl8k_tx_queue *txq = priv->txq + index;
1170 int size;
1171 int i;
1172
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001173 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1174 txq->stats.limit = MWL8K_TX_DESCS;
1175 txq->head = 0;
1176 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001177
1178 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1179
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001180 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1181 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001182 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001183 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001184 return -ENOMEM;
1185 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001186 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001187
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001188 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1189 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001190 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001191 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001192 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001193 return -ENOMEM;
1194 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001195 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001196
1197 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1198 struct mwl8k_tx_desc *tx_desc;
1199 int nexti;
1200
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001201 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001202 nexti = (i + 1) % MWL8K_TX_DESCS;
1203
1204 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001205 tx_desc->next_txd_phys_addr =
1206 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001207 }
1208
1209 return 0;
1210}
1211
1212static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1213{
1214 iowrite32(MWL8K_H2A_INT_PPA_READY,
1215 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1216 iowrite32(MWL8K_H2A_INT_DUMMY,
1217 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1218 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1219}
1220
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001221struct mwl8k_txq_info {
1222 u32 fw_owned;
1223 u32 drv_owned;
1224 u32 unused;
1225 u32 len;
1226 u32 head;
1227 u32 tail;
1228};
1229
1230static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001231 struct mwl8k_txq_info *txinfo)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001232{
1233 int count, desc, status;
1234 struct mwl8k_tx_queue *txq;
1235 struct mwl8k_tx_desc *tx_desc;
1236 int ndescs = 0;
1237
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001238 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
1239
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001240 for (count = 0; count < MWL8K_TX_QUEUES; count++) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001241 txq = priv->txq + count;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001242 txinfo[count].len = txq->stats.len;
1243 txinfo[count].head = txq->head;
1244 txinfo[count].tail = txq->tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001245 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001246 tx_desc = txq->txd + desc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001247 status = le32_to_cpu(tx_desc->status);
1248
1249 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1250 txinfo[count].fw_owned++;
1251 else
1252 txinfo[count].drv_owned++;
1253
1254 if (tx_desc->pkt_len == 0)
1255 txinfo[count].unused++;
1256 }
1257 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001258
1259 return ndescs;
1260}
1261
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001262/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001263 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001264 */
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001265static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001266{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001267 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001268 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001269 u32 count;
1270 unsigned long timeout;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001271
1272 might_sleep();
1273
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001274 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001275 count = priv->pending_tx_pkts;
1276 if (count)
1277 priv->tx_wait = &tx_wait;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001278 spin_unlock_bh(&priv->tx_lock);
1279
1280 if (count) {
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001281 struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001282 int index;
1283 int newcount;
1284
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001285 timeout = wait_for_completion_timeout(&tx_wait,
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001286 msecs_to_jiffies(5000));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001287 if (timeout)
1288 return 0;
1289
1290 spin_lock_bh(&priv->tx_lock);
1291 priv->tx_wait = NULL;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001292 newcount = priv->pending_tx_pkts;
1293 mwl8k_scan_tx_ring(priv, txinfo);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001294 spin_unlock_bh(&priv->tx_lock);
1295
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001296 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001297 __func__, __LINE__, count, newcount);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001298
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001299 for (index = 0; index < MWL8K_TX_QUEUES; index++)
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001300 printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u "
1301 "DRV:%u U:%u\n",
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001302 index,
1303 txinfo[index].len,
1304 txinfo[index].head,
1305 txinfo[index].tail,
1306 txinfo[index].fw_owned,
1307 txinfo[index].drv_owned,
1308 txinfo[index].unused);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001309
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001310 return -ETIMEDOUT;
1311 }
1312
1313 return 0;
1314}
1315
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001316#define MWL8K_TXD_SUCCESS(status) \
1317 ((status) & (MWL8K_TXD_STATUS_OK | \
1318 MWL8K_TXD_STATUS_OK_RETRY | \
1319 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001320
1321static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1322{
1323 struct mwl8k_priv *priv = hw->priv;
1324 struct mwl8k_tx_queue *txq = priv->txq + index;
1325 int wake = 0;
1326
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001327 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001328 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001329 struct mwl8k_tx_desc *tx_desc;
1330 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001331 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001332 struct sk_buff *skb;
1333 struct ieee80211_tx_info *info;
1334 u32 status;
1335
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001336 tx = txq->head;
1337 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001338
1339 status = le32_to_cpu(tx_desc->status);
1340
1341 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1342 if (!force)
1343 break;
1344 tx_desc->status &=
1345 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1346 }
1347
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001348 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1349 BUG_ON(txq->stats.len == 0);
1350 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001351 priv->pending_tx_pkts--;
1352
1353 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001354 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001355 skb = txq->skb[tx];
1356 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001357
1358 BUG_ON(skb == NULL);
1359 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1360
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001361 mwl8k_remove_dma_header(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001362
1363 /* Mark descriptor as unused */
1364 tx_desc->pkt_phys_addr = 0;
1365 tx_desc->pkt_len = 0;
1366
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001367 info = IEEE80211_SKB_CB(skb);
1368 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001369 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001370 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001371
1372 ieee80211_tx_status_irqsafe(hw, skb);
1373
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001374 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001375 }
1376
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001377 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001378 ieee80211_wake_queue(hw, index);
1379}
1380
1381/* must be called only when the card's transmit is completely halted */
1382static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1383{
1384 struct mwl8k_priv *priv = hw->priv;
1385 struct mwl8k_tx_queue *txq = priv->txq + index;
1386
1387 mwl8k_txq_reclaim(hw, index, 1);
1388
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001389 kfree(txq->skb);
1390 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001391
1392 pci_free_consistent(priv->pdev,
1393 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001394 txq->txd, txq->txd_dma);
1395 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001396}
1397
1398static int
1399mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1400{
1401 struct mwl8k_priv *priv = hw->priv;
1402 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001403 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001404 struct ieee80211_hdr *wh;
1405 struct mwl8k_tx_queue *txq;
1406 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001407 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001408 u32 txstatus;
1409 u8 txdatarate;
1410 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001411
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001412 wh = (struct ieee80211_hdr *)skb->data;
1413 if (ieee80211_is_data_qos(wh->frame_control))
1414 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1415 else
1416 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001417
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001418 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001419 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001420
1421 tx_info = IEEE80211_SKB_CB(skb);
1422 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001423
1424 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1425 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001426
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001427 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1428 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1429 mwl8k_vif->seqno = seqno++ % 4096;
1430 }
1431
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001432 /* Setup firmware control bit fields for each frame type. */
1433 txstatus = 0;
1434 txdatarate = 0;
1435 if (ieee80211_is_mgmt(wh->frame_control) ||
1436 ieee80211_is_ctl(wh->frame_control)) {
1437 txdatarate = 0;
1438 qos = mwl8k_qos_setbit_eosp(qos);
1439 /* Set Queue size to unspecified */
1440 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1441 } else if (ieee80211_is_data(wh->frame_control)) {
1442 txdatarate = 1;
1443 if (is_multicast_ether_addr(wh->addr1))
1444 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1445
1446 /* Send pkt in an aggregate if AMPDU frame. */
1447 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1448 qos = mwl8k_qos_setbit_ack(qos,
1449 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1450 else
1451 qos = mwl8k_qos_setbit_ack(qos,
1452 MWL8K_TXD_ACK_POLICY_NORMAL);
1453
1454 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1455 qos = mwl8k_qos_setbit_amsdu(qos);
1456 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001457
1458 dma = pci_map_single(priv->pdev, skb->data,
1459 skb->len, PCI_DMA_TODEVICE);
1460
1461 if (pci_dma_mapping_error(priv->pdev, dma)) {
1462 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001463 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001464 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001465 return NETDEV_TX_OK;
1466 }
1467
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001468 spin_lock_bh(&priv->tx_lock);
1469
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001470 txq = priv->txq + index;
1471
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001472 BUG_ON(txq->skb[txq->tail] != NULL);
1473 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001474
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001475 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001476 tx->data_rate = txdatarate;
1477 tx->tx_priority = index;
1478 tx->qos_control = cpu_to_le16(qos);
1479 tx->pkt_phys_addr = cpu_to_le32(dma);
1480 tx->pkt_len = cpu_to_le16(skb->len);
1481 tx->rate_info = 0;
1482 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001483 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001484 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1485
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001486 txq->stats.count++;
1487 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001488 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001489
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001490 txq->tail++;
1491 if (txq->tail == MWL8K_TX_DESCS)
1492 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001493
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001494 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001495 ieee80211_stop_queue(hw, index);
1496
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001497 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001498
1499 spin_unlock_bh(&priv->tx_lock);
1500
1501 return NETDEV_TX_OK;
1502}
1503
1504
1505/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001506 * Firmware access.
1507 *
1508 * We have the following requirements for issuing firmware commands:
1509 * - Some commands require that the packet transmit path is idle when
1510 * the command is issued. (For simplicity, we'll just quiesce the
1511 * transmit path for every command.)
1512 * - There are certain sequences of commands that need to be issued to
1513 * the hardware sequentially, with no other intervening commands.
1514 *
1515 * This leads to an implementation of a "firmware lock" as a mutex that
1516 * can be taken recursively, and which is taken by both the low-level
1517 * command submission function (mwl8k_post_cmd) as well as any users of
1518 * that function that require issuing of an atomic sequence of commands,
1519 * and quiesces the transmit path whenever it's taken.
1520 */
1521static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1522{
1523 struct mwl8k_priv *priv = hw->priv;
1524
1525 if (priv->fw_mutex_owner != current) {
1526 int rc;
1527
1528 mutex_lock(&priv->fw_mutex);
1529 ieee80211_stop_queues(hw);
1530
1531 rc = mwl8k_tx_wait_empty(hw);
1532 if (rc) {
1533 ieee80211_wake_queues(hw);
1534 mutex_unlock(&priv->fw_mutex);
1535
1536 return rc;
1537 }
1538
1539 priv->fw_mutex_owner = current;
1540 }
1541
1542 priv->fw_mutex_depth++;
1543
1544 return 0;
1545}
1546
1547static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1548{
1549 struct mwl8k_priv *priv = hw->priv;
1550
1551 if (!--priv->fw_mutex_depth) {
1552 ieee80211_wake_queues(hw);
1553 priv->fw_mutex_owner = NULL;
1554 mutex_unlock(&priv->fw_mutex);
1555 }
1556}
1557
1558
1559/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001560 * Command processing.
1561 */
1562
1563/* Timeout firmware commands after 2000ms */
1564#define MWL8K_CMD_TIMEOUT_MS 2000
1565
1566static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1567{
1568 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1569 struct mwl8k_priv *priv = hw->priv;
1570 void __iomem *regs = priv->regs;
1571 dma_addr_t dma_addr;
1572 unsigned int dma_size;
1573 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001574 unsigned long timeout = 0;
1575 u8 buf[32];
1576
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001577 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001578 dma_size = le16_to_cpu(cmd->length);
1579 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1580 PCI_DMA_BIDIRECTIONAL);
1581 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1582 return -ENOMEM;
1583
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001584 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001585 if (rc) {
1586 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1587 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001588 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001589 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001590
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001591 priv->hostcmd_wait = &cmd_wait;
1592 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1593 iowrite32(MWL8K_H2A_INT_DOORBELL,
1594 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1595 iowrite32(MWL8K_H2A_INT_DUMMY,
1596 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001597
1598 timeout = wait_for_completion_timeout(&cmd_wait,
1599 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1600
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001601 priv->hostcmd_wait = NULL;
1602
1603 mwl8k_fw_unlock(hw);
1604
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001605 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1606 PCI_DMA_BIDIRECTIONAL);
1607
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001608 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001609 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001610 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001611 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1612 MWL8K_CMD_TIMEOUT_MS);
1613 rc = -ETIMEDOUT;
1614 } else {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001615 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001616 if (rc)
1617 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001618 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001619 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001620 le16_to_cpu(cmd->result));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001621 }
1622
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001623 return rc;
1624}
1625
1626/*
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001627 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001628 */
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001629struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001630 struct mwl8k_cmd_pkt header;
1631 __u8 hw_rev;
1632 __u8 host_interface;
1633 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001634 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001635 __le16 region_code;
1636 __le32 fw_rev;
1637 __le32 ps_cookie;
1638 __le32 caps;
1639 __u8 mcs_bitmap[16];
1640 __le32 rx_queue_ptr;
1641 __le32 num_tx_queues;
1642 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1643 __le32 caps2;
1644 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001645 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001646} __attribute__((packed));
1647
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001648static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001649{
1650 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001651 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001652 int rc;
1653 int i;
1654
1655 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1656 if (cmd == NULL)
1657 return -ENOMEM;
1658
1659 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1660 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1661
1662 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1663 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001664 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001665 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001666 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001667 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001668 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001669 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001670
1671 rc = mwl8k_post_cmd(hw, &cmd->header);
1672
1673 if (!rc) {
1674 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1675 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001676 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001677 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001678 }
1679
1680 kfree(cmd);
1681 return rc;
1682}
1683
1684/*
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02001685 * CMD_GET_HW_SPEC (AP version).
1686 */
1687struct mwl8k_cmd_get_hw_spec_ap {
1688 struct mwl8k_cmd_pkt header;
1689 __u8 hw_rev;
1690 __u8 host_interface;
1691 __le16 num_wcb;
1692 __le16 num_mcaddrs;
1693 __u8 perm_addr[ETH_ALEN];
1694 __le16 region_code;
1695 __le16 num_antenna;
1696 __le32 fw_rev;
1697 __le32 wcbbase0;
1698 __le32 rxwrptr;
1699 __le32 rxrdptr;
1700 __le32 ps_cookie;
1701 __le32 wcbbase1;
1702 __le32 wcbbase2;
1703 __le32 wcbbase3;
1704} __attribute__((packed));
1705
1706static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1707{
1708 struct mwl8k_priv *priv = hw->priv;
1709 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1710 int rc;
1711
1712 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1713 if (cmd == NULL)
1714 return -ENOMEM;
1715
1716 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1717 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1718
1719 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1720 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1721
1722 rc = mwl8k_post_cmd(hw, &cmd->header);
1723
1724 if (!rc) {
1725 int off;
1726
1727 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1728 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1729 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1730 priv->hw_rev = cmd->hw_rev;
1731
1732 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1733 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1734
1735 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1736 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1737
1738 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1739 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1740
1741 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1742 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1743
1744 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1745 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1746
1747 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1748 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1749 }
1750
1751 kfree(cmd);
1752 return rc;
1753}
1754
1755/*
1756 * CMD_SET_HW_SPEC.
1757 */
1758struct mwl8k_cmd_set_hw_spec {
1759 struct mwl8k_cmd_pkt header;
1760 __u8 hw_rev;
1761 __u8 host_interface;
1762 __le16 num_mcaddrs;
1763 __u8 perm_addr[ETH_ALEN];
1764 __le16 region_code;
1765 __le32 fw_rev;
1766 __le32 ps_cookie;
1767 __le32 caps;
1768 __le32 rx_queue_ptr;
1769 __le32 num_tx_queues;
1770 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1771 __le32 flags;
1772 __le32 num_tx_desc_per_queue;
1773 __le32 total_rxd;
1774} __attribute__((packed));
1775
1776#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1777
1778static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1779{
1780 struct mwl8k_priv *priv = hw->priv;
1781 struct mwl8k_cmd_set_hw_spec *cmd;
1782 int rc;
1783 int i;
1784
1785 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1786 if (cmd == NULL)
1787 return -ENOMEM;
1788
1789 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1790 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1791
1792 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1793 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1794 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1795 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1796 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1797 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1798 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1799 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1800
1801 rc = mwl8k_post_cmd(hw, &cmd->header);
1802 kfree(cmd);
1803
1804 return rc;
1805}
1806
1807/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001808 * CMD_MAC_MULTICAST_ADR.
1809 */
1810struct mwl8k_cmd_mac_multicast_adr {
1811 struct mwl8k_cmd_pkt header;
1812 __le16 action;
1813 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001814 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001815};
1816
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001817#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1818#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1819#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1820#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001821
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001822static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001823__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001824 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001825{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001826 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001827 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001828 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001829
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001830 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001831 allmulti = 1;
1832 mc_count = 0;
1833 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001834
1835 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1836
1837 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001838 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001839 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001840
1841 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1842 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001843 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1844 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001845
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001846 if (allmulti) {
1847 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1848 } else if (mc_count) {
1849 int i;
1850
1851 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1852 cmd->numaddr = cpu_to_le16(mc_count);
1853 for (i = 0; i < mc_count && mclist; i++) {
1854 if (mclist->da_addrlen != ETH_ALEN) {
1855 kfree(cmd);
1856 return NULL;
1857 }
1858 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1859 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001860 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001861 }
1862
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001863 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001864}
1865
1866/*
1867 * CMD_802_11_GET_STAT.
1868 */
1869struct mwl8k_cmd_802_11_get_stat {
1870 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001871 __le32 stats[64];
1872} __attribute__((packed));
1873
1874#define MWL8K_STAT_ACK_FAILURE 9
1875#define MWL8K_STAT_RTS_FAILURE 12
1876#define MWL8K_STAT_FCS_ERROR 24
1877#define MWL8K_STAT_RTS_SUCCESS 11
1878
1879static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1880 struct ieee80211_low_level_stats *stats)
1881{
1882 struct mwl8k_cmd_802_11_get_stat *cmd;
1883 int rc;
1884
1885 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1886 if (cmd == NULL)
1887 return -ENOMEM;
1888
1889 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1890 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001891
1892 rc = mwl8k_post_cmd(hw, &cmd->header);
1893 if (!rc) {
1894 stats->dot11ACKFailureCount =
1895 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1896 stats->dot11RTSFailureCount =
1897 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1898 stats->dot11FCSErrorCount =
1899 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1900 stats->dot11RTSSuccessCount =
1901 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1902 }
1903 kfree(cmd);
1904
1905 return rc;
1906}
1907
1908/*
1909 * CMD_802_11_RADIO_CONTROL.
1910 */
1911struct mwl8k_cmd_802_11_radio_control {
1912 struct mwl8k_cmd_pkt header;
1913 __le16 action;
1914 __le16 control;
1915 __le16 radio_on;
1916} __attribute__((packed));
1917
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001918static int
1919mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001920{
1921 struct mwl8k_priv *priv = hw->priv;
1922 struct mwl8k_cmd_802_11_radio_control *cmd;
1923 int rc;
1924
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001925 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001926 return 0;
1927
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001928 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1929 if (cmd == NULL)
1930 return -ENOMEM;
1931
1932 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1933 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1934 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001935 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001936 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1937
1938 rc = mwl8k_post_cmd(hw, &cmd->header);
1939 kfree(cmd);
1940
1941 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001942 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001943
1944 return rc;
1945}
1946
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001947static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1948{
1949 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1950}
1951
1952static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1953{
1954 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1955}
1956
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001957static int
1958mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1959{
1960 struct mwl8k_priv *priv;
1961
1962 if (hw == NULL || hw->priv == NULL)
1963 return -EINVAL;
1964 priv = hw->priv;
1965
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001966 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001967
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001968 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001969}
1970
1971/*
1972 * CMD_802_11_RF_TX_POWER.
1973 */
1974#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1975
1976struct mwl8k_cmd_802_11_rf_tx_power {
1977 struct mwl8k_cmd_pkt header;
1978 __le16 action;
1979 __le16 support_level;
1980 __le16 current_level;
1981 __le16 reserved;
1982 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1983} __attribute__((packed));
1984
1985static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1986{
1987 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1988 int rc;
1989
1990 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1991 if (cmd == NULL)
1992 return -ENOMEM;
1993
1994 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1995 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1996 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1997 cmd->support_level = cpu_to_le16(dBm);
1998
1999 rc = mwl8k_post_cmd(hw, &cmd->header);
2000 kfree(cmd);
2001
2002 return rc;
2003}
2004
2005/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002006 * CMD_RF_ANTENNA.
2007 */
2008struct mwl8k_cmd_rf_antenna {
2009 struct mwl8k_cmd_pkt header;
2010 __le16 antenna;
2011 __le16 mode;
2012} __attribute__((packed));
2013
2014#define MWL8K_RF_ANTENNA_RX 1
2015#define MWL8K_RF_ANTENNA_TX 2
2016
2017static int
2018mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2019{
2020 struct mwl8k_cmd_rf_antenna *cmd;
2021 int rc;
2022
2023 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2024 if (cmd == NULL)
2025 return -ENOMEM;
2026
2027 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2028 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2029 cmd->antenna = cpu_to_le16(antenna);
2030 cmd->mode = cpu_to_le16(mask);
2031
2032 rc = mwl8k_post_cmd(hw, &cmd->header);
2033 kfree(cmd);
2034
2035 return rc;
2036}
2037
2038/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002039 * CMD_SET_PRE_SCAN.
2040 */
2041struct mwl8k_cmd_set_pre_scan {
2042 struct mwl8k_cmd_pkt header;
2043} __attribute__((packed));
2044
2045static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2046{
2047 struct mwl8k_cmd_set_pre_scan *cmd;
2048 int rc;
2049
2050 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2051 if (cmd == NULL)
2052 return -ENOMEM;
2053
2054 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2055 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2056
2057 rc = mwl8k_post_cmd(hw, &cmd->header);
2058 kfree(cmd);
2059
2060 return rc;
2061}
2062
2063/*
2064 * CMD_SET_POST_SCAN.
2065 */
2066struct mwl8k_cmd_set_post_scan {
2067 struct mwl8k_cmd_pkt header;
2068 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002069 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002070} __attribute__((packed));
2071
2072static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002073mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002074{
2075 struct mwl8k_cmd_set_post_scan *cmd;
2076 int rc;
2077
2078 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2079 if (cmd == NULL)
2080 return -ENOMEM;
2081
2082 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2083 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2084 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002085 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002086
2087 rc = mwl8k_post_cmd(hw, &cmd->header);
2088 kfree(cmd);
2089
2090 return rc;
2091}
2092
2093/*
2094 * CMD_SET_RF_CHANNEL.
2095 */
2096struct mwl8k_cmd_set_rf_channel {
2097 struct mwl8k_cmd_pkt header;
2098 __le16 action;
2099 __u8 current_channel;
2100 __le32 channel_flags;
2101} __attribute__((packed));
2102
2103static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2104 struct ieee80211_channel *channel)
2105{
2106 struct mwl8k_cmd_set_rf_channel *cmd;
2107 int rc;
2108
2109 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2110 if (cmd == NULL)
2111 return -ENOMEM;
2112
2113 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2114 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2115 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2116 cmd->current_channel = channel->hw_value;
2117 if (channel->band == IEEE80211_BAND_2GHZ)
2118 cmd->channel_flags = cpu_to_le32(0x00000081);
2119 else
2120 cmd->channel_flags = cpu_to_le32(0x00000000);
2121
2122 rc = mwl8k_post_cmd(hw, &cmd->header);
2123 kfree(cmd);
2124
2125 return rc;
2126}
2127
2128/*
2129 * CMD_SET_SLOT.
2130 */
2131struct mwl8k_cmd_set_slot {
2132 struct mwl8k_cmd_pkt header;
2133 __le16 action;
2134 __u8 short_slot;
2135} __attribute__((packed));
2136
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002137static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002138{
2139 struct mwl8k_cmd_set_slot *cmd;
2140 int rc;
2141
2142 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2143 if (cmd == NULL)
2144 return -ENOMEM;
2145
2146 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2147 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2148 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002149 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002150
2151 rc = mwl8k_post_cmd(hw, &cmd->header);
2152 kfree(cmd);
2153
2154 return rc;
2155}
2156
2157/*
2158 * CMD_MIMO_CONFIG.
2159 */
2160struct mwl8k_cmd_mimo_config {
2161 struct mwl8k_cmd_pkt header;
2162 __le32 action;
2163 __u8 rx_antenna_map;
2164 __u8 tx_antenna_map;
2165} __attribute__((packed));
2166
2167static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2168{
2169 struct mwl8k_cmd_mimo_config *cmd;
2170 int rc;
2171
2172 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2173 if (cmd == NULL)
2174 return -ENOMEM;
2175
2176 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2177 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2178 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2179 cmd->rx_antenna_map = rx;
2180 cmd->tx_antenna_map = tx;
2181
2182 rc = mwl8k_post_cmd(hw, &cmd->header);
2183 kfree(cmd);
2184
2185 return rc;
2186}
2187
2188/*
2189 * CMD_ENABLE_SNIFFER.
2190 */
2191struct mwl8k_cmd_enable_sniffer {
2192 struct mwl8k_cmd_pkt header;
2193 __le32 action;
2194} __attribute__((packed));
2195
2196static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2197{
2198 struct mwl8k_cmd_enable_sniffer *cmd;
2199 int rc;
2200
2201 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2202 if (cmd == NULL)
2203 return -ENOMEM;
2204
2205 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2206 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002207 cmd->action = cpu_to_le32(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002208
2209 rc = mwl8k_post_cmd(hw, &cmd->header);
2210 kfree(cmd);
2211
2212 return rc;
2213}
2214
2215/*
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002216 * CMD_SET_MAC_ADDR.
2217 */
2218struct mwl8k_cmd_set_mac_addr {
2219 struct mwl8k_cmd_pkt header;
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002220 union {
2221 struct {
2222 __le16 mac_type;
2223 __u8 mac_addr[ETH_ALEN];
2224 } mbss;
2225 __u8 mac_addr[ETH_ALEN];
2226 };
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002227} __attribute__((packed));
2228
2229static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2230{
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002231 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002232 struct mwl8k_cmd_set_mac_addr *cmd;
2233 int rc;
2234
2235 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2236 if (cmd == NULL)
2237 return -ENOMEM;
2238
2239 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2240 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002241 if (priv->ap_fw) {
2242 cmd->mbss.mac_type = 0;
2243 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2244 } else {
2245 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2246 }
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002247
2248 rc = mwl8k_post_cmd(hw, &cmd->header);
2249 kfree(cmd);
2250
2251 return rc;
2252}
2253
2254
2255/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002256 * CMD_SET_RATEADAPT_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002257 */
2258struct mwl8k_cmd_set_rate_adapt_mode {
2259 struct mwl8k_cmd_pkt header;
2260 __le16 action;
2261 __le16 mode;
2262} __attribute__((packed));
2263
2264static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2265{
2266 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2267 int rc;
2268
2269 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2270 if (cmd == NULL)
2271 return -ENOMEM;
2272
2273 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2274 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2275 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2276 cmd->mode = cpu_to_le16(mode);
2277
2278 rc = mwl8k_post_cmd(hw, &cmd->header);
2279 kfree(cmd);
2280
2281 return rc;
2282}
2283
2284/*
2285 * CMD_SET_WMM_MODE.
2286 */
2287struct mwl8k_cmd_set_wmm {
2288 struct mwl8k_cmd_pkt header;
2289 __le16 action;
2290} __attribute__((packed));
2291
2292static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2293{
2294 struct mwl8k_priv *priv = hw->priv;
2295 struct mwl8k_cmd_set_wmm *cmd;
2296 int rc;
2297
2298 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2299 if (cmd == NULL)
2300 return -ENOMEM;
2301
2302 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2303 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002304 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002305
2306 rc = mwl8k_post_cmd(hw, &cmd->header);
2307 kfree(cmd);
2308
2309 if (!rc)
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002310 priv->wmm_enabled = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002311
2312 return rc;
2313}
2314
2315/*
2316 * CMD_SET_RTS_THRESHOLD.
2317 */
2318struct mwl8k_cmd_rts_threshold {
2319 struct mwl8k_cmd_pkt header;
2320 __le16 action;
2321 __le16 threshold;
2322} __attribute__((packed));
2323
2324static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002325 u16 action, u16 threshold)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002326{
2327 struct mwl8k_cmd_rts_threshold *cmd;
2328 int rc;
2329
2330 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2331 if (cmd == NULL)
2332 return -ENOMEM;
2333
2334 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2335 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2336 cmd->action = cpu_to_le16(action);
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002337 cmd->threshold = cpu_to_le16(threshold);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002338
2339 rc = mwl8k_post_cmd(hw, &cmd->header);
2340 kfree(cmd);
2341
2342 return rc;
2343}
2344
2345/*
2346 * CMD_SET_EDCA_PARAMS.
2347 */
2348struct mwl8k_cmd_set_edca_params {
2349 struct mwl8k_cmd_pkt header;
2350
2351 /* See MWL8K_SET_EDCA_XXX below */
2352 __le16 action;
2353
2354 /* TX opportunity in units of 32 us */
2355 __le16 txop;
2356
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002357 union {
2358 struct {
2359 /* Log exponent of max contention period: 0...15 */
2360 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002361
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002362 /* Log exponent of min contention period: 0...15 */
2363 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002364
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002365 /* Adaptive interframe spacing in units of 32us */
2366 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002367
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002368 /* TX queue to configure */
2369 __u8 txq;
2370 } ap;
2371 struct {
2372 /* Log exponent of max contention period: 0...15 */
2373 __u8 log_cw_max;
2374
2375 /* Log exponent of min contention period: 0...15 */
2376 __u8 log_cw_min;
2377
2378 /* Adaptive interframe spacing in units of 32us */
2379 __u8 aifs;
2380
2381 /* TX queue to configure */
2382 __u8 txq;
2383 } sta;
2384 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002385} __attribute__((packed));
2386
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002387#define MWL8K_SET_EDCA_CW 0x01
2388#define MWL8K_SET_EDCA_TXOP 0x02
2389#define MWL8K_SET_EDCA_AIFS 0x04
2390
2391#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2392 MWL8K_SET_EDCA_TXOP | \
2393 MWL8K_SET_EDCA_AIFS)
2394
2395static int
2396mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2397 __u16 cw_min, __u16 cw_max,
2398 __u8 aifs, __u16 txop)
2399{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002400 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002401 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002402 int rc;
2403
2404 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2405 if (cmd == NULL)
2406 return -ENOMEM;
2407
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002408 /*
2409 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2410 * this call.
2411 */
2412 qnum ^= !(qnum >> 1);
2413
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002414 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2415 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002416 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2417 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002418 if (priv->ap_fw) {
2419 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2420 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2421 cmd->ap.aifs = aifs;
2422 cmd->ap.txq = qnum;
2423 } else {
2424 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2425 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2426 cmd->sta.aifs = aifs;
2427 cmd->sta.txq = qnum;
2428 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002429
2430 rc = mwl8k_post_cmd(hw, &cmd->header);
2431 kfree(cmd);
2432
2433 return rc;
2434}
2435
2436/*
2437 * CMD_FINALIZE_JOIN.
2438 */
2439
2440/* FJ beacon buffer size is compiled into the firmware. */
2441#define MWL8K_FJ_BEACON_MAXLEN 128
2442
2443struct mwl8k_cmd_finalize_join {
2444 struct mwl8k_cmd_pkt header;
2445 __le32 sleep_interval; /* Number of beacon periods to sleep */
2446 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2447} __attribute__((packed));
2448
2449static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2450 __u16 framelen, __u16 dtim)
2451{
2452 struct mwl8k_cmd_finalize_join *cmd;
2453 struct ieee80211_mgmt *payload = frame;
2454 u16 hdrlen;
2455 u32 payload_len;
2456 int rc;
2457
2458 if (frame == NULL)
2459 return -EINVAL;
2460
2461 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2462 if (cmd == NULL)
2463 return -ENOMEM;
2464
2465 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2466 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002467 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002468
2469 hdrlen = ieee80211_hdrlen(payload->frame_control);
2470
2471 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2472
2473 /* XXX TBD Might just have to abort and return an error */
2474 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2475 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002476 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2477 payload_len, MWL8K_FJ_BEACON_MAXLEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002478
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002479 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2480 payload_len = MWL8K_FJ_BEACON_MAXLEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002481
2482 if (payload && payload_len)
2483 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2484
2485 rc = mwl8k_post_cmd(hw, &cmd->header);
2486 kfree(cmd);
2487 return rc;
2488}
2489
2490/*
2491 * CMD_UPDATE_STADB.
2492 */
2493struct mwl8k_cmd_update_sta_db {
2494 struct mwl8k_cmd_pkt header;
2495
2496 /* See STADB_ACTION_TYPE */
2497 __le32 action;
2498
2499 /* Peer MAC address */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002500 __u8 peer_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002501
2502 __le32 reserved;
2503
2504 /* Peer info - valid during add/update. */
2505 struct peer_capability_info peer_info;
2506} __attribute__((packed));
2507
2508static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2509 struct ieee80211_vif *vif, __u32 action)
2510{
2511 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2512 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2513 struct mwl8k_cmd_update_sta_db *cmd;
2514 struct peer_capability_info *peer_info;
2515 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002516 int rc;
2517 __u8 count, *rates;
2518
2519 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2520 if (cmd == NULL)
2521 return -ENOMEM;
2522
2523 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2524 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2525
2526 cmd->action = cpu_to_le32(action);
2527 peer_info = &cmd->peer_info;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002528 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002529
2530 switch (action) {
2531 case MWL8K_STA_DB_ADD_ENTRY:
2532 case MWL8K_STA_DB_MODIFY_ENTRY:
2533 /* Build peer_info block */
2534 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2535 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2536 peer_info->interop = 1;
2537 peer_info->amsdu_enabled = 0;
2538
2539 rates = peer_info->legacy_rates;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002540 for (count = 0; count < mv_vif->legacy_nrates; count++)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002541 rates[count] = bitrates[count].hw_value;
2542
2543 rc = mwl8k_post_cmd(hw, &cmd->header);
2544 if (rc == 0)
2545 mv_vif->peer_id = peer_info->station_id;
2546
2547 break;
2548
2549 case MWL8K_STA_DB_DEL_ENTRY:
2550 case MWL8K_STA_DB_FLUSH:
2551 default:
2552 rc = mwl8k_post_cmd(hw, &cmd->header);
2553 if (rc == 0)
2554 mv_vif->peer_id = 0;
2555 break;
2556 }
2557 kfree(cmd);
2558
2559 return rc;
2560}
2561
2562/*
2563 * CMD_SET_AID.
2564 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002565#define MWL8K_RATE_INDEX_MAX_ARRAY 14
2566
2567#define MWL8K_FRAME_PROT_DISABLED 0x00
2568#define MWL8K_FRAME_PROT_11G 0x07
2569#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2570#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002571
2572struct mwl8k_cmd_update_set_aid {
2573 struct mwl8k_cmd_pkt header;
2574 __le16 aid;
2575
2576 /* AP's MAC address (BSSID) */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002577 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002578 __le16 protection_mode;
2579 __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2580} __attribute__((packed));
2581
2582static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2583 struct ieee80211_vif *vif)
2584{
2585 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2586 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2587 struct mwl8k_cmd_update_set_aid *cmd;
2588 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2589 int count;
2590 u16 prot_mode;
2591 int rc;
2592
2593 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2594 if (cmd == NULL)
2595 return -ENOMEM;
2596
2597 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2598 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2599 cmd->aid = cpu_to_le16(info->aid);
2600
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002601 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002602
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002603 if (info->use_cts_prot) {
2604 prot_mode = MWL8K_FRAME_PROT_11G;
2605 } else {
Johannes Berg9ed6bcc2009-05-08 20:47:39 +02002606 switch (info->ht_operation_mode &
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002607 IEEE80211_HT_OP_MODE_PROTECTION) {
2608 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2609 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2610 break;
2611 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2612 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2613 break;
2614 default:
2615 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2616 break;
2617 }
2618 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002619 cmd->protection_mode = cpu_to_le16(prot_mode);
2620
2621 for (count = 0; count < mv_vif->legacy_nrates; count++)
2622 cmd->supp_rates[count] = bitrates[count].hw_value;
2623
2624 rc = mwl8k_post_cmd(hw, &cmd->header);
2625 kfree(cmd);
2626
2627 return rc;
2628}
2629
2630/*
2631 * CMD_SET_RATE.
2632 */
2633struct mwl8k_cmd_update_rateset {
2634 struct mwl8k_cmd_pkt header;
2635 __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
2636
2637 /* Bitmap for supported MCS codes. */
2638 __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
2639 __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
2640} __attribute__((packed));
2641
2642static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2643 struct ieee80211_vif *vif)
2644{
2645 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2646 struct mwl8k_cmd_update_rateset *cmd;
2647 struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
2648 int count;
2649 int rc;
2650
2651 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2652 if (cmd == NULL)
2653 return -ENOMEM;
2654
2655 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2656 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2657
2658 for (count = 0; count < mv_vif->legacy_nrates; count++)
2659 cmd->legacy_rates[count] = bitrates[count].hw_value;
2660
2661 rc = mwl8k_post_cmd(hw, &cmd->header);
2662 kfree(cmd);
2663
2664 return rc;
2665}
2666
2667/*
2668 * CMD_USE_FIXED_RATE.
2669 */
2670#define MWL8K_RATE_TABLE_SIZE 8
2671#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002672#define MWL8K_USE_AUTO_RATE 0x0002
2673
2674struct mwl8k_rate_entry {
2675 /* Set to 1 if HT rate, 0 if legacy. */
2676 __le32 is_ht_rate;
2677
2678 /* Set to 1 to use retry_count field. */
2679 __le32 enable_retry;
2680
2681 /* Specified legacy rate or MCS. */
2682 __le32 rate;
2683
2684 /* Number of allowed retries. */
2685 __le32 retry_count;
2686} __attribute__((packed));
2687
2688struct mwl8k_rate_table {
2689 /* 1 to allow specified rate and below */
2690 __le32 allow_rate_drop;
2691 __le32 num_rates;
2692 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2693} __attribute__((packed));
2694
2695struct mwl8k_cmd_use_fixed_rate {
2696 struct mwl8k_cmd_pkt header;
2697 __le32 action;
2698 struct mwl8k_rate_table rate_table;
2699
2700 /* Unicast, Broadcast or Multicast */
2701 __le32 rate_type;
2702 __le32 reserved1;
2703 __le32 reserved2;
2704} __attribute__((packed));
2705
2706static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2707 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2708{
2709 struct mwl8k_cmd_use_fixed_rate *cmd;
2710 int count;
2711 int rc;
2712
2713 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2714 if (cmd == NULL)
2715 return -ENOMEM;
2716
2717 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2718 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2719
2720 cmd->action = cpu_to_le32(action);
2721 cmd->rate_type = cpu_to_le32(rate_type);
2722
2723 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002724 /*
2725 * Copy over each field manually so that endian
2726 * conversion can be done.
2727 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002728 cmd->rate_table.allow_rate_drop =
2729 cpu_to_le32(rate_table->allow_rate_drop);
2730 cmd->rate_table.num_rates =
2731 cpu_to_le32(rate_table->num_rates);
2732
2733 for (count = 0; count < rate_table->num_rates; count++) {
2734 struct mwl8k_rate_entry *dst =
2735 &cmd->rate_table.rate_entry[count];
2736 struct mwl8k_rate_entry *src =
2737 &rate_table->rate_entry[count];
2738
2739 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2740 dst->enable_retry = cpu_to_le32(src->enable_retry);
2741 dst->rate = cpu_to_le32(src->rate);
2742 dst->retry_count = cpu_to_le32(src->retry_count);
2743 }
2744 }
2745
2746 rc = mwl8k_post_cmd(hw, &cmd->header);
2747 kfree(cmd);
2748
2749 return rc;
2750}
2751
2752
2753/*
2754 * Interrupt handling.
2755 */
2756static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2757{
2758 struct ieee80211_hw *hw = dev_id;
2759 struct mwl8k_priv *priv = hw->priv;
2760 u32 status;
2761
2762 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2763 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2764
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002765 if (!status)
2766 return IRQ_NONE;
2767
2768 if (status & MWL8K_A2H_INT_TX_DONE)
2769 tasklet_schedule(&priv->tx_reclaim_task);
2770
2771 if (status & MWL8K_A2H_INT_RX_READY) {
2772 while (rxq_process(hw, 0, 1))
2773 rxq_refill(hw, 0, 1);
2774 }
2775
2776 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002777 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002778 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002779 }
2780
2781 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002782 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002783 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002784 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002785 }
2786
2787 return IRQ_HANDLED;
2788}
2789
2790
2791/*
2792 * Core driver operations.
2793 */
2794static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2795{
2796 struct mwl8k_priv *priv = hw->priv;
2797 int index = skb_get_queue_mapping(skb);
2798 int rc;
2799
2800 if (priv->current_channel == NULL) {
2801 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002802 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002803 dev_kfree_skb(skb);
2804 return NETDEV_TX_OK;
2805 }
2806
2807 rc = mwl8k_txq_xmit(hw, index, skb);
2808
2809 return rc;
2810}
2811
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002812static int mwl8k_start(struct ieee80211_hw *hw)
2813{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002814 struct mwl8k_priv *priv = hw->priv;
2815 int rc;
2816
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002817 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
2818 IRQF_SHARED, MWL8K_NAME, hw);
2819 if (rc) {
2820 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002821 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002822 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002823 }
2824
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002825 /* Enable tx reclaim tasklet */
2826 tasklet_enable(&priv->tx_reclaim_task);
2827
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002828 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002829 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002830
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002831 rc = mwl8k_fw_lock(hw);
2832 if (!rc) {
2833 rc = mwl8k_cmd_802_11_radio_enable(hw);
2834
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002835 if (!priv->ap_fw) {
2836 if (!rc)
2837 rc = mwl8k_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002838
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002839 if (!rc)
2840 rc = mwl8k_cmd_set_pre_scan(hw);
2841
2842 if (!rc)
2843 rc = mwl8k_cmd_set_post_scan(hw,
2844 "\x00\x00\x00\x00\x00\x00");
2845 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002846
2847 if (!rc)
2848 rc = mwl8k_cmd_setrateadaptmode(hw, 0);
2849
2850 if (!rc)
2851 rc = mwl8k_set_wmm(hw, 0);
2852
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002853 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002854 }
2855
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002856 if (rc) {
2857 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2858 free_irq(priv->pdev->irq, hw);
2859 tasklet_disable(&priv->tx_reclaim_task);
2860 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002861
2862 return rc;
2863}
2864
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002865static void mwl8k_stop(struct ieee80211_hw *hw)
2866{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002867 struct mwl8k_priv *priv = hw->priv;
2868 int i;
2869
Lennert Buytenhekd3cea0b2009-07-17 07:15:49 +02002870 mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002871
2872 ieee80211_stop_queues(hw);
2873
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002874 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002875 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002876 free_irq(priv->pdev->irq, hw);
2877
2878 /* Stop finalize join worker */
2879 cancel_work_sync(&priv->finalize_join_worker);
2880 if (priv->beacon_skb != NULL)
2881 dev_kfree_skb(priv->beacon_skb);
2882
2883 /* Stop tx reclaim tasklet */
2884 tasklet_disable(&priv->tx_reclaim_task);
2885
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002886 /* Return all skbs to mac80211 */
2887 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2888 mwl8k_txq_reclaim(hw, i, 1);
2889}
2890
2891static int mwl8k_add_interface(struct ieee80211_hw *hw,
2892 struct ieee80211_if_init_conf *conf)
2893{
2894 struct mwl8k_priv *priv = hw->priv;
2895 struct mwl8k_vif *mwl8k_vif;
2896
2897 /*
2898 * We only support one active interface at a time.
2899 */
2900 if (priv->vif != NULL)
2901 return -EBUSY;
2902
2903 /*
2904 * We only support managed interfaces for now.
2905 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002906 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002907 return -EINVAL;
2908
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002909 /*
2910 * Reject interface creation if sniffer mode is active, as
2911 * STA operation is mutually exclusive with hardware sniffer
2912 * mode.
2913 */
2914 if (priv->sniffer_enabled) {
2915 printk(KERN_INFO "%s: unable to create STA "
2916 "interface due to sniffer mode being enabled\n",
2917 wiphy_name(hw->wiphy));
2918 return -EINVAL;
2919 }
2920
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002921 /* Clean out driver private area */
2922 mwl8k_vif = MWL8K_VIF(conf->vif);
2923 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2924
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002925 /* Set and save the mac address */
2926 mwl8k_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002927 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002928
2929 /* Back pointer to parent config block */
2930 mwl8k_vif->priv = priv;
2931
2932 /* Setup initial PHY parameters */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002933 memcpy(mwl8k_vif->legacy_rates,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002934 priv->rates, sizeof(mwl8k_vif->legacy_rates));
2935 mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
2936
2937 /* Set Initial sequence number to zero */
2938 mwl8k_vif->seqno = 0;
2939
2940 priv->vif = conf->vif;
2941 priv->current_channel = NULL;
2942
2943 return 0;
2944}
2945
2946static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2947 struct ieee80211_if_init_conf *conf)
2948{
2949 struct mwl8k_priv *priv = hw->priv;
2950
2951 if (priv->vif == NULL)
2952 return;
2953
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002954 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
2955
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002956 priv->vif = NULL;
2957}
2958
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002959static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002960{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002961 struct ieee80211_conf *conf = &hw->conf;
2962 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002963 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002964
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002965 if (conf->flags & IEEE80211_CONF_IDLE) {
2966 mwl8k_cmd_802_11_radio_disable(hw);
2967 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002968 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002969 }
2970
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002971 rc = mwl8k_fw_lock(hw);
2972 if (rc)
2973 return rc;
2974
2975 rc = mwl8k_cmd_802_11_radio_enable(hw);
2976 if (rc)
2977 goto out;
2978
2979 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2980 if (rc)
2981 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002982
2983 priv->current_channel = conf->channel;
2984
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002985 if (conf->power_level > 18)
2986 conf->power_level = 18;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002987 rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level);
2988 if (rc)
2989 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002990
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002991 if (priv->ap_fw) {
2992 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2993 if (!rc)
2994 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2995 } else {
2996 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2997 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002998
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002999out:
3000 mwl8k_fw_unlock(hw);
3001
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003002 return rc;
3003}
3004
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003005static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3006 struct ieee80211_vif *vif,
3007 struct ieee80211_bss_conf *info,
3008 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003009{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003010 struct mwl8k_priv *priv = hw->priv;
3011 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003012 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003013
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003014 if (changed & BSS_CHANGED_BSSID)
3015 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
3016
3017 if ((changed & BSS_CHANGED_ASSOC) == 0)
3018 return;
3019
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003020 priv->capture_beacon = false;
3021
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003022 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02003023 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003024 return;
3025
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003026 if (info->assoc) {
3027 memcpy(&mwl8k_vif->bss_info, info,
3028 sizeof(struct ieee80211_bss_conf));
3029
3030 /* Install rates */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003031 rc = mwl8k_update_rateset(hw, vif);
3032 if (rc)
3033 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003034
3035 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003036 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3037 MWL8K_UCAST_RATE, NULL);
3038 if (rc)
3039 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003040
3041 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003042 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
3043 if (rc)
3044 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003045
3046 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003047 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
3048 if (rc)
3049 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003050
3051 /* Update peer rate info */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003052 rc = mwl8k_cmd_update_sta_db(hw, vif,
3053 MWL8K_STA_DB_MODIFY_ENTRY);
3054 if (rc)
3055 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003056
3057 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003058 rc = mwl8k_cmd_set_aid(hw, vif);
3059 if (rc)
3060 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003061
3062 /*
3063 * Finalize the join. Tell rx handler to process
3064 * next beacon from our BSSID.
3065 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003066 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003067 priv->capture_beacon = true;
3068 } else {
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003069 rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003070 memset(&mwl8k_vif->bss_info, 0,
3071 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003072 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003073 }
3074
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003075out:
3076 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003077}
3078
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003079static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3080 int mc_count, struct dev_addr_list *mclist)
3081{
3082 struct mwl8k_cmd_pkt *cmd;
3083
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003084 /*
3085 * Synthesize and return a command packet that programs the
3086 * hardware multicast address filter. At this point we don't
3087 * know whether FIF_ALLMULTI is being requested, but if it is,
3088 * we'll end up throwing this packet away and creating a new
3089 * one in mwl8k_configure_filter().
3090 */
3091 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003092
3093 return (unsigned long)cmd;
3094}
3095
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003096static int
3097mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3098 unsigned int changed_flags,
3099 unsigned int *total_flags)
3100{
3101 struct mwl8k_priv *priv = hw->priv;
3102
3103 /*
3104 * Hardware sniffer mode is mutually exclusive with STA
3105 * operation, so refuse to enable sniffer mode if a STA
3106 * interface is active.
3107 */
3108 if (priv->vif != NULL) {
3109 if (net_ratelimit())
3110 printk(KERN_INFO "%s: not enabling sniffer "
3111 "mode because STA interface is active\n",
3112 wiphy_name(hw->wiphy));
3113 return 0;
3114 }
3115
3116 if (!priv->sniffer_enabled) {
3117 if (mwl8k_enable_sniffer(hw, 1))
3118 return 0;
3119 priv->sniffer_enabled = true;
3120 }
3121
3122 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3123 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3124 FIF_OTHER_BSS;
3125
3126 return 1;
3127}
3128
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003129static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3130 unsigned int changed_flags,
3131 unsigned int *total_flags,
3132 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003133{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003134 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003135 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3136
3137 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003138 * AP firmware doesn't allow fine-grained control over
3139 * the receive filter.
3140 */
3141 if (priv->ap_fw) {
3142 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3143 kfree(cmd);
3144 return;
3145 }
3146
3147 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003148 * Enable hardware sniffer mode if FIF_CONTROL or
3149 * FIF_OTHER_BSS is requested.
3150 */
3151 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3152 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3153 kfree(cmd);
3154 return;
3155 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003156
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003157 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003158 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003159
3160 if (mwl8k_fw_lock(hw))
3161 return;
3162
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003163 if (priv->sniffer_enabled) {
3164 mwl8k_enable_sniffer(hw, 0);
3165 priv->sniffer_enabled = false;
3166 }
3167
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003168 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003169 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3170 /*
3171 * Disable the BSS filter.
3172 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003173 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003174 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003175 u8 *bssid;
3176
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003177 /*
3178 * Enable the BSS filter.
3179 *
3180 * If there is an active STA interface, use that
3181 * interface's BSSID, otherwise use a dummy one
3182 * (where the OUI part needs to be nonzero for
3183 * the BSSID to be accepted by POST_SCAN).
3184 */
3185 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003186 if (priv->vif != NULL)
3187 bssid = MWL8K_VIF(priv->vif)->bssid;
3188
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003189 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003190 }
3191 }
3192
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003193 /*
3194 * If FIF_ALLMULTI is being requested, throw away the command
3195 * packet that ->prepare_multicast() built and replace it with
3196 * a command packet that enables reception of all multicast
3197 * packets.
3198 */
3199 if (*total_flags & FIF_ALLMULTI) {
3200 kfree(cmd);
3201 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3202 }
3203
3204 if (cmd != NULL) {
3205 mwl8k_post_cmd(hw, cmd);
3206 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003207 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003208
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003209 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003210}
3211
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003212static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3213{
Lennert Buytenhek733d3062009-07-17 07:24:15 +02003214 return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003215}
3216
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003217static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3218 const struct ieee80211_tx_queue_params *params)
3219{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003220 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003221 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003222
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003223 rc = mwl8k_fw_lock(hw);
3224 if (!rc) {
3225 if (!priv->wmm_enabled)
3226 rc = mwl8k_set_wmm(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003227
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003228 if (!rc)
3229 rc = mwl8k_set_edca_params(hw, queue,
3230 params->cw_min,
3231 params->cw_max,
3232 params->aifs,
3233 params->txop);
3234
3235 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003236 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003237
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003238 return rc;
3239}
3240
3241static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3242 struct ieee80211_tx_queue_stats *stats)
3243{
3244 struct mwl8k_priv *priv = hw->priv;
3245 struct mwl8k_tx_queue *txq;
3246 int index;
3247
3248 spin_lock_bh(&priv->tx_lock);
3249 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3250 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003251 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003252 sizeof(struct ieee80211_tx_queue_stats));
3253 }
3254 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003255
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003256 return 0;
3257}
3258
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003259static int mwl8k_get_stats(struct ieee80211_hw *hw,
3260 struct ieee80211_low_level_stats *stats)
3261{
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003262 return mwl8k_cmd_802_11_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003263}
3264
3265static const struct ieee80211_ops mwl8k_ops = {
3266 .tx = mwl8k_tx,
3267 .start = mwl8k_start,
3268 .stop = mwl8k_stop,
3269 .add_interface = mwl8k_add_interface,
3270 .remove_interface = mwl8k_remove_interface,
3271 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003272 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003273 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003274 .configure_filter = mwl8k_configure_filter,
3275 .set_rts_threshold = mwl8k_set_rts_threshold,
3276 .conf_tx = mwl8k_conf_tx,
3277 .get_tx_stats = mwl8k_get_tx_stats,
3278 .get_stats = mwl8k_get_stats,
3279};
3280
3281static void mwl8k_tx_reclaim_handler(unsigned long data)
3282{
3283 int i;
3284 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3285 struct mwl8k_priv *priv = hw->priv;
3286
3287 spin_lock_bh(&priv->tx_lock);
3288 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3289 mwl8k_txq_reclaim(hw, i, 0);
3290
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003291 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003292 complete(priv->tx_wait);
3293 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003294 }
3295 spin_unlock_bh(&priv->tx_lock);
3296}
3297
3298static void mwl8k_finalize_join_worker(struct work_struct *work)
3299{
3300 struct mwl8k_priv *priv =
3301 container_of(work, struct mwl8k_priv, finalize_join_worker);
3302 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003303 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003304
3305 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3306 dev_kfree_skb(skb);
3307
3308 priv->beacon_skb = NULL;
3309}
3310
John W. Linvillebcb628d2009-11-06 16:40:16 -05003311enum {
3312 MWL8687 = 0,
3313 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003314};
3315
John W. Linvillebcb628d2009-11-06 16:40:16 -05003316static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3317 {
3318 .part_name = "88w8687",
3319 .helper_image = "mwl8k/helper_8687.fw",
3320 .fw_image = "mwl8k/fmimage_8687.fw",
3321 .rxd_ops = &rxd_8687_ops,
3322 .modes = BIT(NL80211_IFTYPE_STATION),
3323 },
3324 {
3325 .part_name = "88w8366",
3326 .helper_image = "mwl8k/helper_8366.fw",
3327 .fw_image = "mwl8k/fmimage_8366.fw",
3328 .rxd_ops = &rxd_8366_ops,
3329 .modes = 0,
3330 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003331};
3332
3333static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003334 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3335 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3336 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3337 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003338};
3339MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3340
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003341static int __devinit mwl8k_probe(struct pci_dev *pdev,
3342 const struct pci_device_id *id)
3343{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003344 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003345 struct ieee80211_hw *hw;
3346 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003347 int rc;
3348 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003349
3350 if (!printed_version) {
3351 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3352 printed_version = 1;
3353 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003354
3355 rc = pci_enable_device(pdev);
3356 if (rc) {
3357 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3358 MWL8K_NAME);
3359 return rc;
3360 }
3361
3362 rc = pci_request_regions(pdev, MWL8K_NAME);
3363 if (rc) {
3364 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3365 MWL8K_NAME);
3366 return rc;
3367 }
3368
3369 pci_set_master(pdev);
3370
3371 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3372 if (hw == NULL) {
3373 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3374 rc = -ENOMEM;
3375 goto err_free_reg;
3376 }
3377
3378 priv = hw->priv;
3379 priv->hw = hw;
3380 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003381 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02003382 priv->rxd_ops = priv->device_info->rxd_ops;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003383 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02003384 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003385 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003386
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003387 SET_IEEE80211_DEV(hw, &pdev->dev);
3388 pci_set_drvdata(pdev, hw);
3389
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003390 priv->sram = pci_iomap(pdev, 0, 0x10000);
3391 if (priv->sram == NULL) {
3392 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003393 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003394 goto err_iounmap;
3395 }
3396
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003397 /*
3398 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3399 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3400 */
3401 priv->regs = pci_iomap(pdev, 1, 0x10000);
3402 if (priv->regs == NULL) {
3403 priv->regs = pci_iomap(pdev, 2, 0x10000);
3404 if (priv->regs == NULL) {
3405 printk(KERN_ERR "%s: Cannot map device registers\n",
3406 wiphy_name(hw->wiphy));
3407 goto err_iounmap;
3408 }
3409 }
3410
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003411 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3412 priv->band.band = IEEE80211_BAND_2GHZ;
3413 priv->band.channels = priv->channels;
3414 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3415 priv->band.bitrates = priv->rates;
3416 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3417 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3418
3419 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3420 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3421
3422 /*
3423 * Extra headroom is the size of the required DMA header
3424 * minus the size of the smallest 802.11 frame (CTS frame).
3425 */
3426 hw->extra_tx_headroom =
3427 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3428
3429 hw->channel_change_time = 10;
3430
3431 hw->queues = MWL8K_TX_QUEUES;
3432
Lennert Buytenhek547810e2009-10-22 20:21:02 +02003433 hw->wiphy->interface_modes = priv->device_info->modes;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003434
3435 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003436 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003437 hw->vif_data_size = sizeof(struct mwl8k_vif);
3438 priv->vif = NULL;
3439
3440 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003441 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003442 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003443
3444 /* Finalize join worker */
3445 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3446
3447 /* TX reclaim tasklet */
3448 tasklet_init(&priv->tx_reclaim_task,
3449 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3450 tasklet_disable(&priv->tx_reclaim_task);
3451
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003452 /* Power management cookie */
3453 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3454 if (priv->cookie == NULL)
3455 goto err_iounmap;
3456
3457 rc = mwl8k_rxq_init(hw, 0);
3458 if (rc)
3459 goto err_iounmap;
3460 rxq_refill(hw, 0, INT_MAX);
3461
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003462 mutex_init(&priv->fw_mutex);
3463 priv->fw_mutex_owner = NULL;
3464 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003465 priv->hostcmd_wait = NULL;
3466
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003467 spin_lock_init(&priv->tx_lock);
3468
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003469 priv->tx_wait = NULL;
3470
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003471 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3472 rc = mwl8k_txq_init(hw, i);
3473 if (rc)
3474 goto err_free_queues;
3475 }
3476
3477 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003478 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003479 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3480 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3481
3482 rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
3483 IRQF_SHARED, MWL8K_NAME, hw);
3484 if (rc) {
3485 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003486 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003487 goto err_free_queues;
3488 }
3489
3490 /* Reset firmware and hardware */
3491 mwl8k_hw_reset(priv);
3492
3493 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003494 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003495 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003496 printk(KERN_ERR "%s: Firmware files not found\n",
3497 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003498 goto err_free_irq;
3499 }
3500
3501 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003502 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003503 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003504 printk(KERN_ERR "%s: Cannot start firmware\n",
3505 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003506 goto err_stop_firmware;
3507 }
3508
3509 /* Reclaim memory once firmware is successfully loaded */
3510 mwl8k_release_firmware(priv);
3511
3512 /*
3513 * Temporarily enable interrupts. Initial firmware host
3514 * commands use interrupts and avoids polling. Disable
3515 * interrupts when done.
3516 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003517 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003518
3519 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02003520 if (priv->ap_fw) {
3521 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3522 if (!rc)
3523 rc = mwl8k_cmd_set_hw_spec(hw);
3524 } else {
3525 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3526 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003527 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003528 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3529 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003530 goto err_stop_firmware;
3531 }
3532
3533 /* Turn radio off */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003534 rc = mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003535 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003536 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003537 goto err_stop_firmware;
3538 }
3539
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003540 /* Clear MAC address */
3541 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3542 if (rc) {
3543 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3544 wiphy_name(hw->wiphy));
3545 goto err_stop_firmware;
3546 }
3547
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003548 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003549 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003550 free_irq(priv->pdev->irq, hw);
3551
3552 rc = ieee80211_register_hw(hw);
3553 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003554 printk(KERN_ERR "%s: Cannot register device\n",
3555 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003556 goto err_stop_firmware;
3557 }
3558
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003559 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003560 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003561 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003562 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003563 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3564 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003565
3566 return 0;
3567
3568err_stop_firmware:
3569 mwl8k_hw_reset(priv);
3570 mwl8k_release_firmware(priv);
3571
3572err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003573 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003574 free_irq(priv->pdev->irq, hw);
3575
3576err_free_queues:
3577 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3578 mwl8k_txq_deinit(hw, i);
3579 mwl8k_rxq_deinit(hw, 0);
3580
3581err_iounmap:
3582 if (priv->cookie != NULL)
3583 pci_free_consistent(priv->pdev, 4,
3584 priv->cookie, priv->cookie_dma);
3585
3586 if (priv->regs != NULL)
3587 pci_iounmap(pdev, priv->regs);
3588
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003589 if (priv->sram != NULL)
3590 pci_iounmap(pdev, priv->sram);
3591
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003592 pci_set_drvdata(pdev, NULL);
3593 ieee80211_free_hw(hw);
3594
3595err_free_reg:
3596 pci_release_regions(pdev);
3597 pci_disable_device(pdev);
3598
3599 return rc;
3600}
3601
Joerg Albert230f7af2009-04-18 02:10:45 +02003602static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003603{
3604 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3605}
3606
Joerg Albert230f7af2009-04-18 02:10:45 +02003607static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003608{
3609 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3610 struct mwl8k_priv *priv;
3611 int i;
3612
3613 if (hw == NULL)
3614 return;
3615 priv = hw->priv;
3616
3617 ieee80211_stop_queues(hw);
3618
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003619 ieee80211_unregister_hw(hw);
3620
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003621 /* Remove tx reclaim tasklet */
3622 tasklet_kill(&priv->tx_reclaim_task);
3623
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003624 /* Stop hardware */
3625 mwl8k_hw_reset(priv);
3626
3627 /* Return all skbs to mac80211 */
3628 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3629 mwl8k_txq_reclaim(hw, i, 1);
3630
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003631 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3632 mwl8k_txq_deinit(hw, i);
3633
3634 mwl8k_rxq_deinit(hw, 0);
3635
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003636 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003637
3638 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003639 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003640 pci_set_drvdata(pdev, NULL);
3641 ieee80211_free_hw(hw);
3642 pci_release_regions(pdev);
3643 pci_disable_device(pdev);
3644}
3645
3646static struct pci_driver mwl8k_driver = {
3647 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003648 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003649 .probe = mwl8k_probe,
3650 .remove = __devexit_p(mwl8k_remove),
3651 .shutdown = __devexit_p(mwl8k_shutdown),
3652};
3653
3654static int __init mwl8k_init(void)
3655{
3656 return pci_register_driver(&mwl8k_driver);
3657}
3658
3659static void __exit mwl8k_exit(void)
3660{
3661 pci_unregister_driver(&mwl8k_driver);
3662}
3663
3664module_init(mwl8k_init);
3665module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003666
3667MODULE_DESCRIPTION(MWL8K_DESC);
3668MODULE_VERSION(MWL8K_VERSION);
3669MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3670MODULE_LICENSE("GPL");