blob: 0251b6144f57bef806fee6ffd9c9e67197b9505d [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 Buytenhek140eb5e2009-11-30 18:11:44 +0100187 struct ieee80211_rate rates[14];
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
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100223 /* Index into station database.Returned by update_sta_db call */
224 u8 peer_id;
225
226 /* Non AMPDU sequence number assigned by driver */
227 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100228};
229
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200230#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100231
232static const struct ieee80211_channel mwl8k_channels[] = {
233 { .center_freq = 2412, .hw_value = 1, },
234 { .center_freq = 2417, .hw_value = 2, },
235 { .center_freq = 2422, .hw_value = 3, },
236 { .center_freq = 2427, .hw_value = 4, },
237 { .center_freq = 2432, .hw_value = 5, },
238 { .center_freq = 2437, .hw_value = 6, },
239 { .center_freq = 2442, .hw_value = 7, },
240 { .center_freq = 2447, .hw_value = 8, },
241 { .center_freq = 2452, .hw_value = 9, },
242 { .center_freq = 2457, .hw_value = 10, },
243 { .center_freq = 2462, .hw_value = 11, },
244};
245
246static const struct ieee80211_rate mwl8k_rates[] = {
247 { .bitrate = 10, .hw_value = 2, },
248 { .bitrate = 20, .hw_value = 4, },
249 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200250 { .bitrate = 110, .hw_value = 22, },
251 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100252 { .bitrate = 60, .hw_value = 12, },
253 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100254 { .bitrate = 120, .hw_value = 24, },
255 { .bitrate = 180, .hw_value = 36, },
256 { .bitrate = 240, .hw_value = 48, },
257 { .bitrate = 360, .hw_value = 72, },
258 { .bitrate = 480, .hw_value = 96, },
259 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100260 { .bitrate = 720, .hw_value = 144, },
261};
262
263static const u8 mwl8k_rateids[12] = {
264 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108,
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100265};
266
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100267/* Set or get info from Firmware */
268#define MWL8K_CMD_SET 0x0001
269#define MWL8K_CMD_GET 0x0000
270
271/* Firmware command codes */
272#define MWL8K_CMD_CODE_DNLD 0x0001
273#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200274#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100275#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
276#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200277#define MWL8K_CMD_RADIO_CONTROL 0x001c
278#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200279#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100280#define MWL8K_CMD_SET_PRE_SCAN 0x0107
281#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200282#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100283#define MWL8K_CMD_SET_AID 0x010d
284#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200285#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100286#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200287#define MWL8K_CMD_SET_SLOT 0x0114
288#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
289#define MWL8K_CMD_SET_WMM_MODE 0x0123
290#define MWL8K_CMD_MIMO_CONFIG 0x0125
291#define MWL8K_CMD_USE_FIXED_RATE 0x0126
292#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200293#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200294#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
295#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100296
297static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
298{
299#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
300 snprintf(buf, bufsize, "%s", #x);\
301 return buf;\
302 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200303 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100304 MWL8K_CMDNAME(CODE_DNLD);
305 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200306 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100307 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
308 MWL8K_CMDNAME(GET_STAT);
309 MWL8K_CMDNAME(RADIO_CONTROL);
310 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200311 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100312 MWL8K_CMDNAME(SET_PRE_SCAN);
313 MWL8K_CMDNAME(SET_POST_SCAN);
314 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100315 MWL8K_CMDNAME(SET_AID);
316 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200317 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100318 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200319 MWL8K_CMDNAME(SET_SLOT);
320 MWL8K_CMDNAME(SET_EDCA_PARAMS);
321 MWL8K_CMDNAME(SET_WMM_MODE);
322 MWL8K_CMDNAME(MIMO_CONFIG);
323 MWL8K_CMDNAME(USE_FIXED_RATE);
324 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200325 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200326 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
327 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100328 default:
329 snprintf(buf, bufsize, "0x%x", cmd);
330 }
331#undef MWL8K_CMDNAME
332
333 return buf;
334}
335
336/* Hardware and firmware reset */
337static void mwl8k_hw_reset(struct mwl8k_priv *priv)
338{
339 iowrite32(MWL8K_H2A_INT_RESET,
340 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
341 iowrite32(MWL8K_H2A_INT_RESET,
342 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
343 msleep(20);
344}
345
346/* Release fw image */
347static void mwl8k_release_fw(struct firmware **fw)
348{
349 if (*fw == NULL)
350 return;
351 release_firmware(*fw);
352 *fw = NULL;
353}
354
355static void mwl8k_release_firmware(struct mwl8k_priv *priv)
356{
357 mwl8k_release_fw(&priv->fw.ucode);
358 mwl8k_release_fw(&priv->fw.helper);
359}
360
361/* Request fw image */
362static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200363 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100364{
365 /* release current image */
366 if (*fw != NULL)
367 mwl8k_release_fw(fw);
368
369 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200370 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100371}
372
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200373static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100374{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200375 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100376 int rc;
377
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200378 if (di->helper_image != NULL) {
379 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
380 if (rc) {
381 printk(KERN_ERR "%s: Error requesting helper "
382 "firmware file %s\n", pci_name(priv->pdev),
383 di->helper_image);
384 return rc;
385 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100386 }
387
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200388 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100389 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200390 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200391 pci_name(priv->pdev), di->fw_image);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100392 mwl8k_release_fw(&priv->fw.helper);
393 return rc;
394 }
395
396 return 0;
397}
398
Ben Hutchings7e75b942009-11-07 22:00:57 +0000399MODULE_FIRMWARE("mwl8k/helper_8687.fw");
400MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
401
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100402struct mwl8k_cmd_pkt {
403 __le16 code;
404 __le16 length;
405 __le16 seq_num;
406 __le16 result;
407 char payload[0];
408} __attribute__((packed));
409
410/*
411 * Firmware loading.
412 */
413static int
414mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
415{
416 void __iomem *regs = priv->regs;
417 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100418 int loops;
419
420 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
421 if (pci_dma_mapping_error(priv->pdev, dma_addr))
422 return -ENOMEM;
423
424 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
425 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
426 iowrite32(MWL8K_H2A_INT_DOORBELL,
427 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
428 iowrite32(MWL8K_H2A_INT_DUMMY,
429 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
430
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100431 loops = 1000;
432 do {
433 u32 int_code;
434
435 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
436 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
437 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100438 break;
439 }
440
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200441 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100442 udelay(1);
443 } while (--loops);
444
445 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
446
Lennert Buytenhekd4b705702009-07-16 12:44:45 +0200447 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100448}
449
450static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
451 const u8 *data, size_t length)
452{
453 struct mwl8k_cmd_pkt *cmd;
454 int done;
455 int rc = 0;
456
457 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
458 if (cmd == NULL)
459 return -ENOMEM;
460
461 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
462 cmd->seq_num = 0;
463 cmd->result = 0;
464
465 done = 0;
466 while (length) {
467 int block_size = length > 256 ? 256 : length;
468
469 memcpy(cmd->payload, data + done, block_size);
470 cmd->length = cpu_to_le16(block_size);
471
472 rc = mwl8k_send_fw_load_cmd(priv, cmd,
473 sizeof(*cmd) + block_size);
474 if (rc)
475 break;
476
477 done += block_size;
478 length -= block_size;
479 }
480
481 if (!rc) {
482 cmd->length = 0;
483 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
484 }
485
486 kfree(cmd);
487
488 return rc;
489}
490
491static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
492 const u8 *data, size_t length)
493{
494 unsigned char *buffer;
495 int may_continue, rc = 0;
496 u32 done, prev_block_size;
497
498 buffer = kmalloc(1024, GFP_KERNEL);
499 if (buffer == NULL)
500 return -ENOMEM;
501
502 done = 0;
503 prev_block_size = 0;
504 may_continue = 1000;
505 while (may_continue > 0) {
506 u32 block_size;
507
508 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
509 if (block_size & 1) {
510 block_size &= ~1;
511 may_continue--;
512 } else {
513 done += prev_block_size;
514 length -= prev_block_size;
515 }
516
517 if (block_size > 1024 || block_size > length) {
518 rc = -EOVERFLOW;
519 break;
520 }
521
522 if (length == 0) {
523 rc = 0;
524 break;
525 }
526
527 if (block_size == 0) {
528 rc = -EPROTO;
529 may_continue--;
530 udelay(1);
531 continue;
532 }
533
534 prev_block_size = block_size;
535 memcpy(buffer, data + done, block_size);
536
537 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
538 if (rc)
539 break;
540 }
541
542 if (!rc && length != 0)
543 rc = -EREMOTEIO;
544
545 kfree(buffer);
546
547 return rc;
548}
549
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200550static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100551{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200552 struct mwl8k_priv *priv = hw->priv;
553 struct firmware *fw = priv->fw.ucode;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200554 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200555 int rc;
556 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100557
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200558 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
559 struct firmware *helper = priv->fw.helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100560
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200561 if (helper == NULL) {
562 printk(KERN_ERR "%s: helper image needed but none "
563 "given\n", pci_name(priv->pdev));
564 return -EINVAL;
565 }
566
567 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100568 if (rc) {
569 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200570 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100571 return rc;
572 }
573 msleep(1);
574
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200575 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100576 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200577 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100578 }
579
580 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200581 printk(KERN_ERR "%s: unable to load firmware image\n",
582 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100583 return rc;
584 }
585
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200586 if (di->modes & BIT(NL80211_IFTYPE_AP))
587 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
588 else
589 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100590 msleep(1);
591
592 loops = 200000;
593 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200594 u32 ready_code;
595
596 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
597 if (ready_code == MWL8K_FWAP_READY) {
598 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100599 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200600 } else if (ready_code == MWL8K_FWSTA_READY) {
601 priv->ap_fw = 0;
602 break;
603 }
604
605 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100606 udelay(1);
607 } while (--loops);
608
609 return loops ? 0 : -ETIMEDOUT;
610}
611
612
613/*
614 * Defines shared between transmission and reception.
615 */
616/* HT control fields for firmware */
617struct ewc_ht_info {
618 __le16 control1;
619 __le16 control2;
620 __le16 control3;
621} __attribute__((packed));
622
623/* Firmware Station database operations */
624#define MWL8K_STA_DB_ADD_ENTRY 0
625#define MWL8K_STA_DB_MODIFY_ENTRY 1
626#define MWL8K_STA_DB_DEL_ENTRY 2
627#define MWL8K_STA_DB_FLUSH 3
628
629/* Peer Entry flags - used to define the type of the peer node */
630#define MWL8K_PEER_TYPE_ACCESSPOINT 2
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100631
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100632struct peer_capability_info {
633 /* Peer type - AP vs. STA. */
634 __u8 peer_type;
635
636 /* Basic 802.11 capabilities from assoc resp. */
637 __le16 basic_caps;
638
639 /* Set if peer supports 802.11n high throughput (HT). */
640 __u8 ht_support;
641
642 /* Valid if HT is supported. */
643 __le16 ht_caps;
644 __u8 extended_ht_caps;
645 struct ewc_ht_info ewc_info;
646
647 /* Legacy rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100648 __u8 legacy_rates[12];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100649
650 /* HT rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek0b5351a2009-11-30 18:11:18 +0100651 __u8 ht_rates[16];
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +0200652 __u8 pad[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100653
654 /* If set, interoperability mode, no proprietary extensions. */
655 __u8 interop;
656 __u8 pad2;
657 __u8 station_id;
658 __le16 amsdu_enabled;
659} __attribute__((packed));
660
661/* Inline functions to manipulate QoS field in data descriptor. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100662static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
663{
664 u16 val_mask = 1 << 4;
665
666 /* End of Service Period Bit 4 */
667 return qos | val_mask;
668}
669
670static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
671{
672 u16 val_mask = 0x3;
673 u8 shift = 5;
674 u16 qos_mask = ~(val_mask << shift);
675
676 /* Ack Policy Bit 5-6 */
677 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
678}
679
680static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
681{
682 u16 val_mask = 1 << 7;
683
684 /* AMSDU present Bit 7 */
685 return qos | val_mask;
686}
687
688static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
689{
690 u16 val_mask = 0xff;
691 u8 shift = 8;
692 u16 qos_mask = ~(val_mask << shift);
693
694 /* Queue Length Bits 8-15 */
695 return (qos & qos_mask) | ((len & val_mask) << shift);
696}
697
698/* DMA header used by firmware and hardware. */
699struct mwl8k_dma_data {
700 __le16 fwlen;
701 struct ieee80211_hdr wh;
702} __attribute__((packed));
703
704/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200705static inline void mwl8k_remove_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100706{
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200707 struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)skb->data;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100708 void *dst, *src = &tr->wh;
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200709 int hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100710 u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
711
712 dst = (void *)tr + space;
713 if (dst != src) {
714 memmove(dst, src, hdrlen);
715 skb_pull(skb, space);
716 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100717}
718
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200719static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100720{
721 struct ieee80211_hdr *wh;
722 u32 hdrlen, pktlen;
723 struct mwl8k_dma_data *tr;
724
725 wh = (struct ieee80211_hdr *)skb->data;
726 hdrlen = ieee80211_hdrlen(wh->frame_control);
727 pktlen = skb->len;
728
729 /*
730 * Copy up/down the 802.11 header; the firmware requires
731 * we present a 2-byte payload length followed by a
732 * 4-address header (w/o QoS), followed (optionally) by
733 * any WEP/ExtIV header (but only filled in for CCMP).
734 */
735 if (hdrlen != sizeof(struct mwl8k_dma_data))
736 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
737
738 tr = (struct mwl8k_dma_data *)skb->data;
739 if (wh != &tr->wh)
740 memmove(&tr->wh, wh, hdrlen);
741
742 /* Clear addr4 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200743 memset(tr->wh.addr4, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100744
745 /*
746 * Firmware length is the length of the fully formed "802.11
747 * payload". That is, everything except for the 802.11 header.
748 * This includes all crypto material including the MIC.
749 */
750 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100751}
752
753
754/*
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200755 * Packet reception for 88w8366.
756 */
757struct mwl8k_rxd_8366 {
758 __le16 pkt_len;
759 __u8 sq2;
760 __u8 rate;
761 __le32 pkt_phys_addr;
762 __le32 next_rxd_phys_addr;
763 __le16 qos_control;
764 __le16 htsig2;
765 __le32 hw_rssi_info;
766 __le32 hw_noise_floor_info;
767 __u8 noise_floor;
768 __u8 pad0[3];
769 __u8 rssi;
770 __u8 rx_status;
771 __u8 channel;
772 __u8 rx_ctrl;
773} __attribute__((packed));
774
775#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
776
777static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
778{
779 struct mwl8k_rxd_8366 *rxd = _rxd;
780
781 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
782 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
783}
784
785static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
786{
787 struct mwl8k_rxd_8366 *rxd = _rxd;
788
789 rxd->pkt_len = cpu_to_le16(len);
790 rxd->pkt_phys_addr = cpu_to_le32(addr);
791 wmb();
792 rxd->rx_ctrl = 0;
793}
794
795static int
796mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status)
797{
798 struct mwl8k_rxd_8366 *rxd = _rxd;
799
800 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
801 return -1;
802 rmb();
803
804 memset(status, 0, sizeof(*status));
805
806 status->signal = -rxd->rssi;
807 status->noise = -rxd->noise_floor;
808
809 if (rxd->rate & 0x80) {
810 status->flag |= RX_FLAG_HT;
811 status->rate_idx = rxd->rate & 0x7f;
812 } else {
813 int i;
814
815 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
816 if (mwl8k_rates[i].hw_value == rxd->rate) {
817 status->rate_idx = i;
818 break;
819 }
820 }
821 }
822
823 status->band = IEEE80211_BAND_2GHZ;
824 status->freq = ieee80211_channel_to_frequency(rxd->channel);
825
826 return le16_to_cpu(rxd->pkt_len);
827}
828
829static struct rxd_ops rxd_8366_ops = {
830 .rxd_size = sizeof(struct mwl8k_rxd_8366),
831 .rxd_init = mwl8k_rxd_8366_init,
832 .rxd_refill = mwl8k_rxd_8366_refill,
833 .rxd_process = mwl8k_rxd_8366_process,
834};
835
836/*
837 * Packet reception for 88w8687.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100838 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200839struct mwl8k_rxd_8687 {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100840 __le16 pkt_len;
841 __u8 link_quality;
842 __u8 noise_level;
843 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200844 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100845 __le16 qos_control;
846 __le16 rate_info;
847 __le32 pad0[4];
848 __u8 rssi;
849 __u8 channel;
850 __le16 pad1;
851 __u8 rx_ctrl;
852 __u8 rx_status;
853 __u8 pad2[2];
854} __attribute__((packed));
855
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200856#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
857#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
858#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
859#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
860#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
861#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
862
863#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
864
865static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
866{
867 struct mwl8k_rxd_8687 *rxd = _rxd;
868
869 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
870 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
871}
872
873static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
874{
875 struct mwl8k_rxd_8687 *rxd = _rxd;
876
877 rxd->pkt_len = cpu_to_le16(len);
878 rxd->pkt_phys_addr = cpu_to_le32(addr);
879 wmb();
880 rxd->rx_ctrl = 0;
881}
882
883static int
884mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status)
885{
886 struct mwl8k_rxd_8687 *rxd = _rxd;
887 u16 rate_info;
888
889 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
890 return -1;
891 rmb();
892
893 rate_info = le16_to_cpu(rxd->rate_info);
894
895 memset(status, 0, sizeof(*status));
896
897 status->signal = -rxd->rssi;
898 status->noise = -rxd->noise_level;
899 status->qual = rxd->link_quality;
900 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
901 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
902
903 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
904 status->flag |= RX_FLAG_SHORTPRE;
905 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
906 status->flag |= RX_FLAG_40MHZ;
907 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
908 status->flag |= RX_FLAG_SHORT_GI;
909 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
910 status->flag |= RX_FLAG_HT;
911
912 status->band = IEEE80211_BAND_2GHZ;
913 status->freq = ieee80211_channel_to_frequency(rxd->channel);
914
915 return le16_to_cpu(rxd->pkt_len);
916}
917
918static struct rxd_ops rxd_8687_ops = {
919 .rxd_size = sizeof(struct mwl8k_rxd_8687),
920 .rxd_init = mwl8k_rxd_8687_init,
921 .rxd_refill = mwl8k_rxd_8687_refill,
922 .rxd_process = mwl8k_rxd_8687_process,
923};
924
925
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100926#define MWL8K_RX_DESCS 256
927#define MWL8K_RX_MAXSZ 3800
928
929static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
930{
931 struct mwl8k_priv *priv = hw->priv;
932 struct mwl8k_rx_queue *rxq = priv->rxq + index;
933 int size;
934 int i;
935
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200936 rxq->rxd_count = 0;
937 rxq->head = 0;
938 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100939
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200940 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100941
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200942 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
943 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100944 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200945 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100946 return -ENOMEM;
947 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200948 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100949
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200950 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
951 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100952 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200953 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200954 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100955 return -ENOMEM;
956 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200957 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100958
959 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200960 int desc_size;
961 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100962 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200963 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100964
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200965 desc_size = priv->rxd_ops->rxd_size;
966 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100967
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200968 nexti = i + 1;
969 if (nexti == MWL8K_RX_DESCS)
970 nexti = 0;
971 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
972
973 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100974 }
975
976 return 0;
977}
978
979static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
980{
981 struct mwl8k_priv *priv = hw->priv;
982 struct mwl8k_rx_queue *rxq = priv->rxq + index;
983 int refilled;
984
985 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200986 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100987 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200988 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100989 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200990 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100991
992 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
993 if (skb == NULL)
994 break;
995
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200996 addr = pci_map_single(priv->pdev, skb->data,
997 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100998
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200999 rxq->rxd_count++;
1000 rx = rxq->tail++;
1001 if (rxq->tail == MWL8K_RX_DESCS)
1002 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001003 rxq->buf[rx].skb = skb;
1004 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001005
1006 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1007 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001008
1009 refilled++;
1010 }
1011
1012 return refilled;
1013}
1014
1015/* Must be called only when the card's reception is completely halted */
1016static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1017{
1018 struct mwl8k_priv *priv = hw->priv;
1019 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1020 int i;
1021
1022 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001023 if (rxq->buf[i].skb != NULL) {
1024 pci_unmap_single(priv->pdev,
1025 pci_unmap_addr(&rxq->buf[i], dma),
1026 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1027 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001028
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001029 kfree_skb(rxq->buf[i].skb);
1030 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001031 }
1032 }
1033
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001034 kfree(rxq->buf);
1035 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001036
1037 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001038 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001039 rxq->rxd, rxq->rxd_dma);
1040 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001041}
1042
1043
1044/*
1045 * Scan a list of BSSIDs to process for finalize join.
1046 * Allows for extension to process multiple BSSIDs.
1047 */
1048static inline int
1049mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1050{
1051 return priv->capture_beacon &&
1052 ieee80211_is_beacon(wh->frame_control) &&
1053 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1054}
1055
Lennert Buytenhek37797522009-10-22 20:19:45 +02001056static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1057 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001058{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001059 struct mwl8k_priv *priv = hw->priv;
1060
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001061 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001062 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001063
1064 /*
1065 * Use GFP_ATOMIC as rxq_process is called from
1066 * the primary interrupt handler, memory allocation call
1067 * must not sleep.
1068 */
1069 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1070 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001071 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001072}
1073
1074static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1075{
1076 struct mwl8k_priv *priv = hw->priv;
1077 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1078 int processed;
1079
1080 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001081 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001082 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001083 void *rxd;
1084 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001085 struct ieee80211_rx_status status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001086
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001087 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001088 if (skb == NULL)
1089 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001090
1091 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1092
1093 pkt_len = priv->rxd_ops->rxd_process(rxd, &status);
1094 if (pkt_len < 0)
1095 break;
1096
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001097 rxq->buf[rxq->head].skb = NULL;
1098
1099 pci_unmap_single(priv->pdev,
1100 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1101 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1102 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001103
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001104 rxq->head++;
1105 if (rxq->head == MWL8K_RX_DESCS)
1106 rxq->head = 0;
1107
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001108 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001109
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001110 skb_put(skb, pkt_len);
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001111 mwl8k_remove_dma_header(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001112
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001113 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001114 * Check for a pending join operation. Save a
1115 * copy of the beacon and schedule a tasklet to
1116 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001117 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001118 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001119 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001120
Johannes Bergf1d58c22009-06-17 13:13:00 +02001121 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1122 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001123
1124 processed++;
1125 }
1126
1127 return processed;
1128}
1129
1130
1131/*
1132 * Packet transmission.
1133 */
1134
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001135/* Transmit packet ACK policy */
1136#define MWL8K_TXD_ACK_POLICY_NORMAL 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001137#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1138
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001139#define MWL8K_TXD_STATUS_OK 0x00000001
1140#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1141#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1142#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001143#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001144
1145struct mwl8k_tx_desc {
1146 __le32 status;
1147 __u8 data_rate;
1148 __u8 tx_priority;
1149 __le16 qos_control;
1150 __le32 pkt_phys_addr;
1151 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001152 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001153 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001154 __le32 reserved;
1155 __le16 rate_info;
1156 __u8 peer_id;
1157 __u8 tx_frag_cnt;
1158} __attribute__((packed));
1159
1160#define MWL8K_TX_DESCS 128
1161
1162static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1163{
1164 struct mwl8k_priv *priv = hw->priv;
1165 struct mwl8k_tx_queue *txq = priv->txq + index;
1166 int size;
1167 int i;
1168
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001169 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1170 txq->stats.limit = MWL8K_TX_DESCS;
1171 txq->head = 0;
1172 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001173
1174 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1175
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001176 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1177 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001178 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001179 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001180 return -ENOMEM;
1181 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001182 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001183
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001184 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1185 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001186 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001187 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001188 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001189 return -ENOMEM;
1190 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001191 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001192
1193 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1194 struct mwl8k_tx_desc *tx_desc;
1195 int nexti;
1196
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001197 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001198 nexti = (i + 1) % MWL8K_TX_DESCS;
1199
1200 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001201 tx_desc->next_txd_phys_addr =
1202 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203 }
1204
1205 return 0;
1206}
1207
1208static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1209{
1210 iowrite32(MWL8K_H2A_INT_PPA_READY,
1211 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1212 iowrite32(MWL8K_H2A_INT_DUMMY,
1213 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1214 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1215}
1216
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001217struct mwl8k_txq_info {
1218 u32 fw_owned;
1219 u32 drv_owned;
1220 u32 unused;
1221 u32 len;
1222 u32 head;
1223 u32 tail;
1224};
1225
1226static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001227 struct mwl8k_txq_info *txinfo)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001228{
1229 int count, desc, status;
1230 struct mwl8k_tx_queue *txq;
1231 struct mwl8k_tx_desc *tx_desc;
1232 int ndescs = 0;
1233
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001234 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
1235
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001236 for (count = 0; count < MWL8K_TX_QUEUES; count++) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001237 txq = priv->txq + count;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001238 txinfo[count].len = txq->stats.len;
1239 txinfo[count].head = txq->head;
1240 txinfo[count].tail = txq->tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001241 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001242 tx_desc = txq->txd + desc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001243 status = le32_to_cpu(tx_desc->status);
1244
1245 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1246 txinfo[count].fw_owned++;
1247 else
1248 txinfo[count].drv_owned++;
1249
1250 if (tx_desc->pkt_len == 0)
1251 txinfo[count].unused++;
1252 }
1253 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001254
1255 return ndescs;
1256}
1257
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001258/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001259 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001260 */
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001261static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001262{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001263 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001264 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001265 u32 count;
1266 unsigned long timeout;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001267
1268 might_sleep();
1269
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001270 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001271 count = priv->pending_tx_pkts;
1272 if (count)
1273 priv->tx_wait = &tx_wait;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001274 spin_unlock_bh(&priv->tx_lock);
1275
1276 if (count) {
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001277 struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001278 int index;
1279 int newcount;
1280
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001281 timeout = wait_for_completion_timeout(&tx_wait,
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001282 msecs_to_jiffies(5000));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001283 if (timeout)
1284 return 0;
1285
1286 spin_lock_bh(&priv->tx_lock);
1287 priv->tx_wait = NULL;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001288 newcount = priv->pending_tx_pkts;
1289 mwl8k_scan_tx_ring(priv, txinfo);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001290 spin_unlock_bh(&priv->tx_lock);
1291
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001292 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001293 __func__, __LINE__, count, newcount);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001294
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001295 for (index = 0; index < MWL8K_TX_QUEUES; index++)
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001296 printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u "
1297 "DRV:%u U:%u\n",
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001298 index,
1299 txinfo[index].len,
1300 txinfo[index].head,
1301 txinfo[index].tail,
1302 txinfo[index].fw_owned,
1303 txinfo[index].drv_owned,
1304 txinfo[index].unused);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001305
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001306 return -ETIMEDOUT;
1307 }
1308
1309 return 0;
1310}
1311
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001312#define MWL8K_TXD_SUCCESS(status) \
1313 ((status) & (MWL8K_TXD_STATUS_OK | \
1314 MWL8K_TXD_STATUS_OK_RETRY | \
1315 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001316
1317static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1318{
1319 struct mwl8k_priv *priv = hw->priv;
1320 struct mwl8k_tx_queue *txq = priv->txq + index;
1321 int wake = 0;
1322
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001323 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001324 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001325 struct mwl8k_tx_desc *tx_desc;
1326 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001327 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001328 struct sk_buff *skb;
1329 struct ieee80211_tx_info *info;
1330 u32 status;
1331
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001332 tx = txq->head;
1333 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001334
1335 status = le32_to_cpu(tx_desc->status);
1336
1337 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1338 if (!force)
1339 break;
1340 tx_desc->status &=
1341 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1342 }
1343
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001344 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1345 BUG_ON(txq->stats.len == 0);
1346 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001347 priv->pending_tx_pkts--;
1348
1349 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001350 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001351 skb = txq->skb[tx];
1352 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001353
1354 BUG_ON(skb == NULL);
1355 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1356
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001357 mwl8k_remove_dma_header(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001358
1359 /* Mark descriptor as unused */
1360 tx_desc->pkt_phys_addr = 0;
1361 tx_desc->pkt_len = 0;
1362
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001363 info = IEEE80211_SKB_CB(skb);
1364 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001365 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001366 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001367
1368 ieee80211_tx_status_irqsafe(hw, skb);
1369
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001370 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001371 }
1372
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001373 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001374 ieee80211_wake_queue(hw, index);
1375}
1376
1377/* must be called only when the card's transmit is completely halted */
1378static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1379{
1380 struct mwl8k_priv *priv = hw->priv;
1381 struct mwl8k_tx_queue *txq = priv->txq + index;
1382
1383 mwl8k_txq_reclaim(hw, index, 1);
1384
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001385 kfree(txq->skb);
1386 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001387
1388 pci_free_consistent(priv->pdev,
1389 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001390 txq->txd, txq->txd_dma);
1391 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001392}
1393
1394static int
1395mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1396{
1397 struct mwl8k_priv *priv = hw->priv;
1398 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001399 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001400 struct ieee80211_hdr *wh;
1401 struct mwl8k_tx_queue *txq;
1402 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001403 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001404 u32 txstatus;
1405 u8 txdatarate;
1406 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001407
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001408 wh = (struct ieee80211_hdr *)skb->data;
1409 if (ieee80211_is_data_qos(wh->frame_control))
1410 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1411 else
1412 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001413
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001414 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001415 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001416
1417 tx_info = IEEE80211_SKB_CB(skb);
1418 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001419
1420 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1421 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001422
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001423 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1424 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1425 mwl8k_vif->seqno = seqno++ % 4096;
1426 }
1427
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001428 /* Setup firmware control bit fields for each frame type. */
1429 txstatus = 0;
1430 txdatarate = 0;
1431 if (ieee80211_is_mgmt(wh->frame_control) ||
1432 ieee80211_is_ctl(wh->frame_control)) {
1433 txdatarate = 0;
1434 qos = mwl8k_qos_setbit_eosp(qos);
1435 /* Set Queue size to unspecified */
1436 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1437 } else if (ieee80211_is_data(wh->frame_control)) {
1438 txdatarate = 1;
1439 if (is_multicast_ether_addr(wh->addr1))
1440 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1441
1442 /* Send pkt in an aggregate if AMPDU frame. */
1443 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1444 qos = mwl8k_qos_setbit_ack(qos,
1445 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1446 else
1447 qos = mwl8k_qos_setbit_ack(qos,
1448 MWL8K_TXD_ACK_POLICY_NORMAL);
1449
1450 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1451 qos = mwl8k_qos_setbit_amsdu(qos);
1452 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001453
1454 dma = pci_map_single(priv->pdev, skb->data,
1455 skb->len, PCI_DMA_TODEVICE);
1456
1457 if (pci_dma_mapping_error(priv->pdev, dma)) {
1458 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001459 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001460 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001461 return NETDEV_TX_OK;
1462 }
1463
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001464 spin_lock_bh(&priv->tx_lock);
1465
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001466 txq = priv->txq + index;
1467
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001468 BUG_ON(txq->skb[txq->tail] != NULL);
1469 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001470
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001471 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001472 tx->data_rate = txdatarate;
1473 tx->tx_priority = index;
1474 tx->qos_control = cpu_to_le16(qos);
1475 tx->pkt_phys_addr = cpu_to_le32(dma);
1476 tx->pkt_len = cpu_to_le16(skb->len);
1477 tx->rate_info = 0;
1478 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001479 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001480 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1481
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001482 txq->stats.count++;
1483 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001484 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001485
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001486 txq->tail++;
1487 if (txq->tail == MWL8K_TX_DESCS)
1488 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001489
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001490 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001491 ieee80211_stop_queue(hw, index);
1492
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001493 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001494
1495 spin_unlock_bh(&priv->tx_lock);
1496
1497 return NETDEV_TX_OK;
1498}
1499
1500
1501/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001502 * Firmware access.
1503 *
1504 * We have the following requirements for issuing firmware commands:
1505 * - Some commands require that the packet transmit path is idle when
1506 * the command is issued. (For simplicity, we'll just quiesce the
1507 * transmit path for every command.)
1508 * - There are certain sequences of commands that need to be issued to
1509 * the hardware sequentially, with no other intervening commands.
1510 *
1511 * This leads to an implementation of a "firmware lock" as a mutex that
1512 * can be taken recursively, and which is taken by both the low-level
1513 * command submission function (mwl8k_post_cmd) as well as any users of
1514 * that function that require issuing of an atomic sequence of commands,
1515 * and quiesces the transmit path whenever it's taken.
1516 */
1517static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1518{
1519 struct mwl8k_priv *priv = hw->priv;
1520
1521 if (priv->fw_mutex_owner != current) {
1522 int rc;
1523
1524 mutex_lock(&priv->fw_mutex);
1525 ieee80211_stop_queues(hw);
1526
1527 rc = mwl8k_tx_wait_empty(hw);
1528 if (rc) {
1529 ieee80211_wake_queues(hw);
1530 mutex_unlock(&priv->fw_mutex);
1531
1532 return rc;
1533 }
1534
1535 priv->fw_mutex_owner = current;
1536 }
1537
1538 priv->fw_mutex_depth++;
1539
1540 return 0;
1541}
1542
1543static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1544{
1545 struct mwl8k_priv *priv = hw->priv;
1546
1547 if (!--priv->fw_mutex_depth) {
1548 ieee80211_wake_queues(hw);
1549 priv->fw_mutex_owner = NULL;
1550 mutex_unlock(&priv->fw_mutex);
1551 }
1552}
1553
1554
1555/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001556 * Command processing.
1557 */
1558
1559/* Timeout firmware commands after 2000ms */
1560#define MWL8K_CMD_TIMEOUT_MS 2000
1561
1562static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1563{
1564 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1565 struct mwl8k_priv *priv = hw->priv;
1566 void __iomem *regs = priv->regs;
1567 dma_addr_t dma_addr;
1568 unsigned int dma_size;
1569 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001570 unsigned long timeout = 0;
1571 u8 buf[32];
1572
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001573 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001574 dma_size = le16_to_cpu(cmd->length);
1575 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1576 PCI_DMA_BIDIRECTIONAL);
1577 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1578 return -ENOMEM;
1579
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001580 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001581 if (rc) {
1582 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1583 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001584 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001585 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001586
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001587 priv->hostcmd_wait = &cmd_wait;
1588 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1589 iowrite32(MWL8K_H2A_INT_DOORBELL,
1590 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1591 iowrite32(MWL8K_H2A_INT_DUMMY,
1592 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001593
1594 timeout = wait_for_completion_timeout(&cmd_wait,
1595 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1596
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001597 priv->hostcmd_wait = NULL;
1598
1599 mwl8k_fw_unlock(hw);
1600
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001601 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1602 PCI_DMA_BIDIRECTIONAL);
1603
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001604 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001605 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001606 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001607 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1608 MWL8K_CMD_TIMEOUT_MS);
1609 rc = -ETIMEDOUT;
1610 } else {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001611 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001612 if (rc)
1613 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001614 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001615 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001616 le16_to_cpu(cmd->result));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001617 }
1618
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001619 return rc;
1620}
1621
1622/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001623 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001624 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001625struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001626 struct mwl8k_cmd_pkt header;
1627 __u8 hw_rev;
1628 __u8 host_interface;
1629 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001630 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001631 __le16 region_code;
1632 __le32 fw_rev;
1633 __le32 ps_cookie;
1634 __le32 caps;
1635 __u8 mcs_bitmap[16];
1636 __le32 rx_queue_ptr;
1637 __le32 num_tx_queues;
1638 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1639 __le32 caps2;
1640 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001641 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001642} __attribute__((packed));
1643
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001644static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001645{
1646 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001647 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001648 int rc;
1649 int i;
1650
1651 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1652 if (cmd == NULL)
1653 return -ENOMEM;
1654
1655 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1656 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1657
1658 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1659 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001660 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001661 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001662 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001663 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001664 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001665 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001666
1667 rc = mwl8k_post_cmd(hw, &cmd->header);
1668
1669 if (!rc) {
1670 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1671 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001672 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001673 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001674 }
1675
1676 kfree(cmd);
1677 return rc;
1678}
1679
1680/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001681 * CMD_GET_HW_SPEC (AP version).
1682 */
1683struct mwl8k_cmd_get_hw_spec_ap {
1684 struct mwl8k_cmd_pkt header;
1685 __u8 hw_rev;
1686 __u8 host_interface;
1687 __le16 num_wcb;
1688 __le16 num_mcaddrs;
1689 __u8 perm_addr[ETH_ALEN];
1690 __le16 region_code;
1691 __le16 num_antenna;
1692 __le32 fw_rev;
1693 __le32 wcbbase0;
1694 __le32 rxwrptr;
1695 __le32 rxrdptr;
1696 __le32 ps_cookie;
1697 __le32 wcbbase1;
1698 __le32 wcbbase2;
1699 __le32 wcbbase3;
1700} __attribute__((packed));
1701
1702static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1703{
1704 struct mwl8k_priv *priv = hw->priv;
1705 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1706 int rc;
1707
1708 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1709 if (cmd == NULL)
1710 return -ENOMEM;
1711
1712 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1713 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1714
1715 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1716 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1717
1718 rc = mwl8k_post_cmd(hw, &cmd->header);
1719
1720 if (!rc) {
1721 int off;
1722
1723 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1724 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1725 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1726 priv->hw_rev = cmd->hw_rev;
1727
1728 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1729 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1730
1731 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1732 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1733
1734 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1735 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1736
1737 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1738 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1739
1740 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1741 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1742
1743 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1744 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1745 }
1746
1747 kfree(cmd);
1748 return rc;
1749}
1750
1751/*
1752 * CMD_SET_HW_SPEC.
1753 */
1754struct mwl8k_cmd_set_hw_spec {
1755 struct mwl8k_cmd_pkt header;
1756 __u8 hw_rev;
1757 __u8 host_interface;
1758 __le16 num_mcaddrs;
1759 __u8 perm_addr[ETH_ALEN];
1760 __le16 region_code;
1761 __le32 fw_rev;
1762 __le32 ps_cookie;
1763 __le32 caps;
1764 __le32 rx_queue_ptr;
1765 __le32 num_tx_queues;
1766 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1767 __le32 flags;
1768 __le32 num_tx_desc_per_queue;
1769 __le32 total_rxd;
1770} __attribute__((packed));
1771
1772#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1773
1774static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1775{
1776 struct mwl8k_priv *priv = hw->priv;
1777 struct mwl8k_cmd_set_hw_spec *cmd;
1778 int rc;
1779 int i;
1780
1781 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1782 if (cmd == NULL)
1783 return -ENOMEM;
1784
1785 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1786 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1787
1788 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1789 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1790 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1791 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1792 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1793 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1794 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1795 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1796
1797 rc = mwl8k_post_cmd(hw, &cmd->header);
1798 kfree(cmd);
1799
1800 return rc;
1801}
1802
1803/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001804 * CMD_MAC_MULTICAST_ADR.
1805 */
1806struct mwl8k_cmd_mac_multicast_adr {
1807 struct mwl8k_cmd_pkt header;
1808 __le16 action;
1809 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001810 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001811};
1812
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001813#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1814#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1815#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1816#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001817
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001818static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001819__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001820 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001821{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001822 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001823 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001824 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001825
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001826 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001827 allmulti = 1;
1828 mc_count = 0;
1829 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001830
1831 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1832
1833 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001834 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001835 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001836
1837 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1838 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001839 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1840 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001841
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001842 if (allmulti) {
1843 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1844 } else if (mc_count) {
1845 int i;
1846
1847 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1848 cmd->numaddr = cpu_to_le16(mc_count);
1849 for (i = 0; i < mc_count && mclist; i++) {
1850 if (mclist->da_addrlen != ETH_ALEN) {
1851 kfree(cmd);
1852 return NULL;
1853 }
1854 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1855 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001856 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001857 }
1858
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001859 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001860}
1861
1862/*
1863 * CMD_802_11_GET_STAT.
1864 */
1865struct mwl8k_cmd_802_11_get_stat {
1866 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001867 __le32 stats[64];
1868} __attribute__((packed));
1869
1870#define MWL8K_STAT_ACK_FAILURE 9
1871#define MWL8K_STAT_RTS_FAILURE 12
1872#define MWL8K_STAT_FCS_ERROR 24
1873#define MWL8K_STAT_RTS_SUCCESS 11
1874
1875static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1876 struct ieee80211_low_level_stats *stats)
1877{
1878 struct mwl8k_cmd_802_11_get_stat *cmd;
1879 int rc;
1880
1881 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1882 if (cmd == NULL)
1883 return -ENOMEM;
1884
1885 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1886 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001887
1888 rc = mwl8k_post_cmd(hw, &cmd->header);
1889 if (!rc) {
1890 stats->dot11ACKFailureCount =
1891 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1892 stats->dot11RTSFailureCount =
1893 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1894 stats->dot11FCSErrorCount =
1895 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1896 stats->dot11RTSSuccessCount =
1897 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1898 }
1899 kfree(cmd);
1900
1901 return rc;
1902}
1903
1904/*
1905 * CMD_802_11_RADIO_CONTROL.
1906 */
1907struct mwl8k_cmd_802_11_radio_control {
1908 struct mwl8k_cmd_pkt header;
1909 __le16 action;
1910 __le16 control;
1911 __le16 radio_on;
1912} __attribute__((packed));
1913
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001914static int
1915mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001916{
1917 struct mwl8k_priv *priv = hw->priv;
1918 struct mwl8k_cmd_802_11_radio_control *cmd;
1919 int rc;
1920
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001921 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001922 return 0;
1923
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001924 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1925 if (cmd == NULL)
1926 return -ENOMEM;
1927
1928 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1929 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1930 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001931 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001932 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1933
1934 rc = mwl8k_post_cmd(hw, &cmd->header);
1935 kfree(cmd);
1936
1937 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001938 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001939
1940 return rc;
1941}
1942
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001943static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1944{
1945 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1946}
1947
1948static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1949{
1950 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1951}
1952
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001953static int
1954mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1955{
1956 struct mwl8k_priv *priv;
1957
1958 if (hw == NULL || hw->priv == NULL)
1959 return -EINVAL;
1960 priv = hw->priv;
1961
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001962 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001963
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001964 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001965}
1966
1967/*
1968 * CMD_802_11_RF_TX_POWER.
1969 */
1970#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1971
1972struct mwl8k_cmd_802_11_rf_tx_power {
1973 struct mwl8k_cmd_pkt header;
1974 __le16 action;
1975 __le16 support_level;
1976 __le16 current_level;
1977 __le16 reserved;
1978 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1979} __attribute__((packed));
1980
1981static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1982{
1983 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
1984 int rc;
1985
1986 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1987 if (cmd == NULL)
1988 return -ENOMEM;
1989
1990 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1991 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1992 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1993 cmd->support_level = cpu_to_le16(dBm);
1994
1995 rc = mwl8k_post_cmd(hw, &cmd->header);
1996 kfree(cmd);
1997
1998 return rc;
1999}
2000
2001/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002002 * CMD_RF_ANTENNA.
2003 */
2004struct mwl8k_cmd_rf_antenna {
2005 struct mwl8k_cmd_pkt header;
2006 __le16 antenna;
2007 __le16 mode;
2008} __attribute__((packed));
2009
2010#define MWL8K_RF_ANTENNA_RX 1
2011#define MWL8K_RF_ANTENNA_TX 2
2012
2013static int
2014mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2015{
2016 struct mwl8k_cmd_rf_antenna *cmd;
2017 int rc;
2018
2019 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2020 if (cmd == NULL)
2021 return -ENOMEM;
2022
2023 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2024 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2025 cmd->antenna = cpu_to_le16(antenna);
2026 cmd->mode = cpu_to_le16(mask);
2027
2028 rc = mwl8k_post_cmd(hw, &cmd->header);
2029 kfree(cmd);
2030
2031 return rc;
2032}
2033
2034/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002035 * CMD_SET_PRE_SCAN.
2036 */
2037struct mwl8k_cmd_set_pre_scan {
2038 struct mwl8k_cmd_pkt header;
2039} __attribute__((packed));
2040
2041static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2042{
2043 struct mwl8k_cmd_set_pre_scan *cmd;
2044 int rc;
2045
2046 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2047 if (cmd == NULL)
2048 return -ENOMEM;
2049
2050 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2051 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2052
2053 rc = mwl8k_post_cmd(hw, &cmd->header);
2054 kfree(cmd);
2055
2056 return rc;
2057}
2058
2059/*
2060 * CMD_SET_POST_SCAN.
2061 */
2062struct mwl8k_cmd_set_post_scan {
2063 struct mwl8k_cmd_pkt header;
2064 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002065 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002066} __attribute__((packed));
2067
2068static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002069mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002070{
2071 struct mwl8k_cmd_set_post_scan *cmd;
2072 int rc;
2073
2074 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2075 if (cmd == NULL)
2076 return -ENOMEM;
2077
2078 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2079 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2080 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002081 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002082
2083 rc = mwl8k_post_cmd(hw, &cmd->header);
2084 kfree(cmd);
2085
2086 return rc;
2087}
2088
2089/*
2090 * CMD_SET_RF_CHANNEL.
2091 */
2092struct mwl8k_cmd_set_rf_channel {
2093 struct mwl8k_cmd_pkt header;
2094 __le16 action;
2095 __u8 current_channel;
2096 __le32 channel_flags;
2097} __attribute__((packed));
2098
2099static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2100 struct ieee80211_channel *channel)
2101{
2102 struct mwl8k_cmd_set_rf_channel *cmd;
2103 int rc;
2104
2105 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2106 if (cmd == NULL)
2107 return -ENOMEM;
2108
2109 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2110 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2111 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2112 cmd->current_channel = channel->hw_value;
2113 if (channel->band == IEEE80211_BAND_2GHZ)
2114 cmd->channel_flags = cpu_to_le32(0x00000081);
2115 else
2116 cmd->channel_flags = cpu_to_le32(0x00000000);
2117
2118 rc = mwl8k_post_cmd(hw, &cmd->header);
2119 kfree(cmd);
2120
2121 return rc;
2122}
2123
2124/*
2125 * CMD_SET_SLOT.
2126 */
2127struct mwl8k_cmd_set_slot {
2128 struct mwl8k_cmd_pkt header;
2129 __le16 action;
2130 __u8 short_slot;
2131} __attribute__((packed));
2132
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002133static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002134{
2135 struct mwl8k_cmd_set_slot *cmd;
2136 int rc;
2137
2138 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2139 if (cmd == NULL)
2140 return -ENOMEM;
2141
2142 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2143 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2144 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002145 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002146
2147 rc = mwl8k_post_cmd(hw, &cmd->header);
2148 kfree(cmd);
2149
2150 return rc;
2151}
2152
2153/*
2154 * CMD_MIMO_CONFIG.
2155 */
2156struct mwl8k_cmd_mimo_config {
2157 struct mwl8k_cmd_pkt header;
2158 __le32 action;
2159 __u8 rx_antenna_map;
2160 __u8 tx_antenna_map;
2161} __attribute__((packed));
2162
2163static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2164{
2165 struct mwl8k_cmd_mimo_config *cmd;
2166 int rc;
2167
2168 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2169 if (cmd == NULL)
2170 return -ENOMEM;
2171
2172 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2173 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2174 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2175 cmd->rx_antenna_map = rx;
2176 cmd->tx_antenna_map = tx;
2177
2178 rc = mwl8k_post_cmd(hw, &cmd->header);
2179 kfree(cmd);
2180
2181 return rc;
2182}
2183
2184/*
2185 * CMD_ENABLE_SNIFFER.
2186 */
2187struct mwl8k_cmd_enable_sniffer {
2188 struct mwl8k_cmd_pkt header;
2189 __le32 action;
2190} __attribute__((packed));
2191
2192static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2193{
2194 struct mwl8k_cmd_enable_sniffer *cmd;
2195 int rc;
2196
2197 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2198 if (cmd == NULL)
2199 return -ENOMEM;
2200
2201 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2202 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002203 cmd->action = cpu_to_le32(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002204
2205 rc = mwl8k_post_cmd(hw, &cmd->header);
2206 kfree(cmd);
2207
2208 return rc;
2209}
2210
2211/*
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002212 * CMD_SET_MAC_ADDR.
2213 */
2214struct mwl8k_cmd_set_mac_addr {
2215 struct mwl8k_cmd_pkt header;
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002216 union {
2217 struct {
2218 __le16 mac_type;
2219 __u8 mac_addr[ETH_ALEN];
2220 } mbss;
2221 __u8 mac_addr[ETH_ALEN];
2222 };
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002223} __attribute__((packed));
2224
2225static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2226{
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002227 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002228 struct mwl8k_cmd_set_mac_addr *cmd;
2229 int rc;
2230
2231 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2232 if (cmd == NULL)
2233 return -ENOMEM;
2234
2235 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2236 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002237 if (priv->ap_fw) {
2238 cmd->mbss.mac_type = 0;
2239 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2240 } else {
2241 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2242 }
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002243
2244 rc = mwl8k_post_cmd(hw, &cmd->header);
2245 kfree(cmd);
2246
2247 return rc;
2248}
2249
2250
2251/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002252 * CMD_SET_RATEADAPT_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002253 */
2254struct mwl8k_cmd_set_rate_adapt_mode {
2255 struct mwl8k_cmd_pkt header;
2256 __le16 action;
2257 __le16 mode;
2258} __attribute__((packed));
2259
2260static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2261{
2262 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2263 int rc;
2264
2265 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2266 if (cmd == NULL)
2267 return -ENOMEM;
2268
2269 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2270 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2271 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2272 cmd->mode = cpu_to_le16(mode);
2273
2274 rc = mwl8k_post_cmd(hw, &cmd->header);
2275 kfree(cmd);
2276
2277 return rc;
2278}
2279
2280/*
2281 * CMD_SET_WMM_MODE.
2282 */
2283struct mwl8k_cmd_set_wmm {
2284 struct mwl8k_cmd_pkt header;
2285 __le16 action;
2286} __attribute__((packed));
2287
2288static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2289{
2290 struct mwl8k_priv *priv = hw->priv;
2291 struct mwl8k_cmd_set_wmm *cmd;
2292 int rc;
2293
2294 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2295 if (cmd == NULL)
2296 return -ENOMEM;
2297
2298 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2299 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002300 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002301
2302 rc = mwl8k_post_cmd(hw, &cmd->header);
2303 kfree(cmd);
2304
2305 if (!rc)
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002306 priv->wmm_enabled = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002307
2308 return rc;
2309}
2310
2311/*
2312 * CMD_SET_RTS_THRESHOLD.
2313 */
2314struct mwl8k_cmd_rts_threshold {
2315 struct mwl8k_cmd_pkt header;
2316 __le16 action;
2317 __le16 threshold;
2318} __attribute__((packed));
2319
2320static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002321 u16 action, u16 threshold)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002322{
2323 struct mwl8k_cmd_rts_threshold *cmd;
2324 int rc;
2325
2326 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2327 if (cmd == NULL)
2328 return -ENOMEM;
2329
2330 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2331 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2332 cmd->action = cpu_to_le16(action);
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002333 cmd->threshold = cpu_to_le16(threshold);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002334
2335 rc = mwl8k_post_cmd(hw, &cmd->header);
2336 kfree(cmd);
2337
2338 return rc;
2339}
2340
2341/*
2342 * CMD_SET_EDCA_PARAMS.
2343 */
2344struct mwl8k_cmd_set_edca_params {
2345 struct mwl8k_cmd_pkt header;
2346
2347 /* See MWL8K_SET_EDCA_XXX below */
2348 __le16 action;
2349
2350 /* TX opportunity in units of 32 us */
2351 __le16 txop;
2352
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002353 union {
2354 struct {
2355 /* Log exponent of max contention period: 0...15 */
2356 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002357
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002358 /* Log exponent of min contention period: 0...15 */
2359 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002360
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002361 /* Adaptive interframe spacing in units of 32us */
2362 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002363
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002364 /* TX queue to configure */
2365 __u8 txq;
2366 } ap;
2367 struct {
2368 /* Log exponent of max contention period: 0...15 */
2369 __u8 log_cw_max;
2370
2371 /* Log exponent of min contention period: 0...15 */
2372 __u8 log_cw_min;
2373
2374 /* Adaptive interframe spacing in units of 32us */
2375 __u8 aifs;
2376
2377 /* TX queue to configure */
2378 __u8 txq;
2379 } sta;
2380 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002381} __attribute__((packed));
2382
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002383#define MWL8K_SET_EDCA_CW 0x01
2384#define MWL8K_SET_EDCA_TXOP 0x02
2385#define MWL8K_SET_EDCA_AIFS 0x04
2386
2387#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2388 MWL8K_SET_EDCA_TXOP | \
2389 MWL8K_SET_EDCA_AIFS)
2390
2391static int
2392mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2393 __u16 cw_min, __u16 cw_max,
2394 __u8 aifs, __u16 txop)
2395{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002396 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002397 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002398 int rc;
2399
2400 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2401 if (cmd == NULL)
2402 return -ENOMEM;
2403
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002404 /*
2405 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2406 * this call.
2407 */
2408 qnum ^= !(qnum >> 1);
2409
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002410 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2411 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002412 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2413 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002414 if (priv->ap_fw) {
2415 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2416 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2417 cmd->ap.aifs = aifs;
2418 cmd->ap.txq = qnum;
2419 } else {
2420 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2421 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2422 cmd->sta.aifs = aifs;
2423 cmd->sta.txq = qnum;
2424 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002425
2426 rc = mwl8k_post_cmd(hw, &cmd->header);
2427 kfree(cmd);
2428
2429 return rc;
2430}
2431
2432/*
2433 * CMD_FINALIZE_JOIN.
2434 */
2435
2436/* FJ beacon buffer size is compiled into the firmware. */
2437#define MWL8K_FJ_BEACON_MAXLEN 128
2438
2439struct mwl8k_cmd_finalize_join {
2440 struct mwl8k_cmd_pkt header;
2441 __le32 sleep_interval; /* Number of beacon periods to sleep */
2442 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2443} __attribute__((packed));
2444
2445static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2446 __u16 framelen, __u16 dtim)
2447{
2448 struct mwl8k_cmd_finalize_join *cmd;
2449 struct ieee80211_mgmt *payload = frame;
2450 u16 hdrlen;
2451 u32 payload_len;
2452 int rc;
2453
2454 if (frame == NULL)
2455 return -EINVAL;
2456
2457 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2458 if (cmd == NULL)
2459 return -ENOMEM;
2460
2461 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2462 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002463 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002464
2465 hdrlen = ieee80211_hdrlen(payload->frame_control);
2466
2467 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2468
2469 /* XXX TBD Might just have to abort and return an error */
2470 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2471 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002472 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2473 payload_len, MWL8K_FJ_BEACON_MAXLEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002474
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002475 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2476 payload_len = MWL8K_FJ_BEACON_MAXLEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002477
2478 if (payload && payload_len)
2479 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2480
2481 rc = mwl8k_post_cmd(hw, &cmd->header);
2482 kfree(cmd);
2483 return rc;
2484}
2485
2486/*
2487 * CMD_UPDATE_STADB.
2488 */
2489struct mwl8k_cmd_update_sta_db {
2490 struct mwl8k_cmd_pkt header;
2491
2492 /* See STADB_ACTION_TYPE */
2493 __le32 action;
2494
2495 /* Peer MAC address */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002496 __u8 peer_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002497
2498 __le32 reserved;
2499
2500 /* Peer info - valid during add/update. */
2501 struct peer_capability_info peer_info;
2502} __attribute__((packed));
2503
2504static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2505 struct ieee80211_vif *vif, __u32 action)
2506{
2507 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2508 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2509 struct mwl8k_cmd_update_sta_db *cmd;
2510 struct peer_capability_info *peer_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002511 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002512
2513 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2514 if (cmd == NULL)
2515 return -ENOMEM;
2516
2517 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2518 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2519
2520 cmd->action = cpu_to_le32(action);
2521 peer_info = &cmd->peer_info;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002522 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002523
2524 switch (action) {
2525 case MWL8K_STA_DB_ADD_ENTRY:
2526 case MWL8K_STA_DB_MODIFY_ENTRY:
2527 /* Build peer_info block */
2528 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2529 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002530 memcpy(peer_info->legacy_rates, mwl8k_rateids,
2531 sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002532 peer_info->interop = 1;
2533 peer_info->amsdu_enabled = 0;
2534
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002535 rc = mwl8k_post_cmd(hw, &cmd->header);
2536 if (rc == 0)
2537 mv_vif->peer_id = peer_info->station_id;
2538
2539 break;
2540
2541 case MWL8K_STA_DB_DEL_ENTRY:
2542 case MWL8K_STA_DB_FLUSH:
2543 default:
2544 rc = mwl8k_post_cmd(hw, &cmd->header);
2545 if (rc == 0)
2546 mv_vif->peer_id = 0;
2547 break;
2548 }
2549 kfree(cmd);
2550
2551 return rc;
2552}
2553
2554/*
2555 * CMD_SET_AID.
2556 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002557#define MWL8K_FRAME_PROT_DISABLED 0x00
2558#define MWL8K_FRAME_PROT_11G 0x07
2559#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2560#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002561
2562struct mwl8k_cmd_update_set_aid {
2563 struct mwl8k_cmd_pkt header;
2564 __le16 aid;
2565
2566 /* AP's MAC address (BSSID) */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002567 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002568 __le16 protection_mode;
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002569 __u8 supp_rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002570} __attribute__((packed));
2571
2572static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2573 struct ieee80211_vif *vif)
2574{
2575 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2576 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2577 struct mwl8k_cmd_update_set_aid *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002578 u16 prot_mode;
2579 int rc;
2580
2581 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2582 if (cmd == NULL)
2583 return -ENOMEM;
2584
2585 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2586 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2587 cmd->aid = cpu_to_le16(info->aid);
2588
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002589 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002590
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002591 if (info->use_cts_prot) {
2592 prot_mode = MWL8K_FRAME_PROT_11G;
2593 } else {
Johannes Berg9ed6bcc2009-05-08 20:47:39 +02002594 switch (info->ht_operation_mode &
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002595 IEEE80211_HT_OP_MODE_PROTECTION) {
2596 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2597 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2598 break;
2599 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2600 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2601 break;
2602 default:
2603 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2604 break;
2605 }
2606 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002607 cmd->protection_mode = cpu_to_le16(prot_mode);
2608
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002609 memcpy(cmd->supp_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002610
2611 rc = mwl8k_post_cmd(hw, &cmd->header);
2612 kfree(cmd);
2613
2614 return rc;
2615}
2616
2617/*
2618 * CMD_SET_RATE.
2619 */
2620struct mwl8k_cmd_update_rateset {
2621 struct mwl8k_cmd_pkt header;
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002622 __u8 legacy_rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002623
2624 /* Bitmap for supported MCS codes. */
Lennert Buytenhek0b5351a2009-11-30 18:11:18 +01002625 __u8 mcs_set[16];
2626 __u8 reserved[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002627} __attribute__((packed));
2628
2629static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2630 struct ieee80211_vif *vif)
2631{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002632 struct mwl8k_cmd_update_rateset *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002633 int rc;
2634
2635 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2636 if (cmd == NULL)
2637 return -ENOMEM;
2638
2639 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2640 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002641 memcpy(cmd->legacy_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002642
2643 rc = mwl8k_post_cmd(hw, &cmd->header);
2644 kfree(cmd);
2645
2646 return rc;
2647}
2648
2649/*
2650 * CMD_USE_FIXED_RATE.
2651 */
2652#define MWL8K_RATE_TABLE_SIZE 8
2653#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002654#define MWL8K_USE_AUTO_RATE 0x0002
2655
2656struct mwl8k_rate_entry {
2657 /* Set to 1 if HT rate, 0 if legacy. */
2658 __le32 is_ht_rate;
2659
2660 /* Set to 1 to use retry_count field. */
2661 __le32 enable_retry;
2662
2663 /* Specified legacy rate or MCS. */
2664 __le32 rate;
2665
2666 /* Number of allowed retries. */
2667 __le32 retry_count;
2668} __attribute__((packed));
2669
2670struct mwl8k_rate_table {
2671 /* 1 to allow specified rate and below */
2672 __le32 allow_rate_drop;
2673 __le32 num_rates;
2674 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2675} __attribute__((packed));
2676
2677struct mwl8k_cmd_use_fixed_rate {
2678 struct mwl8k_cmd_pkt header;
2679 __le32 action;
2680 struct mwl8k_rate_table rate_table;
2681
2682 /* Unicast, Broadcast or Multicast */
2683 __le32 rate_type;
2684 __le32 reserved1;
2685 __le32 reserved2;
2686} __attribute__((packed));
2687
2688static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2689 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2690{
2691 struct mwl8k_cmd_use_fixed_rate *cmd;
2692 int count;
2693 int rc;
2694
2695 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2696 if (cmd == NULL)
2697 return -ENOMEM;
2698
2699 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2700 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2701
2702 cmd->action = cpu_to_le32(action);
2703 cmd->rate_type = cpu_to_le32(rate_type);
2704
2705 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002706 /*
2707 * Copy over each field manually so that endian
2708 * conversion can be done.
2709 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002710 cmd->rate_table.allow_rate_drop =
2711 cpu_to_le32(rate_table->allow_rate_drop);
2712 cmd->rate_table.num_rates =
2713 cpu_to_le32(rate_table->num_rates);
2714
2715 for (count = 0; count < rate_table->num_rates; count++) {
2716 struct mwl8k_rate_entry *dst =
2717 &cmd->rate_table.rate_entry[count];
2718 struct mwl8k_rate_entry *src =
2719 &rate_table->rate_entry[count];
2720
2721 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2722 dst->enable_retry = cpu_to_le32(src->enable_retry);
2723 dst->rate = cpu_to_le32(src->rate);
2724 dst->retry_count = cpu_to_le32(src->retry_count);
2725 }
2726 }
2727
2728 rc = mwl8k_post_cmd(hw, &cmd->header);
2729 kfree(cmd);
2730
2731 return rc;
2732}
2733
2734
2735/*
2736 * Interrupt handling.
2737 */
2738static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2739{
2740 struct ieee80211_hw *hw = dev_id;
2741 struct mwl8k_priv *priv = hw->priv;
2742 u32 status;
2743
2744 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2745 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2746
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002747 if (!status)
2748 return IRQ_NONE;
2749
2750 if (status & MWL8K_A2H_INT_TX_DONE)
2751 tasklet_schedule(&priv->tx_reclaim_task);
2752
2753 if (status & MWL8K_A2H_INT_RX_READY) {
2754 while (rxq_process(hw, 0, 1))
2755 rxq_refill(hw, 0, 1);
2756 }
2757
2758 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002759 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002760 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002761 }
2762
2763 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002764 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002765 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002766 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002767 }
2768
2769 return IRQ_HANDLED;
2770}
2771
2772
2773/*
2774 * Core driver operations.
2775 */
2776static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2777{
2778 struct mwl8k_priv *priv = hw->priv;
2779 int index = skb_get_queue_mapping(skb);
2780 int rc;
2781
2782 if (priv->current_channel == NULL) {
2783 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002784 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002785 dev_kfree_skb(skb);
2786 return NETDEV_TX_OK;
2787 }
2788
2789 rc = mwl8k_txq_xmit(hw, index, skb);
2790
2791 return rc;
2792}
2793
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002794static int mwl8k_start(struct ieee80211_hw *hw)
2795{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002796 struct mwl8k_priv *priv = hw->priv;
2797 int rc;
2798
Joe Perchesa0607fd2009-11-18 23:29:17 -08002799 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002800 IRQF_SHARED, MWL8K_NAME, hw);
2801 if (rc) {
2802 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002803 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002804 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002805 }
2806
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002807 /* Enable tx reclaim tasklet */
2808 tasklet_enable(&priv->tx_reclaim_task);
2809
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002810 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002811 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002812
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002813 rc = mwl8k_fw_lock(hw);
2814 if (!rc) {
2815 rc = mwl8k_cmd_802_11_radio_enable(hw);
2816
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002817 if (!priv->ap_fw) {
2818 if (!rc)
2819 rc = mwl8k_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002820
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002821 if (!rc)
2822 rc = mwl8k_cmd_set_pre_scan(hw);
2823
2824 if (!rc)
2825 rc = mwl8k_cmd_set_post_scan(hw,
2826 "\x00\x00\x00\x00\x00\x00");
2827 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002828
2829 if (!rc)
2830 rc = mwl8k_cmd_setrateadaptmode(hw, 0);
2831
2832 if (!rc)
2833 rc = mwl8k_set_wmm(hw, 0);
2834
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002835 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002836 }
2837
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002838 if (rc) {
2839 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2840 free_irq(priv->pdev->irq, hw);
2841 tasklet_disable(&priv->tx_reclaim_task);
2842 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002843
2844 return rc;
2845}
2846
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002847static void mwl8k_stop(struct ieee80211_hw *hw)
2848{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002849 struct mwl8k_priv *priv = hw->priv;
2850 int i;
2851
Lennert Buytenhekd3cea0b2009-07-17 07:15:49 +02002852 mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002853
2854 ieee80211_stop_queues(hw);
2855
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002856 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002857 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002858 free_irq(priv->pdev->irq, hw);
2859
2860 /* Stop finalize join worker */
2861 cancel_work_sync(&priv->finalize_join_worker);
2862 if (priv->beacon_skb != NULL)
2863 dev_kfree_skb(priv->beacon_skb);
2864
2865 /* Stop tx reclaim tasklet */
2866 tasklet_disable(&priv->tx_reclaim_task);
2867
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002868 /* Return all skbs to mac80211 */
2869 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2870 mwl8k_txq_reclaim(hw, i, 1);
2871}
2872
2873static int mwl8k_add_interface(struct ieee80211_hw *hw,
2874 struct ieee80211_if_init_conf *conf)
2875{
2876 struct mwl8k_priv *priv = hw->priv;
2877 struct mwl8k_vif *mwl8k_vif;
2878
2879 /*
2880 * We only support one active interface at a time.
2881 */
2882 if (priv->vif != NULL)
2883 return -EBUSY;
2884
2885 /*
2886 * We only support managed interfaces for now.
2887 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002888 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002889 return -EINVAL;
2890
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002891 /*
2892 * Reject interface creation if sniffer mode is active, as
2893 * STA operation is mutually exclusive with hardware sniffer
2894 * mode.
2895 */
2896 if (priv->sniffer_enabled) {
2897 printk(KERN_INFO "%s: unable to create STA "
2898 "interface due to sniffer mode being enabled\n",
2899 wiphy_name(hw->wiphy));
2900 return -EINVAL;
2901 }
2902
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002903 /* Clean out driver private area */
2904 mwl8k_vif = MWL8K_VIF(conf->vif);
2905 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2906
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002907 /* Set and save the mac address */
2908 mwl8k_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002909 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002910
2911 /* Back pointer to parent config block */
2912 mwl8k_vif->priv = priv;
2913
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002914 /* Set Initial sequence number to zero */
2915 mwl8k_vif->seqno = 0;
2916
2917 priv->vif = conf->vif;
2918 priv->current_channel = NULL;
2919
2920 return 0;
2921}
2922
2923static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2924 struct ieee80211_if_init_conf *conf)
2925{
2926 struct mwl8k_priv *priv = hw->priv;
2927
2928 if (priv->vif == NULL)
2929 return;
2930
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002931 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
2932
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002933 priv->vif = NULL;
2934}
2935
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002936static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002937{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002938 struct ieee80211_conf *conf = &hw->conf;
2939 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002940 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002941
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002942 if (conf->flags & IEEE80211_CONF_IDLE) {
2943 mwl8k_cmd_802_11_radio_disable(hw);
2944 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002945 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002946 }
2947
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002948 rc = mwl8k_fw_lock(hw);
2949 if (rc)
2950 return rc;
2951
2952 rc = mwl8k_cmd_802_11_radio_enable(hw);
2953 if (rc)
2954 goto out;
2955
2956 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2957 if (rc)
2958 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002959
2960 priv->current_channel = conf->channel;
2961
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002962 if (conf->power_level > 18)
2963 conf->power_level = 18;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002964 rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level);
2965 if (rc)
2966 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002967
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002968 if (priv->ap_fw) {
2969 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2970 if (!rc)
2971 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2972 } else {
2973 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2974 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002975
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002976out:
2977 mwl8k_fw_unlock(hw);
2978
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002979 return rc;
2980}
2981
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002982static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
2983 struct ieee80211_vif *vif,
2984 struct ieee80211_bss_conf *info,
2985 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002986{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002987 struct mwl8k_priv *priv = hw->priv;
2988 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002989 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002990
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002991 if (changed & BSS_CHANGED_BSSID)
2992 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
2993
2994 if ((changed & BSS_CHANGED_ASSOC) == 0)
2995 return;
2996
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002997 priv->capture_beacon = false;
2998
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002999 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02003000 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003001 return;
3002
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003003 if (info->assoc) {
3004 memcpy(&mwl8k_vif->bss_info, info,
3005 sizeof(struct ieee80211_bss_conf));
3006
3007 /* Install rates */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003008 rc = mwl8k_update_rateset(hw, vif);
3009 if (rc)
3010 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003011
3012 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003013 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3014 MWL8K_UCAST_RATE, NULL);
3015 if (rc)
3016 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003017
3018 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003019 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
3020 if (rc)
3021 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003022
3023 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003024 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
3025 if (rc)
3026 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003027
3028 /* Update peer rate info */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003029 rc = mwl8k_cmd_update_sta_db(hw, vif,
3030 MWL8K_STA_DB_MODIFY_ENTRY);
3031 if (rc)
3032 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003033
3034 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003035 rc = mwl8k_cmd_set_aid(hw, vif);
3036 if (rc)
3037 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003038
3039 /*
3040 * Finalize the join. Tell rx handler to process
3041 * next beacon from our BSSID.
3042 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003043 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003044 priv->capture_beacon = true;
3045 } else {
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003046 rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003047 memset(&mwl8k_vif->bss_info, 0,
3048 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003049 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003050 }
3051
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003052out:
3053 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003054}
3055
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003056static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3057 int mc_count, struct dev_addr_list *mclist)
3058{
3059 struct mwl8k_cmd_pkt *cmd;
3060
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003061 /*
3062 * Synthesize and return a command packet that programs the
3063 * hardware multicast address filter. At this point we don't
3064 * know whether FIF_ALLMULTI is being requested, but if it is,
3065 * we'll end up throwing this packet away and creating a new
3066 * one in mwl8k_configure_filter().
3067 */
3068 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003069
3070 return (unsigned long)cmd;
3071}
3072
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003073static int
3074mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3075 unsigned int changed_flags,
3076 unsigned int *total_flags)
3077{
3078 struct mwl8k_priv *priv = hw->priv;
3079
3080 /*
3081 * Hardware sniffer mode is mutually exclusive with STA
3082 * operation, so refuse to enable sniffer mode if a STA
3083 * interface is active.
3084 */
3085 if (priv->vif != NULL) {
3086 if (net_ratelimit())
3087 printk(KERN_INFO "%s: not enabling sniffer "
3088 "mode because STA interface is active\n",
3089 wiphy_name(hw->wiphy));
3090 return 0;
3091 }
3092
3093 if (!priv->sniffer_enabled) {
3094 if (mwl8k_enable_sniffer(hw, 1))
3095 return 0;
3096 priv->sniffer_enabled = true;
3097 }
3098
3099 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3100 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3101 FIF_OTHER_BSS;
3102
3103 return 1;
3104}
3105
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003106static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3107 unsigned int changed_flags,
3108 unsigned int *total_flags,
3109 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003110{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003111 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003112 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3113
3114 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003115 * AP firmware doesn't allow fine-grained control over
3116 * the receive filter.
3117 */
3118 if (priv->ap_fw) {
3119 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3120 kfree(cmd);
3121 return;
3122 }
3123
3124 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003125 * Enable hardware sniffer mode if FIF_CONTROL or
3126 * FIF_OTHER_BSS is requested.
3127 */
3128 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3129 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3130 kfree(cmd);
3131 return;
3132 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003133
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003134 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003135 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003136
3137 if (mwl8k_fw_lock(hw))
3138 return;
3139
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003140 if (priv->sniffer_enabled) {
3141 mwl8k_enable_sniffer(hw, 0);
3142 priv->sniffer_enabled = false;
3143 }
3144
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003145 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003146 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3147 /*
3148 * Disable the BSS filter.
3149 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003150 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003151 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003152 u8 *bssid;
3153
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003154 /*
3155 * Enable the BSS filter.
3156 *
3157 * If there is an active STA interface, use that
3158 * interface's BSSID, otherwise use a dummy one
3159 * (where the OUI part needs to be nonzero for
3160 * the BSSID to be accepted by POST_SCAN).
3161 */
3162 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003163 if (priv->vif != NULL)
3164 bssid = MWL8K_VIF(priv->vif)->bssid;
3165
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003166 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003167 }
3168 }
3169
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003170 /*
3171 * If FIF_ALLMULTI is being requested, throw away the command
3172 * packet that ->prepare_multicast() built and replace it with
3173 * a command packet that enables reception of all multicast
3174 * packets.
3175 */
3176 if (*total_flags & FIF_ALLMULTI) {
3177 kfree(cmd);
3178 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3179 }
3180
3181 if (cmd != NULL) {
3182 mwl8k_post_cmd(hw, cmd);
3183 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003184 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003185
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003186 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003187}
3188
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003189static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3190{
Lennert Buytenhek733d3062009-07-17 07:24:15 +02003191 return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003192}
3193
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003194static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3195 const struct ieee80211_tx_queue_params *params)
3196{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003197 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003198 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003199
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003200 rc = mwl8k_fw_lock(hw);
3201 if (!rc) {
3202 if (!priv->wmm_enabled)
3203 rc = mwl8k_set_wmm(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003204
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003205 if (!rc)
3206 rc = mwl8k_set_edca_params(hw, queue,
3207 params->cw_min,
3208 params->cw_max,
3209 params->aifs,
3210 params->txop);
3211
3212 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003213 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003214
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003215 return rc;
3216}
3217
3218static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3219 struct ieee80211_tx_queue_stats *stats)
3220{
3221 struct mwl8k_priv *priv = hw->priv;
3222 struct mwl8k_tx_queue *txq;
3223 int index;
3224
3225 spin_lock_bh(&priv->tx_lock);
3226 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3227 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003228 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003229 sizeof(struct ieee80211_tx_queue_stats));
3230 }
3231 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003232
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003233 return 0;
3234}
3235
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003236static int mwl8k_get_stats(struct ieee80211_hw *hw,
3237 struct ieee80211_low_level_stats *stats)
3238{
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003239 return mwl8k_cmd_802_11_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003240}
3241
3242static const struct ieee80211_ops mwl8k_ops = {
3243 .tx = mwl8k_tx,
3244 .start = mwl8k_start,
3245 .stop = mwl8k_stop,
3246 .add_interface = mwl8k_add_interface,
3247 .remove_interface = mwl8k_remove_interface,
3248 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003249 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003250 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003251 .configure_filter = mwl8k_configure_filter,
3252 .set_rts_threshold = mwl8k_set_rts_threshold,
3253 .conf_tx = mwl8k_conf_tx,
3254 .get_tx_stats = mwl8k_get_tx_stats,
3255 .get_stats = mwl8k_get_stats,
3256};
3257
3258static void mwl8k_tx_reclaim_handler(unsigned long data)
3259{
3260 int i;
3261 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3262 struct mwl8k_priv *priv = hw->priv;
3263
3264 spin_lock_bh(&priv->tx_lock);
3265 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3266 mwl8k_txq_reclaim(hw, i, 0);
3267
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003268 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003269 complete(priv->tx_wait);
3270 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003271 }
3272 spin_unlock_bh(&priv->tx_lock);
3273}
3274
3275static void mwl8k_finalize_join_worker(struct work_struct *work)
3276{
3277 struct mwl8k_priv *priv =
3278 container_of(work, struct mwl8k_priv, finalize_join_worker);
3279 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003280 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003281
3282 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3283 dev_kfree_skb(skb);
3284
3285 priv->beacon_skb = NULL;
3286}
3287
John W. Linvillebcb628d2009-11-06 16:40:16 -05003288enum {
3289 MWL8687 = 0,
3290 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003291};
3292
John W. Linvillebcb628d2009-11-06 16:40:16 -05003293static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3294 {
3295 .part_name = "88w8687",
3296 .helper_image = "mwl8k/helper_8687.fw",
3297 .fw_image = "mwl8k/fmimage_8687.fw",
3298 .rxd_ops = &rxd_8687_ops,
3299 .modes = BIT(NL80211_IFTYPE_STATION),
3300 },
3301 {
3302 .part_name = "88w8366",
3303 .helper_image = "mwl8k/helper_8366.fw",
3304 .fw_image = "mwl8k/fmimage_8366.fw",
3305 .rxd_ops = &rxd_8366_ops,
3306 .modes = 0,
3307 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003308};
3309
3310static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003311 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3312 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3313 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3314 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003315};
3316MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3317
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003318static int __devinit mwl8k_probe(struct pci_dev *pdev,
3319 const struct pci_device_id *id)
3320{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003321 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003322 struct ieee80211_hw *hw;
3323 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003324 int rc;
3325 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003326
3327 if (!printed_version) {
3328 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3329 printed_version = 1;
3330 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003331
3332 rc = pci_enable_device(pdev);
3333 if (rc) {
3334 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3335 MWL8K_NAME);
3336 return rc;
3337 }
3338
3339 rc = pci_request_regions(pdev, MWL8K_NAME);
3340 if (rc) {
3341 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3342 MWL8K_NAME);
3343 return rc;
3344 }
3345
3346 pci_set_master(pdev);
3347
3348 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3349 if (hw == NULL) {
3350 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3351 rc = -ENOMEM;
3352 goto err_free_reg;
3353 }
3354
3355 priv = hw->priv;
3356 priv->hw = hw;
3357 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003358 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02003359 priv->rxd_ops = priv->device_info->rxd_ops;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003360 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02003361 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003362 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003363
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003364 SET_IEEE80211_DEV(hw, &pdev->dev);
3365 pci_set_drvdata(pdev, hw);
3366
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003367 priv->sram = pci_iomap(pdev, 0, 0x10000);
3368 if (priv->sram == NULL) {
3369 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003370 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003371 goto err_iounmap;
3372 }
3373
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003374 /*
3375 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3376 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3377 */
3378 priv->regs = pci_iomap(pdev, 1, 0x10000);
3379 if (priv->regs == NULL) {
3380 priv->regs = pci_iomap(pdev, 2, 0x10000);
3381 if (priv->regs == NULL) {
3382 printk(KERN_ERR "%s: Cannot map device registers\n",
3383 wiphy_name(hw->wiphy));
3384 goto err_iounmap;
3385 }
3386 }
3387
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003388 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3389 priv->band.band = IEEE80211_BAND_2GHZ;
3390 priv->band.channels = priv->channels;
3391 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3392 priv->band.bitrates = priv->rates;
3393 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3394 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3395
3396 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3397 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3398
3399 /*
3400 * Extra headroom is the size of the required DMA header
3401 * minus the size of the smallest 802.11 frame (CTS frame).
3402 */
3403 hw->extra_tx_headroom =
3404 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3405
3406 hw->channel_change_time = 10;
3407
3408 hw->queues = MWL8K_TX_QUEUES;
3409
Lennert Buytenhek547810e2009-10-22 20:21:02 +02003410 hw->wiphy->interface_modes = priv->device_info->modes;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003411
3412 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003413 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003414 hw->vif_data_size = sizeof(struct mwl8k_vif);
3415 priv->vif = NULL;
3416
3417 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003418 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003419 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003420
3421 /* Finalize join worker */
3422 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3423
3424 /* TX reclaim tasklet */
3425 tasklet_init(&priv->tx_reclaim_task,
3426 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3427 tasklet_disable(&priv->tx_reclaim_task);
3428
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003429 /* Power management cookie */
3430 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3431 if (priv->cookie == NULL)
3432 goto err_iounmap;
3433
3434 rc = mwl8k_rxq_init(hw, 0);
3435 if (rc)
3436 goto err_iounmap;
3437 rxq_refill(hw, 0, INT_MAX);
3438
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003439 mutex_init(&priv->fw_mutex);
3440 priv->fw_mutex_owner = NULL;
3441 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003442 priv->hostcmd_wait = NULL;
3443
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003444 spin_lock_init(&priv->tx_lock);
3445
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003446 priv->tx_wait = NULL;
3447
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003448 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3449 rc = mwl8k_txq_init(hw, i);
3450 if (rc)
3451 goto err_free_queues;
3452 }
3453
3454 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003455 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003456 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3457 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3458
Joe Perchesa0607fd2009-11-18 23:29:17 -08003459 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003460 IRQF_SHARED, MWL8K_NAME, hw);
3461 if (rc) {
3462 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003463 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003464 goto err_free_queues;
3465 }
3466
3467 /* Reset firmware and hardware */
3468 mwl8k_hw_reset(priv);
3469
3470 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003471 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003472 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003473 printk(KERN_ERR "%s: Firmware files not found\n",
3474 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003475 goto err_free_irq;
3476 }
3477
3478 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003479 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003480 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003481 printk(KERN_ERR "%s: Cannot start firmware\n",
3482 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003483 goto err_stop_firmware;
3484 }
3485
3486 /* Reclaim memory once firmware is successfully loaded */
3487 mwl8k_release_firmware(priv);
3488
3489 /*
3490 * Temporarily enable interrupts. Initial firmware host
3491 * commands use interrupts and avoids polling. Disable
3492 * interrupts when done.
3493 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003494 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003495
3496 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02003497 if (priv->ap_fw) {
3498 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3499 if (!rc)
3500 rc = mwl8k_cmd_set_hw_spec(hw);
3501 } else {
3502 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3503 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003504 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003505 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3506 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003507 goto err_stop_firmware;
3508 }
3509
3510 /* Turn radio off */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003511 rc = mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003512 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003513 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003514 goto err_stop_firmware;
3515 }
3516
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003517 /* Clear MAC address */
3518 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3519 if (rc) {
3520 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3521 wiphy_name(hw->wiphy));
3522 goto err_stop_firmware;
3523 }
3524
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003525 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003526 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003527 free_irq(priv->pdev->irq, hw);
3528
3529 rc = ieee80211_register_hw(hw);
3530 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003531 printk(KERN_ERR "%s: Cannot register device\n",
3532 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003533 goto err_stop_firmware;
3534 }
3535
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003536 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003537 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003538 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003539 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003540 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3541 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003542
3543 return 0;
3544
3545err_stop_firmware:
3546 mwl8k_hw_reset(priv);
3547 mwl8k_release_firmware(priv);
3548
3549err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003550 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003551 free_irq(priv->pdev->irq, hw);
3552
3553err_free_queues:
3554 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3555 mwl8k_txq_deinit(hw, i);
3556 mwl8k_rxq_deinit(hw, 0);
3557
3558err_iounmap:
3559 if (priv->cookie != NULL)
3560 pci_free_consistent(priv->pdev, 4,
3561 priv->cookie, priv->cookie_dma);
3562
3563 if (priv->regs != NULL)
3564 pci_iounmap(pdev, priv->regs);
3565
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003566 if (priv->sram != NULL)
3567 pci_iounmap(pdev, priv->sram);
3568
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003569 pci_set_drvdata(pdev, NULL);
3570 ieee80211_free_hw(hw);
3571
3572err_free_reg:
3573 pci_release_regions(pdev);
3574 pci_disable_device(pdev);
3575
3576 return rc;
3577}
3578
Joerg Albert230f7af2009-04-18 02:10:45 +02003579static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003580{
3581 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3582}
3583
Joerg Albert230f7af2009-04-18 02:10:45 +02003584static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003585{
3586 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3587 struct mwl8k_priv *priv;
3588 int i;
3589
3590 if (hw == NULL)
3591 return;
3592 priv = hw->priv;
3593
3594 ieee80211_stop_queues(hw);
3595
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003596 ieee80211_unregister_hw(hw);
3597
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003598 /* Remove tx reclaim tasklet */
3599 tasklet_kill(&priv->tx_reclaim_task);
3600
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003601 /* Stop hardware */
3602 mwl8k_hw_reset(priv);
3603
3604 /* Return all skbs to mac80211 */
3605 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3606 mwl8k_txq_reclaim(hw, i, 1);
3607
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003608 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3609 mwl8k_txq_deinit(hw, i);
3610
3611 mwl8k_rxq_deinit(hw, 0);
3612
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003613 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003614
3615 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003616 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003617 pci_set_drvdata(pdev, NULL);
3618 ieee80211_free_hw(hw);
3619 pci_release_regions(pdev);
3620 pci_disable_device(pdev);
3621}
3622
3623static struct pci_driver mwl8k_driver = {
3624 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003625 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003626 .probe = mwl8k_probe,
3627 .remove = __devexit_p(mwl8k_remove),
3628 .shutdown = __devexit_p(mwl8k_shutdown),
3629};
3630
3631static int __init mwl8k_init(void)
3632{
3633 return pci_register_driver(&mwl8k_driver);
3634}
3635
3636static void __exit mwl8k_exit(void)
3637{
3638 pci_unregister_driver(&mwl8k_driver);
3639}
3640
3641module_init(mwl8k_init);
3642module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003643
3644MODULE_DESCRIPTION(MWL8K_DESC);
3645MODULE_VERSION(MWL8K_VERSION);
3646MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3647MODULE_LICENSE("GPL");