blob: 6b12d81ba94bafc1e4e0fc504fa0d5b143adfac9 [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);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +010087 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
88 __le16 *qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020089};
90
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020091struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +020092 char *part_name;
93 char *helper_image;
94 char *fw_image;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020095 struct rxd_ops *rxd_ops;
Lennert Buytenhek547810e2009-10-22 20:21:02 +020096 u16 modes;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020097};
98
Lennert Buytenheka66098d2009-03-10 10:13:33 +010099struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200100 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100101
102 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200103 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100104
105 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200106 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100107
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200108 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200109 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200110 struct {
111 struct sk_buff *skb;
112 DECLARE_PCI_UNMAP_ADDR(dma)
113 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100114};
115
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100116struct mwl8k_tx_queue {
117 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200118 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100119
120 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200121 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100122
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200123 struct ieee80211_tx_queue_stats stats;
124 struct mwl8k_tx_desc *txd;
125 dma_addr_t txd_dma;
126 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100127};
128
129/* Pointers to the firmware data and meta information about it. */
130struct mwl8k_firmware {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131 /* Boot helper code */
132 struct firmware *helper;
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200133
134 /* Microcode */
135 struct firmware *ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100136};
137
138struct mwl8k_priv {
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +0200139 void __iomem *sram;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100140 void __iomem *regs;
141 struct ieee80211_hw *hw;
142
143 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100144
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200145 struct mwl8k_device_info *device_info;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200146 bool ap_fw;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200147 struct rxd_ops *rxd_ops;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200148
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100149 /* firmware files and meta data */
150 struct mwl8k_firmware fw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100151
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200152 /* firmware access */
153 struct mutex fw_mutex;
154 struct task_struct *fw_mutex_owner;
155 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200156 struct completion *hostcmd_wait;
157
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100158 /* lock held over TX and TX reap */
159 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100160
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200161 /* TX quiesce completion, protected by fw_mutex and tx_lock */
162 struct completion *tx_wait;
163
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100164 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100165
166 struct ieee80211_channel *current_channel;
167
168 /* power management status cookie from firmware */
169 u32 *cookie;
170 dma_addr_t cookie_dma;
171
172 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100173 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200174 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100175
176 /*
177 * Running count of TX packets in flight, to avoid
178 * iterating over the transmit rings each time.
179 */
180 int pending_tx_pkts;
181
182 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
183 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
184
185 /* PHY parameters */
186 struct ieee80211_supported_band band;
187 struct ieee80211_channel channels[14];
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100188 struct ieee80211_rate rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100189
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200190 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200191 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200192 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200193 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100194
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100195 /* XXX need to convert this to handle multiple interfaces */
196 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200197 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100198 struct sk_buff *beacon_skb;
199
200 /*
201 * This FJ worker has to be global as it is scheduled from the
202 * RX handler. At this point we don't know which interface it
203 * belongs to until the list of bssids waiting to complete join
204 * is checked.
205 */
206 struct work_struct finalize_join_worker;
207
208 /* Tasklet to reclaim TX descriptors and buffers after tx */
209 struct tasklet_struct tx_reclaim_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100210};
211
212/* Per interface specific private data */
213struct mwl8k_vif {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100214 /* backpointer to parent config block */
215 struct mwl8k_priv *priv;
216
217 /* BSS config of AP or IBSS from mac80211*/
218 struct ieee80211_bss_conf bss_info;
219
220 /* BSSID of AP or IBSS */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200221 u8 bssid[ETH_ALEN];
222 u8 mac_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100223
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100224 /* Index into station database.Returned by update_sta_db call */
225 u8 peer_id;
226
227 /* Non AMPDU sequence number assigned by driver */
228 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100229};
230
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200231#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100232
233static const struct ieee80211_channel mwl8k_channels[] = {
234 { .center_freq = 2412, .hw_value = 1, },
235 { .center_freq = 2417, .hw_value = 2, },
236 { .center_freq = 2422, .hw_value = 3, },
237 { .center_freq = 2427, .hw_value = 4, },
238 { .center_freq = 2432, .hw_value = 5, },
239 { .center_freq = 2437, .hw_value = 6, },
240 { .center_freq = 2442, .hw_value = 7, },
241 { .center_freq = 2447, .hw_value = 8, },
242 { .center_freq = 2452, .hw_value = 9, },
243 { .center_freq = 2457, .hw_value = 10, },
244 { .center_freq = 2462, .hw_value = 11, },
245};
246
247static const struct ieee80211_rate mwl8k_rates[] = {
248 { .bitrate = 10, .hw_value = 2, },
249 { .bitrate = 20, .hw_value = 4, },
250 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200251 { .bitrate = 110, .hw_value = 22, },
252 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100253 { .bitrate = 60, .hw_value = 12, },
254 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100255 { .bitrate = 120, .hw_value = 24, },
256 { .bitrate = 180, .hw_value = 36, },
257 { .bitrate = 240, .hw_value = 48, },
258 { .bitrate = 360, .hw_value = 72, },
259 { .bitrate = 480, .hw_value = 96, },
260 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100261 { .bitrate = 720, .hw_value = 144, },
262};
263
264static const u8 mwl8k_rateids[12] = {
265 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108,
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100266};
267
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100268/* Set or get info from Firmware */
269#define MWL8K_CMD_SET 0x0001
270#define MWL8K_CMD_GET 0x0000
271
272/* Firmware command codes */
273#define MWL8K_CMD_CODE_DNLD 0x0001
274#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200275#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100276#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
277#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200278#define MWL8K_CMD_RADIO_CONTROL 0x001c
279#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200280#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100281#define MWL8K_CMD_SET_PRE_SCAN 0x0107
282#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200283#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100284#define MWL8K_CMD_SET_AID 0x010d
285#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200286#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100287#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200288#define MWL8K_CMD_SET_SLOT 0x0114
289#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
290#define MWL8K_CMD_SET_WMM_MODE 0x0123
291#define MWL8K_CMD_MIMO_CONFIG 0x0125
292#define MWL8K_CMD_USE_FIXED_RATE 0x0126
293#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200294#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200295#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
296#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100297
298static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
299{
300#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
301 snprintf(buf, bufsize, "%s", #x);\
302 return buf;\
303 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200304 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100305 MWL8K_CMDNAME(CODE_DNLD);
306 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200307 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100308 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
309 MWL8K_CMDNAME(GET_STAT);
310 MWL8K_CMDNAME(RADIO_CONTROL);
311 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200312 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100313 MWL8K_CMDNAME(SET_PRE_SCAN);
314 MWL8K_CMDNAME(SET_POST_SCAN);
315 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100316 MWL8K_CMDNAME(SET_AID);
317 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200318 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100319 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200320 MWL8K_CMDNAME(SET_SLOT);
321 MWL8K_CMDNAME(SET_EDCA_PARAMS);
322 MWL8K_CMDNAME(SET_WMM_MODE);
323 MWL8K_CMDNAME(MIMO_CONFIG);
324 MWL8K_CMDNAME(USE_FIXED_RATE);
325 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200326 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200327 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
328 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100329 default:
330 snprintf(buf, bufsize, "0x%x", cmd);
331 }
332#undef MWL8K_CMDNAME
333
334 return buf;
335}
336
337/* Hardware and firmware reset */
338static void mwl8k_hw_reset(struct mwl8k_priv *priv)
339{
340 iowrite32(MWL8K_H2A_INT_RESET,
341 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
342 iowrite32(MWL8K_H2A_INT_RESET,
343 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
344 msleep(20);
345}
346
347/* Release fw image */
348static void mwl8k_release_fw(struct firmware **fw)
349{
350 if (*fw == NULL)
351 return;
352 release_firmware(*fw);
353 *fw = NULL;
354}
355
356static void mwl8k_release_firmware(struct mwl8k_priv *priv)
357{
358 mwl8k_release_fw(&priv->fw.ucode);
359 mwl8k_release_fw(&priv->fw.helper);
360}
361
362/* Request fw image */
363static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200364 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100365{
366 /* release current image */
367 if (*fw != NULL)
368 mwl8k_release_fw(fw);
369
370 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200371 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100372}
373
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200374static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100375{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200376 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100377 int rc;
378
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200379 if (di->helper_image != NULL) {
380 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
381 if (rc) {
382 printk(KERN_ERR "%s: Error requesting helper "
383 "firmware file %s\n", pci_name(priv->pdev),
384 di->helper_image);
385 return rc;
386 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100387 }
388
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200389 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100390 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200391 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200392 pci_name(priv->pdev), di->fw_image);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100393 mwl8k_release_fw(&priv->fw.helper);
394 return rc;
395 }
396
397 return 0;
398}
399
Ben Hutchings7e75b942009-11-07 22:00:57 +0000400MODULE_FIRMWARE("mwl8k/helper_8687.fw");
401MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
402
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100403struct mwl8k_cmd_pkt {
404 __le16 code;
405 __le16 length;
406 __le16 seq_num;
407 __le16 result;
408 char payload[0];
409} __attribute__((packed));
410
411/*
412 * Firmware loading.
413 */
414static int
415mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
416{
417 void __iomem *regs = priv->regs;
418 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100419 int loops;
420
421 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
422 if (pci_dma_mapping_error(priv->pdev, dma_addr))
423 return -ENOMEM;
424
425 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
426 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
427 iowrite32(MWL8K_H2A_INT_DOORBELL,
428 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
429 iowrite32(MWL8K_H2A_INT_DUMMY,
430 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
431
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100432 loops = 1000;
433 do {
434 u32 int_code;
435
436 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
437 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
438 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100439 break;
440 }
441
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200442 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100443 udelay(1);
444 } while (--loops);
445
446 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
447
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200448 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100449}
450
451static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
452 const u8 *data, size_t length)
453{
454 struct mwl8k_cmd_pkt *cmd;
455 int done;
456 int rc = 0;
457
458 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
459 if (cmd == NULL)
460 return -ENOMEM;
461
462 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
463 cmd->seq_num = 0;
464 cmd->result = 0;
465
466 done = 0;
467 while (length) {
468 int block_size = length > 256 ? 256 : length;
469
470 memcpy(cmd->payload, data + done, block_size);
471 cmd->length = cpu_to_le16(block_size);
472
473 rc = mwl8k_send_fw_load_cmd(priv, cmd,
474 sizeof(*cmd) + block_size);
475 if (rc)
476 break;
477
478 done += block_size;
479 length -= block_size;
480 }
481
482 if (!rc) {
483 cmd->length = 0;
484 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
485 }
486
487 kfree(cmd);
488
489 return rc;
490}
491
492static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
493 const u8 *data, size_t length)
494{
495 unsigned char *buffer;
496 int may_continue, rc = 0;
497 u32 done, prev_block_size;
498
499 buffer = kmalloc(1024, GFP_KERNEL);
500 if (buffer == NULL)
501 return -ENOMEM;
502
503 done = 0;
504 prev_block_size = 0;
505 may_continue = 1000;
506 while (may_continue > 0) {
507 u32 block_size;
508
509 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
510 if (block_size & 1) {
511 block_size &= ~1;
512 may_continue--;
513 } else {
514 done += prev_block_size;
515 length -= prev_block_size;
516 }
517
518 if (block_size > 1024 || block_size > length) {
519 rc = -EOVERFLOW;
520 break;
521 }
522
523 if (length == 0) {
524 rc = 0;
525 break;
526 }
527
528 if (block_size == 0) {
529 rc = -EPROTO;
530 may_continue--;
531 udelay(1);
532 continue;
533 }
534
535 prev_block_size = block_size;
536 memcpy(buffer, data + done, block_size);
537
538 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
539 if (rc)
540 break;
541 }
542
543 if (!rc && length != 0)
544 rc = -EREMOTEIO;
545
546 kfree(buffer);
547
548 return rc;
549}
550
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200551static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100552{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200553 struct mwl8k_priv *priv = hw->priv;
554 struct firmware *fw = priv->fw.ucode;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200555 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200556 int rc;
557 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100558
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200559 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
560 struct firmware *helper = priv->fw.helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100561
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200562 if (helper == NULL) {
563 printk(KERN_ERR "%s: helper image needed but none "
564 "given\n", pci_name(priv->pdev));
565 return -EINVAL;
566 }
567
568 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100569 if (rc) {
570 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200571 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100572 return rc;
573 }
574 msleep(1);
575
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200576 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100577 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200578 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100579 }
580
581 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200582 printk(KERN_ERR "%s: unable to load firmware image\n",
583 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100584 return rc;
585 }
586
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200587 if (di->modes & BIT(NL80211_IFTYPE_AP))
588 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
589 else
590 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100591 msleep(1);
592
593 loops = 200000;
594 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200595 u32 ready_code;
596
597 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
598 if (ready_code == MWL8K_FWAP_READY) {
599 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100600 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200601 } else if (ready_code == MWL8K_FWSTA_READY) {
602 priv->ap_fw = 0;
603 break;
604 }
605
606 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100607 udelay(1);
608 } while (--loops);
609
610 return loops ? 0 : -ETIMEDOUT;
611}
612
613
614/*
615 * Defines shared between transmission and reception.
616 */
617/* HT control fields for firmware */
618struct ewc_ht_info {
619 __le16 control1;
620 __le16 control2;
621 __le16 control3;
622} __attribute__((packed));
623
624/* Firmware Station database operations */
625#define MWL8K_STA_DB_ADD_ENTRY 0
626#define MWL8K_STA_DB_MODIFY_ENTRY 1
627#define MWL8K_STA_DB_DEL_ENTRY 2
628#define MWL8K_STA_DB_FLUSH 3
629
630/* Peer Entry flags - used to define the type of the peer node */
631#define MWL8K_PEER_TYPE_ACCESSPOINT 2
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100632
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100633struct peer_capability_info {
634 /* Peer type - AP vs. STA. */
635 __u8 peer_type;
636
637 /* Basic 802.11 capabilities from assoc resp. */
638 __le16 basic_caps;
639
640 /* Set if peer supports 802.11n high throughput (HT). */
641 __u8 ht_support;
642
643 /* Valid if HT is supported. */
644 __le16 ht_caps;
645 __u8 extended_ht_caps;
646 struct ewc_ht_info ewc_info;
647
648 /* Legacy rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100649 __u8 legacy_rates[12];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100650
651 /* HT rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek0b5351a2009-11-30 18:11:18 +0100652 __u8 ht_rates[16];
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +0200653 __u8 pad[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100654
655 /* If set, interoperability mode, no proprietary extensions. */
656 __u8 interop;
657 __u8 pad2;
658 __u8 station_id;
659 __le16 amsdu_enabled;
660} __attribute__((packed));
661
662/* Inline functions to manipulate QoS field in data descriptor. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100663static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
664{
665 u16 val_mask = 1 << 4;
666
667 /* End of Service Period Bit 4 */
668 return qos | val_mask;
669}
670
671static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
672{
673 u16 val_mask = 0x3;
674 u8 shift = 5;
675 u16 qos_mask = ~(val_mask << shift);
676
677 /* Ack Policy Bit 5-6 */
678 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
679}
680
681static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
682{
683 u16 val_mask = 1 << 7;
684
685 /* AMSDU present Bit 7 */
686 return qos | val_mask;
687}
688
689static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
690{
691 u16 val_mask = 0xff;
692 u8 shift = 8;
693 u16 qos_mask = ~(val_mask << shift);
694
695 /* Queue Length Bits 8-15 */
696 return (qos & qos_mask) | ((len & val_mask) << shift);
697}
698
699/* DMA header used by firmware and hardware. */
700struct mwl8k_dma_data {
701 __le16 fwlen;
702 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100703 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100704} __attribute__((packed));
705
706/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100707static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100708{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100709 struct mwl8k_dma_data *tr;
710 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100711
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100712 tr = (struct mwl8k_dma_data *)skb->data;
713 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
714
715 if (hdrlen != sizeof(tr->wh)) {
716 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
717 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
718 *((__le16 *)(tr->data - 2)) = qos;
719 } else {
720 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
721 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100722 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100723
724 if (hdrlen != sizeof(*tr))
725 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100726}
727
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200728static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100729{
730 struct ieee80211_hdr *wh;
731 u32 hdrlen, pktlen;
732 struct mwl8k_dma_data *tr;
733
734 wh = (struct ieee80211_hdr *)skb->data;
735 hdrlen = ieee80211_hdrlen(wh->frame_control);
736 pktlen = skb->len;
737
738 /*
739 * Copy up/down the 802.11 header; the firmware requires
740 * we present a 2-byte payload length followed by a
741 * 4-address header (w/o QoS), followed (optionally) by
742 * any WEP/ExtIV header (but only filled in for CCMP).
743 */
744 if (hdrlen != sizeof(struct mwl8k_dma_data))
745 skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
746
747 tr = (struct mwl8k_dma_data *)skb->data;
748 if (wh != &tr->wh)
749 memmove(&tr->wh, wh, hdrlen);
750
751 /* Clear addr4 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200752 memset(tr->wh.addr4, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100753
754 /*
755 * Firmware length is the length of the fully formed "802.11
756 * payload". That is, everything except for the 802.11 header.
757 * This includes all crypto material including the MIC.
758 */
759 tr->fwlen = cpu_to_le16(pktlen - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100760}
761
762
763/*
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200764 * Packet reception for 88w8366.
765 */
766struct mwl8k_rxd_8366 {
767 __le16 pkt_len;
768 __u8 sq2;
769 __u8 rate;
770 __le32 pkt_phys_addr;
771 __le32 next_rxd_phys_addr;
772 __le16 qos_control;
773 __le16 htsig2;
774 __le32 hw_rssi_info;
775 __le32 hw_noise_floor_info;
776 __u8 noise_floor;
777 __u8 pad0[3];
778 __u8 rssi;
779 __u8 rx_status;
780 __u8 channel;
781 __u8 rx_ctrl;
782} __attribute__((packed));
783
784#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
785
786static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
787{
788 struct mwl8k_rxd_8366 *rxd = _rxd;
789
790 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
791 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
792}
793
794static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
795{
796 struct mwl8k_rxd_8366 *rxd = _rxd;
797
798 rxd->pkt_len = cpu_to_le16(len);
799 rxd->pkt_phys_addr = cpu_to_le32(addr);
800 wmb();
801 rxd->rx_ctrl = 0;
802}
803
804static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100805mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status,
806 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200807{
808 struct mwl8k_rxd_8366 *rxd = _rxd;
809
810 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
811 return -1;
812 rmb();
813
814 memset(status, 0, sizeof(*status));
815
816 status->signal = -rxd->rssi;
817 status->noise = -rxd->noise_floor;
818
819 if (rxd->rate & 0x80) {
820 status->flag |= RX_FLAG_HT;
821 status->rate_idx = rxd->rate & 0x7f;
822 } else {
823 int i;
824
825 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
826 if (mwl8k_rates[i].hw_value == rxd->rate) {
827 status->rate_idx = i;
828 break;
829 }
830 }
831 }
832
833 status->band = IEEE80211_BAND_2GHZ;
834 status->freq = ieee80211_channel_to_frequency(rxd->channel);
835
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100836 *qos = rxd->qos_control;
837
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200838 return le16_to_cpu(rxd->pkt_len);
839}
840
841static struct rxd_ops rxd_8366_ops = {
842 .rxd_size = sizeof(struct mwl8k_rxd_8366),
843 .rxd_init = mwl8k_rxd_8366_init,
844 .rxd_refill = mwl8k_rxd_8366_refill,
845 .rxd_process = mwl8k_rxd_8366_process,
846};
847
848/*
849 * Packet reception for 88w8687.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100850 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200851struct mwl8k_rxd_8687 {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100852 __le16 pkt_len;
853 __u8 link_quality;
854 __u8 noise_level;
855 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200856 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100857 __le16 qos_control;
858 __le16 rate_info;
859 __le32 pad0[4];
860 __u8 rssi;
861 __u8 channel;
862 __le16 pad1;
863 __u8 rx_ctrl;
864 __u8 rx_status;
865 __u8 pad2[2];
866} __attribute__((packed));
867
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200868#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
869#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
870#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
871#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
872#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
873#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
874
875#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
876
877static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
878{
879 struct mwl8k_rxd_8687 *rxd = _rxd;
880
881 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
882 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
883}
884
885static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
886{
887 struct mwl8k_rxd_8687 *rxd = _rxd;
888
889 rxd->pkt_len = cpu_to_le16(len);
890 rxd->pkt_phys_addr = cpu_to_le32(addr);
891 wmb();
892 rxd->rx_ctrl = 0;
893}
894
895static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100896mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status,
897 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200898{
899 struct mwl8k_rxd_8687 *rxd = _rxd;
900 u16 rate_info;
901
902 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
903 return -1;
904 rmb();
905
906 rate_info = le16_to_cpu(rxd->rate_info);
907
908 memset(status, 0, sizeof(*status));
909
910 status->signal = -rxd->rssi;
911 status->noise = -rxd->noise_level;
912 status->qual = rxd->link_quality;
913 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
914 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
915
916 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
917 status->flag |= RX_FLAG_SHORTPRE;
918 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
919 status->flag |= RX_FLAG_40MHZ;
920 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
921 status->flag |= RX_FLAG_SHORT_GI;
922 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
923 status->flag |= RX_FLAG_HT;
924
925 status->band = IEEE80211_BAND_2GHZ;
926 status->freq = ieee80211_channel_to_frequency(rxd->channel);
927
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100928 *qos = rxd->qos_control;
929
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200930 return le16_to_cpu(rxd->pkt_len);
931}
932
933static struct rxd_ops rxd_8687_ops = {
934 .rxd_size = sizeof(struct mwl8k_rxd_8687),
935 .rxd_init = mwl8k_rxd_8687_init,
936 .rxd_refill = mwl8k_rxd_8687_refill,
937 .rxd_process = mwl8k_rxd_8687_process,
938};
939
940
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100941#define MWL8K_RX_DESCS 256
942#define MWL8K_RX_MAXSZ 3800
943
944static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
945{
946 struct mwl8k_priv *priv = hw->priv;
947 struct mwl8k_rx_queue *rxq = priv->rxq + index;
948 int size;
949 int i;
950
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200951 rxq->rxd_count = 0;
952 rxq->head = 0;
953 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100954
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200955 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100956
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200957 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
958 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100959 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200960 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100961 return -ENOMEM;
962 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200963 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100964
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200965 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
966 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100967 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200968 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200969 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100970 return -ENOMEM;
971 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200972 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100973
974 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200975 int desc_size;
976 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100977 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200978 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100979
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200980 desc_size = priv->rxd_ops->rxd_size;
981 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100982
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200983 nexti = i + 1;
984 if (nexti == MWL8K_RX_DESCS)
985 nexti = 0;
986 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
987
988 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100989 }
990
991 return 0;
992}
993
994static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
995{
996 struct mwl8k_priv *priv = hw->priv;
997 struct mwl8k_rx_queue *rxq = priv->rxq + index;
998 int refilled;
999
1000 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001001 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001002 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001003 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001004 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001005 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001006
1007 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1008 if (skb == NULL)
1009 break;
1010
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001011 addr = pci_map_single(priv->pdev, skb->data,
1012 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001013
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001014 rxq->rxd_count++;
1015 rx = rxq->tail++;
1016 if (rxq->tail == MWL8K_RX_DESCS)
1017 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001018 rxq->buf[rx].skb = skb;
1019 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001020
1021 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1022 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001023
1024 refilled++;
1025 }
1026
1027 return refilled;
1028}
1029
1030/* Must be called only when the card's reception is completely halted */
1031static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1032{
1033 struct mwl8k_priv *priv = hw->priv;
1034 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1035 int i;
1036
1037 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001038 if (rxq->buf[i].skb != NULL) {
1039 pci_unmap_single(priv->pdev,
1040 pci_unmap_addr(&rxq->buf[i], dma),
1041 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1042 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001043
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001044 kfree_skb(rxq->buf[i].skb);
1045 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001046 }
1047 }
1048
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001049 kfree(rxq->buf);
1050 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001051
1052 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001053 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001054 rxq->rxd, rxq->rxd_dma);
1055 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001056}
1057
1058
1059/*
1060 * Scan a list of BSSIDs to process for finalize join.
1061 * Allows for extension to process multiple BSSIDs.
1062 */
1063static inline int
1064mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1065{
1066 return priv->capture_beacon &&
1067 ieee80211_is_beacon(wh->frame_control) &&
1068 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1069}
1070
Lennert Buytenhek37797522009-10-22 20:19:45 +02001071static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1072 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001073{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001074 struct mwl8k_priv *priv = hw->priv;
1075
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001076 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001077 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001078
1079 /*
1080 * Use GFP_ATOMIC as rxq_process is called from
1081 * the primary interrupt handler, memory allocation call
1082 * must not sleep.
1083 */
1084 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1085 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001086 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001087}
1088
1089static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1090{
1091 struct mwl8k_priv *priv = hw->priv;
1092 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1093 int processed;
1094
1095 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001096 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001097 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001098 void *rxd;
1099 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001100 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001101 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001102
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001103 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001104 if (skb == NULL)
1105 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001106
1107 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1108
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001109 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001110 if (pkt_len < 0)
1111 break;
1112
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001113 rxq->buf[rxq->head].skb = NULL;
1114
1115 pci_unmap_single(priv->pdev,
1116 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1117 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1118 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001119
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001120 rxq->head++;
1121 if (rxq->head == MWL8K_RX_DESCS)
1122 rxq->head = 0;
1123
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001124 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001125
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001126 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001127 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001128
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001129 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001130 * Check for a pending join operation. Save a
1131 * copy of the beacon and schedule a tasklet to
1132 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001133 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001134 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001135 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001136
Johannes Bergf1d58c22009-06-17 13:13:00 +02001137 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1138 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001139
1140 processed++;
1141 }
1142
1143 return processed;
1144}
1145
1146
1147/*
1148 * Packet transmission.
1149 */
1150
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001151/* Transmit packet ACK policy */
1152#define MWL8K_TXD_ACK_POLICY_NORMAL 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001153#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1154
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001155#define MWL8K_TXD_STATUS_OK 0x00000001
1156#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1157#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1158#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001159#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001160
1161struct mwl8k_tx_desc {
1162 __le32 status;
1163 __u8 data_rate;
1164 __u8 tx_priority;
1165 __le16 qos_control;
1166 __le32 pkt_phys_addr;
1167 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001168 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001169 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001170 __le32 reserved;
1171 __le16 rate_info;
1172 __u8 peer_id;
1173 __u8 tx_frag_cnt;
1174} __attribute__((packed));
1175
1176#define MWL8K_TX_DESCS 128
1177
1178static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1179{
1180 struct mwl8k_priv *priv = hw->priv;
1181 struct mwl8k_tx_queue *txq = priv->txq + index;
1182 int size;
1183 int i;
1184
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001185 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1186 txq->stats.limit = MWL8K_TX_DESCS;
1187 txq->head = 0;
1188 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001189
1190 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1191
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001192 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1193 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001194 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001195 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001196 return -ENOMEM;
1197 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001198 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001199
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001200 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1201 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001202 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001203 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001204 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001205 return -ENOMEM;
1206 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001207 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001208
1209 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1210 struct mwl8k_tx_desc *tx_desc;
1211 int nexti;
1212
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001213 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001214 nexti = (i + 1) % MWL8K_TX_DESCS;
1215
1216 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001217 tx_desc->next_txd_phys_addr =
1218 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001219 }
1220
1221 return 0;
1222}
1223
1224static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1225{
1226 iowrite32(MWL8K_H2A_INT_PPA_READY,
1227 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1228 iowrite32(MWL8K_H2A_INT_DUMMY,
1229 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1230 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1231}
1232
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001233struct mwl8k_txq_info {
1234 u32 fw_owned;
1235 u32 drv_owned;
1236 u32 unused;
1237 u32 len;
1238 u32 head;
1239 u32 tail;
1240};
1241
1242static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001243 struct mwl8k_txq_info *txinfo)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001244{
1245 int count, desc, status;
1246 struct mwl8k_tx_queue *txq;
1247 struct mwl8k_tx_desc *tx_desc;
1248 int ndescs = 0;
1249
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001250 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
1251
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001252 for (count = 0; count < MWL8K_TX_QUEUES; count++) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001253 txq = priv->txq + count;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001254 txinfo[count].len = txq->stats.len;
1255 txinfo[count].head = txq->head;
1256 txinfo[count].tail = txq->tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001257 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001258 tx_desc = txq->txd + desc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001259 status = le32_to_cpu(tx_desc->status);
1260
1261 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1262 txinfo[count].fw_owned++;
1263 else
1264 txinfo[count].drv_owned++;
1265
1266 if (tx_desc->pkt_len == 0)
1267 txinfo[count].unused++;
1268 }
1269 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001270
1271 return ndescs;
1272}
1273
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001274/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001275 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001276 */
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001277static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001278{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001279 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001280 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001281 u32 count;
1282 unsigned long timeout;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001283
1284 might_sleep();
1285
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001286 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001287 count = priv->pending_tx_pkts;
1288 if (count)
1289 priv->tx_wait = &tx_wait;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001290 spin_unlock_bh(&priv->tx_lock);
1291
1292 if (count) {
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001293 struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001294 int index;
1295 int newcount;
1296
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001297 timeout = wait_for_completion_timeout(&tx_wait,
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001298 msecs_to_jiffies(5000));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001299 if (timeout)
1300 return 0;
1301
1302 spin_lock_bh(&priv->tx_lock);
1303 priv->tx_wait = NULL;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001304 newcount = priv->pending_tx_pkts;
1305 mwl8k_scan_tx_ring(priv, txinfo);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001306 spin_unlock_bh(&priv->tx_lock);
1307
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001308 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001309 __func__, __LINE__, count, newcount);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001310
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001311 for (index = 0; index < MWL8K_TX_QUEUES; index++)
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001312 printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u "
1313 "DRV:%u U:%u\n",
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001314 index,
1315 txinfo[index].len,
1316 txinfo[index].head,
1317 txinfo[index].tail,
1318 txinfo[index].fw_owned,
1319 txinfo[index].drv_owned,
1320 txinfo[index].unused);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001321
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001322 return -ETIMEDOUT;
1323 }
1324
1325 return 0;
1326}
1327
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001328#define MWL8K_TXD_SUCCESS(status) \
1329 ((status) & (MWL8K_TXD_STATUS_OK | \
1330 MWL8K_TXD_STATUS_OK_RETRY | \
1331 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001332
1333static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1334{
1335 struct mwl8k_priv *priv = hw->priv;
1336 struct mwl8k_tx_queue *txq = priv->txq + index;
1337 int wake = 0;
1338
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001339 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001340 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001341 struct mwl8k_tx_desc *tx_desc;
1342 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001343 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001344 struct sk_buff *skb;
1345 struct ieee80211_tx_info *info;
1346 u32 status;
1347
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001348 tx = txq->head;
1349 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001350
1351 status = le32_to_cpu(tx_desc->status);
1352
1353 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1354 if (!force)
1355 break;
1356 tx_desc->status &=
1357 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1358 }
1359
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001360 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1361 BUG_ON(txq->stats.len == 0);
1362 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001363 priv->pending_tx_pkts--;
1364
1365 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001366 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001367 skb = txq->skb[tx];
1368 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001369
1370 BUG_ON(skb == NULL);
1371 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1372
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001373 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001374
1375 /* Mark descriptor as unused */
1376 tx_desc->pkt_phys_addr = 0;
1377 tx_desc->pkt_len = 0;
1378
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001379 info = IEEE80211_SKB_CB(skb);
1380 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001381 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001382 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001383
1384 ieee80211_tx_status_irqsafe(hw, skb);
1385
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001386 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001387 }
1388
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001389 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001390 ieee80211_wake_queue(hw, index);
1391}
1392
1393/* must be called only when the card's transmit is completely halted */
1394static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1395{
1396 struct mwl8k_priv *priv = hw->priv;
1397 struct mwl8k_tx_queue *txq = priv->txq + index;
1398
1399 mwl8k_txq_reclaim(hw, index, 1);
1400
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001401 kfree(txq->skb);
1402 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001403
1404 pci_free_consistent(priv->pdev,
1405 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001406 txq->txd, txq->txd_dma);
1407 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001408}
1409
1410static int
1411mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1412{
1413 struct mwl8k_priv *priv = hw->priv;
1414 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001415 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001416 struct ieee80211_hdr *wh;
1417 struct mwl8k_tx_queue *txq;
1418 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001419 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001420 u32 txstatus;
1421 u8 txdatarate;
1422 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001423
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001424 wh = (struct ieee80211_hdr *)skb->data;
1425 if (ieee80211_is_data_qos(wh->frame_control))
1426 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1427 else
1428 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001429
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001430 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001431 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001432
1433 tx_info = IEEE80211_SKB_CB(skb);
1434 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001435
1436 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1437 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001438
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001439 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1440 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1441 mwl8k_vif->seqno = seqno++ % 4096;
1442 }
1443
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001444 /* Setup firmware control bit fields for each frame type. */
1445 txstatus = 0;
1446 txdatarate = 0;
1447 if (ieee80211_is_mgmt(wh->frame_control) ||
1448 ieee80211_is_ctl(wh->frame_control)) {
1449 txdatarate = 0;
1450 qos = mwl8k_qos_setbit_eosp(qos);
1451 /* Set Queue size to unspecified */
1452 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1453 } else if (ieee80211_is_data(wh->frame_control)) {
1454 txdatarate = 1;
1455 if (is_multicast_ether_addr(wh->addr1))
1456 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1457
1458 /* Send pkt in an aggregate if AMPDU frame. */
1459 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1460 qos = mwl8k_qos_setbit_ack(qos,
1461 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1462 else
1463 qos = mwl8k_qos_setbit_ack(qos,
1464 MWL8K_TXD_ACK_POLICY_NORMAL);
1465
1466 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1467 qos = mwl8k_qos_setbit_amsdu(qos);
1468 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001469
1470 dma = pci_map_single(priv->pdev, skb->data,
1471 skb->len, PCI_DMA_TODEVICE);
1472
1473 if (pci_dma_mapping_error(priv->pdev, dma)) {
1474 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001475 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001476 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001477 return NETDEV_TX_OK;
1478 }
1479
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001480 spin_lock_bh(&priv->tx_lock);
1481
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001482 txq = priv->txq + index;
1483
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001484 BUG_ON(txq->skb[txq->tail] != NULL);
1485 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001486
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001487 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001488 tx->data_rate = txdatarate;
1489 tx->tx_priority = index;
1490 tx->qos_control = cpu_to_le16(qos);
1491 tx->pkt_phys_addr = cpu_to_le32(dma);
1492 tx->pkt_len = cpu_to_le16(skb->len);
1493 tx->rate_info = 0;
1494 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001495 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001496 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1497
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001498 txq->stats.count++;
1499 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001500 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001501
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001502 txq->tail++;
1503 if (txq->tail == MWL8K_TX_DESCS)
1504 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001505
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001506 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001507 ieee80211_stop_queue(hw, index);
1508
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001509 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001510
1511 spin_unlock_bh(&priv->tx_lock);
1512
1513 return NETDEV_TX_OK;
1514}
1515
1516
1517/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001518 * Firmware access.
1519 *
1520 * We have the following requirements for issuing firmware commands:
1521 * - Some commands require that the packet transmit path is idle when
1522 * the command is issued. (For simplicity, we'll just quiesce the
1523 * transmit path for every command.)
1524 * - There are certain sequences of commands that need to be issued to
1525 * the hardware sequentially, with no other intervening commands.
1526 *
1527 * This leads to an implementation of a "firmware lock" as a mutex that
1528 * can be taken recursively, and which is taken by both the low-level
1529 * command submission function (mwl8k_post_cmd) as well as any users of
1530 * that function that require issuing of an atomic sequence of commands,
1531 * and quiesces the transmit path whenever it's taken.
1532 */
1533static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1534{
1535 struct mwl8k_priv *priv = hw->priv;
1536
1537 if (priv->fw_mutex_owner != current) {
1538 int rc;
1539
1540 mutex_lock(&priv->fw_mutex);
1541 ieee80211_stop_queues(hw);
1542
1543 rc = mwl8k_tx_wait_empty(hw);
1544 if (rc) {
1545 ieee80211_wake_queues(hw);
1546 mutex_unlock(&priv->fw_mutex);
1547
1548 return rc;
1549 }
1550
1551 priv->fw_mutex_owner = current;
1552 }
1553
1554 priv->fw_mutex_depth++;
1555
1556 return 0;
1557}
1558
1559static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1560{
1561 struct mwl8k_priv *priv = hw->priv;
1562
1563 if (!--priv->fw_mutex_depth) {
1564 ieee80211_wake_queues(hw);
1565 priv->fw_mutex_owner = NULL;
1566 mutex_unlock(&priv->fw_mutex);
1567 }
1568}
1569
1570
1571/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001572 * Command processing.
1573 */
1574
1575/* Timeout firmware commands after 2000ms */
1576#define MWL8K_CMD_TIMEOUT_MS 2000
1577
1578static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1579{
1580 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1581 struct mwl8k_priv *priv = hw->priv;
1582 void __iomem *regs = priv->regs;
1583 dma_addr_t dma_addr;
1584 unsigned int dma_size;
1585 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001586 unsigned long timeout = 0;
1587 u8 buf[32];
1588
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001589 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001590 dma_size = le16_to_cpu(cmd->length);
1591 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1592 PCI_DMA_BIDIRECTIONAL);
1593 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1594 return -ENOMEM;
1595
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001596 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001597 if (rc) {
1598 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1599 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001600 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001601 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001602
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001603 priv->hostcmd_wait = &cmd_wait;
1604 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1605 iowrite32(MWL8K_H2A_INT_DOORBELL,
1606 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1607 iowrite32(MWL8K_H2A_INT_DUMMY,
1608 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001609
1610 timeout = wait_for_completion_timeout(&cmd_wait,
1611 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1612
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001613 priv->hostcmd_wait = NULL;
1614
1615 mwl8k_fw_unlock(hw);
1616
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001617 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1618 PCI_DMA_BIDIRECTIONAL);
1619
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001620 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001621 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001622 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001623 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1624 MWL8K_CMD_TIMEOUT_MS);
1625 rc = -ETIMEDOUT;
1626 } else {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001627 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001628 if (rc)
1629 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001630 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001631 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001632 le16_to_cpu(cmd->result));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001633 }
1634
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001635 return rc;
1636}
1637
1638/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001639 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001640 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001641struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001642 struct mwl8k_cmd_pkt header;
1643 __u8 hw_rev;
1644 __u8 host_interface;
1645 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001646 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001647 __le16 region_code;
1648 __le32 fw_rev;
1649 __le32 ps_cookie;
1650 __le32 caps;
1651 __u8 mcs_bitmap[16];
1652 __le32 rx_queue_ptr;
1653 __le32 num_tx_queues;
1654 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1655 __le32 caps2;
1656 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001657 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001658} __attribute__((packed));
1659
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001660static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001661{
1662 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001663 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001664 int rc;
1665 int i;
1666
1667 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1668 if (cmd == NULL)
1669 return -ENOMEM;
1670
1671 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1672 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1673
1674 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1675 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001676 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001677 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001678 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001679 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001680 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001681 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001682
1683 rc = mwl8k_post_cmd(hw, &cmd->header);
1684
1685 if (!rc) {
1686 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1687 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001688 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001689 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001690 }
1691
1692 kfree(cmd);
1693 return rc;
1694}
1695
1696/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001697 * CMD_GET_HW_SPEC (AP version).
1698 */
1699struct mwl8k_cmd_get_hw_spec_ap {
1700 struct mwl8k_cmd_pkt header;
1701 __u8 hw_rev;
1702 __u8 host_interface;
1703 __le16 num_wcb;
1704 __le16 num_mcaddrs;
1705 __u8 perm_addr[ETH_ALEN];
1706 __le16 region_code;
1707 __le16 num_antenna;
1708 __le32 fw_rev;
1709 __le32 wcbbase0;
1710 __le32 rxwrptr;
1711 __le32 rxrdptr;
1712 __le32 ps_cookie;
1713 __le32 wcbbase1;
1714 __le32 wcbbase2;
1715 __le32 wcbbase3;
1716} __attribute__((packed));
1717
1718static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1719{
1720 struct mwl8k_priv *priv = hw->priv;
1721 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1722 int rc;
1723
1724 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1725 if (cmd == NULL)
1726 return -ENOMEM;
1727
1728 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1729 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1730
1731 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1732 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1733
1734 rc = mwl8k_post_cmd(hw, &cmd->header);
1735
1736 if (!rc) {
1737 int off;
1738
1739 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1740 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1741 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1742 priv->hw_rev = cmd->hw_rev;
1743
1744 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1745 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1746
1747 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1748 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1749
1750 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1751 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1752
1753 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1754 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1755
1756 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1757 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1758
1759 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1760 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1761 }
1762
1763 kfree(cmd);
1764 return rc;
1765}
1766
1767/*
1768 * CMD_SET_HW_SPEC.
1769 */
1770struct mwl8k_cmd_set_hw_spec {
1771 struct mwl8k_cmd_pkt header;
1772 __u8 hw_rev;
1773 __u8 host_interface;
1774 __le16 num_mcaddrs;
1775 __u8 perm_addr[ETH_ALEN];
1776 __le16 region_code;
1777 __le32 fw_rev;
1778 __le32 ps_cookie;
1779 __le32 caps;
1780 __le32 rx_queue_ptr;
1781 __le32 num_tx_queues;
1782 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1783 __le32 flags;
1784 __le32 num_tx_desc_per_queue;
1785 __le32 total_rxd;
1786} __attribute__((packed));
1787
1788#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1789
1790static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1791{
1792 struct mwl8k_priv *priv = hw->priv;
1793 struct mwl8k_cmd_set_hw_spec *cmd;
1794 int rc;
1795 int i;
1796
1797 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1798 if (cmd == NULL)
1799 return -ENOMEM;
1800
1801 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1802 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1803
1804 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1805 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1806 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1807 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1808 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1809 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1810 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1811 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1812
1813 rc = mwl8k_post_cmd(hw, &cmd->header);
1814 kfree(cmd);
1815
1816 return rc;
1817}
1818
1819/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001820 * CMD_MAC_MULTICAST_ADR.
1821 */
1822struct mwl8k_cmd_mac_multicast_adr {
1823 struct mwl8k_cmd_pkt header;
1824 __le16 action;
1825 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001826 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001827};
1828
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001829#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1830#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1831#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1832#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001833
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001834static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001835__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001836 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001837{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001838 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001839 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001840 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001841
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001842 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001843 allmulti = 1;
1844 mc_count = 0;
1845 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001846
1847 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1848
1849 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001850 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001851 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001852
1853 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1854 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001855 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1856 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001857
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001858 if (allmulti) {
1859 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1860 } else if (mc_count) {
1861 int i;
1862
1863 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1864 cmd->numaddr = cpu_to_le16(mc_count);
1865 for (i = 0; i < mc_count && mclist; i++) {
1866 if (mclist->da_addrlen != ETH_ALEN) {
1867 kfree(cmd);
1868 return NULL;
1869 }
1870 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1871 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001872 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001873 }
1874
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001875 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001876}
1877
1878/*
1879 * CMD_802_11_GET_STAT.
1880 */
1881struct mwl8k_cmd_802_11_get_stat {
1882 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001883 __le32 stats[64];
1884} __attribute__((packed));
1885
1886#define MWL8K_STAT_ACK_FAILURE 9
1887#define MWL8K_STAT_RTS_FAILURE 12
1888#define MWL8K_STAT_FCS_ERROR 24
1889#define MWL8K_STAT_RTS_SUCCESS 11
1890
1891static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1892 struct ieee80211_low_level_stats *stats)
1893{
1894 struct mwl8k_cmd_802_11_get_stat *cmd;
1895 int rc;
1896
1897 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1898 if (cmd == NULL)
1899 return -ENOMEM;
1900
1901 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1902 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001903
1904 rc = mwl8k_post_cmd(hw, &cmd->header);
1905 if (!rc) {
1906 stats->dot11ACKFailureCount =
1907 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1908 stats->dot11RTSFailureCount =
1909 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1910 stats->dot11FCSErrorCount =
1911 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1912 stats->dot11RTSSuccessCount =
1913 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1914 }
1915 kfree(cmd);
1916
1917 return rc;
1918}
1919
1920/*
1921 * CMD_802_11_RADIO_CONTROL.
1922 */
1923struct mwl8k_cmd_802_11_radio_control {
1924 struct mwl8k_cmd_pkt header;
1925 __le16 action;
1926 __le16 control;
1927 __le16 radio_on;
1928} __attribute__((packed));
1929
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001930static int
1931mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001932{
1933 struct mwl8k_priv *priv = hw->priv;
1934 struct mwl8k_cmd_802_11_radio_control *cmd;
1935 int rc;
1936
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001937 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001938 return 0;
1939
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001940 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1941 if (cmd == NULL)
1942 return -ENOMEM;
1943
1944 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1945 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1946 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001947 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001948 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1949
1950 rc = mwl8k_post_cmd(hw, &cmd->header);
1951 kfree(cmd);
1952
1953 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001954 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001955
1956 return rc;
1957}
1958
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001959static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1960{
1961 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1962}
1963
1964static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1965{
1966 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1967}
1968
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001969static int
1970mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1971{
1972 struct mwl8k_priv *priv;
1973
1974 if (hw == NULL || hw->priv == NULL)
1975 return -EINVAL;
1976 priv = hw->priv;
1977
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001978 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001979
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001980 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001981}
1982
1983/*
1984 * CMD_802_11_RF_TX_POWER.
1985 */
1986#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1987
1988struct mwl8k_cmd_802_11_rf_tx_power {
1989 struct mwl8k_cmd_pkt header;
1990 __le16 action;
1991 __le16 support_level;
1992 __le16 current_level;
1993 __le16 reserved;
1994 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1995} __attribute__((packed));
1996
1997static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1998{
1999 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
2000 int rc;
2001
2002 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2003 if (cmd == NULL)
2004 return -ENOMEM;
2005
2006 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2007 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2008 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2009 cmd->support_level = cpu_to_le16(dBm);
2010
2011 rc = mwl8k_post_cmd(hw, &cmd->header);
2012 kfree(cmd);
2013
2014 return rc;
2015}
2016
2017/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002018 * CMD_RF_ANTENNA.
2019 */
2020struct mwl8k_cmd_rf_antenna {
2021 struct mwl8k_cmd_pkt header;
2022 __le16 antenna;
2023 __le16 mode;
2024} __attribute__((packed));
2025
2026#define MWL8K_RF_ANTENNA_RX 1
2027#define MWL8K_RF_ANTENNA_TX 2
2028
2029static int
2030mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2031{
2032 struct mwl8k_cmd_rf_antenna *cmd;
2033 int rc;
2034
2035 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2036 if (cmd == NULL)
2037 return -ENOMEM;
2038
2039 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2040 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2041 cmd->antenna = cpu_to_le16(antenna);
2042 cmd->mode = cpu_to_le16(mask);
2043
2044 rc = mwl8k_post_cmd(hw, &cmd->header);
2045 kfree(cmd);
2046
2047 return rc;
2048}
2049
2050/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002051 * CMD_SET_PRE_SCAN.
2052 */
2053struct mwl8k_cmd_set_pre_scan {
2054 struct mwl8k_cmd_pkt header;
2055} __attribute__((packed));
2056
2057static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2058{
2059 struct mwl8k_cmd_set_pre_scan *cmd;
2060 int rc;
2061
2062 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2063 if (cmd == NULL)
2064 return -ENOMEM;
2065
2066 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2067 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2068
2069 rc = mwl8k_post_cmd(hw, &cmd->header);
2070 kfree(cmd);
2071
2072 return rc;
2073}
2074
2075/*
2076 * CMD_SET_POST_SCAN.
2077 */
2078struct mwl8k_cmd_set_post_scan {
2079 struct mwl8k_cmd_pkt header;
2080 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002081 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002082} __attribute__((packed));
2083
2084static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002085mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002086{
2087 struct mwl8k_cmd_set_post_scan *cmd;
2088 int rc;
2089
2090 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2091 if (cmd == NULL)
2092 return -ENOMEM;
2093
2094 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2095 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2096 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002097 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002098
2099 rc = mwl8k_post_cmd(hw, &cmd->header);
2100 kfree(cmd);
2101
2102 return rc;
2103}
2104
2105/*
2106 * CMD_SET_RF_CHANNEL.
2107 */
2108struct mwl8k_cmd_set_rf_channel {
2109 struct mwl8k_cmd_pkt header;
2110 __le16 action;
2111 __u8 current_channel;
2112 __le32 channel_flags;
2113} __attribute__((packed));
2114
2115static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2116 struct ieee80211_channel *channel)
2117{
2118 struct mwl8k_cmd_set_rf_channel *cmd;
2119 int rc;
2120
2121 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2122 if (cmd == NULL)
2123 return -ENOMEM;
2124
2125 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2126 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2127 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2128 cmd->current_channel = channel->hw_value;
2129 if (channel->band == IEEE80211_BAND_2GHZ)
2130 cmd->channel_flags = cpu_to_le32(0x00000081);
2131 else
2132 cmd->channel_flags = cpu_to_le32(0x00000000);
2133
2134 rc = mwl8k_post_cmd(hw, &cmd->header);
2135 kfree(cmd);
2136
2137 return rc;
2138}
2139
2140/*
2141 * CMD_SET_SLOT.
2142 */
2143struct mwl8k_cmd_set_slot {
2144 struct mwl8k_cmd_pkt header;
2145 __le16 action;
2146 __u8 short_slot;
2147} __attribute__((packed));
2148
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002149static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002150{
2151 struct mwl8k_cmd_set_slot *cmd;
2152 int rc;
2153
2154 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2155 if (cmd == NULL)
2156 return -ENOMEM;
2157
2158 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2159 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2160 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002161 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002162
2163 rc = mwl8k_post_cmd(hw, &cmd->header);
2164 kfree(cmd);
2165
2166 return rc;
2167}
2168
2169/*
2170 * CMD_MIMO_CONFIG.
2171 */
2172struct mwl8k_cmd_mimo_config {
2173 struct mwl8k_cmd_pkt header;
2174 __le32 action;
2175 __u8 rx_antenna_map;
2176 __u8 tx_antenna_map;
2177} __attribute__((packed));
2178
2179static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2180{
2181 struct mwl8k_cmd_mimo_config *cmd;
2182 int rc;
2183
2184 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2185 if (cmd == NULL)
2186 return -ENOMEM;
2187
2188 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2189 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2190 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2191 cmd->rx_antenna_map = rx;
2192 cmd->tx_antenna_map = tx;
2193
2194 rc = mwl8k_post_cmd(hw, &cmd->header);
2195 kfree(cmd);
2196
2197 return rc;
2198}
2199
2200/*
2201 * CMD_ENABLE_SNIFFER.
2202 */
2203struct mwl8k_cmd_enable_sniffer {
2204 struct mwl8k_cmd_pkt header;
2205 __le32 action;
2206} __attribute__((packed));
2207
2208static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2209{
2210 struct mwl8k_cmd_enable_sniffer *cmd;
2211 int rc;
2212
2213 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2214 if (cmd == NULL)
2215 return -ENOMEM;
2216
2217 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2218 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002219 cmd->action = cpu_to_le32(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002220
2221 rc = mwl8k_post_cmd(hw, &cmd->header);
2222 kfree(cmd);
2223
2224 return rc;
2225}
2226
2227/*
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002228 * CMD_SET_MAC_ADDR.
2229 */
2230struct mwl8k_cmd_set_mac_addr {
2231 struct mwl8k_cmd_pkt header;
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002232 union {
2233 struct {
2234 __le16 mac_type;
2235 __u8 mac_addr[ETH_ALEN];
2236 } mbss;
2237 __u8 mac_addr[ETH_ALEN];
2238 };
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002239} __attribute__((packed));
2240
2241static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2242{
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002243 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002244 struct mwl8k_cmd_set_mac_addr *cmd;
2245 int rc;
2246
2247 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2248 if (cmd == NULL)
2249 return -ENOMEM;
2250
2251 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2252 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002253 if (priv->ap_fw) {
2254 cmd->mbss.mac_type = 0;
2255 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2256 } else {
2257 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2258 }
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002259
2260 rc = mwl8k_post_cmd(hw, &cmd->header);
2261 kfree(cmd);
2262
2263 return rc;
2264}
2265
2266
2267/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002268 * CMD_SET_RATEADAPT_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002269 */
2270struct mwl8k_cmd_set_rate_adapt_mode {
2271 struct mwl8k_cmd_pkt header;
2272 __le16 action;
2273 __le16 mode;
2274} __attribute__((packed));
2275
2276static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2277{
2278 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2279 int rc;
2280
2281 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2282 if (cmd == NULL)
2283 return -ENOMEM;
2284
2285 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2286 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2287 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2288 cmd->mode = cpu_to_le16(mode);
2289
2290 rc = mwl8k_post_cmd(hw, &cmd->header);
2291 kfree(cmd);
2292
2293 return rc;
2294}
2295
2296/*
2297 * CMD_SET_WMM_MODE.
2298 */
2299struct mwl8k_cmd_set_wmm {
2300 struct mwl8k_cmd_pkt header;
2301 __le16 action;
2302} __attribute__((packed));
2303
2304static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2305{
2306 struct mwl8k_priv *priv = hw->priv;
2307 struct mwl8k_cmd_set_wmm *cmd;
2308 int rc;
2309
2310 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2311 if (cmd == NULL)
2312 return -ENOMEM;
2313
2314 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2315 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002316 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002317
2318 rc = mwl8k_post_cmd(hw, &cmd->header);
2319 kfree(cmd);
2320
2321 if (!rc)
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002322 priv->wmm_enabled = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002323
2324 return rc;
2325}
2326
2327/*
2328 * CMD_SET_RTS_THRESHOLD.
2329 */
2330struct mwl8k_cmd_rts_threshold {
2331 struct mwl8k_cmd_pkt header;
2332 __le16 action;
2333 __le16 threshold;
2334} __attribute__((packed));
2335
2336static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002337 u16 action, u16 threshold)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002338{
2339 struct mwl8k_cmd_rts_threshold *cmd;
2340 int rc;
2341
2342 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2343 if (cmd == NULL)
2344 return -ENOMEM;
2345
2346 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2347 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2348 cmd->action = cpu_to_le16(action);
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002349 cmd->threshold = cpu_to_le16(threshold);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002350
2351 rc = mwl8k_post_cmd(hw, &cmd->header);
2352 kfree(cmd);
2353
2354 return rc;
2355}
2356
2357/*
2358 * CMD_SET_EDCA_PARAMS.
2359 */
2360struct mwl8k_cmd_set_edca_params {
2361 struct mwl8k_cmd_pkt header;
2362
2363 /* See MWL8K_SET_EDCA_XXX below */
2364 __le16 action;
2365
2366 /* TX opportunity in units of 32 us */
2367 __le16 txop;
2368
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002369 union {
2370 struct {
2371 /* Log exponent of max contention period: 0...15 */
2372 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002373
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002374 /* Log exponent of min contention period: 0...15 */
2375 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002376
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002377 /* Adaptive interframe spacing in units of 32us */
2378 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002379
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002380 /* TX queue to configure */
2381 __u8 txq;
2382 } ap;
2383 struct {
2384 /* Log exponent of max contention period: 0...15 */
2385 __u8 log_cw_max;
2386
2387 /* Log exponent of min contention period: 0...15 */
2388 __u8 log_cw_min;
2389
2390 /* Adaptive interframe spacing in units of 32us */
2391 __u8 aifs;
2392
2393 /* TX queue to configure */
2394 __u8 txq;
2395 } sta;
2396 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002397} __attribute__((packed));
2398
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002399#define MWL8K_SET_EDCA_CW 0x01
2400#define MWL8K_SET_EDCA_TXOP 0x02
2401#define MWL8K_SET_EDCA_AIFS 0x04
2402
2403#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2404 MWL8K_SET_EDCA_TXOP | \
2405 MWL8K_SET_EDCA_AIFS)
2406
2407static int
2408mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2409 __u16 cw_min, __u16 cw_max,
2410 __u8 aifs, __u16 txop)
2411{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002412 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002413 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002414 int rc;
2415
2416 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2417 if (cmd == NULL)
2418 return -ENOMEM;
2419
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002420 /*
2421 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2422 * this call.
2423 */
2424 qnum ^= !(qnum >> 1);
2425
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002426 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2427 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002428 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2429 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002430 if (priv->ap_fw) {
2431 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2432 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2433 cmd->ap.aifs = aifs;
2434 cmd->ap.txq = qnum;
2435 } else {
2436 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2437 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2438 cmd->sta.aifs = aifs;
2439 cmd->sta.txq = qnum;
2440 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002441
2442 rc = mwl8k_post_cmd(hw, &cmd->header);
2443 kfree(cmd);
2444
2445 return rc;
2446}
2447
2448/*
2449 * CMD_FINALIZE_JOIN.
2450 */
2451
2452/* FJ beacon buffer size is compiled into the firmware. */
2453#define MWL8K_FJ_BEACON_MAXLEN 128
2454
2455struct mwl8k_cmd_finalize_join {
2456 struct mwl8k_cmd_pkt header;
2457 __le32 sleep_interval; /* Number of beacon periods to sleep */
2458 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2459} __attribute__((packed));
2460
2461static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2462 __u16 framelen, __u16 dtim)
2463{
2464 struct mwl8k_cmd_finalize_join *cmd;
2465 struct ieee80211_mgmt *payload = frame;
2466 u16 hdrlen;
2467 u32 payload_len;
2468 int rc;
2469
2470 if (frame == NULL)
2471 return -EINVAL;
2472
2473 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2474 if (cmd == NULL)
2475 return -ENOMEM;
2476
2477 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2478 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002479 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002480
2481 hdrlen = ieee80211_hdrlen(payload->frame_control);
2482
2483 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2484
2485 /* XXX TBD Might just have to abort and return an error */
2486 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2487 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002488 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2489 payload_len, MWL8K_FJ_BEACON_MAXLEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002490
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002491 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2492 payload_len = MWL8K_FJ_BEACON_MAXLEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002493
2494 if (payload && payload_len)
2495 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2496
2497 rc = mwl8k_post_cmd(hw, &cmd->header);
2498 kfree(cmd);
2499 return rc;
2500}
2501
2502/*
2503 * CMD_UPDATE_STADB.
2504 */
2505struct mwl8k_cmd_update_sta_db {
2506 struct mwl8k_cmd_pkt header;
2507
2508 /* See STADB_ACTION_TYPE */
2509 __le32 action;
2510
2511 /* Peer MAC address */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002512 __u8 peer_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002513
2514 __le32 reserved;
2515
2516 /* Peer info - valid during add/update. */
2517 struct peer_capability_info peer_info;
2518} __attribute__((packed));
2519
2520static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2521 struct ieee80211_vif *vif, __u32 action)
2522{
2523 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2524 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2525 struct mwl8k_cmd_update_sta_db *cmd;
2526 struct peer_capability_info *peer_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002527 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002528
2529 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2530 if (cmd == NULL)
2531 return -ENOMEM;
2532
2533 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2534 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2535
2536 cmd->action = cpu_to_le32(action);
2537 peer_info = &cmd->peer_info;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002538 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002539
2540 switch (action) {
2541 case MWL8K_STA_DB_ADD_ENTRY:
2542 case MWL8K_STA_DB_MODIFY_ENTRY:
2543 /* Build peer_info block */
2544 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2545 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002546 memcpy(peer_info->legacy_rates, mwl8k_rateids,
2547 sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002548 peer_info->interop = 1;
2549 peer_info->amsdu_enabled = 0;
2550
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002551 rc = mwl8k_post_cmd(hw, &cmd->header);
2552 if (rc == 0)
2553 mv_vif->peer_id = peer_info->station_id;
2554
2555 break;
2556
2557 case MWL8K_STA_DB_DEL_ENTRY:
2558 case MWL8K_STA_DB_FLUSH:
2559 default:
2560 rc = mwl8k_post_cmd(hw, &cmd->header);
2561 if (rc == 0)
2562 mv_vif->peer_id = 0;
2563 break;
2564 }
2565 kfree(cmd);
2566
2567 return rc;
2568}
2569
2570/*
2571 * CMD_SET_AID.
2572 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002573#define MWL8K_FRAME_PROT_DISABLED 0x00
2574#define MWL8K_FRAME_PROT_11G 0x07
2575#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2576#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002577
2578struct mwl8k_cmd_update_set_aid {
2579 struct mwl8k_cmd_pkt header;
2580 __le16 aid;
2581
2582 /* AP's MAC address (BSSID) */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002583 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002584 __le16 protection_mode;
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002585 __u8 supp_rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002586} __attribute__((packed));
2587
2588static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2589 struct ieee80211_vif *vif)
2590{
2591 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2592 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2593 struct mwl8k_cmd_update_set_aid *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002594 u16 prot_mode;
2595 int rc;
2596
2597 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2598 if (cmd == NULL)
2599 return -ENOMEM;
2600
2601 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2602 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2603 cmd->aid = cpu_to_le16(info->aid);
2604
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002605 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002606
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002607 if (info->use_cts_prot) {
2608 prot_mode = MWL8K_FRAME_PROT_11G;
2609 } else {
Johannes Berg9ed6bcc2009-05-08 20:47:39 +02002610 switch (info->ht_operation_mode &
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002611 IEEE80211_HT_OP_MODE_PROTECTION) {
2612 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2613 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2614 break;
2615 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2616 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2617 break;
2618 default:
2619 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2620 break;
2621 }
2622 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002623 cmd->protection_mode = cpu_to_le16(prot_mode);
2624
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002625 memcpy(cmd->supp_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002626
2627 rc = mwl8k_post_cmd(hw, &cmd->header);
2628 kfree(cmd);
2629
2630 return rc;
2631}
2632
2633/*
2634 * CMD_SET_RATE.
2635 */
2636struct mwl8k_cmd_update_rateset {
2637 struct mwl8k_cmd_pkt header;
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002638 __u8 legacy_rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002639
2640 /* Bitmap for supported MCS codes. */
Lennert Buytenhek0b5351a2009-11-30 18:11:18 +01002641 __u8 mcs_set[16];
2642 __u8 reserved[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002643} __attribute__((packed));
2644
2645static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2646 struct ieee80211_vif *vif)
2647{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002648 struct mwl8k_cmd_update_rateset *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002649 int rc;
2650
2651 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2652 if (cmd == NULL)
2653 return -ENOMEM;
2654
2655 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2656 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002657 memcpy(cmd->legacy_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002658
2659 rc = mwl8k_post_cmd(hw, &cmd->header);
2660 kfree(cmd);
2661
2662 return rc;
2663}
2664
2665/*
2666 * CMD_USE_FIXED_RATE.
2667 */
2668#define MWL8K_RATE_TABLE_SIZE 8
2669#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002670#define MWL8K_USE_AUTO_RATE 0x0002
2671
2672struct mwl8k_rate_entry {
2673 /* Set to 1 if HT rate, 0 if legacy. */
2674 __le32 is_ht_rate;
2675
2676 /* Set to 1 to use retry_count field. */
2677 __le32 enable_retry;
2678
2679 /* Specified legacy rate or MCS. */
2680 __le32 rate;
2681
2682 /* Number of allowed retries. */
2683 __le32 retry_count;
2684} __attribute__((packed));
2685
2686struct mwl8k_rate_table {
2687 /* 1 to allow specified rate and below */
2688 __le32 allow_rate_drop;
2689 __le32 num_rates;
2690 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2691} __attribute__((packed));
2692
2693struct mwl8k_cmd_use_fixed_rate {
2694 struct mwl8k_cmd_pkt header;
2695 __le32 action;
2696 struct mwl8k_rate_table rate_table;
2697
2698 /* Unicast, Broadcast or Multicast */
2699 __le32 rate_type;
2700 __le32 reserved1;
2701 __le32 reserved2;
2702} __attribute__((packed));
2703
2704static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2705 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2706{
2707 struct mwl8k_cmd_use_fixed_rate *cmd;
2708 int count;
2709 int rc;
2710
2711 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2712 if (cmd == NULL)
2713 return -ENOMEM;
2714
2715 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2716 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2717
2718 cmd->action = cpu_to_le32(action);
2719 cmd->rate_type = cpu_to_le32(rate_type);
2720
2721 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002722 /*
2723 * Copy over each field manually so that endian
2724 * conversion can be done.
2725 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002726 cmd->rate_table.allow_rate_drop =
2727 cpu_to_le32(rate_table->allow_rate_drop);
2728 cmd->rate_table.num_rates =
2729 cpu_to_le32(rate_table->num_rates);
2730
2731 for (count = 0; count < rate_table->num_rates; count++) {
2732 struct mwl8k_rate_entry *dst =
2733 &cmd->rate_table.rate_entry[count];
2734 struct mwl8k_rate_entry *src =
2735 &rate_table->rate_entry[count];
2736
2737 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2738 dst->enable_retry = cpu_to_le32(src->enable_retry);
2739 dst->rate = cpu_to_le32(src->rate);
2740 dst->retry_count = cpu_to_le32(src->retry_count);
2741 }
2742 }
2743
2744 rc = mwl8k_post_cmd(hw, &cmd->header);
2745 kfree(cmd);
2746
2747 return rc;
2748}
2749
2750
2751/*
2752 * Interrupt handling.
2753 */
2754static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2755{
2756 struct ieee80211_hw *hw = dev_id;
2757 struct mwl8k_priv *priv = hw->priv;
2758 u32 status;
2759
2760 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2761 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2762
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002763 if (!status)
2764 return IRQ_NONE;
2765
2766 if (status & MWL8K_A2H_INT_TX_DONE)
2767 tasklet_schedule(&priv->tx_reclaim_task);
2768
2769 if (status & MWL8K_A2H_INT_RX_READY) {
2770 while (rxq_process(hw, 0, 1))
2771 rxq_refill(hw, 0, 1);
2772 }
2773
2774 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002775 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002776 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002777 }
2778
2779 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002780 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002781 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002782 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002783 }
2784
2785 return IRQ_HANDLED;
2786}
2787
2788
2789/*
2790 * Core driver operations.
2791 */
2792static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2793{
2794 struct mwl8k_priv *priv = hw->priv;
2795 int index = skb_get_queue_mapping(skb);
2796 int rc;
2797
2798 if (priv->current_channel == NULL) {
2799 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002800 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002801 dev_kfree_skb(skb);
2802 return NETDEV_TX_OK;
2803 }
2804
2805 rc = mwl8k_txq_xmit(hw, index, skb);
2806
2807 return rc;
2808}
2809
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002810static int mwl8k_start(struct ieee80211_hw *hw)
2811{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002812 struct mwl8k_priv *priv = hw->priv;
2813 int rc;
2814
Joe Perchesa0607fd2009-11-18 23:29:17 -08002815 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002816 IRQF_SHARED, MWL8K_NAME, hw);
2817 if (rc) {
2818 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002819 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002820 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002821 }
2822
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002823 /* Enable tx reclaim tasklet */
2824 tasklet_enable(&priv->tx_reclaim_task);
2825
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002826 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002827 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002828
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002829 rc = mwl8k_fw_lock(hw);
2830 if (!rc) {
2831 rc = mwl8k_cmd_802_11_radio_enable(hw);
2832
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002833 if (!priv->ap_fw) {
2834 if (!rc)
2835 rc = mwl8k_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002836
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002837 if (!rc)
2838 rc = mwl8k_cmd_set_pre_scan(hw);
2839
2840 if (!rc)
2841 rc = mwl8k_cmd_set_post_scan(hw,
2842 "\x00\x00\x00\x00\x00\x00");
2843 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002844
2845 if (!rc)
2846 rc = mwl8k_cmd_setrateadaptmode(hw, 0);
2847
2848 if (!rc)
2849 rc = mwl8k_set_wmm(hw, 0);
2850
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002851 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002852 }
2853
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002854 if (rc) {
2855 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2856 free_irq(priv->pdev->irq, hw);
2857 tasklet_disable(&priv->tx_reclaim_task);
2858 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002859
2860 return rc;
2861}
2862
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002863static void mwl8k_stop(struct ieee80211_hw *hw)
2864{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002865 struct mwl8k_priv *priv = hw->priv;
2866 int i;
2867
Lennert Buytenhekd3cea0b2009-07-17 07:15:49 +02002868 mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002869
2870 ieee80211_stop_queues(hw);
2871
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002872 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002873 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002874 free_irq(priv->pdev->irq, hw);
2875
2876 /* Stop finalize join worker */
2877 cancel_work_sync(&priv->finalize_join_worker);
2878 if (priv->beacon_skb != NULL)
2879 dev_kfree_skb(priv->beacon_skb);
2880
2881 /* Stop tx reclaim tasklet */
2882 tasklet_disable(&priv->tx_reclaim_task);
2883
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002884 /* Return all skbs to mac80211 */
2885 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2886 mwl8k_txq_reclaim(hw, i, 1);
2887}
2888
2889static int mwl8k_add_interface(struct ieee80211_hw *hw,
2890 struct ieee80211_if_init_conf *conf)
2891{
2892 struct mwl8k_priv *priv = hw->priv;
2893 struct mwl8k_vif *mwl8k_vif;
2894
2895 /*
2896 * We only support one active interface at a time.
2897 */
2898 if (priv->vif != NULL)
2899 return -EBUSY;
2900
2901 /*
2902 * We only support managed interfaces for now.
2903 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002904 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002905 return -EINVAL;
2906
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002907 /*
2908 * Reject interface creation if sniffer mode is active, as
2909 * STA operation is mutually exclusive with hardware sniffer
2910 * mode.
2911 */
2912 if (priv->sniffer_enabled) {
2913 printk(KERN_INFO "%s: unable to create STA "
2914 "interface due to sniffer mode being enabled\n",
2915 wiphy_name(hw->wiphy));
2916 return -EINVAL;
2917 }
2918
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002919 /* Clean out driver private area */
2920 mwl8k_vif = MWL8K_VIF(conf->vif);
2921 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2922
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002923 /* Set and save the mac address */
2924 mwl8k_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002925 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002926
2927 /* Back pointer to parent config block */
2928 mwl8k_vif->priv = priv;
2929
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002930 /* Set Initial sequence number to zero */
2931 mwl8k_vif->seqno = 0;
2932
2933 priv->vif = conf->vif;
2934 priv->current_channel = NULL;
2935
2936 return 0;
2937}
2938
2939static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2940 struct ieee80211_if_init_conf *conf)
2941{
2942 struct mwl8k_priv *priv = hw->priv;
2943
2944 if (priv->vif == NULL)
2945 return;
2946
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002947 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
2948
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002949 priv->vif = NULL;
2950}
2951
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002952static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002953{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002954 struct ieee80211_conf *conf = &hw->conf;
2955 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002956 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002957
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002958 if (conf->flags & IEEE80211_CONF_IDLE) {
2959 mwl8k_cmd_802_11_radio_disable(hw);
2960 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002961 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002962 }
2963
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002964 rc = mwl8k_fw_lock(hw);
2965 if (rc)
2966 return rc;
2967
2968 rc = mwl8k_cmd_802_11_radio_enable(hw);
2969 if (rc)
2970 goto out;
2971
2972 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2973 if (rc)
2974 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002975
2976 priv->current_channel = conf->channel;
2977
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002978 if (conf->power_level > 18)
2979 conf->power_level = 18;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002980 rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level);
2981 if (rc)
2982 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002983
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002984 if (priv->ap_fw) {
2985 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2986 if (!rc)
2987 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2988 } else {
2989 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2990 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002991
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002992out:
2993 mwl8k_fw_unlock(hw);
2994
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002995 return rc;
2996}
2997
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002998static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
2999 struct ieee80211_vif *vif,
3000 struct ieee80211_bss_conf *info,
3001 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003002{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003003 struct mwl8k_priv *priv = hw->priv;
3004 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003005 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003006
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003007 if (changed & BSS_CHANGED_BSSID)
3008 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
3009
3010 if ((changed & BSS_CHANGED_ASSOC) == 0)
3011 return;
3012
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003013 priv->capture_beacon = false;
3014
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003015 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02003016 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003017 return;
3018
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003019 if (info->assoc) {
3020 memcpy(&mwl8k_vif->bss_info, info,
3021 sizeof(struct ieee80211_bss_conf));
3022
3023 /* Install rates */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003024 rc = mwl8k_update_rateset(hw, vif);
3025 if (rc)
3026 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003027
3028 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003029 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3030 MWL8K_UCAST_RATE, NULL);
3031 if (rc)
3032 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003033
3034 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003035 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
3036 if (rc)
3037 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003038
3039 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003040 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
3041 if (rc)
3042 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003043
3044 /* Update peer rate info */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003045 rc = mwl8k_cmd_update_sta_db(hw, vif,
3046 MWL8K_STA_DB_MODIFY_ENTRY);
3047 if (rc)
3048 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003049
3050 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003051 rc = mwl8k_cmd_set_aid(hw, vif);
3052 if (rc)
3053 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003054
3055 /*
3056 * Finalize the join. Tell rx handler to process
3057 * next beacon from our BSSID.
3058 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003059 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003060 priv->capture_beacon = true;
3061 } else {
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003062 rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003063 memset(&mwl8k_vif->bss_info, 0,
3064 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003065 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003066 }
3067
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003068out:
3069 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003070}
3071
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003072static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3073 int mc_count, struct dev_addr_list *mclist)
3074{
3075 struct mwl8k_cmd_pkt *cmd;
3076
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003077 /*
3078 * Synthesize and return a command packet that programs the
3079 * hardware multicast address filter. At this point we don't
3080 * know whether FIF_ALLMULTI is being requested, but if it is,
3081 * we'll end up throwing this packet away and creating a new
3082 * one in mwl8k_configure_filter().
3083 */
3084 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003085
3086 return (unsigned long)cmd;
3087}
3088
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003089static int
3090mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3091 unsigned int changed_flags,
3092 unsigned int *total_flags)
3093{
3094 struct mwl8k_priv *priv = hw->priv;
3095
3096 /*
3097 * Hardware sniffer mode is mutually exclusive with STA
3098 * operation, so refuse to enable sniffer mode if a STA
3099 * interface is active.
3100 */
3101 if (priv->vif != NULL) {
3102 if (net_ratelimit())
3103 printk(KERN_INFO "%s: not enabling sniffer "
3104 "mode because STA interface is active\n",
3105 wiphy_name(hw->wiphy));
3106 return 0;
3107 }
3108
3109 if (!priv->sniffer_enabled) {
3110 if (mwl8k_enable_sniffer(hw, 1))
3111 return 0;
3112 priv->sniffer_enabled = true;
3113 }
3114
3115 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3116 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3117 FIF_OTHER_BSS;
3118
3119 return 1;
3120}
3121
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003122static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3123 unsigned int changed_flags,
3124 unsigned int *total_flags,
3125 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003126{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003127 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003128 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3129
3130 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003131 * AP firmware doesn't allow fine-grained control over
3132 * the receive filter.
3133 */
3134 if (priv->ap_fw) {
3135 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3136 kfree(cmd);
3137 return;
3138 }
3139
3140 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003141 * Enable hardware sniffer mode if FIF_CONTROL or
3142 * FIF_OTHER_BSS is requested.
3143 */
3144 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3145 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3146 kfree(cmd);
3147 return;
3148 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003149
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003150 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003151 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003152
3153 if (mwl8k_fw_lock(hw))
3154 return;
3155
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003156 if (priv->sniffer_enabled) {
3157 mwl8k_enable_sniffer(hw, 0);
3158 priv->sniffer_enabled = false;
3159 }
3160
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003161 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003162 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3163 /*
3164 * Disable the BSS filter.
3165 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003166 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003167 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003168 u8 *bssid;
3169
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003170 /*
3171 * Enable the BSS filter.
3172 *
3173 * If there is an active STA interface, use that
3174 * interface's BSSID, otherwise use a dummy one
3175 * (where the OUI part needs to be nonzero for
3176 * the BSSID to be accepted by POST_SCAN).
3177 */
3178 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003179 if (priv->vif != NULL)
3180 bssid = MWL8K_VIF(priv->vif)->bssid;
3181
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003182 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003183 }
3184 }
3185
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003186 /*
3187 * If FIF_ALLMULTI is being requested, throw away the command
3188 * packet that ->prepare_multicast() built and replace it with
3189 * a command packet that enables reception of all multicast
3190 * packets.
3191 */
3192 if (*total_flags & FIF_ALLMULTI) {
3193 kfree(cmd);
3194 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3195 }
3196
3197 if (cmd != NULL) {
3198 mwl8k_post_cmd(hw, cmd);
3199 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003200 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003201
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003202 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003203}
3204
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003205static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3206{
Lennert Buytenhek733d3062009-07-17 07:24:15 +02003207 return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003208}
3209
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003210static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3211 const struct ieee80211_tx_queue_params *params)
3212{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003213 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003214 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003215
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003216 rc = mwl8k_fw_lock(hw);
3217 if (!rc) {
3218 if (!priv->wmm_enabled)
3219 rc = mwl8k_set_wmm(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003220
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003221 if (!rc)
3222 rc = mwl8k_set_edca_params(hw, queue,
3223 params->cw_min,
3224 params->cw_max,
3225 params->aifs,
3226 params->txop);
3227
3228 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003229 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003230
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003231 return rc;
3232}
3233
3234static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3235 struct ieee80211_tx_queue_stats *stats)
3236{
3237 struct mwl8k_priv *priv = hw->priv;
3238 struct mwl8k_tx_queue *txq;
3239 int index;
3240
3241 spin_lock_bh(&priv->tx_lock);
3242 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3243 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003244 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003245 sizeof(struct ieee80211_tx_queue_stats));
3246 }
3247 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003248
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003249 return 0;
3250}
3251
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003252static int mwl8k_get_stats(struct ieee80211_hw *hw,
3253 struct ieee80211_low_level_stats *stats)
3254{
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003255 return mwl8k_cmd_802_11_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003256}
3257
3258static const struct ieee80211_ops mwl8k_ops = {
3259 .tx = mwl8k_tx,
3260 .start = mwl8k_start,
3261 .stop = mwl8k_stop,
3262 .add_interface = mwl8k_add_interface,
3263 .remove_interface = mwl8k_remove_interface,
3264 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003265 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003266 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003267 .configure_filter = mwl8k_configure_filter,
3268 .set_rts_threshold = mwl8k_set_rts_threshold,
3269 .conf_tx = mwl8k_conf_tx,
3270 .get_tx_stats = mwl8k_get_tx_stats,
3271 .get_stats = mwl8k_get_stats,
3272};
3273
3274static void mwl8k_tx_reclaim_handler(unsigned long data)
3275{
3276 int i;
3277 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3278 struct mwl8k_priv *priv = hw->priv;
3279
3280 spin_lock_bh(&priv->tx_lock);
3281 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3282 mwl8k_txq_reclaim(hw, i, 0);
3283
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003284 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003285 complete(priv->tx_wait);
3286 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003287 }
3288 spin_unlock_bh(&priv->tx_lock);
3289}
3290
3291static void mwl8k_finalize_join_worker(struct work_struct *work)
3292{
3293 struct mwl8k_priv *priv =
3294 container_of(work, struct mwl8k_priv, finalize_join_worker);
3295 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003296 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003297
3298 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3299 dev_kfree_skb(skb);
3300
3301 priv->beacon_skb = NULL;
3302}
3303
John W. Linvillebcb628d2009-11-06 16:40:16 -05003304enum {
3305 MWL8687 = 0,
3306 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003307};
3308
John W. Linvillebcb628d2009-11-06 16:40:16 -05003309static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3310 {
3311 .part_name = "88w8687",
3312 .helper_image = "mwl8k/helper_8687.fw",
3313 .fw_image = "mwl8k/fmimage_8687.fw",
3314 .rxd_ops = &rxd_8687_ops,
3315 .modes = BIT(NL80211_IFTYPE_STATION),
3316 },
3317 {
3318 .part_name = "88w8366",
3319 .helper_image = "mwl8k/helper_8366.fw",
3320 .fw_image = "mwl8k/fmimage_8366.fw",
3321 .rxd_ops = &rxd_8366_ops,
3322 .modes = 0,
3323 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003324};
3325
3326static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003327 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3328 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3329 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3330 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003331};
3332MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3333
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003334static int __devinit mwl8k_probe(struct pci_dev *pdev,
3335 const struct pci_device_id *id)
3336{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003337 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003338 struct ieee80211_hw *hw;
3339 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003340 int rc;
3341 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003342
3343 if (!printed_version) {
3344 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3345 printed_version = 1;
3346 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003347
3348 rc = pci_enable_device(pdev);
3349 if (rc) {
3350 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3351 MWL8K_NAME);
3352 return rc;
3353 }
3354
3355 rc = pci_request_regions(pdev, MWL8K_NAME);
3356 if (rc) {
3357 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3358 MWL8K_NAME);
3359 return rc;
3360 }
3361
3362 pci_set_master(pdev);
3363
3364 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3365 if (hw == NULL) {
3366 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3367 rc = -ENOMEM;
3368 goto err_free_reg;
3369 }
3370
3371 priv = hw->priv;
3372 priv->hw = hw;
3373 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003374 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02003375 priv->rxd_ops = priv->device_info->rxd_ops;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003376 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02003377 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003378 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003379
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003380 SET_IEEE80211_DEV(hw, &pdev->dev);
3381 pci_set_drvdata(pdev, hw);
3382
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003383 priv->sram = pci_iomap(pdev, 0, 0x10000);
3384 if (priv->sram == NULL) {
3385 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003386 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003387 goto err_iounmap;
3388 }
3389
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003390 /*
3391 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3392 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3393 */
3394 priv->regs = pci_iomap(pdev, 1, 0x10000);
3395 if (priv->regs == NULL) {
3396 priv->regs = pci_iomap(pdev, 2, 0x10000);
3397 if (priv->regs == NULL) {
3398 printk(KERN_ERR "%s: Cannot map device registers\n",
3399 wiphy_name(hw->wiphy));
3400 goto err_iounmap;
3401 }
3402 }
3403
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003404 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3405 priv->band.band = IEEE80211_BAND_2GHZ;
3406 priv->band.channels = priv->channels;
3407 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3408 priv->band.bitrates = priv->rates;
3409 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3410 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3411
3412 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3413 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3414
3415 /*
3416 * Extra headroom is the size of the required DMA header
3417 * minus the size of the smallest 802.11 frame (CTS frame).
3418 */
3419 hw->extra_tx_headroom =
3420 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3421
3422 hw->channel_change_time = 10;
3423
3424 hw->queues = MWL8K_TX_QUEUES;
3425
Lennert Buytenhek547810e2009-10-22 20:21:02 +02003426 hw->wiphy->interface_modes = priv->device_info->modes;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003427
3428 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003429 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003430 hw->vif_data_size = sizeof(struct mwl8k_vif);
3431 priv->vif = NULL;
3432
3433 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003434 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003435 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003436
3437 /* Finalize join worker */
3438 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3439
3440 /* TX reclaim tasklet */
3441 tasklet_init(&priv->tx_reclaim_task,
3442 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3443 tasklet_disable(&priv->tx_reclaim_task);
3444
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003445 /* Power management cookie */
3446 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3447 if (priv->cookie == NULL)
3448 goto err_iounmap;
3449
3450 rc = mwl8k_rxq_init(hw, 0);
3451 if (rc)
3452 goto err_iounmap;
3453 rxq_refill(hw, 0, INT_MAX);
3454
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003455 mutex_init(&priv->fw_mutex);
3456 priv->fw_mutex_owner = NULL;
3457 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003458 priv->hostcmd_wait = NULL;
3459
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003460 spin_lock_init(&priv->tx_lock);
3461
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003462 priv->tx_wait = NULL;
3463
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003464 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3465 rc = mwl8k_txq_init(hw, i);
3466 if (rc)
3467 goto err_free_queues;
3468 }
3469
3470 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003471 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003472 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3473 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3474
Joe Perchesa0607fd2009-11-18 23:29:17 -08003475 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003476 IRQF_SHARED, MWL8K_NAME, hw);
3477 if (rc) {
3478 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003479 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003480 goto err_free_queues;
3481 }
3482
3483 /* Reset firmware and hardware */
3484 mwl8k_hw_reset(priv);
3485
3486 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003487 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003488 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003489 printk(KERN_ERR "%s: Firmware files not found\n",
3490 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003491 goto err_free_irq;
3492 }
3493
3494 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003495 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003496 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003497 printk(KERN_ERR "%s: Cannot start firmware\n",
3498 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003499 goto err_stop_firmware;
3500 }
3501
3502 /* Reclaim memory once firmware is successfully loaded */
3503 mwl8k_release_firmware(priv);
3504
3505 /*
3506 * Temporarily enable interrupts. Initial firmware host
3507 * commands use interrupts and avoids polling. Disable
3508 * interrupts when done.
3509 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003510 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003511
3512 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02003513 if (priv->ap_fw) {
3514 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3515 if (!rc)
3516 rc = mwl8k_cmd_set_hw_spec(hw);
3517 } else {
3518 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3519 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003520 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003521 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3522 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003523 goto err_stop_firmware;
3524 }
3525
3526 /* Turn radio off */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003527 rc = mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003528 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003529 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003530 goto err_stop_firmware;
3531 }
3532
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003533 /* Clear MAC address */
3534 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3535 if (rc) {
3536 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3537 wiphy_name(hw->wiphy));
3538 goto err_stop_firmware;
3539 }
3540
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003541 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003542 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003543 free_irq(priv->pdev->irq, hw);
3544
3545 rc = ieee80211_register_hw(hw);
3546 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003547 printk(KERN_ERR "%s: Cannot register device\n",
3548 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003549 goto err_stop_firmware;
3550 }
3551
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003552 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003553 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003554 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003555 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003556 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3557 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003558
3559 return 0;
3560
3561err_stop_firmware:
3562 mwl8k_hw_reset(priv);
3563 mwl8k_release_firmware(priv);
3564
3565err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003566 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003567 free_irq(priv->pdev->irq, hw);
3568
3569err_free_queues:
3570 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3571 mwl8k_txq_deinit(hw, i);
3572 mwl8k_rxq_deinit(hw, 0);
3573
3574err_iounmap:
3575 if (priv->cookie != NULL)
3576 pci_free_consistent(priv->pdev, 4,
3577 priv->cookie, priv->cookie_dma);
3578
3579 if (priv->regs != NULL)
3580 pci_iounmap(pdev, priv->regs);
3581
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003582 if (priv->sram != NULL)
3583 pci_iounmap(pdev, priv->sram);
3584
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003585 pci_set_drvdata(pdev, NULL);
3586 ieee80211_free_hw(hw);
3587
3588err_free_reg:
3589 pci_release_regions(pdev);
3590 pci_disable_device(pdev);
3591
3592 return rc;
3593}
3594
Joerg Albert230f7af2009-04-18 02:10:45 +02003595static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003596{
3597 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3598}
3599
Joerg Albert230f7af2009-04-18 02:10:45 +02003600static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003601{
3602 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3603 struct mwl8k_priv *priv;
3604 int i;
3605
3606 if (hw == NULL)
3607 return;
3608 priv = hw->priv;
3609
3610 ieee80211_stop_queues(hw);
3611
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003612 ieee80211_unregister_hw(hw);
3613
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003614 /* Remove tx reclaim tasklet */
3615 tasklet_kill(&priv->tx_reclaim_task);
3616
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003617 /* Stop hardware */
3618 mwl8k_hw_reset(priv);
3619
3620 /* Return all skbs to mac80211 */
3621 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3622 mwl8k_txq_reclaim(hw, i, 1);
3623
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003624 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3625 mwl8k_txq_deinit(hw, i);
3626
3627 mwl8k_rxq_deinit(hw, 0);
3628
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003629 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003630
3631 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003632 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003633 pci_set_drvdata(pdev, NULL);
3634 ieee80211_free_hw(hw);
3635 pci_release_regions(pdev);
3636 pci_disable_device(pdev);
3637}
3638
3639static struct pci_driver mwl8k_driver = {
3640 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003641 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003642 .probe = mwl8k_probe,
3643 .remove = __devexit_p(mwl8k_remove),
3644 .shutdown = __devexit_p(mwl8k_shutdown),
3645};
3646
3647static int __init mwl8k_init(void)
3648{
3649 return pci_register_driver(&mwl8k_driver);
3650}
3651
3652static void __exit mwl8k_exit(void)
3653{
3654 pci_unregister_driver(&mwl8k_driver);
3655}
3656
3657module_init(mwl8k_init);
3658module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003659
3660MODULE_DESCRIPTION(MWL8K_DESC);
3661MODULE_VERSION(MWL8K_VERSION);
3662MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3663MODULE_LICENSE("GPL");