blob: 8cbb52cc4269ffa83ffb258eb6ac5560bacf0b22 [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 Buytenhek55489b62009-11-30 18:31:33 +0100224 /* Index into station database. Returned by UPDATE_STADB. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100225 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 Buytenhek42fba21d2009-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 Buytenhek42fba21d2009-10-22 20:21:30 +0200307 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100308 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
309 MWL8K_CMDNAME(GET_STAT);
310 MWL8K_CMDNAME(RADIO_CONTROL);
311 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200312 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100313 MWL8K_CMDNAME(SET_PRE_SCAN);
314 MWL8K_CMDNAME(SET_POST_SCAN);
315 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100316 MWL8K_CMDNAME(SET_AID);
317 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200318 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100319 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200320 MWL8K_CMDNAME(SET_SLOT);
321 MWL8K_CMDNAME(SET_EDCA_PARAMS);
322 MWL8K_CMDNAME(SET_WMM_MODE);
323 MWL8K_CMDNAME(MIMO_CONFIG);
324 MWL8K_CMDNAME(USE_FIXED_RATE);
325 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200326 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200327 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
328 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100329 default:
330 snprintf(buf, bufsize, "0x%x", cmd);
331 }
332#undef MWL8K_CMDNAME
333
334 return buf;
335}
336
337/* Hardware and firmware reset */
338static void mwl8k_hw_reset(struct mwl8k_priv *priv)
339{
340 iowrite32(MWL8K_H2A_INT_RESET,
341 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
342 iowrite32(MWL8K_H2A_INT_RESET,
343 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
344 msleep(20);
345}
346
347/* Release fw image */
348static void mwl8k_release_fw(struct firmware **fw)
349{
350 if (*fw == NULL)
351 return;
352 release_firmware(*fw);
353 *fw = NULL;
354}
355
356static void mwl8k_release_firmware(struct mwl8k_priv *priv)
357{
358 mwl8k_release_fw(&priv->fw.ucode);
359 mwl8k_release_fw(&priv->fw.helper);
360}
361
362/* Request fw image */
363static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200364 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100365{
366 /* release current image */
367 if (*fw != NULL)
368 mwl8k_release_fw(fw);
369
370 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200371 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100372}
373
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200374static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100375{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200376 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100377 int rc;
378
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200379 if (di->helper_image != NULL) {
380 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
381 if (rc) {
382 printk(KERN_ERR "%s: Error requesting helper "
383 "firmware file %s\n", pci_name(priv->pdev),
384 di->helper_image);
385 return rc;
386 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100387 }
388
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200389 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100390 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200391 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200392 pci_name(priv->pdev), di->fw_image);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100393 mwl8k_release_fw(&priv->fw.helper);
394 return rc;
395 }
396
397 return 0;
398}
399
Ben Hutchings7e75b942009-11-07 22:00:57 +0000400MODULE_FIRMWARE("mwl8k/helper_8687.fw");
401MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
402
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100403struct mwl8k_cmd_pkt {
404 __le16 code;
405 __le16 length;
406 __le16 seq_num;
407 __le16 result;
408 char payload[0];
409} __attribute__((packed));
410
411/*
412 * Firmware loading.
413 */
414static int
415mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
416{
417 void __iomem *regs = priv->regs;
418 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100419 int loops;
420
421 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
422 if (pci_dma_mapping_error(priv->pdev, dma_addr))
423 return -ENOMEM;
424
425 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
426 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
427 iowrite32(MWL8K_H2A_INT_DOORBELL,
428 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
429 iowrite32(MWL8K_H2A_INT_DUMMY,
430 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
431
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100432 loops = 1000;
433 do {
434 u32 int_code;
435
436 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
437 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
438 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100439 break;
440 }
441
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200442 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100443 udelay(1);
444 } while (--loops);
445
446 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
447
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200448 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100449}
450
451static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
452 const u8 *data, size_t length)
453{
454 struct mwl8k_cmd_pkt *cmd;
455 int done;
456 int rc = 0;
457
458 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
459 if (cmd == NULL)
460 return -ENOMEM;
461
462 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
463 cmd->seq_num = 0;
464 cmd->result = 0;
465
466 done = 0;
467 while (length) {
468 int block_size = length > 256 ? 256 : length;
469
470 memcpy(cmd->payload, data + done, block_size);
471 cmd->length = cpu_to_le16(block_size);
472
473 rc = mwl8k_send_fw_load_cmd(priv, cmd,
474 sizeof(*cmd) + block_size);
475 if (rc)
476 break;
477
478 done += block_size;
479 length -= block_size;
480 }
481
482 if (!rc) {
483 cmd->length = 0;
484 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
485 }
486
487 kfree(cmd);
488
489 return rc;
490}
491
492static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
493 const u8 *data, size_t length)
494{
495 unsigned char *buffer;
496 int may_continue, rc = 0;
497 u32 done, prev_block_size;
498
499 buffer = kmalloc(1024, GFP_KERNEL);
500 if (buffer == NULL)
501 return -ENOMEM;
502
503 done = 0;
504 prev_block_size = 0;
505 may_continue = 1000;
506 while (may_continue > 0) {
507 u32 block_size;
508
509 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
510 if (block_size & 1) {
511 block_size &= ~1;
512 may_continue--;
513 } else {
514 done += prev_block_size;
515 length -= prev_block_size;
516 }
517
518 if (block_size > 1024 || block_size > length) {
519 rc = -EOVERFLOW;
520 break;
521 }
522
523 if (length == 0) {
524 rc = 0;
525 break;
526 }
527
528 if (block_size == 0) {
529 rc = -EPROTO;
530 may_continue--;
531 udelay(1);
532 continue;
533 }
534
535 prev_block_size = block_size;
536 memcpy(buffer, data + done, block_size);
537
538 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
539 if (rc)
540 break;
541 }
542
543 if (!rc && length != 0)
544 rc = -EREMOTEIO;
545
546 kfree(buffer);
547
548 return rc;
549}
550
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200551static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100552{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200553 struct mwl8k_priv *priv = hw->priv;
554 struct firmware *fw = priv->fw.ucode;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200555 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200556 int rc;
557 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100558
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200559 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
560 struct firmware *helper = priv->fw.helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100561
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200562 if (helper == NULL) {
563 printk(KERN_ERR "%s: helper image needed but none "
564 "given\n", pci_name(priv->pdev));
565 return -EINVAL;
566 }
567
568 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100569 if (rc) {
570 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200571 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100572 return rc;
573 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100574 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100575
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
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100592 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100593 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200594 u32 ready_code;
595
596 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
597 if (ready_code == MWL8K_FWAP_READY) {
598 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100599 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200600 } else if (ready_code == MWL8K_FWSTA_READY) {
601 priv->ap_fw = 0;
602 break;
603 }
604
605 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100606 udelay(1);
607 } while (--loops);
608
609 return loops ? 0 : -ETIMEDOUT;
610}
611
612
613/*
614 * Defines shared between transmission and reception.
615 */
616/* HT control fields for firmware */
617struct ewc_ht_info {
618 __le16 control1;
619 __le16 control2;
620 __le16 control3;
621} __attribute__((packed));
622
623/* Firmware Station database operations */
624#define MWL8K_STA_DB_ADD_ENTRY 0
625#define MWL8K_STA_DB_MODIFY_ENTRY 1
626#define MWL8K_STA_DB_DEL_ENTRY 2
627#define MWL8K_STA_DB_FLUSH 3
628
629/* Peer Entry flags - used to define the type of the peer node */
630#define MWL8K_PEER_TYPE_ACCESSPOINT 2
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100631
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100632struct peer_capability_info {
633 /* Peer type - AP vs. STA. */
634 __u8 peer_type;
635
636 /* Basic 802.11 capabilities from assoc resp. */
637 __le16 basic_caps;
638
639 /* Set if peer supports 802.11n high throughput (HT). */
640 __u8 ht_support;
641
642 /* Valid if HT is supported. */
643 __le16 ht_caps;
644 __u8 extended_ht_caps;
645 struct ewc_ht_info ewc_info;
646
647 /* Legacy rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100648 __u8 legacy_rates[12];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100649
650 /* HT rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek0b5351a2009-11-30 18:11:18 +0100651 __u8 ht_rates[16];
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +0200652 __u8 pad[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100653
654 /* If set, interoperability mode, no proprietary extensions. */
655 __u8 interop;
656 __u8 pad2;
657 __u8 station_id;
658 __le16 amsdu_enabled;
659} __attribute__((packed));
660
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100661/* DMA header used by firmware and hardware. */
662struct mwl8k_dma_data {
663 __le16 fwlen;
664 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100665 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100666} __attribute__((packed));
667
668/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100669static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100670{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100671 struct mwl8k_dma_data *tr;
672 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100673
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100674 tr = (struct mwl8k_dma_data *)skb->data;
675 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
676
677 if (hdrlen != sizeof(tr->wh)) {
678 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
679 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
680 *((__le16 *)(tr->data - 2)) = qos;
681 } else {
682 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
683 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100684 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100685
686 if (hdrlen != sizeof(*tr))
687 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100688}
689
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200690static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100691{
692 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100693 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100694 struct mwl8k_dma_data *tr;
695
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100696 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100697 * Add a firmware DMA header; the firmware requires that we
698 * present a 2-byte payload length followed by a 4-address
699 * header (without QoS field), followed (optionally) by any
700 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100701 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100702 wh = (struct ieee80211_hdr *)skb->data;
703
704 hdrlen = ieee80211_hdrlen(wh->frame_control);
705 if (hdrlen != sizeof(*tr))
706 skb_push(skb, sizeof(*tr) - hdrlen);
707
708 if (ieee80211_is_data_qos(wh->frame_control))
709 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100710
711 tr = (struct mwl8k_dma_data *)skb->data;
712 if (wh != &tr->wh)
713 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100714 if (hdrlen != sizeof(tr->wh))
715 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100716
717 /*
718 * Firmware length is the length of the fully formed "802.11
719 * payload". That is, everything except for the 802.11 header.
720 * This includes all crypto material including the MIC.
721 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100722 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100723}
724
725
726/*
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200727 * Packet reception for 88w8366.
728 */
729struct mwl8k_rxd_8366 {
730 __le16 pkt_len;
731 __u8 sq2;
732 __u8 rate;
733 __le32 pkt_phys_addr;
734 __le32 next_rxd_phys_addr;
735 __le16 qos_control;
736 __le16 htsig2;
737 __le32 hw_rssi_info;
738 __le32 hw_noise_floor_info;
739 __u8 noise_floor;
740 __u8 pad0[3];
741 __u8 rssi;
742 __u8 rx_status;
743 __u8 channel;
744 __u8 rx_ctrl;
745} __attribute__((packed));
746
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100747#define MWL8K_8366_RATE_INFO_MCS_FORMAT 0x80
748#define MWL8K_8366_RATE_INFO_40MHZ 0x40
749#define MWL8K_8366_RATE_INFO_RATEID(x) ((x) & 0x3f)
750
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200751#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
752
753static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
754{
755 struct mwl8k_rxd_8366 *rxd = _rxd;
756
757 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
758 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
759}
760
761static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
762{
763 struct mwl8k_rxd_8366 *rxd = _rxd;
764
765 rxd->pkt_len = cpu_to_le16(len);
766 rxd->pkt_phys_addr = cpu_to_le32(addr);
767 wmb();
768 rxd->rx_ctrl = 0;
769}
770
771static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100772mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status,
773 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200774{
775 struct mwl8k_rxd_8366 *rxd = _rxd;
776
777 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
778 return -1;
779 rmb();
780
781 memset(status, 0, sizeof(*status));
782
783 status->signal = -rxd->rssi;
784 status->noise = -rxd->noise_floor;
785
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100786 if (rxd->rate & MWL8K_8366_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200787 status->flag |= RX_FLAG_HT;
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100788 if (rxd->rate & MWL8K_8366_RATE_INFO_40MHZ)
789 status->flag |= RX_FLAG_40MHZ;
790 status->rate_idx = MWL8K_8366_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200791 } else {
792 int i;
793
794 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
795 if (mwl8k_rates[i].hw_value == rxd->rate) {
796 status->rate_idx = i;
797 break;
798 }
799 }
800 }
801
802 status->band = IEEE80211_BAND_2GHZ;
803 status->freq = ieee80211_channel_to_frequency(rxd->channel);
804
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100805 *qos = rxd->qos_control;
806
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200807 return le16_to_cpu(rxd->pkt_len);
808}
809
810static struct rxd_ops rxd_8366_ops = {
811 .rxd_size = sizeof(struct mwl8k_rxd_8366),
812 .rxd_init = mwl8k_rxd_8366_init,
813 .rxd_refill = mwl8k_rxd_8366_refill,
814 .rxd_process = mwl8k_rxd_8366_process,
815};
816
817/*
818 * Packet reception for 88w8687.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100819 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200820struct mwl8k_rxd_8687 {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100821 __le16 pkt_len;
822 __u8 link_quality;
823 __u8 noise_level;
824 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200825 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100826 __le16 qos_control;
827 __le16 rate_info;
828 __le32 pad0[4];
829 __u8 rssi;
830 __u8 channel;
831 __le16 pad1;
832 __u8 rx_ctrl;
833 __u8 rx_status;
834 __u8 pad2[2];
835} __attribute__((packed));
836
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200837#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
838#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
839#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
840#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
841#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
842#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
843
844#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
845
846static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
847{
848 struct mwl8k_rxd_8687 *rxd = _rxd;
849
850 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
851 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
852}
853
854static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
855{
856 struct mwl8k_rxd_8687 *rxd = _rxd;
857
858 rxd->pkt_len = cpu_to_le16(len);
859 rxd->pkt_phys_addr = cpu_to_le32(addr);
860 wmb();
861 rxd->rx_ctrl = 0;
862}
863
864static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100865mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status,
866 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200867{
868 struct mwl8k_rxd_8687 *rxd = _rxd;
869 u16 rate_info;
870
871 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
872 return -1;
873 rmb();
874
875 rate_info = le16_to_cpu(rxd->rate_info);
876
877 memset(status, 0, sizeof(*status));
878
879 status->signal = -rxd->rssi;
880 status->noise = -rxd->noise_level;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200881 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
882 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
883
884 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
885 status->flag |= RX_FLAG_SHORTPRE;
886 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
887 status->flag |= RX_FLAG_40MHZ;
888 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
889 status->flag |= RX_FLAG_SHORT_GI;
890 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
891 status->flag |= RX_FLAG_HT;
892
893 status->band = IEEE80211_BAND_2GHZ;
894 status->freq = ieee80211_channel_to_frequency(rxd->channel);
895
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100896 *qos = rxd->qos_control;
897
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200898 return le16_to_cpu(rxd->pkt_len);
899}
900
901static struct rxd_ops rxd_8687_ops = {
902 .rxd_size = sizeof(struct mwl8k_rxd_8687),
903 .rxd_init = mwl8k_rxd_8687_init,
904 .rxd_refill = mwl8k_rxd_8687_refill,
905 .rxd_process = mwl8k_rxd_8687_process,
906};
907
908
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100909#define MWL8K_RX_DESCS 256
910#define MWL8K_RX_MAXSZ 3800
911
912static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
913{
914 struct mwl8k_priv *priv = hw->priv;
915 struct mwl8k_rx_queue *rxq = priv->rxq + index;
916 int size;
917 int i;
918
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200919 rxq->rxd_count = 0;
920 rxq->head = 0;
921 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100922
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200923 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100924
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200925 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
926 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100927 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200928 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100929 return -ENOMEM;
930 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200931 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100932
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200933 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
934 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100935 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200936 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200937 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100938 return -ENOMEM;
939 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200940 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100941
942 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200943 int desc_size;
944 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100945 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200946 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100947
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200948 desc_size = priv->rxd_ops->rxd_size;
949 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100950
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200951 nexti = i + 1;
952 if (nexti == MWL8K_RX_DESCS)
953 nexti = 0;
954 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
955
956 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100957 }
958
959 return 0;
960}
961
962static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
963{
964 struct mwl8k_priv *priv = hw->priv;
965 struct mwl8k_rx_queue *rxq = priv->rxq + index;
966 int refilled;
967
968 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200969 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100970 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200971 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100972 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200973 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100974
975 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
976 if (skb == NULL)
977 break;
978
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200979 addr = pci_map_single(priv->pdev, skb->data,
980 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100981
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200982 rxq->rxd_count++;
983 rx = rxq->tail++;
984 if (rxq->tail == MWL8K_RX_DESCS)
985 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200986 rxq->buf[rx].skb = skb;
987 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200988
989 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
990 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100991
992 refilled++;
993 }
994
995 return refilled;
996}
997
998/* Must be called only when the card's reception is completely halted */
999static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1000{
1001 struct mwl8k_priv *priv = hw->priv;
1002 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1003 int i;
1004
1005 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001006 if (rxq->buf[i].skb != NULL) {
1007 pci_unmap_single(priv->pdev,
1008 pci_unmap_addr(&rxq->buf[i], dma),
1009 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1010 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001011
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001012 kfree_skb(rxq->buf[i].skb);
1013 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001014 }
1015 }
1016
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001017 kfree(rxq->buf);
1018 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001019
1020 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001021 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001022 rxq->rxd, rxq->rxd_dma);
1023 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001024}
1025
1026
1027/*
1028 * Scan a list of BSSIDs to process for finalize join.
1029 * Allows for extension to process multiple BSSIDs.
1030 */
1031static inline int
1032mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1033{
1034 return priv->capture_beacon &&
1035 ieee80211_is_beacon(wh->frame_control) &&
1036 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1037}
1038
Lennert Buytenhek37797522009-10-22 20:19:45 +02001039static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1040 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001041{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001042 struct mwl8k_priv *priv = hw->priv;
1043
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001044 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001045 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001046
1047 /*
1048 * Use GFP_ATOMIC as rxq_process is called from
1049 * the primary interrupt handler, memory allocation call
1050 * must not sleep.
1051 */
1052 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1053 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001054 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001055}
1056
1057static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1058{
1059 struct mwl8k_priv *priv = hw->priv;
1060 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1061 int processed;
1062
1063 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001064 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001065 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001066 void *rxd;
1067 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001068 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001069 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001070
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001071 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001072 if (skb == NULL)
1073 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001074
1075 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1076
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001077 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001078 if (pkt_len < 0)
1079 break;
1080
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001081 rxq->buf[rxq->head].skb = NULL;
1082
1083 pci_unmap_single(priv->pdev,
1084 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1085 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1086 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001087
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001088 rxq->head++;
1089 if (rxq->head == MWL8K_RX_DESCS)
1090 rxq->head = 0;
1091
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001092 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001093
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001094 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001095 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001096
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001097 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001098 * Check for a pending join operation. Save a
1099 * copy of the beacon and schedule a tasklet to
1100 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001101 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001102 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001103 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001104
Johannes Bergf1d58c22009-06-17 13:13:00 +02001105 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1106 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001107
1108 processed++;
1109 }
1110
1111 return processed;
1112}
1113
1114
1115/*
1116 * Packet transmission.
1117 */
1118
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001119#define MWL8K_TXD_STATUS_OK 0x00000001
1120#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1121#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1122#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001123#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001124
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001125#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1126#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1127#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1128#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1129#define MWL8K_QOS_EOSP 0x0010
1130
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001131struct mwl8k_tx_desc {
1132 __le32 status;
1133 __u8 data_rate;
1134 __u8 tx_priority;
1135 __le16 qos_control;
1136 __le32 pkt_phys_addr;
1137 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001138 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001139 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001140 __le32 reserved;
1141 __le16 rate_info;
1142 __u8 peer_id;
1143 __u8 tx_frag_cnt;
1144} __attribute__((packed));
1145
1146#define MWL8K_TX_DESCS 128
1147
1148static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1149{
1150 struct mwl8k_priv *priv = hw->priv;
1151 struct mwl8k_tx_queue *txq = priv->txq + index;
1152 int size;
1153 int i;
1154
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001155 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1156 txq->stats.limit = MWL8K_TX_DESCS;
1157 txq->head = 0;
1158 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001159
1160 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1161
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001162 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1163 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001164 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001165 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001166 return -ENOMEM;
1167 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001168 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001169
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001170 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1171 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001172 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001173 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001174 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001175 return -ENOMEM;
1176 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001177 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001178
1179 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1180 struct mwl8k_tx_desc *tx_desc;
1181 int nexti;
1182
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001183 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001184 nexti = (i + 1) % MWL8K_TX_DESCS;
1185
1186 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001187 tx_desc->next_txd_phys_addr =
1188 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001189 }
1190
1191 return 0;
1192}
1193
1194static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1195{
1196 iowrite32(MWL8K_H2A_INT_PPA_READY,
1197 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1198 iowrite32(MWL8K_H2A_INT_DUMMY,
1199 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1200 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1201}
1202
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001203static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001204{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001205 struct mwl8k_priv *priv = hw->priv;
1206 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001207
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001208 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1209 struct mwl8k_tx_queue *txq = priv->txq + i;
1210 int fw_owned = 0;
1211 int drv_owned = 0;
1212 int unused = 0;
1213 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001214
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001215 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001216 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1217 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001218
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001219 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001220 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001221 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001222 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001223 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001224
1225 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001226 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001227 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001228
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001229 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1230 "fw_owned=%d drv_owned=%d unused=%d\n",
1231 wiphy_name(hw->wiphy), i,
1232 txq->stats.len, txq->head, txq->tail,
1233 fw_owned, drv_owned, unused);
1234 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001235}
1236
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001237/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001238 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001239 */
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001240#define MWL8K_TX_WAIT_TIMEOUT_MS 1000
1241
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001242static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001243{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001244 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001245 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001246 int retry;
1247 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001248
1249 might_sleep();
1250
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001251 /*
1252 * The TX queues are stopped at this point, so this test
1253 * doesn't need to take ->tx_lock.
1254 */
1255 if (!priv->pending_tx_pkts)
1256 return 0;
1257
1258 retry = 0;
1259 rc = 0;
1260
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001261 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001262 priv->tx_wait = &tx_wait;
1263 while (!rc) {
1264 int oldcount;
1265 unsigned long timeout;
1266
1267 oldcount = priv->pending_tx_pkts;
1268
1269 spin_unlock_bh(&priv->tx_lock);
1270 timeout = wait_for_completion_timeout(&tx_wait,
1271 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1272 spin_lock_bh(&priv->tx_lock);
1273
1274 if (timeout) {
1275 WARN_ON(priv->pending_tx_pkts);
1276 if (retry) {
1277 printk(KERN_NOTICE "%s: tx rings drained\n",
1278 wiphy_name(hw->wiphy));
1279 }
1280 break;
1281 }
1282
1283 if (priv->pending_tx_pkts < oldcount) {
1284 printk(KERN_NOTICE "%s: timeout waiting for tx "
1285 "rings to drain (%d -> %d pkts), retrying\n",
1286 wiphy_name(hw->wiphy), oldcount,
1287 priv->pending_tx_pkts);
1288 retry = 1;
1289 continue;
1290 }
1291
1292 priv->tx_wait = NULL;
1293
1294 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1295 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1296 mwl8k_dump_tx_rings(hw);
1297
1298 rc = -ETIMEDOUT;
1299 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001300 spin_unlock_bh(&priv->tx_lock);
1301
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001302 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001303}
1304
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001305#define MWL8K_TXD_SUCCESS(status) \
1306 ((status) & (MWL8K_TXD_STATUS_OK | \
1307 MWL8K_TXD_STATUS_OK_RETRY | \
1308 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001309
1310static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1311{
1312 struct mwl8k_priv *priv = hw->priv;
1313 struct mwl8k_tx_queue *txq = priv->txq + index;
1314 int wake = 0;
1315
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001316 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001317 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001318 struct mwl8k_tx_desc *tx_desc;
1319 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001320 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001321 struct sk_buff *skb;
1322 struct ieee80211_tx_info *info;
1323 u32 status;
1324
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001325 tx = txq->head;
1326 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001327
1328 status = le32_to_cpu(tx_desc->status);
1329
1330 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1331 if (!force)
1332 break;
1333 tx_desc->status &=
1334 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1335 }
1336
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001337 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1338 BUG_ON(txq->stats.len == 0);
1339 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001340 priv->pending_tx_pkts--;
1341
1342 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001343 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001344 skb = txq->skb[tx];
1345 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001346
1347 BUG_ON(skb == NULL);
1348 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1349
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001350 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001351
1352 /* Mark descriptor as unused */
1353 tx_desc->pkt_phys_addr = 0;
1354 tx_desc->pkt_len = 0;
1355
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001356 info = IEEE80211_SKB_CB(skb);
1357 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001358 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001359 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001360
1361 ieee80211_tx_status_irqsafe(hw, skb);
1362
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001363 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001364 }
1365
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001366 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001367 ieee80211_wake_queue(hw, index);
1368}
1369
1370/* must be called only when the card's transmit is completely halted */
1371static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1372{
1373 struct mwl8k_priv *priv = hw->priv;
1374 struct mwl8k_tx_queue *txq = priv->txq + index;
1375
1376 mwl8k_txq_reclaim(hw, index, 1);
1377
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001378 kfree(txq->skb);
1379 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001380
1381 pci_free_consistent(priv->pdev,
1382 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001383 txq->txd, txq->txd_dma);
1384 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001385}
1386
1387static int
1388mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1389{
1390 struct mwl8k_priv *priv = hw->priv;
1391 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001392 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001393 struct ieee80211_hdr *wh;
1394 struct mwl8k_tx_queue *txq;
1395 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001396 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001397 u32 txstatus;
1398 u8 txdatarate;
1399 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001400
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001401 wh = (struct ieee80211_hdr *)skb->data;
1402 if (ieee80211_is_data_qos(wh->frame_control))
1403 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1404 else
1405 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001406
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001407 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001408 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001409
1410 tx_info = IEEE80211_SKB_CB(skb);
1411 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001412
1413 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1414 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001415
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001416 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1417 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1418 mwl8k_vif->seqno = seqno++ % 4096;
1419 }
1420
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001421 /* Setup firmware control bit fields for each frame type. */
1422 txstatus = 0;
1423 txdatarate = 0;
1424 if (ieee80211_is_mgmt(wh->frame_control) ||
1425 ieee80211_is_ctl(wh->frame_control)) {
1426 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001427 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001428 } else if (ieee80211_is_data(wh->frame_control)) {
1429 txdatarate = 1;
1430 if (is_multicast_ether_addr(wh->addr1))
1431 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1432
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001433 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001434 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001435 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001436 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001437 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001438 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001439
1440 dma = pci_map_single(priv->pdev, skb->data,
1441 skb->len, PCI_DMA_TODEVICE);
1442
1443 if (pci_dma_mapping_error(priv->pdev, dma)) {
1444 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001445 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001446 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001447 return NETDEV_TX_OK;
1448 }
1449
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001450 spin_lock_bh(&priv->tx_lock);
1451
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001452 txq = priv->txq + index;
1453
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001454 BUG_ON(txq->skb[txq->tail] != NULL);
1455 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001456
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001457 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001458 tx->data_rate = txdatarate;
1459 tx->tx_priority = index;
1460 tx->qos_control = cpu_to_le16(qos);
1461 tx->pkt_phys_addr = cpu_to_le32(dma);
1462 tx->pkt_len = cpu_to_le16(skb->len);
1463 tx->rate_info = 0;
1464 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001465 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001466 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1467
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001468 txq->stats.count++;
1469 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001470 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001471
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001472 txq->tail++;
1473 if (txq->tail == MWL8K_TX_DESCS)
1474 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001475
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001476 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001477 ieee80211_stop_queue(hw, index);
1478
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001479 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001480
1481 spin_unlock_bh(&priv->tx_lock);
1482
1483 return NETDEV_TX_OK;
1484}
1485
1486
1487/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001488 * Firmware access.
1489 *
1490 * We have the following requirements for issuing firmware commands:
1491 * - Some commands require that the packet transmit path is idle when
1492 * the command is issued. (For simplicity, we'll just quiesce the
1493 * transmit path for every command.)
1494 * - There are certain sequences of commands that need to be issued to
1495 * the hardware sequentially, with no other intervening commands.
1496 *
1497 * This leads to an implementation of a "firmware lock" as a mutex that
1498 * can be taken recursively, and which is taken by both the low-level
1499 * command submission function (mwl8k_post_cmd) as well as any users of
1500 * that function that require issuing of an atomic sequence of commands,
1501 * and quiesces the transmit path whenever it's taken.
1502 */
1503static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1504{
1505 struct mwl8k_priv *priv = hw->priv;
1506
1507 if (priv->fw_mutex_owner != current) {
1508 int rc;
1509
1510 mutex_lock(&priv->fw_mutex);
1511 ieee80211_stop_queues(hw);
1512
1513 rc = mwl8k_tx_wait_empty(hw);
1514 if (rc) {
1515 ieee80211_wake_queues(hw);
1516 mutex_unlock(&priv->fw_mutex);
1517
1518 return rc;
1519 }
1520
1521 priv->fw_mutex_owner = current;
1522 }
1523
1524 priv->fw_mutex_depth++;
1525
1526 return 0;
1527}
1528
1529static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1530{
1531 struct mwl8k_priv *priv = hw->priv;
1532
1533 if (!--priv->fw_mutex_depth) {
1534 ieee80211_wake_queues(hw);
1535 priv->fw_mutex_owner = NULL;
1536 mutex_unlock(&priv->fw_mutex);
1537 }
1538}
1539
1540
1541/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001542 * Command processing.
1543 */
1544
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01001545/* Timeout firmware commands after 10s */
1546#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001547
1548static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1549{
1550 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1551 struct mwl8k_priv *priv = hw->priv;
1552 void __iomem *regs = priv->regs;
1553 dma_addr_t dma_addr;
1554 unsigned int dma_size;
1555 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001556 unsigned long timeout = 0;
1557 u8 buf[32];
1558
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001559 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001560 dma_size = le16_to_cpu(cmd->length);
1561 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1562 PCI_DMA_BIDIRECTIONAL);
1563 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1564 return -ENOMEM;
1565
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001566 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001567 if (rc) {
1568 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1569 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001570 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001571 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001572
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001573 priv->hostcmd_wait = &cmd_wait;
1574 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1575 iowrite32(MWL8K_H2A_INT_DOORBELL,
1576 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1577 iowrite32(MWL8K_H2A_INT_DUMMY,
1578 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001579
1580 timeout = wait_for_completion_timeout(&cmd_wait,
1581 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1582
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001583 priv->hostcmd_wait = NULL;
1584
1585 mwl8k_fw_unlock(hw);
1586
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001587 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1588 PCI_DMA_BIDIRECTIONAL);
1589
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001590 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001591 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001592 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001593 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1594 MWL8K_CMD_TIMEOUT_MS);
1595 rc = -ETIMEDOUT;
1596 } else {
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01001597 int ms;
1598
1599 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1600
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001601 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001602 if (rc)
1603 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001604 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001605 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001606 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01001607 else if (ms > 2000)
1608 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1609 wiphy_name(hw->wiphy),
1610 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1611 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001612 }
1613
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001614 return rc;
1615}
1616
1617/*
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001618 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001619 */
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001620struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001621 struct mwl8k_cmd_pkt header;
1622 __u8 hw_rev;
1623 __u8 host_interface;
1624 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001625 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001626 __le16 region_code;
1627 __le32 fw_rev;
1628 __le32 ps_cookie;
1629 __le32 caps;
1630 __u8 mcs_bitmap[16];
1631 __le32 rx_queue_ptr;
1632 __le32 num_tx_queues;
1633 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1634 __le32 caps2;
1635 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001636 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001637} __attribute__((packed));
1638
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001639static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001640{
1641 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001642 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001643 int rc;
1644 int i;
1645
1646 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1647 if (cmd == NULL)
1648 return -ENOMEM;
1649
1650 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1651 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1652
1653 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1654 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001655 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001656 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001657 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001658 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001659 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001660 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001661
1662 rc = mwl8k_post_cmd(hw, &cmd->header);
1663
1664 if (!rc) {
1665 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1666 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001667 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001668 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001669 }
1670
1671 kfree(cmd);
1672 return rc;
1673}
1674
1675/*
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02001676 * CMD_GET_HW_SPEC (AP version).
1677 */
1678struct mwl8k_cmd_get_hw_spec_ap {
1679 struct mwl8k_cmd_pkt header;
1680 __u8 hw_rev;
1681 __u8 host_interface;
1682 __le16 num_wcb;
1683 __le16 num_mcaddrs;
1684 __u8 perm_addr[ETH_ALEN];
1685 __le16 region_code;
1686 __le16 num_antenna;
1687 __le32 fw_rev;
1688 __le32 wcbbase0;
1689 __le32 rxwrptr;
1690 __le32 rxrdptr;
1691 __le32 ps_cookie;
1692 __le32 wcbbase1;
1693 __le32 wcbbase2;
1694 __le32 wcbbase3;
1695} __attribute__((packed));
1696
1697static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1698{
1699 struct mwl8k_priv *priv = hw->priv;
1700 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1701 int rc;
1702
1703 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1704 if (cmd == NULL)
1705 return -ENOMEM;
1706
1707 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1708 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1709
1710 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1711 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1712
1713 rc = mwl8k_post_cmd(hw, &cmd->header);
1714
1715 if (!rc) {
1716 int off;
1717
1718 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1719 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1720 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1721 priv->hw_rev = cmd->hw_rev;
1722
1723 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1724 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1725
1726 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1727 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1728
1729 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1730 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1731
1732 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1733 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1734
1735 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1736 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1737
1738 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1739 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1740 }
1741
1742 kfree(cmd);
1743 return rc;
1744}
1745
1746/*
1747 * CMD_SET_HW_SPEC.
1748 */
1749struct mwl8k_cmd_set_hw_spec {
1750 struct mwl8k_cmd_pkt header;
1751 __u8 hw_rev;
1752 __u8 host_interface;
1753 __le16 num_mcaddrs;
1754 __u8 perm_addr[ETH_ALEN];
1755 __le16 region_code;
1756 __le32 fw_rev;
1757 __le32 ps_cookie;
1758 __le32 caps;
1759 __le32 rx_queue_ptr;
1760 __le32 num_tx_queues;
1761 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1762 __le32 flags;
1763 __le32 num_tx_desc_per_queue;
1764 __le32 total_rxd;
1765} __attribute__((packed));
1766
1767#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1768
1769static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1770{
1771 struct mwl8k_priv *priv = hw->priv;
1772 struct mwl8k_cmd_set_hw_spec *cmd;
1773 int rc;
1774 int i;
1775
1776 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1777 if (cmd == NULL)
1778 return -ENOMEM;
1779
1780 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1781 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1782
1783 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1784 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1785 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1786 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1787 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1788 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1789 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1790 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1791
1792 rc = mwl8k_post_cmd(hw, &cmd->header);
1793 kfree(cmd);
1794
1795 return rc;
1796}
1797
1798/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001799 * CMD_MAC_MULTICAST_ADR.
1800 */
1801struct mwl8k_cmd_mac_multicast_adr {
1802 struct mwl8k_cmd_pkt header;
1803 __le16 action;
1804 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001805 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001806};
1807
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001808#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1809#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1810#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1811#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001812
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001813static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001814__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001815 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001816{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001817 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001818 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001819 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001820
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001821 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001822 allmulti = 1;
1823 mc_count = 0;
1824 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001825
1826 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1827
1828 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001829 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001830 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001831
1832 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1833 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001834 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1835 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001836
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001837 if (allmulti) {
1838 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1839 } else if (mc_count) {
1840 int i;
1841
1842 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1843 cmd->numaddr = cpu_to_le16(mc_count);
1844 for (i = 0; i < mc_count && mclist; i++) {
1845 if (mclist->da_addrlen != ETH_ALEN) {
1846 kfree(cmd);
1847 return NULL;
1848 }
1849 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1850 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001851 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001852 }
1853
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001854 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001855}
1856
1857/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001858 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001859 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001860struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001861 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001862 __le32 stats[64];
1863} __attribute__((packed));
1864
1865#define MWL8K_STAT_ACK_FAILURE 9
1866#define MWL8K_STAT_RTS_FAILURE 12
1867#define MWL8K_STAT_FCS_ERROR 24
1868#define MWL8K_STAT_RTS_SUCCESS 11
1869
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001870static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1871 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001872{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001873 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001874 int rc;
1875
1876 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1877 if (cmd == NULL)
1878 return -ENOMEM;
1879
1880 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1881 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001882
1883 rc = mwl8k_post_cmd(hw, &cmd->header);
1884 if (!rc) {
1885 stats->dot11ACKFailureCount =
1886 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1887 stats->dot11RTSFailureCount =
1888 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1889 stats->dot11FCSErrorCount =
1890 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1891 stats->dot11RTSSuccessCount =
1892 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1893 }
1894 kfree(cmd);
1895
1896 return rc;
1897}
1898
1899/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001900 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001901 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001902struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001903 struct mwl8k_cmd_pkt header;
1904 __le16 action;
1905 __le16 control;
1906 __le16 radio_on;
1907} __attribute__((packed));
1908
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001909static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001910mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001911{
1912 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001913 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001914 int rc;
1915
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001916 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001917 return 0;
1918
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001919 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1920 if (cmd == NULL)
1921 return -ENOMEM;
1922
1923 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1924 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1925 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001926 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001927 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1928
1929 rc = mwl8k_post_cmd(hw, &cmd->header);
1930 kfree(cmd);
1931
1932 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001933 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001934
1935 return rc;
1936}
1937
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001938static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001939{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001940 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001941}
1942
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001943static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001944{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001945 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001946}
1947
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001948static int
1949mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1950{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01001951 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001952
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001953 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001954
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001955 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001956}
1957
1958/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001959 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001960 */
1961#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1962
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001963struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001964 struct mwl8k_cmd_pkt header;
1965 __le16 action;
1966 __le16 support_level;
1967 __le16 current_level;
1968 __le16 reserved;
1969 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1970} __attribute__((packed));
1971
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001972static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001973{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001974 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001975 int rc;
1976
1977 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1978 if (cmd == NULL)
1979 return -ENOMEM;
1980
1981 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1982 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1983 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1984 cmd->support_level = cpu_to_le16(dBm);
1985
1986 rc = mwl8k_post_cmd(hw, &cmd->header);
1987 kfree(cmd);
1988
1989 return rc;
1990}
1991
1992/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02001993 * CMD_RF_ANTENNA.
1994 */
1995struct mwl8k_cmd_rf_antenna {
1996 struct mwl8k_cmd_pkt header;
1997 __le16 antenna;
1998 __le16 mode;
1999} __attribute__((packed));
2000
2001#define MWL8K_RF_ANTENNA_RX 1
2002#define MWL8K_RF_ANTENNA_TX 2
2003
2004static int
2005mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2006{
2007 struct mwl8k_cmd_rf_antenna *cmd;
2008 int rc;
2009
2010 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2011 if (cmd == NULL)
2012 return -ENOMEM;
2013
2014 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2015 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2016 cmd->antenna = cpu_to_le16(antenna);
2017 cmd->mode = cpu_to_le16(mask);
2018
2019 rc = mwl8k_post_cmd(hw, &cmd->header);
2020 kfree(cmd);
2021
2022 return rc;
2023}
2024
2025/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002026 * CMD_SET_PRE_SCAN.
2027 */
2028struct mwl8k_cmd_set_pre_scan {
2029 struct mwl8k_cmd_pkt header;
2030} __attribute__((packed));
2031
2032static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2033{
2034 struct mwl8k_cmd_set_pre_scan *cmd;
2035 int rc;
2036
2037 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2038 if (cmd == NULL)
2039 return -ENOMEM;
2040
2041 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2042 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2043
2044 rc = mwl8k_post_cmd(hw, &cmd->header);
2045 kfree(cmd);
2046
2047 return rc;
2048}
2049
2050/*
2051 * CMD_SET_POST_SCAN.
2052 */
2053struct mwl8k_cmd_set_post_scan {
2054 struct mwl8k_cmd_pkt header;
2055 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002056 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002057} __attribute__((packed));
2058
2059static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002060mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002061{
2062 struct mwl8k_cmd_set_post_scan *cmd;
2063 int rc;
2064
2065 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2066 if (cmd == NULL)
2067 return -ENOMEM;
2068
2069 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2070 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2071 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002072 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002073
2074 rc = mwl8k_post_cmd(hw, &cmd->header);
2075 kfree(cmd);
2076
2077 return rc;
2078}
2079
2080/*
2081 * CMD_SET_RF_CHANNEL.
2082 */
2083struct mwl8k_cmd_set_rf_channel {
2084 struct mwl8k_cmd_pkt header;
2085 __le16 action;
2086 __u8 current_channel;
2087 __le32 channel_flags;
2088} __attribute__((packed));
2089
2090static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2091 struct ieee80211_channel *channel)
2092{
2093 struct mwl8k_cmd_set_rf_channel *cmd;
2094 int rc;
2095
2096 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2097 if (cmd == NULL)
2098 return -ENOMEM;
2099
2100 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2101 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2102 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2103 cmd->current_channel = channel->hw_value;
2104 if (channel->band == IEEE80211_BAND_2GHZ)
2105 cmd->channel_flags = cpu_to_le32(0x00000081);
2106 else
2107 cmd->channel_flags = cpu_to_le32(0x00000000);
2108
2109 rc = mwl8k_post_cmd(hw, &cmd->header);
2110 kfree(cmd);
2111
2112 return rc;
2113}
2114
2115/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002116 * CMD_SET_AID.
2117 */
2118#define MWL8K_FRAME_PROT_DISABLED 0x00
2119#define MWL8K_FRAME_PROT_11G 0x07
2120#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2121#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2122
2123struct mwl8k_cmd_update_set_aid {
2124 struct mwl8k_cmd_pkt header;
2125 __le16 aid;
2126
2127 /* AP's MAC address (BSSID) */
2128 __u8 bssid[ETH_ALEN];
2129 __le16 protection_mode;
2130 __u8 supp_rates[14];
2131} __attribute__((packed));
2132
2133static int
2134mwl8k_cmd_set_aid(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2135{
2136 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2137 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2138 struct mwl8k_cmd_update_set_aid *cmd;
2139 u16 prot_mode;
2140 int rc;
2141
2142 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2143 if (cmd == NULL)
2144 return -ENOMEM;
2145
2146 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2147 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2148 cmd->aid = cpu_to_le16(info->aid);
2149
2150 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
2151
2152 if (info->use_cts_prot) {
2153 prot_mode = MWL8K_FRAME_PROT_11G;
2154 } else {
2155 switch (info->ht_operation_mode &
2156 IEEE80211_HT_OP_MODE_PROTECTION) {
2157 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2158 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2159 break;
2160 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2161 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2162 break;
2163 default:
2164 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2165 break;
2166 }
2167 }
2168 cmd->protection_mode = cpu_to_le16(prot_mode);
2169
2170 memcpy(cmd->supp_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
2171
2172 rc = mwl8k_post_cmd(hw, &cmd->header);
2173 kfree(cmd);
2174
2175 return rc;
2176}
2177
2178/*
2179 * CMD_SET_RATE.
2180 */
2181struct mwl8k_cmd_set_rate {
2182 struct mwl8k_cmd_pkt header;
2183 __u8 legacy_rates[14];
2184
2185 /* Bitmap for supported MCS codes. */
2186 __u8 mcs_set[16];
2187 __u8 reserved[16];
2188} __attribute__((packed));
2189
2190static int
2191mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2192{
2193 struct mwl8k_cmd_set_rate *cmd;
2194 int rc;
2195
2196 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2197 if (cmd == NULL)
2198 return -ENOMEM;
2199
2200 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2201 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2202 memcpy(cmd->legacy_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
2203
2204 rc = mwl8k_post_cmd(hw, &cmd->header);
2205 kfree(cmd);
2206
2207 return rc;
2208}
2209
2210/*
2211 * CMD_FINALIZE_JOIN.
2212 */
2213#define MWL8K_FJ_BEACON_MAXLEN 128
2214
2215struct mwl8k_cmd_finalize_join {
2216 struct mwl8k_cmd_pkt header;
2217 __le32 sleep_interval; /* Number of beacon periods to sleep */
2218 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2219} __attribute__((packed));
2220
2221static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2222 int framelen, int dtim)
2223{
2224 struct mwl8k_cmd_finalize_join *cmd;
2225 struct ieee80211_mgmt *payload = frame;
2226 int payload_len;
2227 int rc;
2228
2229 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2230 if (cmd == NULL)
2231 return -ENOMEM;
2232
2233 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2234 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2235 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2236
2237 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2238 if (payload_len < 0)
2239 payload_len = 0;
2240 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2241 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2242
2243 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2244
2245 rc = mwl8k_post_cmd(hw, &cmd->header);
2246 kfree(cmd);
2247
2248 return rc;
2249}
2250
2251/*
2252 * CMD_SET_RTS_THRESHOLD.
2253 */
2254struct mwl8k_cmd_set_rts_threshold {
2255 struct mwl8k_cmd_pkt header;
2256 __le16 action;
2257 __le16 threshold;
2258} __attribute__((packed));
2259
2260static int mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw,
2261 u16 action, u16 threshold)
2262{
2263 struct mwl8k_cmd_set_rts_threshold *cmd;
2264 int rc;
2265
2266 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2267 if (cmd == NULL)
2268 return -ENOMEM;
2269
2270 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2271 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2272 cmd->action = cpu_to_le16(action);
2273 cmd->threshold = cpu_to_le16(threshold);
2274
2275 rc = mwl8k_post_cmd(hw, &cmd->header);
2276 kfree(cmd);
2277
2278 return rc;
2279}
2280
2281/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002282 * CMD_SET_SLOT.
2283 */
2284struct mwl8k_cmd_set_slot {
2285 struct mwl8k_cmd_pkt header;
2286 __le16 action;
2287 __u8 short_slot;
2288} __attribute__((packed));
2289
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002290static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002291{
2292 struct mwl8k_cmd_set_slot *cmd;
2293 int rc;
2294
2295 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2296 if (cmd == NULL)
2297 return -ENOMEM;
2298
2299 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2300 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2301 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002302 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002303
2304 rc = mwl8k_post_cmd(hw, &cmd->header);
2305 kfree(cmd);
2306
2307 return rc;
2308}
2309
2310/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002311 * CMD_SET_EDCA_PARAMS.
2312 */
2313struct mwl8k_cmd_set_edca_params {
2314 struct mwl8k_cmd_pkt header;
2315
2316 /* See MWL8K_SET_EDCA_XXX below */
2317 __le16 action;
2318
2319 /* TX opportunity in units of 32 us */
2320 __le16 txop;
2321
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002322 union {
2323 struct {
2324 /* Log exponent of max contention period: 0...15 */
2325 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002326
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002327 /* Log exponent of min contention period: 0...15 */
2328 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002329
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002330 /* Adaptive interframe spacing in units of 32us */
2331 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002332
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002333 /* TX queue to configure */
2334 __u8 txq;
2335 } ap;
2336 struct {
2337 /* Log exponent of max contention period: 0...15 */
2338 __u8 log_cw_max;
2339
2340 /* Log exponent of min contention period: 0...15 */
2341 __u8 log_cw_min;
2342
2343 /* Adaptive interframe spacing in units of 32us */
2344 __u8 aifs;
2345
2346 /* TX queue to configure */
2347 __u8 txq;
2348 } sta;
2349 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002350} __attribute__((packed));
2351
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002352#define MWL8K_SET_EDCA_CW 0x01
2353#define MWL8K_SET_EDCA_TXOP 0x02
2354#define MWL8K_SET_EDCA_AIFS 0x04
2355
2356#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2357 MWL8K_SET_EDCA_TXOP | \
2358 MWL8K_SET_EDCA_AIFS)
2359
2360static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002361mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2362 __u16 cw_min, __u16 cw_max,
2363 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002364{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002365 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002366 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002367 int rc;
2368
2369 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2370 if (cmd == NULL)
2371 return -ENOMEM;
2372
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002373 /*
2374 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2375 * this call.
2376 */
2377 qnum ^= !(qnum >> 1);
2378
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002379 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2380 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002381 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2382 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002383 if (priv->ap_fw) {
2384 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2385 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2386 cmd->ap.aifs = aifs;
2387 cmd->ap.txq = qnum;
2388 } else {
2389 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2390 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2391 cmd->sta.aifs = aifs;
2392 cmd->sta.txq = qnum;
2393 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002394
2395 rc = mwl8k_post_cmd(hw, &cmd->header);
2396 kfree(cmd);
2397
2398 return rc;
2399}
2400
2401/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002402 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002403 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002404struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002405 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002406 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002407} __attribute__((packed));
2408
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002409static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002410{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002411 struct mwl8k_priv *priv = hw->priv;
2412 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002413 int rc;
2414
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002415 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2416 if (cmd == NULL)
2417 return -ENOMEM;
2418
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002419 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002420 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002421 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002422
2423 rc = mwl8k_post_cmd(hw, &cmd->header);
2424 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002425
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002426 if (!rc)
2427 priv->wmm_enabled = enable;
2428
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002429 return rc;
2430}
2431
2432/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002433 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002434 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002435struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002436 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002437 __le32 action;
2438 __u8 rx_antenna_map;
2439 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002440} __attribute__((packed));
2441
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002442static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002443{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002444 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002445 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002446
2447 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2448 if (cmd == NULL)
2449 return -ENOMEM;
2450
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002451 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002452 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002453 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2454 cmd->rx_antenna_map = rx;
2455 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002456
2457 rc = mwl8k_post_cmd(hw, &cmd->header);
2458 kfree(cmd);
2459
2460 return rc;
2461}
2462
2463/*
2464 * CMD_USE_FIXED_RATE.
2465 */
2466#define MWL8K_RATE_TABLE_SIZE 8
2467#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002468#define MWL8K_USE_AUTO_RATE 0x0002
2469
2470struct mwl8k_rate_entry {
2471 /* Set to 1 if HT rate, 0 if legacy. */
2472 __le32 is_ht_rate;
2473
2474 /* Set to 1 to use retry_count field. */
2475 __le32 enable_retry;
2476
2477 /* Specified legacy rate or MCS. */
2478 __le32 rate;
2479
2480 /* Number of allowed retries. */
2481 __le32 retry_count;
2482} __attribute__((packed));
2483
2484struct mwl8k_rate_table {
2485 /* 1 to allow specified rate and below */
2486 __le32 allow_rate_drop;
2487 __le32 num_rates;
2488 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2489} __attribute__((packed));
2490
2491struct mwl8k_cmd_use_fixed_rate {
2492 struct mwl8k_cmd_pkt header;
2493 __le32 action;
2494 struct mwl8k_rate_table rate_table;
2495
2496 /* Unicast, Broadcast or Multicast */
2497 __le32 rate_type;
2498 __le32 reserved1;
2499 __le32 reserved2;
2500} __attribute__((packed));
2501
2502static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2503 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2504{
2505 struct mwl8k_cmd_use_fixed_rate *cmd;
2506 int count;
2507 int rc;
2508
2509 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2510 if (cmd == NULL)
2511 return -ENOMEM;
2512
2513 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2514 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2515
2516 cmd->action = cpu_to_le32(action);
2517 cmd->rate_type = cpu_to_le32(rate_type);
2518
2519 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002520 /*
2521 * Copy over each field manually so that endian
2522 * conversion can be done.
2523 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002524 cmd->rate_table.allow_rate_drop =
2525 cpu_to_le32(rate_table->allow_rate_drop);
2526 cmd->rate_table.num_rates =
2527 cpu_to_le32(rate_table->num_rates);
2528
2529 for (count = 0; count < rate_table->num_rates; count++) {
2530 struct mwl8k_rate_entry *dst =
2531 &cmd->rate_table.rate_entry[count];
2532 struct mwl8k_rate_entry *src =
2533 &rate_table->rate_entry[count];
2534
2535 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2536 dst->enable_retry = cpu_to_le32(src->enable_retry);
2537 dst->rate = cpu_to_le32(src->rate);
2538 dst->retry_count = cpu_to_le32(src->retry_count);
2539 }
2540 }
2541
2542 rc = mwl8k_post_cmd(hw, &cmd->header);
2543 kfree(cmd);
2544
2545 return rc;
2546}
2547
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002548/*
2549 * CMD_ENABLE_SNIFFER.
2550 */
2551struct mwl8k_cmd_enable_sniffer {
2552 struct mwl8k_cmd_pkt header;
2553 __le32 action;
2554} __attribute__((packed));
2555
2556static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2557{
2558 struct mwl8k_cmd_enable_sniffer *cmd;
2559 int rc;
2560
2561 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2562 if (cmd == NULL)
2563 return -ENOMEM;
2564
2565 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2566 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2567 cmd->action = cpu_to_le32(!!enable);
2568
2569 rc = mwl8k_post_cmd(hw, &cmd->header);
2570 kfree(cmd);
2571
2572 return rc;
2573}
2574
2575/*
2576 * CMD_SET_MAC_ADDR.
2577 */
2578struct mwl8k_cmd_set_mac_addr {
2579 struct mwl8k_cmd_pkt header;
2580 union {
2581 struct {
2582 __le16 mac_type;
2583 __u8 mac_addr[ETH_ALEN];
2584 } mbss;
2585 __u8 mac_addr[ETH_ALEN];
2586 };
2587} __attribute__((packed));
2588
2589static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2590{
2591 struct mwl8k_priv *priv = hw->priv;
2592 struct mwl8k_cmd_set_mac_addr *cmd;
2593 int rc;
2594
2595 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2596 if (cmd == NULL)
2597 return -ENOMEM;
2598
2599 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2600 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2601 if (priv->ap_fw) {
2602 cmd->mbss.mac_type = 0;
2603 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2604 } else {
2605 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2606 }
2607
2608 rc = mwl8k_post_cmd(hw, &cmd->header);
2609 kfree(cmd);
2610
2611 return rc;
2612}
2613
2614/*
2615 * CMD_SET_RATEADAPT_MODE.
2616 */
2617struct mwl8k_cmd_set_rate_adapt_mode {
2618 struct mwl8k_cmd_pkt header;
2619 __le16 action;
2620 __le16 mode;
2621} __attribute__((packed));
2622
2623static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2624{
2625 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2626 int rc;
2627
2628 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2629 if (cmd == NULL)
2630 return -ENOMEM;
2631
2632 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2633 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2634 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2635 cmd->mode = cpu_to_le16(mode);
2636
2637 rc = mwl8k_post_cmd(hw, &cmd->header);
2638 kfree(cmd);
2639
2640 return rc;
2641}
2642
2643/*
2644 * CMD_UPDATE_STADB.
2645 */
2646struct mwl8k_cmd_update_stadb {
2647 struct mwl8k_cmd_pkt header;
2648
2649 /* See STADB_ACTION_TYPE */
2650 __le32 action;
2651
2652 /* Peer MAC address */
2653 __u8 peer_addr[ETH_ALEN];
2654
2655 __le32 reserved;
2656
2657 /* Peer info - valid during add/update. */
2658 struct peer_capability_info peer_info;
2659} __attribute__((packed));
2660
2661static int mwl8k_cmd_update_stadb(struct ieee80211_hw *hw,
2662 struct ieee80211_vif *vif, __u32 action)
2663{
2664 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2665 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2666 struct mwl8k_cmd_update_stadb *cmd;
2667 struct peer_capability_info *peer_info;
2668 int rc;
2669
2670 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2671 if (cmd == NULL)
2672 return -ENOMEM;
2673
2674 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2675 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2676
2677 cmd->action = cpu_to_le32(action);
2678 peer_info = &cmd->peer_info;
2679 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2680
2681 switch (action) {
2682 case MWL8K_STA_DB_ADD_ENTRY:
2683 case MWL8K_STA_DB_MODIFY_ENTRY:
2684 /* Build peer_info block */
2685 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2686 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2687 memcpy(peer_info->legacy_rates, mwl8k_rateids,
2688 sizeof(mwl8k_rateids));
2689 peer_info->interop = 1;
2690 peer_info->amsdu_enabled = 0;
2691
2692 rc = mwl8k_post_cmd(hw, &cmd->header);
2693 if (rc == 0)
2694 mv_vif->peer_id = peer_info->station_id;
2695
2696 break;
2697
2698 case MWL8K_STA_DB_DEL_ENTRY:
2699 case MWL8K_STA_DB_FLUSH:
2700 default:
2701 rc = mwl8k_post_cmd(hw, &cmd->header);
2702 if (rc == 0)
2703 mv_vif->peer_id = 0;
2704 break;
2705 }
2706 kfree(cmd);
2707
2708 return rc;
2709}
2710
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002711
2712/*
2713 * Interrupt handling.
2714 */
2715static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2716{
2717 struct ieee80211_hw *hw = dev_id;
2718 struct mwl8k_priv *priv = hw->priv;
2719 u32 status;
2720
2721 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2722 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2723
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002724 if (!status)
2725 return IRQ_NONE;
2726
2727 if (status & MWL8K_A2H_INT_TX_DONE)
2728 tasklet_schedule(&priv->tx_reclaim_task);
2729
2730 if (status & MWL8K_A2H_INT_RX_READY) {
2731 while (rxq_process(hw, 0, 1))
2732 rxq_refill(hw, 0, 1);
2733 }
2734
2735 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002736 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002737 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002738 }
2739
2740 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002741 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002742 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002743 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002744 }
2745
2746 return IRQ_HANDLED;
2747}
2748
2749
2750/*
2751 * Core driver operations.
2752 */
2753static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2754{
2755 struct mwl8k_priv *priv = hw->priv;
2756 int index = skb_get_queue_mapping(skb);
2757 int rc;
2758
2759 if (priv->current_channel == NULL) {
2760 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002761 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002762 dev_kfree_skb(skb);
2763 return NETDEV_TX_OK;
2764 }
2765
2766 rc = mwl8k_txq_xmit(hw, index, skb);
2767
2768 return rc;
2769}
2770
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002771static int mwl8k_start(struct ieee80211_hw *hw)
2772{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002773 struct mwl8k_priv *priv = hw->priv;
2774 int rc;
2775
Joe Perchesa0607fd2009-11-18 23:29:17 -08002776 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002777 IRQF_SHARED, MWL8K_NAME, hw);
2778 if (rc) {
2779 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002780 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002781 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002782 }
2783
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002784 /* Enable tx reclaim tasklet */
2785 tasklet_enable(&priv->tx_reclaim_task);
2786
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002787 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002788 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002789
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002790 rc = mwl8k_fw_lock(hw);
2791 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002792 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002793
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002794 if (!priv->ap_fw) {
2795 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002796 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002797
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002798 if (!rc)
2799 rc = mwl8k_cmd_set_pre_scan(hw);
2800
2801 if (!rc)
2802 rc = mwl8k_cmd_set_post_scan(hw,
2803 "\x00\x00\x00\x00\x00\x00");
2804 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002805
2806 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002807 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002808
2809 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002810 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002811
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002812 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002813 }
2814
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002815 if (rc) {
2816 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2817 free_irq(priv->pdev->irq, hw);
2818 tasklet_disable(&priv->tx_reclaim_task);
2819 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002820
2821 return rc;
2822}
2823
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002824static void mwl8k_stop(struct ieee80211_hw *hw)
2825{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002826 struct mwl8k_priv *priv = hw->priv;
2827 int i;
2828
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002829 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002830
2831 ieee80211_stop_queues(hw);
2832
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002833 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002834 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002835 free_irq(priv->pdev->irq, hw);
2836
2837 /* Stop finalize join worker */
2838 cancel_work_sync(&priv->finalize_join_worker);
2839 if (priv->beacon_skb != NULL)
2840 dev_kfree_skb(priv->beacon_skb);
2841
2842 /* Stop tx reclaim tasklet */
2843 tasklet_disable(&priv->tx_reclaim_task);
2844
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002845 /* Return all skbs to mac80211 */
2846 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2847 mwl8k_txq_reclaim(hw, i, 1);
2848}
2849
2850static int mwl8k_add_interface(struct ieee80211_hw *hw,
2851 struct ieee80211_if_init_conf *conf)
2852{
2853 struct mwl8k_priv *priv = hw->priv;
2854 struct mwl8k_vif *mwl8k_vif;
2855
2856 /*
2857 * We only support one active interface at a time.
2858 */
2859 if (priv->vif != NULL)
2860 return -EBUSY;
2861
2862 /*
2863 * We only support managed interfaces for now.
2864 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002865 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002866 return -EINVAL;
2867
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002868 /*
2869 * Reject interface creation if sniffer mode is active, as
2870 * STA operation is mutually exclusive with hardware sniffer
2871 * mode.
2872 */
2873 if (priv->sniffer_enabled) {
2874 printk(KERN_INFO "%s: unable to create STA "
2875 "interface due to sniffer mode being enabled\n",
2876 wiphy_name(hw->wiphy));
2877 return -EINVAL;
2878 }
2879
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002880 /* Clean out driver private area */
2881 mwl8k_vif = MWL8K_VIF(conf->vif);
2882 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2883
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002884 /* Set and save the mac address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002885 mwl8k_cmd_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002886 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002887
2888 /* Back pointer to parent config block */
2889 mwl8k_vif->priv = priv;
2890
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002891 /* Set Initial sequence number to zero */
2892 mwl8k_vif->seqno = 0;
2893
2894 priv->vif = conf->vif;
2895 priv->current_channel = NULL;
2896
2897 return 0;
2898}
2899
2900static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2901 struct ieee80211_if_init_conf *conf)
2902{
2903 struct mwl8k_priv *priv = hw->priv;
2904
2905 if (priv->vif == NULL)
2906 return;
2907
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002908 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002909
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002910 priv->vif = NULL;
2911}
2912
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002913static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002914{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002915 struct ieee80211_conf *conf = &hw->conf;
2916 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002917 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002918
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002919 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002920 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002921 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002922 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002923 }
2924
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002925 rc = mwl8k_fw_lock(hw);
2926 if (rc)
2927 return rc;
2928
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002929 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002930 if (rc)
2931 goto out;
2932
2933 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2934 if (rc)
2935 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002936
2937 priv->current_channel = conf->channel;
2938
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002939 if (conf->power_level > 18)
2940 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002941 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002942 if (rc)
2943 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002944
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002945 if (priv->ap_fw) {
2946 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2947 if (!rc)
2948 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2949 } else {
2950 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2951 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002952
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002953out:
2954 mwl8k_fw_unlock(hw);
2955
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002956 return rc;
2957}
2958
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002959static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
2960 struct ieee80211_vif *vif,
2961 struct ieee80211_bss_conf *info,
2962 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002963{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002964 struct mwl8k_priv *priv = hw->priv;
2965 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002966 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002967
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002968 if ((changed & BSS_CHANGED_ASSOC) == 0)
2969 return;
2970
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002971 priv->capture_beacon = false;
2972
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002973 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02002974 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002975 return;
2976
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002977 if (info->assoc) {
2978 memcpy(&mwl8k_vif->bss_info, info,
2979 sizeof(struct ieee80211_bss_conf));
2980
Lennert Buytenhekd1844d72009-11-30 18:13:56 +01002981 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
2982
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002983 /* Install rates */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002984 rc = mwl8k_cmd_set_rate(hw, vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002985 if (rc)
2986 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002987
2988 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002989 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
2990 MWL8K_UCAST_RATE, NULL);
2991 if (rc)
2992 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002993
2994 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002995 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
2996 if (rc)
2997 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002998
2999 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003000 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
3001 if (rc)
3002 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003003
3004 /* Update peer rate info */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003005 rc = mwl8k_cmd_update_stadb(hw, vif,
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003006 MWL8K_STA_DB_MODIFY_ENTRY);
3007 if (rc)
3008 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003009
3010 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003011 rc = mwl8k_cmd_set_aid(hw, vif);
3012 if (rc)
3013 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003014
3015 /*
3016 * Finalize the join. Tell rx handler to process
3017 * next beacon from our BSSID.
3018 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003019 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003020 priv->capture_beacon = true;
3021 } else {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003022 rc = mwl8k_cmd_update_stadb(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003023 memset(&mwl8k_vif->bss_info, 0,
3024 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003025 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003026 }
3027
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003028out:
3029 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003030}
3031
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003032static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3033 int mc_count, struct dev_addr_list *mclist)
3034{
3035 struct mwl8k_cmd_pkt *cmd;
3036
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003037 /*
3038 * Synthesize and return a command packet that programs the
3039 * hardware multicast address filter. At this point we don't
3040 * know whether FIF_ALLMULTI is being requested, but if it is,
3041 * we'll end up throwing this packet away and creating a new
3042 * one in mwl8k_configure_filter().
3043 */
3044 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003045
3046 return (unsigned long)cmd;
3047}
3048
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003049static int
3050mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3051 unsigned int changed_flags,
3052 unsigned int *total_flags)
3053{
3054 struct mwl8k_priv *priv = hw->priv;
3055
3056 /*
3057 * Hardware sniffer mode is mutually exclusive with STA
3058 * operation, so refuse to enable sniffer mode if a STA
3059 * interface is active.
3060 */
3061 if (priv->vif != NULL) {
3062 if (net_ratelimit())
3063 printk(KERN_INFO "%s: not enabling sniffer "
3064 "mode because STA interface is active\n",
3065 wiphy_name(hw->wiphy));
3066 return 0;
3067 }
3068
3069 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003070 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003071 return 0;
3072 priv->sniffer_enabled = true;
3073 }
3074
3075 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3076 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3077 FIF_OTHER_BSS;
3078
3079 return 1;
3080}
3081
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003082static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3083 unsigned int changed_flags,
3084 unsigned int *total_flags,
3085 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003086{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003087 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003088 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3089
3090 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003091 * AP firmware doesn't allow fine-grained control over
3092 * the receive filter.
3093 */
3094 if (priv->ap_fw) {
3095 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3096 kfree(cmd);
3097 return;
3098 }
3099
3100 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003101 * Enable hardware sniffer mode if FIF_CONTROL or
3102 * FIF_OTHER_BSS is requested.
3103 */
3104 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3105 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3106 kfree(cmd);
3107 return;
3108 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003109
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003110 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003111 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003112
3113 if (mwl8k_fw_lock(hw))
3114 return;
3115
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003116 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003117 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003118 priv->sniffer_enabled = false;
3119 }
3120
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003121 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003122 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3123 /*
3124 * Disable the BSS filter.
3125 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003126 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003127 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003128 u8 *bssid;
3129
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003130 /*
3131 * Enable the BSS filter.
3132 *
3133 * If there is an active STA interface, use that
3134 * interface's BSSID, otherwise use a dummy one
3135 * (where the OUI part needs to be nonzero for
3136 * the BSSID to be accepted by POST_SCAN).
3137 */
3138 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003139 if (priv->vif != NULL)
3140 bssid = MWL8K_VIF(priv->vif)->bssid;
3141
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003142 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003143 }
3144 }
3145
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003146 /*
3147 * If FIF_ALLMULTI is being requested, throw away the command
3148 * packet that ->prepare_multicast() built and replace it with
3149 * a command packet that enables reception of all multicast
3150 * packets.
3151 */
3152 if (*total_flags & FIF_ALLMULTI) {
3153 kfree(cmd);
3154 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3155 }
3156
3157 if (cmd != NULL) {
3158 mwl8k_post_cmd(hw, cmd);
3159 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003160 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003161
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003162 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003163}
3164
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003165static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3166{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003167 return mwl8k_cmd_set_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003168}
3169
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003170static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3171 const struct ieee80211_tx_queue_params *params)
3172{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003173 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003174 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003175
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003176 rc = mwl8k_fw_lock(hw);
3177 if (!rc) {
3178 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003179 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003180
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003181 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003182 rc = mwl8k_cmd_set_edca_params(hw, queue,
3183 params->cw_min,
3184 params->cw_max,
3185 params->aifs,
3186 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003187
3188 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003189 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003190
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003191 return rc;
3192}
3193
3194static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3195 struct ieee80211_tx_queue_stats *stats)
3196{
3197 struct mwl8k_priv *priv = hw->priv;
3198 struct mwl8k_tx_queue *txq;
3199 int index;
3200
3201 spin_lock_bh(&priv->tx_lock);
3202 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3203 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003204 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003205 sizeof(struct ieee80211_tx_queue_stats));
3206 }
3207 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003208
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003209 return 0;
3210}
3211
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003212static int mwl8k_get_stats(struct ieee80211_hw *hw,
3213 struct ieee80211_low_level_stats *stats)
3214{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003215 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003216}
3217
3218static const struct ieee80211_ops mwl8k_ops = {
3219 .tx = mwl8k_tx,
3220 .start = mwl8k_start,
3221 .stop = mwl8k_stop,
3222 .add_interface = mwl8k_add_interface,
3223 .remove_interface = mwl8k_remove_interface,
3224 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003225 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003226 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003227 .configure_filter = mwl8k_configure_filter,
3228 .set_rts_threshold = mwl8k_set_rts_threshold,
3229 .conf_tx = mwl8k_conf_tx,
3230 .get_tx_stats = mwl8k_get_tx_stats,
3231 .get_stats = mwl8k_get_stats,
3232};
3233
3234static void mwl8k_tx_reclaim_handler(unsigned long data)
3235{
3236 int i;
3237 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3238 struct mwl8k_priv *priv = hw->priv;
3239
3240 spin_lock_bh(&priv->tx_lock);
3241 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3242 mwl8k_txq_reclaim(hw, i, 0);
3243
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003244 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003245 complete(priv->tx_wait);
3246 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003247 }
3248 spin_unlock_bh(&priv->tx_lock);
3249}
3250
3251static void mwl8k_finalize_join_worker(struct work_struct *work)
3252{
3253 struct mwl8k_priv *priv =
3254 container_of(work, struct mwl8k_priv, finalize_join_worker);
3255 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003256 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003257
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003258 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003259 dev_kfree_skb(skb);
3260
3261 priv->beacon_skb = NULL;
3262}
3263
John W. Linvillebcb628d2009-11-06 16:40:16 -05003264enum {
3265 MWL8687 = 0,
3266 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003267};
3268
John W. Linvillebcb628d2009-11-06 16:40:16 -05003269static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3270 {
3271 .part_name = "88w8687",
3272 .helper_image = "mwl8k/helper_8687.fw",
3273 .fw_image = "mwl8k/fmimage_8687.fw",
3274 .rxd_ops = &rxd_8687_ops,
3275 .modes = BIT(NL80211_IFTYPE_STATION),
3276 },
3277 {
3278 .part_name = "88w8366",
3279 .helper_image = "mwl8k/helper_8366.fw",
3280 .fw_image = "mwl8k/fmimage_8366.fw",
3281 .rxd_ops = &rxd_8366_ops,
3282 .modes = 0,
3283 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003284};
3285
3286static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003287 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3288 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3289 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3290 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003291};
3292MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3293
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003294static int __devinit mwl8k_probe(struct pci_dev *pdev,
3295 const struct pci_device_id *id)
3296{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003297 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003298 struct ieee80211_hw *hw;
3299 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003300 int rc;
3301 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003302
3303 if (!printed_version) {
3304 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3305 printed_version = 1;
3306 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003307
3308 rc = pci_enable_device(pdev);
3309 if (rc) {
3310 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3311 MWL8K_NAME);
3312 return rc;
3313 }
3314
3315 rc = pci_request_regions(pdev, MWL8K_NAME);
3316 if (rc) {
3317 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3318 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003319 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003320 }
3321
3322 pci_set_master(pdev);
3323
3324 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3325 if (hw == NULL) {
3326 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3327 rc = -ENOMEM;
3328 goto err_free_reg;
3329 }
3330
3331 priv = hw->priv;
3332 priv->hw = hw;
3333 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003334 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02003335 priv->rxd_ops = priv->device_info->rxd_ops;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003336 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02003337 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003338 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003339
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003340 SET_IEEE80211_DEV(hw, &pdev->dev);
3341 pci_set_drvdata(pdev, hw);
3342
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003343 priv->sram = pci_iomap(pdev, 0, 0x10000);
3344 if (priv->sram == NULL) {
3345 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003346 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003347 goto err_iounmap;
3348 }
3349
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003350 /*
3351 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3352 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3353 */
3354 priv->regs = pci_iomap(pdev, 1, 0x10000);
3355 if (priv->regs == NULL) {
3356 priv->regs = pci_iomap(pdev, 2, 0x10000);
3357 if (priv->regs == NULL) {
3358 printk(KERN_ERR "%s: Cannot map device registers\n",
3359 wiphy_name(hw->wiphy));
3360 goto err_iounmap;
3361 }
3362 }
3363
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003364 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3365 priv->band.band = IEEE80211_BAND_2GHZ;
3366 priv->band.channels = priv->channels;
3367 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3368 priv->band.bitrates = priv->rates;
3369 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3370 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3371
3372 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3373 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3374
3375 /*
3376 * Extra headroom is the size of the required DMA header
3377 * minus the size of the smallest 802.11 frame (CTS frame).
3378 */
3379 hw->extra_tx_headroom =
3380 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3381
3382 hw->channel_change_time = 10;
3383
3384 hw->queues = MWL8K_TX_QUEUES;
3385
Lennert Buytenhek547810e2009-10-22 20:21:02 +02003386 hw->wiphy->interface_modes = priv->device_info->modes;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003387
3388 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003389 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003390 hw->vif_data_size = sizeof(struct mwl8k_vif);
3391 priv->vif = NULL;
3392
3393 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003394 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003395 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003396
3397 /* Finalize join worker */
3398 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3399
3400 /* TX reclaim tasklet */
3401 tasklet_init(&priv->tx_reclaim_task,
3402 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3403 tasklet_disable(&priv->tx_reclaim_task);
3404
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003405 /* Power management cookie */
3406 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3407 if (priv->cookie == NULL)
3408 goto err_iounmap;
3409
3410 rc = mwl8k_rxq_init(hw, 0);
3411 if (rc)
3412 goto err_iounmap;
3413 rxq_refill(hw, 0, INT_MAX);
3414
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003415 mutex_init(&priv->fw_mutex);
3416 priv->fw_mutex_owner = NULL;
3417 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003418 priv->hostcmd_wait = NULL;
3419
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003420 spin_lock_init(&priv->tx_lock);
3421
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003422 priv->tx_wait = NULL;
3423
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003424 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3425 rc = mwl8k_txq_init(hw, i);
3426 if (rc)
3427 goto err_free_queues;
3428 }
3429
3430 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003431 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003432 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3433 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3434
Joe Perchesa0607fd2009-11-18 23:29:17 -08003435 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003436 IRQF_SHARED, MWL8K_NAME, hw);
3437 if (rc) {
3438 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003439 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003440 goto err_free_queues;
3441 }
3442
3443 /* Reset firmware and hardware */
3444 mwl8k_hw_reset(priv);
3445
3446 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003447 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003448 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003449 printk(KERN_ERR "%s: Firmware files not found\n",
3450 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003451 goto err_free_irq;
3452 }
3453
3454 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003455 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003456 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003457 printk(KERN_ERR "%s: Cannot start firmware\n",
3458 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003459 goto err_stop_firmware;
3460 }
3461
3462 /* Reclaim memory once firmware is successfully loaded */
3463 mwl8k_release_firmware(priv);
3464
3465 /*
3466 * Temporarily enable interrupts. Initial firmware host
3467 * commands use interrupts and avoids polling. Disable
3468 * interrupts when done.
3469 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003470 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003471
3472 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02003473 if (priv->ap_fw) {
3474 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3475 if (!rc)
3476 rc = mwl8k_cmd_set_hw_spec(hw);
3477 } else {
3478 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3479 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003480 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003481 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3482 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003483 goto err_stop_firmware;
3484 }
3485
3486 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003487 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003488 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003489 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003490 goto err_stop_firmware;
3491 }
3492
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003493 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003494 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003495 if (rc) {
3496 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3497 wiphy_name(hw->wiphy));
3498 goto err_stop_firmware;
3499 }
3500
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003501 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003502 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003503 free_irq(priv->pdev->irq, hw);
3504
3505 rc = ieee80211_register_hw(hw);
3506 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003507 printk(KERN_ERR "%s: Cannot register device\n",
3508 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003509 goto err_stop_firmware;
3510 }
3511
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003512 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003513 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003514 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003515 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003516 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3517 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003518
3519 return 0;
3520
3521err_stop_firmware:
3522 mwl8k_hw_reset(priv);
3523 mwl8k_release_firmware(priv);
3524
3525err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003526 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003527 free_irq(priv->pdev->irq, hw);
3528
3529err_free_queues:
3530 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3531 mwl8k_txq_deinit(hw, i);
3532 mwl8k_rxq_deinit(hw, 0);
3533
3534err_iounmap:
3535 if (priv->cookie != NULL)
3536 pci_free_consistent(priv->pdev, 4,
3537 priv->cookie, priv->cookie_dma);
3538
3539 if (priv->regs != NULL)
3540 pci_iounmap(pdev, priv->regs);
3541
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003542 if (priv->sram != NULL)
3543 pci_iounmap(pdev, priv->sram);
3544
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003545 pci_set_drvdata(pdev, NULL);
3546 ieee80211_free_hw(hw);
3547
3548err_free_reg:
3549 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003550
3551err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003552 pci_disable_device(pdev);
3553
3554 return rc;
3555}
3556
Joerg Albert230f7af2009-04-18 02:10:45 +02003557static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003558{
3559 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3560}
3561
Joerg Albert230f7af2009-04-18 02:10:45 +02003562static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003563{
3564 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3565 struct mwl8k_priv *priv;
3566 int i;
3567
3568 if (hw == NULL)
3569 return;
3570 priv = hw->priv;
3571
3572 ieee80211_stop_queues(hw);
3573
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003574 ieee80211_unregister_hw(hw);
3575
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003576 /* Remove tx reclaim tasklet */
3577 tasklet_kill(&priv->tx_reclaim_task);
3578
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003579 /* Stop hardware */
3580 mwl8k_hw_reset(priv);
3581
3582 /* Return all skbs to mac80211 */
3583 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3584 mwl8k_txq_reclaim(hw, i, 1);
3585
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003586 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3587 mwl8k_txq_deinit(hw, i);
3588
3589 mwl8k_rxq_deinit(hw, 0);
3590
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003591 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003592
3593 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003594 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003595 pci_set_drvdata(pdev, NULL);
3596 ieee80211_free_hw(hw);
3597 pci_release_regions(pdev);
3598 pci_disable_device(pdev);
3599}
3600
3601static struct pci_driver mwl8k_driver = {
3602 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003603 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003604 .probe = mwl8k_probe,
3605 .remove = __devexit_p(mwl8k_remove),
3606 .shutdown = __devexit_p(mwl8k_shutdown),
3607};
3608
3609static int __init mwl8k_init(void)
3610{
3611 return pci_register_driver(&mwl8k_driver);
3612}
3613
3614static void __exit mwl8k_exit(void)
3615{
3616 pci_unregister_driver(&mwl8k_driver);
3617}
3618
3619module_init(mwl8k_init);
3620module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003621
3622MODULE_DESCRIPTION(MWL8K_DESC);
3623MODULE_VERSION(MWL8K_VERSION);
3624MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3625MODULE_LICENSE("GPL");