blob: c1cb20fceaff3552674b0a9a230e65a0e2d16398 [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 Buytenhekd4b705702009-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;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100731 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100732 struct mwl8k_dma_data *tr;
733
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100734 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100735 * Add a firmware DMA header; the firmware requires that we
736 * present a 2-byte payload length followed by a 4-address
737 * header (without QoS field), followed (optionally) by any
738 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100739 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100740 wh = (struct ieee80211_hdr *)skb->data;
741
742 hdrlen = ieee80211_hdrlen(wh->frame_control);
743 if (hdrlen != sizeof(*tr))
744 skb_push(skb, sizeof(*tr) - hdrlen);
745
746 if (ieee80211_is_data_qos(wh->frame_control))
747 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100748
749 tr = (struct mwl8k_dma_data *)skb->data;
750 if (wh != &tr->wh)
751 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100752 if (hdrlen != sizeof(tr->wh))
753 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100754
755 /*
756 * Firmware length is the length of the fully formed "802.11
757 * payload". That is, everything except for the 802.11 header.
758 * This includes all crypto material including the MIC.
759 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100760 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100761}
762
763
764/*
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200765 * Packet reception for 88w8366.
766 */
767struct mwl8k_rxd_8366 {
768 __le16 pkt_len;
769 __u8 sq2;
770 __u8 rate;
771 __le32 pkt_phys_addr;
772 __le32 next_rxd_phys_addr;
773 __le16 qos_control;
774 __le16 htsig2;
775 __le32 hw_rssi_info;
776 __le32 hw_noise_floor_info;
777 __u8 noise_floor;
778 __u8 pad0[3];
779 __u8 rssi;
780 __u8 rx_status;
781 __u8 channel;
782 __u8 rx_ctrl;
783} __attribute__((packed));
784
785#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
786
787static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
788{
789 struct mwl8k_rxd_8366 *rxd = _rxd;
790
791 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
792 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
793}
794
795static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
796{
797 struct mwl8k_rxd_8366 *rxd = _rxd;
798
799 rxd->pkt_len = cpu_to_le16(len);
800 rxd->pkt_phys_addr = cpu_to_le32(addr);
801 wmb();
802 rxd->rx_ctrl = 0;
803}
804
805static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100806mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status,
807 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200808{
809 struct mwl8k_rxd_8366 *rxd = _rxd;
810
811 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
812 return -1;
813 rmb();
814
815 memset(status, 0, sizeof(*status));
816
817 status->signal = -rxd->rssi;
818 status->noise = -rxd->noise_floor;
819
820 if (rxd->rate & 0x80) {
821 status->flag |= RX_FLAG_HT;
822 status->rate_idx = rxd->rate & 0x7f;
823 } else {
824 int i;
825
826 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
827 if (mwl8k_rates[i].hw_value == rxd->rate) {
828 status->rate_idx = i;
829 break;
830 }
831 }
832 }
833
834 status->band = IEEE80211_BAND_2GHZ;
835 status->freq = ieee80211_channel_to_frequency(rxd->channel);
836
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100837 *qos = rxd->qos_control;
838
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200839 return le16_to_cpu(rxd->pkt_len);
840}
841
842static struct rxd_ops rxd_8366_ops = {
843 .rxd_size = sizeof(struct mwl8k_rxd_8366),
844 .rxd_init = mwl8k_rxd_8366_init,
845 .rxd_refill = mwl8k_rxd_8366_refill,
846 .rxd_process = mwl8k_rxd_8366_process,
847};
848
849/*
850 * Packet reception for 88w8687.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100851 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200852struct mwl8k_rxd_8687 {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100853 __le16 pkt_len;
854 __u8 link_quality;
855 __u8 noise_level;
856 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200857 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100858 __le16 qos_control;
859 __le16 rate_info;
860 __le32 pad0[4];
861 __u8 rssi;
862 __u8 channel;
863 __le16 pad1;
864 __u8 rx_ctrl;
865 __u8 rx_status;
866 __u8 pad2[2];
867} __attribute__((packed));
868
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200869#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
870#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
871#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
872#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
873#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
874#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
875
876#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
877
878static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
879{
880 struct mwl8k_rxd_8687 *rxd = _rxd;
881
882 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
883 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
884}
885
886static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
887{
888 struct mwl8k_rxd_8687 *rxd = _rxd;
889
890 rxd->pkt_len = cpu_to_le16(len);
891 rxd->pkt_phys_addr = cpu_to_le32(addr);
892 wmb();
893 rxd->rx_ctrl = 0;
894}
895
896static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100897mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status,
898 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200899{
900 struct mwl8k_rxd_8687 *rxd = _rxd;
901 u16 rate_info;
902
903 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
904 return -1;
905 rmb();
906
907 rate_info = le16_to_cpu(rxd->rate_info);
908
909 memset(status, 0, sizeof(*status));
910
911 status->signal = -rxd->rssi;
912 status->noise = -rxd->noise_level;
913 status->qual = rxd->link_quality;
914 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
915 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
916
917 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
918 status->flag |= RX_FLAG_SHORTPRE;
919 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
920 status->flag |= RX_FLAG_40MHZ;
921 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
922 status->flag |= RX_FLAG_SHORT_GI;
923 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
924 status->flag |= RX_FLAG_HT;
925
926 status->band = IEEE80211_BAND_2GHZ;
927 status->freq = ieee80211_channel_to_frequency(rxd->channel);
928
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100929 *qos = rxd->qos_control;
930
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200931 return le16_to_cpu(rxd->pkt_len);
932}
933
934static struct rxd_ops rxd_8687_ops = {
935 .rxd_size = sizeof(struct mwl8k_rxd_8687),
936 .rxd_init = mwl8k_rxd_8687_init,
937 .rxd_refill = mwl8k_rxd_8687_refill,
938 .rxd_process = mwl8k_rxd_8687_process,
939};
940
941
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100942#define MWL8K_RX_DESCS 256
943#define MWL8K_RX_MAXSZ 3800
944
945static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
946{
947 struct mwl8k_priv *priv = hw->priv;
948 struct mwl8k_rx_queue *rxq = priv->rxq + index;
949 int size;
950 int i;
951
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200952 rxq->rxd_count = 0;
953 rxq->head = 0;
954 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100955
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200956 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100957
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200958 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
959 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100960 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200961 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100962 return -ENOMEM;
963 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200964 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100965
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200966 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
967 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100968 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200969 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200970 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100971 return -ENOMEM;
972 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200973 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100974
975 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200976 int desc_size;
977 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100978 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200979 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100980
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200981 desc_size = priv->rxd_ops->rxd_size;
982 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100983
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200984 nexti = i + 1;
985 if (nexti == MWL8K_RX_DESCS)
986 nexti = 0;
987 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
988
989 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100990 }
991
992 return 0;
993}
994
995static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
996{
997 struct mwl8k_priv *priv = hw->priv;
998 struct mwl8k_rx_queue *rxq = priv->rxq + index;
999 int refilled;
1000
1001 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001002 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001003 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001004 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001005 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001006 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001007
1008 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1009 if (skb == NULL)
1010 break;
1011
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001012 addr = pci_map_single(priv->pdev, skb->data,
1013 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001014
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001015 rxq->rxd_count++;
1016 rx = rxq->tail++;
1017 if (rxq->tail == MWL8K_RX_DESCS)
1018 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001019 rxq->buf[rx].skb = skb;
1020 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001021
1022 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1023 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001024
1025 refilled++;
1026 }
1027
1028 return refilled;
1029}
1030
1031/* Must be called only when the card's reception is completely halted */
1032static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1033{
1034 struct mwl8k_priv *priv = hw->priv;
1035 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1036 int i;
1037
1038 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001039 if (rxq->buf[i].skb != NULL) {
1040 pci_unmap_single(priv->pdev,
1041 pci_unmap_addr(&rxq->buf[i], dma),
1042 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1043 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001044
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001045 kfree_skb(rxq->buf[i].skb);
1046 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001047 }
1048 }
1049
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001050 kfree(rxq->buf);
1051 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001052
1053 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001054 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001055 rxq->rxd, rxq->rxd_dma);
1056 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001057}
1058
1059
1060/*
1061 * Scan a list of BSSIDs to process for finalize join.
1062 * Allows for extension to process multiple BSSIDs.
1063 */
1064static inline int
1065mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1066{
1067 return priv->capture_beacon &&
1068 ieee80211_is_beacon(wh->frame_control) &&
1069 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1070}
1071
Lennert Buytenhek37797522009-10-22 20:19:45 +02001072static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1073 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001074{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001075 struct mwl8k_priv *priv = hw->priv;
1076
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001077 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001078 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001079
1080 /*
1081 * Use GFP_ATOMIC as rxq_process is called from
1082 * the primary interrupt handler, memory allocation call
1083 * must not sleep.
1084 */
1085 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1086 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001087 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001088}
1089
1090static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1091{
1092 struct mwl8k_priv *priv = hw->priv;
1093 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1094 int processed;
1095
1096 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001097 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001098 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001099 void *rxd;
1100 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001101 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001102 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001103
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001104 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001105 if (skb == NULL)
1106 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001107
1108 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1109
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001110 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001111 if (pkt_len < 0)
1112 break;
1113
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001114 rxq->buf[rxq->head].skb = NULL;
1115
1116 pci_unmap_single(priv->pdev,
1117 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1118 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1119 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001120
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001121 rxq->head++;
1122 if (rxq->head == MWL8K_RX_DESCS)
1123 rxq->head = 0;
1124
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001125 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001126
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001127 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001128 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001129
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001130 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001131 * Check for a pending join operation. Save a
1132 * copy of the beacon and schedule a tasklet to
1133 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001134 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001135 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001136 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001137
Johannes Bergf1d58c22009-06-17 13:13:00 +02001138 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1139 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001140
1141 processed++;
1142 }
1143
1144 return processed;
1145}
1146
1147
1148/*
1149 * Packet transmission.
1150 */
1151
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001152/* Transmit packet ACK policy */
1153#define MWL8K_TXD_ACK_POLICY_NORMAL 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001154#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1155
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001156#define MWL8K_TXD_STATUS_OK 0x00000001
1157#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1158#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1159#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001160#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001161
1162struct mwl8k_tx_desc {
1163 __le32 status;
1164 __u8 data_rate;
1165 __u8 tx_priority;
1166 __le16 qos_control;
1167 __le32 pkt_phys_addr;
1168 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001169 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001170 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001171 __le32 reserved;
1172 __le16 rate_info;
1173 __u8 peer_id;
1174 __u8 tx_frag_cnt;
1175} __attribute__((packed));
1176
1177#define MWL8K_TX_DESCS 128
1178
1179static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1180{
1181 struct mwl8k_priv *priv = hw->priv;
1182 struct mwl8k_tx_queue *txq = priv->txq + index;
1183 int size;
1184 int i;
1185
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001186 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1187 txq->stats.limit = MWL8K_TX_DESCS;
1188 txq->head = 0;
1189 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001190
1191 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1192
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001193 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1194 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001195 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001196 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001197 return -ENOMEM;
1198 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001199 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001200
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001201 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1202 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001204 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001205 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001206 return -ENOMEM;
1207 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001208 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001209
1210 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1211 struct mwl8k_tx_desc *tx_desc;
1212 int nexti;
1213
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001214 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001215 nexti = (i + 1) % MWL8K_TX_DESCS;
1216
1217 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001218 tx_desc->next_txd_phys_addr =
1219 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001220 }
1221
1222 return 0;
1223}
1224
1225static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1226{
1227 iowrite32(MWL8K_H2A_INT_PPA_READY,
1228 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1229 iowrite32(MWL8K_H2A_INT_DUMMY,
1230 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1231 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1232}
1233
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001234struct mwl8k_txq_info {
1235 u32 fw_owned;
1236 u32 drv_owned;
1237 u32 unused;
1238 u32 len;
1239 u32 head;
1240 u32 tail;
1241};
1242
1243static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001244 struct mwl8k_txq_info *txinfo)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001245{
1246 int count, desc, status;
1247 struct mwl8k_tx_queue *txq;
1248 struct mwl8k_tx_desc *tx_desc;
1249 int ndescs = 0;
1250
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001251 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
1252
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001253 for (count = 0; count < MWL8K_TX_QUEUES; count++) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001254 txq = priv->txq + count;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001255 txinfo[count].len = txq->stats.len;
1256 txinfo[count].head = txq->head;
1257 txinfo[count].tail = txq->tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001258 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001259 tx_desc = txq->txd + desc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001260 status = le32_to_cpu(tx_desc->status);
1261
1262 if (status & MWL8K_TXD_STATUS_FW_OWNED)
1263 txinfo[count].fw_owned++;
1264 else
1265 txinfo[count].drv_owned++;
1266
1267 if (tx_desc->pkt_len == 0)
1268 txinfo[count].unused++;
1269 }
1270 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001271
1272 return ndescs;
1273}
1274
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001275/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001276 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001277 */
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001278static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001279{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001280 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001281 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001282 u32 count;
1283 unsigned long timeout;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001284
1285 might_sleep();
1286
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001287 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001288 count = priv->pending_tx_pkts;
1289 if (count)
1290 priv->tx_wait = &tx_wait;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001291 spin_unlock_bh(&priv->tx_lock);
1292
1293 if (count) {
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001294 struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001295 int index;
1296 int newcount;
1297
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001298 timeout = wait_for_completion_timeout(&tx_wait,
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001299 msecs_to_jiffies(5000));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001300 if (timeout)
1301 return 0;
1302
1303 spin_lock_bh(&priv->tx_lock);
1304 priv->tx_wait = NULL;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001305 newcount = priv->pending_tx_pkts;
1306 mwl8k_scan_tx_ring(priv, txinfo);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001307 spin_unlock_bh(&priv->tx_lock);
1308
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001309 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001310 __func__, __LINE__, count, newcount);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001311
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001312 for (index = 0; index < MWL8K_TX_QUEUES; index++)
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001313 printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u "
1314 "DRV:%u U:%u\n",
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001315 index,
1316 txinfo[index].len,
1317 txinfo[index].head,
1318 txinfo[index].tail,
1319 txinfo[index].fw_owned,
1320 txinfo[index].drv_owned,
1321 txinfo[index].unused);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001322
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001323 return -ETIMEDOUT;
1324 }
1325
1326 return 0;
1327}
1328
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001329#define MWL8K_TXD_SUCCESS(status) \
1330 ((status) & (MWL8K_TXD_STATUS_OK | \
1331 MWL8K_TXD_STATUS_OK_RETRY | \
1332 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001333
1334static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1335{
1336 struct mwl8k_priv *priv = hw->priv;
1337 struct mwl8k_tx_queue *txq = priv->txq + index;
1338 int wake = 0;
1339
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001340 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001341 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001342 struct mwl8k_tx_desc *tx_desc;
1343 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001344 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001345 struct sk_buff *skb;
1346 struct ieee80211_tx_info *info;
1347 u32 status;
1348
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001349 tx = txq->head;
1350 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001351
1352 status = le32_to_cpu(tx_desc->status);
1353
1354 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1355 if (!force)
1356 break;
1357 tx_desc->status &=
1358 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1359 }
1360
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001361 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1362 BUG_ON(txq->stats.len == 0);
1363 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001364 priv->pending_tx_pkts--;
1365
1366 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001367 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001368 skb = txq->skb[tx];
1369 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001370
1371 BUG_ON(skb == NULL);
1372 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1373
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001374 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001375
1376 /* Mark descriptor as unused */
1377 tx_desc->pkt_phys_addr = 0;
1378 tx_desc->pkt_len = 0;
1379
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001380 info = IEEE80211_SKB_CB(skb);
1381 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001382 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001383 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001384
1385 ieee80211_tx_status_irqsafe(hw, skb);
1386
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001387 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001388 }
1389
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001390 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001391 ieee80211_wake_queue(hw, index);
1392}
1393
1394/* must be called only when the card's transmit is completely halted */
1395static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1396{
1397 struct mwl8k_priv *priv = hw->priv;
1398 struct mwl8k_tx_queue *txq = priv->txq + index;
1399
1400 mwl8k_txq_reclaim(hw, index, 1);
1401
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001402 kfree(txq->skb);
1403 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001404
1405 pci_free_consistent(priv->pdev,
1406 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001407 txq->txd, txq->txd_dma);
1408 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001409}
1410
1411static int
1412mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1413{
1414 struct mwl8k_priv *priv = hw->priv;
1415 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001416 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001417 struct ieee80211_hdr *wh;
1418 struct mwl8k_tx_queue *txq;
1419 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001420 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001421 u32 txstatus;
1422 u8 txdatarate;
1423 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001424
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001425 wh = (struct ieee80211_hdr *)skb->data;
1426 if (ieee80211_is_data_qos(wh->frame_control))
1427 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1428 else
1429 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001430
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001431 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001432 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001433
1434 tx_info = IEEE80211_SKB_CB(skb);
1435 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001436
1437 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1438 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001439
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001440 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1441 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1442 mwl8k_vif->seqno = seqno++ % 4096;
1443 }
1444
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001445 /* Setup firmware control bit fields for each frame type. */
1446 txstatus = 0;
1447 txdatarate = 0;
1448 if (ieee80211_is_mgmt(wh->frame_control) ||
1449 ieee80211_is_ctl(wh->frame_control)) {
1450 txdatarate = 0;
1451 qos = mwl8k_qos_setbit_eosp(qos);
1452 /* Set Queue size to unspecified */
1453 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1454 } else if (ieee80211_is_data(wh->frame_control)) {
1455 txdatarate = 1;
1456 if (is_multicast_ether_addr(wh->addr1))
1457 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1458
1459 /* Send pkt in an aggregate if AMPDU frame. */
1460 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1461 qos = mwl8k_qos_setbit_ack(qos,
1462 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1463 else
1464 qos = mwl8k_qos_setbit_ack(qos,
1465 MWL8K_TXD_ACK_POLICY_NORMAL);
1466
1467 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1468 qos = mwl8k_qos_setbit_amsdu(qos);
1469 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001470
1471 dma = pci_map_single(priv->pdev, skb->data,
1472 skb->len, PCI_DMA_TODEVICE);
1473
1474 if (pci_dma_mapping_error(priv->pdev, dma)) {
1475 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001476 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001477 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001478 return NETDEV_TX_OK;
1479 }
1480
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001481 spin_lock_bh(&priv->tx_lock);
1482
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001483 txq = priv->txq + index;
1484
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001485 BUG_ON(txq->skb[txq->tail] != NULL);
1486 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001487
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001488 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001489 tx->data_rate = txdatarate;
1490 tx->tx_priority = index;
1491 tx->qos_control = cpu_to_le16(qos);
1492 tx->pkt_phys_addr = cpu_to_le32(dma);
1493 tx->pkt_len = cpu_to_le16(skb->len);
1494 tx->rate_info = 0;
1495 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001496 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001497 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1498
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001499 txq->stats.count++;
1500 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001501 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001502
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001503 txq->tail++;
1504 if (txq->tail == MWL8K_TX_DESCS)
1505 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001506
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001507 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001508 ieee80211_stop_queue(hw, index);
1509
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001510 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001511
1512 spin_unlock_bh(&priv->tx_lock);
1513
1514 return NETDEV_TX_OK;
1515}
1516
1517
1518/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001519 * Firmware access.
1520 *
1521 * We have the following requirements for issuing firmware commands:
1522 * - Some commands require that the packet transmit path is idle when
1523 * the command is issued. (For simplicity, we'll just quiesce the
1524 * transmit path for every command.)
1525 * - There are certain sequences of commands that need to be issued to
1526 * the hardware sequentially, with no other intervening commands.
1527 *
1528 * This leads to an implementation of a "firmware lock" as a mutex that
1529 * can be taken recursively, and which is taken by both the low-level
1530 * command submission function (mwl8k_post_cmd) as well as any users of
1531 * that function that require issuing of an atomic sequence of commands,
1532 * and quiesces the transmit path whenever it's taken.
1533 */
1534static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1535{
1536 struct mwl8k_priv *priv = hw->priv;
1537
1538 if (priv->fw_mutex_owner != current) {
1539 int rc;
1540
1541 mutex_lock(&priv->fw_mutex);
1542 ieee80211_stop_queues(hw);
1543
1544 rc = mwl8k_tx_wait_empty(hw);
1545 if (rc) {
1546 ieee80211_wake_queues(hw);
1547 mutex_unlock(&priv->fw_mutex);
1548
1549 return rc;
1550 }
1551
1552 priv->fw_mutex_owner = current;
1553 }
1554
1555 priv->fw_mutex_depth++;
1556
1557 return 0;
1558}
1559
1560static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1561{
1562 struct mwl8k_priv *priv = hw->priv;
1563
1564 if (!--priv->fw_mutex_depth) {
1565 ieee80211_wake_queues(hw);
1566 priv->fw_mutex_owner = NULL;
1567 mutex_unlock(&priv->fw_mutex);
1568 }
1569}
1570
1571
1572/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001573 * Command processing.
1574 */
1575
1576/* Timeout firmware commands after 2000ms */
1577#define MWL8K_CMD_TIMEOUT_MS 2000
1578
1579static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1580{
1581 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1582 struct mwl8k_priv *priv = hw->priv;
1583 void __iomem *regs = priv->regs;
1584 dma_addr_t dma_addr;
1585 unsigned int dma_size;
1586 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001587 unsigned long timeout = 0;
1588 u8 buf[32];
1589
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001590 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001591 dma_size = le16_to_cpu(cmd->length);
1592 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1593 PCI_DMA_BIDIRECTIONAL);
1594 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1595 return -ENOMEM;
1596
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001597 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001598 if (rc) {
1599 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1600 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001601 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001602 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001603
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001604 priv->hostcmd_wait = &cmd_wait;
1605 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1606 iowrite32(MWL8K_H2A_INT_DOORBELL,
1607 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1608 iowrite32(MWL8K_H2A_INT_DUMMY,
1609 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001610
1611 timeout = wait_for_completion_timeout(&cmd_wait,
1612 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1613
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001614 priv->hostcmd_wait = NULL;
1615
1616 mwl8k_fw_unlock(hw);
1617
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001618 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1619 PCI_DMA_BIDIRECTIONAL);
1620
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001621 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001622 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001623 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001624 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1625 MWL8K_CMD_TIMEOUT_MS);
1626 rc = -ETIMEDOUT;
1627 } else {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001628 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001629 if (rc)
1630 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001631 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001632 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001633 le16_to_cpu(cmd->result));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001634 }
1635
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001636 return rc;
1637}
1638
1639/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001640 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001641 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001642struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001643 struct mwl8k_cmd_pkt header;
1644 __u8 hw_rev;
1645 __u8 host_interface;
1646 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001647 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001648 __le16 region_code;
1649 __le32 fw_rev;
1650 __le32 ps_cookie;
1651 __le32 caps;
1652 __u8 mcs_bitmap[16];
1653 __le32 rx_queue_ptr;
1654 __le32 num_tx_queues;
1655 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1656 __le32 caps2;
1657 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001658 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001659} __attribute__((packed));
1660
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001661static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001662{
1663 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001664 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001665 int rc;
1666 int i;
1667
1668 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1669 if (cmd == NULL)
1670 return -ENOMEM;
1671
1672 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1673 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1674
1675 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1676 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001677 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001678 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001679 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001680 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001681 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001682 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001683
1684 rc = mwl8k_post_cmd(hw, &cmd->header);
1685
1686 if (!rc) {
1687 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1688 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001689 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001690 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001691 }
1692
1693 kfree(cmd);
1694 return rc;
1695}
1696
1697/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001698 * CMD_GET_HW_SPEC (AP version).
1699 */
1700struct mwl8k_cmd_get_hw_spec_ap {
1701 struct mwl8k_cmd_pkt header;
1702 __u8 hw_rev;
1703 __u8 host_interface;
1704 __le16 num_wcb;
1705 __le16 num_mcaddrs;
1706 __u8 perm_addr[ETH_ALEN];
1707 __le16 region_code;
1708 __le16 num_antenna;
1709 __le32 fw_rev;
1710 __le32 wcbbase0;
1711 __le32 rxwrptr;
1712 __le32 rxrdptr;
1713 __le32 ps_cookie;
1714 __le32 wcbbase1;
1715 __le32 wcbbase2;
1716 __le32 wcbbase3;
1717} __attribute__((packed));
1718
1719static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1720{
1721 struct mwl8k_priv *priv = hw->priv;
1722 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1723 int rc;
1724
1725 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1726 if (cmd == NULL)
1727 return -ENOMEM;
1728
1729 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1730 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1731
1732 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1733 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1734
1735 rc = mwl8k_post_cmd(hw, &cmd->header);
1736
1737 if (!rc) {
1738 int off;
1739
1740 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1741 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1742 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1743 priv->hw_rev = cmd->hw_rev;
1744
1745 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1746 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1747
1748 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1749 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1750
1751 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1752 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1753
1754 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1755 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1756
1757 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1758 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1759
1760 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1761 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1762 }
1763
1764 kfree(cmd);
1765 return rc;
1766}
1767
1768/*
1769 * CMD_SET_HW_SPEC.
1770 */
1771struct mwl8k_cmd_set_hw_spec {
1772 struct mwl8k_cmd_pkt header;
1773 __u8 hw_rev;
1774 __u8 host_interface;
1775 __le16 num_mcaddrs;
1776 __u8 perm_addr[ETH_ALEN];
1777 __le16 region_code;
1778 __le32 fw_rev;
1779 __le32 ps_cookie;
1780 __le32 caps;
1781 __le32 rx_queue_ptr;
1782 __le32 num_tx_queues;
1783 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1784 __le32 flags;
1785 __le32 num_tx_desc_per_queue;
1786 __le32 total_rxd;
1787} __attribute__((packed));
1788
1789#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1790
1791static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1792{
1793 struct mwl8k_priv *priv = hw->priv;
1794 struct mwl8k_cmd_set_hw_spec *cmd;
1795 int rc;
1796 int i;
1797
1798 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1799 if (cmd == NULL)
1800 return -ENOMEM;
1801
1802 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1803 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1804
1805 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1806 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1807 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1808 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1809 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1810 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1811 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1812 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1813
1814 rc = mwl8k_post_cmd(hw, &cmd->header);
1815 kfree(cmd);
1816
1817 return rc;
1818}
1819
1820/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001821 * CMD_MAC_MULTICAST_ADR.
1822 */
1823struct mwl8k_cmd_mac_multicast_adr {
1824 struct mwl8k_cmd_pkt header;
1825 __le16 action;
1826 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001827 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001828};
1829
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001830#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1831#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1832#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1833#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001834
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001835static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001836__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001837 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001838{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001839 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001840 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001841 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001842
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001843 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001844 allmulti = 1;
1845 mc_count = 0;
1846 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001847
1848 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1849
1850 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001851 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001852 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001853
1854 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1855 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001856 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1857 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001858
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001859 if (allmulti) {
1860 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1861 } else if (mc_count) {
1862 int i;
1863
1864 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1865 cmd->numaddr = cpu_to_le16(mc_count);
1866 for (i = 0; i < mc_count && mclist; i++) {
1867 if (mclist->da_addrlen != ETH_ALEN) {
1868 kfree(cmd);
1869 return NULL;
1870 }
1871 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1872 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001873 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001874 }
1875
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001876 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001877}
1878
1879/*
1880 * CMD_802_11_GET_STAT.
1881 */
1882struct mwl8k_cmd_802_11_get_stat {
1883 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001884 __le32 stats[64];
1885} __attribute__((packed));
1886
1887#define MWL8K_STAT_ACK_FAILURE 9
1888#define MWL8K_STAT_RTS_FAILURE 12
1889#define MWL8K_STAT_FCS_ERROR 24
1890#define MWL8K_STAT_RTS_SUCCESS 11
1891
1892static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1893 struct ieee80211_low_level_stats *stats)
1894{
1895 struct mwl8k_cmd_802_11_get_stat *cmd;
1896 int rc;
1897
1898 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1899 if (cmd == NULL)
1900 return -ENOMEM;
1901
1902 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1903 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001904
1905 rc = mwl8k_post_cmd(hw, &cmd->header);
1906 if (!rc) {
1907 stats->dot11ACKFailureCount =
1908 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1909 stats->dot11RTSFailureCount =
1910 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1911 stats->dot11FCSErrorCount =
1912 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1913 stats->dot11RTSSuccessCount =
1914 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1915 }
1916 kfree(cmd);
1917
1918 return rc;
1919}
1920
1921/*
1922 * CMD_802_11_RADIO_CONTROL.
1923 */
1924struct mwl8k_cmd_802_11_radio_control {
1925 struct mwl8k_cmd_pkt header;
1926 __le16 action;
1927 __le16 control;
1928 __le16 radio_on;
1929} __attribute__((packed));
1930
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001931static int
1932mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001933{
1934 struct mwl8k_priv *priv = hw->priv;
1935 struct mwl8k_cmd_802_11_radio_control *cmd;
1936 int rc;
1937
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001938 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001939 return 0;
1940
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001941 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1942 if (cmd == NULL)
1943 return -ENOMEM;
1944
1945 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1946 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1947 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001948 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001949 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1950
1951 rc = mwl8k_post_cmd(hw, &cmd->header);
1952 kfree(cmd);
1953
1954 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001955 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001956
1957 return rc;
1958}
1959
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001960static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw)
1961{
1962 return mwl8k_cmd_802_11_radio_control(hw, 0, 0);
1963}
1964
1965static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw)
1966{
1967 return mwl8k_cmd_802_11_radio_control(hw, 1, 0);
1968}
1969
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001970static int
1971mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1972{
1973 struct mwl8k_priv *priv;
1974
1975 if (hw == NULL || hw->priv == NULL)
1976 return -EINVAL;
1977 priv = hw->priv;
1978
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001979 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001980
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001981 return mwl8k_cmd_802_11_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001982}
1983
1984/*
1985 * CMD_802_11_RF_TX_POWER.
1986 */
1987#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1988
1989struct mwl8k_cmd_802_11_rf_tx_power {
1990 struct mwl8k_cmd_pkt header;
1991 __le16 action;
1992 __le16 support_level;
1993 __le16 current_level;
1994 __le16 reserved;
1995 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1996} __attribute__((packed));
1997
1998static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1999{
2000 struct mwl8k_cmd_802_11_rf_tx_power *cmd;
2001 int rc;
2002
2003 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2004 if (cmd == NULL)
2005 return -ENOMEM;
2006
2007 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2008 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2009 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2010 cmd->support_level = cpu_to_le16(dBm);
2011
2012 rc = mwl8k_post_cmd(hw, &cmd->header);
2013 kfree(cmd);
2014
2015 return rc;
2016}
2017
2018/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002019 * CMD_RF_ANTENNA.
2020 */
2021struct mwl8k_cmd_rf_antenna {
2022 struct mwl8k_cmd_pkt header;
2023 __le16 antenna;
2024 __le16 mode;
2025} __attribute__((packed));
2026
2027#define MWL8K_RF_ANTENNA_RX 1
2028#define MWL8K_RF_ANTENNA_TX 2
2029
2030static int
2031mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2032{
2033 struct mwl8k_cmd_rf_antenna *cmd;
2034 int rc;
2035
2036 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2037 if (cmd == NULL)
2038 return -ENOMEM;
2039
2040 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2041 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2042 cmd->antenna = cpu_to_le16(antenna);
2043 cmd->mode = cpu_to_le16(mask);
2044
2045 rc = mwl8k_post_cmd(hw, &cmd->header);
2046 kfree(cmd);
2047
2048 return rc;
2049}
2050
2051/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002052 * CMD_SET_PRE_SCAN.
2053 */
2054struct mwl8k_cmd_set_pre_scan {
2055 struct mwl8k_cmd_pkt header;
2056} __attribute__((packed));
2057
2058static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2059{
2060 struct mwl8k_cmd_set_pre_scan *cmd;
2061 int rc;
2062
2063 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2064 if (cmd == NULL)
2065 return -ENOMEM;
2066
2067 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2068 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2069
2070 rc = mwl8k_post_cmd(hw, &cmd->header);
2071 kfree(cmd);
2072
2073 return rc;
2074}
2075
2076/*
2077 * CMD_SET_POST_SCAN.
2078 */
2079struct mwl8k_cmd_set_post_scan {
2080 struct mwl8k_cmd_pkt header;
2081 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002082 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002083} __attribute__((packed));
2084
2085static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002086mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002087{
2088 struct mwl8k_cmd_set_post_scan *cmd;
2089 int rc;
2090
2091 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2092 if (cmd == NULL)
2093 return -ENOMEM;
2094
2095 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2096 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2097 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002098 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002099
2100 rc = mwl8k_post_cmd(hw, &cmd->header);
2101 kfree(cmd);
2102
2103 return rc;
2104}
2105
2106/*
2107 * CMD_SET_RF_CHANNEL.
2108 */
2109struct mwl8k_cmd_set_rf_channel {
2110 struct mwl8k_cmd_pkt header;
2111 __le16 action;
2112 __u8 current_channel;
2113 __le32 channel_flags;
2114} __attribute__((packed));
2115
2116static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2117 struct ieee80211_channel *channel)
2118{
2119 struct mwl8k_cmd_set_rf_channel *cmd;
2120 int rc;
2121
2122 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2123 if (cmd == NULL)
2124 return -ENOMEM;
2125
2126 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2127 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2128 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2129 cmd->current_channel = channel->hw_value;
2130 if (channel->band == IEEE80211_BAND_2GHZ)
2131 cmd->channel_flags = cpu_to_le32(0x00000081);
2132 else
2133 cmd->channel_flags = cpu_to_le32(0x00000000);
2134
2135 rc = mwl8k_post_cmd(hw, &cmd->header);
2136 kfree(cmd);
2137
2138 return rc;
2139}
2140
2141/*
2142 * CMD_SET_SLOT.
2143 */
2144struct mwl8k_cmd_set_slot {
2145 struct mwl8k_cmd_pkt header;
2146 __le16 action;
2147 __u8 short_slot;
2148} __attribute__((packed));
2149
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002150static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002151{
2152 struct mwl8k_cmd_set_slot *cmd;
2153 int rc;
2154
2155 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2156 if (cmd == NULL)
2157 return -ENOMEM;
2158
2159 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2160 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2161 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002162 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002163
2164 rc = mwl8k_post_cmd(hw, &cmd->header);
2165 kfree(cmd);
2166
2167 return rc;
2168}
2169
2170/*
2171 * CMD_MIMO_CONFIG.
2172 */
2173struct mwl8k_cmd_mimo_config {
2174 struct mwl8k_cmd_pkt header;
2175 __le32 action;
2176 __u8 rx_antenna_map;
2177 __u8 tx_antenna_map;
2178} __attribute__((packed));
2179
2180static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2181{
2182 struct mwl8k_cmd_mimo_config *cmd;
2183 int rc;
2184
2185 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2186 if (cmd == NULL)
2187 return -ENOMEM;
2188
2189 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2190 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2191 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2192 cmd->rx_antenna_map = rx;
2193 cmd->tx_antenna_map = tx;
2194
2195 rc = mwl8k_post_cmd(hw, &cmd->header);
2196 kfree(cmd);
2197
2198 return rc;
2199}
2200
2201/*
2202 * CMD_ENABLE_SNIFFER.
2203 */
2204struct mwl8k_cmd_enable_sniffer {
2205 struct mwl8k_cmd_pkt header;
2206 __le32 action;
2207} __attribute__((packed));
2208
2209static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2210{
2211 struct mwl8k_cmd_enable_sniffer *cmd;
2212 int rc;
2213
2214 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2215 if (cmd == NULL)
2216 return -ENOMEM;
2217
2218 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2219 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002220 cmd->action = cpu_to_le32(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002221
2222 rc = mwl8k_post_cmd(hw, &cmd->header);
2223 kfree(cmd);
2224
2225 return rc;
2226}
2227
2228/*
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002229 * CMD_SET_MAC_ADDR.
2230 */
2231struct mwl8k_cmd_set_mac_addr {
2232 struct mwl8k_cmd_pkt header;
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002233 union {
2234 struct {
2235 __le16 mac_type;
2236 __u8 mac_addr[ETH_ALEN];
2237 } mbss;
2238 __u8 mac_addr[ETH_ALEN];
2239 };
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002240} __attribute__((packed));
2241
2242static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2243{
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002244 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002245 struct mwl8k_cmd_set_mac_addr *cmd;
2246 int rc;
2247
2248 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2249 if (cmd == NULL)
2250 return -ENOMEM;
2251
2252 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2253 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek259a8e72009-10-22 20:21:40 +02002254 if (priv->ap_fw) {
2255 cmd->mbss.mac_type = 0;
2256 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2257 } else {
2258 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2259 }
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002260
2261 rc = mwl8k_post_cmd(hw, &cmd->header);
2262 kfree(cmd);
2263
2264 return rc;
2265}
2266
2267
2268/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002269 * CMD_SET_RATEADAPT_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002270 */
2271struct mwl8k_cmd_set_rate_adapt_mode {
2272 struct mwl8k_cmd_pkt header;
2273 __le16 action;
2274 __le16 mode;
2275} __attribute__((packed));
2276
2277static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2278{
2279 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2280 int rc;
2281
2282 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2283 if (cmd == NULL)
2284 return -ENOMEM;
2285
2286 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2287 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2288 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2289 cmd->mode = cpu_to_le16(mode);
2290
2291 rc = mwl8k_post_cmd(hw, &cmd->header);
2292 kfree(cmd);
2293
2294 return rc;
2295}
2296
2297/*
2298 * CMD_SET_WMM_MODE.
2299 */
2300struct mwl8k_cmd_set_wmm {
2301 struct mwl8k_cmd_pkt header;
2302 __le16 action;
2303} __attribute__((packed));
2304
2305static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
2306{
2307 struct mwl8k_priv *priv = hw->priv;
2308 struct mwl8k_cmd_set_wmm *cmd;
2309 int rc;
2310
2311 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2312 if (cmd == NULL)
2313 return -ENOMEM;
2314
2315 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2316 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002317 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002318
2319 rc = mwl8k_post_cmd(hw, &cmd->header);
2320 kfree(cmd);
2321
2322 if (!rc)
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02002323 priv->wmm_enabled = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002324
2325 return rc;
2326}
2327
2328/*
2329 * CMD_SET_RTS_THRESHOLD.
2330 */
2331struct mwl8k_cmd_rts_threshold {
2332 struct mwl8k_cmd_pkt header;
2333 __le16 action;
2334 __le16 threshold;
2335} __attribute__((packed));
2336
2337static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002338 u16 action, u16 threshold)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002339{
2340 struct mwl8k_cmd_rts_threshold *cmd;
2341 int rc;
2342
2343 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2344 if (cmd == NULL)
2345 return -ENOMEM;
2346
2347 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2348 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2349 cmd->action = cpu_to_le16(action);
Lennert Buytenhek733d3062009-07-17 07:24:15 +02002350 cmd->threshold = cpu_to_le16(threshold);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002351
2352 rc = mwl8k_post_cmd(hw, &cmd->header);
2353 kfree(cmd);
2354
2355 return rc;
2356}
2357
2358/*
2359 * CMD_SET_EDCA_PARAMS.
2360 */
2361struct mwl8k_cmd_set_edca_params {
2362 struct mwl8k_cmd_pkt header;
2363
2364 /* See MWL8K_SET_EDCA_XXX below */
2365 __le16 action;
2366
2367 /* TX opportunity in units of 32 us */
2368 __le16 txop;
2369
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002370 union {
2371 struct {
2372 /* Log exponent of max contention period: 0...15 */
2373 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002374
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002375 /* Log exponent of min contention period: 0...15 */
2376 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002377
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002378 /* Adaptive interframe spacing in units of 32us */
2379 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002380
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002381 /* TX queue to configure */
2382 __u8 txq;
2383 } ap;
2384 struct {
2385 /* Log exponent of max contention period: 0...15 */
2386 __u8 log_cw_max;
2387
2388 /* Log exponent of min contention period: 0...15 */
2389 __u8 log_cw_min;
2390
2391 /* Adaptive interframe spacing in units of 32us */
2392 __u8 aifs;
2393
2394 /* TX queue to configure */
2395 __u8 txq;
2396 } sta;
2397 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002398} __attribute__((packed));
2399
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002400#define MWL8K_SET_EDCA_CW 0x01
2401#define MWL8K_SET_EDCA_TXOP 0x02
2402#define MWL8K_SET_EDCA_AIFS 0x04
2403
2404#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2405 MWL8K_SET_EDCA_TXOP | \
2406 MWL8K_SET_EDCA_AIFS)
2407
2408static int
2409mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2410 __u16 cw_min, __u16 cw_max,
2411 __u8 aifs, __u16 txop)
2412{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002413 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002414 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002415 int rc;
2416
2417 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2418 if (cmd == NULL)
2419 return -ENOMEM;
2420
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002421 /*
2422 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2423 * this call.
2424 */
2425 qnum ^= !(qnum >> 1);
2426
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002427 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2428 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002429 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2430 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002431 if (priv->ap_fw) {
2432 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2433 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2434 cmd->ap.aifs = aifs;
2435 cmd->ap.txq = qnum;
2436 } else {
2437 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2438 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2439 cmd->sta.aifs = aifs;
2440 cmd->sta.txq = qnum;
2441 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002442
2443 rc = mwl8k_post_cmd(hw, &cmd->header);
2444 kfree(cmd);
2445
2446 return rc;
2447}
2448
2449/*
2450 * CMD_FINALIZE_JOIN.
2451 */
2452
2453/* FJ beacon buffer size is compiled into the firmware. */
2454#define MWL8K_FJ_BEACON_MAXLEN 128
2455
2456struct mwl8k_cmd_finalize_join {
2457 struct mwl8k_cmd_pkt header;
2458 __le32 sleep_interval; /* Number of beacon periods to sleep */
2459 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2460} __attribute__((packed));
2461
2462static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2463 __u16 framelen, __u16 dtim)
2464{
2465 struct mwl8k_cmd_finalize_join *cmd;
2466 struct ieee80211_mgmt *payload = frame;
2467 u16 hdrlen;
2468 u32 payload_len;
2469 int rc;
2470
2471 if (frame == NULL)
2472 return -EINVAL;
2473
2474 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2475 if (cmd == NULL)
2476 return -ENOMEM;
2477
2478 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2479 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002480 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002481
2482 hdrlen = ieee80211_hdrlen(payload->frame_control);
2483
2484 payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
2485
2486 /* XXX TBD Might just have to abort and return an error */
2487 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2488 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002489 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2490 payload_len, MWL8K_FJ_BEACON_MAXLEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002491
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002492 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2493 payload_len = MWL8K_FJ_BEACON_MAXLEN;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002494
2495 if (payload && payload_len)
2496 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2497
2498 rc = mwl8k_post_cmd(hw, &cmd->header);
2499 kfree(cmd);
2500 return rc;
2501}
2502
2503/*
2504 * CMD_UPDATE_STADB.
2505 */
2506struct mwl8k_cmd_update_sta_db {
2507 struct mwl8k_cmd_pkt header;
2508
2509 /* See STADB_ACTION_TYPE */
2510 __le32 action;
2511
2512 /* Peer MAC address */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002513 __u8 peer_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002514
2515 __le32 reserved;
2516
2517 /* Peer info - valid during add/update. */
2518 struct peer_capability_info peer_info;
2519} __attribute__((packed));
2520
2521static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
2522 struct ieee80211_vif *vif, __u32 action)
2523{
2524 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2525 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2526 struct mwl8k_cmd_update_sta_db *cmd;
2527 struct peer_capability_info *peer_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002528 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002529
2530 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2531 if (cmd == NULL)
2532 return -ENOMEM;
2533
2534 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2535 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2536
2537 cmd->action = cpu_to_le32(action);
2538 peer_info = &cmd->peer_info;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002539 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002540
2541 switch (action) {
2542 case MWL8K_STA_DB_ADD_ENTRY:
2543 case MWL8K_STA_DB_MODIFY_ENTRY:
2544 /* Build peer_info block */
2545 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2546 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002547 memcpy(peer_info->legacy_rates, mwl8k_rateids,
2548 sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002549 peer_info->interop = 1;
2550 peer_info->amsdu_enabled = 0;
2551
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002552 rc = mwl8k_post_cmd(hw, &cmd->header);
2553 if (rc == 0)
2554 mv_vif->peer_id = peer_info->station_id;
2555
2556 break;
2557
2558 case MWL8K_STA_DB_DEL_ENTRY:
2559 case MWL8K_STA_DB_FLUSH:
2560 default:
2561 rc = mwl8k_post_cmd(hw, &cmd->header);
2562 if (rc == 0)
2563 mv_vif->peer_id = 0;
2564 break;
2565 }
2566 kfree(cmd);
2567
2568 return rc;
2569}
2570
2571/*
2572 * CMD_SET_AID.
2573 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002574#define MWL8K_FRAME_PROT_DISABLED 0x00
2575#define MWL8K_FRAME_PROT_11G 0x07
2576#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2577#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002578
2579struct mwl8k_cmd_update_set_aid {
2580 struct mwl8k_cmd_pkt header;
2581 __le16 aid;
2582
2583 /* AP's MAC address (BSSID) */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002584 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002585 __le16 protection_mode;
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002586 __u8 supp_rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002587} __attribute__((packed));
2588
2589static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2590 struct ieee80211_vif *vif)
2591{
2592 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2593 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2594 struct mwl8k_cmd_update_set_aid *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002595 u16 prot_mode;
2596 int rc;
2597
2598 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2599 if (cmd == NULL)
2600 return -ENOMEM;
2601
2602 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2603 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2604 cmd->aid = cpu_to_le16(info->aid);
2605
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002606 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002607
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002608 if (info->use_cts_prot) {
2609 prot_mode = MWL8K_FRAME_PROT_11G;
2610 } else {
Johannes Berg9ed6bcc2009-05-08 20:47:39 +02002611 switch (info->ht_operation_mode &
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002612 IEEE80211_HT_OP_MODE_PROTECTION) {
2613 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2614 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2615 break;
2616 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2617 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2618 break;
2619 default:
2620 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2621 break;
2622 }
2623 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002624 cmd->protection_mode = cpu_to_le16(prot_mode);
2625
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002626 memcpy(cmd->supp_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002627
2628 rc = mwl8k_post_cmd(hw, &cmd->header);
2629 kfree(cmd);
2630
2631 return rc;
2632}
2633
2634/*
2635 * CMD_SET_RATE.
2636 */
2637struct mwl8k_cmd_update_rateset {
2638 struct mwl8k_cmd_pkt header;
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002639 __u8 legacy_rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002640
2641 /* Bitmap for supported MCS codes. */
Lennert Buytenhek0b5351a2009-11-30 18:11:18 +01002642 __u8 mcs_set[16];
2643 __u8 reserved[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002644} __attribute__((packed));
2645
2646static int mwl8k_update_rateset(struct ieee80211_hw *hw,
2647 struct ieee80211_vif *vif)
2648{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002649 struct mwl8k_cmd_update_rateset *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002650 int rc;
2651
2652 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2653 if (cmd == NULL)
2654 return -ENOMEM;
2655
2656 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2657 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +01002658 memcpy(cmd->legacy_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002659
2660 rc = mwl8k_post_cmd(hw, &cmd->header);
2661 kfree(cmd);
2662
2663 return rc;
2664}
2665
2666/*
2667 * CMD_USE_FIXED_RATE.
2668 */
2669#define MWL8K_RATE_TABLE_SIZE 8
2670#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002671#define MWL8K_USE_AUTO_RATE 0x0002
2672
2673struct mwl8k_rate_entry {
2674 /* Set to 1 if HT rate, 0 if legacy. */
2675 __le32 is_ht_rate;
2676
2677 /* Set to 1 to use retry_count field. */
2678 __le32 enable_retry;
2679
2680 /* Specified legacy rate or MCS. */
2681 __le32 rate;
2682
2683 /* Number of allowed retries. */
2684 __le32 retry_count;
2685} __attribute__((packed));
2686
2687struct mwl8k_rate_table {
2688 /* 1 to allow specified rate and below */
2689 __le32 allow_rate_drop;
2690 __le32 num_rates;
2691 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2692} __attribute__((packed));
2693
2694struct mwl8k_cmd_use_fixed_rate {
2695 struct mwl8k_cmd_pkt header;
2696 __le32 action;
2697 struct mwl8k_rate_table rate_table;
2698
2699 /* Unicast, Broadcast or Multicast */
2700 __le32 rate_type;
2701 __le32 reserved1;
2702 __le32 reserved2;
2703} __attribute__((packed));
2704
2705static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2706 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2707{
2708 struct mwl8k_cmd_use_fixed_rate *cmd;
2709 int count;
2710 int rc;
2711
2712 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2713 if (cmd == NULL)
2714 return -ENOMEM;
2715
2716 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2717 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2718
2719 cmd->action = cpu_to_le32(action);
2720 cmd->rate_type = cpu_to_le32(rate_type);
2721
2722 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002723 /*
2724 * Copy over each field manually so that endian
2725 * conversion can be done.
2726 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002727 cmd->rate_table.allow_rate_drop =
2728 cpu_to_le32(rate_table->allow_rate_drop);
2729 cmd->rate_table.num_rates =
2730 cpu_to_le32(rate_table->num_rates);
2731
2732 for (count = 0; count < rate_table->num_rates; count++) {
2733 struct mwl8k_rate_entry *dst =
2734 &cmd->rate_table.rate_entry[count];
2735 struct mwl8k_rate_entry *src =
2736 &rate_table->rate_entry[count];
2737
2738 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2739 dst->enable_retry = cpu_to_le32(src->enable_retry);
2740 dst->rate = cpu_to_le32(src->rate);
2741 dst->retry_count = cpu_to_le32(src->retry_count);
2742 }
2743 }
2744
2745 rc = mwl8k_post_cmd(hw, &cmd->header);
2746 kfree(cmd);
2747
2748 return rc;
2749}
2750
2751
2752/*
2753 * Interrupt handling.
2754 */
2755static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2756{
2757 struct ieee80211_hw *hw = dev_id;
2758 struct mwl8k_priv *priv = hw->priv;
2759 u32 status;
2760
2761 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2762 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2763
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002764 if (!status)
2765 return IRQ_NONE;
2766
2767 if (status & MWL8K_A2H_INT_TX_DONE)
2768 tasklet_schedule(&priv->tx_reclaim_task);
2769
2770 if (status & MWL8K_A2H_INT_RX_READY) {
2771 while (rxq_process(hw, 0, 1))
2772 rxq_refill(hw, 0, 1);
2773 }
2774
2775 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002776 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002777 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002778 }
2779
2780 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002781 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002782 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002783 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002784 }
2785
2786 return IRQ_HANDLED;
2787}
2788
2789
2790/*
2791 * Core driver operations.
2792 */
2793static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2794{
2795 struct mwl8k_priv *priv = hw->priv;
2796 int index = skb_get_queue_mapping(skb);
2797 int rc;
2798
2799 if (priv->current_channel == NULL) {
2800 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002801 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002802 dev_kfree_skb(skb);
2803 return NETDEV_TX_OK;
2804 }
2805
2806 rc = mwl8k_txq_xmit(hw, index, skb);
2807
2808 return rc;
2809}
2810
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002811static int mwl8k_start(struct ieee80211_hw *hw)
2812{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002813 struct mwl8k_priv *priv = hw->priv;
2814 int rc;
2815
Joe Perchesa0607fd2009-11-18 23:29:17 -08002816 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002817 IRQF_SHARED, MWL8K_NAME, hw);
2818 if (rc) {
2819 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002820 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002821 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002822 }
2823
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002824 /* Enable tx reclaim tasklet */
2825 tasklet_enable(&priv->tx_reclaim_task);
2826
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002827 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002828 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002829
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002830 rc = mwl8k_fw_lock(hw);
2831 if (!rc) {
2832 rc = mwl8k_cmd_802_11_radio_enable(hw);
2833
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002834 if (!priv->ap_fw) {
2835 if (!rc)
2836 rc = mwl8k_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002837
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002838 if (!rc)
2839 rc = mwl8k_cmd_set_pre_scan(hw);
2840
2841 if (!rc)
2842 rc = mwl8k_cmd_set_post_scan(hw,
2843 "\x00\x00\x00\x00\x00\x00");
2844 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002845
2846 if (!rc)
2847 rc = mwl8k_cmd_setrateadaptmode(hw, 0);
2848
2849 if (!rc)
2850 rc = mwl8k_set_wmm(hw, 0);
2851
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002852 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002853 }
2854
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002855 if (rc) {
2856 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2857 free_irq(priv->pdev->irq, hw);
2858 tasklet_disable(&priv->tx_reclaim_task);
2859 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002860
2861 return rc;
2862}
2863
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002864static void mwl8k_stop(struct ieee80211_hw *hw)
2865{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002866 struct mwl8k_priv *priv = hw->priv;
2867 int i;
2868
Lennert Buytenhekd3cea0b2009-07-17 07:15:49 +02002869 mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002870
2871 ieee80211_stop_queues(hw);
2872
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002873 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002874 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002875 free_irq(priv->pdev->irq, hw);
2876
2877 /* Stop finalize join worker */
2878 cancel_work_sync(&priv->finalize_join_worker);
2879 if (priv->beacon_skb != NULL)
2880 dev_kfree_skb(priv->beacon_skb);
2881
2882 /* Stop tx reclaim tasklet */
2883 tasklet_disable(&priv->tx_reclaim_task);
2884
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002885 /* Return all skbs to mac80211 */
2886 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2887 mwl8k_txq_reclaim(hw, i, 1);
2888}
2889
2890static int mwl8k_add_interface(struct ieee80211_hw *hw,
2891 struct ieee80211_if_init_conf *conf)
2892{
2893 struct mwl8k_priv *priv = hw->priv;
2894 struct mwl8k_vif *mwl8k_vif;
2895
2896 /*
2897 * We only support one active interface at a time.
2898 */
2899 if (priv->vif != NULL)
2900 return -EBUSY;
2901
2902 /*
2903 * We only support managed interfaces for now.
2904 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002905 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002906 return -EINVAL;
2907
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002908 /*
2909 * Reject interface creation if sniffer mode is active, as
2910 * STA operation is mutually exclusive with hardware sniffer
2911 * mode.
2912 */
2913 if (priv->sniffer_enabled) {
2914 printk(KERN_INFO "%s: unable to create STA "
2915 "interface due to sniffer mode being enabled\n",
2916 wiphy_name(hw->wiphy));
2917 return -EINVAL;
2918 }
2919
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002920 /* Clean out driver private area */
2921 mwl8k_vif = MWL8K_VIF(conf->vif);
2922 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2923
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002924 /* Set and save the mac address */
2925 mwl8k_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002926 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002927
2928 /* Back pointer to parent config block */
2929 mwl8k_vif->priv = priv;
2930
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002931 /* Set Initial sequence number to zero */
2932 mwl8k_vif->seqno = 0;
2933
2934 priv->vif = conf->vif;
2935 priv->current_channel = NULL;
2936
2937 return 0;
2938}
2939
2940static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2941 struct ieee80211_if_init_conf *conf)
2942{
2943 struct mwl8k_priv *priv = hw->priv;
2944
2945 if (priv->vif == NULL)
2946 return;
2947
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002948 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
2949
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002950 priv->vif = NULL;
2951}
2952
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002953static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002954{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002955 struct ieee80211_conf *conf = &hw->conf;
2956 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002957 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002958
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002959 if (conf->flags & IEEE80211_CONF_IDLE) {
2960 mwl8k_cmd_802_11_radio_disable(hw);
2961 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002962 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002963 }
2964
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002965 rc = mwl8k_fw_lock(hw);
2966 if (rc)
2967 return rc;
2968
2969 rc = mwl8k_cmd_802_11_radio_enable(hw);
2970 if (rc)
2971 goto out;
2972
2973 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2974 if (rc)
2975 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002976
2977 priv->current_channel = conf->channel;
2978
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002979 if (conf->power_level > 18)
2980 conf->power_level = 18;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002981 rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level);
2982 if (rc)
2983 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002984
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002985 if (priv->ap_fw) {
2986 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2987 if (!rc)
2988 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2989 } else {
2990 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2991 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002992
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002993out:
2994 mwl8k_fw_unlock(hw);
2995
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002996 return rc;
2997}
2998
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002999static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3000 struct ieee80211_vif *vif,
3001 struct ieee80211_bss_conf *info,
3002 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003003{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003004 struct mwl8k_priv *priv = hw->priv;
3005 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003006 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003007
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003008 if (changed & BSS_CHANGED_BSSID)
3009 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
3010
3011 if ((changed & BSS_CHANGED_ASSOC) == 0)
3012 return;
3013
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003014 priv->capture_beacon = false;
3015
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003016 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02003017 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003018 return;
3019
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003020 if (info->assoc) {
3021 memcpy(&mwl8k_vif->bss_info, info,
3022 sizeof(struct ieee80211_bss_conf));
3023
3024 /* Install rates */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003025 rc = mwl8k_update_rateset(hw, vif);
3026 if (rc)
3027 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003028
3029 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003030 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3031 MWL8K_UCAST_RATE, NULL);
3032 if (rc)
3033 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003034
3035 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003036 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
3037 if (rc)
3038 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003039
3040 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003041 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
3042 if (rc)
3043 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003044
3045 /* Update peer rate info */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003046 rc = mwl8k_cmd_update_sta_db(hw, vif,
3047 MWL8K_STA_DB_MODIFY_ENTRY);
3048 if (rc)
3049 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003050
3051 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003052 rc = mwl8k_cmd_set_aid(hw, vif);
3053 if (rc)
3054 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003055
3056 /*
3057 * Finalize the join. Tell rx handler to process
3058 * next beacon from our BSSID.
3059 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003060 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003061 priv->capture_beacon = true;
3062 } else {
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003063 rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003064 memset(&mwl8k_vif->bss_info, 0,
3065 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003066 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003067 }
3068
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003069out:
3070 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003071}
3072
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003073static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3074 int mc_count, struct dev_addr_list *mclist)
3075{
3076 struct mwl8k_cmd_pkt *cmd;
3077
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003078 /*
3079 * Synthesize and return a command packet that programs the
3080 * hardware multicast address filter. At this point we don't
3081 * know whether FIF_ALLMULTI is being requested, but if it is,
3082 * we'll end up throwing this packet away and creating a new
3083 * one in mwl8k_configure_filter().
3084 */
3085 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003086
3087 return (unsigned long)cmd;
3088}
3089
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003090static int
3091mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3092 unsigned int changed_flags,
3093 unsigned int *total_flags)
3094{
3095 struct mwl8k_priv *priv = hw->priv;
3096
3097 /*
3098 * Hardware sniffer mode is mutually exclusive with STA
3099 * operation, so refuse to enable sniffer mode if a STA
3100 * interface is active.
3101 */
3102 if (priv->vif != NULL) {
3103 if (net_ratelimit())
3104 printk(KERN_INFO "%s: not enabling sniffer "
3105 "mode because STA interface is active\n",
3106 wiphy_name(hw->wiphy));
3107 return 0;
3108 }
3109
3110 if (!priv->sniffer_enabled) {
3111 if (mwl8k_enable_sniffer(hw, 1))
3112 return 0;
3113 priv->sniffer_enabled = true;
3114 }
3115
3116 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3117 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3118 FIF_OTHER_BSS;
3119
3120 return 1;
3121}
3122
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003123static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3124 unsigned int changed_flags,
3125 unsigned int *total_flags,
3126 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003127{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003128 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003129 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3130
3131 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003132 * AP firmware doesn't allow fine-grained control over
3133 * the receive filter.
3134 */
3135 if (priv->ap_fw) {
3136 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3137 kfree(cmd);
3138 return;
3139 }
3140
3141 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003142 * Enable hardware sniffer mode if FIF_CONTROL or
3143 * FIF_OTHER_BSS is requested.
3144 */
3145 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3146 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3147 kfree(cmd);
3148 return;
3149 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003150
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003151 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003152 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003153
3154 if (mwl8k_fw_lock(hw))
3155 return;
3156
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003157 if (priv->sniffer_enabled) {
3158 mwl8k_enable_sniffer(hw, 0);
3159 priv->sniffer_enabled = false;
3160 }
3161
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003162 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003163 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3164 /*
3165 * Disable the BSS filter.
3166 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003167 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003168 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003169 u8 *bssid;
3170
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003171 /*
3172 * Enable the BSS filter.
3173 *
3174 * If there is an active STA interface, use that
3175 * interface's BSSID, otherwise use a dummy one
3176 * (where the OUI part needs to be nonzero for
3177 * the BSSID to be accepted by POST_SCAN).
3178 */
3179 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003180 if (priv->vif != NULL)
3181 bssid = MWL8K_VIF(priv->vif)->bssid;
3182
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003183 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003184 }
3185 }
3186
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003187 /*
3188 * If FIF_ALLMULTI is being requested, throw away the command
3189 * packet that ->prepare_multicast() built and replace it with
3190 * a command packet that enables reception of all multicast
3191 * packets.
3192 */
3193 if (*total_flags & FIF_ALLMULTI) {
3194 kfree(cmd);
3195 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3196 }
3197
3198 if (cmd != NULL) {
3199 mwl8k_post_cmd(hw, cmd);
3200 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003201 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003202
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003203 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003204}
3205
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003206static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3207{
Lennert Buytenhek733d3062009-07-17 07:24:15 +02003208 return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003209}
3210
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003211static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3212 const struct ieee80211_tx_queue_params *params)
3213{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003214 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003215 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003216
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003217 rc = mwl8k_fw_lock(hw);
3218 if (!rc) {
3219 if (!priv->wmm_enabled)
3220 rc = mwl8k_set_wmm(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003221
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003222 if (!rc)
3223 rc = mwl8k_set_edca_params(hw, queue,
3224 params->cw_min,
3225 params->cw_max,
3226 params->aifs,
3227 params->txop);
3228
3229 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003230 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003231
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003232 return rc;
3233}
3234
3235static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3236 struct ieee80211_tx_queue_stats *stats)
3237{
3238 struct mwl8k_priv *priv = hw->priv;
3239 struct mwl8k_tx_queue *txq;
3240 int index;
3241
3242 spin_lock_bh(&priv->tx_lock);
3243 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3244 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003245 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003246 sizeof(struct ieee80211_tx_queue_stats));
3247 }
3248 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003249
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003250 return 0;
3251}
3252
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003253static int mwl8k_get_stats(struct ieee80211_hw *hw,
3254 struct ieee80211_low_level_stats *stats)
3255{
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003256 return mwl8k_cmd_802_11_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003257}
3258
3259static const struct ieee80211_ops mwl8k_ops = {
3260 .tx = mwl8k_tx,
3261 .start = mwl8k_start,
3262 .stop = mwl8k_stop,
3263 .add_interface = mwl8k_add_interface,
3264 .remove_interface = mwl8k_remove_interface,
3265 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003266 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003267 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003268 .configure_filter = mwl8k_configure_filter,
3269 .set_rts_threshold = mwl8k_set_rts_threshold,
3270 .conf_tx = mwl8k_conf_tx,
3271 .get_tx_stats = mwl8k_get_tx_stats,
3272 .get_stats = mwl8k_get_stats,
3273};
3274
3275static void mwl8k_tx_reclaim_handler(unsigned long data)
3276{
3277 int i;
3278 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3279 struct mwl8k_priv *priv = hw->priv;
3280
3281 spin_lock_bh(&priv->tx_lock);
3282 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3283 mwl8k_txq_reclaim(hw, i, 0);
3284
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003285 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003286 complete(priv->tx_wait);
3287 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003288 }
3289 spin_unlock_bh(&priv->tx_lock);
3290}
3291
3292static void mwl8k_finalize_join_worker(struct work_struct *work)
3293{
3294 struct mwl8k_priv *priv =
3295 container_of(work, struct mwl8k_priv, finalize_join_worker);
3296 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003297 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003298
3299 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
3300 dev_kfree_skb(skb);
3301
3302 priv->beacon_skb = NULL;
3303}
3304
John W. Linvillebcb628d2009-11-06 16:40:16 -05003305enum {
3306 MWL8687 = 0,
3307 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003308};
3309
John W. Linvillebcb628d2009-11-06 16:40:16 -05003310static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3311 {
3312 .part_name = "88w8687",
3313 .helper_image = "mwl8k/helper_8687.fw",
3314 .fw_image = "mwl8k/fmimage_8687.fw",
3315 .rxd_ops = &rxd_8687_ops,
3316 .modes = BIT(NL80211_IFTYPE_STATION),
3317 },
3318 {
3319 .part_name = "88w8366",
3320 .helper_image = "mwl8k/helper_8366.fw",
3321 .fw_image = "mwl8k/fmimage_8366.fw",
3322 .rxd_ops = &rxd_8366_ops,
3323 .modes = 0,
3324 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003325};
3326
3327static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003328 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3329 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3330 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3331 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003332};
3333MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3334
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003335static int __devinit mwl8k_probe(struct pci_dev *pdev,
3336 const struct pci_device_id *id)
3337{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003338 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003339 struct ieee80211_hw *hw;
3340 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003341 int rc;
3342 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003343
3344 if (!printed_version) {
3345 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3346 printed_version = 1;
3347 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003348
3349 rc = pci_enable_device(pdev);
3350 if (rc) {
3351 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3352 MWL8K_NAME);
3353 return rc;
3354 }
3355
3356 rc = pci_request_regions(pdev, MWL8K_NAME);
3357 if (rc) {
3358 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3359 MWL8K_NAME);
3360 return rc;
3361 }
3362
3363 pci_set_master(pdev);
3364
3365 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3366 if (hw == NULL) {
3367 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3368 rc = -ENOMEM;
3369 goto err_free_reg;
3370 }
3371
3372 priv = hw->priv;
3373 priv->hw = hw;
3374 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003375 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02003376 priv->rxd_ops = priv->device_info->rxd_ops;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003377 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02003378 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003379 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003380
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003381 SET_IEEE80211_DEV(hw, &pdev->dev);
3382 pci_set_drvdata(pdev, hw);
3383
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003384 priv->sram = pci_iomap(pdev, 0, 0x10000);
3385 if (priv->sram == NULL) {
3386 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003387 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003388 goto err_iounmap;
3389 }
3390
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003391 /*
3392 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3393 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3394 */
3395 priv->regs = pci_iomap(pdev, 1, 0x10000);
3396 if (priv->regs == NULL) {
3397 priv->regs = pci_iomap(pdev, 2, 0x10000);
3398 if (priv->regs == NULL) {
3399 printk(KERN_ERR "%s: Cannot map device registers\n",
3400 wiphy_name(hw->wiphy));
3401 goto err_iounmap;
3402 }
3403 }
3404
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003405 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3406 priv->band.band = IEEE80211_BAND_2GHZ;
3407 priv->band.channels = priv->channels;
3408 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3409 priv->band.bitrates = priv->rates;
3410 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3411 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3412
3413 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3414 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3415
3416 /*
3417 * Extra headroom is the size of the required DMA header
3418 * minus the size of the smallest 802.11 frame (CTS frame).
3419 */
3420 hw->extra_tx_headroom =
3421 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3422
3423 hw->channel_change_time = 10;
3424
3425 hw->queues = MWL8K_TX_QUEUES;
3426
Lennert Buytenhek547810e2009-10-22 20:21:02 +02003427 hw->wiphy->interface_modes = priv->device_info->modes;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003428
3429 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003430 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003431 hw->vif_data_size = sizeof(struct mwl8k_vif);
3432 priv->vif = NULL;
3433
3434 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003435 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003436 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003437
3438 /* Finalize join worker */
3439 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3440
3441 /* TX reclaim tasklet */
3442 tasklet_init(&priv->tx_reclaim_task,
3443 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3444 tasklet_disable(&priv->tx_reclaim_task);
3445
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003446 /* Power management cookie */
3447 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3448 if (priv->cookie == NULL)
3449 goto err_iounmap;
3450
3451 rc = mwl8k_rxq_init(hw, 0);
3452 if (rc)
3453 goto err_iounmap;
3454 rxq_refill(hw, 0, INT_MAX);
3455
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003456 mutex_init(&priv->fw_mutex);
3457 priv->fw_mutex_owner = NULL;
3458 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003459 priv->hostcmd_wait = NULL;
3460
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003461 spin_lock_init(&priv->tx_lock);
3462
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003463 priv->tx_wait = NULL;
3464
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003465 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3466 rc = mwl8k_txq_init(hw, i);
3467 if (rc)
3468 goto err_free_queues;
3469 }
3470
3471 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003472 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003473 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3474 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3475
Joe Perchesa0607fd2009-11-18 23:29:17 -08003476 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003477 IRQF_SHARED, MWL8K_NAME, hw);
3478 if (rc) {
3479 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003480 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003481 goto err_free_queues;
3482 }
3483
3484 /* Reset firmware and hardware */
3485 mwl8k_hw_reset(priv);
3486
3487 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003488 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003489 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003490 printk(KERN_ERR "%s: Firmware files not found\n",
3491 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003492 goto err_free_irq;
3493 }
3494
3495 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003496 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003497 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003498 printk(KERN_ERR "%s: Cannot start firmware\n",
3499 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003500 goto err_stop_firmware;
3501 }
3502
3503 /* Reclaim memory once firmware is successfully loaded */
3504 mwl8k_release_firmware(priv);
3505
3506 /*
3507 * Temporarily enable interrupts. Initial firmware host
3508 * commands use interrupts and avoids polling. Disable
3509 * interrupts when done.
3510 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003511 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003512
3513 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02003514 if (priv->ap_fw) {
3515 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3516 if (!rc)
3517 rc = mwl8k_cmd_set_hw_spec(hw);
3518 } else {
3519 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3520 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003521 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003522 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3523 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003524 goto err_stop_firmware;
3525 }
3526
3527 /* Turn radio off */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003528 rc = mwl8k_cmd_802_11_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003529 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003530 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003531 goto err_stop_firmware;
3532 }
3533
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003534 /* Clear MAC address */
3535 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3536 if (rc) {
3537 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3538 wiphy_name(hw->wiphy));
3539 goto err_stop_firmware;
3540 }
3541
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003542 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003543 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003544 free_irq(priv->pdev->irq, hw);
3545
3546 rc = ieee80211_register_hw(hw);
3547 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003548 printk(KERN_ERR "%s: Cannot register device\n",
3549 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003550 goto err_stop_firmware;
3551 }
3552
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003553 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003554 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003555 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003556 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003557 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3558 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003559
3560 return 0;
3561
3562err_stop_firmware:
3563 mwl8k_hw_reset(priv);
3564 mwl8k_release_firmware(priv);
3565
3566err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003567 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003568 free_irq(priv->pdev->irq, hw);
3569
3570err_free_queues:
3571 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3572 mwl8k_txq_deinit(hw, i);
3573 mwl8k_rxq_deinit(hw, 0);
3574
3575err_iounmap:
3576 if (priv->cookie != NULL)
3577 pci_free_consistent(priv->pdev, 4,
3578 priv->cookie, priv->cookie_dma);
3579
3580 if (priv->regs != NULL)
3581 pci_iounmap(pdev, priv->regs);
3582
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003583 if (priv->sram != NULL)
3584 pci_iounmap(pdev, priv->sram);
3585
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003586 pci_set_drvdata(pdev, NULL);
3587 ieee80211_free_hw(hw);
3588
3589err_free_reg:
3590 pci_release_regions(pdev);
3591 pci_disable_device(pdev);
3592
3593 return rc;
3594}
3595
Joerg Albert230f7af2009-04-18 02:10:45 +02003596static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003597{
3598 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3599}
3600
Joerg Albert230f7af2009-04-18 02:10:45 +02003601static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003602{
3603 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3604 struct mwl8k_priv *priv;
3605 int i;
3606
3607 if (hw == NULL)
3608 return;
3609 priv = hw->priv;
3610
3611 ieee80211_stop_queues(hw);
3612
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003613 ieee80211_unregister_hw(hw);
3614
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003615 /* Remove tx reclaim tasklet */
3616 tasklet_kill(&priv->tx_reclaim_task);
3617
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003618 /* Stop hardware */
3619 mwl8k_hw_reset(priv);
3620
3621 /* Return all skbs to mac80211 */
3622 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3623 mwl8k_txq_reclaim(hw, i, 1);
3624
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003625 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3626 mwl8k_txq_deinit(hw, i);
3627
3628 mwl8k_rxq_deinit(hw, 0);
3629
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003630 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003631
3632 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003633 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003634 pci_set_drvdata(pdev, NULL);
3635 ieee80211_free_hw(hw);
3636 pci_release_regions(pdev);
3637 pci_disable_device(pdev);
3638}
3639
3640static struct pci_driver mwl8k_driver = {
3641 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003642 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003643 .probe = mwl8k_probe,
3644 .remove = __devexit_p(mwl8k_remove),
3645 .shutdown = __devexit_p(mwl8k_shutdown),
3646};
3647
3648static int __init mwl8k_init(void)
3649{
3650 return pci_register_driver(&mwl8k_driver);
3651}
3652
3653static void __exit mwl8k_exit(void)
3654{
3655 pci_unregister_driver(&mwl8k_driver);
3656}
3657
3658module_init(mwl8k_init);
3659module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003660
3661MODULE_DESCRIPTION(MWL8K_DESC);
3662MODULE_VERSION(MWL8K_VERSION);
3663MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3664MODULE_LICENSE("GPL");