blob: b543defdde8a49abe9b2fe102d4643ce28b4f09a [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 Buytenhek42fba212009-10-22 20:21:30 +0200275#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100276#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
277#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200278#define MWL8K_CMD_RADIO_CONTROL 0x001c
279#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200280#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100281#define MWL8K_CMD_SET_PRE_SCAN 0x0107
282#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200283#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100284#define MWL8K_CMD_SET_AID 0x010d
285#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200286#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100287#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200288#define MWL8K_CMD_SET_SLOT 0x0114
289#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
290#define MWL8K_CMD_SET_WMM_MODE 0x0123
291#define MWL8K_CMD_MIMO_CONFIG 0x0125
292#define MWL8K_CMD_USE_FIXED_RATE 0x0126
293#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200294#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200295#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
296#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100297
298static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
299{
300#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
301 snprintf(buf, bufsize, "%s", #x);\
302 return buf;\
303 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200304 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100305 MWL8K_CMDNAME(CODE_DNLD);
306 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200307 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100308 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
309 MWL8K_CMDNAME(GET_STAT);
310 MWL8K_CMDNAME(RADIO_CONTROL);
311 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200312 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100313 MWL8K_CMDNAME(SET_PRE_SCAN);
314 MWL8K_CMDNAME(SET_POST_SCAN);
315 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100316 MWL8K_CMDNAME(SET_AID);
317 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200318 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100319 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200320 MWL8K_CMDNAME(SET_SLOT);
321 MWL8K_CMDNAME(SET_EDCA_PARAMS);
322 MWL8K_CMDNAME(SET_WMM_MODE);
323 MWL8K_CMDNAME(MIMO_CONFIG);
324 MWL8K_CMDNAME(USE_FIXED_RATE);
325 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200326 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200327 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
328 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100329 default:
330 snprintf(buf, bufsize, "0x%x", cmd);
331 }
332#undef MWL8K_CMDNAME
333
334 return buf;
335}
336
337/* Hardware and firmware reset */
338static void mwl8k_hw_reset(struct mwl8k_priv *priv)
339{
340 iowrite32(MWL8K_H2A_INT_RESET,
341 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
342 iowrite32(MWL8K_H2A_INT_RESET,
343 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
344 msleep(20);
345}
346
347/* Release fw image */
348static void mwl8k_release_fw(struct firmware **fw)
349{
350 if (*fw == NULL)
351 return;
352 release_firmware(*fw);
353 *fw = NULL;
354}
355
356static void mwl8k_release_firmware(struct mwl8k_priv *priv)
357{
358 mwl8k_release_fw(&priv->fw.ucode);
359 mwl8k_release_fw(&priv->fw.helper);
360}
361
362/* Request fw image */
363static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200364 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100365{
366 /* release current image */
367 if (*fw != NULL)
368 mwl8k_release_fw(fw);
369
370 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200371 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100372}
373
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200374static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100375{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200376 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100377 int rc;
378
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200379 if (di->helper_image != NULL) {
380 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
381 if (rc) {
382 printk(KERN_ERR "%s: Error requesting helper "
383 "firmware file %s\n", pci_name(priv->pdev),
384 di->helper_image);
385 return rc;
386 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100387 }
388
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200389 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100390 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200391 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200392 pci_name(priv->pdev), di->fw_image);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100393 mwl8k_release_fw(&priv->fw.helper);
394 return rc;
395 }
396
397 return 0;
398}
399
Ben Hutchings7e75b942009-11-07 22:00:57 +0000400MODULE_FIRMWARE("mwl8k/helper_8687.fw");
401MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
402
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100403struct mwl8k_cmd_pkt {
404 __le16 code;
405 __le16 length;
406 __le16 seq_num;
407 __le16 result;
408 char payload[0];
409} __attribute__((packed));
410
411/*
412 * Firmware loading.
413 */
414static int
415mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
416{
417 void __iomem *regs = priv->regs;
418 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100419 int loops;
420
421 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
422 if (pci_dma_mapping_error(priv->pdev, dma_addr))
423 return -ENOMEM;
424
425 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
426 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
427 iowrite32(MWL8K_H2A_INT_DOORBELL,
428 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
429 iowrite32(MWL8K_H2A_INT_DUMMY,
430 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
431
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100432 loops = 1000;
433 do {
434 u32 int_code;
435
436 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
437 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
438 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100439 break;
440 }
441
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200442 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100443 udelay(1);
444 } while (--loops);
445
446 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
447
Lennert Buytenhekd4b705702009-07-16 12:44:45 +0200448 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100449}
450
451static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
452 const u8 *data, size_t length)
453{
454 struct mwl8k_cmd_pkt *cmd;
455 int done;
456 int rc = 0;
457
458 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
459 if (cmd == NULL)
460 return -ENOMEM;
461
462 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
463 cmd->seq_num = 0;
464 cmd->result = 0;
465
466 done = 0;
467 while (length) {
468 int block_size = length > 256 ? 256 : length;
469
470 memcpy(cmd->payload, data + done, block_size);
471 cmd->length = cpu_to_le16(block_size);
472
473 rc = mwl8k_send_fw_load_cmd(priv, cmd,
474 sizeof(*cmd) + block_size);
475 if (rc)
476 break;
477
478 done += block_size;
479 length -= block_size;
480 }
481
482 if (!rc) {
483 cmd->length = 0;
484 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
485 }
486
487 kfree(cmd);
488
489 return rc;
490}
491
492static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
493 const u8 *data, size_t length)
494{
495 unsigned char *buffer;
496 int may_continue, rc = 0;
497 u32 done, prev_block_size;
498
499 buffer = kmalloc(1024, GFP_KERNEL);
500 if (buffer == NULL)
501 return -ENOMEM;
502
503 done = 0;
504 prev_block_size = 0;
505 may_continue = 1000;
506 while (may_continue > 0) {
507 u32 block_size;
508
509 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
510 if (block_size & 1) {
511 block_size &= ~1;
512 may_continue--;
513 } else {
514 done += prev_block_size;
515 length -= prev_block_size;
516 }
517
518 if (block_size > 1024 || block_size > length) {
519 rc = -EOVERFLOW;
520 break;
521 }
522
523 if (length == 0) {
524 rc = 0;
525 break;
526 }
527
528 if (block_size == 0) {
529 rc = -EPROTO;
530 may_continue--;
531 udelay(1);
532 continue;
533 }
534
535 prev_block_size = block_size;
536 memcpy(buffer, data + done, block_size);
537
538 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
539 if (rc)
540 break;
541 }
542
543 if (!rc && length != 0)
544 rc = -EREMOTEIO;
545
546 kfree(buffer);
547
548 return rc;
549}
550
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200551static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100552{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200553 struct mwl8k_priv *priv = hw->priv;
554 struct firmware *fw = priv->fw.ucode;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200555 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200556 int rc;
557 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100558
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200559 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
560 struct firmware *helper = priv->fw.helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100561
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200562 if (helper == NULL) {
563 printk(KERN_ERR "%s: helper image needed but none "
564 "given\n", pci_name(priv->pdev));
565 return -EINVAL;
566 }
567
568 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100569 if (rc) {
570 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200571 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100572 return rc;
573 }
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
661/* Inline functions to manipulate QoS field in data descriptor. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100662static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
663{
664 u16 val_mask = 1 << 4;
665
666 /* End of Service Period Bit 4 */
667 return qos | val_mask;
668}
669
670static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
671{
672 u16 val_mask = 0x3;
673 u8 shift = 5;
674 u16 qos_mask = ~(val_mask << shift);
675
676 /* Ack Policy Bit 5-6 */
677 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
678}
679
680static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
681{
682 u16 val_mask = 1 << 7;
683
684 /* AMSDU present Bit 7 */
685 return qos | val_mask;
686}
687
688static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
689{
690 u16 val_mask = 0xff;
691 u8 shift = 8;
692 u16 qos_mask = ~(val_mask << shift);
693
694 /* Queue Length Bits 8-15 */
695 return (qos & qos_mask) | ((len & val_mask) << shift);
696}
697
698/* DMA header used by firmware and hardware. */
699struct mwl8k_dma_data {
700 __le16 fwlen;
701 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100702 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100703} __attribute__((packed));
704
705/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100706static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100707{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100708 struct mwl8k_dma_data *tr;
709 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100710
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100711 tr = (struct mwl8k_dma_data *)skb->data;
712 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
713
714 if (hdrlen != sizeof(tr->wh)) {
715 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
716 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
717 *((__le16 *)(tr->data - 2)) = qos;
718 } else {
719 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
720 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100721 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100722
723 if (hdrlen != sizeof(*tr))
724 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100725}
726
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200727static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100728{
729 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100730 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100731 struct mwl8k_dma_data *tr;
732
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100733 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100734 * Add a firmware DMA header; the firmware requires that we
735 * present a 2-byte payload length followed by a 4-address
736 * header (without QoS field), followed (optionally) by any
737 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100738 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100739 wh = (struct ieee80211_hdr *)skb->data;
740
741 hdrlen = ieee80211_hdrlen(wh->frame_control);
742 if (hdrlen != sizeof(*tr))
743 skb_push(skb, sizeof(*tr) - hdrlen);
744
745 if (ieee80211_is_data_qos(wh->frame_control))
746 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100747
748 tr = (struct mwl8k_dma_data *)skb->data;
749 if (wh != &tr->wh)
750 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100751 if (hdrlen != sizeof(tr->wh))
752 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100753
754 /*
755 * Firmware length is the length of the fully formed "802.11
756 * payload". That is, everything except for the 802.11 header.
757 * This includes all crypto material including the MIC.
758 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100759 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100760}
761
762
763/*
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200764 * Packet reception for 88w8366.
765 */
766struct mwl8k_rxd_8366 {
767 __le16 pkt_len;
768 __u8 sq2;
769 __u8 rate;
770 __le32 pkt_phys_addr;
771 __le32 next_rxd_phys_addr;
772 __le16 qos_control;
773 __le16 htsig2;
774 __le32 hw_rssi_info;
775 __le32 hw_noise_floor_info;
776 __u8 noise_floor;
777 __u8 pad0[3];
778 __u8 rssi;
779 __u8 rx_status;
780 __u8 channel;
781 __u8 rx_ctrl;
782} __attribute__((packed));
783
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100784#define MWL8K_8366_RATE_INFO_MCS_FORMAT 0x80
785#define MWL8K_8366_RATE_INFO_40MHZ 0x40
786#define MWL8K_8366_RATE_INFO_RATEID(x) ((x) & 0x3f)
787
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200788#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
789
790static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
791{
792 struct mwl8k_rxd_8366 *rxd = _rxd;
793
794 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
795 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
796}
797
798static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
799{
800 struct mwl8k_rxd_8366 *rxd = _rxd;
801
802 rxd->pkt_len = cpu_to_le16(len);
803 rxd->pkt_phys_addr = cpu_to_le32(addr);
804 wmb();
805 rxd->rx_ctrl = 0;
806}
807
808static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100809mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status,
810 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200811{
812 struct mwl8k_rxd_8366 *rxd = _rxd;
813
814 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
815 return -1;
816 rmb();
817
818 memset(status, 0, sizeof(*status));
819
820 status->signal = -rxd->rssi;
821 status->noise = -rxd->noise_floor;
822
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100823 if (rxd->rate & MWL8K_8366_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200824 status->flag |= RX_FLAG_HT;
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100825 if (rxd->rate & MWL8K_8366_RATE_INFO_40MHZ)
826 status->flag |= RX_FLAG_40MHZ;
827 status->rate_idx = MWL8K_8366_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200828 } else {
829 int i;
830
831 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
832 if (mwl8k_rates[i].hw_value == rxd->rate) {
833 status->rate_idx = i;
834 break;
835 }
836 }
837 }
838
839 status->band = IEEE80211_BAND_2GHZ;
840 status->freq = ieee80211_channel_to_frequency(rxd->channel);
841
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100842 *qos = rxd->qos_control;
843
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200844 return le16_to_cpu(rxd->pkt_len);
845}
846
847static struct rxd_ops rxd_8366_ops = {
848 .rxd_size = sizeof(struct mwl8k_rxd_8366),
849 .rxd_init = mwl8k_rxd_8366_init,
850 .rxd_refill = mwl8k_rxd_8366_refill,
851 .rxd_process = mwl8k_rxd_8366_process,
852};
853
854/*
855 * Packet reception for 88w8687.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100856 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200857struct mwl8k_rxd_8687 {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100858 __le16 pkt_len;
859 __u8 link_quality;
860 __u8 noise_level;
861 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200862 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100863 __le16 qos_control;
864 __le16 rate_info;
865 __le32 pad0[4];
866 __u8 rssi;
867 __u8 channel;
868 __le16 pad1;
869 __u8 rx_ctrl;
870 __u8 rx_status;
871 __u8 pad2[2];
872} __attribute__((packed));
873
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200874#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
875#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
876#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
877#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
878#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
879#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
880
881#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
882
883static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
884{
885 struct mwl8k_rxd_8687 *rxd = _rxd;
886
887 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
888 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
889}
890
891static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
892{
893 struct mwl8k_rxd_8687 *rxd = _rxd;
894
895 rxd->pkt_len = cpu_to_le16(len);
896 rxd->pkt_phys_addr = cpu_to_le32(addr);
897 wmb();
898 rxd->rx_ctrl = 0;
899}
900
901static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100902mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status,
903 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200904{
905 struct mwl8k_rxd_8687 *rxd = _rxd;
906 u16 rate_info;
907
908 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
909 return -1;
910 rmb();
911
912 rate_info = le16_to_cpu(rxd->rate_info);
913
914 memset(status, 0, sizeof(*status));
915
916 status->signal = -rxd->rssi;
917 status->noise = -rxd->noise_level;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200918 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
919 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
920
921 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
922 status->flag |= RX_FLAG_SHORTPRE;
923 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
924 status->flag |= RX_FLAG_40MHZ;
925 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
926 status->flag |= RX_FLAG_SHORT_GI;
927 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
928 status->flag |= RX_FLAG_HT;
929
930 status->band = IEEE80211_BAND_2GHZ;
931 status->freq = ieee80211_channel_to_frequency(rxd->channel);
932
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100933 *qos = rxd->qos_control;
934
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200935 return le16_to_cpu(rxd->pkt_len);
936}
937
938static struct rxd_ops rxd_8687_ops = {
939 .rxd_size = sizeof(struct mwl8k_rxd_8687),
940 .rxd_init = mwl8k_rxd_8687_init,
941 .rxd_refill = mwl8k_rxd_8687_refill,
942 .rxd_process = mwl8k_rxd_8687_process,
943};
944
945
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100946#define MWL8K_RX_DESCS 256
947#define MWL8K_RX_MAXSZ 3800
948
949static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
950{
951 struct mwl8k_priv *priv = hw->priv;
952 struct mwl8k_rx_queue *rxq = priv->rxq + index;
953 int size;
954 int i;
955
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200956 rxq->rxd_count = 0;
957 rxq->head = 0;
958 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100959
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200960 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100961
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200962 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
963 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100964 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200965 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100966 return -ENOMEM;
967 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200968 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100969
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200970 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
971 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100972 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200973 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200974 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100975 return -ENOMEM;
976 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200977 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100978
979 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200980 int desc_size;
981 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100982 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200983 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100984
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200985 desc_size = priv->rxd_ops->rxd_size;
986 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100987
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200988 nexti = i + 1;
989 if (nexti == MWL8K_RX_DESCS)
990 nexti = 0;
991 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
992
993 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100994 }
995
996 return 0;
997}
998
999static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
1000{
1001 struct mwl8k_priv *priv = hw->priv;
1002 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1003 int refilled;
1004
1005 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001006 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001007 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001008 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001009 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001010 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001011
1012 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
1013 if (skb == NULL)
1014 break;
1015
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001016 addr = pci_map_single(priv->pdev, skb->data,
1017 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001018
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001019 rxq->rxd_count++;
1020 rx = rxq->tail++;
1021 if (rxq->tail == MWL8K_RX_DESCS)
1022 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001023 rxq->buf[rx].skb = skb;
1024 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001025
1026 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
1027 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001028
1029 refilled++;
1030 }
1031
1032 return refilled;
1033}
1034
1035/* Must be called only when the card's reception is completely halted */
1036static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
1037{
1038 struct mwl8k_priv *priv = hw->priv;
1039 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1040 int i;
1041
1042 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001043 if (rxq->buf[i].skb != NULL) {
1044 pci_unmap_single(priv->pdev,
1045 pci_unmap_addr(&rxq->buf[i], dma),
1046 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1047 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001048
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001049 kfree_skb(rxq->buf[i].skb);
1050 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001051 }
1052 }
1053
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001054 kfree(rxq->buf);
1055 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001056
1057 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001058 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001059 rxq->rxd, rxq->rxd_dma);
1060 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001061}
1062
1063
1064/*
1065 * Scan a list of BSSIDs to process for finalize join.
1066 * Allows for extension to process multiple BSSIDs.
1067 */
1068static inline int
1069mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1070{
1071 return priv->capture_beacon &&
1072 ieee80211_is_beacon(wh->frame_control) &&
1073 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1074}
1075
Lennert Buytenhek37797522009-10-22 20:19:45 +02001076static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1077 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001078{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001079 struct mwl8k_priv *priv = hw->priv;
1080
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001081 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001082 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001083
1084 /*
1085 * Use GFP_ATOMIC as rxq_process is called from
1086 * the primary interrupt handler, memory allocation call
1087 * must not sleep.
1088 */
1089 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1090 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001091 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001092}
1093
1094static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1095{
1096 struct mwl8k_priv *priv = hw->priv;
1097 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1098 int processed;
1099
1100 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001101 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001102 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001103 void *rxd;
1104 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001105 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001106 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001107
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001108 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001109 if (skb == NULL)
1110 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001111
1112 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1113
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001114 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001115 if (pkt_len < 0)
1116 break;
1117
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001118 rxq->buf[rxq->head].skb = NULL;
1119
1120 pci_unmap_single(priv->pdev,
1121 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1122 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1123 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001124
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001125 rxq->head++;
1126 if (rxq->head == MWL8K_RX_DESCS)
1127 rxq->head = 0;
1128
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001129 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001130
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001131 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001132 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001133
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001134 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001135 * Check for a pending join operation. Save a
1136 * copy of the beacon and schedule a tasklet to
1137 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001138 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001139 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001140 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001141
Johannes Bergf1d58c22009-06-17 13:13:00 +02001142 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1143 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001144
1145 processed++;
1146 }
1147
1148 return processed;
1149}
1150
1151
1152/*
1153 * Packet transmission.
1154 */
1155
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001156/* Transmit packet ACK policy */
1157#define MWL8K_TXD_ACK_POLICY_NORMAL 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001158#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1159
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001160#define MWL8K_TXD_STATUS_OK 0x00000001
1161#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1162#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1163#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001164#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001165
1166struct mwl8k_tx_desc {
1167 __le32 status;
1168 __u8 data_rate;
1169 __u8 tx_priority;
1170 __le16 qos_control;
1171 __le32 pkt_phys_addr;
1172 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001173 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001174 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001175 __le32 reserved;
1176 __le16 rate_info;
1177 __u8 peer_id;
1178 __u8 tx_frag_cnt;
1179} __attribute__((packed));
1180
1181#define MWL8K_TX_DESCS 128
1182
1183static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1184{
1185 struct mwl8k_priv *priv = hw->priv;
1186 struct mwl8k_tx_queue *txq = priv->txq + index;
1187 int size;
1188 int i;
1189
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001190 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1191 txq->stats.limit = MWL8K_TX_DESCS;
1192 txq->head = 0;
1193 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001194
1195 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1196
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001197 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1198 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001199 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001200 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001201 return -ENOMEM;
1202 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001203 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001204
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001205 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1206 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001207 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001208 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001209 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001210 return -ENOMEM;
1211 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001212 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001213
1214 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1215 struct mwl8k_tx_desc *tx_desc;
1216 int nexti;
1217
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001218 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001219 nexti = (i + 1) % MWL8K_TX_DESCS;
1220
1221 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001222 tx_desc->next_txd_phys_addr =
1223 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001224 }
1225
1226 return 0;
1227}
1228
1229static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1230{
1231 iowrite32(MWL8K_H2A_INT_PPA_READY,
1232 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1233 iowrite32(MWL8K_H2A_INT_DUMMY,
1234 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1235 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1236}
1237
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001238static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001239{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001240 struct mwl8k_priv *priv = hw->priv;
1241 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001242
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001243 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1244 struct mwl8k_tx_queue *txq = priv->txq + i;
1245 int fw_owned = 0;
1246 int drv_owned = 0;
1247 int unused = 0;
1248 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001249
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001250 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001251 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1252 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001253
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001254 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001255 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001256 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001257 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001258 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001259
1260 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001261 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001262 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001263
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001264 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1265 "fw_owned=%d drv_owned=%d unused=%d\n",
1266 wiphy_name(hw->wiphy), i,
1267 txq->stats.len, txq->head, txq->tail,
1268 fw_owned, drv_owned, unused);
1269 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001270}
1271
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001272/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001273 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001274 */
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001275#define MWL8K_TX_WAIT_TIMEOUT_MS 1000
1276
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001277static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001278{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001279 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001280 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001281 int retry;
1282 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001283
1284 might_sleep();
1285
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001286 /*
1287 * The TX queues are stopped at this point, so this test
1288 * doesn't need to take ->tx_lock.
1289 */
1290 if (!priv->pending_tx_pkts)
1291 return 0;
1292
1293 retry = 0;
1294 rc = 0;
1295
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001296 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001297 priv->tx_wait = &tx_wait;
1298 while (!rc) {
1299 int oldcount;
1300 unsigned long timeout;
1301
1302 oldcount = priv->pending_tx_pkts;
1303
1304 spin_unlock_bh(&priv->tx_lock);
1305 timeout = wait_for_completion_timeout(&tx_wait,
1306 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1307 spin_lock_bh(&priv->tx_lock);
1308
1309 if (timeout) {
1310 WARN_ON(priv->pending_tx_pkts);
1311 if (retry) {
1312 printk(KERN_NOTICE "%s: tx rings drained\n",
1313 wiphy_name(hw->wiphy));
1314 }
1315 break;
1316 }
1317
1318 if (priv->pending_tx_pkts < oldcount) {
1319 printk(KERN_NOTICE "%s: timeout waiting for tx "
1320 "rings to drain (%d -> %d pkts), retrying\n",
1321 wiphy_name(hw->wiphy), oldcount,
1322 priv->pending_tx_pkts);
1323 retry = 1;
1324 continue;
1325 }
1326
1327 priv->tx_wait = NULL;
1328
1329 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1330 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1331 mwl8k_dump_tx_rings(hw);
1332
1333 rc = -ETIMEDOUT;
1334 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001335 spin_unlock_bh(&priv->tx_lock);
1336
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001337 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001338}
1339
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001340#define MWL8K_TXD_SUCCESS(status) \
1341 ((status) & (MWL8K_TXD_STATUS_OK | \
1342 MWL8K_TXD_STATUS_OK_RETRY | \
1343 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001344
1345static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1346{
1347 struct mwl8k_priv *priv = hw->priv;
1348 struct mwl8k_tx_queue *txq = priv->txq + index;
1349 int wake = 0;
1350
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001351 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001352 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001353 struct mwl8k_tx_desc *tx_desc;
1354 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001355 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001356 struct sk_buff *skb;
1357 struct ieee80211_tx_info *info;
1358 u32 status;
1359
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001360 tx = txq->head;
1361 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001362
1363 status = le32_to_cpu(tx_desc->status);
1364
1365 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1366 if (!force)
1367 break;
1368 tx_desc->status &=
1369 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1370 }
1371
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001372 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1373 BUG_ON(txq->stats.len == 0);
1374 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001375 priv->pending_tx_pkts--;
1376
1377 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001378 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001379 skb = txq->skb[tx];
1380 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001381
1382 BUG_ON(skb == NULL);
1383 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1384
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001385 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001386
1387 /* Mark descriptor as unused */
1388 tx_desc->pkt_phys_addr = 0;
1389 tx_desc->pkt_len = 0;
1390
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001391 info = IEEE80211_SKB_CB(skb);
1392 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001393 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001394 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001395
1396 ieee80211_tx_status_irqsafe(hw, skb);
1397
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001398 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001399 }
1400
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001401 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001402 ieee80211_wake_queue(hw, index);
1403}
1404
1405/* must be called only when the card's transmit is completely halted */
1406static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1407{
1408 struct mwl8k_priv *priv = hw->priv;
1409 struct mwl8k_tx_queue *txq = priv->txq + index;
1410
1411 mwl8k_txq_reclaim(hw, index, 1);
1412
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001413 kfree(txq->skb);
1414 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001415
1416 pci_free_consistent(priv->pdev,
1417 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001418 txq->txd, txq->txd_dma);
1419 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001420}
1421
1422static int
1423mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1424{
1425 struct mwl8k_priv *priv = hw->priv;
1426 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001427 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001428 struct ieee80211_hdr *wh;
1429 struct mwl8k_tx_queue *txq;
1430 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001431 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001432 u32 txstatus;
1433 u8 txdatarate;
1434 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001435
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001436 wh = (struct ieee80211_hdr *)skb->data;
1437 if (ieee80211_is_data_qos(wh->frame_control))
1438 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1439 else
1440 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001441
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001442 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001443 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001444
1445 tx_info = IEEE80211_SKB_CB(skb);
1446 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001447
1448 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1449 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001450
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001451 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1452 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1453 mwl8k_vif->seqno = seqno++ % 4096;
1454 }
1455
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001456 /* Setup firmware control bit fields for each frame type. */
1457 txstatus = 0;
1458 txdatarate = 0;
1459 if (ieee80211_is_mgmt(wh->frame_control) ||
1460 ieee80211_is_ctl(wh->frame_control)) {
1461 txdatarate = 0;
1462 qos = mwl8k_qos_setbit_eosp(qos);
1463 /* Set Queue size to unspecified */
1464 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1465 } else if (ieee80211_is_data(wh->frame_control)) {
1466 txdatarate = 1;
1467 if (is_multicast_ether_addr(wh->addr1))
1468 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1469
1470 /* Send pkt in an aggregate if AMPDU frame. */
1471 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1472 qos = mwl8k_qos_setbit_ack(qos,
1473 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1474 else
1475 qos = mwl8k_qos_setbit_ack(qos,
1476 MWL8K_TXD_ACK_POLICY_NORMAL);
1477
1478 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1479 qos = mwl8k_qos_setbit_amsdu(qos);
1480 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001481
1482 dma = pci_map_single(priv->pdev, skb->data,
1483 skb->len, PCI_DMA_TODEVICE);
1484
1485 if (pci_dma_mapping_error(priv->pdev, dma)) {
1486 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001487 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001488 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001489 return NETDEV_TX_OK;
1490 }
1491
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001492 spin_lock_bh(&priv->tx_lock);
1493
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001494 txq = priv->txq + index;
1495
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001496 BUG_ON(txq->skb[txq->tail] != NULL);
1497 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001498
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001499 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001500 tx->data_rate = txdatarate;
1501 tx->tx_priority = index;
1502 tx->qos_control = cpu_to_le16(qos);
1503 tx->pkt_phys_addr = cpu_to_le32(dma);
1504 tx->pkt_len = cpu_to_le16(skb->len);
1505 tx->rate_info = 0;
1506 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001507 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001508 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1509
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001510 txq->stats.count++;
1511 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001512 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001513
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001514 txq->tail++;
1515 if (txq->tail == MWL8K_TX_DESCS)
1516 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001517
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001518 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001519 ieee80211_stop_queue(hw, index);
1520
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001521 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001522
1523 spin_unlock_bh(&priv->tx_lock);
1524
1525 return NETDEV_TX_OK;
1526}
1527
1528
1529/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001530 * Firmware access.
1531 *
1532 * We have the following requirements for issuing firmware commands:
1533 * - Some commands require that the packet transmit path is idle when
1534 * the command is issued. (For simplicity, we'll just quiesce the
1535 * transmit path for every command.)
1536 * - There are certain sequences of commands that need to be issued to
1537 * the hardware sequentially, with no other intervening commands.
1538 *
1539 * This leads to an implementation of a "firmware lock" as a mutex that
1540 * can be taken recursively, and which is taken by both the low-level
1541 * command submission function (mwl8k_post_cmd) as well as any users of
1542 * that function that require issuing of an atomic sequence of commands,
1543 * and quiesces the transmit path whenever it's taken.
1544 */
1545static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1546{
1547 struct mwl8k_priv *priv = hw->priv;
1548
1549 if (priv->fw_mutex_owner != current) {
1550 int rc;
1551
1552 mutex_lock(&priv->fw_mutex);
1553 ieee80211_stop_queues(hw);
1554
1555 rc = mwl8k_tx_wait_empty(hw);
1556 if (rc) {
1557 ieee80211_wake_queues(hw);
1558 mutex_unlock(&priv->fw_mutex);
1559
1560 return rc;
1561 }
1562
1563 priv->fw_mutex_owner = current;
1564 }
1565
1566 priv->fw_mutex_depth++;
1567
1568 return 0;
1569}
1570
1571static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1572{
1573 struct mwl8k_priv *priv = hw->priv;
1574
1575 if (!--priv->fw_mutex_depth) {
1576 ieee80211_wake_queues(hw);
1577 priv->fw_mutex_owner = NULL;
1578 mutex_unlock(&priv->fw_mutex);
1579 }
1580}
1581
1582
1583/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001584 * Command processing.
1585 */
1586
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001587/* Timeout firmware commands after 10s */
1588#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001589
1590static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1591{
1592 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1593 struct mwl8k_priv *priv = hw->priv;
1594 void __iomem *regs = priv->regs;
1595 dma_addr_t dma_addr;
1596 unsigned int dma_size;
1597 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001598 unsigned long timeout = 0;
1599 u8 buf[32];
1600
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001601 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001602 dma_size = le16_to_cpu(cmd->length);
1603 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1604 PCI_DMA_BIDIRECTIONAL);
1605 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1606 return -ENOMEM;
1607
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001608 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001609 if (rc) {
1610 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1611 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001612 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001613 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001614
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001615 priv->hostcmd_wait = &cmd_wait;
1616 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1617 iowrite32(MWL8K_H2A_INT_DOORBELL,
1618 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1619 iowrite32(MWL8K_H2A_INT_DUMMY,
1620 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001621
1622 timeout = wait_for_completion_timeout(&cmd_wait,
1623 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1624
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001625 priv->hostcmd_wait = NULL;
1626
1627 mwl8k_fw_unlock(hw);
1628
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001629 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1630 PCI_DMA_BIDIRECTIONAL);
1631
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001632 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001633 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001634 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001635 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1636 MWL8K_CMD_TIMEOUT_MS);
1637 rc = -ETIMEDOUT;
1638 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001639 int ms;
1640
1641 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1642
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001643 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001644 if (rc)
1645 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001646 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001647 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001648 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001649 else if (ms > 2000)
1650 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1651 wiphy_name(hw->wiphy),
1652 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1653 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001654 }
1655
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001656 return rc;
1657}
1658
1659/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001660 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001661 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001662struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001663 struct mwl8k_cmd_pkt header;
1664 __u8 hw_rev;
1665 __u8 host_interface;
1666 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001667 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001668 __le16 region_code;
1669 __le32 fw_rev;
1670 __le32 ps_cookie;
1671 __le32 caps;
1672 __u8 mcs_bitmap[16];
1673 __le32 rx_queue_ptr;
1674 __le32 num_tx_queues;
1675 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1676 __le32 caps2;
1677 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001678 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001679} __attribute__((packed));
1680
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001681static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001682{
1683 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001684 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001685 int rc;
1686 int i;
1687
1688 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1689 if (cmd == NULL)
1690 return -ENOMEM;
1691
1692 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1693 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1694
1695 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1696 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001697 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001698 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001699 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001700 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001701 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001702 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001703
1704 rc = mwl8k_post_cmd(hw, &cmd->header);
1705
1706 if (!rc) {
1707 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1708 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001709 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001710 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001711 }
1712
1713 kfree(cmd);
1714 return rc;
1715}
1716
1717/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001718 * CMD_GET_HW_SPEC (AP version).
1719 */
1720struct mwl8k_cmd_get_hw_spec_ap {
1721 struct mwl8k_cmd_pkt header;
1722 __u8 hw_rev;
1723 __u8 host_interface;
1724 __le16 num_wcb;
1725 __le16 num_mcaddrs;
1726 __u8 perm_addr[ETH_ALEN];
1727 __le16 region_code;
1728 __le16 num_antenna;
1729 __le32 fw_rev;
1730 __le32 wcbbase0;
1731 __le32 rxwrptr;
1732 __le32 rxrdptr;
1733 __le32 ps_cookie;
1734 __le32 wcbbase1;
1735 __le32 wcbbase2;
1736 __le32 wcbbase3;
1737} __attribute__((packed));
1738
1739static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1740{
1741 struct mwl8k_priv *priv = hw->priv;
1742 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1743 int rc;
1744
1745 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1746 if (cmd == NULL)
1747 return -ENOMEM;
1748
1749 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1750 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1751
1752 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1753 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1754
1755 rc = mwl8k_post_cmd(hw, &cmd->header);
1756
1757 if (!rc) {
1758 int off;
1759
1760 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1761 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1762 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1763 priv->hw_rev = cmd->hw_rev;
1764
1765 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1766 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1767
1768 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1769 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1770
1771 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1772 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1773
1774 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1775 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1776
1777 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1778 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1779
1780 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1781 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1782 }
1783
1784 kfree(cmd);
1785 return rc;
1786}
1787
1788/*
1789 * CMD_SET_HW_SPEC.
1790 */
1791struct mwl8k_cmd_set_hw_spec {
1792 struct mwl8k_cmd_pkt header;
1793 __u8 hw_rev;
1794 __u8 host_interface;
1795 __le16 num_mcaddrs;
1796 __u8 perm_addr[ETH_ALEN];
1797 __le16 region_code;
1798 __le32 fw_rev;
1799 __le32 ps_cookie;
1800 __le32 caps;
1801 __le32 rx_queue_ptr;
1802 __le32 num_tx_queues;
1803 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1804 __le32 flags;
1805 __le32 num_tx_desc_per_queue;
1806 __le32 total_rxd;
1807} __attribute__((packed));
1808
1809#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1810
1811static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1812{
1813 struct mwl8k_priv *priv = hw->priv;
1814 struct mwl8k_cmd_set_hw_spec *cmd;
1815 int rc;
1816 int i;
1817
1818 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1819 if (cmd == NULL)
1820 return -ENOMEM;
1821
1822 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1823 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1824
1825 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1826 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1827 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1828 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1829 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1830 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1831 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1832 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1833
1834 rc = mwl8k_post_cmd(hw, &cmd->header);
1835 kfree(cmd);
1836
1837 return rc;
1838}
1839
1840/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001841 * CMD_MAC_MULTICAST_ADR.
1842 */
1843struct mwl8k_cmd_mac_multicast_adr {
1844 struct mwl8k_cmd_pkt header;
1845 __le16 action;
1846 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001847 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001848};
1849
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001850#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1851#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1852#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1853#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001854
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001855static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001856__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001857 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001858{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001859 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001860 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001861 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001862
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001863 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001864 allmulti = 1;
1865 mc_count = 0;
1866 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001867
1868 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1869
1870 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001871 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001872 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001873
1874 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1875 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001876 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1877 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001878
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001879 if (allmulti) {
1880 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1881 } else if (mc_count) {
1882 int i;
1883
1884 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1885 cmd->numaddr = cpu_to_le16(mc_count);
1886 for (i = 0; i < mc_count && mclist; i++) {
1887 if (mclist->da_addrlen != ETH_ALEN) {
1888 kfree(cmd);
1889 return NULL;
1890 }
1891 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1892 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001893 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001894 }
1895
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001896 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001897}
1898
1899/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001900 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001901 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001902struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001903 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001904 __le32 stats[64];
1905} __attribute__((packed));
1906
1907#define MWL8K_STAT_ACK_FAILURE 9
1908#define MWL8K_STAT_RTS_FAILURE 12
1909#define MWL8K_STAT_FCS_ERROR 24
1910#define MWL8K_STAT_RTS_SUCCESS 11
1911
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001912static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1913 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001914{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001915 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001916 int rc;
1917
1918 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1919 if (cmd == NULL)
1920 return -ENOMEM;
1921
1922 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1923 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001924
1925 rc = mwl8k_post_cmd(hw, &cmd->header);
1926 if (!rc) {
1927 stats->dot11ACKFailureCount =
1928 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1929 stats->dot11RTSFailureCount =
1930 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1931 stats->dot11FCSErrorCount =
1932 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1933 stats->dot11RTSSuccessCount =
1934 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1935 }
1936 kfree(cmd);
1937
1938 return rc;
1939}
1940
1941/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001942 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001943 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001944struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001945 struct mwl8k_cmd_pkt header;
1946 __le16 action;
1947 __le16 control;
1948 __le16 radio_on;
1949} __attribute__((packed));
1950
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001951static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001952mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001953{
1954 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001955 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001956 int rc;
1957
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001958 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001959 return 0;
1960
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001961 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1962 if (cmd == NULL)
1963 return -ENOMEM;
1964
1965 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1966 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1967 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001968 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001969 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1970
1971 rc = mwl8k_post_cmd(hw, &cmd->header);
1972 kfree(cmd);
1973
1974 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001975 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001976
1977 return rc;
1978}
1979
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001980static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001981{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001982 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001983}
1984
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001985static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001986{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001987 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001988}
1989
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001990static int
1991mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1992{
1993 struct mwl8k_priv *priv;
1994
1995 if (hw == NULL || hw->priv == NULL)
1996 return -EINVAL;
1997 priv = hw->priv;
1998
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001999 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002000
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002001 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002002}
2003
2004/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002005 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002006 */
2007#define MWL8K_TX_POWER_LEVEL_TOTAL 8
2008
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002009struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002010 struct mwl8k_cmd_pkt header;
2011 __le16 action;
2012 __le16 support_level;
2013 __le16 current_level;
2014 __le16 reserved;
2015 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2016} __attribute__((packed));
2017
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002018static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002019{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002020 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002021 int rc;
2022
2023 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2024 if (cmd == NULL)
2025 return -ENOMEM;
2026
2027 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2028 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2029 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2030 cmd->support_level = cpu_to_le16(dBm);
2031
2032 rc = mwl8k_post_cmd(hw, &cmd->header);
2033 kfree(cmd);
2034
2035 return rc;
2036}
2037
2038/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002039 * CMD_RF_ANTENNA.
2040 */
2041struct mwl8k_cmd_rf_antenna {
2042 struct mwl8k_cmd_pkt header;
2043 __le16 antenna;
2044 __le16 mode;
2045} __attribute__((packed));
2046
2047#define MWL8K_RF_ANTENNA_RX 1
2048#define MWL8K_RF_ANTENNA_TX 2
2049
2050static int
2051mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2052{
2053 struct mwl8k_cmd_rf_antenna *cmd;
2054 int rc;
2055
2056 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2057 if (cmd == NULL)
2058 return -ENOMEM;
2059
2060 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2061 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2062 cmd->antenna = cpu_to_le16(antenna);
2063 cmd->mode = cpu_to_le16(mask);
2064
2065 rc = mwl8k_post_cmd(hw, &cmd->header);
2066 kfree(cmd);
2067
2068 return rc;
2069}
2070
2071/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002072 * CMD_SET_PRE_SCAN.
2073 */
2074struct mwl8k_cmd_set_pre_scan {
2075 struct mwl8k_cmd_pkt header;
2076} __attribute__((packed));
2077
2078static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2079{
2080 struct mwl8k_cmd_set_pre_scan *cmd;
2081 int rc;
2082
2083 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2084 if (cmd == NULL)
2085 return -ENOMEM;
2086
2087 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2088 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2089
2090 rc = mwl8k_post_cmd(hw, &cmd->header);
2091 kfree(cmd);
2092
2093 return rc;
2094}
2095
2096/*
2097 * CMD_SET_POST_SCAN.
2098 */
2099struct mwl8k_cmd_set_post_scan {
2100 struct mwl8k_cmd_pkt header;
2101 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002102 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002103} __attribute__((packed));
2104
2105static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002106mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002107{
2108 struct mwl8k_cmd_set_post_scan *cmd;
2109 int rc;
2110
2111 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2112 if (cmd == NULL)
2113 return -ENOMEM;
2114
2115 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2116 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2117 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002118 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002119
2120 rc = mwl8k_post_cmd(hw, &cmd->header);
2121 kfree(cmd);
2122
2123 return rc;
2124}
2125
2126/*
2127 * CMD_SET_RF_CHANNEL.
2128 */
2129struct mwl8k_cmd_set_rf_channel {
2130 struct mwl8k_cmd_pkt header;
2131 __le16 action;
2132 __u8 current_channel;
2133 __le32 channel_flags;
2134} __attribute__((packed));
2135
2136static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2137 struct ieee80211_channel *channel)
2138{
2139 struct mwl8k_cmd_set_rf_channel *cmd;
2140 int rc;
2141
2142 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2143 if (cmd == NULL)
2144 return -ENOMEM;
2145
2146 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2147 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2148 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2149 cmd->current_channel = channel->hw_value;
2150 if (channel->band == IEEE80211_BAND_2GHZ)
2151 cmd->channel_flags = cpu_to_le32(0x00000081);
2152 else
2153 cmd->channel_flags = cpu_to_le32(0x00000000);
2154
2155 rc = mwl8k_post_cmd(hw, &cmd->header);
2156 kfree(cmd);
2157
2158 return rc;
2159}
2160
2161/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002162 * CMD_SET_AID.
2163 */
2164#define MWL8K_FRAME_PROT_DISABLED 0x00
2165#define MWL8K_FRAME_PROT_11G 0x07
2166#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2167#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2168
2169struct mwl8k_cmd_update_set_aid {
2170 struct mwl8k_cmd_pkt header;
2171 __le16 aid;
2172
2173 /* AP's MAC address (BSSID) */
2174 __u8 bssid[ETH_ALEN];
2175 __le16 protection_mode;
2176 __u8 supp_rates[14];
2177} __attribute__((packed));
2178
2179static int
2180mwl8k_cmd_set_aid(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2181{
2182 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2183 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2184 struct mwl8k_cmd_update_set_aid *cmd;
2185 u16 prot_mode;
2186 int rc;
2187
2188 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2189 if (cmd == NULL)
2190 return -ENOMEM;
2191
2192 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2193 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2194 cmd->aid = cpu_to_le16(info->aid);
2195
2196 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
2197
2198 if (info->use_cts_prot) {
2199 prot_mode = MWL8K_FRAME_PROT_11G;
2200 } else {
2201 switch (info->ht_operation_mode &
2202 IEEE80211_HT_OP_MODE_PROTECTION) {
2203 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2204 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2205 break;
2206 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2207 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2208 break;
2209 default:
2210 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2211 break;
2212 }
2213 }
2214 cmd->protection_mode = cpu_to_le16(prot_mode);
2215
2216 memcpy(cmd->supp_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
2217
2218 rc = mwl8k_post_cmd(hw, &cmd->header);
2219 kfree(cmd);
2220
2221 return rc;
2222}
2223
2224/*
2225 * CMD_SET_RATE.
2226 */
2227struct mwl8k_cmd_set_rate {
2228 struct mwl8k_cmd_pkt header;
2229 __u8 legacy_rates[14];
2230
2231 /* Bitmap for supported MCS codes. */
2232 __u8 mcs_set[16];
2233 __u8 reserved[16];
2234} __attribute__((packed));
2235
2236static int
2237mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2238{
2239 struct mwl8k_cmd_set_rate *cmd;
2240 int rc;
2241
2242 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2243 if (cmd == NULL)
2244 return -ENOMEM;
2245
2246 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2247 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2248 memcpy(cmd->legacy_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
2249
2250 rc = mwl8k_post_cmd(hw, &cmd->header);
2251 kfree(cmd);
2252
2253 return rc;
2254}
2255
2256/*
2257 * CMD_FINALIZE_JOIN.
2258 */
2259#define MWL8K_FJ_BEACON_MAXLEN 128
2260
2261struct mwl8k_cmd_finalize_join {
2262 struct mwl8k_cmd_pkt header;
2263 __le32 sleep_interval; /* Number of beacon periods to sleep */
2264 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2265} __attribute__((packed));
2266
2267static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2268 int framelen, int dtim)
2269{
2270 struct mwl8k_cmd_finalize_join *cmd;
2271 struct ieee80211_mgmt *payload = frame;
2272 int payload_len;
2273 int rc;
2274
2275 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2276 if (cmd == NULL)
2277 return -ENOMEM;
2278
2279 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2280 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2281 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2282
2283 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2284 if (payload_len < 0)
2285 payload_len = 0;
2286 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2287 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2288
2289 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2290
2291 rc = mwl8k_post_cmd(hw, &cmd->header);
2292 kfree(cmd);
2293
2294 return rc;
2295}
2296
2297/*
2298 * CMD_SET_RTS_THRESHOLD.
2299 */
2300struct mwl8k_cmd_set_rts_threshold {
2301 struct mwl8k_cmd_pkt header;
2302 __le16 action;
2303 __le16 threshold;
2304} __attribute__((packed));
2305
2306static int mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw,
2307 u16 action, u16 threshold)
2308{
2309 struct mwl8k_cmd_set_rts_threshold *cmd;
2310 int rc;
2311
2312 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2313 if (cmd == NULL)
2314 return -ENOMEM;
2315
2316 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2317 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2318 cmd->action = cpu_to_le16(action);
2319 cmd->threshold = cpu_to_le16(threshold);
2320
2321 rc = mwl8k_post_cmd(hw, &cmd->header);
2322 kfree(cmd);
2323
2324 return rc;
2325}
2326
2327/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002328 * CMD_SET_SLOT.
2329 */
2330struct mwl8k_cmd_set_slot {
2331 struct mwl8k_cmd_pkt header;
2332 __le16 action;
2333 __u8 short_slot;
2334} __attribute__((packed));
2335
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002336static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002337{
2338 struct mwl8k_cmd_set_slot *cmd;
2339 int rc;
2340
2341 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2342 if (cmd == NULL)
2343 return -ENOMEM;
2344
2345 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2346 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2347 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002348 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002349
2350 rc = mwl8k_post_cmd(hw, &cmd->header);
2351 kfree(cmd);
2352
2353 return rc;
2354}
2355
2356/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002357 * CMD_SET_EDCA_PARAMS.
2358 */
2359struct mwl8k_cmd_set_edca_params {
2360 struct mwl8k_cmd_pkt header;
2361
2362 /* See MWL8K_SET_EDCA_XXX below */
2363 __le16 action;
2364
2365 /* TX opportunity in units of 32 us */
2366 __le16 txop;
2367
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002368 union {
2369 struct {
2370 /* Log exponent of max contention period: 0...15 */
2371 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002372
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002373 /* Log exponent of min contention period: 0...15 */
2374 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002375
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002376 /* Adaptive interframe spacing in units of 32us */
2377 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002378
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002379 /* TX queue to configure */
2380 __u8 txq;
2381 } ap;
2382 struct {
2383 /* Log exponent of max contention period: 0...15 */
2384 __u8 log_cw_max;
2385
2386 /* Log exponent of min contention period: 0...15 */
2387 __u8 log_cw_min;
2388
2389 /* Adaptive interframe spacing in units of 32us */
2390 __u8 aifs;
2391
2392 /* TX queue to configure */
2393 __u8 txq;
2394 } sta;
2395 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002396} __attribute__((packed));
2397
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002398#define MWL8K_SET_EDCA_CW 0x01
2399#define MWL8K_SET_EDCA_TXOP 0x02
2400#define MWL8K_SET_EDCA_AIFS 0x04
2401
2402#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2403 MWL8K_SET_EDCA_TXOP | \
2404 MWL8K_SET_EDCA_AIFS)
2405
2406static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002407mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2408 __u16 cw_min, __u16 cw_max,
2409 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002410{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002411 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002412 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002413 int rc;
2414
2415 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2416 if (cmd == NULL)
2417 return -ENOMEM;
2418
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002419 /*
2420 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2421 * this call.
2422 */
2423 qnum ^= !(qnum >> 1);
2424
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002425 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2426 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002427 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2428 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002429 if (priv->ap_fw) {
2430 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2431 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2432 cmd->ap.aifs = aifs;
2433 cmd->ap.txq = qnum;
2434 } else {
2435 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2436 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2437 cmd->sta.aifs = aifs;
2438 cmd->sta.txq = qnum;
2439 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002440
2441 rc = mwl8k_post_cmd(hw, &cmd->header);
2442 kfree(cmd);
2443
2444 return rc;
2445}
2446
2447/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002448 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002449 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002450struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002451 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002452 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002453} __attribute__((packed));
2454
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002455static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002456{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002457 struct mwl8k_priv *priv = hw->priv;
2458 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002459 int rc;
2460
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002461 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2462 if (cmd == NULL)
2463 return -ENOMEM;
2464
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002465 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002466 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002467 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002468
2469 rc = mwl8k_post_cmd(hw, &cmd->header);
2470 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002471
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002472 if (!rc)
2473 priv->wmm_enabled = enable;
2474
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002475 return rc;
2476}
2477
2478/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002479 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002480 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002481struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002482 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002483 __le32 action;
2484 __u8 rx_antenna_map;
2485 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002486} __attribute__((packed));
2487
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002488static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002489{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002490 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002491 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002492
2493 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2494 if (cmd == NULL)
2495 return -ENOMEM;
2496
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002497 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002498 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002499 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2500 cmd->rx_antenna_map = rx;
2501 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002502
2503 rc = mwl8k_post_cmd(hw, &cmd->header);
2504 kfree(cmd);
2505
2506 return rc;
2507}
2508
2509/*
2510 * CMD_USE_FIXED_RATE.
2511 */
2512#define MWL8K_RATE_TABLE_SIZE 8
2513#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002514#define MWL8K_USE_AUTO_RATE 0x0002
2515
2516struct mwl8k_rate_entry {
2517 /* Set to 1 if HT rate, 0 if legacy. */
2518 __le32 is_ht_rate;
2519
2520 /* Set to 1 to use retry_count field. */
2521 __le32 enable_retry;
2522
2523 /* Specified legacy rate or MCS. */
2524 __le32 rate;
2525
2526 /* Number of allowed retries. */
2527 __le32 retry_count;
2528} __attribute__((packed));
2529
2530struct mwl8k_rate_table {
2531 /* 1 to allow specified rate and below */
2532 __le32 allow_rate_drop;
2533 __le32 num_rates;
2534 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2535} __attribute__((packed));
2536
2537struct mwl8k_cmd_use_fixed_rate {
2538 struct mwl8k_cmd_pkt header;
2539 __le32 action;
2540 struct mwl8k_rate_table rate_table;
2541
2542 /* Unicast, Broadcast or Multicast */
2543 __le32 rate_type;
2544 __le32 reserved1;
2545 __le32 reserved2;
2546} __attribute__((packed));
2547
2548static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2549 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2550{
2551 struct mwl8k_cmd_use_fixed_rate *cmd;
2552 int count;
2553 int rc;
2554
2555 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2556 if (cmd == NULL)
2557 return -ENOMEM;
2558
2559 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2560 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2561
2562 cmd->action = cpu_to_le32(action);
2563 cmd->rate_type = cpu_to_le32(rate_type);
2564
2565 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002566 /*
2567 * Copy over each field manually so that endian
2568 * conversion can be done.
2569 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002570 cmd->rate_table.allow_rate_drop =
2571 cpu_to_le32(rate_table->allow_rate_drop);
2572 cmd->rate_table.num_rates =
2573 cpu_to_le32(rate_table->num_rates);
2574
2575 for (count = 0; count < rate_table->num_rates; count++) {
2576 struct mwl8k_rate_entry *dst =
2577 &cmd->rate_table.rate_entry[count];
2578 struct mwl8k_rate_entry *src =
2579 &rate_table->rate_entry[count];
2580
2581 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2582 dst->enable_retry = cpu_to_le32(src->enable_retry);
2583 dst->rate = cpu_to_le32(src->rate);
2584 dst->retry_count = cpu_to_le32(src->retry_count);
2585 }
2586 }
2587
2588 rc = mwl8k_post_cmd(hw, &cmd->header);
2589 kfree(cmd);
2590
2591 return rc;
2592}
2593
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002594/*
2595 * CMD_ENABLE_SNIFFER.
2596 */
2597struct mwl8k_cmd_enable_sniffer {
2598 struct mwl8k_cmd_pkt header;
2599 __le32 action;
2600} __attribute__((packed));
2601
2602static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2603{
2604 struct mwl8k_cmd_enable_sniffer *cmd;
2605 int rc;
2606
2607 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2608 if (cmd == NULL)
2609 return -ENOMEM;
2610
2611 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2612 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2613 cmd->action = cpu_to_le32(!!enable);
2614
2615 rc = mwl8k_post_cmd(hw, &cmd->header);
2616 kfree(cmd);
2617
2618 return rc;
2619}
2620
2621/*
2622 * CMD_SET_MAC_ADDR.
2623 */
2624struct mwl8k_cmd_set_mac_addr {
2625 struct mwl8k_cmd_pkt header;
2626 union {
2627 struct {
2628 __le16 mac_type;
2629 __u8 mac_addr[ETH_ALEN];
2630 } mbss;
2631 __u8 mac_addr[ETH_ALEN];
2632 };
2633} __attribute__((packed));
2634
2635static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2636{
2637 struct mwl8k_priv *priv = hw->priv;
2638 struct mwl8k_cmd_set_mac_addr *cmd;
2639 int rc;
2640
2641 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2642 if (cmd == NULL)
2643 return -ENOMEM;
2644
2645 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2646 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2647 if (priv->ap_fw) {
2648 cmd->mbss.mac_type = 0;
2649 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2650 } else {
2651 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2652 }
2653
2654 rc = mwl8k_post_cmd(hw, &cmd->header);
2655 kfree(cmd);
2656
2657 return rc;
2658}
2659
2660/*
2661 * CMD_SET_RATEADAPT_MODE.
2662 */
2663struct mwl8k_cmd_set_rate_adapt_mode {
2664 struct mwl8k_cmd_pkt header;
2665 __le16 action;
2666 __le16 mode;
2667} __attribute__((packed));
2668
2669static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2670{
2671 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2672 int rc;
2673
2674 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2675 if (cmd == NULL)
2676 return -ENOMEM;
2677
2678 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2679 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2680 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2681 cmd->mode = cpu_to_le16(mode);
2682
2683 rc = mwl8k_post_cmd(hw, &cmd->header);
2684 kfree(cmd);
2685
2686 return rc;
2687}
2688
2689/*
2690 * CMD_UPDATE_STADB.
2691 */
2692struct mwl8k_cmd_update_stadb {
2693 struct mwl8k_cmd_pkt header;
2694
2695 /* See STADB_ACTION_TYPE */
2696 __le32 action;
2697
2698 /* Peer MAC address */
2699 __u8 peer_addr[ETH_ALEN];
2700
2701 __le32 reserved;
2702
2703 /* Peer info - valid during add/update. */
2704 struct peer_capability_info peer_info;
2705} __attribute__((packed));
2706
2707static int mwl8k_cmd_update_stadb(struct ieee80211_hw *hw,
2708 struct ieee80211_vif *vif, __u32 action)
2709{
2710 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2711 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2712 struct mwl8k_cmd_update_stadb *cmd;
2713 struct peer_capability_info *peer_info;
2714 int rc;
2715
2716 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2717 if (cmd == NULL)
2718 return -ENOMEM;
2719
2720 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2721 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2722
2723 cmd->action = cpu_to_le32(action);
2724 peer_info = &cmd->peer_info;
2725 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2726
2727 switch (action) {
2728 case MWL8K_STA_DB_ADD_ENTRY:
2729 case MWL8K_STA_DB_MODIFY_ENTRY:
2730 /* Build peer_info block */
2731 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2732 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2733 memcpy(peer_info->legacy_rates, mwl8k_rateids,
2734 sizeof(mwl8k_rateids));
2735 peer_info->interop = 1;
2736 peer_info->amsdu_enabled = 0;
2737
2738 rc = mwl8k_post_cmd(hw, &cmd->header);
2739 if (rc == 0)
2740 mv_vif->peer_id = peer_info->station_id;
2741
2742 break;
2743
2744 case MWL8K_STA_DB_DEL_ENTRY:
2745 case MWL8K_STA_DB_FLUSH:
2746 default:
2747 rc = mwl8k_post_cmd(hw, &cmd->header);
2748 if (rc == 0)
2749 mv_vif->peer_id = 0;
2750 break;
2751 }
2752 kfree(cmd);
2753
2754 return rc;
2755}
2756
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002757
2758/*
2759 * Interrupt handling.
2760 */
2761static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2762{
2763 struct ieee80211_hw *hw = dev_id;
2764 struct mwl8k_priv *priv = hw->priv;
2765 u32 status;
2766
2767 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2768 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2769
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002770 if (!status)
2771 return IRQ_NONE;
2772
2773 if (status & MWL8K_A2H_INT_TX_DONE)
2774 tasklet_schedule(&priv->tx_reclaim_task);
2775
2776 if (status & MWL8K_A2H_INT_RX_READY) {
2777 while (rxq_process(hw, 0, 1))
2778 rxq_refill(hw, 0, 1);
2779 }
2780
2781 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002782 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002783 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002784 }
2785
2786 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002787 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002788 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002789 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002790 }
2791
2792 return IRQ_HANDLED;
2793}
2794
2795
2796/*
2797 * Core driver operations.
2798 */
2799static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2800{
2801 struct mwl8k_priv *priv = hw->priv;
2802 int index = skb_get_queue_mapping(skb);
2803 int rc;
2804
2805 if (priv->current_channel == NULL) {
2806 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002807 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002808 dev_kfree_skb(skb);
2809 return NETDEV_TX_OK;
2810 }
2811
2812 rc = mwl8k_txq_xmit(hw, index, skb);
2813
2814 return rc;
2815}
2816
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002817static int mwl8k_start(struct ieee80211_hw *hw)
2818{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002819 struct mwl8k_priv *priv = hw->priv;
2820 int rc;
2821
Joe Perchesa0607fd2009-11-18 23:29:17 -08002822 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002823 IRQF_SHARED, MWL8K_NAME, hw);
2824 if (rc) {
2825 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002826 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002827 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002828 }
2829
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002830 /* Enable tx reclaim tasklet */
2831 tasklet_enable(&priv->tx_reclaim_task);
2832
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002833 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002834 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002835
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002836 rc = mwl8k_fw_lock(hw);
2837 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002838 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002839
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002840 if (!priv->ap_fw) {
2841 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002842 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002843
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002844 if (!rc)
2845 rc = mwl8k_cmd_set_pre_scan(hw);
2846
2847 if (!rc)
2848 rc = mwl8k_cmd_set_post_scan(hw,
2849 "\x00\x00\x00\x00\x00\x00");
2850 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002851
2852 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002853 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002854
2855 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002856 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002857
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002858 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002859 }
2860
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002861 if (rc) {
2862 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2863 free_irq(priv->pdev->irq, hw);
2864 tasklet_disable(&priv->tx_reclaim_task);
2865 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002866
2867 return rc;
2868}
2869
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002870static void mwl8k_stop(struct ieee80211_hw *hw)
2871{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002872 struct mwl8k_priv *priv = hw->priv;
2873 int i;
2874
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002875 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002876
2877 ieee80211_stop_queues(hw);
2878
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002879 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002880 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002881 free_irq(priv->pdev->irq, hw);
2882
2883 /* Stop finalize join worker */
2884 cancel_work_sync(&priv->finalize_join_worker);
2885 if (priv->beacon_skb != NULL)
2886 dev_kfree_skb(priv->beacon_skb);
2887
2888 /* Stop tx reclaim tasklet */
2889 tasklet_disable(&priv->tx_reclaim_task);
2890
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002891 /* Return all skbs to mac80211 */
2892 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2893 mwl8k_txq_reclaim(hw, i, 1);
2894}
2895
2896static int mwl8k_add_interface(struct ieee80211_hw *hw,
2897 struct ieee80211_if_init_conf *conf)
2898{
2899 struct mwl8k_priv *priv = hw->priv;
2900 struct mwl8k_vif *mwl8k_vif;
2901
2902 /*
2903 * We only support one active interface at a time.
2904 */
2905 if (priv->vif != NULL)
2906 return -EBUSY;
2907
2908 /*
2909 * We only support managed interfaces for now.
2910 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002911 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002912 return -EINVAL;
2913
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002914 /*
2915 * Reject interface creation if sniffer mode is active, as
2916 * STA operation is mutually exclusive with hardware sniffer
2917 * mode.
2918 */
2919 if (priv->sniffer_enabled) {
2920 printk(KERN_INFO "%s: unable to create STA "
2921 "interface due to sniffer mode being enabled\n",
2922 wiphy_name(hw->wiphy));
2923 return -EINVAL;
2924 }
2925
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002926 /* Clean out driver private area */
2927 mwl8k_vif = MWL8K_VIF(conf->vif);
2928 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2929
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002930 /* Set and save the mac address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002931 mwl8k_cmd_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002932 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002933
2934 /* Back pointer to parent config block */
2935 mwl8k_vif->priv = priv;
2936
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002937 /* Set Initial sequence number to zero */
2938 mwl8k_vif->seqno = 0;
2939
2940 priv->vif = conf->vif;
2941 priv->current_channel = NULL;
2942
2943 return 0;
2944}
2945
2946static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2947 struct ieee80211_if_init_conf *conf)
2948{
2949 struct mwl8k_priv *priv = hw->priv;
2950
2951 if (priv->vif == NULL)
2952 return;
2953
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002954 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002955
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002956 priv->vif = NULL;
2957}
2958
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002959static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002960{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002961 struct ieee80211_conf *conf = &hw->conf;
2962 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002963 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002964
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002965 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002966 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002967 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002968 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002969 }
2970
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002971 rc = mwl8k_fw_lock(hw);
2972 if (rc)
2973 return rc;
2974
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002975 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002976 if (rc)
2977 goto out;
2978
2979 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2980 if (rc)
2981 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002982
2983 priv->current_channel = conf->channel;
2984
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002985 if (conf->power_level > 18)
2986 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002987 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002988 if (rc)
2989 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002990
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002991 if (priv->ap_fw) {
2992 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2993 if (!rc)
2994 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2995 } else {
2996 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2997 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002998
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002999out:
3000 mwl8k_fw_unlock(hw);
3001
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003002 return rc;
3003}
3004
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003005static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3006 struct ieee80211_vif *vif,
3007 struct ieee80211_bss_conf *info,
3008 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003009{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003010 struct mwl8k_priv *priv = hw->priv;
3011 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003012 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003013
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003014 if ((changed & BSS_CHANGED_ASSOC) == 0)
3015 return;
3016
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003017 priv->capture_beacon = false;
3018
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003019 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02003020 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003021 return;
3022
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003023 if (info->assoc) {
3024 memcpy(&mwl8k_vif->bss_info, info,
3025 sizeof(struct ieee80211_bss_conf));
3026
Lennert Buytenhekd1844d72009-11-30 18:13:56 +01003027 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
3028
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003029 /* Install rates */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003030 rc = mwl8k_cmd_set_rate(hw, vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003031 if (rc)
3032 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003033
3034 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003035 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
3036 MWL8K_UCAST_RATE, NULL);
3037 if (rc)
3038 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003039
3040 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003041 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
3042 if (rc)
3043 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003044
3045 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003046 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
3047 if (rc)
3048 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003049
3050 /* Update peer rate info */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003051 rc = mwl8k_cmd_update_stadb(hw, vif,
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003052 MWL8K_STA_DB_MODIFY_ENTRY);
3053 if (rc)
3054 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003055
3056 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003057 rc = mwl8k_cmd_set_aid(hw, vif);
3058 if (rc)
3059 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003060
3061 /*
3062 * Finalize the join. Tell rx handler to process
3063 * next beacon from our BSSID.
3064 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003065 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003066 priv->capture_beacon = true;
3067 } else {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003068 rc = mwl8k_cmd_update_stadb(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003069 memset(&mwl8k_vif->bss_info, 0,
3070 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003071 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003072 }
3073
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003074out:
3075 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003076}
3077
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003078static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3079 int mc_count, struct dev_addr_list *mclist)
3080{
3081 struct mwl8k_cmd_pkt *cmd;
3082
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003083 /*
3084 * Synthesize and return a command packet that programs the
3085 * hardware multicast address filter. At this point we don't
3086 * know whether FIF_ALLMULTI is being requested, but if it is,
3087 * we'll end up throwing this packet away and creating a new
3088 * one in mwl8k_configure_filter().
3089 */
3090 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003091
3092 return (unsigned long)cmd;
3093}
3094
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003095static int
3096mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3097 unsigned int changed_flags,
3098 unsigned int *total_flags)
3099{
3100 struct mwl8k_priv *priv = hw->priv;
3101
3102 /*
3103 * Hardware sniffer mode is mutually exclusive with STA
3104 * operation, so refuse to enable sniffer mode if a STA
3105 * interface is active.
3106 */
3107 if (priv->vif != NULL) {
3108 if (net_ratelimit())
3109 printk(KERN_INFO "%s: not enabling sniffer "
3110 "mode because STA interface is active\n",
3111 wiphy_name(hw->wiphy));
3112 return 0;
3113 }
3114
3115 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003116 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003117 return 0;
3118 priv->sniffer_enabled = true;
3119 }
3120
3121 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3122 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3123 FIF_OTHER_BSS;
3124
3125 return 1;
3126}
3127
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003128static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3129 unsigned int changed_flags,
3130 unsigned int *total_flags,
3131 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003132{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003133 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003134 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3135
3136 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003137 * AP firmware doesn't allow fine-grained control over
3138 * the receive filter.
3139 */
3140 if (priv->ap_fw) {
3141 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3142 kfree(cmd);
3143 return;
3144 }
3145
3146 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003147 * Enable hardware sniffer mode if FIF_CONTROL or
3148 * FIF_OTHER_BSS is requested.
3149 */
3150 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3151 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3152 kfree(cmd);
3153 return;
3154 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003155
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003156 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003157 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003158
3159 if (mwl8k_fw_lock(hw))
3160 return;
3161
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003162 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003163 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003164 priv->sniffer_enabled = false;
3165 }
3166
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003167 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003168 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3169 /*
3170 * Disable the BSS filter.
3171 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003172 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003173 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003174 u8 *bssid;
3175
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003176 /*
3177 * Enable the BSS filter.
3178 *
3179 * If there is an active STA interface, use that
3180 * interface's BSSID, otherwise use a dummy one
3181 * (where the OUI part needs to be nonzero for
3182 * the BSSID to be accepted by POST_SCAN).
3183 */
3184 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003185 if (priv->vif != NULL)
3186 bssid = MWL8K_VIF(priv->vif)->bssid;
3187
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003188 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003189 }
3190 }
3191
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003192 /*
3193 * If FIF_ALLMULTI is being requested, throw away the command
3194 * packet that ->prepare_multicast() built and replace it with
3195 * a command packet that enables reception of all multicast
3196 * packets.
3197 */
3198 if (*total_flags & FIF_ALLMULTI) {
3199 kfree(cmd);
3200 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3201 }
3202
3203 if (cmd != NULL) {
3204 mwl8k_post_cmd(hw, cmd);
3205 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003206 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003207
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003208 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003209}
3210
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003211static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3212{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003213 return mwl8k_cmd_set_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003214}
3215
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003216static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3217 const struct ieee80211_tx_queue_params *params)
3218{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003219 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003220 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003221
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003222 rc = mwl8k_fw_lock(hw);
3223 if (!rc) {
3224 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003225 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003226
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003227 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003228 rc = mwl8k_cmd_set_edca_params(hw, queue,
3229 params->cw_min,
3230 params->cw_max,
3231 params->aifs,
3232 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003233
3234 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003235 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003236
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003237 return rc;
3238}
3239
3240static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3241 struct ieee80211_tx_queue_stats *stats)
3242{
3243 struct mwl8k_priv *priv = hw->priv;
3244 struct mwl8k_tx_queue *txq;
3245 int index;
3246
3247 spin_lock_bh(&priv->tx_lock);
3248 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3249 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003250 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003251 sizeof(struct ieee80211_tx_queue_stats));
3252 }
3253 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003254
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003255 return 0;
3256}
3257
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003258static int mwl8k_get_stats(struct ieee80211_hw *hw,
3259 struct ieee80211_low_level_stats *stats)
3260{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003261 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003262}
3263
3264static const struct ieee80211_ops mwl8k_ops = {
3265 .tx = mwl8k_tx,
3266 .start = mwl8k_start,
3267 .stop = mwl8k_stop,
3268 .add_interface = mwl8k_add_interface,
3269 .remove_interface = mwl8k_remove_interface,
3270 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003271 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003272 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003273 .configure_filter = mwl8k_configure_filter,
3274 .set_rts_threshold = mwl8k_set_rts_threshold,
3275 .conf_tx = mwl8k_conf_tx,
3276 .get_tx_stats = mwl8k_get_tx_stats,
3277 .get_stats = mwl8k_get_stats,
3278};
3279
3280static void mwl8k_tx_reclaim_handler(unsigned long data)
3281{
3282 int i;
3283 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3284 struct mwl8k_priv *priv = hw->priv;
3285
3286 spin_lock_bh(&priv->tx_lock);
3287 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3288 mwl8k_txq_reclaim(hw, i, 0);
3289
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003290 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003291 complete(priv->tx_wait);
3292 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003293 }
3294 spin_unlock_bh(&priv->tx_lock);
3295}
3296
3297static void mwl8k_finalize_join_worker(struct work_struct *work)
3298{
3299 struct mwl8k_priv *priv =
3300 container_of(work, struct mwl8k_priv, finalize_join_worker);
3301 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003302 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003303
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003304 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003305 dev_kfree_skb(skb);
3306
3307 priv->beacon_skb = NULL;
3308}
3309
John W. Linvillebcb628d2009-11-06 16:40:16 -05003310enum {
3311 MWL8687 = 0,
3312 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003313};
3314
John W. Linvillebcb628d2009-11-06 16:40:16 -05003315static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3316 {
3317 .part_name = "88w8687",
3318 .helper_image = "mwl8k/helper_8687.fw",
3319 .fw_image = "mwl8k/fmimage_8687.fw",
3320 .rxd_ops = &rxd_8687_ops,
3321 .modes = BIT(NL80211_IFTYPE_STATION),
3322 },
3323 {
3324 .part_name = "88w8366",
3325 .helper_image = "mwl8k/helper_8366.fw",
3326 .fw_image = "mwl8k/fmimage_8366.fw",
3327 .rxd_ops = &rxd_8366_ops,
3328 .modes = 0,
3329 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003330};
3331
3332static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003333 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3334 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3335 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3336 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003337};
3338MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3339
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003340static int __devinit mwl8k_probe(struct pci_dev *pdev,
3341 const struct pci_device_id *id)
3342{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003343 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003344 struct ieee80211_hw *hw;
3345 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003346 int rc;
3347 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003348
3349 if (!printed_version) {
3350 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3351 printed_version = 1;
3352 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003353
3354 rc = pci_enable_device(pdev);
3355 if (rc) {
3356 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3357 MWL8K_NAME);
3358 return rc;
3359 }
3360
3361 rc = pci_request_regions(pdev, MWL8K_NAME);
3362 if (rc) {
3363 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3364 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003365 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003366 }
3367
3368 pci_set_master(pdev);
3369
3370 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3371 if (hw == NULL) {
3372 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3373 rc = -ENOMEM;
3374 goto err_free_reg;
3375 }
3376
3377 priv = hw->priv;
3378 priv->hw = hw;
3379 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003380 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02003381 priv->rxd_ops = priv->device_info->rxd_ops;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003382 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02003383 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003384 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003385
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003386 SET_IEEE80211_DEV(hw, &pdev->dev);
3387 pci_set_drvdata(pdev, hw);
3388
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003389 priv->sram = pci_iomap(pdev, 0, 0x10000);
3390 if (priv->sram == NULL) {
3391 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003392 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003393 goto err_iounmap;
3394 }
3395
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003396 /*
3397 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3398 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3399 */
3400 priv->regs = pci_iomap(pdev, 1, 0x10000);
3401 if (priv->regs == NULL) {
3402 priv->regs = pci_iomap(pdev, 2, 0x10000);
3403 if (priv->regs == NULL) {
3404 printk(KERN_ERR "%s: Cannot map device registers\n",
3405 wiphy_name(hw->wiphy));
3406 goto err_iounmap;
3407 }
3408 }
3409
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003410 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3411 priv->band.band = IEEE80211_BAND_2GHZ;
3412 priv->band.channels = priv->channels;
3413 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3414 priv->band.bitrates = priv->rates;
3415 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3416 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3417
3418 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3419 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3420
3421 /*
3422 * Extra headroom is the size of the required DMA header
3423 * minus the size of the smallest 802.11 frame (CTS frame).
3424 */
3425 hw->extra_tx_headroom =
3426 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3427
3428 hw->channel_change_time = 10;
3429
3430 hw->queues = MWL8K_TX_QUEUES;
3431
Lennert Buytenhek547810e2009-10-22 20:21:02 +02003432 hw->wiphy->interface_modes = priv->device_info->modes;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003433
3434 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003435 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003436 hw->vif_data_size = sizeof(struct mwl8k_vif);
3437 priv->vif = NULL;
3438
3439 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003440 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003441 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003442
3443 /* Finalize join worker */
3444 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3445
3446 /* TX reclaim tasklet */
3447 tasklet_init(&priv->tx_reclaim_task,
3448 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3449 tasklet_disable(&priv->tx_reclaim_task);
3450
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003451 /* Power management cookie */
3452 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3453 if (priv->cookie == NULL)
3454 goto err_iounmap;
3455
3456 rc = mwl8k_rxq_init(hw, 0);
3457 if (rc)
3458 goto err_iounmap;
3459 rxq_refill(hw, 0, INT_MAX);
3460
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003461 mutex_init(&priv->fw_mutex);
3462 priv->fw_mutex_owner = NULL;
3463 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003464 priv->hostcmd_wait = NULL;
3465
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003466 spin_lock_init(&priv->tx_lock);
3467
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003468 priv->tx_wait = NULL;
3469
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003470 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3471 rc = mwl8k_txq_init(hw, i);
3472 if (rc)
3473 goto err_free_queues;
3474 }
3475
3476 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003477 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003478 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3479 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3480
Joe Perchesa0607fd2009-11-18 23:29:17 -08003481 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003482 IRQF_SHARED, MWL8K_NAME, hw);
3483 if (rc) {
3484 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003485 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003486 goto err_free_queues;
3487 }
3488
3489 /* Reset firmware and hardware */
3490 mwl8k_hw_reset(priv);
3491
3492 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003493 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003494 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003495 printk(KERN_ERR "%s: Firmware files not found\n",
3496 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003497 goto err_free_irq;
3498 }
3499
3500 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003501 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003502 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003503 printk(KERN_ERR "%s: Cannot start firmware\n",
3504 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003505 goto err_stop_firmware;
3506 }
3507
3508 /* Reclaim memory once firmware is successfully loaded */
3509 mwl8k_release_firmware(priv);
3510
3511 /*
3512 * Temporarily enable interrupts. Initial firmware host
3513 * commands use interrupts and avoids polling. Disable
3514 * interrupts when done.
3515 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003516 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003517
3518 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02003519 if (priv->ap_fw) {
3520 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3521 if (!rc)
3522 rc = mwl8k_cmd_set_hw_spec(hw);
3523 } else {
3524 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3525 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003526 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003527 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3528 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003529 goto err_stop_firmware;
3530 }
3531
3532 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003533 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003534 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003535 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003536 goto err_stop_firmware;
3537 }
3538
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003539 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003540 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003541 if (rc) {
3542 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3543 wiphy_name(hw->wiphy));
3544 goto err_stop_firmware;
3545 }
3546
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003547 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003548 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003549 free_irq(priv->pdev->irq, hw);
3550
3551 rc = ieee80211_register_hw(hw);
3552 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003553 printk(KERN_ERR "%s: Cannot register device\n",
3554 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003555 goto err_stop_firmware;
3556 }
3557
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003558 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003559 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003560 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003561 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003562 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3563 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003564
3565 return 0;
3566
3567err_stop_firmware:
3568 mwl8k_hw_reset(priv);
3569 mwl8k_release_firmware(priv);
3570
3571err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003572 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003573 free_irq(priv->pdev->irq, hw);
3574
3575err_free_queues:
3576 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3577 mwl8k_txq_deinit(hw, i);
3578 mwl8k_rxq_deinit(hw, 0);
3579
3580err_iounmap:
3581 if (priv->cookie != NULL)
3582 pci_free_consistent(priv->pdev, 4,
3583 priv->cookie, priv->cookie_dma);
3584
3585 if (priv->regs != NULL)
3586 pci_iounmap(pdev, priv->regs);
3587
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003588 if (priv->sram != NULL)
3589 pci_iounmap(pdev, priv->sram);
3590
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003591 pci_set_drvdata(pdev, NULL);
3592 ieee80211_free_hw(hw);
3593
3594err_free_reg:
3595 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003596
3597err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003598 pci_disable_device(pdev);
3599
3600 return rc;
3601}
3602
Joerg Albert230f7af2009-04-18 02:10:45 +02003603static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003604{
3605 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3606}
3607
Joerg Albert230f7af2009-04-18 02:10:45 +02003608static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003609{
3610 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3611 struct mwl8k_priv *priv;
3612 int i;
3613
3614 if (hw == NULL)
3615 return;
3616 priv = hw->priv;
3617
3618 ieee80211_stop_queues(hw);
3619
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003620 ieee80211_unregister_hw(hw);
3621
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003622 /* Remove tx reclaim tasklet */
3623 tasklet_kill(&priv->tx_reclaim_task);
3624
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003625 /* Stop hardware */
3626 mwl8k_hw_reset(priv);
3627
3628 /* Return all skbs to mac80211 */
3629 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3630 mwl8k_txq_reclaim(hw, i, 1);
3631
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003632 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3633 mwl8k_txq_deinit(hw, i);
3634
3635 mwl8k_rxq_deinit(hw, 0);
3636
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003637 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003638
3639 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003640 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003641 pci_set_drvdata(pdev, NULL);
3642 ieee80211_free_hw(hw);
3643 pci_release_regions(pdev);
3644 pci_disable_device(pdev);
3645}
3646
3647static struct pci_driver mwl8k_driver = {
3648 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003649 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003650 .probe = mwl8k_probe,
3651 .remove = __devexit_p(mwl8k_remove),
3652 .shutdown = __devexit_p(mwl8k_shutdown),
3653};
3654
3655static int __init mwl8k_init(void)
3656{
3657 return pci_register_driver(&mwl8k_driver);
3658}
3659
3660static void __exit mwl8k_exit(void)
3661{
3662 pci_unregister_driver(&mwl8k_driver);
3663}
3664
3665module_init(mwl8k_init);
3666module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003667
3668MODULE_DESCRIPTION(MWL8K_DESC);
3669MODULE_VERSION(MWL8K_VERSION);
3670MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3671MODULE_LICENSE("GPL");